void ParameterWindow::_updateParameterView(
    BMediaTheme *theme) {
    D_INTERNAL(("ParameterWindow::_updateParameterView()\n"));

    // clear the old version
    if (m_parameters) {
        ParameterContainerView *view = dynamic_cast<ParameterContainerView *>(FindView("ParameterContainerView"));
        RemoveChild(view);
        delete m_parameters;
        m_parameters = 0;
        delete view;
    }

    // fetch ParameterWeb from the MediaRoster
    BMediaRoster *roster = BMediaRoster::CurrentRoster();
    if (roster) {
        BParameterWeb *web;
        status_t error = roster->GetParameterWebFor(m_node, &web);
        if (!error && (web->CountParameters() || web->CountGroups())) {
            // if no theme was specified, use the preferred theme
            if (!theme) {
                theme = BMediaTheme::PreferredTheme();
            }
            // acquire the view
            m_parameters = BMediaTheme::ViewFor(web, 0, theme);
            if (m_parameters) {
                BMenuBar *menuBar = KeyMenuBar();
                m_idealSize = m_parameters->Bounds();
                m_idealSize.right += B_V_SCROLL_BAR_WIDTH;
                m_idealSize.bottom += B_H_SCROLL_BAR_HEIGHT;
                if (menuBar) {
                    m_parameters->MoveTo(0.0, menuBar->Bounds().bottom + 1.0);
                    m_idealSize.bottom += menuBar->Bounds().bottom + 1.0;
                }
            }
        }
    }

    // limit min size to avoid funny-looking scrollbars
    float hMin = B_V_SCROLL_BAR_WIDTH*6, vMin = B_H_SCROLL_BAR_HEIGHT*3;
    // limit max size to full extents of the parameter view
    float hMax = m_idealSize.Width(), vMax = m_idealSize.Height();
    SetSizeLimits(hMin, hMax, vMin, vMax);

    // adapt the window to the new dimensions
    ResizeTo(m_idealSize.Width(), m_idealSize.Height());
    m_zoomed = true;

    if (m_parameters) {
        BRect paramRect = m_parameters->Bounds();
        AddChild(new ParameterContainerView(paramRect, m_parameters));
    }
}
Beispiel #2
0
ReloadedWin::ReloadedWin()
    : BWindow(BRect(80,80,847,619),"Reloaded", B_TITLED_WINDOW,
              B_NOT_ZOOMABLE|B_NOT_RESIZABLE|B_QUIT_ON_WINDOW_CLOSE)
{
    // TODO - compute the size instead of hardcoding it
    SetSizeLimits(847-80,847-80,619-61,619-61);

    BMenuBar* menu = new BMenuBar(BRect(0,0,Bounds().Width() - 16,16),
                                  "mainmenu", B_FOLLOW_LEFT | B_FOLLOW_TOP);
    BMenu* file = new BMenu("File");
    menu->AddItem(file);
    BMenuItem* insertdsk = new BMenuItem("Insert Disc",
                                         new BMessage('dins'));
    file->AddItem(insertdsk);

    BMenu* settings = new BMenu("Settings");
    menu->AddItem(settings);
    BMenuItem* keymap = new BMenuItem("Keymap",
                                      new BMessage('kymp'));
    settings->AddItem(keymap);
    AddChild(menu);

    fStatusLed = new BView(BRect(Bounds().Width() - 16, 0, Bounds().Width(), 16), "fdcLed",
                           B_FOLLOW_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW);
    fStatusLed->SetViewColor(0x77,00,00);
    AddChild(fStatusLed);

    fBitmapView = new RBitmapView(this, false);
    fBitmapView->MoveTo(0, menu->Bounds().bottom + 1);

    Show();
}
Beispiel #3
0
void PProjectWindow::SetupSizeAndLayout()
{
	inherited::SetupSizeAndLayout();
	ResizeTo(180, 400);
	SetSizeLimits(100, 100000, 100, 100000);

	BRect r(Bounds());

	BMenuBar *mbar;
	AddChild(mbar = HResources::GetMenuBar(r, rid_Mbar_ProjectWin));
	mbar->FindItem(msg_Quit)->SetTarget(be_app);

	r.bottom = r.top + kToolBarHeight;
	r.OffsetBy(0, mbar->Bounds().bottom + 1);

	AddChild(fToolBar = new PToolBar(r, "toolbar"));

	r.bottom -= 2;
	r.OffsetTo(0, 0);

	fToolBar->AddChild(fButtonBar = new HButtonBar(r, "buttonbar", rid_Tbar_ProjectWin, this));

	r = Bounds();
	r.top = r.bottom - B_H_SCROLL_BAR_HEIGHT + 1;
	r.right -= B_V_SCROLL_BAR_WIDTH;
	AddChild(fStatus
		= new PGroupStatus(r, fDocIO->EntryRef() ? fDocIO->EntryRef()->name : NULL));

	r = Bounds();
	r.top = fToolBar->Frame().bottom;

	r.right -= B_V_SCROLL_BAR_WIDTH;
	r.bottom -= B_H_SCROLL_BAR_HEIGHT;
	fList = new PTypeAHeadList(r, "group", fStatus);
	fList->SetInvocationMessage(new BMessage(msg_PProjectItemInvoked));
	fList->SetSelectionMessage(new BMessage(msg_PProjectItemSelected));

	AddChild(new BScrollView("scroller", fList, B_FOLLOW_ALL_SIDES, 0, false, true, B_NO_BORDER));

	Read();

	NameChanged();
	SelectionChanged();
}
ScribbleWindow::ScribbleWindow() 
		: BWindow(BRect(100,100,300,400), "Scribble", B_TITLED_WINDOW, 0)
{
	BMenuBar *pMenuBar = new BMenuBar(BRect(), "Mainmenu");
	BMenu *pMenu = new BMenu("File");
	BMenuItem *pCloseItem = 
		new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'q');	
	pMenu->AddItem(pCloseItem);
	pMenuBar->AddItem(pMenu);
	
	AddChild(pMenuBar);

	float menuHeight = pMenuBar->Bounds().Height();

	ScribbleView *aView;
	// set up a rectangle and instantiate a new view
	BRect aRect( Bounds() );
	aRect.top = aRect.top+menuHeight+1;
	aView = new ScribbleView(aRect);
	// add view to window
	AddChild(aView);
}
void PictureTestWindow::BuildGUI()
{
	BView* backdrop = new BView(Bounds(), "backdrop", B_FOLLOW_ALL, B_WILL_DRAW);
	backdrop->SetViewColor(::ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(backdrop);
	
	BMenuBar* mb = new BMenuBar(Bounds(), "menubar");
	BMenu* m = new BMenu("File");
		m->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'));
		m->SetTargetForItems(be_app_messenger);
	mb->AddItem(m);

	m = new BMenu("Tests");
		m->AddItem(new BMenuItem("Run", new BMessage(kMsgRunTests), 'R'));
		m->AddItem(new BMenuItem("Run Color Space B_RGB32", new BMessage(kMsgRunTests1), 'S'));
	mb->AddItem(m);

	backdrop->AddChild(mb);

	BRect b = Bounds();
	b.top = mb->Bounds().bottom + 1;
	
	fHeader = new BStringView(b, "header", 
		"X", B_FOLLOW_LEFT | B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	float width, height;
	fHeader->GetPreferredSize(&width, &height);
	fHeader->ResizeTo(b.Width(), height);
	backdrop->AddChild(fHeader);
	b.top = fHeader->Frame().bottom + 1;
	
	b.right -= B_V_SCROLL_BAR_WIDTH;
	b.bottom -= B_H_SCROLL_BAR_HEIGHT;
	fListView = new BListView(b, "Results", B_SINGLE_SELECTION_LIST, 
		B_FOLLOW_ALL_SIDES, 
		B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE);
	backdrop->AddChild(new BScrollView("scroll_results", fListView, B_FOLLOW_ALL_SIDES, 0, true, true));	

	UpdateHeader();
}
Beispiel #6
0
ShortcutsWindow::ShortcutsWindow()
	:
	BWindow(BRect(WINDOW_START_X, WINDOW_START_Y, WINDOW_START_X + MIN_WIDTH, 
		WINDOW_START_Y + MIN_HEIGHT * 2), "Shortcuts", B_DOCUMENT_WINDOW, 0L), 
		fSavePanel(NULL), 
		fOpenPanel(NULL), 
		fSelectPanel(NULL), 
		fKeySetModified(false), 		
		fLastOpenWasAppend(false)
{
	InitializeMetaMaps();
	SetSizeLimits(MIN_WIDTH, MAX_WIDTH, MIN_HEIGHT, MAX_HEIGHT);
	BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "Menu Bar");

	BMenu* fileMenu = new BMenu("File");
	fileMenu->AddItem(new BMenuItem("Open KeySet...", 
		new BMessage(OPEN_KEYSET), 'O'));
	fileMenu->AddItem(new BMenuItem("Append KeySet...", 
		new BMessage(APPEND_KEYSET), 'A'));
	fileMenu->AddItem(new BMenuItem("Revert to saved", 
		new BMessage(REVERT_KEYSET), 'A'));
	fileMenu->AddItem(new BSeparatorItem);
	fileMenu->AddItem(new BMenuItem("Save KeySet as...", 
		new BMessage(SAVE_KEYSET_AS), 'S'));
	fileMenu->AddItem(new BSeparatorItem);
	fileMenu->AddItem(new BMenuItem("About Shortcuts",
		new BMessage(B_ABOUT_REQUESTED)));
	fileMenu->AddItem(new BSeparatorItem);
	fileMenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 
		'Q'));
	menuBar->AddItem(fileMenu);

	AddChild(menuBar);

	font_height fh;
	be_plain_font->GetHeight(&fh);
	float vButtonHeight = ceil(fh.ascent) + ceil(fh.descent) + 5.0f;

	BRect tableBounds = Bounds();
	tableBounds.top = menuBar->Bounds().bottom + 1;
	tableBounds.right -= B_V_SCROLL_BAR_WIDTH;
	tableBounds.bottom -= (B_H_SCROLL_BAR_HEIGHT + V_SPACING + vButtonHeight + 
		V_SPACING * 2);
	
	BScrollView* containerView;
	fColumnListView = new ColumnListView(tableBounds, &containerView, NULL, 
		B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE, 
		B_SINGLE_SELECTION_LIST, true, true, true, B_NO_BORDER);
	
	fColumnListView->SetEditMessage(new BMessage(HOTKEY_ITEM_MODIFIED), 
		BMessenger(this));
	
	const float metaWidth = 50.0f;

	for (int i = 0; i < ShortcutsSpec::NUM_META_COLUMNS; i++)
		fColumnListView->AddColumn(
			new CLVColumn(ShortcutsSpec::GetColumnName(i), CreateMetaPopUp(i), 
			metaWidth, CLV_SORT_KEYABLE));

	fColumnListView->AddColumn(new CLVColumn("Key", CreateKeysPopUp(), 60, 
		CLV_SORT_KEYABLE));

	BPopUpMenu* popup = new BPopUpMenu(NULL, false);
	popup->AddItem(new BMenuItem("(Choose application with file requester)", NULL));
	popup->AddItem(new BMenuItem("*InsertString \"Your Text Here\"", NULL));
	popup->AddItem(new BMenuItem("*MoveMouse +20 +0", NULL));
	popup->AddItem(new BMenuItem("*MoveMouseTo 50% 50%", NULL));
	popup->AddItem(new BMenuItem("*MouseButton 1", NULL));
	popup->AddItem(new BMenuItem("*LaunchHandler text/html", NULL));
	popup->AddItem(new BMenuItem(
		"*Multi \"*MoveMouseTo 100% 0\" \"*MouseButton 1\"", NULL));
	popup->AddItem(new BMenuItem("*MouseDown", NULL));
	popup->AddItem(new BMenuItem("*MouseUp", NULL));
	popup->AddItem(new BMenuItem(
		"*SendMessage application/x-vnd.Be-TRAK 'Tfnd'", NULL));
	popup->AddItem(new BMenuItem("*Beep", NULL));
	fColumnListView->AddColumn(new CLVColumn("Application", popup, 323.0, 
		CLV_SORT_KEYABLE));

	fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare);
	AddChild(containerView);

	fColumnListView->SetSelectionMessage(new BMessage(HOTKEY_ITEM_SELECTED));
	fColumnListView->SetTarget(this);

	BRect buttonBounds = Bounds();
	buttonBounds.left += V_SPACING;
	buttonBounds.right = ((buttonBounds.right - buttonBounds.left) / 2.0f) + 
		buttonBounds.left;
	buttonBounds.bottom -= V_SPACING * 2;
	buttonBounds.top = buttonBounds.bottom - vButtonHeight;
	buttonBounds.right -= B_V_SCROLL_BAR_WIDTH;
	float origRight = buttonBounds.right;
	buttonBounds.right = (buttonBounds.left + origRight) * 0.40f - 
		(V_SPACING / 2);
	AddChild(fAddButton = new ResizableButton(Bounds(), buttonBounds, "add", 
		"Add new shortcut", new BMessage(ADD_HOTKEY_ITEM)));
	buttonBounds.left = buttonBounds.right + V_SPACING;
	buttonBounds.right = origRight;
	AddChild(fRemoveButton = new ResizableButton(Bounds(), buttonBounds, 
		"remove", "Remove selected shortcut", 
		new BMessage(REMOVE_HOTKEY_ITEM)));
	
	fRemoveButton->SetEnabled(false);

	float offset = (buttonBounds.right - buttonBounds.left) / 2.0f;
	BRect saveButtonBounds = buttonBounds;
	saveButtonBounds.right = Bounds().right - B_V_SCROLL_BAR_WIDTH - offset;
	saveButtonBounds.left = buttonBounds.right + V_SPACING + offset;
	AddChild(fSaveButton = new ResizableButton(Bounds(), saveButtonBounds, 
		"save", "Save & apply", new BMessage(SAVE_KEYSET)));
	
	fSaveButton->SetEnabled(false);

	entry_ref ref;	
	if (_GetSettingsFile(&ref)) {
		BMessage msg(B_REFS_RECEIVED);
		msg.AddRef("refs", &ref);
		msg.AddString("startupRef", "please");
		PostMessage(&msg); // Tell ourself to load this file if it exists.
	}
	Show();
}
void
ImageView::SetImage(BMessage *pmsg)
{
	// Replace current image with the image
	// specified in the given BMessage

	entry_ref ref;
	if (!pmsg)
		ref = fcurrentRef;
	else if (pmsg->FindRef("refs", &ref) != B_OK)
		// If refs not found, just ignore the message
		return;

	StatusCheck chk;

	try {
		BFile file(&ref, B_READ_ONLY);
		chk = file.InitCheck();

		BTranslatorRoster roster, *proster;
		proster = SelectTranslatorRoster(roster);
		if (!proster)
			// throw exception
			chk = B_ERROR;
		// determine what type the image is
		translator_info tinfo;
		BMessage ioExtension;
		if (ref != fcurrentRef)
			// if new image, reset to first document
			fdocumentIndex = 1;
		chk = ioExtension.AddInt32("/documentIndex", fdocumentIndex);
		chk = proster->Identify(&file, &ioExtension, &tinfo, 0, NULL,
			B_TRANSLATOR_BITMAP);

		// perform the actual translation
		BBitmapStream outstream;
		chk = proster->Translate(&file, &tinfo, &ioExtension, &outstream,
			B_TRANSLATOR_BITMAP);
		BBitmap *pbitmap = NULL;
		chk = outstream.DetachBitmap(&pbitmap);
		delete fpbitmap;
		fpbitmap = pbitmap;
		pbitmap = NULL;
		fcurrentRef = ref;
			// need to keep the ref around if user wants to switch pages
		int32 documentCount = 0;
		if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK &&
			documentCount > 0)
			fdocumentCount = documentCount;
		else
			fdocumentCount = 1;

		// Set the name of the Window to reflect the file name
		BWindow *pwin = Window();
		BEntry entry(&ref);
		BPath path;
		if (entry.InitCheck() == B_OK) {
			if (path.SetTo(&entry) == B_OK)
				pwin->SetTitle(path.Leaf());
			else
				pwin->SetTitle(IMAGEWINDOW_TITLE);
		} else
			pwin->SetTitle(IMAGEWINDOW_TITLE);
		UpdateInfoWindow(path, ioExtension, tinfo, proster);

		// Resize parent window and set size limits to
		// reflect the size of the new bitmap
		float width, height;
		BMenuBar *pbar = pwin->KeyMenuBar();
		width = fpbitmap->Bounds().Width() + B_V_SCROLL_BAR_WIDTH + (BORDER_WIDTH * 2);
		height = fpbitmap->Bounds().Height() +
			pbar->Bounds().Height() + B_H_SCROLL_BAR_HEIGHT + (BORDER_HEIGHT * 2) + 1;
		BScreen *pscreen = new BScreen(pwin);
		BRect rctscreen = pscreen->Frame();
		if (width > rctscreen.Width())
			width = rctscreen.Width();
		if (height > rctscreen.Height())
			height = rctscreen.Height();
		pwin->SetSizeLimits(B_V_SCROLL_BAR_WIDTH * 4, width,
			pbar->Bounds().Height() + (B_H_SCROLL_BAR_HEIGHT * 4) + 1, height);
		pwin->SetZoomLimits(width, height);
		AdjustScrollBars();

		//pwin->Zoom();
			// Perform all of the hard work of resizing the
			// window while taking into account the size of
			// the screen, the tab and borders of the window
			//
			// HACK: Need to fix case where window un-zooms
			// when the window is already the correct size
			// for the current image

		// repaint view
		Invalidate();

	} catch (StatusNotOKException) {
		BAlert *palert = new BAlert(NULL,
			B_TRANSLATE("Sorry, unable to load the image."),
			B_TRANSLATE("OK"));
		palert->Go();
	}
}
ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry)
	: BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position),
		"Application Type", B_TITLED_WINDOW,
		B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
	fChangedProperties(0)
{
	// add the menu

	BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
	AddChild(menuBar);

	BMenu* menu = new BMenu("File");
	fSaveMenuItem = new BMenuItem("Save", new BMessage(kMsgSave), 'S');
	fSaveMenuItem->SetEnabled(false);
	menu->AddItem(fSaveMenuItem);
	BMenuItem* item;
	menu->AddItem(item = new BMenuItem("Save into resource file" B_UTF8_ELLIPSIS,
		NULL));
	item->SetEnabled(false);

	menu->AddSeparatorItem();
	menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED),
		'W', B_COMMAND_KEY));
	menuBar->AddItem(menu);

	// Top view and signature

	BRect rect = Bounds();
	rect.top = menuBar->Bounds().Height() + 1.0f;
	BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(topView);

	rect = topView->Bounds().InsetByCopy(8.0f, 8.0f);
	fSignatureControl = new BTextControl(rect, "signature", "Signature:", NULL,
		new BMessage(kMsgSignatureChanged), B_FOLLOW_LEFT_RIGHT);
	fSignatureControl->SetModificationMessage(
		new BMessage(kMsgSignatureChanged));
	fSignatureControl->SetDivider(fSignatureControl->StringWidth(
		fSignatureControl->Label()) + 4.0f);
	float width, height;
	fSignatureControl->GetPreferredSize(&width, &height);
	fSignatureControl->ResizeTo(rect.Width(), height);
	topView->AddChild(fSignatureControl);

	// filter out invalid characters that can't be part of a MIME type name
	BTextView* textView = fSignatureControl->TextView();
	textView->SetMaxBytes(B_MIME_TYPE_LENGTH);
	const char* disallowedCharacters = "<>@,;:\"()[]?=";
	for (int32 i = 0; disallowedCharacters[i]; i++) {
		textView->DisallowChar(disallowedCharacters[i]);
	}

	// "Application Flags" group

	BFont font(be_bold_font);
	font_height fontHeight;
	font.GetHeight(&fontHeight);

	width = font.StringWidth("Icon") + 16.0f;
	if (width < B_LARGE_ICON + 16.0f)
		width = B_LARGE_ICON + 16.0f;

	rect.top = fSignatureControl->Frame().bottom + 4.0f;
	rect.bottom = rect.top + 100.0f;
	rect.right -= width + 8.0f;
	BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
	topView->AddChild(box);

	fFlagsCheckBox = new BCheckBox(rect, "flags", "Application flags",
		new BMessage(kMsgToggleAppFlags));
	fFlagsCheckBox->SetValue(B_CONTROL_ON);
	fFlagsCheckBox->ResizeToPreferred();
	box->SetLabel(fFlagsCheckBox);

	rect.top = fFlagsCheckBox->Bounds().Height() + 4.0f;
	fSingleLaunchButton = new BRadioButton(rect, "single", "Single launch",
		new BMessage(kMsgAppFlagsChanged));
	fSingleLaunchButton->ResizeToPreferred();
	box->AddChild(fSingleLaunchButton);

	rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f);
	fMultipleLaunchButton = new BRadioButton(rect, "multiple",
		"Multiple launch", new BMessage(kMsgAppFlagsChanged));
	fMultipleLaunchButton->ResizeToPreferred();
	box->AddChild(fMultipleLaunchButton);

	rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f);
	fExclusiveLaunchButton = new BRadioButton(rect, "exclusive",
		"Exclusive launch", new BMessage(kMsgAppFlagsChanged));
	fExclusiveLaunchButton->ResizeToPreferred();
	box->AddChild(fExclusiveLaunchButton);

	rect.top = fSingleLaunchButton->Frame().top;
	rect.left = fExclusiveLaunchButton->Frame().right + 4.0f;
	fArgsOnlyCheckBox = new BCheckBox(rect, "args only", "Args only",
		new BMessage(kMsgAppFlagsChanged));
	fArgsOnlyCheckBox->ResizeToPreferred();
	box->AddChild(fArgsOnlyCheckBox);

	rect.top += fArgsOnlyCheckBox->Bounds().Height();
	fBackgroundAppCheckBox = new BCheckBox(rect, "background",
		"Background app", new BMessage(kMsgAppFlagsChanged));
	fBackgroundAppCheckBox->ResizeToPreferred();
	box->AddChild(fBackgroundAppCheckBox);

	box->ResizeTo(box->Bounds().Width(),
		fExclusiveLaunchButton->Frame().bottom + 8.0f);

	// "Icon" group

	rect = box->Frame();
