Author: stippi Date: 2010-04-21 22:05:31 +0200 (Wed, 21 Apr 2010) New Revision: 36405 Changeset: http://dev.haiku-os.org/changeset/36405/haiku Ticket: http://dev.haiku-os.org/ticket/5690 Modified: haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp haiku/trunk/src/preferences/filetypes/ApplicationTypesWindow.cpp haiku/trunk/src/preferences/filetypes/ApplicationTypesWindow.h haiku/trunk/src/preferences/filetypes/AttributeListView.cpp haiku/trunk/src/preferences/filetypes/AttributeListView.h haiku/trunk/src/preferences/filetypes/AttributeWindow.cpp haiku/trunk/src/preferences/filetypes/DropTargetListView.cpp haiku/trunk/src/preferences/filetypes/DropTargetListView.h haiku/trunk/src/preferences/filetypes/ExtensionWindow.cpp haiku/trunk/src/preferences/filetypes/FileTypeWindow.cpp haiku/trunk/src/preferences/filetypes/FileTypes.cpp haiku/trunk/src/preferences/filetypes/FileTypesWindow.cpp haiku/trunk/src/preferences/filetypes/FileTypesWindow.h haiku/trunk/src/preferences/filetypes/IconView.cpp haiku/trunk/src/preferences/filetypes/IconView.h haiku/trunk/src/preferences/filetypes/MimeTypeListView.cpp haiku/trunk/src/preferences/filetypes/MimeTypeListView.h haiku/trunk/src/preferences/filetypes/NewFileTypeWindow.cpp haiku/trunk/src/preferences/filetypes/PreferredAppMenu.cpp haiku/trunk/src/preferences/filetypes/PreferredAppMenu.h haiku/trunk/src/preferences/filetypes/StringView.cpp haiku/trunk/src/preferences/filetypes/StringView.h haiku/trunk/src/preferences/filetypes/TypeListWindow.cpp Log: Puh... basically this is the patch by "yourpalal" from ticket #5690, which converts the FileTypes preflet to use layout management. However, I had to revert r36252, apply the patch and then manually add r36252 back on top. I have fixed issues both in the layout management patch (broken layout in the ApplicationTypesWindow) as well as the translation (untranslated labels in alerts) and other problems with composed strings (one problem remains, but already had a TODO). However, the hard work was taken care of by yourpalal! Thanks a bunch! Modified: haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp =================================================================== --- haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp 2010-04-21 19:32:19 UTC (rev 36404) +++ haiku/trunk/src/preferences/filetypes/ApplicationTypeWindow.cpp 2010-04-21 20:05:31 UTC (rev 36405) @@ -18,8 +18,12 @@ #include <Button.h> #include <Catalog.h> #include <CheckBox.h> +#include <ControlLook.h> #include <File.h> #include <Locale.h> +#include <GridLayoutBuilder.h> +#include <GroupLayoutBuilder.h> +#include <GroupView.h> #include <ListView.h> #include <MenuBar.h> #include <MenuField.h> @@ -30,6 +34,7 @@ #include <RadioButton.h> #include <Roster.h> #include <ScrollView.h> +#include <StringView.h> #include <TextControl.h> #include <ctype.h> @@ -60,16 +65,14 @@ // TextView that filters the tab key to be able to tab-navigate while editing class TabFilteringTextView : public BTextView { public: - TabFilteringTextView(BRect frame, const char* name, BRect textRect, - uint32 resizeMask, uint32 flags = B_WILL_DRAW | B_PULSE_NEEDED); + TabFilteringTextView(const char* name); virtual ~TabFilteringTextView(); virtual void KeyDown(const char* bytes, int32 count); }; -TabFilteringTextView::TabFilteringTextView(BRect frame, const char* name, - BRect textRect, uint32 resizeMask, uint32 flags) - : BTextView(frame, name, textRect, resizeMask, flags) +TabFilteringTextView::TabFilteringTextView(const char* name) + : BTextView(name, B_WILL_DRAW | B_PULSE_NEEDED) { } @@ -108,9 +111,8 @@ class SupportedTypeListView : public DropTargetListView { public: - SupportedTypeListView(BRect frame, const char* name, + SupportedTypeListView(const char* name, list_view_type type = B_SINGLE_SELECTION_LIST, - uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE); virtual ~SupportedTypeListView(); @@ -159,11 +161,11 @@ { const SupportedTypeItem* a = *(const SupportedTypeItem**)_a; const SupportedTypeItem* b = *(const SupportedTypeItem**)_b; - + int compare = strcasecmp(a->Text(), b->Text()); if (compare != 0) return compare; - + return strcasecmp(a->Type(), b->Type()); } @@ -171,9 +173,10 @@ // #pragma mark - -SupportedTypeListView::SupportedTypeListView(BRect frame, const char* name, - list_view_type type, uint32 resizeMask, uint32 flags) - : DropTargetListView(frame, name, type, resizeMask, flags) +SupportedTypeListView::SupportedTypeListView(const char* name, + list_view_type type, uint32 flags) + : + DropTargetListView(name, type, flags) { } @@ -194,12 +197,12 @@ BNodeInfo info(&node); if (node.InitCheck() != B_OK || info.InitCheck() != B_OK) continue; - + // TODO: we could identify the file in case it doesn't have a type... char type[B_MIME_TYPE_LENGTH]; if (info.GetType(type) != B_OK) continue; - + // check if that type is already in our list bool found = false; for (int32 i = CountItems(); i-- > 0;) { @@ -209,13 +212,13 @@ break; } } - + if (!found) { // add type AddItem(new SupportedTypeItem(type)); } } - + SortItems(&SupportedTypeItem::Compare); } else DropTargetListView::MessageReceived(message); @@ -233,17 +236,26 @@ // #pragma mark - -ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entry) - : BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), - TR("Application Type"), B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), +ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, + const BEntry& entry) + : + BWindow(BRect(0.0f, 0.0f, 250.0f, 340.0f).OffsetBySelf(position), + TR("Application type"), B_TITLED_WINDOW, + B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | + B_FRAME_EVENTS | B_AUTO_UPDATE_SIZE_LIMITS), fChangedProperties(0) { - // add the menu - - BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); - AddChild(menuBar); - + float padding = 3.0f; + BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); + if (be_control_look){ + // padding = be_control_look->DefaultItemSpacing(); + // seems too big + labelAlignment = be_control_look->DefaultLabelAlignment(); + } + + BMenuBar* menuBar = new BMenuBar((char*)NULL); + menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); + BMenu* menu = new BMenu(TR("File")); fSaveMenuItem = new BMenuItem(TR("Save"), new BMessage(kMsgSave), 'S'); fSaveMenuItem->SetEnabled(false); @@ -252,32 +264,20 @@ menu->AddItem(item = new BMenuItem( TR("Save into resource file" B_UTF8_ELLIPSIS), NULL)); item->SetEnabled(false); - + menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(TR("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", TR("Signature:"), NULL, - new BMessage(kMsgSignatureChanged), B_FOLLOW_LEFT_RIGHT); - fSignatureControl->SetModificationMessage( + // Signature + + fSignatureControl = new BTextControl(TR("Signature:"), NULL, 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); - + 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); @@ -285,278 +285,162 @@ for (int32 i = 0; disallowedCharacters[i]; i++) { textView->DisallowChar(disallowedCharacters[i]); } - + // "Application Flags" group + + BBox* flagsBox = new BBox("flagsBox"); - 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", TR("Application flags"), + fFlagsCheckBox = new BCheckBox("flags", TR("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", TR("Single launch"), + + fSingleLaunchButton = new BRadioButton("single", TR("Single launch"), new BMessage(kMsgAppFlagsChanged)); - fSingleLaunchButton->ResizeToPreferred(); - box->AddChild(fSingleLaunchButton); - - rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f); - fMultipleLaunchButton = new BRadioButton(rect, "multiple", + + fMultipleLaunchButton = new BRadioButton("multiple", TR("Multiple launch"), new BMessage(kMsgAppFlagsChanged)); - fMultipleLaunchButton->ResizeToPreferred(); - box->AddChild(fMultipleLaunchButton); - - rect.OffsetBy(0.0f, fSingleLaunchButton->Bounds().Height() + 0.0f); - fExclusiveLaunchButton = new BRadioButton(rect, "exclusive", + + fExclusiveLaunchButton = new BRadioButton("exclusive", TR("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", TR("Args only"), + + fArgsOnlyCheckBox = new BCheckBox("args only", TR("Args only"), new BMessage(kMsgAppFlagsChanged)); - fArgsOnlyCheckBox->ResizeToPreferred(); - box->AddChild(fArgsOnlyCheckBox); - - rect.top += fArgsOnlyCheckBox->Bounds().Height(); - fBackgroundAppCheckBox = new BCheckBox(rect, "background", + + fBackgroundAppCheckBox = new BCheckBox("background", TR("Background app"), new BMessage(kMsgAppFlagsChanged)); - fBackgroundAppCheckBox->ResizeToPreferred(); - box->AddChild(fBackgroundAppCheckBox); - - box->ResizeTo(box->Bounds().Width(), - fExclusiveLaunchButton->Frame().bottom + 8.0f); - + + flagsBox->AddChild(BGridLayoutBuilder(padding, padding) + .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 - - rect = box->Frame(); -#ifdef __HAIKU__ - 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 __HAIKU__ - 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 __HAIKU__ - 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"); + + BBox* iconBox = new BBox("IconBox"); + iconBox->SetLabel(TR("Icon")); + fIconView = new IconView("icon"); fIconView->SetModificationMessage(new BMessage(kMsgIconChanged)); - box->AddChild(fIconView); - + iconBox->AddChild( + BGroupLayoutBuilder(B_HORIZONTAL) + .Add(fIconView) + .SetInsets(padding, padding, padding, padding) + ); + // "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); + + BBox* typeBox = new BBox("typesBox"); typeBox->SetLabel(TR("Supported types")); - topView->AddChild(typeBox); - - rect = typeBox->Bounds().InsetByCopy(8.0f, 6.0f); - rect.top += ceilf(fontHeight.ascent); - fAddTypeButton = new BButton(rect, "add type", TR("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", TR("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 = new SupportedTypeListView("Suppported Types", + B_SINGLE_SELECTION_LIST); 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 __HAIKU__ - 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); + B_FRAME_EVENTS | B_WILL_DRAW, false, true); + + fAddTypeButton = new BButton("add type", TR("Add" B_UTF8_ELLIPSIS), + new BMessage(kMsgAddType)); + + fRemoveTypeButton = new BButton("remove type", TR("Remove"), + new BMessage(kMsgRemoveType)); + + fTypeIconView = new IconView("type icon"); + BView* iconHolder = BGroupLayoutBuilder(B_HORIZONTAL).Add(fTypeIconView); fTypeIconView->SetModificationMessage(new BMessage(kMsgTypeIconsChanged)); - typeBox->AddChild(fTypeIconView); - + + 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 - - 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(TR("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", TR("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); + + BBox* versionBox = new BBox("versionBox"); + versionBox->SetLabel(TR("Version info")); + + fMajorVersionControl = new BTextControl(TR("Version:"), NULL, NULL); _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); + + fMiddleVersionControl = new BTextControl(".", NULL, NULL); _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); + + fMinorVersionControl = new BTextControl(".", NULL, NULL); _MakeNumberTextControl(fMinorVersionControl); - box->AddChild(fMinorVersionControl); - + fVarietyMenu = new BPopUpMenu("variety", true, true); fVarietyMenu->AddItem(new BMenuItem(TR("Development"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Alpha"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Beta"), NULL)); fVarietyMenu->AddItem(new BMenuItem(TR("Gamma"), NULL)); - fVarietyMenu->AddItem(item = new BMenuItem(TR("Golden master"), NULL)); + item = new BMenuItem(TR("Golden master"), NULL); + fVarietyMenu->AddItem(item); item->SetMarked(true); fVarietyMenu->AddItem(new BMenuItem(TR("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", TR("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); - + + BMenuField* varietyField = new BMenuField("", fVarietyMenu); + fInternalVersionControl = new BTextControl("/", NULL, NULL); + fShortDescriptionControl = + new BTextControl(TR("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)); - box->AddChild(fShortDescriptionControl); - - rect.OffsetBy(0.0f, fShortDescriptionControl->Bounds().Height() + 5.0f); - rect.right = rect.left + labelWidth; - StringView* label = new StringView(rect, NULL, TR("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); + fShortDescriptionControl->TextView()->SetMaxBytes( + sizeof(versionInfo.short_info)); + + BStringView* longLabel = new BStringView(NULL, TR("Long description:")); + longLabel->SetExplicitAlignment(labelAlignment); + fLongDescriptionView = new TabFilteringTextView("long desc"); 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); + B_FRAME_EVENTS | B_WILL_DRAW, false, true); - // Adjust window size and limits + // TODO: remove workaround (bug #5678) + BSize minScrollSize = scrollView->ScrollBar(B_VERTICAL)->MinSize(); + minScrollSize.width+=fLongDescriptionView->MinSize().width; + scrollView->SetExplicitMinSize(minScrollSize); + + versionBox->AddChild(BGridLayoutBuilder(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) + .SetInsets(padding, padding, padding, padding) + .SetRowWeight(3, 3) + ); - width = fInternalVersionControl->Frame().right + 16.0f; - float minWidth = fBackgroundAppCheckBox->Frame().right + iconBoxWidth + 32.0f; - if (width > minWidth) - minWidth = width; + // 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) + ); - 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); + SetKeyMenuBar(menuBar); fSignatureControl->MakeFocus(true); - BMimeType::StartWatching(this); _SetTo(entry); } @@ -982,7 +866,8 @@ { int32 index; if (message->FindInt32("index", &index) == B_OK) { - SupportedTypeItem* item = (SupportedTypeItem*)fTypeListView->ItemAt(index); + SupportedTypeItem* item + = (SupportedTypeItem*)fTypeListView->ItemAt(index); fTypeIconView->SetModificationMessage(NULL); fTypeIconView->SetTo(item != NULL ? &item->Icon() : NULL); Modified: haiku/trunk/src/preferences/filetypes/ApplicationTypesWindow.cpp =================================================================== --- haiku/trunk/src/preferences/filetypes/ApplicationTypesWindow.cpp 2010-04-21 19:32:19 UTC (rev 36404) +++ haiku/trunk/src/preferences/filetypes/ApplicationTypesWindow.cpp 2010-04-21 20:05:31 UTC (rev 36405) @@ -18,6 +18,9 @@ #include <Button.h> #include <Catalog.h> #include <Locale.h> +#include <ControlLook.h> +#include <GridLayoutBuilder.h> +#include <GroupLayoutBuilder.h> #include <MenuField.h> #include <MenuItem.h> #include <Mime.h> @@ -60,7 +63,7 @@ const uint32 kMsgEdit = 'edit'; -const char* +const char* variety_to_text(uint32 variety) { #if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE) @@ -94,42 +97,34 @@ // #pragma mark - -ProgressWindow::ProgressWindow(const char* message, int32 max, volatile bool* signalQuit) - : BWindow(BRect(0, 0, 300, 200), TR("Progress"), B_MODAL_WINDOW_LOOK, - B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_NOT_V_RESIZABLE), +ProgressWindow::ProgressWindow(const char* message, + int32 max, volatile bool* signalQuit) + : + BWindow(BRect(0, 0, 300, 200), TR("Progress"), B_MODAL_WINDOW_LOOK, + B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | + B_NOT_V_RESIZABLE | B_AUTO_UPDATE_SIZE_LIMITS), fQuitListener(signalQuit) { - BView* topView = new BView(Bounds(), NULL, B_FOLLOW_ALL, B_WILL_DRAW); - topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(topView); - char count[100]; snprintf(count, sizeof(count), "/%ld", max); - BRect rect = Bounds().InsetByCopy(8, 8); - fStatusBar = new BStatusBar(rect, "status", message, count); + fStatusBar = new BStatusBar("status", message, count); fStatusBar->SetMaxValue(max); - fStatusBar->SetResizingMode(B_FOLLOW_LEFT_RIGHT); - float width, height; - fStatusBar->GetPreferredSize(&width, &height); - fStatusBar->ResizeTo(rect.Width(), height); - topView->AddChild(fStatusBar); + fAbortButton = new BButton("abort", TR("Abort"), new BMessage(B_CANCEL)); + + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGroupLayoutBuilder(B_VERTICAL, 3.0f) + .Add(fStatusBar) + .Add(fAbortButton) + .SetInsets(3.0f, 3.0f, 3.0f, 3.0f) + ); - fAbortButton = new BButton(rect, "abort", TR("Abort"), new BMessage(B_CANCEL), - B_FOLLOW_H_CENTER | B_FOLLOW_TOP); - fAbortButton->ResizeToPreferred(); - fAbortButton->MoveTo((Bounds().Width() - fAbortButton->Bounds().Width()) / 2, - fStatusBar->Frame().bottom + 10.0f); - topView->AddChild(fAbortButton); - - ResizeTo(width * 1.4f, fAbortButton->Frame().bottom + 8.0f); - SetSizeLimits(width + 42.0f, 32767.0f, - Bounds().Height(), Bounds().Height()); - // center on screen BScreen screen(this); - MoveTo(screen.Frame().left + (screen.Frame().Width() - Bounds().Width()) / 2.0f, - screen.Frame().top + (screen.Frame().Height() - Bounds().Height()) / 2.0f); + MoveTo(screen.Frame().left + (screen.Frame().Width() + - Bounds().Width()) / 2.0f, + screen.Frame().top + (screen.Frame().Height() + - Bounds().Height()) / 2.0f); } @@ -165,139 +160,116 @@ // #pragma mark - -ApplicationTypesWindow::ApplicationTypesWindow(const BMessage &settings) +ApplicationTypesWindow::ApplicationTypesWindow(const BMessage& settings) : BWindow(_Frame(settings), TR("Application types"), B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) + B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { - // Application list - 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); + float padding = 3.0f; + BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); + BAlignment fullWidthTopAlignment = + BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_TOP); + if (be_control_look) { + // padding = be_control_look->DefaultItemSpacing(); + // seems too big + labelAlignment = be_control_look->DefaultLabelAlignment(); + } - BButton* button = new BButton(rect, "remove", TR("Remove uninstalled"), - new BMessage(kMsgRemoveUninstalled), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->MoveTo(8.0f, rect.bottom - 8.0f - button->Bounds().Height()); - topView->AddChild(button); + // Application list + BView* currentView = new BGroupView(B_VERTICAL, padding); - rect.bottom = button->Frame().top - 10.0f; - rect.top = 10.0f; - rect.left = 10.0f; - rect.right = 170; - - fTypeListView = new MimeTypeListView(rect, "listview", "application", true, true, - B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); + fTypeListView = new MimeTypeListView("listview", "application", true, true); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fTypeListView->SetInvocationMessage(new BMessage(kMsgTypeInvoked)); BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, - B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - topView->AddChild(scrollView); + B_FRAME_EVENTS | B_WILL_DRAW, false, true); - // "Information" group + BButton* button = new BButton("remove", TR("Remove uninstalled"), + new BMessage(kMsgRemoveUninstalled)); - BFont font(be_bold_font); - font_height fontHeight; - font.GetHeight(&fontHeight); + SetLayout(BGroupLayoutBuilder(B_HORIZONTAL)); - rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; - rect.top -= 2.0f; - rect.right = topView->Bounds().Width() - 8.0f; - rect.bottom = rect.top + ceilf(fontHeight.ascent) + 24.0f; - BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); - box->SetLabel(TR("Information")); - topView->AddChild(box); + // "Information" group - BRect innerRect = box->Bounds().InsetByCopy(8.0f, 6.0f); - float labelWidth = topView->StringWidth(TR("Description:")) + 4.0f; + BBox* infoBox = new BBox((char*)NULL); + infoBox->SetLabel(TR("Information")); + infoBox->SetExplicitAlignment(fullWidthTopAlignment); + + fNameView = new StringView(TR("Name:"), NULL); + fNameView->TextView()->SetExplicitAlignment(labelAlignment); + fNameView->LabelView()->SetExplicitAlignment(labelAlignment); + fSignatureView = new StringView(TR("Signature:"), NULL); + fSignatureView->TextView()->SetExplicitAlignment(labelAlignment); + fSignatureView->LabelView()->SetExplicitAlignment(labelAlignment); + fPathView = new StringView(TR("Path:"), NULL); + fPathView->TextView()->SetExplicitAlignment(labelAlignment); + fPathView->LabelView()->SetExplicitAlignment(labelAlignment); - innerRect.right = box->Bounds().Width() - 8.0f; - innerRect.top += ceilf(fontHeight.ascent); - fNameView = new StringView(innerRect, "name", TR("Name:"), NULL, B_FOLLOW_LEFT_RIGHT); - fNameView->SetDivider(labelWidth); - float width, height; - fNameView->GetPreferredSize(&width, &height); - fNameView->ResizeTo(innerRect.Width(), height); - box->ResizeBy(0, fNameView->Bounds().Height() * 3.0f); - box->AddChild(fNameView); + infoBox->AddChild( + BGridLayoutBuilder(padding, padding) + .Add(fNameView->LabelView(), 0, 0) + .Add(fNameView->TextView(), 1, 0, 2) + .Add(fSignatureView->LabelView(), 0, 1) + .Add(fSignatureView->TextView(), 1, 1, 2) + .Add(fPathView->LabelView(), 0, 2) + .Add(fPathView->TextView(), 1, 2, 2) + .SetInsets(padding, padding, padding, padding) + ); - innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f); - innerRect.bottom = innerRect.top + height; - fSignatureView = new StringView(innerRect, "signature", TR("Signature:"), NULL, - B_FOLLOW_LEFT_RIGHT); - fSignatureView->SetDivider(labelWidth); - box->AddChild(fSignatureView); - - innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f); - fPathView = new StringView(innerRect, "path", TR("Path:"), NULL, - B_FOLLOW_LEFT_RIGHT); - fPathView->SetDivider(labelWidth); - box->AddChild(fPathView); - // "Version" group - rect.top = box->Frame().bottom + 8.0f; - rect.bottom = rect.top + ceilf(fontHeight.ascent) - + fNameView->Bounds().Height() * 4.0f + 20.0f; - box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); - box->SetLabel(TR("Version")); - topView->AddChild(box); + BBox* versionBox = new BBox(""); + versionBox->SetLabel(TR("Version")); + versionBox->SetExplicitAlignment(fullWidthTopAlignment); - innerRect = fNameView->Frame(); - fVersionView = new StringView(innerRect, "version", TR("Version:"), NULL, - B_FOLLOW_LEFT_RIGHT); - fVersionView->SetDivider(labelWidth); - box->AddChild(fVersionView); - - innerRect.OffsetBy(0, fNameView->Bounds().Height() + 5.0f); - innerRect.right = innerRect.left + labelWidth; - fDescriptionLabel = new StringView(innerRect, "description", TR("Description:"), NULL); - fDescriptionLabel->SetDivider(labelWidth); - box->AddChild(fDescriptionLabel); - - innerRect.left = innerRect.right + 3.0f; - innerRect.top += 1.0f; - innerRect.right = box->Bounds().Width() - 8.0f; - innerRect.bottom += fNameView->Bounds().Height() * 2.0f - 1.0f; - fDescriptionView = new BTextView(innerRect, "description", - innerRect.OffsetToCopy(B_ORIGIN), B_FOLLOW_LEFT_RIGHT, - B_WILL_DRAW | B_FRAME_EVENTS); + fVersionView = new StringView(TR("Version:"), NULL); + fVersionView->TextView()->SetExplicitAlignment(labelAlignment); + fVersionView->LabelView()->SetExplicitAlignment(labelAlignment); + fDescriptionLabel = new StringView(TR("Description:"), NULL); + fDescriptionLabel->LabelView()->SetExplicitAlignment(labelAlignment); + fDescriptionView = new BTextView("description"); fDescriptionView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); fDescriptionView->SetLowColor(fDescriptionView->ViewColor()); fDescriptionView->MakeEditable(false); - box->AddChild(fDescriptionView); + + versionBox->AddChild(currentView = + BGridLayoutBuilder(padding, padding) + .Add(fVersionView->LabelView(), 0, 0) + .Add(fVersionView->TextView(), 1, 0) + .Add(fDescriptionLabel->LabelView(), 0, 1) + .Add(fDescriptionView, 1, 1, 2, 2) + .SetInsets(padding, padding, padding, padding) + ); + currentView->SetExplicitAlignment(fullWidthTopAlignment); // Launch and Tracker buttons - rect = box->Frame(); - rect.top = rect.bottom + 8.0f; - rect.bottom = rect.top + 20.0f; - fTrackerButton = new BButton(rect, "tracker", TR("Show in Tracker" B_UTF8_ELLIPSIS), NULL, - B_FOLLOW_RIGHT); - fTrackerButton->ResizeToPreferred(); - fTrackerButton->MoveTo(rect.right - fTrackerButton->Bounds().Width(), rect.top); - topView->AddChild(fTrackerButton); + fEditButton = new BButton(TR("Edit" B_UTF8_ELLIPSIS), new BMessage(kMsgEdit)); + // launch and tracker buttons get messages in _SetType() + fLaunchButton = new BButton(TR("Launch")); + fTrackerButton = new BButton(TR("Show in Tracker" B_UTF8_ELLIPSIS)); - fLaunchButton = new BButton(rect, "launch", TR("Launch"), NULL, - B_FOLLOW_RIGHT); - fLaunchButton->ResizeToPreferred(); - fLaunchButton->MoveTo(fTrackerButton->Frame().left - 6.0f - - fLaunchButton->Bounds().Width(), rect.top); - topView->AddChild(fLaunchButton); - - fEditButton = new BButton(rect, "edit", TR("Edit" B_UTF8_ELLIPSIS), new BMessage(kMsgEdit), - B_FOLLOW_RIGHT); - fEditButton->ResizeToPreferred(); - fEditButton->MoveTo(fLaunchButton->Frame().left - 6.0f - - fEditButton->Bounds().Width(), rect.top); - topView->AddChild(fEditButton); + AddChild(BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(BGroupLayoutBuilder(B_VERTICAL, padding) + .Add(scrollView) + .Add(button) + .SetInsets(padding, padding, padding, padding) + , 3) + .Add(BGroupLayoutBuilder(B_VERTICAL, padding) + .Add(infoBox) + .Add(versionBox) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(fEditButton) + .Add(fLaunchButton) + .Add(fTrackerButton) + ) + .AddGlue() + .SetInsets(padding, padding, padding, padding) + ) + .SetInsets(padding, padding, padding, padding) + ); - SetSizeLimits(scrollView->Frame().right + 22.0f + fTrackerButton->Frame().Width() - + fLaunchButton->Frame().Width() + 6 + fEditButton->Frame().Width(), 32767.0f, - fTrackerButton->Frame().bottom + 8.0f, 32767.0f); - BMimeType::StartWatching(this); _SetType(NULL); } @@ -328,13 +300,15 @@ int32 removed = 0; volatile bool quit = false; - BWindow* progressWindow = new ProgressWindow(TR("Removing uninstalled application types"), - fTypeListView->FullListCountItems(), &quit); + BWindow* progressWindow = + new ProgressWindow(TR("Removing uninstalled application types"), + fTypeListView->FullListCountItems(), &quit); progressWindow->AddToSubset(this); progressWindow->Show(); for (int32 i = fTypeListView->FullListCountItems(); i-- > 0 && !quit;) { - MimeTypeItem* item = dynamic_cast<MimeTypeItem*>(fTypeListView->FullListItemAt(i)); + MimeTypeItem* item = dynamic_cast<MimeTypeItem*> + (fTypeListView->FullListItemAt(i)); progressWindow->PostMessage(B_UPDATE_STATUS_BAR); if (item == NULL) @@ -381,9 +355,9 @@ progressWindow->PostMessage(B_QUIT_REQUESTED); char message[512]; - // TODO : use ICU to properly format this - snprintf(message, sizeof(message), TR("%ld Application type%s could be removed."), - removed, removed == 1 ? "" : "s"); + // TODO: Use ICU to properly format this. + snprintf(message, sizeof(message), TR("%ld Application type%s could be " + "removed."), removed, removed == 1 ? "" : "s"); error_alert(message, B_OK, B_INFO_ALERT); } @@ -456,11 +430,14 @@ BAppFileInfo appInfo(&file); version_info versionInfo; if (appInfo.InitCheck() == B_OK - && appInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK) { + && appInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) + == B_OK) { char version[256]; snprintf(version, sizeof(version), "%lu.%lu.%lu, %s/%lu", - versionInfo.major, versionInfo.middle, versionInfo.minor, - variety_to_text(versionInfo.variety), versionInfo.internal); + versionInfo.major, versionInfo.middle, + versionInfo.minor, + variety_to_text(versionInfo.variety), + versionInfo.internal); fVersionView->SetText(version); fDescriptionView->SetText(versionInfo.long_info); } else { @@ -481,7 +458,7 @@ fNameView->SetEnabled(enabled); fSignatureView->SetEnabled(enabled); fPathView->SetEnabled(enabled); - + fVersionView->SetEnabled(enabled); fDescriptionLabel->SetEnabled(enabled); @@ -492,14 +469,6 @@ void -ApplicationTypesWindow::FrameResized(float width, float height) -{ - // This works around a flaw of BTextView - fDescriptionView->SetTextRect(fDescriptionView->Bounds()); -} - - -void ApplicationTypesWindow::MessageReceived(BMessage* message) { switch (message->what) { @@ -537,10 +506,8 @@ } case kMsgEdit: - { fTypeListView->Invoke(); break; - } case kMsgRemoveUninstalled: _RemoveUninstalled(); @@ -551,8 +518,9 @@ const char* type; int32 which; if (message->FindString("be:type", &type) != B_OK [... truncated: 2959 lines follow ...]