FontSelectionView::FontSelectionView(const char* name, const char* label, const BFont* currentFont) : BView(name, B_WILL_DRAW), fMessageTarget(this) { if (currentFont == NULL) { if (!strcmp(Name(), "plain")) fCurrentFont = *be_plain_font; else if (!strcmp(Name(), "bold")) fCurrentFont = *be_bold_font; else if (!strcmp(Name(), "fixed")) fCurrentFont = *be_fixed_font; else if (!strcmp(Name(), "menu")) { menu_info info; get_menu_info(&info); fCurrentFont.SetFamilyAndStyle(info.f_family, info.f_style); fCurrentFont.SetSize(info.font_size); } } else fCurrentFont = *currentFont; fSavedFont = fCurrentFont; fFontsMenu = new BPopUpMenu("font menu"); // font menu fFontsMenuField = new BMenuField("fonts", label, fFontsMenu); fFontsMenuField->SetAlignment(B_ALIGN_RIGHT); // font size BMessage* fontSizeMessage = new BMessage(kMsgSetSize); fontSizeMessage->AddString("name", Name()); fFontSizeSpinner = new BSpinner("font size", B_TRANSLATE("Size:"), fontSizeMessage); fFontSizeSpinner->SetRange(kMinSize, kMaxSize); fFontSizeSpinner->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); // preview fPreviewTextView = new BStringView("preview text", kPreviewText); fPreviewTextView->SetFont(&fCurrentFont); fPreviewTextView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); // box around preview fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS); fPreviewBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) .Add(fPreviewTextView) .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) .TopView() ); _SelectCurrentSize(); }
FontSelectionView::FontSelectionView(const char* name, const char* label, const BFont* currentFont) : BView(name, B_WILL_DRAW), fMessageTarget(this) { if (currentFont == NULL) { if (!strcmp(Name(), "plain")) fCurrentFont = *be_plain_font; else if (!strcmp(Name(), "bold")) fCurrentFont = *be_bold_font; else if (!strcmp(Name(), "fixed")) fCurrentFont = *be_fixed_font; else if (!strcmp(Name(), "menu")) { menu_info info; get_menu_info(&info); fCurrentFont.SetFamilyAndStyle(info.f_family, info.f_style); fCurrentFont.SetSize(info.font_size); } } else fCurrentFont = *currentFont; fSavedFont = fCurrentFont; fSizesMenu = new BPopUpMenu("size menu"); _BuildSizesMenu(); fFontsMenu = new BPopUpMenu("font menu"); // font menu fFontsMenuField = new BMenuField("fonts", label, fFontsMenu); fFontsMenuField->SetAlignment(B_ALIGN_RIGHT); // size menu fSizesMenuField = new BMenuField("size", B_TRANSLATE("Size:"), fSizesMenu); fSizesMenuField->SetAlignment(B_ALIGN_RIGHT); // preview fPreviewText = new BStringView("preview text", B_TRANSLATE_COMMENT("The quick brown fox jumps over the lazy dog.", "Don't translate this literally ! Use a phrase showing all chars " "from A to Z.")); fPreviewText->SetFont(&fCurrentFont); fPreviewText->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)); // box around preview fPreviewBox = new BBox("preview box", B_WILL_DRAW | B_FRAME_EVENTS); fPreviewBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) .Add(fPreviewText) .SetInsets(B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING, B_USE_SMALL_SPACING) .TopView() ); }
SketchApp::SketchApp() : BApplication("application/x-vnd.Prok-Sketch") { // most of this function was ripped out of Be's old HelloWorld Example SketchWindow *mainWindow = NULL; SketchView *aView = NULL; BMenuBar *myMenubar = NULL; BMenu *firstMenu = NULL, *secondMenu = NULL; BRect aRect; menu_info m_info; int32 menubarheight=0; // the price we pay to be font sensitive... get_menu_info(&m_info); menubarheight = (int32)m_info.font_size + 8; aRect.Set(100, 100, 449, 349 + menubarheight); mainWindow = new SketchWindow(aRect); // a pretty standard set of menus aRect.Set(0,0, mainWindow->Bounds().Width(), menubarheight); myMenubar = new BMenuBar(aRect, "menubar"); // main menu firstMenu = new BMenu("Sketch"); firstMenu->AddItem(new BMenuItem("About Sketch", new BMessage(B_ABOUT_REQUESTED), 'A', B_COMMAND_KEY)); firstMenu->AddItem(new BMenuItem("Save", new BMessage(SAVE_BITMAP), 'S', B_COMMAND_KEY)); firstMenu->AddItem(new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q', B_COMMAND_KEY)); ((BMenuItem *)firstMenu->ItemAt(0))->SetTarget(be_app); ((BMenuItem *)firstMenu->ItemAt(1))->SetTarget(be_app); #if __INTEL__ // only cuz the translation kit is busted in R3, will undo in R3.1 //((BMenuItem *)firstMenu->ItemAt(1))->SetEnabled(false); #endif // edit menu secondMenu = new BMenu("Edit"); secondMenu->AddItem(new BMenuItem("Erase", new BMessage(ANIMATED_ERASE), 'E', B_COMMAND_KEY)); myMenubar->AddItem(firstMenu); myMenubar->AddItem(secondMenu); // SketchView aRect.Set(0,menubarheight -1, mainWindow->Bounds().Width(), mainWindow->Bounds().Height()); aView = new SketchView(aRect, "SketchView"); // add views to window mainWindow->AddChild(aView); mainWindow->AddChild(myMenubar); // make window visible mainWindow->Show(); }
BComboBox::ChoiceListView::ChoiceListView(BRect frame, BComboBox *parent) : BView(frame, "_choice_list_view_", B_FOLLOW_ALL_SIDES, B_WILL_DRAW | B_NAVIGABLE), fClickLoc(-100, -100) { fParent = parent; GetFontHeight(&fFontHeight); menu_info mi; get_menu_info(&mi); fForeCol = create_color(0, 0, 0); fBackCol = mi.background_color; fSelCol = create_color(144, 144, 144); SetViewColor(B_TRANSPARENT_COLOR); SetHighColor(fForeCol); fTrackingMouseDown = false; fClickTime = 0; }
void FontSelectionView::_UpdateSystemFont() { font_family family; font_style style; fCurrentFont.GetFamilyAndStyle(&family, &style); if (strcmp(Name(), "menu") == 0) { // The menu font is not handled as a system font menu_info info; get_menu_info(&info); strlcpy(info.f_family, (const char*)family, B_FONT_FAMILY_LENGTH); strlcpy(info.f_style, (const char*)style, B_FONT_STYLE_LENGTH); info.font_size = fCurrentFont.Size(); set_menu_info(&info); } else _set_system_font_(Name(), family, style, fCurrentFont.Size()); }
void SketchApp::ReadyToRun() { // Build a menu into your filepanel for fun and profit! SketchWindow *mainWindow = ((SketchWindow *)FindWindow("Etch-A-Sketch"B_UTF8_REGISTERED)); //BFilePanel *saver = NULL; BMenuField *formatMenu = NULL; BMenu *menu = NULL; BView *saverView = NULL; BRect rect, bounds; menu_info m_info; int32 menubarheight=0; // get some menu measurements get_menu_info(&m_info); menubarheight = (int32)m_info.font_size + 8; // make the filepanel saver = new BFilePanel(B_SAVE_PANEL, NULL, NULL, B_FILE_NODE, false); // _ctor if(saver->Window()->Lock()) { // get a pointer to a view saverView = (BView *)saver->Window()->ChildAt(0); // get a rect for the filepanel's window bounds = saverView->Bounds(); // make a menu menu = new BMenu("Format"); // construct the BMenuFeild for the menu rect.Set(bounds.right - 100, bounds.top + menubarheight, bounds.right - 40, bounds.top + menubarheight + 15); formatMenu = new BMenuField(rect, "format menu", "", menu); formatMenu->SetDivider(0); // Below was ganked from the BeBook //find all the translators BTranslatorRoster *roster = BTranslatorRoster::Default(); int32 num_translators, i; translator_id *translators; const char *translator_name, *translator_info; int32 translator_version; roster->GetAllTranslators(&translators, &num_translators); // function allocates the memory for translators for (i=0;i<num_translators;i++) { const translation_format *fmts; int32 num_fmts; roster->GetTranslatorInfo(translators[i], &translator_name, &translator_info, &translator_version); roster->GetOutputFormats(translators[i], &fmts, &num_fmts); if(fmts[0].group == B_TRANSLATOR_BITMAP) // make sure we only get bitmap translators { BMessage *message = new BMessage(TRANSLATOR); message->AddString("save format", fmts[0].MIME); if(i == 0) mainWindow->PostMessage(message); // this will init 'format' for us menu->AddItem(new BMenuItem(translator_name, message)); } //printf("%s: %s (%.2f)\n", translator_name, translator_info, translator_version/100.); } delete [] translators; // clean up our droppings // found em all menu->SetRadioMode(true); menu->ItemAt(0)->SetMarked(true); menu->SetTargetForItems(mainWindow); saverView->AddChild(formatMenu); saver->Window()->Unlock(); } }