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())); }
ScheduleAddWindow::ScheduleAddWindow(const BRect &frame, const TransactionData &data) : BWindow(frame,TRANSLATE("Schedule Transaction"),B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL,B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_MINIMIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), fTransData(data) { AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); BView *back = new BView("backview",B_WILL_DRAW); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .SetInsets(0) .Add(back) .End(); back->SetViewColor(240,240,240); BString label; label << TRANSLATE("Type") << ": " << data.Type().Type(); BStringView *typelabel = new BStringView("typelabel", label.String()); label = TRANSLATE("Payee"); label << ": " << data.Payee(); BStringView *payeelabel = new BStringView("payeelabel",label.String()); BString temp; gCurrentLocale.CurrencyToString(data.Amount().AbsoluteValue(),temp); label = TRANSLATE("Amount"); label << ": " << temp; BStringView *amountlabel = new BStringView("amountlabel",label.String()); label = TRANSLATE("Category"); label+=": "; if(data.CountCategories()>1) label << TRANSLATE("Split"); else label << data.NameAt(0); BStringView *categorylabel = new BStringView("categorylabel",label.String()); label = TRANSLATE("Memo"); label << ": " << data.Memo(); BStringView *memolabel = new BStringView("memolabel",label.String()); // Since layout-api, we need other way to make divider // BBox *divider = new BBox(r); // AddChild(divider); fIntervalMenu = new BMenu(TRANSLATE("Frequency")); fIntervalMenu->AddItem(new BMenuItem(TRANSLATE("Monthly"), new BMessage(M_SCHEDULED_MONTHLY))); fIntervalMenu->AddItem(new BMenuItem(TRANSLATE("Quarterly"), new BMessage(M_SCHEDULED_QUARTERLY))); fIntervalMenu->AddItem(new BMenuItem(TRANSLATE("Annually"), new BMessage(M_SCHEDULED_ANNUALLY))); fIntervalMenu->ItemAt(0)->SetMarked(true); fIntervalMenu->SetLabelFromMarked(true); temp = TRANSLATE("Frequency"); temp += ": "; BMenuField *intervalfield = new BMenuField("intervalfield", temp.String(),fIntervalMenu); temp = TRANSLATE("Starting Date"); temp += ": "; fStartDate = new DateBox("startdate",temp.String(),"", new BMessage(M_DATE_CHANGED)); fStartDate->UseTabFiltering(false); gDefaultLocale.DateToString(data.Date(),temp); fStartDate->SetText(temp.String()); fRepeatAlways = new BRadioButton("inftimes",TRANSLATE("Indefinitely"), new BMessage(M_REPEAT_ALWAYS)); fRepeatLimited = new BRadioButton("limitedtimes","",new BMessage(M_REPEAT_LIMITED)); fRepeatCount = new NumBox("repeatcount",NULL,"999", new BMessage(M_COUNT_CHANGED)); fRepeatCount->UseTabFiltering(false); fRepeatCount->SetEnabled(false); BStringView *timeslabel = new BStringView("timeslabel",TRANSLATE("times")); fRepeatAlways->SetValue(B_CONTROL_ON); intervalfield->MakeFocus(true); BButton *okbutton = new BButton("okbutton",TRANSLATE("Cancel"), new BMessage(M_SCHEDULE_TRANSACTION)); okbutton->MakeDefault(true); okbutton->SetLabel(TRANSLATE("OK")); BButton *cancelbutton = new BButton("cancelbutton", TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED)); cancelbutton->MakeDefault(true); BLayoutBuilder::Group<>(back, B_VERTICAL) .SetInsets(10) .AddGrid(8.0f, 1.0f) .Add(typelabel, 0, 0) .Add(payeelabel, 1, 0) .Add(amountlabel, 2, 0) .Add(categorylabel, 0, 1) .Add(memolabel, 1, 1) .End() .AddGrid(1.0f, 1.0f) .Add(intervalfield, 0, 0) .Add(fRepeatAlways, 1, 0) .Add(fStartDate, 0, 1) .AddGrid(1.0f, 1.0f, 1, 1) .Add(fRepeatLimited, 0, 0) .Add(fRepeatCount, 1, 0) .End() .End() .AddGrid(1.0f, 1.0f) .AddGlue(0, 0) .Add(cancelbutton, 1, 0) .Add(okbutton, 2, 0) .End() .End(); }