#ifdef __ANTARES__
	rect.top += box->TopBorderOffset();
#endif
	rect.left = rect.right + 8.0f;
	rect.right += width + 8.0f;
	float iconBoxWidth = rect.Width();
	box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	box->SetLabel("Icon");
#ifdef __ANTARES__
	box->MoveBy(0.0f, -box->TopBorderOffset());
	box->ResizeBy(0.0f, box->TopBorderOffset());
#endif
	topView->AddChild(box);

	rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f);
#ifdef __ANTARES__
	rect.OffsetBy(0.0f, (box->Bounds().Height() + box->TopBorderOffset()
		- rect.Height()) / 2.0f);
#else
	rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f);
#endif
	if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f)
		rect.top = fontHeight.ascent + fontHeight.descent + 4.0f;
	fIconView = new IconView(rect, "icon");
	fIconView->SetModificationMessage(new BMessage(kMsgIconChanged));
	box->AddChild(fIconView);

	// "Supported Types" group

	rect.top = box->Frame().bottom + 8.0f;
	rect.bottom = rect.top + box->Bounds().Height();
	rect.left = 8.0f;
	rect.right = Bounds().Width() - 8.0f;
	BBox* typeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
	typeBox->SetLabel("Supported types");
	topView->AddChild(typeBox);

	rect = typeBox->Bounds().InsetByCopy(8.0f, 6.0f);
	rect.top += ceilf(fontHeight.ascent);
	fAddTypeButton = new BButton(rect, "add type", "Add" B_UTF8_ELLIPSIS,
		new BMessage(kMsgAddType), B_FOLLOW_RIGHT);
	fAddTypeButton->ResizeToPreferred();
	fAddTypeButton->MoveBy(rect.right - fAddTypeButton->Bounds().Width()
		- B_LARGE_ICON - 16.0f, 0.0f);
	typeBox->AddChild(fAddTypeButton);

	rect = fAddTypeButton->Frame();
	rect.OffsetBy(0, rect.Height() + 4.0f);
	fRemoveTypeButton = new BButton(rect, "remove type", "Remove",
		new BMessage(kMsgRemoveType), B_FOLLOW_RIGHT);
	typeBox->AddChild(fRemoveTypeButton);

	rect.right = rect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
	rect.left = 10.0f;
	rect.top = 8.0f + ceilf(fontHeight.ascent);
	rect.bottom -= 2.0f;
		// take scrollview border into account
	fTypeListView = new SupportedTypeListView(rect, "type listview",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL);
	fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));

	BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView,
		B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true);

	typeBox->ResizeTo(typeBox->Bounds().Width(), fRemoveTypeButton->Frame().bottom + 8.0f);
	typeBox->AddChild(scrollView);

	rect.left = fRemoveTypeButton->Frame().right + 8.0f;
