void PadView::DisplayMenu(BPoint where, LaunchButton* button) const { MainWindow* window = dynamic_cast<MainWindow*>(Window()); if (window == NULL) return; LaunchButton* nearestButton = button; if (!nearestButton) { // find the nearest button for (int32 i = 0; (nearestButton = ButtonAt(i)); i++) { if (nearestButton->Frame().top > where.y) break; } } BPopUpMenu* menu = new BPopUpMenu(B_TRANSLATE("launch popup"), false, false); // add button BMessage* message = new BMessage(MSG_ADD_SLOT); message->AddPointer("be:source", (void*)nearestButton); BMenuItem* item = new BMenuItem(B_TRANSLATE("Add button here"), message); item->SetTarget(window); menu->AddItem(item); // button options if (button) { // clear button message = new BMessage(MSG_CLEAR_SLOT); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Clear button"), message); item->SetTarget(window); menu->AddItem(item); // remove button message = new BMessage(MSG_REMOVE_SLOT); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Remove button"), message); item->SetTarget(window); menu->AddItem(item); // set button description if (button->Ref()) { message = new BMessage(MSG_SET_DESCRIPTION); message->AddPointer("be:source", (void*)button); item = new BMenuItem(B_TRANSLATE("Set description"B_UTF8_ELLIPSIS), message); item->SetTarget(window); menu->AddItem(item); } } menu->AddSeparatorItem(); // window settings BMenu* settingsM = new BMenu(B_TRANSLATE("Settings")); settingsM->SetFont(be_plain_font); const char* toggleLayoutLabel; if (fButtonLayout->Orientation() == B_HORIZONTAL) toggleLayoutLabel = B_TRANSLATE("Vertical layout"); else toggleLayoutLabel = B_TRANSLATE("Horizontal layout"); item = new BMenuItem(toggleLayoutLabel, new BMessage(MSG_TOGGLE_LAYOUT)); item->SetTarget(this); settingsM->AddItem(item); BMenu* iconSizeM = new BMenu(B_TRANSLATE("Icon size")); for (uint32 i = 0; i < sizeof(kIconSizes) / sizeof(uint32); i++) { uint32 iconSize = kIconSizes[i]; message = new BMessage(MSG_SET_ICON_SIZE); message->AddInt32("size", iconSize); BString label; label << iconSize << " x " << iconSize; item = new BMenuItem(label.String(), message); item->SetTarget(this); item->SetMarked(IconSize() == iconSize); iconSizeM->AddItem(item); } settingsM->AddItem(iconSizeM); item = new BMenuItem(B_TRANSLATE("Ignore double-click"), new BMessage(MSG_SET_IGNORE_DOUBLECLICK)); item->SetTarget(this); item->SetMarked(IgnoreDoubleClick()); settingsM->AddItem(item); uint32 what = window->Look() == B_BORDERED_WINDOW_LOOK ? MSG_SHOW_BORDER : MSG_HIDE_BORDER; item = new BMenuItem(B_TRANSLATE("Show window border"), new BMessage(what)); item->SetTarget(window); item->SetMarked(what == MSG_HIDE_BORDER); settingsM->AddItem(item); item = new BMenuItem(B_TRANSLATE("Auto-raise"), new BMessage(MSG_TOGGLE_AUTORAISE)); item->SetTarget(window); item->SetMarked(window->AutoRaise()); settingsM->AddItem(item); item = new BMenuItem(B_TRANSLATE("Show on all workspaces"), new BMessage(MSG_SHOW_ON_ALL_WORKSPACES)); item->SetTarget(window); item->SetMarked(window->ShowOnAllWorkspaces()); settingsM->AddItem(item); menu->AddItem(settingsM); menu->AddSeparatorItem(); // pad commands BMenu* padM = new BMenu(B_TRANSLATE("Pad")); padM->SetFont(be_plain_font); // new pad item = new BMenuItem(B_TRANSLATE("New"), new BMessage(MSG_ADD_WINDOW)); item->SetTarget(be_app); padM->AddItem(item); // new pad item = new BMenuItem(B_TRANSLATE("Clone"), new BMessage(MSG_ADD_WINDOW)); item->SetTarget(window); padM->AddItem(item); padM->AddSeparatorItem(); // close item = new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED)); item->SetTarget(window); padM->AddItem(item); menu->AddItem(padM); // app commands BMenu* appM = new BMenu(B_TRANSLATE_SYSTEM_NAME("LaunchBox")); appM->SetFont(be_plain_font); // quit item = new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED)); item->SetTarget(be_app); appM->AddItem(item); menu->AddItem(appM); // finish popup menu->SetAsyncAutoDestruct(true); menu->SetFont(be_plain_font); where = ConvertToScreen(where); BRect mouseRect(where, where); mouseRect.InsetBy(-4.0, -4.0); menu->Go(where, true, false, mouseRect, true); }
ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry) : BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), B_TRANSLATE("Application type"), B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_FRAME_EVENTS | B_AUTO_UPDATE_SIZE_LIMITS), fChangedProperties(0) { float padding = be_control_look->DefaultItemSpacing(); BAlignment labelAlignment = be_control_look->DefaultLabelAlignment(); BMenuBar* menuBar = new BMenuBar((char*)NULL); menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); BMenu* menu = new BMenu(B_TRANSLATE("File")); fSaveMenuItem = new BMenuItem(B_TRANSLATE("Save"), new BMessage(kMsgSave), 'S'); fSaveMenuItem->SetEnabled(false); menu->AddItem(fSaveMenuItem); BMenuItem* item; menu->AddItem(item = new BMenuItem( B_TRANSLATE("Save into resource file" B_UTF8_ELLIPSIS), NULL)); item->SetEnabled(false); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Close"), new BMessage(B_QUIT_REQUESTED), 'W', B_COMMAND_KEY)); menuBar->AddItem(menu); // Signature fSignatureControl = new BTextControl(B_TRANSLATE("Signature:"), NULL, new BMessage(kMsgSignatureChanged)); fSignatureControl->SetModificationMessage( new BMessage(kMsgSignatureChanged)); // filter out invalid characters that can't be part of a MIME type name BTextView* textView = fSignatureControl->TextView(); textView->SetMaxBytes(B_MIME_TYPE_LENGTH); const char* disallowedCharacters = "<>@,;:\"()[]?= "; for (int32 i = 0; disallowedCharacters[i]; i++) { textView->DisallowChar(disallowedCharacters[i]); } // "Application Flags" group BBox* flagsBox = new BBox("flagsBox"); fFlagsCheckBox = new BCheckBox("flags", B_TRANSLATE("Application flags"), new BMessage(kMsgToggleAppFlags)); fFlagsCheckBox->SetValue(B_CONTROL_ON); fSingleLaunchButton = new BRadioButton("single", B_TRANSLATE("Single launch"), new BMessage(kMsgAppFlagsChanged)); fMultipleLaunchButton = new BRadioButton("multiple", B_TRANSLATE("Multiple launch"), new BMessage(kMsgAppFlagsChanged)); fExclusiveLaunchButton = new BRadioButton("exclusive", B_TRANSLATE("Exclusive launch"), new BMessage(kMsgAppFlagsChanged)); fArgsOnlyCheckBox = new BCheckBox("args only", B_TRANSLATE("Args only"), new BMessage(kMsgAppFlagsChanged)); fBackgroundAppCheckBox = new BCheckBox("background", B_TRANSLATE("Background app"), new BMessage(kMsgAppFlagsChanged)); BLayoutBuilder::Grid<>(flagsBox, 0, 0) .SetInsets(padding, padding * 2, padding, padding) .Add(fSingleLaunchButton, 0, 0).Add(fArgsOnlyCheckBox, 1, 0) .Add(fMultipleLaunchButton, 0, 1).Add(fBackgroundAppCheckBox, 1, 1) .Add(fExclusiveLaunchButton, 0, 2); flagsBox->SetLabel(fFlagsCheckBox); // "Icon" group BBox* iconBox = new BBox("IconBox"); iconBox->SetLabel(B_TRANSLATE("Icon")); fIconView = new IconView("icon"); fIconView->SetModificationMessage(new BMessage(kMsgIconChanged)); BLayoutBuilder::Group<>(iconBox, B_HORIZONTAL) .SetInsets(padding, padding * 2, padding, padding) .Add(fIconView); // "Supported Types" group BBox* typeBox = new BBox("typesBox"); typeBox->SetLabel(B_TRANSLATE("Supported types")); fTypeListView = new SupportedTypeListView("Suppported Types", B_SINGLE_SELECTION_LIST); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); fAddTypeButton = new BButton("add type", B_TRANSLATE("Add" B_UTF8_ELLIPSIS), new BMessage(kMsgAddType)); fRemoveTypeButton = new BButton("remove type", B_TRANSLATE("Remove"), new BMessage(kMsgRemoveType)); fTypeIconView = new IconView("type icon"); BGroupView* iconHolder = new BGroupView(B_HORIZONTAL); iconHolder->AddChild(fTypeIconView); fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged)); BLayoutBuilder::Grid<>(typeBox, padding, padding) .SetInsets(padding, padding * 2, padding, padding) .Add(scrollView, 0, 0, 1, 4) .Add(fAddTypeButton, 1, 0, 1, 2) .Add(fRemoveTypeButton, 1, 2, 1, 2) .Add(iconHolder, 2, 1, 1, 2) .SetColumnWeight(0, 3) .SetColumnWeight(1, 2) .SetColumnWeight(2, 1); iconHolder->SetExplicitAlignment( BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE)); // "Version Info" group BBox* versionBox = new BBox("versionBox"); versionBox->SetLabel(B_TRANSLATE("Version info")); fMajorVersionControl = new BTextControl(B_TRANSLATE("Version:"), NULL, NULL); _MakeNumberTextControl(fMajorVersionControl); fMiddleVersionControl = new BTextControl(".", NULL, NULL); _MakeNumberTextControl(fMiddleVersionControl); fMinorVersionControl = new BTextControl(".", NULL, NULL); _MakeNumberTextControl(fMinorVersionControl); fVarietyMenu = new BPopUpMenu("variety", true, true); fVarietyMenu->AddItem(new BMenuItem(B_TRANSLATE("Development"), NULL)); fVarietyMenu->AddItem(new BMenuItem(B_TRANSLATE("Alpha"), NULL)); fVarietyMenu->AddItem(new BMenuItem(B_TRANSLATE("Beta"), NULL)); fVarietyMenu->AddItem(new BMenuItem(B_TRANSLATE("Gamma"), NULL)); item = new BMenuItem(B_TRANSLATE("Golden master"), NULL); fVarietyMenu->AddItem(item); item->SetMarked(true); fVarietyMenu->AddItem(new BMenuItem(B_TRANSLATE("Final"), NULL)); BMenuField* varietyField = new BMenuField("", fVarietyMenu); fInternalVersionControl = new BTextControl("/", NULL, NULL); fShortDescriptionControl = new BTextControl(B_TRANSLATE("Short description:"), NULL, NULL); // TODO: workaround for a GCC 4.1.0 bug? Or is that really what the standard says? version_info versionInfo; fShortDescriptionControl->TextView()->SetMaxBytes( sizeof(versionInfo.short_info)); BStringView* longLabel = new BStringView(NULL, B_TRANSLATE("Long description:")); longLabel->SetExplicitAlignment(labelAlignment); fLongDescriptionView = new TabFilteringTextView("long desc"); fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info)); scrollView = new BScrollView("desc scrollview", fLongDescriptionView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); // TODO: remove workaround (bug #5678) BSize minScrollSize = scrollView->ScrollBar(B_VERTICAL)->MinSize(); minScrollSize.width += fLongDescriptionView->MinSize().width; scrollView->SetExplicitMinSize(minScrollSize); // Manually set a minimum size for the version text controls // TODO: the same does not work when applied to the layout items float width = be_plain_font->StringWidth("99") + 16; fMajorVersionControl->TextView()->SetExplicitMinSize( BSize(width, fMajorVersionControl->MinSize().height)); fMiddleVersionControl->TextView()->SetExplicitMinSize( BSize(width, fMiddleVersionControl->MinSize().height)); fMinorVersionControl->TextView()->SetExplicitMinSize( BSize(width, fMinorVersionControl->MinSize().height)); fInternalVersionControl->TextView()->SetExplicitMinSize( BSize(width, fInternalVersionControl->MinSize().height)); BLayoutBuilder::Grid<>(versionBox, padding / 2, padding / 2) .SetInsets(padding, padding * 2, padding, padding) .Add(fMajorVersionControl->CreateLabelLayoutItem(), 0, 0) .Add(fMajorVersionControl->CreateTextViewLayoutItem(), 1, 0) .Add(fMiddleVersionControl, 2, 0, 2) .Add(fMinorVersionControl, 4, 0, 2) .Add(varietyField, 6, 0, 3) .Add(fInternalVersionControl, 9, 0, 2) .Add(fShortDescriptionControl->CreateLabelLayoutItem(), 0, 1) .Add(fShortDescriptionControl->CreateTextViewLayoutItem(), 1, 1, 10) .Add(longLabel, 0, 2) .Add(scrollView, 1, 2, 10, 3) .SetRowWeight(3, 3); // put it all together BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .SetInsets(0, 0, 0, 0) .Add(menuBar) .AddGroup(B_VERTICAL, padding) .SetInsets(padding, padding, padding, padding) .Add(fSignatureControl) .AddGroup(B_HORIZONTAL, padding) .Add(flagsBox, 3) .Add(iconBox, 1) .End() .Add(typeBox) .Add(versionBox); SetKeyMenuBar(menuBar); fSignatureControl->MakeFocus(true); BMimeType::StartWatching(this); _SetTo(entry); }
void MediaWindow::MessageReceived(BMessage* message) { switch(message->what) { case ML_INIT_MEDIA: InitMedia(false); break; case ML_RESTART_MEDIA_SERVER: { thread_id thread = spawn_thread(&MediaWindow::RestartMediaServices, "restart_thread", B_NORMAL_PRIORITY, this); if (thread < B_OK) fprintf(stderr, "couldn't create restart thread\n"); else resume_thread(thread); break; } case B_MEDIA_WEB_CHANGED: case ML_SELECTED_NODE: { PRINT_OBJECT(*message); MediaListItem* item = static_cast<MediaListItem*>( fListView->ItemAt(fListView->CurrentSelection())); if (!item) break; fCurrentNode.SetTo(NULL); _ClearParamView(); item->AlterWindow(this); break; } case B_SOME_APP_LAUNCHED: { PRINT_OBJECT(*message); if (!fAlert) break; BString mimeSig; if (message->FindString("be:signature", &mimeSig) == B_OK && (mimeSig == "application/x-vnd.Be.addon-host" || mimeSig == "application/x-vnd.Be.media-server")) { fAlert->Lock(); fAlert->TextView()->SetText( B_TRANSLATE("Starting media server" B_UTF8_ELLIPSIS)); fAlert->Unlock(); } } break; case B_SOME_APP_QUIT: { PRINT_OBJECT(*message); BString mimeSig; if (message->FindString("be:signature", &mimeSig) == B_OK) { if (mimeSig == "application/x-vnd.Be.addon-host" || mimeSig == "application/x-vnd.Be.media-server") { BMediaRoster* roster = BMediaRoster::CurrentRoster(); if (roster && roster->Lock()) roster->Quit(); } } } break; default: BWindow::MessageReceived(message); break; } }
// Handling of user interface and other events void MainWindow::MessageReceived(BMessage *message) { switch(message->what){ case SELECTION_CHANGED: BRow *row; row = teamView->RowAt(message->FindInt32("index")); if(row != NULL && message->FindInt32("buttons") == B_SECONDARY_MOUSE_BUTTON){ BPoint point; uint32 state; teamView->GetMouse(&point,&state); BPoint p2 = teamView->ConvertToScreen(point); p2.x -= 5.0; p2.y -= 5.0; //if(fItemMenu->FindMarked()) // fItemMenu->FindMarked()->SetMarked(false); teamView->SelectionMessage()->ReplaceInt32("buttons",0); teamView->ActionMenu()->Go(p2, true, true, true); //fItemMenu->Go(p2, true, true, true); } SetButtonState(); break; case IE_MAINWINDOW_MAINMENU_ACTION_KILL: case IE_MAINWINDOW_MAINKILL: DoKill(); UpdateTeams(); SetButtonState(); break; case IE_MAINWINDOW_MAINMENU_ACTION_SUSPEND: case IE_MAINWINDOW_MAINSUSPEND: DoSuspend(); UpdateTeams(); SetButtonState(); break; case IE_MAINWINDOW_MAINMENU_ACTION_RESUME: case IE_MAINWINDOW_MAINRESUME: DoResume(); UpdateTeams(); SetButtonState(); break; case SET_PRIORITY: { int32 priority = message->FindInt32("priority"); DoPriority(priority); UpdateTeams(); SetButtonState(); break; } case IE_MAINWINDOW_MAINPRIORITYVALUE: // takes priority from text field DoPriority(); UpdateTeams(); SetButtonState(); break; case IE_MAINWINDOW_MAINUPDATE: UpdateTeams(); SetButtonState(); break; case B_ABOUT_REQUESTED: // "About…" is selected from menu… { BAboutWindow* fAboutWin = new BAboutWindow(B_TRANSLATE_SYSTEM_NAME("Slayer"), slayer_signature); fAboutWin->AddDescription(B_TRANSLATE("A thread manager for Haiku")); fAboutWin->SetVersion(SLAYER_VERSION); fAboutWin->AddCopyright(1999, "Arto Jalkanen"); const char* authors[] = { "Arto Jalkanen ([email protected])", NULL }; fAboutWin->AddAuthors(authors); fAboutWin->Show(); } break; case IE_MAINWINDOW_MAINMENU_FILE_DOCS__: { BMessage message(B_REFS_RECEIVED); message.AddString("url", ProjectWebsite); be_roster->Launch("text/html", &message); } break; case IE_MAINWINDOW_MAINMENU_FILE_QUIT: // "Quit" is selected from menu… be_app->PostMessage(B_QUIT_REQUESTED); break; case IE_MAINWINDOW_MAINMENU_WINDOWS_SETTINGS: { const char* windowSettingsTitle = B_TRANSLATE("Settings"); BWindow *settings = slayer->FindWindow(windowSettingsTitle); if (!settings) new SettingsWindow(windowSettingsTitle); else if (settings->Lock()) { settings->Activate(true); settings->Unlock(); } } break; default: BWindow::MessageReceived(message); break; } }
void TouchpadPrefView::SetupView() { SetLayout(new BGroupLayout(B_VERTICAL)); BBox* scrollBox = new BBox("Touchpad"); scrollBox->SetLabel(B_TRANSLATE("Scrolling")); fTouchpadView = new TouchpadView(BRect(0, 0, 130, 120)); fTouchpadView->SetExplicitMaxSize(BSize(130, 120)); // Create the "Mouse Speed" slider... fScrollAccelSlider = new BSlider("scroll_accel", B_TRANSLATE("Scroll acceleration"), new BMessage(SCROLL_CONTROL_CHANGED), 0, 20, B_HORIZONTAL); fScrollAccelSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fScrollAccelSlider->SetHashMarkCount(7); fScrollAccelSlider->SetLimitLabels(B_TRANSLATE("Slow"), B_TRANSLATE("Fast")); fScrollStepXSlider = new BSlider("scroll_stepX", B_TRANSLATE("Horizontal scroll speed"), new BMessage(SCROLL_CONTROL_CHANGED), 0, 20, B_HORIZONTAL); fScrollStepXSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fScrollStepXSlider->SetHashMarkCount(7); fScrollStepXSlider->SetLimitLabels(B_TRANSLATE("Slow"), B_TRANSLATE("Fast")); fScrollStepYSlider = new BSlider("scroll_stepY", B_TRANSLATE("Vertical scroll speed"), new BMessage(SCROLL_CONTROL_CHANGED), 0, 20, B_HORIZONTAL); fScrollStepYSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fScrollStepYSlider->SetHashMarkCount(7); fScrollStepYSlider->SetLimitLabels(B_TRANSLATE("Slow"), B_TRANSLATE("Fast")); fTwoFingerBox = new BCheckBox(B_TRANSLATE("Two finger scrolling"), new BMessage(SCROLL_CONTROL_CHANGED)); fTwoFingerHorizontalBox = new BCheckBox( B_TRANSLATE("Horizontal scrolling"), new BMessage(SCROLL_CONTROL_CHANGED)); BGroupView* scrollPrefLeftLayout = new BGroupView(B_VERTICAL); BLayoutBuilder::Group<>(scrollPrefLeftLayout) .Add(fTouchpadView) .Add(fTwoFingerBox) .AddGroup(B_HORIZONTAL) .AddStrut(20) .Add(fTwoFingerHorizontalBox); BGroupView* scrollPrefRightLayout = new BGroupView(B_VERTICAL); scrollPrefRightLayout->AddChild(fScrollAccelSlider); scrollPrefRightLayout->AddChild(fScrollStepXSlider); scrollPrefRightLayout->AddChild(fScrollStepYSlider); BGroupLayout* scrollPrefLayout = new BGroupLayout(B_HORIZONTAL); scrollPrefLayout->SetSpacing(10); scrollPrefLayout->SetInsets(10, scrollBox->TopBorderOffset() * 2 + 10, 10, 10); scrollBox->SetLayout(scrollPrefLayout); scrollPrefLayout->AddView(scrollPrefLeftLayout); scrollPrefLayout->AddItem(BSpaceLayoutItem::CreateVerticalStrut(15)); scrollPrefLayout->AddView(scrollPrefRightLayout); BBox* tapBox = new BBox("tapbox"); tapBox->SetLabel(B_TRANSLATE("Tap gesture")); BGroupLayout* tapPrefLayout = new BGroupLayout(B_HORIZONTAL); tapPrefLayout->SetInsets(10, tapBox->TopBorderOffset() * 2 + 10, 10, 10); tapBox->SetLayout(tapPrefLayout); fTapSlider = new BSlider("tap_sens", B_TRANSLATE("Tap click sensitivity"), new BMessage(TAP_CONTROL_CHANGED), 0, 20, B_HORIZONTAL); fTapSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fTapSlider->SetHashMarkCount(7); fTapSlider->SetLimitLabels(B_TRANSLATE("Off"), B_TRANSLATE("High")); tapPrefLayout->AddView(fTapSlider); BGroupView* buttonView = new BGroupView(B_HORIZONTAL); fDefaultButton = new BButton(B_TRANSLATE("Defaults"), new BMessage(DEFAULT_SETTINGS)); buttonView->AddChild(fDefaultButton); buttonView->GetLayout()->AddItem( BSpaceLayoutItem::CreateHorizontalStrut(7)); fRevertButton = new BButton(B_TRANSLATE("Revert"), new BMessage(REVERT_SETTINGS)); fRevertButton->SetEnabled(false); buttonView->AddChild(fRevertButton); buttonView->GetLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); BGroupLayout* layout = new BGroupLayout(B_VERTICAL); layout->SetInsets(10, 10, 10, 10); layout->SetSpacing(10); BView* rootView = new BView("root view", 0, layout); AddChild(rootView); rootView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); layout->AddView(scrollBox); layout->AddView(tapBox); layout->AddView(buttonView); }
FilterView::FilterView() : BGroupView("filter view", B_VERTICAL) { // Contruct category popup BPopUpMenu* showMenu = new BPopUpMenu(B_TRANSLATE("Category")); fShowField = new BMenuField("category", B_TRANSLATE("Category:"), showMenu); // Construct repository popup BPopUpMenu* repositoryMenu = new BPopUpMenu(B_TRANSLATE("Depot")); fRepositoryField = new BMenuField("repository", B_TRANSLATE("Depot:"), repositoryMenu); // Construct search terms field fSearchTermsText = new BTextControl("search terms", B_TRANSLATE("Search terms:"), "", NULL); fSearchTermsText->SetModificationMessage( new BMessage(MSG_SEARCH_TERMS_MODIFIED)); BSize minSearchSize = fSearchTermsText->MinSize(); float minSearchWidth = be_plain_font->StringWidth(fSearchTermsText->Label()) + be_plain_font->StringWidth("XXX") * 6; minSearchWidth = std::max(minSearchSize.width, minSearchWidth); minSearchSize.width = minSearchWidth; fSearchTermsText->SetExplicitMinSize(minSearchSize); float maxSearchWidth = minSearchWidth * 2; fSearchTermsText->SetExplicitMaxSize(BSize(maxSearchWidth, B_SIZE_UNSET)); // Construct check boxen fAvailableCheckBox = create_check_box( B_TRANSLATE("Available"), "available"); fInstalledCheckBox = create_check_box( B_TRANSLATE("Installed"), "installed"); fDevelopmentCheckBox = create_check_box( B_TRANSLATE("Development"), "development"); fSourceCodeCheckBox = create_check_box( B_TRANSLATE("Source code"), "source code"); // Build layout BLayoutBuilder::Group<>(this) .AddGroup(B_HORIZONTAL) .AddGroup(B_HORIZONTAL, B_USE_DEFAULT_SPACING, 1.2f) .Add(fShowField, 0.0f) .Add(fRepositoryField, 0.0f) .SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET)) .End() .AddGlue(0.5f) .Add(fSearchTermsText, 1.0f) .End() .AddGroup(B_HORIZONTAL) .Add(fAvailableCheckBox) .Add(fInstalledCheckBox) .Add(fDevelopmentCheckBox) .Add(fSourceCodeCheckBox) .AddGlue(0.5f) .End() .SetInsets(B_USE_DEFAULT_SPACING) ; }
void AttributeWindow::MessageReceived(BMessage* message) { switch (message->what) { case kMsgAttributeUpdated: case kMsgAlignmentChosen: case kMsgTypeChosen: _CheckDisplayAs(); _CheckAcceptable(); break; case kMsgDisplayAsChosen: fSpecialControl->SetEnabled(!_DefaultDisplayAs()->IsMarked()); _CheckAcceptable(); break; case kMsgVisibilityChanged: { bool enabled = fVisibleCheckBox->Value() != B_CONTROL_OFF; fDisplayAsMenuField->SetEnabled(enabled); fWidthControl->SetEnabled(enabled); fAlignmentMenuField->SetEnabled(enabled); fEditableCheckBox->SetEnabled(enabled); _CheckDisplayAs(); _CheckAcceptable(); break; } case kMsgAccept: { BMessage attributes; status_t status = fMimeType.GetAttrInfo(&attributes); if (status == B_OK) { // replace the entry, and remove any equivalent entries BList list; const char* newAttribute = fAttributeControl->Text(); const char* attribute; for (int32 i = 0; attributes.FindString("attr:name", i, &attribute) == B_OK; i++) { if (!strcmp(fAttribute.Name(), attribute) || !strcmp(newAttribute, attribute)) { // remove this item continue; } AttributeItem* item = create_attribute_item(attributes, i); if (item != NULL) list.AddItem(item); } list.AddItem(_NewItemFromCurrent()); // Copy them to a new message (their memory is still part of the // original BMessage) BMessage newAttributes; for (int32 i = 0; i < list.CountItems(); i++) { AttributeItem* item = (AttributeItem*)list.ItemAt(i); newAttributes.AddString("attr:name", item->Name()); newAttributes.AddString("attr:public_name", item->PublicName()); newAttributes.AddInt32("attr:type", (int32)item->Type()); newAttributes.AddString("attr:display_as", item->DisplayAs()); newAttributes.AddInt32("attr:alignment", item->Alignment()); newAttributes.AddInt32("attr:width", item->Width()); newAttributes.AddBool("attr:viewable", item->Visible()); newAttributes.AddBool("attr:editable", item->Editable()); delete item; } status = fMimeType.SetAttrInfo(&newAttributes); } if (status != B_OK) { error_alert(B_TRANSLATE("Could not change attributes"), status); } PostMessage(B_QUIT_REQUESTED); break; } default: BWindow::MessageReceived(message); break; } }
status_t RTFTranslator::Identify(BPositionIO *stream, const translation_format *format, BMessage *ioExtension, translator_info *info, uint32 outType) { if (!outType) outType = B_TRANSLATOR_TEXT; else if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT && outType != RTF_TEXT_FORMAT) return B_NO_TRANSLATOR; RTF::Parser parser(*stream); status_t status = parser.Identify(); if (status == B_OK) { // Source data is RTF. We can translate to RTF (no-op), plaintext, or // styled text. // return information about the data in the stream info->type = B_TRANSLATOR_TEXT; //RTF_TEXT_FORMAT; info->group = B_TRANSLATOR_TEXT; info->quality = RTF_IN_QUALITY; info->capability = RTF_IN_CAPABILITY; strlcpy(info->name, B_TRANSLATE("RichTextFormat file"), sizeof(info->name)); strcpy(info->MIME, "text/rtf"); } else { // Not an RTF file. We can only work with it if we are translating to // RTF. if (outType != RTF_TEXT_FORMAT) return B_NO_TRANSLATOR; stream->Seek(0, SEEK_SET); TranslatorStyledTextStreamHeader header; stream->Read(&header, sizeof(header)); swap_data(B_UINT32_TYPE, &header, sizeof(header), B_SWAP_BENDIAN_TO_HOST); stream->Seek(0, SEEK_SET); if (header.header.magic == B_STYLED_TEXT_FORMAT && header.header.header_size == (int32)sizeof(header) && header.header.data_size == 0 && header.version == 100) { info->type = B_STYLED_TEXT_FORMAT; info->group = B_TRANSLATOR_TEXT; info->quality = STXT_IN_QUALITY; info->capability = STXT_IN_CAPABILITY; strlcpy(info->name, B_TRANSLATE("Be style text file"), sizeof(info->name)); strcpy(info->MIME, "text/x-vnd.Be-stxt"); } else { info->type = B_TRANSLATOR_TEXT; info->group = B_TRANSLATOR_TEXT; info->quality = TEXT_IN_QUALITY; info->capability = TEXT_IN_CAPABILITY; strlcpy(info->name, B_TRANSLATE("Plain text file"), sizeof(info->name)); strcpy(info->MIME, "text/plain"); } } return B_OK; }
AutomountSettingsPanel::AutomountSettingsPanel(BMessage* settings, const BMessenger& target) : BBox("", B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, B_NO_BORDER), fTarget(target) { const float spacing = be_control_look->DefaultItemSpacing(); // "Automatic Disk Mounting" group BBox* autoMountBox = new BBox("autoMountBox", B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); autoMountBox->SetLabel(B_TRANSLATE("Automatic disk mounting")); BGroupLayout* autoMountLayout = new BGroupLayout(B_VERTICAL, 0); autoMountBox->SetLayout(autoMountLayout); autoMountLayout->SetInsets(spacing, autoMountBox->InnerFrame().top + spacing / 2, spacing, spacing); fScanningDisabledCheck = new BRadioButton("scanningOff", B_TRANSLATE("Don't automount"), new BMessage(kAutomountSettingsChanged)); fAutoMountAllBFSCheck = new BRadioButton("autoBFS", B_TRANSLATE("All BeOS disks"), new BMessage(kAutomountSettingsChanged)); fAutoMountAllCheck = new BRadioButton("autoAll", B_TRANSLATE("All disks"), new BMessage(kAutomountSettingsChanged)); // "Disk Mounting During Boot" group BBox* bootMountBox = new BBox("", B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED | B_NAVIGABLE_JUMP); bootMountBox->SetLabel(B_TRANSLATE("Disk mounting during boot")); BGroupLayout* bootMountLayout = new BGroupLayout(B_VERTICAL, 0); bootMountBox->SetLayout(bootMountLayout); bootMountLayout->SetInsets(spacing, bootMountBox->InnerFrame().top + spacing / 2, spacing, spacing); fInitialDontMountCheck = new BRadioButton("initialNone", B_TRANSLATE("Only the boot disk"), new BMessage(kBootMountSettingsChanged)); fInitialMountRestoreCheck = new BRadioButton("initialRestore", B_TRANSLATE("Previously mounted disks"), new BMessage(kBootMountSettingsChanged)); fInitialMountAllBFSCheck = new BRadioButton("initialBFS", B_TRANSLATE("All BeOS disks"), new BMessage(kBootMountSettingsChanged)); fInitialMountAllCheck = new BRadioButton("initialAll", B_TRANSLATE("All disks"), new BMessage(kBootMountSettingsChanged)); fEjectWhenUnmountingCheckBox = new BCheckBox("ejectWhenUnmounting", B_TRANSLATE("Eject when unmounting"), new BMessage(kEjectWhenUnmountingChanged)); // Buttons fDone = new BButton(B_TRANSLATE("Done"), new BMessage(B_QUIT_REQUESTED)); fMountAllNow = new BButton("mountAll", B_TRANSLATE("Mount all disks now"), new BMessage(kMountAllNow)); fDone->MakeDefault(true); // Layout the controls BGroupView* contentView = new BGroupView(B_VERTICAL, 0); AddChild(contentView); BLayoutBuilder::Group<>(contentView) .AddGroup(B_VERTICAL, spacing) .SetInsets(spacing, spacing, spacing, spacing) .AddGroup(autoMountLayout) .Add(fScanningDisabledCheck) .Add(fAutoMountAllBFSCheck) .Add(fAutoMountAllCheck) .End() .AddGroup(bootMountLayout) .Add(fInitialDontMountCheck) .Add(fInitialMountRestoreCheck) .Add(fInitialMountAllBFSCheck) .Add(fInitialMountAllCheck) .End() .AddGroup(B_HORIZONTAL) .AddStrut(spacing - 1) .Add(fEjectWhenUnmountingCheckBox) .End() .End() .Add(new BSeparatorView(B_HORIZONTAL/*, B_FANCY_BORDER*/)) .AddGroup(B_HORIZONTAL, spacing) .SetInsets(0, spacing, spacing, spacing) .AddGlue() .Add(fMountAllNow) .Add(fDone); // Apply the settings bool result; if (settings->FindBool("autoMountAll", &result) == B_OK && result) fAutoMountAllCheck->SetValue(B_CONTROL_ON); else if (settings->FindBool("autoMountAllBFS", &result) == B_OK && result) fAutoMountAllBFSCheck->SetValue(B_CONTROL_ON); else fScanningDisabledCheck->SetValue(B_CONTROL_ON); if (settings->FindBool("suspended", &result) == B_OK && result) fScanningDisabledCheck->SetValue(B_CONTROL_ON); if (settings->FindBool("initialMountAll", &result) == B_OK && result) fInitialMountAllCheck->SetValue(B_CONTROL_ON); else if (settings->FindBool("initialMountRestore", &result) == B_OK && result) { fInitialMountRestoreCheck->SetValue(B_CONTROL_ON); } else if (settings->FindBool("initialMountAllBFS", &result) == B_OK && result) { fInitialMountAllBFSCheck->SetValue(B_CONTROL_ON); } else fInitialDontMountCheck->SetValue(B_CONTROL_ON); if (settings->FindBool("ejectWhenUnmounting", &result) == B_OK && result) fEjectWhenUnmountingCheckBox->SetValue(B_CONTROL_ON); }
const char * RTFTranslator::TranslatorName() const { return B_TRANSLATE("RTF text files"); }
const char * RTFTranslator::TranslatorInfo() const { return B_TRANSLATE("Rich Text Format translator"); }
AppearancePrefView::AppearancePrefView(const char* name, const BMessenger& messenger) : BGroupView(name, B_VERTICAL, 5), fTerminalMessenger(messenger) { const char* kColorTable[] = { B_TRANSLATE("Text"), B_TRANSLATE("Background"), B_TRANSLATE("Selected text"), B_TRANSLATE("Selected background"), NULL }; fWarnOnExit = new BCheckBox( B_TRANSLATE("Confirm exit if active programs exist"), new BMessage(MSG_WARN_ON_EXIT_CHANGED)); BMenu* fontMenu = _MakeFontMenu(MSG_HALF_FONT_CHANGED, PrefHandler::Default()->getString(PREF_HALF_FONT_FAMILY), PrefHandler::Default()->getString(PREF_HALF_FONT_STYLE)); BMenu* sizeMenu = _MakeSizeMenu(MSG_HALF_SIZE_CHANGED, PrefHandler::Default()->getInt32(PREF_HALF_FONT_SIZE)); fFont = new BMenuField(B_TRANSLATE("Font:"), fontMenu); fFontSize = new BMenuField(B_TRANSLATE("Size:"), sizeMenu); BPopUpMenu* schemasPopUp = _MakeColorSchemaMenu(MSG_COLOR_SCHEMA_CHANGED, gPredefinedSchemas, gPredefinedSchemas[0]); fColorSchemaField = new BMenuField(B_TRANSLATE("Color schema:"), schemasPopUp); BPopUpMenu* colorsPopUp = _MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable, kColorTable[0]); fColorField = new BMenuField(B_TRANSLATE("Color:"), colorsPopUp); fColorField->SetEnabled(false); fTabTitle = new BTextControl("tabTitle", B_TRANSLATE("Tab title:"), "", NULL); fTabTitle->SetModificationMessage( new BMessage(MSG_TAB_TITLE_SETTING_CHANGED)); fTabTitle->SetToolTip(BString(B_TRANSLATE( "The pattern specifying the tab titles. The following placeholders\n" "can be used:\n")) << kTooTipSetTabTitlePlaceholders); fWindowTitle = new BTextControl("windowTitle", B_TRANSLATE("Window title:"), "", NULL); fWindowTitle->SetModificationMessage( new BMessage(MSG_WINDOW_TITLE_SETTING_CHANGED)); fWindowTitle->SetToolTip(BString(B_TRANSLATE( "The pattern specifying the window titles. The following placeholders\n" "can be used:\n")) << kTooTipSetWindowTitlePlaceholders); BLayoutBuilder::Group<>(this) .SetInsets(5, 5, 5, 5) .AddGrid(5, 5) .Add(fTabTitle->CreateLabelLayoutItem(), 0, 0) .Add(fTabTitle->CreateTextViewLayoutItem(), 1, 0) .Add(fWindowTitle->CreateLabelLayoutItem(), 0, 1) .Add(fWindowTitle->CreateTextViewLayoutItem(), 1, 1) .Add(fFont->CreateLabelLayoutItem(), 0, 2) .Add(fFont->CreateMenuBarLayoutItem(), 1, 2) .Add(fFontSize->CreateLabelLayoutItem(), 0, 3) .Add(fFontSize->CreateMenuBarLayoutItem(), 1, 3) .Add(fColorSchemaField->CreateLabelLayoutItem(), 0, 4) .Add(fColorSchemaField->CreateMenuBarLayoutItem(), 1, 4) .Add(fColorField->CreateLabelLayoutItem(), 0, 5) .Add(fColorField->CreateMenuBarLayoutItem(), 1, 5) .End() .AddGlue() .Add(fColorControl = new BColorControl(BPoint(10, 10), B_CELLS_32x8, 8.0, "", new BMessage(MSG_COLOR_CHANGED))) .Add(fWarnOnExit); fTabTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fWindowTitle->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fFont->SetAlignment(B_ALIGN_RIGHT); fFontSize->SetAlignment(B_ALIGN_RIGHT); fColorField->SetAlignment(B_ALIGN_RIGHT); fColorSchemaField->SetAlignment(B_ALIGN_RIGHT); fTabTitle->SetText(PrefHandler::Default()->getString(PREF_TAB_TITLE)); fWindowTitle->SetText(PrefHandler::Default()->getString(PREF_WINDOW_TITLE)); fColorControl->SetEnabled(false); fColorControl->SetValue( PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR)); fWarnOnExit->SetValue(PrefHandler::Default()->getBool(PREF_WARN_ON_EXIT)); BTextControl* redInput = (BTextControl*)fColorControl->ChildAt(0); BTextControl* greenInput = (BTextControl*)fColorControl->ChildAt(1); BTextControl* blueInput = (BTextControl*)fColorControl->ChildAt(2); redInput->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); greenInput->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); blueInput->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); }
void HWindow::MessageReceived(BMessage* message) { switch (message->what) { case M_OTHER_MESSAGE: { BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu")); if (menufield == NULL) return; BMenu* menu = menufield->Menu(); HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (row != NULL) { BPath path(row->Path()); if (path.InitCheck() != B_OK) { BMenuItem* item = menu->FindItem(B_TRANSLATE("<none>")); if (item != NULL) item->SetMarked(true); } else { BMenuItem* item = menu->FindItem(path.Leaf()); if (item != NULL) item->SetMarked(true); } } fFilePanel->Show(); break; } case B_SIMPLE_DATA: case B_REFS_RECEIVED: { entry_ref ref; HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (message->FindRef("refs", &ref) == B_OK && row != NULL) { BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu")); if (menufield == NULL) return; BMenu* menu = menufield->Menu(); // check audio file BNode node(&ref); BNodeInfo ninfo(&node); char type[B_MIME_TYPE_LENGTH + 1]; ninfo.GetType(type); BMimeType mtype(type); BMimeType superType; mtype.GetSupertype(&superType); if (superType.Type() == NULL || strcmp(superType.Type(), "audio") != 0) { beep(); BAlert* alert = new BAlert("", B_TRANSLATE("This is not an audio file."), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); break; } // add file item BMessage* msg = new BMessage(M_ITEM_MESSAGE); BPath path(&ref); msg->AddRef("refs", &ref); BMenuItem* menuitem = menu->FindItem(path.Leaf()); if (menuitem == NULL) menu->AddItem(menuitem = new BMenuItem(path.Leaf(), msg), 0); // refresh item fEventList->SetPath(BPath(&ref).Path()); // check file menu if (menuitem != NULL) menuitem->SetMarked(true); } break; } case M_PLAY_MESSAGE: { HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); if (row != NULL) { const char* path = row->Path(); if (path != NULL) { entry_ref ref; ::get_ref_for_path(path, &ref); delete fPlayer; fPlayer = new BFileGameSound(&ref, false); fPlayer->StartPlaying(); } } break; } case M_STOP_MESSAGE: { if (fPlayer == NULL) break; if (fPlayer->IsPlaying()) { fPlayer->StopPlaying(); delete fPlayer; fPlayer = NULL; } break; } case M_EVENT_CHANGED: { const char* path; BMenuField* menufield = dynamic_cast<BMenuField*>(FindView("filemenu")); if (menufield == NULL) return; BMenu* menu = menufield->Menu(); if (message->FindString("path", &path) == B_OK) { BPath path(path); if (path.InitCheck() != B_OK) { BMenuItem* item = menu->FindItem(B_TRANSLATE("<none>")); if (item != NULL) item->SetMarked(true); } else { BMenuItem* item = menu->FindItem(path.Leaf()); if (item != NULL) item->SetMarked(true); } HEventRow* row = (HEventRow*)fEventList->CurrentSelection(); BButton* button = dynamic_cast<BButton*>(FindView("play")); if (row != NULL) { menufield->SetEnabled(true); const char* path = row->Path(); if (path != NULL && strcmp(path, "")) button->SetEnabled(true); else button->SetEnabled(false); } else { menufield->SetEnabled(false); button->SetEnabled(false); } } break; } case M_ITEM_MESSAGE: { entry_ref ref; if (message->FindRef("refs", &ref) == B_OK) { fEventList->SetPath(BPath(&ref).Path()); _UpdateZoomLimits(); } break; } case M_NONE_MESSAGE: { fEventList->SetPath(NULL); break; } default: BWindow::MessageReceived(message); } }
void SnowView::Draw(BRect ur) { int i; if (!fCachedParent) { if (!fShowClickMe) { /* show "drag me" */ SetLowColor(ViewColor()); SetHighColor(0,0,0); SetFontSize(12); DrawString(B_TRANSLATE("Drag me on your desktop"B_UTF8_ELLIPSIS), BPoint(15,25)); BPoint arrowHead(Bounds().RightBottom() + BPoint(-10,-10)); StrokeLine(arrowHead, arrowHead - BPoint(7,0)); StrokeLine(arrowHead, arrowHead - BPoint(0,7)); StrokeLine(arrowHead, arrowHead - BPoint(12,12)); return; } else { SetLowColor(ViewColor()); SetHighColor(0,0,0); SetFontSize(12); DrawString(B_TRANSLATE("Click me to remove BSnow"B_UTF8_ELLIPSIS), BPoint(15,25)); return; } } //printf("Draw()\n"); uint32 cw = fCurrentWorkspace; if (fFlakes[cw] == NULL) return; /* draw the snow already fallen */ // BRect fallenRect(Bounds()); // fallenRect.top = fallenRect.bottom - FALLEN_HEIGHT; // if (ur.Intersects(fallenRect)) { //if (fFallenBmp->Lock()) { // DrawBitmap(fFallenBmp, fallenRect); // fFallenBmp->Unlock(); //} int32 cnt = fFallenReg->CountRects(); // drawing_mode oldmode = DrawingMode(); // SetDrawingMode(B_OP_ADD); for (i=0; i<cnt; i++) { BRect r = fFallenReg->RectAt(i); // SetHighColor(245, 245, 245, 200); // FillRect(r); // SetHighColor(255, 255, 255, 255); // r.InsetBy(1,1); FillRect(r); } // SetDrawingMode(oldmode); // } /* draw our flakes */ for (i=0; i<fNumFlakes; i++) { int pat; if (!ur.Contains(BRect(fFlakes[cw][i].pos-BPoint(4,4), fFlakes[cw][i].pos+BPoint(4,4)))) continue; if (fFlakes[cw][i].weight == 0) continue; pat = (fFlakes[cw][i].weight>3)?1:0; //FillRect(BRect(fFlakes[cw][i].pos-BPoint(PAT_HOTSPOT),fFlakes[cw][i].pos-BPoint(PAT_HOTSPOT)+BPoint(7,7)), gFlakePatterns[pat]); /* StrokeLine(fFlakes[cw][i].pos+BPoint(-1,-1), fFlakes[cw][i].pos+BPoint(1,1)); StrokeLine(fFlakes[cw][i].pos+BPoint(-1,1), fFlakes[cw][i].pos+BPoint(1,-1)); */ DrawBitmap(fFlakeBitmaps[pat], fFlakes[cw][i].pos-BPoint(PAT_HOTSPOT)); } }
void CharacterWindow::MessageReceived(BMessage* message) { if (message->WasDropped()) { const char* text; ssize_t size; uint32 c; if (message->FindInt32("character", (int32*)&c) == B_OK) { fCharacterView->ScrollToCharacter(c); return; } else if (message->FindData("text/plain", B_MIME_TYPE, (const void**)&text, &size) == B_OK) { fCharacterView->ScrollToCharacter(BUnicodeChar::FromUTF8(text)); return; } } switch (message->what) { case B_COPY: PostMessage(message, fCharacterView); break; case kMsgUnicodeBlockSelected: { int32 index; if (message->FindInt32("index", &index) != B_OK || index < 0) break; BlockListItem* item = static_cast<BlockListItem*>(fUnicodeBlockView->ItemAt(index)); fCharacterView->ScrollToBlock(item->BlockIndex()); fFilterControl->MakeFocus(); break; } case kMsgCharacterChanged: { uint32 character; if (message->FindInt32("character", (int32*)&character) != B_OK) break; char utf8[16]; CharacterView::UnicodeToUTF8(character, utf8, sizeof(utf8)); char utf8Hex[32]; CharacterView::UnicodeToUTF8Hex(character, utf8Hex, sizeof(utf8Hex)); char text[128]; snprintf(text, sizeof(text), " %s: %#lx (%ld), UTF-8: %s", B_TRANSLATE("Code"), character, character, utf8Hex); char glyph[20]; snprintf(glyph, sizeof(glyph), "'%s'", utf8); fGlyphView->SetText(glyph); fCodeView->SetText(text); break; } case kMsgFontSelected: { BMenuItem* item; if (message->FindPointer("source", (void**)&item) != B_OK) break; fSelectedFontItem->SetMarked(false); // If it's the family menu, just select the first style if (item->Submenu() != NULL) { item->SetMarked(true); item = item->Submenu()->ItemAt(0); } if (item != NULL) { item->SetMarked(true); fSelectedFontItem = item; _SetFont(item->Menu()->Name(), item->Label()); item = item->Menu()->Superitem(); item->SetMarked(true); } break; } case kMsgFontSizeChanged: { int32 size = fFontSizeSlider->Value(); if (size < kMinFontSize) size = kMinFontSize; else if (size > kMaxFontSize) size = kMaxFontSize; BFont font = fCharacterView->CharacterFont(); font.SetSize(size); fCharacterView->SetCharacterFont(font); break; } case kMsgPrivateBlocks: { BMenuItem* item; if (message->FindPointer("source", (void**)&item) != B_OK || item == NULL) break; item->SetMarked(!item->IsMarked()); fCharacterView->ShowPrivateBlocks(item->IsMarked()); fUnicodeBlockView->ShowPrivateBlocks(item->IsMarked()); break; } case kMsgContainedBlocks: { BMenuItem* item; if (message->FindPointer("source", (void**)&item) != B_OK || item == NULL) break; item->SetMarked(!item->IsMarked()); fCharacterView->ShowContainedBlocksOnly(item->IsMarked()); fUnicodeBlockView->ShowContainedBlocksOnly(item->IsMarked()); break; } case kMsgFilterChanged: fUnicodeBlockView->SetFilter(fFilterControl->Text()); fUnicodeBlockView->Select(0); break; case kMsgClearFilter: fFilterControl->SetText(""); fFilterControl->MakeFocus(); break; default: BWindow::MessageReceived(message); break; } }
void ModulesView::MessageReceived(BMessage* message) { switch (message->what) { case kMsgSaverSelected: { int selection = fListView->CurrentSelection(); if (selection < 0) break; ScreenSaverItem* item = (ScreenSaverItem*)fListView->ItemAt(selection); if (item == NULL) break; if (!strcmp(item->Text(), B_TRANSLATE("Blackness"))) fSettings.SetModuleName(""); else fSettings.SetModuleName(item->Text()); SaveState(); _CloseSaver(); _OpenSaver(); fSettings.Save(); break; } case kMsgTestSaver: { SaveState(); fSettings.Save(); _CloseSaver(); be_roster->StartWatching(BMessenger(this, Looper()), B_REQUEST_QUIT); if (be_roster->Launch(SCREEN_BLANKER_SIG, &fSettings.Message(), &fScreenSaverTestTeam) == B_OK) break; // Try really hard to launch it. It's very likely that this fails // when we run from the CD, and there is only an incomplete mime // database for example... BPath path; if (find_directory(B_SYSTEM_BIN_DIRECTORY, &path) != B_OK || path.Append("screen_blanker") != B_OK) path.SetTo("/boot/system/bin/screen_blanker"); BEntry entry(path.Path()); entry_ref ref; if (entry.GetRef(&ref) == B_OK) { be_roster->Launch(&ref, &fSettings.Message(), &fScreenSaverTestTeam); } break; } case kMsgAddSaver: fFilePanel->Show(); break; case B_SOME_APP_QUIT: { team_id team; if (message->FindInt32("be:team", &team) == B_OK && team == fScreenSaverTestTeam) { be_roster->StopWatching(this); _OpenSaver(); } break; } default: BView::MessageReceived(message); } }
void DataTranslationsApplication::RefsReceived(BMessage* message) { BTranslatorRoster* roster = BTranslatorRoster::Default(); BPath path; status_t status = find_directory(B_USER_ADDONS_DIRECTORY, &path, true); if (status != B_OK) { _InstallError("translator", status); return; } BDirectory target; status = target.SetTo(path.Path()); if (status == B_OK) { if (!target.Contains("Translators")) status = target.CreateDirectory("Translators", &target); else status = target.SetTo(&target, "Translators"); } if (status != B_OK) { _InstallError("translator", status); return; } int32 i = 0; entry_ref ref; while (message->FindRef("refs", i++, &ref) == B_OK) { if (!roster->IsTranslator(&ref)) { _NoTranslatorError(ref.name); continue; } BEntry entry(&ref, true); status = entry.InitCheck(); if (status != B_OK) { _InstallError(ref.name, status); continue; } if (target.Contains(ref.name)) { BString string( B_TRANSLATE("An item named '%name' already exists in the " "Translators folder! Shall the existing translator be " "overwritten?")); string.ReplaceAll("%name", ref.name); BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"), string.String(), B_TRANSLATE("Cancel"), B_TRANSLATE("Overwrite")); alert->SetShortcut(0, B_ESCAPE); if (alert->Go() != 1) continue; // the original file will be replaced } // find out whether we need to copy it or not status = _Install(target, entry); if (status == B_OK) { BAlert* alert = new BAlert(B_TRANSLATE("DataTranslations - Note"), B_TRANSLATE("The new translator has been installed " "successfully."), B_TRANSLATE("OK")); alert->Go(NULL); } else _InstallError(ref.name, status); } }
void ModulesView::_OpenSaver() { // create new screen saver preview & config BView* view = fPreviewView->AddPreview(); fCurrentName = fSettings.ModuleName(); fSaverRunner = new ScreenSaverRunner(Window(), view, true, fSettings); BScreenSaver* saver = _ScreenSaver(); #ifdef __HAIKU__ BRect rect = fSettingsBox->InnerFrame().InsetByCopy(4, 4); #else BRect rect = fSettingsBox->Bounds().InsetByCopy(4, 4); rect.top += 14; #endif fSettingsView = new BView(rect, "SettingsView", B_FOLLOW_ALL, B_WILL_DRAW); fSettingsView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fSettingsBox->AddChild(fSettingsView); if (saver != NULL) { fSaverRunner->Run(); saver->StartConfig(fSettingsView); } if (fSettingsView->ChildAt(0) == NULL) { // There are no settings at all, we add the module name here to // let it look a bit better at least. BPrivate::BuildScreenSaverDefaultSettingsView(fSettingsView, fSettings.ModuleName()[0] ? fSettings.ModuleName() : B_TRANSLATE("Blackness"), saver || !fSettings.ModuleName()[0] ? B_TRANSLATE("No options available") : B_TRANSLATE("Could not load screen saver")); } ScreenSaverWindow* window = dynamic_cast<ScreenSaverWindow*>(Window()); if (window == NULL) return; // find the minimal size of the settings view float right = 0, bottom = 0; int32 i = 0; while ((view = fSettingsView->ChildAt(i++)) != NULL) { // very simple heuristic... float viewRight = view->Frame().right; if ((view->ResizingMode() & _rule_(0, 0xf, 0, 0xf)) == B_FOLLOW_LEFT_RIGHT) { float width, height; view->GetPreferredSize(&width, &height); viewRight = view->Frame().left + width / 2; } else if ((view->ResizingMode() & _rule_(0, 0xf, 0, 0xf)) == B_FOLLOW_RIGHT) viewRight = 8 + view->Frame().Width(); float viewBottom = view->Frame().bottom; if ((view->ResizingMode() & _rule_(0xf, 0, 0xf, 0)) == B_FOLLOW_TOP_BOTTOM) { float width, height; view->GetPreferredSize(&width, &height); viewBottom = view->Frame().top + height; } else if ((view->ResizingMode() & _rule_(0xf, 0, 0xf, 0)) == B_FOLLOW_BOTTOM) viewBottom = 8 + view->Frame().Height(); if (viewRight > right) right = viewRight; if (viewBottom > bottom) bottom = viewBottom; } if (right < kMinSettingsWidth) right = kMinSettingsWidth; if (bottom < kMinSettingsHeight) bottom = kMinSettingsHeight; BPoint leftTop = fSettingsView->LeftTop(); fSettingsView->ConvertToScreen(&leftTop); window->ConvertFromScreen(&leftTop); window->SetMinimalSizeLimit(leftTop.x + right + 16, leftTop.y + bottom + 16); }
// GetName void PathCommand::GetName(BString& name) { name << B_TRANSLATE("<modify path>"); }
//! Create the controls for the "General" tab void ScreenSaverWindow::_SetupFadeTab(BRect rect) { fFadeView = new FadeView(rect, B_TRANSLATE("General"), fSettings); float StringWidth1 = be_plain_font->StringWidth(B_TRANSLATE ("Start screensaver")); float StringWidth2 = be_plain_font->StringWidth(B_TRANSLATE ("Turn off screen")); float StringWidth3 = be_plain_font->StringWidth(B_TRANSLATE ("Password lock")); float labelWidth = StringWidth1; if (labelWidth < StringWidth2) labelWidth = StringWidth2; if (labelWidth < StringWidth3) labelWidth = StringWidth3; labelWidth += 20.0f; font_height fontHeight; be_plain_font->GetHeight(&fontHeight); float textHeight = ceilf(fontHeight.ascent + fontHeight.descent); // taken from BRadioButton: float radioButtonOffset = 2 * floorf(textHeight / 2 - 2) + floorf(textHeight / 2); fEnableCheckBox = new BCheckBox(BRect(0, 0, 1, 1), "EnableCheckBox", B_TRANSLATE("Enable screensaver"), new BMessage(kMsgEnableScreenSaverBox)); fEnableCheckBox->ResizeToPreferred(); rect.InsetBy(8, 8); BBox* box = new BBox(rect, "EnableScreenSaverBox", B_FOLLOW_ALL); box->SetLabel(fEnableCheckBox); fFadeView->AddChild(box); // Start Screensaver rect.left += radioButtonOffset + 6; rect.top = fEnableCheckBox->Bounds().bottom + 8.0f; rect.right = box->Bounds().right - 8; BStringView* stringView = new BStringView(rect, NULL, B_TRANSLATE("Start screensaver")); stringView->ResizeToPreferred(); box->AddChild(stringView); rect.left += labelWidth - 4; fRunSlider = new TimeSlider(rect, "RunSlider", kMsgRunSliderChanged, kMsgRunSliderUpdate); float width, height; fRunSlider->GetPreferredSize(&width, &height); fRunSlider->ResizeTo(fRunSlider->Bounds().Width(), height); box->AddChild(fRunSlider); // Turn Off rect.left = 10; rect.OffsetBy(0, fRunSlider->Bounds().Height() + 4.0f); fTurnOffCheckBox = new BCheckBox(rect, "TurnOffScreenCheckBox", B_TRANSLATE("Turn off screen"), new BMessage(kMsgTurnOffCheckBox)); fTurnOffCheckBox->ResizeToPreferred(); box->AddChild(fTurnOffCheckBox); rect.top += 3; rect.left += radioButtonOffset + labelWidth; fTurnOffSlider = new TimeSlider(rect, "TurnOffSlider", kMsgTurnOffSliderChanged, kMsgTurnOffSliderUpdate); fTurnOffSlider->ResizeTo(fTurnOffSlider->Bounds().Width(), height); box->AddChild(fTurnOffSlider); rgb_color textColor = tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT); BRect textRect(0, 0, fTurnOffSlider->Bounds().Width(), height); textRect.InsetBy(0, 3); fTurnOffNotSupported = new BTextView(rect, "not_supported", textRect, be_plain_font, &textColor, B_FOLLOW_ALL, B_WILL_DRAW); fTurnOffNotSupported->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fTurnOffNotSupported->MakeEditable(false); fTurnOffNotSupported->MakeSelectable(false); fTurnOffNotSupported->SetText( B_TRANSLATE("Display Power Management Signaling not available")); fTurnOffNotSupported->ResizeTo(fTurnOffSlider->Bounds().Width(), height); box->AddChild(fTurnOffNotSupported); // Password rect.left = 10; rect.OffsetBy(0, fTurnOffSlider->Bounds().Height() + 4.0f); fPasswordCheckBox = new BCheckBox(rect, "PasswordCheckbox", B_TRANSLATE("Password lock"), new BMessage(kMsgPasswordCheckBox)); fPasswordCheckBox->ResizeToPreferred(); box->AddChild(fPasswordCheckBox); rect.top += 3; rect.left += radioButtonOffset + labelWidth; fPasswordSlider = new TimeSlider(rect, "PasswordSlider", kMsgPasswordSliderChanged, kMsgPasswordSliderUpdate); fPasswordSlider->ResizeTo(fPasswordSlider->Bounds().Width(), height); box->AddChild(fPasswordSlider); rect.OffsetBy(0, fTurnOffSlider->Bounds().Height() + 4.0f); rect.left = rect.right; fPasswordButton = new BButton(rect, "PasswordButton", B_TRANSLATE("Password" B_UTF8_ELLIPSIS), new BMessage(kMsgChangePassword), B_FOLLOW_TOP | B_FOLLOW_RIGHT); fPasswordButton->ResizeToPreferred(); fPasswordButton->MoveBy(-fPasswordButton->Bounds().Width(), 0); box->AddChild(fPasswordButton); // Bottom float monitorHeight = 10 + textHeight * 3; float monitorWidth = monitorHeight * 4 / 3; rect.left = 11; rect.top = box->Bounds().Height() - 15 - monitorHeight; rect.right = rect.left + monitorWidth; rect.bottom = rect.top + monitorHeight; box->AddChild(fFadeNow = new ScreenCornerSelector(rect, "FadeNow", new BMessage(kMsgFadeCornerChanged), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)); rect.OffsetBy(monitorWidth + 10, 0); stringView = new BStringView(rect, NULL, B_TRANSLATE("Fade now when"), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); stringView->ResizeToPreferred(); float maxWidth = stringView->Bounds().Width(); box->AddChild(stringView); rect.OffsetBy(0, stringView->Bounds().Height()); stringView = new BStringView(rect, NULL, B_TRANSLATE("mouse is here"), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); stringView->ResizeToPreferred(); if (maxWidth < stringView->Bounds().Width()) maxWidth = stringView->Bounds().Width(); box->AddChild(stringView); rect.left += maxWidth + 20; rect.top = box->Bounds().Height() - 15 - monitorHeight; rect.right = rect.left + monitorWidth; rect.bottom = rect.top + monitorHeight; box->AddChild(fFadeNever = new ScreenCornerSelector(rect, "FadeNever", new BMessage(kMsgNeverFadeCornerChanged), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM)); rect.OffsetBy(monitorWidth + 10, 0); stringView = new BStringView(rect, NULL,B_TRANSLATE("Don't fade when"), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); stringView->ResizeToPreferred(); if (maxWidth < stringView->Bounds().Width()) maxWidth = stringView->Bounds().Width(); box->AddChild(stringView); rect.OffsetBy(0, stringView->Bounds().Height()); stringView = new BStringView(rect, NULL, B_TRANSLATE("mouse is here"), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); stringView->ResizeToPreferred(); if (maxWidth < stringView->Bounds().Width()) maxWidth = stringView->Bounds().Width(); box->AddChild(stringView); float size = rect.left + maxWidth + 40; if (fMinWidth < size) fMinWidth = size; size = fPasswordButton->Frame().bottom + box->Frame().top + monitorHeight + 40 + textHeight * 2; if (fMinHeight < size) fMinHeight = size; }
AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, AttributeItem* attributeItem) : BWindow(BRect(100, 100, 350, 200), B_TRANSLATE("Attribute"), B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS), fTarget(target), fMimeType(mimeType.Type()) { float padding = be_control_look->DefaultItemSpacing(); if (attributeItem != NULL) fAttribute = *attributeItem; fPublicNameControl = new BTextControl(B_TRANSLATE("Attribute name:"), fAttribute.PublicName(), NULL); fPublicNameControl->SetModificationMessage( new BMessage(kMsgAttributeUpdated)); fPublicNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fAttributeControl = new BTextControl(B_TRANSLATE("Internal name:"), fAttribute.Name(), NULL); fAttributeControl->SetModificationMessage( new BMessage(kMsgAttributeUpdated)); fAttributeControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); // filter out invalid characters that can't be part of an attribute BTextView* textView = fAttributeControl->TextView(); const char* disallowedCharacters = "/"; for (int32 i = 0; disallowedCharacters[i]; i++) { textView->DisallowChar(disallowedCharacters[i]); } fTypeMenu = new BPopUpMenu("type"); BMenuItem* item = NULL; for (int32 i = 0; kTypeMap[i].name != NULL; i++) { BMessage* message = new BMessage(kMsgTypeChosen); message->AddInt32("type", kTypeMap[i].type); item = new BMenuItem(kTypeMap[i].name, message); fTypeMenu->AddItem(item); if (kTypeMap[i].type == fAttribute.Type()) item->SetMarked(true); } BMenuField* typeMenuField = new BMenuField("types" , B_TRANSLATE("Type:"), fTypeMenu); typeMenuField->SetAlignment(B_ALIGN_RIGHT); // we must set the color manually when adding a menuField directly // into a window. typeMenuField->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); typeMenuField->SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fVisibleCheckBox = new BCheckBox("visible", B_TRANSLATE("Visible"), new BMessage(kMsgVisibilityChanged)); fVisibleCheckBox->SetValue(fAttribute.Visible()); BMenu* menu = new BPopUpMenu("display as"); for (int32 i = 0; kDisplayAsMap[i].name != NULL; i++) { BMessage* message = new BMessage(kMsgDisplayAsChosen); if (kDisplayAsMap[i].identifier != NULL) { message->AddString("identifier", kDisplayAsMap[i].identifier); for (int32 j = 0; kDisplayAsMap[i].supported[j]; j++) { message->AddInt32("supports", kDisplayAsMap[i].supported[j]); } } item = new BMenuItem(kDisplayAsMap[i].name, message); menu->AddItem(item); if (compare_display_as(kDisplayAsMap[i].identifier, fAttribute.DisplayAs())) item->SetMarked(true); } fDisplayAsMenuField = new BMenuField("display as", B_TRANSLATE_COMMENT("Display as:", "Tracker offers different display modes for attributes."), menu); fDisplayAsMenuField->SetAlignment(B_ALIGN_RIGHT); fEditableCheckBox = new BCheckBox("editable", B_TRANSLATE_COMMENT("Editable", "If Tracker allows to edit this attribute."), new BMessage(kMsgAttributeUpdated)); fEditableCheckBox->SetValue(fAttribute.Editable()); fSpecialControl = new BTextControl(B_TRANSLATE("Special:"), display_as_parameter(fAttribute.DisplayAs()), NULL); fSpecialControl->SetModificationMessage( new BMessage(kMsgAttributeUpdated)); fSpecialControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fSpecialControl->SetEnabled(false); char text[64]; snprintf(text, sizeof(text), "%ld", fAttribute.Width()); fWidthControl = new BTextControl(B_TRANSLATE_COMMENT("Width:", "Default column width in Tracker for this attribute."), text, NULL); fWidthControl->SetModificationMessage( new BMessage(kMsgAttributeUpdated)); fWidthControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); // filter out invalid characters that can't be part of a width textView = fWidthControl->TextView(); for (int32 i = 0; i < 256; i++) { if (!isdigit(i)) textView->DisallowChar(i); } textView->SetMaxBytes(4); const struct alignment_map { int32 alignment; const char* name; } kAlignmentMap[] = { {B_ALIGN_LEFT, B_TRANSLATE_COMMENT("Left", "Attribute column alignment in Tracker")}, {B_ALIGN_RIGHT, B_TRANSLATE_COMMENT("Right", "Attribute column alignment in Tracker")}, {B_ALIGN_CENTER, B_TRANSLATE_COMMENT("Center", "Attribute column alignment in Tracker")}, {0, NULL} }; menu = new BPopUpMenu("alignment"); for (int32 i = 0; kAlignmentMap[i].name != NULL; i++) { BMessage* message = new BMessage(kMsgAlignmentChosen); message->AddInt32("alignment", kAlignmentMap[i].alignment); item = new BMenuItem(kAlignmentMap[i].name, message); menu->AddItem(item); if (kAlignmentMap[i].alignment == fAttribute.Alignment()) item->SetMarked(true); } fAlignmentMenuField = new BMenuField("alignment", B_TRANSLATE("Alignment:"), menu); fAlignmentMenuField->SetAlignment(B_ALIGN_RIGHT); fAcceptButton = new BButton("add", item ? B_TRANSLATE("Done") : B_TRANSLATE("Add"), new BMessage(kMsgAccept)); fAcceptButton->SetEnabled(false); BButton* cancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED)); BBox* visibleBox; BLayoutBuilder::Group<>(this, B_VERTICAL, padding) .SetInsets(padding, padding, padding, padding) .AddGrid(padding, padding / 2) .Add(fPublicNameControl->CreateLabelLayoutItem(), 0, 0) .Add(fPublicNameControl->CreateTextViewLayoutItem(), 1, 0) .Add(fAttributeControl->CreateLabelLayoutItem(), 0, 1) .Add(fAttributeControl->CreateTextViewLayoutItem(), 1, 1) .Add(typeMenuField->CreateLabelLayoutItem(), 0, 2) .Add(typeMenuField->CreateMenuBarLayoutItem(), 1, 2) .End() .Add(visibleBox = new BBox(B_FANCY_BORDER, BLayoutBuilder::Grid<>(padding, padding / 2) .Add(fDisplayAsMenuField->CreateLabelLayoutItem(), 0, 0) .Add(fDisplayAsMenuField->CreateMenuBarLayoutItem(), 1, 0) .Add(fEditableCheckBox, 2, 0) .Add(fSpecialControl->CreateLabelLayoutItem(), 0, 1) .Add(fSpecialControl->CreateTextViewLayoutItem(), 1, 1, 2) .Add(fWidthControl->CreateLabelLayoutItem(), 0, 2) .Add(fWidthControl->CreateTextViewLayoutItem(), 1, 2, 2) .Add(fAlignmentMenuField->CreateLabelLayoutItem(), 0, 3) .Add(fAlignmentMenuField->CreateMenuBarLayoutItem(), 1, 3, 2) .SetInsets(padding, padding, padding, padding) .View()) ) .AddGroup(B_HORIZONTAL, padding) .Add(BSpaceLayoutItem::CreateGlue()) .Add(cancelButton) .Add(fAcceptButton); visibleBox->SetLabel(fVisibleCheckBox); fAcceptButton->MakeDefault(true); fPublicNameControl->MakeFocus(true); target->PlaceSubWindow(this); AddToSubset(target); _CheckDisplayAs(); _CheckAcceptable(); }
SudokuWindow::SudokuWindow() : BWindow(BRect(-1, -1, 400, 420), B_TRANSLATE_SYSTEM_NAME("Sudoku"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE), fGenerator(NULL), fStoredState(NULL), fExportFormat(kExportAsText) { BMessage settings; _LoadSettings(settings); BRect frame; if (settings.FindRect("window frame", &frame) == B_OK) { MoveTo(frame.LeftTop()); ResizeTo(frame.Width(), frame.Height()); frame.OffsetTo(B_ORIGIN); } else { float scaling = std::max(1.0f, be_plain_font->Size() / 12.0f); ResizeTo(Frame().Width() * scaling, Frame().Height() * scaling); frame = Bounds(); } MoveOnScreen(); if (settings.HasMessage("stored state")) { fStoredState = new BMessage; if (settings.FindMessage("stored state", fStoredState) != B_OK) { delete fStoredState; fStoredState = NULL; } } int32 level = 0; settings.FindInt32("level", &level); // create GUI BMenuBar* menuBar = new BMenuBar(Bounds(), "menu"); AddChild(menuBar); frame.top = menuBar->Frame().bottom; BView* top = new BView(frame, NULL, B_FOLLOW_ALL, B_WILL_DRAW); top->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(top); fSudokuView = new SudokuView( top->Bounds().InsetByCopy(10, 10).OffsetToSelf(0, 0), "sudoku view", settings, B_FOLLOW_NONE); CenteredViewContainer* container = new CenteredViewContainer(fSudokuView, top->Bounds().InsetByCopy(10, 10), "center", B_FOLLOW_ALL); container->SetHighColor(top->ViewColor()); top->AddChild(container); // add menu // "File" menu BMenu* menu = new BMenu(B_TRANSLATE("File")); fNewMenu = new BMenu(B_TRANSLATE("New")); menu->AddItem(new BMenuItem(fNewMenu, new BMessage(kMsgGenerateSudoku))); fNewMenu->Superitem()->SetShortcut('N', B_COMMAND_KEY); BMessage* message = new BMessage(kMsgGenerateSudoku); message->AddInt32("level", kEasyLevel); fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Easy"), message)); message = new BMessage(kMsgGenerateSudoku); message->AddInt32("level", kAdvancedLevel); fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Advanced"), message)); message = new BMessage(kMsgGenerateSudoku); message->AddInt32("level", kHardLevel); fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Hard"), message)); fNewMenu->AddSeparatorItem(); fNewMenu->AddItem(new BMenuItem(B_TRANSLATE("Blank"), new BMessage(kMsgNewBlank))); menu->AddItem(new BMenuItem(B_TRANSLATE("Start again"), new BMessage(kMsgStartAgain))); menu->AddSeparatorItem(); BMenu* recentsMenu = BRecentFilesList::NewFileListMenu( B_TRANSLATE("Open file" B_UTF8_ELLIPSIS), NULL, NULL, this, 10, false, NULL, kSignature); BMenuItem *item; menu->AddItem(item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel))); item->SetShortcut('O', B_COMMAND_KEY); menu->AddSeparatorItem(); BMenu* subMenu = new BMenu(B_TRANSLATE("Export as" B_UTF8_ELLIPSIS)); message = new BMessage(kMsgExportAs); message->AddInt32("as", kExportAsText); subMenu->AddItem(new BMenuItem(B_TRANSLATE("Text"), message)); message= new BMessage(kMsgExportAs); message->AddInt32("as", kExportAsHTML); subMenu->AddItem(new BMenuItem(B_TRANSLATE("HTML"), message)); menu->AddItem(subMenu); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Copy"), new BMessage(B_COPY), 'C')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q')); menu->SetTargetForItems(this); item->SetTarget(be_app); menuBar->AddItem(menu); // "View" menu menu = new BMenu(B_TRANSLATE("View")); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark invalid values"), new BMessage(kMsgMarkInvalid))); if ((fSudokuView->HintFlags() & kMarkInvalid) != 0) item->SetMarked(true); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Mark valid hints"), new BMessage(kMsgMarkValidHints))); if ((fSudokuView->HintFlags() & kMarkValidHints) != 0) item->SetMarked(true); menu->SetTargetForItems(this); menuBar->AddItem(menu); // "Help" menu menu = new BMenu(B_TRANSLATE("Help")); menu->AddItem(fUndoItem = new BMenuItem(B_TRANSLATE("Undo"), new BMessage(B_UNDO), 'Z')); fUndoItem->SetEnabled(false); menu->AddItem(fRedoItem = new BMenuItem(B_TRANSLATE("Redo"), new BMessage(B_REDO), 'Z', B_SHIFT_KEY)); fRedoItem->SetEnabled(false); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Snapshot current"), new BMessage(kMsgStoreState))); menu->AddItem(fRestoreStateItem = new BMenuItem( B_TRANSLATE("Restore snapshot"), new BMessage(kMsgRestoreState))); fRestoreStateItem->SetEnabled(fStoredState != NULL); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Set all hints"), new BMessage(kMsgSetAllHints))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Solve"), new BMessage(kMsgSolveSudoku))); menu->AddItem(new BMenuItem(B_TRANSLATE("Solve single field"), new BMessage(kMsgSolveSingle))); menu->SetTargetForItems(fSudokuView); menuBar->AddItem(menu); fOpenPanel = new BFilePanel(B_OPEN_PANEL); fOpenPanel->SetTarget(this); fSavePanel = new BFilePanel(B_SAVE_PANEL); fSavePanel->SetTarget(this); _SetLevel(level); fSudokuView->StartWatching(this, kUndoRedoChanged); // we like to know whenever the undo/redo state changes fProgressWindow = new ProgressWindow(this, new BMessage(kMsgAbortSudokuGenerator)); if (fSudokuView->Field()->IsEmpty()) PostMessage(kMsgGenerateSudoku); }
MainWindow::MainWindow(void) : BWindow(BRect(200,200,800,750), B_TRANSLATE_SYSTEM_NAME("Slayer"), B_TITLED_WINDOW, 0) { slayer->mainWindow = this; refreshThread = NULL; if (Lock()) { teamView = new TeamListView("MainTeamList"); // Menü BMenuBar* menuBar = new BMenuBar("MenuBar"); BMenu* menu; menu = new BMenu(B_TRANSLATE_SYSTEM_NAME("Slayer")); menuBar->AddItem(menu); menu->AddItem(new BMenuItem(B_TRANSLATE("About Slayer..."), new BMessage(B_ABOUT_REQUESTED))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Settings..."), new BMessage(IE_MAINWINDOW_MAINMENU_WINDOWS_SETTINGS))); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q')); menu = new BMenu(B_TRANSLATE("Action")); menu->AddItem(new BMenuItem(B_TRANSLATE("Kill"), new BMessage(IE_MAINWINDOW_MAINKILL), 'K')); menu->AddItem(new BMenuItem(B_TRANSLATE("Suspend"), new BMessage(IE_MAINWINDOW_MAINSUSPEND), 'S')); menu->AddItem(new BMenuItem(B_TRANSLATE("Resume"), new BMessage(IE_MAINWINDOW_MAINRESUME), 'R')); menu->AddSeparatorItem(); priorityMenu = new PriorityMenu(teamView); menu->AddItem(priorityMenu); priorityMenu->BuildMenu(); menuBar->AddItem(menu); fToolBar = new BToolBar(B_HORIZONTAL); BGroupLayout *topBox = BLayoutBuilder::Group<>(this,B_VERTICAL, 0) .Add(menuBar) .Add(fToolBar) .AddGroup(B_VERTICAL) .SetInsets(B_USE_WINDOW_INSETS, 0, B_USE_WINDOW_INSETS, B_USE_WINDOW_INSETS) .Add(teamView); teamView->LoadState(&(slayer->options.columnsState)); team_items_list = 0; team_amount = 0; iteration = 0; refreshThread = new RefreshThread(); UpdateTeams(); if (slayer->options.wind_rect.IsValid()) { MoveTo(slayer->options.wind_rect.left, slayer->options.wind_rect.top); ResizeTo(slayer->options.wind_rect.Width(), slayer->options.wind_rect.Height()); } minimized = false; if (slayer->options.workspace_activation == Options::all_workspaces) SetWorkspaces(B_ALL_WORKSPACES); else if (slayer->options.workspace_activation == Options::saved_workspace) SetWorkspaces(0x1UL << (slayer->options.workspaces -1 )); if (slayer->options.wind_minimized) Minimize(true); // Quitting has to be disabled if docked if (slayer->docked) { BMenu *menu = (BMenu *)FindView("MainMenu"); BMenuItem *item = menu->FindItem(IE_MAINWINDOW_MAINMENU_FILE_QUIT); item->SetEnabled(false); } fToolBar->AddAction(new BMessage(IE_MAINWINDOW_MAINKILL),this, ResourceVectorToBitmap("KILL"),B_TRANSLATE("Kill"),"",false); fToolBar->AddAction(new BMessage(IE_MAINWINDOW_MAINSUSPEND),this, ResourceVectorToBitmap("SUSPEND"),B_TRANSLATE("Suspend"),"",false); fToolBar->AddAction(new BMessage(IE_MAINWINDOW_MAINRESUME),this, ResourceVectorToBitmap("RESUME"),B_TRANSLATE("Resume"),"",false); fToolBar->AddAction(new BMessage(IE_MAINWINDOW_MAINUPDATE),this, ResourceVectorToBitmap("FORCED_RELOAD"),B_TRANSLATE("Forced reload"),"",false); fToolBar->GetLayout()->AddItem(BSpaceLayoutItem::CreateGlue()); if (teamView != NULL) teamView->MakeFocus(); SetButtonState(); refreshThread->Go(); Unlock(); } Show(); }
void SudokuWindow::MessageReceived(BMessage* message) { if (message->WasDropped()) { _MessageDropped(message); return; } switch (message->what) { case kMsgOpenFilePanel: fOpenPanel->Show(); break; case B_REFS_RECEIVED: case B_SIMPLE_DATA: _MessageDropped(message); break; case kMsgGenerateSudoku: { int32 level; if (message->FindInt32("level", &level) != B_OK) level = _Level(); _SetLevel(level); _Generate(level); break; } case kMsgAbortSudokuGenerator: if (fGenerator != NULL) fGenerator->Abort(); break; case kMsgSudokuGenerated: { BMessage archive; if (message->FindMessage("field", &archive) == B_OK) { SudokuField* field = new SudokuField(&archive); fSudokuView->SetTo(field); } fSudokuView->SetEditable(true); fProgressWindow->Stop(); delete fGenerator; fGenerator = NULL; break; } case kMsgExportAs: { if (message->FindInt32("as", (int32 *)&fExportFormat) < B_OK) fExportFormat = kExportAsText; fSavePanel->Show(); break; } case B_COPY: fSudokuView->CopyToClipboard(); break; case B_SAVE_REQUESTED: { entry_ref directoryRef; const char* name; if (message->FindRef("directory", &directoryRef) != B_OK || message->FindString("name", &name) != B_OK) break; BDirectory directory(&directoryRef); BEntry entry(&directory, name); entry_ref ref; if (entry.GetRef(&ref) == B_OK) fSudokuView->SaveTo(ref, fExportFormat); break; } case kMsgNewBlank: _ResetStoredState(); fSudokuView->ClearAll(); break; case kMsgStartAgain: fSudokuView->ClearChanged(); break; case kMsgMarkInvalid: case kMsgMarkValidHints: { BMenuItem* item; if (message->FindPointer("source", (void**)&item) != B_OK) return; uint32 flag = message->what == kMsgMarkInvalid ? kMarkInvalid : kMarkValidHints; item->SetMarked(!item->IsMarked()); if (item->IsMarked()) fSudokuView->SetHintFlags(fSudokuView->HintFlags() | flag); else fSudokuView->SetHintFlags(fSudokuView->HintFlags() & ~flag); break; } case kMsgStoreState: delete fStoredState; fStoredState = new BMessage; fSudokuView->Field()->Archive(fStoredState, true); fRestoreStateItem->SetEnabled(true); break; case kMsgRestoreState: { if (fStoredState == NULL) break; SudokuField* field = new SudokuField(fStoredState); fSudokuView->SetTo(field); break; } case kMsgSudokuSolved: { BAlert* alert = new BAlert(B_TRANSLATE("Sudoku request"), B_TRANSLATE("Sudoku solved - congratulations!\n"), B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_IDEA_ALERT); alert->SetFlags(alert->Flags() | B_CLOSE_ON_ESCAPE); alert->Go(); break; } case B_OBSERVER_NOTICE_CHANGE: { int32 what; if (message->FindInt32(B_OBSERVE_WHAT_CHANGE, &what) != B_OK) break; if (what == kUndoRedoChanged) { fUndoItem->SetEnabled(fSudokuView->CanUndo()); fRedoItem->SetEnabled(fSudokuView->CanRedo()); } break; } default: BWindow::MessageReceived(message); break; } }
bool FavoritesMenu::AddNextItem() { // run the next chunk of code for a given item adding state if (fState == kStart) { fState = kAddingFavorites; fSectionItemCount = 0; fAddedSeparatorForSection = false; // set up adding the GoTo menu items try { BPath path; ThrowOnError(find_directory(B_USER_SETTINGS_DIRECTORY, &path, true)); path.Append(kGoDirectory); mkdir(path.Path(), 0777); BEntry entry(path.Path()); Model startModel(&entry, true); ThrowOnInitCheckError(&startModel); if (!startModel.IsContainer()) throw B_ERROR; if (startModel.IsQuery()) fContainer = new QueryEntryListCollection(&startModel); else if (startModel.IsVirtualDirectory()) fContainer = new VirtualDirectoryEntryList(&startModel); else { fContainer = new DirectoryEntryList(*dynamic_cast<BDirectory*> (startModel.Node())); } ThrowOnInitCheckError(fContainer); ThrowOnError( fContainer->Rewind() ); } catch (...) { delete fContainer; fContainer = NULL; } } if (fState == kAddingFavorites) { entry_ref ref; if (fContainer != NULL && fContainer->GetNextRef(&ref) == B_OK) { Model model(&ref, true); if (model.InitCheck() != B_OK) return true; if (!ShouldShowModel(&model)) return true; BMenuItem* item = BNavMenu::NewModelItem(&model, model.IsDirectory() ? fOpenFolderMessage : fOpenFileMessage, fTarget); if (item == NULL) return true; item->SetLabel(ref.name); // this is the name of the link in the Go dir if (!fAddedSeparatorForSection) { fAddedSeparatorForSection = true; AddItem(new TitledSeparatorItem(B_TRANSLATE("Favorites"))); } fUniqueRefCheck.push_back(*model.EntryRef()); AddItem(item); fSectionItemCount++; return true; } // done with favorites, set up for adding recent files fState = kAddingFiles; fAddedSeparatorForSection = false; app_info info; be_app->GetAppInfo(&info); fItems.MakeEmpty(); int32 apps, docs, folders; TrackerSettings().RecentCounts(&apps, &docs, &folders); BRoster().GetRecentDocuments(&fItems, docs, NULL, info.signature); fIndex = 0; fSectionItemCount = 0; } if (fState == kAddingFiles) { // if this is a Save panel, not an Open panel // then don't add the recent documents if (!fIsSavePanel) { for (;;) { entry_ref ref; if (fItems.FindRef("refs", fIndex++, &ref) != B_OK) break; Model model(&ref, true); if (model.InitCheck() != B_OK) return true; if (!ShouldShowModel(&model)) return true; BMenuItem* item = BNavMenu::NewModelItem(&model, fOpenFileMessage, fTarget); if (item) { if (!fAddedSeparatorForSection) { fAddedSeparatorForSection = true; AddItem(new TitledSeparatorItem( B_TRANSLATE("Recent documents"))); } AddItem(item); fSectionItemCount++; return true; } } } // done with recent files, set up for adding recent folders fState = kAddingFolders; fAddedSeparatorForSection = false; app_info info; be_app->GetAppInfo(&info); fItems.MakeEmpty(); int32 apps, docs, folders; TrackerSettings().RecentCounts(&apps, &docs, &folders); BRoster().GetRecentFolders(&fItems, folders, info.signature); fIndex = 0; } if (fState == kAddingFolders) { for (;;) { entry_ref ref; if (fItems.FindRef("refs", fIndex++, &ref) != B_OK) break; // don't add folders that are already in the GoTo section if (find_if(fUniqueRefCheck.begin(), fUniqueRefCheck.end(), bind2nd(std::equal_to<entry_ref>(), ref)) != fUniqueRefCheck.end()) { continue; } Model model(&ref, true); if (model.InitCheck() != B_OK) return true; if (!ShouldShowModel(&model)) return true; BMenuItem* item = BNavMenu::NewModelItem(&model, fOpenFolderMessage, fTarget, true); if (item != NULL) { if (!fAddedSeparatorForSection) { fAddedSeparatorForSection = true; AddItem(new TitledSeparatorItem( B_TRANSLATE("Recent folders"))); } AddItem(item); item->SetEnabled(true); // BNavMenu::NewModelItem returns a disabled item here - // need to fix this in BNavMenu::NewModelItem return true; } } } return false; }
uint32 PackageInstall::_Install() { PackageInfo *info = fParent->GetPackageInfo(); pkg_profile *type = static_cast<pkg_profile *>(info->GetProfile( fParent->GetCurrentType())); uint32 n = type->items.CountItems(), m = info->GetScriptCount(); PackageStatus *progress = fParent->GetStatusWindow(); progress->Reset(n + m + 5); progress->StageStep(1, B_TRANSLATE("Preparing package")); InstalledPackageInfo packageInfo(info->GetName(), info->GetVersion()); status_t err = packageInfo.InitCheck(); if (err == B_OK) { // The package is already installed, inform the user BAlert *reinstall = new BAlert("reinstall", B_TRANSLATE("The given package seems to be already installed on " "your system. Would you like to uninstall the existing one " "and continue the installation?"), B_TRANSLATE("Continue"), B_TRANSLATE("Abort")); if (reinstall->Go() == 0) { // Uninstall the package err = packageInfo.Uninstall(); if (err != B_OK) { fprintf(stderr, B_TRANSLATE("Error on uninstall\n")); return P_MSG_I_ERROR; } err = packageInfo.SetTo(info->GetName(), info->GetVersion(), true); if (err != B_OK) { fprintf(stderr, B_TRANSLATE("Error on SetTo\n")); return P_MSG_I_ERROR; } } else { // Abort the installation return P_MSG_I_ABORT; } } else if (err == B_ENTRY_NOT_FOUND) { err = packageInfo.SetTo(info->GetName(), info->GetVersion(), true); if (err != B_OK) { fprintf(stderr, B_TRANSLATE("Error on SetTo\n")); return P_MSG_I_ERROR; } } else if (progress->Stopped()) { return P_MSG_I_ABORT; } else { fprintf(stderr, B_TRANSLATE("returning on error\n")); return P_MSG_I_ERROR; } progress->StageStep(1, B_TRANSLATE("Installing files and folders")); // Install files and directories PackageItem *iter; ItemState state; uint32 i; int32 choice; BString label; packageInfo.SetName(info->GetName()); // TODO: Here's a small problem, since right now it's not quite sure // which description is really used as such. The one displayed on // the installer is mostly package installation description, but // most people use it for describing the application in more detail // then in the short description. // For now, we'll use the short description if possible. BString description = info->GetShortDescription(); if (description.Length() <= 0) description = info->GetDescription(); packageInfo.SetDescription(description.String()); packageInfo.SetSpaceNeeded(type->space_needed); fItemExistsPolicy = P_EXISTS_NONE; const char *installPath = fParent->GetCurrentPath()->Path(); for (i = 0; i < n; i++) { state.Reset(fItemExistsPolicy); // Reset the current item state iter = static_cast<PackageItem *>(type->items.ItemAt(i)); err = iter->DoInstall(installPath, &state); if (err == B_FILE_EXISTS) { // Writing to path failed because path already exists - ask the user // what to do and retry the writing process choice = fParent->ItemExists(*iter, state.destination, fItemExistsPolicy); if (choice != P_EXISTS_ABORT) { state.policy = choice; err = iter->DoInstall(installPath, &state); } } if (err != B_OK) { fprintf(stderr, B_TRANSLATE("Error while writing path\n")); return P_MSG_I_ERROR; } if (progress->Stopped()) return P_MSG_I_ABORT; label = ""; label << (uint32)(i + 1) << " of " << (uint32)n; progress->StageStep(1, NULL, label.String()); packageInfo.AddItem(state.destination.Path()); } progress->StageStep(1, B_TRANSLATE("Running post-installation scripts"), ""); PackageScript *scr; status_t status; // Run all scripts for (i = 0; i < m; i++) { scr = info->GetScript(i); fCurrentScriptLocker.Lock(); fCurrentScript = scr; if (scr->DoInstall() != B_OK) { fprintf(stderr, B_TRANSLATE("Error while running script\n")); return P_MSG_I_ERROR; } fCurrentScriptLocker.Unlock(); wait_for_thread(scr->GetThreadId(), &status); fCurrentScriptLocker.Lock(); scr->SetThreadId(-1); fCurrentScript = NULL; fCurrentScriptLocker.Unlock(); if (progress->Stopped()) return P_MSG_I_ABORT; label = ""; label << (uint32)(i + 1) << " of " << (uint32)m; progress->StageStep(1, NULL, label.String()); } progress->StageStep(1, B_TRANSLATE("Finishing installation"), ""); err = packageInfo.Save(); if (err != B_OK) return P_MSG_I_ERROR; progress->StageStep(1, B_TRANSLATE("Done")); // Inform our parent that we finished return P_MSG_I_FINISHED; }
status_t MediaWindow::InitMedia(bool first) { status_t err = B_OK; BMediaRoster* roster = BMediaRoster::Roster(&err); if (first && err != B_OK) { BAlert* alert = new BAlert("start_media_server", B_TRANSLATE("Could not connect to the media server.\n" "Would you like to start it ?"), B_TRANSLATE("Quit"), B_TRANSLATE("Start media server"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); if (alert->Go()==0) return B_ERROR; fAlert = new MediaAlert(BRect(0, 0, 300, 60), "restart_alert", B_TRANSLATE( "Restarting media services\nStarting media server" B_UTF8_ELLIPSIS "\n")); fAlert->Show(); Show(); launch_media_server(); } Lock(); bool isVideoSelected = true; if (!first && fListView->ItemAt(0) && fListView->ItemAt(0)->IsSelected()) isVideoSelected = false; if ((!first || (first && err) ) && fAlert) { BAutolock locker(fAlert); if (locker.IsLocked()) fAlert->TextView()->SetText( B_TRANSLATE("Ready for use" B_UTF8_ELLIPSIS)); } while (fListView->CountItems() > 0) delete fListView->RemoveItem((int32)0); _EmptyNodeLists(); // Grab Media Info _FindNodes(); // Add video nodes first. They might have an additional audio // output or input, but still should be listed as video node. _AddNodeItems(fVideoOutputs, MediaListItem::VIDEO_TYPE); _AddNodeItems(fVideoInputs, MediaListItem::VIDEO_TYPE); _AddNodeItems(fAudioOutputs, MediaListItem::AUDIO_TYPE); _AddNodeItems(fAudioInputs, MediaListItem::AUDIO_TYPE); fAudioView->AddOutputNodes(fAudioOutputs); fAudioView->AddInputNodes(fAudioInputs); fVideoView->AddOutputNodes(fVideoOutputs); fVideoView->AddInputNodes(fVideoInputs); // build our list view DeviceListItem* audio = new DeviceListItem(B_TRANSLATE("Audio settings"), MediaListItem::AUDIO_TYPE); fListView->AddItem(audio); MediaListItem* video = new DeviceListItem(B_TRANSLATE("Video settings"), MediaListItem::VIDEO_TYPE); fListView->AddItem(video); MediaListItem* mixer = new AudioMixerListItem(B_TRANSLATE("Audio mixer")); fListView->AddItem(mixer); fListView->SortItems(&MediaListItem::Compare); _UpdateListViewMinWidth(); // Set default nodes for our setting views media_node default_node; dormant_node_info node_info; int32 outputID; BString outputName; if (roster->GetAudioInput(&default_node) == B_OK) { roster->GetDormantNodeFor(default_node, &node_info); fAudioView->SetDefaultInput(&node_info); // this causes our listview to be updated as well } if (roster->GetAudioOutput(&default_node, &outputID, &outputName)==B_OK) { roster->GetDormantNodeFor(default_node, &node_info); fAudioView->SetDefaultOutput(&node_info); fAudioView->SetDefaultChannel(outputID); // this causes our listview to be updated as well } if (roster->GetVideoInput(&default_node)==B_OK) { roster->GetDormantNodeFor(default_node, &node_info); fVideoView->SetDefaultInput(&node_info); // this causes our listview to be updated as well } if (roster->GetVideoOutput(&default_node)==B_OK) { roster->GetDormantNodeFor(default_node, &node_info); fVideoView->SetDefaultOutput(&node_info); // this causes our listview to be updated as well } if (first) { fListView->Select(fListView->IndexOf(mixer)); } else { if (isVideoSelected) fListView->Select(fListView->IndexOf(video)); else fListView->Select(fListView->IndexOf(audio)); } if (fAlert) { snooze(800000); fAlert->PostMessage(B_QUIT_REQUESTED); } fAlert = NULL; Unlock(); return B_OK; }
CharacterWindow::CharacterWindow() : BWindow(BRect(100, 100, 700, 550), B_TRANSLATE_SYSTEM_NAME("CharacterMap"), B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS) { BMessage settings; _LoadSettings(settings); BRect frame; if (settings.FindRect("window frame", &frame) == B_OK) { MoveTo(frame.LeftTop()); ResizeTo(frame.Width(), frame.Height()); } // create GUI SetLayout(new BGroupLayout(B_VERTICAL)); BMenuBar* menuBar = new BMenuBar("menu"); fFilterControl = new BTextControl(B_TRANSLATE("Filter:"), NULL, NULL); fFilterControl->SetModificationMessage(new BMessage(kMsgFilterChanged)); BButton* clearButton = new BButton("clear", B_TRANSLATE("Clear"), new BMessage(kMsgClearFilter)); fUnicodeBlockView = new UnicodeBlockView("unicodeBlocks"); fUnicodeBlockView->SetSelectionMessage( new BMessage(kMsgUnicodeBlockSelected)); BScrollView* unicodeScroller = new BScrollView("unicodeScroller", fUnicodeBlockView, 0, false, true); fCharacterView = new CharacterView("characters"); fCharacterView->SetTarget(this, kMsgCharacterChanged); fGlyphView = new BStringView("glyph", ""); fGlyphView->SetExplicitMaxSize(BSize(B_SIZE_UNSET, fGlyphView->PreferredSize().Height())); // TODO: have a context object shared by CharacterView/UnicodeBlockView bool show; if (settings.FindBool("show private blocks", &show) == B_OK) { fCharacterView->ShowPrivateBlocks(show); fUnicodeBlockView->ShowPrivateBlocks(show); } if (settings.FindBool("show contained blocks only", &show) == B_OK) { fCharacterView->ShowContainedBlocksOnly(show); fUnicodeBlockView->ShowPrivateBlocks(show); } const char* family; const char* style; if (settings.FindString("font family", &family) == B_OK && settings.FindString("font style", &style) == B_OK) { _SetFont(family, style); } int32 fontSize; if (settings.FindInt32("font size", &fontSize) == B_OK) { BFont font = fCharacterView->CharacterFont(); if (fontSize < kMinFontSize) fontSize = kMinFontSize; else if (fontSize > kMaxFontSize) fontSize = kMaxFontSize; font.SetSize(fontSize); fCharacterView->SetCharacterFont(font); } else fontSize = (int32)fCharacterView->CharacterFont().Size(); BScrollView* characterScroller = new BScrollView("characterScroller", fCharacterView, 0, false, true); fFontSizeSlider = new FontSizeSlider("fontSizeSlider", B_TRANSLATE("Font size:"), new BMessage(kMsgFontSizeChanged), kMinFontSize, kMaxFontSize); fFontSizeSlider->SetValue(fontSize); fCodeView = new BStringView("code", "-"); fCodeView->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, fCodeView->PreferredSize().Height())); AddChild(BGroupLayoutBuilder(B_VERTICAL) .Add(menuBar) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10)//BSplitLayoutBuilder() .Add(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 10) .Add(fFilterControl) .Add(clearButton)) .Add(unicodeScroller)) .Add(BGroupLayoutBuilder(B_VERTICAL, 10) .Add(characterScroller) .Add(fFontSizeSlider) .Add(BGroupLayoutBuilder(B_HORIZONTAL, 0) .Add(fGlyphView) .Add(fCodeView))) .SetInsets(10, 10, 10, 10))); // Add menu // "File" menu BMenu* menu = new BMenu(B_TRANSLATE("File")); BMenuItem* item; menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED), 'Q')); menu->SetTargetForItems(this); menuBar->AddItem(menu); menu = new BMenu(B_TRANSLATE("View")); menu->AddItem(item = new BMenuItem(B_TRANSLATE("Show private blocks"), new BMessage(kMsgPrivateBlocks))); item->SetMarked(fCharacterView->IsShowingPrivateBlocks()); // TODO: this feature is not yet supported by Haiku! #if 0 menu->AddItem(item = new BMenuItem("Only show blocks contained in font", new BMessage(kMsgContainedBlocks))); item->SetMarked(fCharacterView->IsShowingContainedBlocksOnly()); #endif menuBar->AddItem(menu); menuBar->AddItem(_CreateFontMenu()); AddCommonFilter(new EscapeMessageFilter(kMsgClearFilter)); AddCommonFilter(new RedirectUpAndDownFilter(fUnicodeBlockView)); // TODO: why is this needed? fUnicodeBlockView->SetTarget(this); fFilterControl->MakeFocus(); }
bool ShortcutsSpec::ProcessColumnKeyStroke(int whichColumn, const char* bytes, int32 key) { bool result = false; switch (whichColumn) { case KEY_COLUMN_INDEX: if (key > -1) { if ((int32)fKey != key) { fKey = key; result = true; } } break; case STRING_COLUMN_INDEX: { switch (bytes[0]) { case B_BACKSPACE: case B_DELETE: if (fCommandNul > 0) { // trim a char off the string fCommand[fCommandNul - 1] = '\0'; fCommandNul--; // note new nul position result = true; } break; case B_TAB: if (_AttemptTabCompletion()) { result = true; } else beep(); break; default: { uint32 newCharLen = strlen(bytes); if ((newCharLen > 0) && (bytes[0] >= ' ')) { bool reAllocString = false; // Make sure we have enough room in our command string // to add these chars... while (fCommandLen - fCommandNul <= newCharLen) { reAllocString = true; // enough for a while... fCommandLen = (fCommandLen + 10) * 2; } if (reAllocString) { char* temp = new char[fCommandLen]; strcpy(temp, fCommand); delete [] fCommand; fCommand = temp; // fCommandNul is still valid since it's an offset // and the string length is the same for now } // Here we should be guaranteed enough room. strncat(fCommand, bytes, fCommandLen); fCommandNul += newCharLen; result = true; } } } break; } default: if (whichColumn < 0 || whichColumn >= NUM_META_COLUMNS) break; MetaKeyStateMap * map = &sMetaMaps[whichColumn]; int curState = fMetaCellStateIndex[whichColumn]; int origState = curState; int numStates = map->GetNumStates(); switch(bytes[0]) { case B_RETURN: // cycle to the previous state curState = (curState + numStates - 1) % numStates; break; case B_SPACE: // cycle to the next state curState = (curState + 1) % numStates; break; default: { // Go to the state starting with the given letter, if // any char letter = bytes[0]; if (islower(letter)) letter = toupper(letter); // convert to upper case if ((letter == B_BACKSPACE) || (letter == B_DELETE)) letter = '('; // so space bar will blank out an entry for (int i = 0; i < numStates; i++) { const char* desc = map->GetNthStateDesc(i); if (desc) { if (desc[0] == letter) { curState = i; break; } } else { puts(B_TRANSLATE( "Error, NULL state description?")); } } } } fMetaCellStateIndex[whichColumn] = curState; if (curState != origState) result = true; } SetField(new BStringField(GetCellText(whichColumn)), whichColumn); return result; }
ErrorWindow::ErrorWindow(BRect frame, ProjectWindow* parent, ErrorList* list) : BWindow(frame, B_TRANSLATE("Errors and warnings"), B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS), fParent(parent), fErrorCount(0), fWarningCount(0) { SetSizeLimits(400, 30000, 250, 30000); MoveTo(100,100); AddShortcut('M', B_COMMAND_KEY, new BMessage(M_MAKE_PROJECT)); AddShortcut('R', B_COMMAND_KEY, new BMessage(M_RUN_PROJECT)); AddShortcut('R', B_COMMAND_KEY | B_SHIFT_KEY, new BMessage(M_RUN_IN_TERMINAL)); AddShortcut('R', B_COMMAND_KEY | B_CONTROL_KEY, new BMessage(M_RUN_IN_DEBUGGER)); AddShortcut('R', B_COMMAND_KEY | B_CONTROL_KEY | B_SHIFT_KEY, new BMessage(M_RUN_WITH_ARGS)); AddShortcut('-', B_COMMAND_KEY, new BMessage(M_FORCE_REBUILD)); AddShortcut('I', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); AddShortcut('W', B_COMMAND_KEY, new BMessage(B_QUIT_REQUESTED)); if (list != NULL) fErrors = *list; if (parent != NULL) { BString text = B_TRANSLATE("Errors and warnings: "); text << fParent->GetProject()->GetName(); SetTitle(text.String()); } else debugger("BUG: Invalid project for error window"); BString startingLabel(B_TRANSLATE("Errors")); startingLabel << " (10000)"; fErrorBox = new BCheckBox("errorbox", startingLabel.String(), new BMessage(M_TOGGLE_ERRORS)); fErrorBox->SetLabel(B_TRANSLATE("Errors")); fErrorBox->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); startingLabel = B_TRANSLATE("Warnings"); startingLabel << " (10000)"; fWarningBox = new BCheckBox("warningbox", startingLabel.String(), new BMessage(M_TOGGLE_WARNINGS)); fWarningBox->SetLabel("Warnings"); fWarningBox->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_CENTER)); fCopyButton = new BButton("copy", B_TRANSLATE("Copy to clipboard"), new BMessage(M_COPY_ERRORS)); fErrorList = new DListView("errorlist", B_SINGLE_SELECTION_LIST, B_WILL_DRAW | B_NAVIGABLE); BScrollView* errorScrollView = fErrorList->MakeScrollView("scroller", true, true); errorScrollView->ScrollBar(B_HORIZONTAL)->SetSteps(25, 75); BPopUpMenu* contextMenu = new BPopUpMenu("context_menu", false, false); contextMenu->AddItem(new BMenuItem(B_TRANSLATE("Copy list to clipboard"), new BMessage(M_COPY_ERRORS))); contextMenu->SetTargetForItems(this); fErrorList->SetContextMenu(contextMenu); BView* header = BLayoutBuilder::Group<>(B_HORIZONTAL) .Add(fErrorBox) .Add(fWarningBox) .Add(fCopyButton) .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, 0, B_USE_DEFAULT_SPACING, 0) .View(); header->SetName("header"); header->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); BLayoutBuilder::Group<>(this, B_VERTICAL, 0) .Add(header) .Add(errorScrollView) .SetInsets(-1.0f) .End(); if (list != NULL) RefreshList(); BRect newframe; BNode node(fParent->GetProject()->GetPath().GetFullPath()); if (node.ReadAttr("error_frame", B_RECT_TYPE, 0, &newframe, sizeof(newframe))) { if (newframe.left < 100) newframe.left = 100; if (newframe.top < 100) newframe.top = 100; MoveTo(newframe.left, newframe.top); ResizeTo(newframe.Width(), newframe.Height()); } fErrorBox->SetValue(B_CONTROL_ON); fWarningBox->SetValue(B_CONTROL_ON); fErrorList->SetInvocationMessage(new BMessage(M_JUMP_TO_MSG)); fErrorList->MakeFocus(true); }