/*static*/ BMenu* AppearancePrefView::_MakeFontMenu(uint32 command, const char* defaultFamily, const char* defaultStyle) { BPopUpMenu* menu = new BPopUpMenu(""); int32 numFamilies = count_font_families(); uint32 flags; for (int32 i = 0; i < numFamilies; i++) { font_family family; if (get_font_family(i, &family, &flags) == B_OK) { BFont font; font_style style; int32 numStyles = count_font_styles(family); for (int32 j = 0; j < numStyles; j++) { if (get_font_style(family, j, &style) == B_OK) { font.SetFamilyAndStyle(family, style); if (IsFontUsable(font)) { BMessage* message = new BMessage(command); const char* size = PrefHandler::Default()->getString(PREF_HALF_FONT_SIZE); message->AddString("font_family", family); message->AddString("font_style", style); message->AddString("font_size", size); char fontMenuLabel[134]; snprintf(fontMenuLabel, sizeof(fontMenuLabel), "%s - %s", family, style); BMenu* fontSizeMenu = _MakeFontSizeMenu(fontMenuLabel, MSG_HALF_FONT_CHANGED, family, style, size); BMenuItem* item = new BMenuItem(fontSizeMenu, message); menu->AddItem(item); if (strcmp(defaultFamily, family) == 0 && strcmp(defaultStyle, style) == 0) item->SetMarked(true); } } } } } if (menu->FindMarked() == NULL) menu->ItemAt(0)->SetMarked(true); return menu; }
bool JobSetupView::UpdateJobData() { fJobData->SetShowPreview(fPreview->Value() == B_CONTROL_ON); fJobData->SetColor(Color()); if (IsHalftoneConfigurationNeeded()) { fJobData->SetGamma(Gamma()); fJobData->SetInkDensity(InkDensity()); fJobData->SetDitherType(DitherType()); } int first_page; int last_page; if (B_CONTROL_ON == fAll->Value()) { first_page = 1; last_page = -1; } else { first_page = atoi(fFromPage->Text()); last_page = atoi(fToPage->Text()); } fJobData->SetFirstPage(first_page); fJobData->SetLastPage(last_page); fJobData->SetPaperSource(PaperSource()); fJobData->SetNup(GetID(gNups, sizeof(gNups) / sizeof(gNups[0]), fNup->FindMarked()->Label(), 1)); if (fPrinterCap->Supports(PrinterCap::kPrintStyle)) { fJobData->SetPrintStyle((B_CONTROL_ON == fDuplex->Value()) ? JobData::kDuplex : JobData::kSimplex); } fJobData->SetCopies(atoi(fCopies->Text())); fJobData->SetCollate(B_CONTROL_ON == fCollate->Value()); fJobData->SetReverse(B_CONTROL_ON == fReverse->Value()); JobData::PageSelection pageSelection = JobData::kAllPages; if (fOddNumberedPages->Value() == B_CONTROL_ON) pageSelection = JobData::kOddNumberedPages; if (fEvenNumberedPages->Value() == B_CONTROL_ON) pageSelection = JobData::kEvenNumberedPages; fJobData->SetPageSelection(pageSelection); { std::map<PrinterCap::CapID, BPopUpMenu*>::iterator it = fDriverSpecificPopUpMenus.begin(); for(; it != fDriverSpecificPopUpMenus.end(); it++) { PrinterCap::CapID category = it->first; BPopUpMenu* popUpMenu = it->second; const char* key = fPrinterCap->FindCap( PrinterCap::kDriverSpecificCapabilities, (int)category)->Key(); const char* label = popUpMenu->FindMarked()->Label(); const char* value = static_cast<const EnumCap*>(fPrinterCap-> FindCap(category, label))->Key(); fJobData->Settings().SetString(key, value); } } { std::map<string, BCheckBox*>::iterator it = fDriverSpecificCheckBoxes.begin(); for(; it != fDriverSpecificCheckBoxes.end(); it++) { const char* key = it->first.c_str(); BCheckBox* checkBox = it->second; bool value = checkBox->Value() == B_CONTROL_ON; fJobData->Settings().SetBoolean(key, value); } } { std::map<PrinterCap::CapID, IntRange>::iterator it = fDriverSpecificIntSliders.begin(); for(; it != fDriverSpecificIntSliders.end(); it++) { IntRange& range = it->second; fJobData->Settings().SetInt(range.Key(), range.Value()); } } { std::map<PrinterCap::CapID, DoubleRange>::iterator it = fDriverSpecificDoubleSliders.begin(); for(; it != fDriverSpecificDoubleSliders.end(); it++) { DoubleRange& range = it->second; fJobData->Settings().SetDouble(range.Key(), range.Value()); } } fJobData->Save(); return true; }
TemplateWindow::TemplateWindow(const BRect& frame) : BWindow(frame, TR("Choose a project type"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { RegisterWindow(); CheckTemplates(); DPath templatePath(gAppPath.GetFolder()); templatePath << TR("Templates"); fTempList.ScanFolder(templatePath.GetFullPath()); // project type BPopUpMenu* projectTypeMenu = new BPopUpMenu("Project type"); for (int32 i = 0; i < fTempList.CountTemplates(); i++) { ProjectTemplate* ptemp = fTempList.TemplateAt(i); entry_ref ref = ptemp->GetRef(); projectTypeMenu->AddItem(new BMenuItem(ref.name, new BMessage(M_TEMPLATE_SELECTED))); } projectTypeMenu->ItemAt(0L)->SetMarked(true); fTemplateField = new BMenuField("templatefield", TR("Project type: "), projectTypeMenu); fTemplateField->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); // project name fNameBox = new AutoTextControl("namebox", TR("Project name:"), "", new BMessage(M_NAME_CHANGED)); SetToolTip(fNameBox, TR("The name of your project. " "It can be the same as the Target name, but it does not have to be.")); // target name fTargetBox = new AutoTextControl("targetbox", TR("Target name:"), "BeApp", new BMessage(M_TARGET_CHANGED)); SetToolTip(fTargetBox, TR("The name of the compiled application or library")); // project path fPathBox = new PathBox("pathbox", gProjectPath.GetFullPath(), ""); fPathBox->SetExplicitMinSize(BSize(be_plain_font->StringWidth("M") * 36, B_SIZE_UNSET)), SetToolTip(fPathBox, TR("Set the location for your project.")); // source control BPopUpMenu* scmMenu = new BPopUpMenu("SCM Chooser"); scmMenu->AddItem(new BMenuItem(TR("Mercurial"), new BMessage())); scmMenu->AddItem(new BMenuItem(TR("Git"), new BMessage())); scmMenu->AddItem(new BMenuItem(TR("Subversion"), new BMessage())); scmMenu->AddItem(new BMenuItem(TR("None"), new BMessage())); if (!gHgAvailable) { scmMenu->ItemAt(0)->SetEnabled(false); scmMenu->ItemAt(0)->SetLabel(TR("Mercurial unavailable")); } if (!gGitAvailable) { scmMenu->ItemAt(1)->SetEnabled(false); scmMenu->ItemAt(1)->SetLabel(TR("Git unavailable")); } if (!gSvnAvailable) { scmMenu->ItemAt(2)->SetEnabled(false); scmMenu->ItemAt(2)->SetLabel(TR("Subversion unavailable")); } fSCMChooser = new BMenuField("scmchooser", TR("Source control: "), scmMenu); fSCMChooser->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetToolTip(fSCMChooser, TR("Choose the source control manager for your project, if any.")); scmMenu->ItemAt(gDefaultSCM)->SetMarked(true); BMenuItem* item = scmMenu->FindMarked(); if (!item->IsEnabled()) { item->SetMarked(false); for (int32 i = 0; i < scmMenu->CountItems(); i++) { if (scmMenu->ItemAt(i)->IsEnabled()) { scmMenu->ItemAt(i)->SetMarked(true); break; } } } // create folder check box fCreateFolder = new BCheckBox(TR("Create project folder")); fCreateFolder->SetValue(B_CONTROL_ON); SetToolTip(fCreateFolder, TR("If checked, a folder for your project will be created " "in the folder in the Location box above.")); // create project button fCreateProjectButton = new BButton("ok", TR("Create project") B_UTF8_ELLIPSIS, new BMessage(M_CREATE_PROJECT)); fCreateProjectButton->SetEnabled(false); fCreateProjectButton->MakeDefault(true); // layout BLayoutBuilder::Group<>(this, B_VERTICAL) .AddGrid(B_USE_DEFAULT_SPACING, B_USE_SMALL_SPACING) .Add(fTemplateField->CreateLabelLayoutItem(), 0, 0) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 0) .Add(fTemplateField->CreateMenuBarLayoutItem()) .AddGlue() .End() .Add(fNameBox->CreateLabelLayoutItem(), 0, 1) .Add(fNameBox->CreateTextViewLayoutItem(), 1, 1) .Add(fTargetBox->CreateLabelLayoutItem(), 0, 2) .Add(fTargetBox->CreateTextViewLayoutItem(), 1, 2) .Add(new BStringView("location", TR("Location:")), 0, 3) .Add(fPathBox, 1, 3) .Add(fSCMChooser->CreateLabelLayoutItem(), 0, 4) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1, 4) .Add(fSCMChooser->CreateMenuBarLayoutItem()) .AddGlue() .End() .Add(fCreateFolder, 1, 5) .End() .AddGlue() .AddGroup(B_HORIZONTAL) .AddGlue() .Add(fCreateProjectButton) .End() .SetInsets(B_USE_DEFAULT_SPACING) .End(); fNameBox->MakeFocus(true); CenterOnScreen(); }
/*! * \brief Create a menu to select the module user is setting up. * \note This is an internal function. */ BPopUpMenu* CalendarModulePreferencesView::PopulateModulesMenu( void ) { BPopUpMenu* toReturn = NULL; BMenuItem* toAdd = NULL; BMessage* toSend = NULL; BString moduleId; // Note: this is not a pointer! CalendarModule* currentCalModule = NULL; toReturn = new BPopUpMenu("Calendar Modules"); if ( ! toReturn ) { /* Panic! */ exit (1); } // Looping on all calendar modules available in the system. for ( uint i=0; i < NUMBER_OF_CALENDAR_MODULES; ++i ) { // Obtain the next calendar module currentCalModule = (CalendarModule *)global_ListOfCalendarModules.ItemAt( i ); if ( !currentCalModule ) { continue; // Skipping unavailable ones } // Create the message toSend = new BMessage( kCalendarModuleChosen ); if ( !toSend ) { /* Panic! */ exit(1); } // Add the ID of the module to the message moduleId = currentCalModule->Identify(); toSend->AddString( "Module ID", moduleId ); // Create the menu item toAdd = new BMenuItem( moduleId.String(), toSend ); if ( ! toAdd ) { /* Panic! */ exit(1); } toAdd->SetTarget( this ); // Add the newly created item to the menu toReturn->AddItem( toAdd ); // Gregorian calendar module is the default one if ( moduleId == "Gregorian" ) { toAdd->SetMarked( true ); } } /* <-- end of "for ( every calendar module )" */ // At least something should be marked. if ( ( ! toReturn->FindMarked() ) && ( toReturn->CountItems() > 0 ) ) { toReturn->ItemAt( 0 )->SetMarked( true ); } return toReturn; } // <-- end of function "CalendarModulePreferencesView::PopulateModulesMenu"