#ifdef __ANTARES__
	rect.top = (box->Bounds().Height() + box->TopBorderOffset() - B_LARGE_ICON) / 2.0f;
#else
	rect.top = (box->Bounds().Height() - B_LARGE_ICON) / 2.0f;
#endif
	rect.right = rect.left + B_LARGE_ICON - 1.0f;
	rect.bottom = rect.top + B_LARGE_ICON - 1.0f;
	fTypeIconView = new IconView(rect, "type icon", B_FOLLOW_RIGHT | B_FOLLOW_TOP);
	fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged));
	typeBox->AddChild(fTypeIconView);

	// "Version Info" group

	rect.top = typeBox->Frame().bottom + 8.0f;
	rect.bottom = rect.top + typeBox->Bounds().Height();
	rect.left = 8.0f;
	rect.right = Bounds().Width() - 8.0f;
	box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
		// the resizing mode will later also be set to B_FOLLOW_BOTTOM
	box->SetLabel("Version info");
	topView->AddChild(box);

	BMenuField* menuField;
#if 0
	BPopUpMenu *popUpMenu = new BPopUpMenu("version info", true, true);
	item = new BMenuItem("Version Info", NULL);
	item->SetMarked(true);
	popUpMenu->AddItem(item);
	item = new BMenuItem("System Version Info", NULL);
	popUpMenu->AddItem(item);

	menuField = new BMenuField(BRect(0, 0, 100, 15),
		"version kind", NULL, popUpMenu, true);
	menuField->ResizeToPreferred();
	box->SetLabel(menuField);
