Esempio n. 1
0
void
HWindow::_InitGUI()
{
	fEventList = new HEventList();
	fEventList->SetType(BMediaFiles::B_SOUNDS);
	fEventList->SetSelectionMode(B_SINGLE_SELECTION_LIST);

	BMenu* menu = new BMenu("file");
	menu->SetRadioMode(true);
	menu->SetLabelFromMarked(true);
	menu->AddSeparatorItem();
	menu->AddItem(new BMenuItem(B_TRANSLATE("<none>"),
		new BMessage(M_NONE_MESSAGE)));
	menu->AddItem(new BMenuItem(B_TRANSLATE("Other" B_UTF8_ELLIPSIS),
		new BMessage(M_OTHER_MESSAGE)));

	BString label(B_TRANSLATE("Sound file:"));
	BMenuField* menuField = new BMenuField("filemenu", label, menu);
	menuField->SetDivider(menuField->StringWidth(label) + 10);

	BSize buttonsSize(be_plain_font->Size() * 2.5, be_plain_font->Size() * 2.5);

	BButton* stopbutton = new BButton("stop", "\xE2\x96\xA0",
		new BMessage(M_STOP_MESSAGE));
	stopbutton->SetEnabled(false);
	stopbutton->SetExplicitSize(buttonsSize);

	// We need at least one view to trigger B_PULSE_NEEDED events which we will
	// intercept in DispatchMessage to trigger the buttons enabling or disabling.
	stopbutton->SetFlags(stopbutton->Flags() | B_PULSE_NEEDED);

	BButton* playbutton = new BButton("play", "\xE2\x96\xB6",
		new BMessage(M_PLAY_MESSAGE));
	playbutton->SetEnabled(false);
	playbutton->SetExplicitSize(buttonsSize);

	BLayoutBuilder::Group<>(this, B_VERTICAL)
		.SetInsets(B_USE_WINDOW_SPACING)
		.Add(fEventList)
		.AddGroup(B_HORIZONTAL)
			.Add(menuField)
			.AddGroup(B_HORIZONTAL, 0)
				.Add(playbutton)
				.Add(stopbutton)
			.End()
		.End();

	// setup file menu
	_SetupMenuField();
	BMenuItem* noneItem = menu->FindItem(B_TRANSLATE("<none>"));
	if (noneItem != NULL)
		noneItem->SetMarked(true);

	_UpdateZoomLimits();
}
Esempio n. 2
0
ProjectSettingsWindow::ProjectSettingsWindow(BRect frame, Project* project)
	:
	BWindow(frame, TR("Project settings"), B_TITLED_WINDOW,
		B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS),
	fProject(project),
	fDirty(false)
{
	if (fProject == NULL)
		debugger("Bad project given to Project Settings window");

	fRefFilter = new TypedRefFilter(NULL, B_DIRECTORY_NODE);

	BMessenger messenger(this);
	entry_ref projectFolderRef;
	BEntry(fProject->GetPath().GetFolder()).GetRef(&projectFolderRef);
	fFilePanel = new BFilePanel(B_OPEN_PANEL, &messenger, &projectFolderRef,
		B_DIRECTORY_NODE, true, new BMessage(M_ADD_PATH), fRefFilter);

	fAutolock = new BAutolock(fProject);

	AddCommonFilter(new EscapeCancelFilter());

	fTargetText = new AutoTextControl("targetname", TR("Target name:"),
		fProject->GetTargetName(), new BMessage(M_TARGET_NAME_CHANGED));

	BPopUpMenu* targetTypeMenu = new BPopUpMenu(TR("Target type"));
	targetTypeMenu->AddItem(new BMenuItem(TR("Application"),
		new BMessage(M_SET_TARGET_TYPE)));
	targetTypeMenu->AddItem(new BMenuItem(TR("Shared library"),
		new BMessage(M_SET_TARGET_TYPE)));
	targetTypeMenu->AddItem(new BMenuItem(TR("Static library"),
		new BMessage(M_SET_TARGET_TYPE)));
	targetTypeMenu->AddItem(new BMenuItem(TR("Device driver"),
		new BMessage(M_SET_TARGET_TYPE)));

	fTypeField = new BMenuField("type", TR("Target type:"), targetTypeMenu);
	SetToolTip(fTypeField, TR("The kind of program you want to build"));

	BMenuItem* item = targetTypeMenu->ItemAt(fProject->TargetType());
	if (item != NULL)
		item->SetMarked(true);

	fIncludeList = new IncludeList(fProject->GetPath().GetFolder());
	SetToolTip(fIncludeList,
		TR("The folders you want Paladin to search for header files"));

	BScrollView* includeScrollView = new BScrollView("includescrollview",
		fIncludeList, B_WILL_DRAW, true, true);
	includeScrollView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	includeScrollView->SetExplicitMinSize(
		BSize(be_plain_font->StringWidth("M") * 34.0f,
			be_plain_font->StringWidth("M") * 12.0f));

	for (int32 i = 0; i < fProject->CountLocalIncludes(); i++) {
		fIncludeList->AddItem(new BStringItem(
			fProject->LocalIncludeAt(i).Relative().String()));
	}

	float buttonWidth = be_plain_font->StringWidth("+") * 2.0f + 3.0f;

	BButton* addButton = new BButton("addbutton", TR("+"),
		new BMessage(M_SHOW_ADD_PATH));
	addButton->SetExplicitSize(BSize(buttonWidth, buttonWidth));
	addButton->SetToolTip(TR("Add a file to the include path list"));

	BButton* removeButton = new BButton("removebutton", TR("−"),
		new BMessage(M_REMOVE_PATH));
	removeButton->SetExplicitSize(BSize(buttonWidth, buttonWidth));
	removeButton->SetToolTip(TR("Remove the selected path"));

	// general tab

	fGeneralView = new BView(TR("General"), B_WILL_DRAW);
	fGeneralView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	BLayoutBuilder::Group<>(fGeneralView, B_VERTICAL, 0)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fTargetText->CreateLabelLayoutItem(), 0, 0)
			.Add(fTargetText->CreateTextViewLayoutItem(), 1, 0)

			.Add(fTypeField->CreateLabelLayoutItem(), 0, 1)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 1)
				.Add(fTypeField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()
			.End()
		.AddStrut(B_USE_DEFAULT_SPACING)
		.AddGroup(B_VERTICAL, 2.0f)
			.Add(new BStringView("include paths", TR("Include paths:")))
			.AddGroup(B_HORIZONTAL, B_USE_SMALL_SPACING)
				.Add(includeScrollView)
				.AddGroup(B_VERTICAL, B_USE_SMALL_SPACING)
					.Add(addButton)
					.Add(removeButton)
					.AddGlue()
					.End()
				.End()
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	BPopUpMenu* optimizationMenu = new BPopUpMenu(TR("Optimization"));
	optimizationMenu->AddItem(new BMenuItem(TR("None"),
		new BMessage(M_SET_OP_VALUE)));
	optimizationMenu->AddItem(new BMenuItem(TR("Some"),
		new BMessage(M_SET_OP_VALUE)));
	optimizationMenu->AddItem(new BMenuItem(TR("More"),
		new BMessage(M_SET_OP_VALUE)));
	optimizationMenu->AddItem(new BMenuItem(TR("Full"),
		new BMessage(M_SET_OP_VALUE)));

	fOpField = new BMenuField("optimize", TR("Optimize:"), optimizationMenu);
	SetToolTip(fOpField, TR("Compiler optimization level. "
		"Disabled when debugging info is checked."));

	item = optimizationMenu->ItemAt(fProject->OpLevel());
	if (item != NULL)
		item->SetMarked(true);

	fOpSizeBox = new BCheckBox("opsizebox", TR("Optimize for size over speed"),
		new BMessage(M_TOGGLE_OPSIZE));

	if (fProject->OpForSize())
		fOpSizeBox->SetValue(B_CONTROL_ON);
	
	if (fProject->Debug()) {
		fOpField->SetEnabled(false);
		fOpSizeBox->SetEnabled(false);
	}

	fDebugBox = new BCheckBox("debugbox", TR("Build debugging information"),
		new BMessage(M_TOGGLE_DEBUG));
	SetToolTip(fDebugBox,
		TR("Check this if you want to use your program in a debugger "
		   "during development. You'll want to rebuild your project "
		   "after change this."));

	if (fProject->Debug())
		fDebugBox->SetValue(B_CONTROL_ON);

	fProfileBox = new BCheckBox("profilebox", TR("Build profiling information"),
		new BMessage(M_TOGGLE_PROFILE));
	SetToolTip(fProfileBox,
		TR("Check this if you want to use your program "
		   "with gprof or bprof for profiling."));

	if (fProject->Profiling())
		fProfileBox->SetValue(B_CONTROL_ON);

	fCompileText = new AutoTextControl("extracc", "Extra compiler options:",
		fProject->ExtraCompilerOptions(), new BMessage(M_CCOPTS_CHANGED));
	SetToolTip(fCompileText,
		TR("Extra GCC flags you wish included when each file is compiled."));

	fLinkText = new AutoTextControl("extrald" ,TR("Extra linker options:"),
		fProject->ExtraLinkerOptions(), new BMessage(M_LDOPTS_CHANGED));
	SetToolTip(fLinkText,
		TR("Extra GCC linker flags you wish included when your project "
		   "is linked."));

	// build tab

	fBuildView = new BView("Build", B_WILL_DRAW);
	fBuildView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	BLayoutBuilder::Group<>(fBuildView, B_VERTICAL)
		.AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING)
			.Add(fOpField->CreateLabelLayoutItem(), 0, 0)
			.AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0)
				.Add(fOpField->CreateMenuBarLayoutItem())
				.AddGlue()
				.End()
			.AddGroup(B_VERTICAL, 0.0f, 1, 2)
				.Add(fOpSizeBox)
				.AddStrut(B_USE_SMALL_SPACING)
				.Add(fDebugBox)
				.Add(fProfileBox)
				.End()
			.End()
		.AddGlue()
		.AddGroup(B_VERTICAL, 0)
			.Add(fCompileText->CreateLabelLayoutItem())
			.Add(fCompileText->CreateTextViewLayoutItem())
			.End()
		.AddGroup(B_VERTICAL, 0)
			.Add(fLinkText->CreateLabelLayoutItem())
			.Add(fLinkText->CreateTextViewLayoutItem())
			.End()
		.SetInsets(B_USE_DEFAULT_SPACING)
		.End();

	fTabView = new BTabView("tabview", B_WIDTH_FROM_LABEL);
	fTabView->SetBorder(B_NO_BORDER);
	fTabView->AddTab(fGeneralView);
	fTabView->AddTab(fBuildView);
	fTabView->Select(0L);

	BLayoutBuilder::Group<>(this, B_VERTICAL, 0)
		.AddStrut(B_USE_SMALL_SPACING)
		.Add(fTabView)
		.End();

	targetTypeMenu->SetTargetForItems(this);
	optimizationMenu->SetTargetForItems(this);

	fIncludeList->Select(0);
	fTargetText->MakeFocus(true);
}
Esempio n. 3
0
/*!	Tweaks the layout according to the configuration.
*/
void
BAlert::_Prepare()
{
	// Must have at least one button
	if (CountButtons() == 0)
		debugger("BAlerts must have at least one button.");

	float fontFactor = be_plain_font->Size() / 11.0f;

	if (fIconView->Bitmap() == NULL)
		fIconView->SetBitmap(_CreateTypeIcon());

	if (fButtonWidth == B_WIDTH_AS_USUAL) {
		float usualWidth = kButtonUsualWidth * fontFactor;

		for (int32 index = 0; index < CountButtons(); index++) {
			BButton* button = ButtonAt(index);
			if (button->MinSize().width < usualWidth)
				button->SetExplicitSize(BSize(usualWidth, B_SIZE_UNSET));
		}
	} else if (fButtonWidth == B_WIDTH_FROM_WIDEST) {
		// Get width of widest label
		float maxWidth = 0;
		for (int32 index = 0; index < CountButtons(); index++) {
			BButton* button = ButtonAt(index);
			float width;
			button->GetPreferredSize(&width, NULL);

			if (width > maxWidth)
				maxWidth = width;
		}
		for (int32 index = 0; index < CountButtons(); index++) {
			BButton* button = ButtonAt(index);
			button->SetExplicitSize(BSize(maxWidth, B_SIZE_UNSET));
		}
	}

	if (fButtonSpacing == B_OFFSET_SPACING && CountButtons() > 1) {
		// Insert some strut
		fButtonLayout->AddItem(1, BSpaceLayoutItem::CreateHorizontalStrut(
			kButtonOffsetSpacing * fontFactor));
	}

	// Position the alert so that it is centered vertically but offset a bit
	// horizontally in the parent window's frame or, if unavailable, the
	// screen frame.
	float minWindowWidth = (fButtonSpacing == B_OFFSET_SPACING
		? kWindowOffsetMinWidth : kWindowMinWidth) * fontFactor;
	GetLayout()->SetExplicitMinSize(BSize(minWindowWidth, B_SIZE_UNSET));

	ResizeToPreferred();

	// Return early if we've already been moved...
	if (Frame().left != 0 && Frame().right != 0)
		return;

	// otherwise center ourselves on-top of parent window/screen
	BWindow* parent = dynamic_cast<BWindow*>(BLooper::LooperForThread(
		find_thread(NULL)));
	const BRect frame = parent != NULL ? parent->Frame()
		: BScreen(this).Frame();

	MoveTo(static_cast<BWindow*>(this)->AlertPosition(frame));
		// Hidden by BAlert::AlertPosition()
}