Example #1
0
void 
TSignatureView::AttachedToWindow()
{
	BRect	rect = Bounds();
	float	name_text_length = StringWidth(kNameText);
	float	sig_text_length = StringWidth(kSigText);
	float	divide_length;

	if (name_text_length > sig_text_length)
		divide_length = name_text_length;
	else
		divide_length = sig_text_length;

	rect.InsetBy(8,0);
	rect.top+= 8;
	
	fName = new TNameControl(rect, kNameText, new BMessage(NAME_FIELD));
	AddChild(fName);

	fName->SetDivider(divide_length + 10);
	fName->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT);

	rect.OffsetBy(0,fName->Bounds().Height()+5);
	rect.bottom = rect.top + kSigHeight;
	rect.left = fName->TextView()->Frame().left;

	BRect text = rect;
	text.OffsetTo(10,0);
	fTextView = new TSigTextView(rect, text);
	BScrollView *scroller = new BScrollView("SigScroller", fTextView, B_FOLLOW_ALL, 0, false, true);
	AddChild(scroller);
	scroller->ResizeBy(-1 * scroller->ScrollBar(B_VERTICAL)->Frame().Width() - 9, 0);
	scroller->MoveBy(7,0);

	/* back up a bit to make room for the label */

	rect = scroller->Frame();
	BStringView *stringView = new BStringView(rect, "SigLabel", kSigText);
	AddChild(stringView);

	float tWidth, tHeight;
	stringView->GetPreferredSize(&tWidth, &tHeight);

	/* the 5 is for the spacer in the TextView */

	rect.OffsetBy(-1 *(tWidth) - 5, 0);
	rect.right = rect.left + tWidth;
	rect.bottom = rect.top + tHeight;

	stringView->MoveTo(rect.LeftTop());
	stringView->ResizeTo(rect.Width(), rect.Height());

	/* Resize the View to the correct height */
	scroller->SetResizingMode(B_FOLLOW_NONE);
	ResizeTo(Frame().Width(), scroller->Frame().bottom + 8);
	scroller->SetResizingMode(B_FOLLOW_ALL);
}
// Private function to switch between follow bottom behaviour
void
OutputFormatView::MakeFollowBottom(bool flag)
{
	scroll_view->SetResizingMode(B_FOLLOW_LEFT_RIGHT | (flag ? B_FOLLOW_TOP_BOTTOM : B_FOLLOW_TOP));
	cancel_button->SetResizingMode(B_FOLLOW_RIGHT | (flag ? B_FOLLOW_BOTTOM : B_FOLLOW_TOP));
	the_button->SetResizingMode(B_FOLLOW_RIGHT | (flag ? B_FOLLOW_BOTTOM : B_FOLLOW_TOP));
	info_caption->SetResizingMode(B_FOLLOW_LEFT_RIGHT | (flag ? B_FOLLOW_BOTTOM : B_FOLLOW_TOP));
	info_view->SetResizingMode(B_FOLLOW_LEFT_RIGHT | (flag ? B_FOLLOW_BOTTOM : B_FOLLOW_TOP));
	if (config_caption)
		config_caption->SetResizingMode(B_FOLLOW_LEFT_RIGHT | (flag ? B_FOLLOW_BOTTOM : B_FOLLOW_TOP));
}
Example #3
0
SCMImportWindow::SCMImportWindow(void)
  :	DWindow(BRect(0,0,350,300), "Import from Repository")
{
	MakeCenteredOnShow(true);
	
	BView *top = GetBackgroundView();
	
	BMenu *menu = new BMenu("Providers");
	
	for (int32 i = 0; i < fProviderMgr.CountImporters(); i++)
	{
		SCMProjectImporter *importer = fProviderMgr.ImporterAt(i);
		if (!importer)
			continue;
		
		BMessage *msg = new BMessage(M_USE_PROVIDER);
		menu->AddItem(new BMenuItem(importer->GetName(), msg));
	}
	
	// Disable custom commands for now	
//	menu->AddSeparatorItem();
//	menu->AddItem(new BMenuItem("Custom", new BMessage(M_USE_CUSTOM_PROVIDER)));
	
	menu->SetLabelFromMarked(true);
	menu->ItemAt(0L)->SetMarked(true);
	
	BRect r(Bounds());
	r.InsetBy(10.0, 10.0);
	r.bottom = 40.0;
	fProviderField = new BMenuField(r, "repofield", "Provider: ", menu,
								B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	float pw, ph;
	fProviderField->GetPreferredSize(&pw, &ph);
	fProviderField->ResizeTo(r.Width(), ph);
	top->AddChild(fProviderField);
	r = fProviderField->Frame();
	
	menu = new BMenu("Methods");
	if (gHgAvailable)
		menu->AddItem(new BMenuItem("Mercurial", new BMessage(M_UPDATE_COMMAND)));
	
	if (gGitAvailable)
		menu->AddItem(new BMenuItem("Git", new BMessage(M_UPDATE_COMMAND)));
	
	if (gSvnAvailable)
		menu->AddItem(new BMenuItem("Subversion", new BMessage(M_UPDATE_COMMAND)));
	menu->SetLabelFromMarked(true);
	menu->ItemAt(0L)->SetMarked(true);
	fProvider = fProviderMgr.ImporterAt(0);
		
	r.OffsetBy(0.0, r.Height() + 10.0);
	fSCMField = new BMenuField(r, "scmfield", "Method: ", menu,
								B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	top->AddChild(fSCMField);
		
	r.OffsetBy(0.0, r.Height() + 10.0);
	fProjectBox = new AutoTextControl(r, "project", "Project: ", "",
									new BMessage(M_UPDATE_COMMAND),
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	fProjectBox->GetPreferredSize(&pw, &ph);
	fProjectBox->ResizeTo(r.Width(), ph);
	r = fProjectBox->Frame();
	top->AddChild(fProjectBox);
	
	r.OffsetBy(0.0, r.Height() + 10.0);
	fAnonymousBox = new BCheckBox(r, "anonymous", "Anonymous check-out",
									new BMessage(M_TOGGLE_ANONYMOUS));
	top->AddChild(fAnonymousBox);
	fAnonymousBox->ResizeToPreferred();
	fAnonymousBox->SetValue(B_CONTROL_ON);
	
	r.OffsetBy(0.0, fAnonymousBox->Bounds().Height() + 10.0);
	fUserNameBox = new AutoTextControl(r, "username", "Username: "******"",
									new BMessage(M_UPDATE_COMMAND),
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	top->AddChild(fUserNameBox);
	fUserNameBox->SetEnabled(false);
	
	r.OffsetBy(0.0, r.Height() + 10.0);
	fRepository = new AutoTextControl(r, "repository", "Repository (opt.): ", "",
									new BMessage(M_UPDATE_COMMAND),
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	fRepository->GetPreferredSize(&pw, &ph);
	fRepository->ResizeTo(r.Width(), ph);
	r = fRepository->Frame();
	top->AddChild(fRepository);
	
	r.OffsetBy(0.0, r.Height() + 10.0);
	fCommandLabel = new BStringView(r, "commandlabel", "Command: ",
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	fCommandLabel->ResizeToPreferred();
	top->AddChild(fCommandLabel);
	
	r.OffsetBy(0.0, fCommandLabel->Bounds().Height() + 5.0);
	r.bottom = r.top + 75.0;
	r.right -= B_V_SCROLL_BAR_WIDTH;
	BRect textRect = r.OffsetToCopy(0.0, 0.0).InsetByCopy(10.0, 10.0);
	fCommandView = new BTextView(r, "command", textRect, B_FOLLOW_ALL);
	
	BScrollView *scroll = new BScrollView("scrollview", fCommandView,
											B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
											0, false, true);
	top->AddChild(scroll);
	fCommandView->MakeEditable(false);
	
	fOK = new BButton(r, "ok", "Import", new BMessage(M_SCM_IMPORT),
					B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
	fOK->ResizeToPreferred();
	fOK->MoveTo(Bounds().right - 10.0 - fOK->Bounds().Width(),
				scroll->Frame().bottom + 10.0);
	
	ResizeTo(Bounds().Width(),  fOK->Frame().bottom + 10.0);
	scroll->SetResizingMode(B_FOLLOW_ALL);
	
	top->AddChild(fOK);
	fOK->MakeDefault(true);
	fOK->SetEnabled(false);
	
	UpdateCommand();
	fProviderField->MakeFocus(true);
}
Example #4
0
RecipeEditor::RecipeEditor(const BRect &frame, const BMessenger &msgr,
						const int32 &number, const char *category)
 :	BWindow(frame,"Add Recipe",B_FLOATING_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL,
 			B_ASYNCHRONOUS_CONTROLS),
 	fMessenger(msgr),
 	fNumber(number),
 	fCategory(category)
{
	AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED));
	AddShortcut('Q', B_COMMAND_KEY, new BMessage(M_QUIT_APP));
	
	BView *back = new BView(Bounds(),"back",B_FOLLOW_ALL, B_WILL_DRAW);
	back->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
	AddChild(back);
	
	fCategories = new BMenu("Categories");
	CppSQLite3Query query = DBQuery("select category from categories order by category;",
									"RecipeEditor:get categories");
	while(!query.eof())
	{
		BString cat(DeescapeIllegalCharacters(query.getStringField(0)));
		BMessage *menumsg = new BMessage(M_CATEGORY_CHANGED);
		menumsg->AddString("name",cat);
		fCategories->AddItem(new BMenuItem(cat.String(),menumsg));
		query.nextRow();
	}
	fCategories->SetRadioMode(true);
	fCategories->SetLabelFromMarked(true);
	if(fCategories->CountItems()>0)
		fCategories->ItemAt(0)->SetMarked(true);
	BRect r(10,10,10 + fCategories->MaxContentWidth(),11);
	BMenuField *field = new BMenuField(r,"field","Category",fCategories,
										B_FOLLOW_LEFT | B_FOLLOW_TOP,
										B_WILL_DRAW | B_NAVIGABLE | B_NAVIGABLE_JUMP);
	back->AddChild(field);
	field->ResizeToPreferred();
	r = field->Frame();
	
	if(category)
	{
		BMenuItem *marked = fCategories->FindItem(category);
		if(marked)
			marked->SetMarked(true);
	}
	else
	{
		BMenuItem *marked = fCategories->ItemAt(0L);
		if(marked)
			marked->SetMarked(true);
	}
	
	r.OffsetBy(0,r.Height() + 10);
	fNameBox = new AutoTextControl(r,"namebox","Name: ",NULL,NULL,
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
									B_WILL_DRAW | B_PULSE_NEEDED | B_NAVIGABLE |
									B_NAVIGABLE_JUMP);
	fNameBox->SetEscapeCancel(true);
	fNameBox->SetDivider(be_plain_font->StringWidth("Name ") + 5);
	back->AddChild(fNameBox);
	fNameBox->ResizeToPreferred();
	r = fNameBox->Frame();
	r.right = Bounds().right - 10;
	fNameBox->ResizeTo(r.Width(), r.Height());
	
	r.OffsetBy(0,r.Height() + 10);
	BStringView *label = new BStringView(r,"inglabel","Ingredients:");
	back->AddChild(label);
	
	r.OffsetBy(0,r.Height() + 10);
	r.bottom = r.top + 100;
	r.right -= B_V_SCROLL_BAR_WIDTH;
	
	BRect textrect = r.OffsetToCopy(0,0);
	textrect.InsetBy(10,10);
	fIngredientBox = new BTextView(r, "ingredients", textrect, B_FOLLOW_ALL,
									B_WILL_DRAW | B_PULSE_NEEDED | B_NAVIGABLE |
									B_NAVIGABLE_JUMP);
	fIngredientBox->SetDoesUndo(true);
	
	
	BScrollView *ingredscroll = new BScrollView("ingredients_scroller",fIngredientBox,
										B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,0,false, true);
	back->AddChild(ingredscroll);
	
	r = ingredscroll->Frame();
	
	label = new BStringView(BRect(10,10,11,11),"dirlabel","Directions:");
	label->ResizeToPreferred();
	label->MoveTo(10, r.bottom + 10);
	back->AddChild(label);
	
	r.OffsetBy(0,r.Height() + 20 + label->Frame().Height());
	r.right -= B_V_SCROLL_BAR_WIDTH;
	textrect = r.OffsetToCopy(0,0);
	textrect.InsetBy(10,10);
	fDirectionsBox = new BTextView(r, "directions", textrect, B_FOLLOW_ALL,
									B_WILL_DRAW | B_PULSE_NEEDED | B_NAVIGABLE |
									B_NAVIGABLE_JUMP);
	fDirectionsBox->SetDoesUndo(true);
	
	BScrollView *dirscroll = new BScrollView("directions_scroller",fDirectionsBox,
										B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,0,false, true);
	back->AddChild(dirscroll);
	
	
	fOK = new BButton(BRect(10,10,11,11),"ok","Cancel", new BMessage(M_ADD_RECIPE),
							B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	fOK->ResizeToPreferred();
	fOK->SetLabel("OK");
	fOK->MoveTo(Bounds().right - fOK->Bounds().Width() - 10,
				Bounds().bottom - fOK->Bounds().Height() - 10);
	r = fOK->Frame();
	back->AddChild(fOK);
	
	r.OffsetBy(-r.Width() - 10, 0);
	fCancel = new BButton(r,"cancel","Cancel",new BMessage(B_QUIT_REQUESTED),
						B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM, B_WILL_DRAW);
	back->AddChild(fCancel);
	
	field->MakeFocus(true);
	
	ResizeTo(Bounds().Width(),
			fDirectionsBox->Parent()->Frame().bottom + 20 + fOK->Bounds().Height());
	
	dirscroll->SetResizingMode(B_FOLLOW_ALL);
	
	// This is the part that's different for editing a recipe as opposed to
	// just adding one to the database
	if(number >= 0 && category)
	{
		SetTitle("Edit Recipe");
		BString name, ingredients, directions;
		if(GetRecipe(number,category,name,ingredients,directions))
		{
			BMenuItem *item = fCategories->FindItem(category);
			if(item)
				item->SetMarked(true);
			
			fNameBox->SetText(name.String());
			fIngredientBox->SetText(ingredients.String());
			fDirectionsBox->SetText(directions.String());
			fOK->SetMessage(new BMessage(M_EDIT_RECIPE));
		}
	}
	
	AddShortcut(B_ENTER, B_COMMAND_KEY, new BMessage(fOK->Command()));
}