AskName::AskName(): BWindow(BRect(100, 100, 500, 200), "Enter your name", B_TITLED_WINDOW, B_NOT_RESIZABLE | B_NOT_CLOSABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE), Text(NULL), text(NULL) { BView *back; BButton * Accept; BTextView *TV; BStringView *str; const char *names[] = { "BeOS forever!", "BShisen Rules!", "Thanks Sheppy", "Say NO to drugs!", "Say NO to piracy!", "Say YES to BeOS!", "Just say \"BShisen\"", "Say YES to BShisen!", }; back = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW); back->SetViewColor(216, 216, 216); AddChild(back); str = new BStringView(BRect(10, 10, 390, 25), "", "Congratulations! Enter your name for posterity."); str->SetFont(be_bold_font); back->AddChild(str); Accept = new BButton( BRect(10, 60+5, 90, 75+5), "Accept", "Accept", new BMessage(ACCEPT_BUTTON)); Accept->MakeDefault(true); back->AddChild(Accept); Text = new BTextControl(BRect(10, 35, 390, 50), "", "Your Name", "", NULL); Text->SetDivider(Text->StringWidth("Your Name ")); TV = Text->TextView(); TV->SetMaxBytes(31); Text->SetText(REGISTERED ? names[rand() % 8] : "I Want To Register!"); back->AddChild(Text); Text->MakeFocus(true); }
void ApplicationTypeWindow::_MakeNumberTextControl(BTextControl* control) { // filter out invalid characters that can't be part of a MIME type name BTextView* textView = control->TextView(); textView->SetMaxBytes(10); for (int32 i = 0; i < 256; i++) { if (!isdigit(i)) textView->DisallowChar(i); } }
/** * AllowOnlyNumbers() * * @param BTextControl, the control we want to only allow numbers * @param maxNum, the maximun number of characters allowed * @return void */ void MarginView::_AllowOnlyNumbers(BTextControl *textControl, int32 maxNum) { BTextView *tv = textControl->TextView(); for (int32 i = 0; i < 256; i++) tv->DisallowChar(i); for (int32 i = '0'; i <= '9'; i++) tv->AllowChar(i); tv->AllowChar(B_BACKSPACE); tv->AllowChar('.'); tv->SetMaxBytes(maxNum); }
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)); flagsBox->AddChild(BGridLayoutBuilder() .Add(fSingleLaunchButton, 0, 0).Add(fArgsOnlyCheckBox, 1, 0) .Add(fMultipleLaunchButton, 0, 1).Add(fBackgroundAppCheckBox, 1, 1) .Add(fExclusiveLaunchButton, 0, 2) .SetInsets(padding, padding, padding, padding)); flagsBox->SetLabel(fFlagsCheckBox); // "Icon" group BBox* iconBox = new BBox("IconBox"); iconBox->SetLabel(B_TRANSLATE("Icon")); fIconView = new IconView("icon"); fIconView->SetModificationMessage(new BMessage(kMsgIconChanged)); iconBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) .Add(fIconView) .SetInsets(padding, padding, padding, padding)); // "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"); BView* iconHolder = BGroupLayoutBuilder(B_HORIZONTAL).Add(fTypeIconView); fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged)); typeBox->AddChild(BGridLayoutBuilder(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) .SetInsets(padding, padding, padding, padding) .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); versionBox->AddChild(BGridLayoutBuilder(padding / 2, 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) .SetInsets(padding, padding, padding, padding) .SetRowWeight(3, 3)); // put it all together SetLayout(new BGroupLayout(B_VERTICAL)); AddChild(menuBar); AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) .Add(fSignatureControl) .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) .Add(flagsBox, 3) .Add(iconBox, 1)) .Add(typeBox) .Add(versionBox) .SetInsets(padding, padding, padding, padding)); SetKeyMenuBar(menuBar); fSignatureControl->MakeFocus(true); BMimeType::StartWatching(this); _SetTo(entry); }
ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry) : BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), "Application Type", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), fChangedProperties(0) { // add the menu BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); AddChild(menuBar); BMenu* menu = new BMenu("File"); fSaveMenuItem = new BMenuItem("Save", new BMessage(kMsgSave), 'S'); fSaveMenuItem->SetEnabled(false); menu->AddItem(fSaveMenuItem); BMenuItem* item; menu->AddItem(item = new BMenuItem("Save into resource file" B_UTF8_ELLIPSIS, NULL)); item->SetEnabled(false); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W', B_COMMAND_KEY)); menuBar->AddItem(menu); // Top view and signature BRect rect = Bounds(); rect.top = menuBar->Bounds().Height() + 1.0f; BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(topView); rect = topView->Bounds().InsetByCopy(8.0f, 8.0f); fSignatureControl = new BTextControl(rect, "signature", "Signature:", NULL, new BMessage(kMsgSignatureChanged), B_FOLLOW_LEFT_RIGHT); fSignatureControl->SetModificationMessage( new BMessage(kMsgSignatureChanged)); fSignatureControl->SetDivider(fSignatureControl->StringWidth( fSignatureControl->Label()) + 4.0f); float width, height; fSignatureControl->GetPreferredSize(&width, &height); fSignatureControl->ResizeTo(rect.Width(), height); topView->AddChild(fSignatureControl); // 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 BFont font(be_bold_font); font_height fontHeight; font.GetHeight(&fontHeight); width = font.StringWidth("Icon") + 16.0f; if (width < B_LARGE_ICON + 16.0f) width = B_LARGE_ICON + 16.0f; rect.top = fSignatureControl->Frame().bottom + 4.0f; rect.bottom = rect.top + 100.0f; rect.right -= width + 8.0f; BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); topView->AddChild(box); fFlagsCheckBox = new BCheckBox(rect, "flags", "Application flags", new BMessage(kMsgToggleAppFlags)); fFlagsCheckBox->SetValue(B_CONTROL_ON); fFlagsCheckBox->ResizeToPreferred(); box->SetLabel(fFlagsCheckBox); rect.top = fFlagsCheckBox->Bounds().Height() + 4.0f; fSingleLaunchButton = new BRadioButton(rect, "single", "Single launch", new BMessage(kMsgAppFlagsChanged)); fSingleLaunchButton->ResizeToPreferred(); box->AddChild(fSingleLaunchButton); rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f); fMultipleLaunchButton = new BRadioButton(rect, "multiple", "Multiple launch", new BMessage(kMsgAppFlagsChanged)); fMultipleLaunchButton->ResizeToPreferred(); box->AddChild(fMultipleLaunchButton); rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f); fExclusiveLaunchButton = new BRadioButton(rect, "exclusive", "Exclusive launch", new BMessage(kMsgAppFlagsChanged)); fExclusiveLaunchButton->ResizeToPreferred(); box->AddChild(fExclusiveLaunchButton); rect.top = fSingleLaunchButton->Frame().top; rect.left = fExclusiveLaunchButton->Frame().right + 4.0f; fArgsOnlyCheckBox = new BCheckBox(rect, "args only", "Args only", new BMessage(kMsgAppFlagsChanged)); fArgsOnlyCheckBox->ResizeToPreferred(); box->AddChild(fArgsOnlyCheckBox); rect.top += fArgsOnlyCheckBox->Bounds().Height(); fBackgroundAppCheckBox = new BCheckBox(rect, "background", "Background app", new BMessage(kMsgAppFlagsChanged)); fBackgroundAppCheckBox->ResizeToPreferred(); box->AddChild(fBackgroundAppCheckBox); box->ResizeTo(box->Bounds().Width(), fExclusiveLaunchButton->Frame().bottom + 8.0f); // "Icon" group rect = box->Frame(); #ifdef __ANTARES__ rect.top += box->TopBorderOffset(); #endif rect.left = rect.right + 8.0f; rect.right += width + 8.0f; float iconBoxWidth = rect.Width(); box = new BBox(rect, NULL, B_FOLLOW_RIGHT | B_FOLLOW_TOP); box->SetLabel("Icon"); #ifdef __ANTARES__ box->MoveBy(0.0f, -box->TopBorderOffset()); box->ResizeBy(0.0f, box->TopBorderOffset()); #endif topView->AddChild(box); rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f); #ifdef __ANTARES__ rect.OffsetBy(0.0f, (box->Bounds().Height() + box->TopBorderOffset() - rect.Height()) / 2.0f); #else rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f); #endif if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f) rect.top = fontHeight.ascent + fontHeight.descent + 4.0f; fIconView = new IconView(rect, "icon"); fIconView->SetModificationMessage(new BMessage(kMsgIconChanged)); box->AddChild(fIconView); // "Supported Types" group rect.top = box->Frame().bottom + 8.0f; rect.bottom = rect.top + box->Bounds().Height(); rect.left = 8.0f; rect.right = Bounds().Width() - 8.0f; BBox* typeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); typeBox->SetLabel("Supported types"); topView->AddChild(typeBox); rect = typeBox->Bounds().InsetByCopy(8.0f, 6.0f); rect.top += ceilf(fontHeight.ascent); fAddTypeButton = new BButton(rect, "add type", "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddType), B_FOLLOW_RIGHT); fAddTypeButton->ResizeToPreferred(); fAddTypeButton->MoveBy(rect.right - fAddTypeButton->Bounds().Width() - B_LARGE_ICON - 16.0f, 0.0f); typeBox->AddChild(fAddTypeButton); rect = fAddTypeButton->Frame(); rect.OffsetBy(0, rect.Height() + 4.0f); fRemoveTypeButton = new BButton(rect, "remove type", "Remove", new BMessage(kMsgRemoveType), B_FOLLOW_RIGHT); typeBox->AddChild(fRemoveTypeButton); rect.right = rect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; rect.left = 10.0f; rect.top = 8.0f + ceilf(fontHeight.ascent); rect.bottom -= 2.0f; // take scrollview border into account fTypeListView = new SupportedTypeListView(rect, "type listview", B_SINGLE_SELECTION_LIST, B_FOLLOW_ALL); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); BScrollView* scrollView = new BScrollView("type scrollview", fTypeListView, B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); typeBox->ResizeTo(typeBox->Bounds().Width(), fRemoveTypeButton->Frame().bottom + 8.0f); typeBox->AddChild(scrollView); rect.left = fRemoveTypeButton->Frame().right + 8.0f; #ifdef __ANTARES__ rect.top = (box->Bounds().Height() + box->TopBorderOffset() - B_LARGE_ICON) / 2.0f; #else rect.top = (box->Bounds().Height() - B_LARGE_ICON) / 2.0f; #endif rect.right = rect.left + B_LARGE_ICON - 1.0f; rect.bottom = rect.top + B_LARGE_ICON - 1.0f; fTypeIconView = new IconView(rect, "type icon", B_FOLLOW_RIGHT | B_FOLLOW_TOP); fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged)); typeBox->AddChild(fTypeIconView); // "Version Info" group rect.top = typeBox->Frame().bottom + 8.0f; rect.bottom = rect.top + typeBox->Bounds().Height(); rect.left = 8.0f; rect.right = Bounds().Width() - 8.0f; box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); // the resizing mode will later also be set to B_FOLLOW_BOTTOM box->SetLabel("Version info"); topView->AddChild(box); BMenuField* menuField; #if 0 BPopUpMenu *popUpMenu = new BPopUpMenu("version info", true, true); item = new BMenuItem("Version Info", NULL); item->SetMarked(true); popUpMenu->AddItem(item); item = new BMenuItem("System Version Info", NULL); popUpMenu->AddItem(item); menuField = new BMenuField(BRect(0, 0, 100, 15), "version kind", NULL, popUpMenu, true); menuField->ResizeToPreferred(); box->SetLabel(menuField); #endif rect.top = 4.0f + ceilf(fontHeight.ascent + fontHeight.descent); rect.bottom = rect.top + height; fMajorVersionControl = new BTextControl(rect, "major", "Version:", NULL, NULL); fMajorVersionControl->SetDivider(fMajorVersionControl->StringWidth( fMajorVersionControl->Label()) + 4.0f); fMajorVersionControl->GetPreferredSize(&width, &height); width = 12.0f + fMajorVersionControl->StringWidth("99"); fMajorVersionControl->ResizeTo(fMajorVersionControl->Divider() + width, height); _MakeNumberTextControl(fMajorVersionControl); box->AddChild(fMajorVersionControl); rect.left = fMajorVersionControl->Frame().right + 1.0f; fMiddleVersionControl = new BTextControl(rect, "middle", ".", NULL, NULL); fMiddleVersionControl->SetDivider(fMiddleVersionControl->StringWidth( fMiddleVersionControl->Label()) + 4.0f); fMiddleVersionControl->ResizeTo(fMiddleVersionControl->Divider() + width, height); _MakeNumberTextControl(fMiddleVersionControl); box->AddChild(fMiddleVersionControl); rect.left = fMiddleVersionControl->Frame().right + 1.0f; fMinorVersionControl = new BTextControl(rect, "middle", ".", NULL, NULL); fMinorVersionControl->SetDivider(fMinorVersionControl->StringWidth( fMinorVersionControl->Label()) + 4.0f); fMinorVersionControl->ResizeTo(fMinorVersionControl->Divider() + width, height); _MakeNumberTextControl(fMinorVersionControl); box->AddChild(fMinorVersionControl); fVarietyMenu = new BPopUpMenu("variety", true, true); fVarietyMenu->AddItem(new BMenuItem("Development", NULL)); fVarietyMenu->AddItem(new BMenuItem("Alpha", NULL)); fVarietyMenu->AddItem(new BMenuItem("Beta", NULL)); fVarietyMenu->AddItem(new BMenuItem("Gamma", NULL)); fVarietyMenu->AddItem(item = new BMenuItem("Golden master", NULL)); item->SetMarked(true); fVarietyMenu->AddItem(new BMenuItem("Final", NULL)); rect.top--; // BMenuField oddity rect.left = fMinorVersionControl->Frame().right + 6.0f; menuField = new BMenuField(rect, "variety", NULL, fVarietyMenu, true); menuField->ResizeToPreferred(); box->AddChild(menuField); rect.top++; rect.left = menuField->Frame().right; rect.right = rect.left + 30.0f; fInternalVersionControl = new BTextControl(rect, "internal", "/", NULL, NULL); fInternalVersionControl->SetDivider(fInternalVersionControl->StringWidth( fInternalVersionControl->Label()) + 4.0f); fInternalVersionControl->ResizeTo(fInternalVersionControl->Divider() + width, height); box->AddChild(fInternalVersionControl); rect = box->Bounds().InsetByCopy(8.0f, 0.0f); rect.top = fInternalVersionControl->Frame().bottom + 8.0f; fShortDescriptionControl = new BTextControl(rect, "short desc", "Short description:", NULL, NULL, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); float labelWidth = fShortDescriptionControl->StringWidth( fShortDescriptionControl->Label()) + 4.0f; fShortDescriptionControl->SetDivider(labelWidth); fShortDescriptionControl->GetPreferredSize(&width, &height); fShortDescriptionControl->ResizeTo(rect.Width(), height); // 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)); box->AddChild(fShortDescriptionControl); rect.OffsetBy(0.0f, fShortDescriptionControl->Bounds().Height() + 5.0f); rect.right = rect.left + labelWidth; StringView* label = new StringView(rect, NULL, "Long description:", NULL); label->SetDivider(labelWidth); box->AddChild(label); rect.left = rect.right + 3.0f; rect.top += 1.0f; rect.right = box->Bounds().Width() - 10.0f - B_V_SCROLL_BAR_WIDTH; rect.bottom = rect.top + fShortDescriptionControl->Bounds().Height() * 3.0f - 1.0f; fLongDescriptionView = new TabFilteringTextView(rect, "long desc", rect.OffsetToCopy(B_ORIGIN), B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); fLongDescriptionView->SetMaxBytes(sizeof(versionInfo.long_info)); scrollView = new BScrollView("desc scrollview", fLongDescriptionView, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_FRAME_EVENTS | B_WILL_DRAW, false, true); box->ResizeTo(box->Bounds().Width(), scrollView->Frame().bottom + 8.0f); box->AddChild(scrollView); // Adjust window size and limits width = fInternalVersionControl->Frame().right + 16.0f; float minWidth = fBackgroundAppCheckBox->Frame().right + iconBoxWidth + 32.0f; if (width > minWidth) minWidth = width; ResizeTo(Bounds().Width() > minWidth ? Bounds().Width() : minWidth, box->Frame().bottom + topView->Frame().top + 8.0f); SetSizeLimits(minWidth, 32767.0f, Bounds().Height(), 32767.0f); typeBox->SetResizingMode(B_FOLLOW_ALL); box->SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM); fSignatureControl->MakeFocus(true); BMimeType::StartWatching(this); _SetTo(entry); }
AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, AttributeItem* attributeItem) : BWindow(BRect(100, 100, 350, 200), "Attribute", B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), fTarget(target), fMimeType(mimeType.Type()) { if (attributeItem != NULL) fAttribute = *attributeItem; BRect rect = Bounds(); BView* topView = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); AddChild(topView); rect.InsetBy(8.0f, 8.0f); fPublicNameControl = new BTextControl(rect, "public", "Attribute name:", fAttribute.PublicName(), NULL, B_FOLLOW_LEFT_RIGHT); fPublicNameControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); float labelWidth = fPublicNameControl->StringWidth(fPublicNameControl->Label()) + 2.0f; fPublicNameControl->SetDivider(labelWidth); fPublicNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); float width, height; fPublicNameControl->GetPreferredSize(&width, &height); fPublicNameControl->ResizeTo(rect.Width(), height); topView->AddChild(fPublicNameControl); rect = fPublicNameControl->Frame(); rect.OffsetBy(0.0f, rect.Height() + 5.0f); fAttributeControl = new BTextControl(rect, "internal", "Internal name:", fAttribute.Name(), NULL, B_FOLLOW_LEFT_RIGHT); fAttributeControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); fAttributeControl->SetDivider(labelWidth); 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]); } topView->AddChild(fAttributeControl); 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); } rect.OffsetBy(0.0f, rect.Height() + 4.0f); BMenuField* menuField = new BMenuField(rect, "types", "Type:", fTypeMenu); menuField->SetDivider(labelWidth); menuField->SetAlignment(B_ALIGN_RIGHT); menuField->GetPreferredSize(&width, &height); menuField->ResizeTo(rect.Width(), height); topView->AddChild(menuField); rect.OffsetBy(0.0f, rect.Height() + 4.0f); rect.bottom = rect.top + fAttributeControl->Bounds().Height() * 2.0f + 18.0f; BBox* box = new BBox(rect, "", B_FOLLOW_LEFT_RIGHT); topView->AddChild(box); fVisibleCheckBox = new BCheckBox(rect, "visible", "Visible", new BMessage(kMsgVisibilityChanged)); fVisibleCheckBox->SetValue(fAttribute.Visible()); fVisibleCheckBox->ResizeToPreferred(); box->SetLabel(fVisibleCheckBox); labelWidth -= 8.0f; 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); } rect.OffsetTo(8.0f, fVisibleCheckBox->Bounds().Height()); rect.right -= 18.0f; fDisplayAsMenuField = new BMenuField(rect, "display as", "Display as:", menu); fDisplayAsMenuField->SetDivider(labelWidth); fDisplayAsMenuField->SetAlignment(B_ALIGN_RIGHT); fDisplayAsMenuField->ResizeTo(rect.Width(), height); box->AddChild(fDisplayAsMenuField); fEditableCheckBox = new BCheckBox(rect, "editable", "Editable", new BMessage(kMsgAttributeUpdated), B_FOLLOW_RIGHT); fEditableCheckBox->SetValue(fAttribute.Editable()); fEditableCheckBox->ResizeToPreferred(); fEditableCheckBox->MoveTo(rect.right - fEditableCheckBox->Bounds().Width(), rect.top + (fDisplayAsMenuField->Bounds().Height() - fEditableCheckBox->Bounds().Height()) / 2.0f); box->AddChild(fEditableCheckBox); rect.OffsetBy(0.0f, menuField->Bounds().Height() + 4.0f); rect.bottom = rect.top + fPublicNameControl->Bounds().Height(); fSpecialControl = new BTextControl(rect, "special", "Special:", display_as_parameter(fAttribute.DisplayAs()), NULL, B_FOLLOW_LEFT_RIGHT); fSpecialControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); fSpecialControl->SetDivider(labelWidth); fSpecialControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fSpecialControl->SetEnabled(false); box->AddChild(fSpecialControl); char text[64]; snprintf(text, sizeof(text), "%ld", fAttribute.Width()); rect.OffsetBy(0.0f, fSpecialControl->Bounds().Height() + 4.0f); fWidthControl = new BTextControl(rect, "width", "Width:", text, NULL, B_FOLLOW_LEFT_RIGHT); fWidthControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); fWidthControl->SetDivider(labelWidth); 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); box->AddChild(fWidthControl); const struct alignment_map { int32 alignment; const char* name; } kAlignmentMap[] = { {B_ALIGN_LEFT, "Left"}, {B_ALIGN_RIGHT, "Right"}, {B_ALIGN_CENTER, "Center"}, {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); } rect.OffsetBy(0.0f, menuField->Bounds().Height() + 1.0f); fAlignmentMenuField = new BMenuField(rect, "alignment", "Alignment:", menu); fAlignmentMenuField->SetDivider(labelWidth); fAlignmentMenuField->SetAlignment(B_ALIGN_RIGHT); fAlignmentMenuField->ResizeTo(rect.Width(), height); box->AddChild(fAlignmentMenuField); box->ResizeBy(0.0f, fAlignmentMenuField->Bounds().Height() * 2.0f + fVisibleCheckBox->Bounds().Height()); fAcceptButton = new BButton(rect, "add", item ? "Done" : "Add", new BMessage(kMsgAccept), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); fAcceptButton->ResizeToPreferred(); fAcceptButton->MoveTo(Bounds().Width() - 8.0f - fAcceptButton->Bounds().Width(), Bounds().Height() - 8.0f - fAcceptButton->Bounds().Height()); fAcceptButton->SetEnabled(false); topView->AddChild(fAcceptButton); BButton* button = new BButton(rect, "cancel", "Cancel", new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); button->ResizeToPreferred(); button->MoveTo(fAcceptButton->Frame().left - 10.0f - button->Bounds().Width(), fAcceptButton->Frame().top); topView->AddChild(button); ResizeTo(labelWidth * 4.0f + 24.0f, box->Frame().bottom + button->Bounds().Height() + 20.0f); SetSizeLimits(fEditableCheckBox->Bounds().Width() + button->Bounds().Width() + fAcceptButton->Bounds().Width() + labelWidth + 24.0f, 32767.0f, Frame().Height(), Frame().Height()); fAcceptButton->MakeDefault(true); fPublicNameControl->MakeFocus(true); target->PlaceSubWindow(this); AddToSubset(target); }
status_t PTextView::SetProperty(const char *name, PValue *value, const int32 &index) { if (!name || !value) return B_ERROR; BString str(name); PProperty *prop = FindProperty(name,index); if (!prop) return B_NAME_NOT_FOUND; if (FlagsForProperty(prop) & PROPERTY_READ_ONLY) return B_READ_ONLY; BTextView *backend = (BTextView*)fView; BoolValue boolval; CharValue charval; ColorValue colorval; FloatValue floatval; IntValue intval; PointValue pointval; RectValue rectval; StringValue stringval; status_t status = prop->SetValue(value); if (status != B_OK) return status; if (backend->Window()) backend->Window()->Lock(); else if (str.ICompare("Selectable") == 0) { prop->GetValue(&boolval); backend->MakeSelectable(*boolval.value); } else if (str.ICompare("CurrentLine") == 0) { prop->GetValue(&intval); backend->GoToLine(*intval.value); } else if (str.ICompare("TabWidth") == 0) { prop->GetValue(&floatval); backend->SetTabWidth(*floatval.value); } else if (str.ICompare("TextRect") == 0) { prop->GetValue(&rectval); backend->SetTextRect(*rectval.value); } else if (str.ICompare("MaxBytes") == 0) { prop->GetValue(&intval); backend->SetMaxBytes(*intval.value); } else if (str.ICompare("UseWordWrap") == 0) { prop->GetValue(&boolval); backend->SetWordWrap(*boolval.value); } else if (str.ICompare("HideTyping") == 0) { prop->GetValue(&boolval); backend->HideTyping(*boolval.value); } else if (str.ICompare("Editable") == 0) { prop->GetValue(&boolval); backend->MakeEditable(*boolval.value); } else if (str.ICompare("ColorSpace") == 0) { prop->GetValue(&intval); backend->SetColorSpace((color_space)*intval.value); } else if (str.ICompare("Text") == 0) { prop->GetValue(&stringval); backend->SetText(*stringval.value); } else if (str.ICompare("Resizable") == 0) { prop->GetValue(&boolval); backend->MakeResizable(*boolval.value); } else if (str.ICompare("Alignment") == 0) { prop->GetValue(&intval); backend->SetAlignment((alignment)*intval.value); } else if (str.ICompare("Undoable") == 0) { prop->GetValue(&boolval); backend->SetDoesUndo(*boolval.value); } else if (str.ICompare("AutoIndent") == 0) { prop->GetValue(&boolval); backend->SetAutoindent(*boolval.value); } else if (str.ICompare("Stylable") == 0) { prop->GetValue(&boolval); backend->SetStylable(*boolval.value); } else { if (backend->Window()) backend->Window()->Unlock(); return PView::SetProperty(name, value, index); } if (backend->Window()) backend->Window()->Unlock(); return prop->GetValue(value); }
PreferencesWindow::PreferencesWindow(BRect frame) : BWindow(frame, B_TRANSLATE("Deskbar preferences"), B_TITLED_WINDOW, B_NOT_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_ZOOMABLE) { // Menu controls fMenuRecentDocuments = new BCheckBox(B_TRANSLATE("Recent documents:"), new BMessage(kUpdateRecentCounts)); fMenuRecentApplications = new BCheckBox(B_TRANSLATE("Recent applications:"), new BMessage(kUpdateRecentCounts)); fMenuRecentFolders = new BCheckBox(B_TRANSLATE("Recent folders:"), new BMessage(kUpdateRecentCounts)); fMenuRecentDocumentCount = new BTextControl(NULL, NULL, new BMessage(kUpdateRecentCounts)); fMenuRecentApplicationCount = new BTextControl(NULL, NULL, new BMessage(kUpdateRecentCounts)); fMenuRecentFolderCount = new BTextControl(NULL, NULL, new BMessage(kUpdateRecentCounts)); // Applications controls fAppsSort = new BCheckBox(B_TRANSLATE("Sort running applications"), new BMessage(kSortRunningApps)); fAppsSortTrackerFirst = new BCheckBox(B_TRANSLATE("Tracker always first"), new BMessage(kTrackerFirst)); fAppsShowExpanders = new BCheckBox(B_TRANSLATE("Show application expander"), new BMessage(kSuperExpando)); fAppsExpandNew = new BCheckBox(B_TRANSLATE("Expand new applications"), new BMessage(kExpandNewTeams)); fAppsHideLabels = new BCheckBox(B_TRANSLATE("Hide application names"), new BMessage(kHideLabels)); fAppsIconSizeSlider = new BSlider("icon_size", B_TRANSLATE("Icon size"), NULL, kMinimumIconSize / kIconSizeInterval, kMaximumIconSize / kIconSizeInterval, B_HORIZONTAL); fAppsIconSizeSlider->SetHashMarks(B_HASH_MARKS_BOTTOM); fAppsIconSizeSlider->SetHashMarkCount((kMaximumIconSize - kMinimumIconSize) / kIconSizeInterval + 1); fAppsIconSizeSlider->SetLimitLabels(B_TRANSLATE("Small"), B_TRANSLATE("Large")); fAppsIconSizeSlider->SetModificationMessage(new BMessage(kResizeTeamIcons)); // Window controls fWindowAlwaysOnTop = new BCheckBox(B_TRANSLATE("Always on top"), new BMessage(kAlwaysTop)); fWindowAutoRaise = new BCheckBox(B_TRANSLATE("Auto-raise"), new BMessage(kAutoRaise)); fWindowAutoHide = new BCheckBox(B_TRANSLATE("Auto-hide"), new BMessage(kAutoHide)); // Clock controls fShowSeconds = new BCheckBox(B_TRANSLATE("Show seconds"), new BMessage(kShowSeconds)); fShowDayOfWeek = new BCheckBox(B_TRANSLATE("Show day of week"), new BMessage(kShowDayOfWeek)); // Get settings from BarApp TBarApp* barApp = static_cast<TBarApp*>(be_app); desk_settings* settings = barApp->Settings(); // Menu settings BTextView* docTextView = fMenuRecentDocumentCount->TextView(); BTextView* appTextView = fMenuRecentApplicationCount->TextView(); BTextView* folderTextView = fMenuRecentFolderCount->TextView(); for (int32 i = 0; i < 256; i++) { if (!isdigit(i)) { docTextView->DisallowChar(i); appTextView->DisallowChar(i); folderTextView->DisallowChar(i); } } docTextView->SetMaxBytes(4); appTextView->SetMaxBytes(4); folderTextView->SetMaxBytes(4); int32 docCount = settings->recentDocsCount; int32 appCount = settings->recentAppsCount; int32 folderCount = settings->recentFoldersCount; fMenuRecentDocuments->SetValue(settings->recentDocsEnabled); fMenuRecentDocumentCount->SetEnabled(settings->recentDocsEnabled); fMenuRecentApplications->SetValue(settings->recentAppsEnabled); fMenuRecentApplicationCount->SetEnabled(settings->recentAppsEnabled); fMenuRecentFolders->SetValue(settings->recentFoldersEnabled); fMenuRecentFolderCount->SetEnabled(settings->recentFoldersEnabled); BString docString; BString appString; BString folderString; docString << docCount; appString << appCount; folderString << folderCount; fMenuRecentDocumentCount->SetText(docString.String()); fMenuRecentApplicationCount->SetText(appString.String()); fMenuRecentFolderCount->SetText(folderString.String()); // Applications settings fAppsSort->SetValue(settings->sortRunningApps); fAppsSortTrackerFirst->SetValue(settings->trackerAlwaysFirst); fAppsShowExpanders->SetValue(settings->superExpando); fAppsExpandNew->SetValue(settings->expandNewTeams); fAppsHideLabels->SetValue(settings->hideLabels); fAppsIconSizeSlider->SetValue(settings->iconSize / kIconSizeInterval); // Window settings fWindowAlwaysOnTop->SetValue(settings->alwaysOnTop); fWindowAutoRaise->SetValue(settings->autoRaise); fWindowAutoHide->SetValue(settings->autoHide); // Clock settings TReplicantTray* replicantTray = barApp->BarView()->ReplicantTray(); if (replicantTray->Time() != NULL) { fShowSeconds->SetValue(replicantTray->Time()->ShowSeconds()); fShowDayOfWeek->SetValue(replicantTray->Time()->ShowDayOfWeek()); } else { fShowSeconds->SetValue(settings->showSeconds); fShowDayOfWeek->SetValue(settings->showDayOfWeek); } EnableDisableDependentItems(); // Targets fAppsSort->SetTarget(be_app); fAppsSortTrackerFirst->SetTarget(be_app); fAppsExpandNew->SetTarget(be_app); fAppsHideLabels->SetTarget(be_app); fAppsIconSizeSlider->SetTarget(be_app); fWindowAlwaysOnTop->SetTarget(be_app); fWindowAutoRaise->SetTarget(be_app); fWindowAutoHide->SetTarget(be_app); fShowSeconds->SetTarget(replicantTray); fShowDayOfWeek->SetTarget(replicantTray); // Layout fMenuBox = new BBox("fMenuBox"); fAppsBox = new BBox("fAppsBox"); fWindowBox = new BBox("fWindowBox"); fClockBox = new BBox("fClockBox"); fMenuBox->SetLabel(B_TRANSLATE("Menu")); fAppsBox->SetLabel(B_TRANSLATE("Applications")); fWindowBox->SetLabel(B_TRANSLATE("Window")); fClockBox->SetLabel(B_TRANSLATE("Clock")); BView* view; view = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .AddGroup(B_HORIZONTAL, 0) .AddGroup(B_VERTICAL, 0) .Add(fMenuRecentDocuments) .Add(fMenuRecentFolders) .Add(fMenuRecentApplications) .End() .AddGroup(B_VERTICAL, 0) .Add(fMenuRecentDocumentCount) .Add(fMenuRecentFolderCount) .Add(fMenuRecentApplicationCount) .End() .End() .AddGroup(B_VERTICAL, 0) .SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0) .Add(new BButton(B_TRANSLATE("Edit menu" B_UTF8_ELLIPSIS), new BMessage(kEditMenuInTracker))) .End() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); fMenuBox->AddChild(view); view = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .Add(fAppsSort) .Add(fAppsSortTrackerFirst) .Add(fAppsShowExpanders) .AddGroup(B_HORIZONTAL, 0) .SetInsets(kIndentSpacing, 0, 0, 0) .Add(fAppsExpandNew) .End() .Add(fAppsHideLabels) .AddGroup(B_HORIZONTAL, 0) .SetInsets(0, B_USE_DEFAULT_SPACING, 0, 0) .Add(fAppsIconSizeSlider) .End() .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); fAppsBox->AddChild(view); view = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .Add(fWindowAlwaysOnTop) .Add(fWindowAutoRaise) .Add(fWindowAutoHide) .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); fWindowBox->AddChild(view); view = BLayoutBuilder::Group<>() .AddGroup(B_VERTICAL, 0) .Add(fShowSeconds) .Add(fShowDayOfWeek) .AddGlue() .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .View(); fClockBox->AddChild(view); BLayoutBuilder::Group<>(this) .AddGrid(5, 5) .Add(fMenuBox, 0, 0) .Add(fWindowBox, 1, 0) .Add(fAppsBox, 0, 1) .Add(fClockBox, 1, 1) .SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING) .End() .End(); CenterOnScreen(); }
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(); }
void HDialog::CreateField(int kind, BPositionIO& data, BView*& inside) { dRect r; char name[256]; char label[256]; uint32 cmd; BView *v; switch (kind) { case 'btn ': data >> r >> name >> label >> cmd; inside->AddChild(v = new BButton(r.ToBe(), name, label, new BMessage(cmd))); if (cmd == msg_OK || strcmp(name, "ok") == 0) SetDefaultButton(static_cast<BButton*>(v)); break; case 'radb': data >> r >> name >> label; inside->AddChild(new BRadioButton(r.ToBe(), name, label, new BMessage(msg_FieldChanged))); break; case 'chkb': data >> r >> name >> label; inside->AddChild(new BCheckBox(r.ToBe(), name, label, new BMessage(msg_FieldChanged))); break; case 'edit': { char val[256], allowed[256]; short max, divider; data >> r >> name >> label >> val >> allowed >> max >> divider; BRect b = r.ToBe(); inside->AddChild(v = new BTextControl(b, name, *label ? label : NULL, val, new BMessage(msg_FieldChanged), B_FOLLOW_NONE)); BTextView *tv = static_cast<BTextControl*>(v)->TextView(); if (*allowed) { for (int i = 0; i < 256; i++) if (isprint(i)) { if (strchr(allowed, i)) tv->AllowChar(i); else tv->DisallowChar(i); } } if (max) tv->SetMaxBytes(max); if (divider) static_cast<BTextControl*>(v)->SetDivider(divider * gFactor); if (v->Bounds().Height() < b.Height()) { float d = v->Bounds().Height() - tv->Bounds().Height(); v->ResizeTo(b.Width(), b.Height()); tv->ResizeTo(tv->Bounds().Width(), b.Height() - d); } break; } case 'capt': data >> r >> name >> label; inside->AddChild(v = new BStringView(r.ToBe(), name, label)); v->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); break; case 'popu': { short id, div; data >> r >> name >> label >> id >> div; inside->AddChild(v = new BMenuField(r.ToBe(), name, *label ? label : NULL, HResources::GetMenu(id, true))); if (div) static_cast<BMenuField*>(v)->SetDivider(div * gFactor); break; } case 'tabb': data >> r >> name; inside->AddChild(v = new HTabSheet(r.ToBe(), name)); inside = v; break; case 'tabe': inside = inside->Parent(); break; case 'shet': data >> name >> label; inside = dynamic_cast<HTabSheet*>(inside)->AddSheet(name, label); break; case 'shte': inside = inside->Parent(); break; case 'box ': data >> r >> name; inside->AddChild(v = new BBox(r.ToBe(), name)); if (*name) dynamic_cast<BBox*>(v)->SetLabel(name); v->SetFont(be_plain_font); inside = v; break; case 'boxe': inside = inside->Parent(); break; case 'list': case 'olst': { data >> r >> name; BRect lr = r.ToBe(); lr.right -= B_V_SCROLL_BAR_WIDTH; BListView *lv; if (kind == 'list') lv = new BListView(lr, name); else lv = new BOutlineListView(lr, name); strcat(name, "_scr"); inside->AddChild(new BScrollView(name, lv, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true)); break; } case 'clct': { data >> r >> name >> label; rgb_color c = { 255, 100, 100, 0 }; inside->AddChild(v = new HColorControl(r.ToBe(), name, label, c)); v->SetViewColor(inside->ViewColor()); break; } case 'line': { HDlogView *dv = dynamic_cast<HDlogView*>(inside); data >> r; if (dv) dv->AddMyLine(r.ToBe()); break; } case 'sldr': { int32 msg, vMin, vMax, thumb; data >> r >> name >> label >> msg >> vMin >> vMax >> thumb; inside->AddChild(new BSlider(r.ToBe(), name, label, new BMessage(msg), vMin, vMax, (thumb_style)thumb)); break; } default: { if (sFieldMap && sFieldMap->find(kind) != sFieldMap->end()) (*sFieldMap)[kind](kind, data, inside); else throw HErr("Unknown type for dialog item (%4.4s)", &kind); } } } /* HDialog::CreateField */