#endif

	rect.top = 4.0f + ceilf(fontHeight.ascent + fontHeight.descent);
	rect.bottom = rect.top + height;
	fMajorVersionControl = new BTextControl(rect, "major", "Version:", NULL,
		NULL);
	fMajorVersionControl->SetDivider(fMajorVersionControl->StringWidth(
		fMajorVersionControl->Label()) + 4.0f);
	fMajorVersionControl->GetPreferredSize(&width, &height);
	width = 12.0f + fMajorVersionControl->StringWidth("99");
	fMajorVersionControl->ResizeTo(fMajorVersionControl->Divider() + width, height);
	_MakeNumberTextControl(fMajorVersionControl);
	box->AddChild(fMajorVersionControl);

	rect.left = fMajorVersionControl->Frame().right + 1.0f;
	fMiddleVersionControl = new BTextControl(rect, "middle", ".", NULL,
		NULL);
	fMiddleVersionControl->SetDivider(fMiddleVersionControl->StringWidth(
		fMiddleVersionControl->Label()) + 4.0f);
	fMiddleVersionControl->ResizeTo(fMiddleVersionControl->Divider() + width, height);
	_MakeNumberTextControl(fMiddleVersionControl);
	box->AddChild(fMiddleVersionControl);

	rect.left = fMiddleVersionControl->Frame().right + 1.0f;
	fMinorVersionControl = new BTextControl(rect, "middle", ".", NULL,
		NULL);
	fMinorVersionControl->SetDivider(fMinorVersionControl->StringWidth(
		fMinorVersionControl->Label()) + 4.0f);
	fMinorVersionControl->ResizeTo(fMinorVersionControl->Divider() + width, height);
	_MakeNumberTextControl(fMinorVersionControl);
	box->AddChild(fMinorVersionControl);

	fVarietyMenu = new BPopUpMenu("variety", true, true);
	fVarietyMenu->AddItem(new BMenuItem("Development", NULL));
	fVarietyMenu->AddItem(new BMenuItem("Alpha", NULL));
	fVarietyMenu->AddItem(new BMenuItem("Beta", NULL));
	fVarietyMenu->AddItem(new BMenuItem("Gamma", NULL));
	fVarietyMenu->AddItem(item = new BMenuItem("Golden master", NULL));
	item->SetMarked(true);
	fVarietyMenu->AddItem(new BMenuItem("Final", NULL));

	rect.top--;
		// BMenuField oddity
	rect.left = fMinorVersionControl->Frame().right + 6.0f;
	menuField = new BMenuField(rect,
		"variety", NULL, fVarietyMenu, true);
	menuField->ResizeToPreferred();
	box->AddChild(menuField);

	rect.top++;
	rect.left = menuField->Frame().right;
	rect.right = rect.left + 30.0f;	
	fInternalVersionControl = new BTextControl(rect, "internal", "/", NULL,
		NULL);
	fInternalVersionControl->SetDivider(fInternalVersionControl->StringWidth(
		fInternalVersionControl->Label()) + 4.0f);
	fInternalVersionControl->ResizeTo(fInternalVersionControl->Divider() + width, height);
	box->AddChild(fInternalVersionControl);

	rect = box->Bounds().InsetByCopy(8.0f, 0.0f);
	rect.top = fInternalVersionControl->Frame().bottom + 8.0f;
	fShortDescriptionControl = new BTextControl(rect, "short desc", "Short description:",
		NULL, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	float labelWidth = fShortDescriptionControl->StringWidth(
		fShortDescriptionControl->Label()) + 4.0f;
	fShortDescriptionControl->SetDivider(labelWidth);
	fShortDescriptionControl->GetPreferredSize(&width, &height);
	fShortDescriptionControl->ResizeTo(rect.Width(), height);

	// TODO: workaround for a GCC 4.1.0 bug? Or is that really what the standard says?
	version_info versionInfo;
	fShortDescriptionControl->TextView()->SetMaxBytes(sizeof(versionInfo.short_info));
	box->AddChild(fShortDescriptionControl);

	rect.OffsetBy(0.0f, fShortDescriptionControl->Bounds().Height() + 5.0f);
	rect.right = rect.left + labelWidth;
	StringView* label = new StringView(rect, NULL, "Long description:", NULL);
	label->SetDivider(labelWidth);
	box->AddChild(label);

	rect.left = rect.right + 3.0f;
	rect.top += 1.0f;
	rect.right = box->Bounds().Width() - 10.0f - B_V_SCROLL_BAR_WIDTH;
	rect.bottom = rect.top + fShortDescriptionControl->Bounds().Height() * 3.0f - 1.0f;
	fLongDescriptionView = new TabFilteringTextView(rect, "long desc",
		rect.OffsetToCopy(B_ORIGIN), B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS
		| B_NAVIGABLE);
	fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info));

	scrollView = new BScrollView("desc scrollview", fLongDescriptionView,
		B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
	box->ResizeTo(box->Bounds().Width(), scrollView->Frame().bottom + 8.0f);
	box->AddChild(scrollView);

	// Adjust window size and limits

	width = fInternalVersionControl->Frame().right + 16.0f;
	float minWidth = fBackgroundAppCheckBox->Frame().right + iconBoxWidth + 32.0f;
	if (width > minWidth)
		minWidth = width;

	ResizeTo(Bounds().Width() > minWidth ? Bounds().Width() : minWidth,
		box->Frame().bottom + topView->Frame().top + 8.0f);
	SetSizeLimits(minWidth, 32767.0f, Bounds().Height(), 32767.0f);
	typeBox->SetResizingMode(B_FOLLOW_ALL);
	box->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);

	fSignatureControl->MakeFocus(true);

	BMimeType::StartWatching(this);
	_SetTo(entry);
}
Beispiel #9
0
FileTypesWindow::FileTypesWindow(const BMessage& settings)
	: BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW,
		B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS),
	fNewTypeWindow(NULL)
{
	bool showIcons;
	bool showRule;
	if (settings.FindBool("show_icons", &showIcons) != B_OK)
		showIcons = true;
	if (settings.FindBool("show_rule", &showRule) != B_OK)
		showRule = false;

	// add the menu

	BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL);
	AddChild(menuBar);

	BMenu* menu = new BMenu("File");
	BMenuItem* item;
	menu->AddItem(item = new BMenuItem("New resource file" B_UTF8_ELLIPSIS,
		NULL, 'N', B_COMMAND_KEY));
	item->SetEnabled(false);

	BMenu* recentsMenu = BRecentFilesList::NewFileListMenu("Open" B_UTF8_ELLIPSIS,
		NULL, NULL, be_app, 10, false, NULL, kSignature);
	item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel));
	item->SetShortcut('O', B_COMMAND_KEY);
	menu->AddItem(item);
	menu->AddItem(new BMenuItem("Application types" B_UTF8_ELLIPSIS,
		new BMessage(kMsgOpenApplicationTypesWindow)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem("About FileTypes" B_UTF8_ELLIPSIS,
		new BMessage(B_ABOUT_REQUESTED)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
		'Q', B_COMMAND_KEY));
	menu->SetTargetForItems(be_app);
	menuBar->AddItem(menu);

	menu = new BMenu("Settings");
	item = new BMenuItem("Show icons in list", new BMessage(kMsgToggleIcons));
	item->SetMarked(showIcons);
	item->SetTarget(this);
	menu->AddItem(item);

	item = new BMenuItem("Show recognition rule", new BMessage(kMsgToggleRule));
	item->SetMarked(showRule);
	item->SetTarget(this);
	menu->AddItem(item);
	menuBar->AddItem(menu);

	// MIME Types list

	BRect rect = Bounds();
	rect.top = menuBar->Bounds().Height() + 1.0f;
	BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW);
	topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(topView);

	BButton* button = new BButton(rect, "add", "Add" B_UTF8_ELLIPSIS,
		new BMessage(kMsgAddType), B_FOLLOW_BOTTOM);
	button->ResizeToPreferred();
	button->MoveTo(8.0f, topView->Bounds().bottom - 8.0f - button->Bounds().Height());
	topView->AddChild(button);

	rect = button->Frame();
	rect.OffsetBy(rect.Width() + 8.0f, 0.0f);
	fRemoveTypeButton = new BButton(rect, "remove", "Remove",
		new BMessage(kMsgRemoveType), B_FOLLOW_BOTTOM);
	fRemoveTypeButton->ResizeToPreferred();
	topView->AddChild(fRemoveTypeButton);

	rect.bottom = rect.top - 10.0f;
	rect.top = 10.0f;
	rect.left = 10.0f;
	rect.right -= B_V_SCROLL_BAR_WIDTH + 2.0f;
	if (rect.right < 180)
		rect.right = 180;

	fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false,
		B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
	fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));

	BScrollView* scrollView = new BScrollView("scrollview", fTypeListView,
		B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
	topView->AddChild(scrollView);

	// "Icon" group

	font_height plainHeight;
	be_plain_font->GetHeight(&plainHeight);
	float height = ceilf(plainHeight.ascent + plainHeight.descent
		+ plainHeight.leading) + 2.0f;

	BFont font(be_bold_font);
	float labelWidth = font.StringWidth("Icon");
	font_height boldHeight;
	font.GetHeight(&boldHeight);

	BRect innerRect;
	fIconView = new TypeIconView(innerRect, "icon",
		B_FOLLOW_LEFT | B_FOLLOW_V_CENTER);
	fIconView->ResizeToPreferred();

	rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH;
	rect.right = rect.left + max_c(fIconView->Bounds().Width(), labelWidth) + 16.0f;
	rect.bottom = rect.top + ceilf(boldHeight.ascent)
		+ max_c(fIconView->Bounds().Height(),
			button->Bounds().Height() * 2.0f + height + 4.0f) + 12.0f;
	rect.top -= 2.0f;
	fIconBox = new BBox(rect);
	fIconBox->SetLabel("Icon");
	topView->AddChild(fIconBox);

	innerRect.left = 8.0f;
	innerRect.top = plainHeight.ascent + 3.0f
		+ (rect.Height() - boldHeight.ascent - fIconView->Bounds().Height()) / 2.0f;
	if (innerRect.top + fIconView->Bounds().Height() > fIconBox->Bounds().Height() - 6.0f)
		innerRect.top = fIconBox->Bounds().Height() - 6.0f - fIconView->Bounds().Height();
	fIconView->MoveTo(innerRect.LeftTop());
	fIconBox->AddChild(fIconView);

	// "File Recognition" group

	BRect rightRect(rect);
	rightRect.left = rect.right + 8.0f;
	rightRect.right = topView->Bounds().Width() - 8.0f;
	fRecognitionBox = new BBox(rightRect, NULL, B_FOLLOW_LEFT_RIGHT);
	fRecognitionBox->SetLabel("File recognition");
	topView->AddChild(fRecognitionBox);

	innerRect = fRecognitionBox->Bounds().InsetByCopy(8.0f, 4.0f);
	innerRect.top += ceilf(boldHeight.ascent);
	fExtensionLabel = new StringView(innerRect, "extension", "Extensions:", NULL);
	fExtensionLabel->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT);
	fExtensionLabel->ResizeToPreferred();
	fRecognitionBox->AddChild(fExtensionLabel);

	innerRect.top += fExtensionLabel->Bounds().Height() + 2.0f;
	innerRect.left = innerRect.right - button->StringWidth("Remove") - 16.0f;
	innerRect.bottom = innerRect.top + button->Bounds().Height();
	fAddExtensionButton = new BButton(innerRect, "add ext", "Add" B_UTF8_ELLIPSIS,
		new BMessage(kMsgAddExtension), B_FOLLOW_RIGHT);
	fRecognitionBox->AddChild(fAddExtensionButton);

	innerRect.OffsetBy(0, innerRect.Height() + 4.0f);
	fRemoveExtensionButton = new BButton(innerRect, "remove ext", "Remove",
		new BMessage(kMsgRemoveExtension), B_FOLLOW_RIGHT);
	fRecognitionBox->AddChild(fRemoveExtensionButton);

	innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
	innerRect.left = 10.0f;
	innerRect.top = fAddExtensionButton->Frame().top + 2.0f;
	innerRect.bottom = innerRect.bottom - 2.0f;
		// take scrollview border into account
	fExtensionListView = new ExtensionListView(innerRect, "listview ext",
		B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT_RIGHT);
	fExtensionListView->SetSelectionMessage(new BMessage(kMsgExtensionSelected));
	fExtensionListView->SetInvocationMessage(new BMessage(kMsgExtensionInvoked));

	scrollView = new BScrollView("scrollview ext", fExtensionListView,
		B_FOLLOW_LEFT_RIGHT, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
	fRecognitionBox->AddChild(scrollView);

	innerRect.left = 8.0f;
	innerRect.top = innerRect.bottom + 10.0f;
	innerRect.right = fRecognitionBox->Bounds().right - 8.0f;
	innerRect.bottom = innerRect.top + 20.0f;
	fRuleControl = new BTextControl(innerRect, "rule", "Rule:", "",
		new BMessage(kMsgRuleEntered), B_FOLLOW_LEFT_RIGHT);
	//fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
	fRuleControl->SetDivider(fRuleControl->StringWidth(fRuleControl->Label()) + 6.0f);
	fRuleControl->Hide();
	fRecognitionBox->AddChild(fRuleControl);

	// "Description" group

	rect.top = rect.bottom + 8.0f;
	rect.bottom = rect.top + ceilf(boldHeight.ascent) + 24.0f;
	rect.right = rightRect.right;
	fDescriptionBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
	fDescriptionBox->SetLabel("Description");
	topView->AddChild(fDescriptionBox);

	innerRect = fDescriptionBox->Bounds().InsetByCopy(8.0f, 6.0f);
	innerRect.top += ceilf(boldHeight.ascent);
	innerRect.bottom = innerRect.top + button->Bounds().Height();
	fInternalNameView = new StringView(innerRect, "internal", "Internal name:", "",
		B_FOLLOW_LEFT_RIGHT);
	labelWidth = fInternalNameView->StringWidth(fInternalNameView->Label()) + 2.0f;
	fInternalNameView->SetDivider(labelWidth);
	fInternalNameView->SetEnabled(false);
	fInternalNameView->ResizeToPreferred();
	fDescriptionBox->AddChild(fInternalNameView);

	innerRect.OffsetBy(0, fInternalNameView->Bounds().Height() + 5.0f);
	fTypeNameControl = new BTextControl(innerRect, "type", "Type name:", "",
		new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT);
	fTypeNameControl->SetDivider(labelWidth);
	fTypeNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
	fDescriptionBox->ResizeBy(0, fInternalNameView->Bounds().Height()
		+ fTypeNameControl->Bounds().Height() * 2.0f);
	fDescriptionBox->AddChild(fTypeNameControl);

	innerRect.OffsetBy(0, fTypeNameControl->Bounds().Height() + 5.0f);
	fDescriptionControl = new BTextControl(innerRect, "description", "Description:", "",
		new BMessage(kMsgDescriptionEntered), B_FOLLOW_LEFT_RIGHT);
	fDescriptionControl->SetDivider(labelWidth);
	fDescriptionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);
	fDescriptionBox->AddChild(fDescriptionControl);

	// "Preferred Application" group

	rect = fDescriptionBox->Frame();
	rect.top = rect.bottom + 8.0f;
	rect.bottom = rect.top + ceilf(boldHeight.ascent)
		+ button->Bounds().Height() + 14.0f;
	fPreferredBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT);
	fPreferredBox->SetLabel("Preferred application");
	topView->AddChild(fPreferredBox);

	innerRect = fPreferredBox->Bounds().InsetByCopy(8.0f, 6.0f);
	innerRect.top += ceilf(boldHeight.ascent);
	innerRect.left = innerRect.right - button->StringWidth(
		"Same as" B_UTF8_ELLIPSIS) - 24.0f;
	innerRect.bottom = innerRect.top + button->Bounds().Height();
	fSameAsButton = new BButton(innerRect, "same as",
		"Same as" B_UTF8_ELLIPSIS,
		new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_RIGHT);
	fPreferredBox->AddChild(fSameAsButton);

	innerRect.OffsetBy(-innerRect.Width() - 6.0f, 0.0f);
	fSelectButton = new BButton(innerRect, "select", "Select" B_UTF8_ELLIPSIS,
		new BMessage(kMsgSelectPreferredApp), B_FOLLOW_RIGHT);
	fPreferredBox->AddChild(fSelectButton);

	menu = new BPopUpMenu("preferred");
	menu->AddItem(item = new BMenuItem("None",
		new BMessage(kMsgPreferredAppChosen)));
	item->SetMarked(true);

	innerRect.right = innerRect.left - 6.0f;
	innerRect.left = 8.0f;

	fPreferredField = new BMenuField(innerRect, "preferred", NULL, menu, true,
		B_FOLLOW_LEFT_RIGHT);
	float width;
	fPreferredField->GetPreferredSize(&width, &height);
	fPreferredField->ResizeTo(innerRect.Width(), height);
	fPreferredField->MoveBy(0.0f, (innerRect.Height() - height) / 2.0f);

	fPreferredBox->AddChild(fPreferredField);

	// "Extra Attributes" group

	rect.top = rect.bottom + 8.0f;
	rect.bottom = topView->Bounds().Height() - 8.0f;
	fAttributeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT
		| B_FOLLOW_TOP_BOTTOM);
	fAttributeBox->SetLabel("Extra attributes");
	topView->AddChild(fAttributeBox);

	innerRect = fAttributeBox->Bounds().InsetByCopy(8.0f, 6.0f);
	innerRect.top += ceilf(boldHeight.ascent);
	innerRect.left = innerRect.right - button->StringWidth("Remove") - 16.0f;
	innerRect.bottom = innerRect.top + button->Bounds().Height();
	fAddAttributeButton = new BButton(innerRect, "add attr",
		"Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddAttribute), B_FOLLOW_RIGHT);
	fAttributeBox->AddChild(fAddAttributeButton);

	innerRect.OffsetBy(0, innerRect.Height() + 4.0f);
	fRemoveAttributeButton = new BButton(innerRect, "remove attr", "Remove",
		new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT);
	fAttributeBox->AddChild(fRemoveAttributeButton);
/*
	innerRect.OffsetBy(0, innerRect.Height() + 4.0f);
	button = new BButton(innerRect, "push attr", "Push Up",
		new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT);
	fAttributeBox->AddChild(button);
*/
	innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
	innerRect.left = 10.0f;
	innerRect.top = 8.0f + ceilf(boldHeight.ascent);
	innerRect.bottom = fAttributeBox->Bounds().bottom - 10.0f;
		// take scrollview border into account
	fAttributeListView = new AttributeListView(innerRect, "listview attr",
		B_FOLLOW_ALL);
	fAttributeListView->SetSelectionMessage(new BMessage(kMsgAttributeSelected));
	fAttributeListView->SetInvocationMessage(new BMessage(kMsgAttributeInvoked));

	scrollView = new BScrollView("scrollview attr", fAttributeListView,
		B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true);
	fAttributeBox->AddChild(scrollView);

	SetSizeLimits(rightRect.left + 72.0f + font.StringWidth("jpg")
		+ font.StringWidth(fRecognitionBox->Label()), 32767.0f,
		rect.top + 2.0f * button->Bounds().Height() + boldHeight.ascent
		+ 32.0f + menuBar->Bounds().Height(), 32767.0f);

	_SetType(NULL);
	_ShowSnifferRule(showRule);

	BMimeType::StartWatching(this);
}
ShortcutsWindow::ShortcutsWindow()
	:
	BWindow(BRect(0, 0, 0, 0), B_TRANSLATE_SYSTEM_NAME("Shortcuts"),
		B_TITLED_WINDOW, 0L),
	fSavePanel(NULL), 
	fOpenPanel(NULL), 
	fSelectPanel(NULL), 
	fKeySetModified(false), 		
	fLastOpenWasAppend(false)
{
	ShortcutsSpec::InitializeMetaMaps();
	
	float spacing = be_control_look->DefaultItemSpacing();

	BView* top = new BView(Bounds(), NULL, B_FOLLOW_ALL_SIDES, 0);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(top);

	BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), "Menu Bar");

	BMenu* fileMenu = new BMenu(B_TRANSLATE("File"));
	fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Open KeySet" B_UTF8_ELLIPSIS),
		new BMessage(OPEN_KEYSET), 'O'));
	fileMenu->AddItem(new BMenuItem(
		B_TRANSLATE("Append KeySet" B_UTF8_ELLIPSIS),
		new BMessage(APPEND_KEYSET), 'A'));
	fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Revert to saved"),
		new BMessage(REVERT_KEYSET), 'A'));
	fileMenu->AddItem(new BSeparatorItem);
	fileMenu->AddItem(new BMenuItem(
		B_TRANSLATE("Save KeySet as" B_UTF8_ELLIPSIS),
		new BMessage(SAVE_KEYSET_AS), 'S'));
	fileMenu->AddItem(new BSeparatorItem);
	fileMenu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menuBar->AddItem(fileMenu);

	top->AddChild(menuBar);

	BRect tableBounds = Bounds();
	tableBounds.top = menuBar->Bounds().bottom + 1;
	tableBounds.right -= B_V_SCROLL_BAR_WIDTH;
	tableBounds.bottom -= B_H_SCROLL_BAR_HEIGHT;

	BScrollView* containerView;
	fColumnListView = new ColumnListView(tableBounds, &containerView, NULL,
		B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE,
		B_SINGLE_SELECTION_LIST, true, true, true, B_NO_BORDER);

	fColumnListView->SetEditMessage(new BMessage(HOTKEY_ITEM_MODIFIED),
		BMessenger(this));

	float minListWidth = 0;
		// A running total is kept as the columns are created.
	float cellWidth = be_plain_font->StringWidth("Either") + 20;
		// ShortcutsSpec does not seem to translate the string "Either".

	for (int i = 0; i < ShortcutsSpec::NUM_META_COLUMNS; i++) {
		const char* name = ShortcutsSpec::GetColumnName(i);
		float headerWidth = be_plain_font->StringWidth(name) + 20;
		float width = max_c(headerWidth, cellWidth);
		minListWidth += width + 1;

		fColumnListView->AddColumn(
			new CLVColumn(name, CreateMetaPopUp(i), width, CLV_SORT_KEYABLE));
	}

	float keyCellWidth = be_plain_font->StringWidth("Caps Lock") + 20;
	fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Key"),
		CreateKeysPopUp(), keyCellWidth, CLV_SORT_KEYABLE));
	minListWidth += keyCellWidth + 1;

	BPopUpMenu* popup = new BPopUpMenu(NULL, false);
	popup->AddItem(new BMenuItem(
		B_TRANSLATE("(Choose application with file requester)"), NULL));
	popup->AddItem(new BMenuItem(
		B_TRANSLATE("*InsertString \"Your Text Here\""), NULL));
	popup->AddItem(new BMenuItem(
		B_TRANSLATE("*MoveMouse +20 +0"), NULL));
	popup->AddItem(new BMenuItem(B_TRANSLATE("*MoveMouseTo 50% 50%"), NULL));
	popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseButton 1"), NULL));
	popup->AddItem(new BMenuItem(
		B_TRANSLATE("*LaunchHandler text/html"), NULL));
	popup->AddItem(new BMenuItem(
		B_TRANSLATE("*Multi \"*MoveMouseTo 100% 0\" \"*MouseButton 1\""),
		NULL));
	popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseDown"), NULL));
	popup->AddItem(new BMenuItem(B_TRANSLATE("*MouseUp"), NULL));
	popup->AddItem(new BMenuItem(
		B_TRANSLATE("*SendMessage application/x-vnd.Be-TRAK 'Tfnd'"), NULL));
	popup->AddItem(new BMenuItem(B_TRANSLATE("*Beep"), NULL));
	fColumnListView->AddColumn(new CLVColumn(B_TRANSLATE("Application"), popup,
		323.0, CLV_SORT_KEYABLE));
	minListWidth += 323.0 + 1;
	minListWidth += B_V_SCROLL_BAR_WIDTH;

	fColumnListView->SetSortFunction(ShortcutsSpec::MyCompare);
	top->AddChild(containerView);

	fColumnListView->SetSelectionMessage(new BMessage(HOTKEY_ITEM_SELECTED));
	fColumnListView->SetTarget(this);

	fAddButton = new BButton(BRect(0, 0, 0, 0), "add",
		B_TRANSLATE("Add new shortcut"), new BMessage(ADD_HOTKEY_ITEM),
		B_FOLLOW_BOTTOM);
	fAddButton->ResizeToPreferred();
	fAddButton->MoveBy(spacing,
		Bounds().bottom - fAddButton->Bounds().bottom - spacing);
	top->AddChild(fAddButton);

	fRemoveButton = new BButton(BRect(0, 0, 0, 0), "remove",
		B_TRANSLATE("Remove selected shortcut"),
		new BMessage(REMOVE_HOTKEY_ITEM), B_FOLLOW_BOTTOM);
	fRemoveButton->ResizeToPreferred();
	fRemoveButton->MoveBy(fAddButton->Frame().right + spacing,
		Bounds().bottom - fRemoveButton->Bounds().bottom - spacing);
	top->AddChild(fRemoveButton);

	fRemoveButton->SetEnabled(false);

	fSaveButton = new BButton(BRect(0, 0, 0, 0), "save",
		B_TRANSLATE("Save & apply"), new BMessage(SAVE_KEYSET),
		B_FOLLOW_BOTTOM | B_FOLLOW_RIGHT);
	fSaveButton->ResizeToPreferred();
	fSaveButton->MoveBy(Bounds().right - fSaveButton->Bounds().right - spacing,
		Bounds().bottom - fSaveButton->Bounds().bottom - spacing);
	top->AddChild(fSaveButton);

	fSaveButton->SetEnabled(false);

	containerView->ResizeBy(0,
		-(fAddButton->Bounds().bottom + 2 * spacing + 2));

	float minButtonBarWidth = fRemoveButton->Frame().right
		+ fSaveButton->Bounds().right + 2 * spacing;
	float minWidth = max_c(minListWidth, minButtonBarWidth);

	float menuBarHeight = menuBar->Bounds().bottom;
	float buttonBarHeight = Bounds().bottom - containerView->Frame().bottom;
	float minHeight = menuBarHeight + 200 + buttonBarHeight;

	SetSizeLimits(minWidth, MAX_WIDTH, minHeight, MAX_HEIGHT);
		// SetSizeLimits() will resize the window to the minimum size.

	CenterOnScreen();

	entry_ref windowSettingsRef;
	if (_GetWindowSettingsFile(&windowSettingsRef)) {
		// The window settings file is not accepted via B_REFS_RECEIVED; this
		// is a behind-the-scenes file that the user will never see or
		// interact with.
		BFile windowSettingsFile(&windowSettingsRef, B_READ_ONLY);
		BMessage loadMsg;
		if (loadMsg.Unflatten(&windowSettingsFile) == B_OK)
			_LoadWindowSettings(loadMsg);
	}

	entry_ref keySetRef;
	if (_GetSettingsFile(&keySetRef)) {
		BMessage msg(B_REFS_RECEIVED);
		msg.AddRef("refs", &keySetRef);
		msg.AddString("startupRef", "please");
		PostMessage(&msg);
			// Tell ourselves to load this file if it exists.
	}
	Show();
}
Beispiel #11
0
// constructor
ObjectWindow::ObjectWindow(BRect frame, const char* name)
	: BWindow(frame, name, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
			  B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE)
{
	BRect b(Bounds());

	b.bottom = b.top + 8;
	BMenuBar* menuBar = new BMenuBar(b, "menu bar");
	AddChild(menuBar);

	BMenu* menu = new BMenu("File");
	menuBar->AddItem(menu);

	menu->AddItem(new BMenu("Submenu"));

	BMenuItem* menuItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED),
										'Q');
	menu->AddItem(menuItem);

	b = Bounds();
	b.top = menuBar->Bounds().bottom + 1;
	b.right = ceilf((b.left + b.right) / 2.0);
	BBox* bg = new BBox(b, "bg box", B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW,
		B_PLAIN_BORDER);

	AddChild(bg);
	bg->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// object view occupies the right side of the window
	b.left = b.right + 1.0;
	b.right = Bounds().right - B_V_SCROLL_BAR_WIDTH;
	b.bottom -= B_H_SCROLL_BAR_HEIGHT;
	fObjectView = new ObjectView(b, "object view", B_FOLLOW_ALL,
								 B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE);
	// wrap a scroll view around the object view
	BScrollView* scrollView = new BScrollView("object scroller", fObjectView,
		B_FOLLOW_ALL, 0, true, true, B_NO_BORDER);

	if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_VERTICAL)) {
		scrollBar->SetRange(0.0, fObjectView->Bounds().Height());
		scrollBar->SetProportion(0.5);
	}
	if (BScrollBar* scrollBar = fObjectView->ScrollBar(B_HORIZONTAL)) {
		scrollBar->SetRange(0.0, fObjectView->Bounds().Width());
		scrollBar->SetProportion(0.5);
	}
	AddChild(scrollView);

	b = bg->Bounds();
	// controls occupy the left side of the window
	b.InsetBy(5.0, 5.0);
	BBox* controlGroup = new BBox(b, "controls box",
		B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_WILL_DRAW, B_FANCY_BORDER);

	controlGroup->SetLabel("Controls");
	bg->AddChild(controlGroup);

	b = controlGroup->Bounds();
	b.top += controlGroup->InnerFrame().top;
	b.bottom = b.top + 25.0;
	b.InsetBy(10.0, 10.0);
	b.right = b.left + b.Width() / 2.0 - 5.0;

	// new button
	fNewB = new BButton(b, "new button", "New Object",
		new BMessage(MSG_NEW_OBJECT));
	controlGroup->AddChild(fNewB);
	SetDefaultButton(fNewB);

	// clear button
	b.OffsetBy(0, fNewB->Bounds().Height() + 5.0);
	fClearB = new BButton(b, "clear button", "Clear", new BMessage(MSG_CLEAR));
	controlGroup->AddChild(fClearB);

	// object type radio buttons
	BMessage* message;
	BRadioButton* radioButton;

	b.OffsetBy(0, fClearB->Bounds().Height() + 5.0);
	message = new BMessage(MSG_SET_OBJECT_TYPE);
	message->AddInt32("type", OBJECT_LINE);
	radioButton = new BRadioButton(b, "radio 1", "Line", message);
	controlGroup->AddChild(radioButton);

	radioButton->SetValue(B_CONTROL_ON);

	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
	message = new BMessage(MSG_SET_OBJECT_TYPE);
	message->AddInt32("type", OBJECT_RECT);
	radioButton = new BRadioButton(b, "radio 2", "Rect", message);
	controlGroup->AddChild(radioButton);

	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
	message = new BMessage(MSG_SET_OBJECT_TYPE);
	message->AddInt32("type", OBJECT_ROUND_RECT);
	radioButton = new BRadioButton(b, "radio 3", "Round Rect", message);
	controlGroup->AddChild(radioButton);

	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
	message = new BMessage(MSG_SET_OBJECT_TYPE);
	message->AddInt32("type", OBJECT_ELLIPSE);
	radioButton = new BRadioButton(b, "radio 4", "Ellipse", message);
	controlGroup->AddChild(radioButton);

	// drawing mode
	BPopUpMenu* popupMenu = new BPopUpMenu("<pick>");

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_COPY);
	popupMenu->AddItem(new BMenuItem("Copy", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_OVER);
	popupMenu->AddItem(new BMenuItem("Over", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_INVERT);
	popupMenu->AddItem(new BMenuItem("Invert", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_BLEND);
	popupMenu->AddItem(new BMenuItem("Blend", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_SELECT);
	popupMenu->AddItem(new BMenuItem("Select", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_ERASE);
	popupMenu->AddItem(new BMenuItem("Erase", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_ADD);
	popupMenu->AddItem(new BMenuItem("Add", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_SUBTRACT);
	popupMenu->AddItem(new BMenuItem("Subtract", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_MIN);
	popupMenu->AddItem(new BMenuItem("Min", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_MAX);
	popupMenu->AddItem(new BMenuItem("Max", message));

	message = new BMessage(MSG_SET_DRAWING_MODE);
	message->AddInt32("mode", B_OP_ALPHA);
	BMenuItem* item = new BMenuItem("Alpha", message);
	item->SetMarked(true);
	popupMenu->AddItem(item);

	b.OffsetBy(0, radioButton->Bounds().Height() + 10.0);
	fDrawingModeMF = new BMenuField(b, "drawing mode field", "Mode:",
		popupMenu);

	controlGroup->AddChild(fDrawingModeMF);

	fDrawingModeMF->SetDivider(fDrawingModeMF->StringWidth(
		fDrawingModeMF->Label()) + 10.0);
	
	// color control
	b.OffsetBy(0, fDrawingModeMF->Bounds().Height() + 10.0);
	fColorControl = new BColorControl(b.LeftTop(), B_CELLS_16x16, 8,
		"color control", new BMessage(MSG_SET_COLOR));
	controlGroup->AddChild(fColorControl);
	
	// alpha text control
	b.OffsetBy(0, fColorControl-> Bounds().Height() + 5.0);
	fAlphaTC = new BTextControl(b, "alpha text control", "Alpha:", "",
		new BMessage(MSG_SET_COLOR));
	controlGroup->AddChild(fAlphaTC);

	// divide text controls the same
    float mWidth = fDrawingModeMF->StringWidth(fDrawingModeMF->Label());
    float aWidth = fAlphaTC->StringWidth(fAlphaTC->Label());
    
    float width = max_c(mWidth, aWidth) + 20.0;
	fDrawingModeMF->SetDivider(width);
	fAlphaTC->SetDivider(width);

	// fill check box
	b.OffsetBy(0, fAlphaTC->Bounds().Height() + 5.0);
	fFillCB = new BCheckBox(b, "fill check box", "Fill",
		new BMessage(MSG_SET_FILL_OR_STROKE));
	controlGroup->AddChild(fFillCB);

	// pen size text control
	b.OffsetBy(0, radioButton->Bounds().Height() + 5.0);
	b.bottom = b.top + 10.0;//35;
	fPenSizeS = new BSlider(b, "width slider", "Width:", NULL, 1, 100,
		B_TRIANGLE_THUMB);
	fPenSizeS->SetLimitLabels("1", "100");
	fPenSizeS->SetModificationMessage(new BMessage(MSG_SET_PEN_SIZE));
	fPenSizeS->SetHashMarks(B_HASH_MARKS_BOTTOM);
	fPenSizeS->SetHashMarkCount(10);

	controlGroup->AddChild(fPenSizeS);

	// list view with objects
	b = controlGroup->Bounds();
	b.top += controlGroup->InnerFrame().top;
	b.InsetBy(10.0, 10.0);
	b.left = b.left + b.Width() / 2.0 + 6.0;
	b.right -= B_V_SCROLL_BAR_WIDTH;
    b.bottom = fDrawingModeMF->Frame().top - 10.0;

	fObjectLV = new ObjectListView(b, "object list", B_SINGLE_SELECTION_LIST);
	fObjectLV->SetSelectionMessage(new BMessage(MSG_OBJECT_SELECTED));

	// wrap a scroll view around the list view
	scrollView = new BScrollView("list scroller", fObjectLV,
		B_FOLLOW_NONE, 0, false, true, B_FANCY_BORDER);
	controlGroup->AddChild(scrollView);

	// enforce some size limits
	float minWidth = controlGroup->Frame().Width() + 30.0;
	float minHeight = fPenSizeS->Frame().bottom
		+ menuBar->Bounds().Height() + 15.0;
	float maxWidth = minWidth * 4.0;
	float maxHeight = minHeight + 100;
	SetSizeLimits(minWidth, maxWidth, minHeight, maxHeight);

	ResizeTo(max_c(frame.Width(), minWidth), max_c(frame.Height(), minHeight));

	_UpdateControls();
}
ActivityWindow::ActivityWindow()
	:
	BWindow(BRect(100, 100, 500, 350), B_TRANSLATE_SYSTEM_NAME("ActivityMonitor"),
	B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE)
{
	BMessage settings;
	_LoadSettings(settings);

	BRect frame;
	if (settings.FindRect("window frame", &frame) == B_OK) {
		MoveTo(frame.LeftTop());
		ResizeTo(frame.Width(), frame.Height());
	}

#ifdef __HAIKU__
	BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 0);
	SetLayout(layout);

	// create GUI

	BMenuBar* menuBar = new BMenuBar("menu");
	layout->AddView(menuBar);

	fLayout = new BGroupLayout(B_VERTICAL);
	float inset = ceilf(be_plain_font->Size() * 0.7);
	fLayout->SetInsets(inset, inset, inset, inset);
	fLayout->SetSpacing(inset);

	BView* top = new BView("top", 0, fLayout);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	layout->AddView(top);

	BMessage viewState;
	int32 count = 0;
	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
			== B_OK; i++) {
		ActivityView* view = new ActivityView("ActivityMonitor", &viewState);
		fLayout->AddItem(view->CreateHistoryLayoutItem());
		fLayout->AddItem(view->CreateLegendLayoutItem());
		count++;
	}
	if (count == 0) {
		// Add default views (memory & CPU usage)
		_AddDefaultView();
		_AddDefaultView();
	}
#else	// !__HAIKU__
	BView *layout = new BView(Bounds(), "topmost", B_FOLLOW_NONE, 0);
	AddChild(layout);

	// create GUI
	BRect mbRect(Bounds());
	mbRect.bottom = 10;
	BMenuBar* menuBar = new BMenuBar(mbRect, "menu");
	layout->AddChild(menuBar);

	BRect topRect(Bounds());
	topRect.top = menuBar->Bounds().bottom + 1;

	BView* top = new BView(topRect, "top", B_FOLLOW_ALL, 0);
	top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	layout->AddChild(top);

	BMessage viewState;
	int32 count = 0;
	ActivityView *aview;
	BRect rect;
	for (int32 i = 0; settings.FindMessage("activity view", i, &viewState)
			== B_OK; i++) {
		aview = new ActivityView("ActivityMonitor", &viewState);
		if (!rect.IsValid())
			rect = aview->Bounds();
		else
			rect.OffsetBySelf(0.0, aview->Bounds().Height());
		top->AddChild(aview);
		count++;
	}
	if (count == 0)
		top->AddChild(new ActivityView("ActivityMonitor", NULL));

#endif
	// add menu

	// "File" menu
	BMenu* menu = new BMenu(B_TRANSLATE("File"));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Add graph"),
		new BMessage(kMsgAddView)));
	menu->AddSeparatorItem();

	menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);

	// "Settings" menu
	menu = new BMenu(B_TRANSLATE("Settings"));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Settings" B_UTF8_ELLIPSIS),
		new BMessage(kMsgShowSettings)));
	menu->SetTargetForItems(this);
	menuBar->AddItem(menu);
}
TeapotWindow::TeapotWindow(BRect rect, const char* name, window_type wt,
	ulong something)
	:
	BDirectWindow(rect, name, wt, something)
{
	GLenum type = BGL_RGB | BGL_DEPTH | BGL_DOUBLE;

	Lock();
	BRect bounds = Bounds();
	bounds.bottom = bounds.top + 14;
	BMenuBar* menuBar = new BMenuBar(bounds, "main menu");

	BMenu* menu;
	BMessage msg(kMsgAddModel);

	menuBar->AddItem(menu = new BMenu(B_TRANSLATE("File")));
	AddChild(menuBar);

	menuBar->ResizeToPreferred();

	bounds = Bounds();
	bounds.top = menuBar->Bounds().bottom + 1;
	BView *subView = new BView(bounds, "subview", B_FOLLOW_ALL, 0);
	AddChild(subView);

	bounds = subView->Bounds();
	fObjectView = new(std::nothrow) ObjectView(bounds, "objectView",
		B_FOLLOW_ALL_SIDES, type);
	subView->AddChild(fObjectView);

	BMenuItem*	item;
	msg.AddInt32("num", 256);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Add a teapot"),
		new BMessage(msg), 'N'));
	item->SetTarget(fObjectView);
	menu->AddSeparatorItem();
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Quit"),
		new BMessage(B_QUIT_REQUESTED), 'Q'));
	item->SetTarget(be_app);
	msg.RemoveName("num");
	menuBar->AddItem(menu = new BMenu(B_TRANSLATE("Options")));
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Perspective"),
		new BMessage(kMsgPerspective)));
	item->SetTarget(fObjectView);
	item->SetMarked(false);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("FPS display"),
		new BMessage(kMsgFPS)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Filled polygons"),
		new BMessage(kMsgFilled)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Lighting"),
		new BMessage(kMsgLighting)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Backface culling"),
		new BMessage(kMsgCulling)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Z-buffered"),
		new BMessage(kMsgZBuffer)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Gouraud shading"),
		new BMessage(kMsgGouraud)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
//	menu->AddItem(item = new BMenuItem("Texture mapped", new BMessage(kMsgTextured)));
//	item->SetTarget(fObjectView);
	menu->AddItem(item = new BMenuItem(B_TRANSLATE("Fog"),
		new BMessage(kMsgFog)));
	item->SetTarget(fObjectView);

	BMenu *subMenu;
	menuBar->AddItem(menu = new BMenu(B_TRANSLATE("Lights")));
	msg.what = kMsgLights;

	msg.AddInt32("num", 1);
	menu->AddItem(item = new BMenuItem(subMenu =
		new BMenu(B_TRANSLATE("Upper center")), NULL));
	item->SetTarget(fObjectView);
	msg.AddInt32("color", lightNone);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Off"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	subMenu->AddSeparatorItem();
	msg.ReplaceInt32("color", lightWhite);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("White"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	msg.ReplaceInt32("color", lightYellow);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Yellow"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightBlue);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Blue"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightRed);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Red"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightGreen);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Green"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);

	msg.RemoveName("color");

	msg.ReplaceInt32("num", 2);
	menu->AddItem(item = new BMenuItem(subMenu =
		new BMenu(B_TRANSLATE("Lower left")), NULL));
	item->SetTarget(fObjectView);
	msg.AddInt32("color", lightNone);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Off"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	subMenu->AddSeparatorItem();
	msg.ReplaceInt32("color", lightWhite);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("White"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightYellow);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Yellow"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightBlue);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Blue"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	msg.ReplaceInt32("color", lightRed);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Red"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightGreen);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Green"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);

	msg.RemoveName("color");

	msg.ReplaceInt32("num", 3);
	menu->AddItem(item = new BMenuItem(subMenu =
		new BMenu(B_TRANSLATE("Right")), NULL));
	item->SetTarget(fObjectView);
	msg.AddInt32("color", lightNone);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Off"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	item->SetMarked(true);
	subMenu->AddSeparatorItem();
	msg.ReplaceInt32("color", lightWhite);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("White"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightYellow);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Yellow"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightBlue);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Blue"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightRed);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Red"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);
	msg.ReplaceInt32("color", lightGreen);
	subMenu->AddItem(item = new BMenuItem(B_TRANSLATE("Green"),
		new BMessage(msg)));
	item->SetTarget(fObjectView);

	float f = menuBar->Bounds().IntegerHeight() + 1;
	SetSizeLimits(32, 1024, 32 + f, 1024 + f);
			//TODO: verify, adding an height to x seems strange
	Unlock();
}
Beispiel #14
0
SerialWindow::SerialWindow()
	: BWindow(BRect(100, 100, 400, 400), SerialWindow::kWindowTitle,
		B_DOCUMENT_WINDOW, B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS)
	, fLogFilePanel(NULL)
{
	BMenuBar* menuBar = new BMenuBar(Bounds(), "menuBar");
	menuBar->ResizeToPreferred();

	BRect r = Bounds();
	r.top = menuBar->Bounds().bottom + 1;
	r.right -= B_V_SCROLL_BAR_WIDTH;
	fTermView = new TermView(r);
	fTermView->ResizeToPreferred();

	r = fTermView->Frame();
	r.left = r.right + 1;
	r.right = r.left + B_V_SCROLL_BAR_WIDTH;
	r.top -= 1;
	r.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
	BScrollBar* scrollBar = new BScrollBar(r, "scrollbar", NULL, 0, 0,
		B_VERTICAL);

	scrollBar->SetTarget(fTermView);

	ResizeTo(r.right - 1, r.bottom + B_H_SCROLL_BAR_HEIGHT - 1);

	AddChild(menuBar);
	AddChild(fTermView);
	AddChild(scrollBar);

	fConnectionMenu = new BMenu("Connection");
	BMenu* fileMenu = new BMenu("File");
	BMenu* settingsMenu = new BMenu("Settings");

	fConnectionMenu->SetRadioMode(true);

	menuBar->AddItem(fConnectionMenu);
	menuBar->AddItem(fileMenu);
	menuBar->AddItem(settingsMenu);

	// TODO edit menu - what's in it ?
	//BMenu* editMenu = new BMenu("Edit");
	//menuBar->AddItem(editMenu);

	BMenuItem* logFile = new BMenuItem("Log to file" B_UTF8_ELLIPSIS,
		new BMessage(kMsgLogfile));
	fileMenu->AddItem(logFile);
#if 0
	// TODO implement these
	BMenuItem* xmodemSend = new BMenuItem("X/Y/ZModem send" B_UTF8_ELLIPSIS,
		NULL);
	fileMenu->AddItem(xmodemSend);
	BMenuItem* xmodemReceive = new BMenuItem(
		"X/Y/Zmodem receive" B_UTF8_ELLIPSIS, NULL);
	fileMenu->AddItem(xmodemReceive);
#endif

	// Configuring all this by menus may be a bit unhandy. Make a setting
	// window instead ?
	fBaudrateMenu = new BMenu("Baud rate");
	fBaudrateMenu->SetRadioMode(true);
	settingsMenu->AddItem(fBaudrateMenu);

	fParityMenu = new BMenu("Parity");
	fParityMenu->SetRadioMode(true);
	settingsMenu->AddItem(fParityMenu);

	fStopbitsMenu = new BMenu("Stop bits");
	fStopbitsMenu->SetRadioMode(true);
	settingsMenu->AddItem(fStopbitsMenu);

	fFlowcontrolMenu = new BMenu("Flow control");
	fFlowcontrolMenu->SetRadioMode(true);
	settingsMenu->AddItem(fFlowcontrolMenu);

	fDatabitsMenu = new BMenu("Data bits");
	fDatabitsMenu->SetRadioMode(true);
	settingsMenu->AddItem(fDatabitsMenu);


	BMessage* message = new BMessage(kMsgSettings);
	message->AddInt32("parity", B_NO_PARITY);
	BMenuItem* parityNone = new BMenuItem("None", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("parity", B_ODD_PARITY);
	BMenuItem* parityOdd = new BMenuItem("Odd", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("parity", B_EVEN_PARITY);
	BMenuItem* parityEven = new BMenuItem("Even", message);

	fParityMenu->AddItem(parityNone);
	fParityMenu->AddItem(parityOdd);
	fParityMenu->AddItem(parityEven);
	fParityMenu->SetTargetForItems(be_app);

	message = new BMessage(kMsgSettings);
	message->AddInt32("databits", B_DATA_BITS_7);
	BMenuItem* data7 = new BMenuItem("7", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("databits", B_DATA_BITS_8);
	BMenuItem* data8 = new BMenuItem("8", message);

	fDatabitsMenu->AddItem(data7);
	fDatabitsMenu->AddItem(data8);
	fDatabitsMenu->SetTargetForItems(be_app);

	message = new BMessage(kMsgSettings);
	message->AddInt32("stopbits", B_STOP_BITS_1);
	BMenuItem* stop1 = new BMenuItem("1", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("stopbits", B_STOP_BITS_2);
	BMenuItem* stop2 = new BMenuItem("2", message);

	fStopbitsMenu->AddItem(stop1);
	fStopbitsMenu->AddItem(stop2);
	fStopbitsMenu->SetTargetForItems(be_app);

	// Loop backwards to add fastest rates at top of menu
	for (int i = sizeof(kBaudrates) / sizeof(char*); --i >= 0;)
	{
		message = new BMessage(kMsgSettings);
		message->AddInt32("baudrate", kBaudrateConstants[i]);

		char buffer[7];
		sprintf(buffer, "%d", kBaudrates[i]);
		BMenuItem* item = new BMenuItem(buffer, message);

		fBaudrateMenu->AddItem(item);
	}

	fBaudrateMenu->SetTargetForItems(be_app);

	message = new BMessage(kMsgSettings);
	message->AddInt32("flowcontrol", B_HARDWARE_CONTROL);
	BMenuItem* hardware = new BMenuItem("Hardware", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("flowcontrol", B_SOFTWARE_CONTROL);
	BMenuItem* software = new BMenuItem("Software", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("flowcontrol", B_HARDWARE_CONTROL | B_SOFTWARE_CONTROL);
	BMenuItem* both = new BMenuItem("Both", message);

	message = new BMessage(kMsgSettings);
	message->AddInt32("flowcontrol", 0);
	BMenuItem* noFlow = new BMenuItem("None", message);

	fFlowcontrolMenu->AddItem(hardware);
	fFlowcontrolMenu->AddItem(software);
	fFlowcontrolMenu->AddItem(both);
	fFlowcontrolMenu->AddItem(noFlow);
	fFlowcontrolMenu->SetTargetForItems(be_app);

	CenterOnScreen();
}
PrefsWindow::PrefsWindow(uint32 msg) : BWindow(BRect(0, 0, 400, 289), GetString(STR_PREFS_TITLE), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), this_messenger(this)
{
	int i;
	ok_message = msg;
	send_quit_on_close = true;
	get_system_info(&sys_info);

	// Move window to right position
	Lock();
	MoveTo(80, 80);

	// Set up menus
	BMenuBar *bar = new BMenuBar(Bounds(), "menu");
	BMenu *menu = new BMenu(GetString(STR_PREFS_MENU));
	menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_ABOUT), new BMessage(B_ABOUT_REQUESTED)));
	menu->AddItem(new BSeparatorItem);
	menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_START), new BMessage(MSG_OK)));
	menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_ZAP_PRAM), new BMessage(MSG_ZAP_PRAM)));
	menu->AddItem(new BSeparatorItem);
	menu->AddItem(new BMenuItem(GetString(STR_PREFS_ITEM_QUIT), new BMessage(MSG_CANCEL), 'Q'));
	bar->AddItem(menu);
	AddChild(bar);
	SetKeyMenuBar(bar);
	int mbar_height = int(bar->Bounds().bottom) + 1;

	// Resize window to fit menu bar
	ResizeBy(0, mbar_height);

	// Light gray background
	BRect b = Bounds();
	top = new BView(BRect(0, mbar_height, b.right, b.bottom), "top", B_FOLLOW_NONE, B_WILL_DRAW);
	AddChild(top);
	top->SetViewColor(fill_color);
	top_frame = top->Bounds();

	// Create panes
	panes[0] = create_volumes_pane();
	panes[1] = create_graphics_pane();
	panes[2] = create_serial_pane();
	panes[3] = create_memory_pane();

	// Prefs item tab view
	pane_tabs = new BTabView(BRect(10, 10, top_frame.right-10, top_frame.bottom-50), "items", B_WIDTH_FROM_LABEL);
	for (i=0; i<NUM_PANES; i++)
		pane_tabs->AddTab(panes[i]);
	top->AddChild(pane_tabs);

	volume_list->Select(0);

	// Create volume file panels
	add_volume_panel = new BFilePanel(B_OPEN_PANEL, &this_messenger, NULL, B_FILE_NODE | B_DIRECTORY_NODE, false, new BMessage(MSG_ADD_VOLUME_PANEL));
	add_volume_panel->SetButtonLabel(B_DEFAULT_BUTTON, GetString(STR_ADD_VOLUME_PANEL_BUTTON));
	add_volume_panel->Window()->SetTitle(GetString(STR_ADD_VOLUME_TITLE));
	create_volume_panel = new BFilePanel(B_SAVE_PANEL, &this_messenger, NULL, B_FILE_NODE | B_DIRECTORY_NODE, false, new BMessage(MSG_CREATE_VOLUME_PANEL));
	create_volume_panel->SetButtonLabel(B_DEFAULT_BUTTON, GetString(STR_CREATE_VOLUME_PANEL_BUTTON));
	create_volume_panel->Window()->SetTitle(GetString(STR_CREATE_VOLUME_TITLE));

	create_volume_panel->Window()->Lock();
	BView *background = create_volume_panel->Window()->ChildAt(0);
	background->FindView("PoseView")->ResizeBy(0, -30);
	background->FindView("VScrollBar")->ResizeBy(0, -30);
	background->FindView("CountVw")->MoveBy(0, -30);
	BView *v = background->FindView("HScrollBar");
	if (v)
		v->MoveBy(0, -30);
	else {
		i = 0;
		while ((v = background->ChildAt(i++)) != NULL) {
			if (v->Name() == NULL || v->Name()[0] == 0) {
				v->MoveBy(0, -30);	// unnamed horizontal scroll bar
				break;
			}
		}
	}
	BView *filename = background->FindView("text view");
	BRect fnr(filename->Frame());
	fnr.OffsetBy(0, -30);
	NumberControl *nc = new NumberControl(fnr, 80, "hardfile_size", GetString(STR_HARDFILE_SIZE_CTRL), 40, NULL);
	background->AddChild(nc);
	create_volume_panel->Window()->Unlock();

	// "Start" button
	BButton *button = new BButton(BRect(20, top_frame.bottom-35, 90, top_frame.bottom-10), "start", GetString(STR_START_BUTTON), new BMessage(MSG_OK));
	top->AddChild(button);
	SetDefaultButton(button);

	// "Quit" button
	top->AddChild(new BButton(BRect(top_frame.right-90, top_frame.bottom-35, top_frame.right-20, top_frame.bottom-10), "cancel", GetString(STR_QUIT_BUTTON), new BMessage(MSG_CANCEL)));

	Unlock();
	Show();
}