From 50a2f6d7b20e0c0b24b47f85622e445bf84e81a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Wed, 21 Apr 2010 20:05:31 +0000 Subject: [PATCH] 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! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36405 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../filetypes/ApplicationTypeWindow.cpp | 449 +++++++---------- .../filetypes/ApplicationTypesWindow.cpp | 284 +++++------ .../filetypes/ApplicationTypesWindow.h | 1 - .../filetypes/AttributeListView.cpp | 9 +- src/preferences/filetypes/AttributeListView.h | 4 +- src/preferences/filetypes/AttributeWindow.cpp | 182 +++---- .../filetypes/DropTargetListView.cpp | 6 +- .../filetypes/DropTargetListView.h | 3 +- src/preferences/filetypes/ExtensionWindow.cpp | 61 +-- src/preferences/filetypes/FileTypeWindow.cpp | 176 +++---- src/preferences/filetypes/FileTypes.cpp | 37 +- src/preferences/filetypes/FileTypesWindow.cpp | 471 ++++++++---------- src/preferences/filetypes/FileTypesWindow.h | 2 +- src/preferences/filetypes/IconView.cpp | 111 ++--- src/preferences/filetypes/IconView.h | 18 +- .../filetypes/MimeTypeListView.cpp | 38 +- src/preferences/filetypes/MimeTypeListView.h | 5 +- .../filetypes/NewFileTypeWindow.cpp | 101 ++-- .../filetypes/PreferredAppMenu.cpp | 27 +- src/preferences/filetypes/PreferredAppMenu.h | 5 +- src/preferences/filetypes/StringView.cpp | 274 +++------- src/preferences/filetypes/StringView.h | 51 +- src/preferences/filetypes/TypeListWindow.cpp | 64 +-- 23 files changed, 976 insertions(+), 1403 deletions(-) diff --git a/src/preferences/filetypes/ApplicationTypeWindow.cpp b/src/preferences/filetypes/ApplicationTypeWindow.cpp index de0dcdb010..1ca444b89b 100644 --- a/src/preferences/filetypes/ApplicationTypeWindow.cpp +++ b/src/preferences/filetypes/ApplicationTypeWindow.cpp @@ -18,8 +18,12 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include #include @@ -30,6 +34,7 @@ #include #include #include +#include #include #include @@ -60,16 +65,14 @@ const uint32 kMsgTypeRemoved = 'tprm'; // 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 SupportedTypeItem : public BStringItem { 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 @@ SupportedTypeItem::Compare(const void* _a, const void* _b) { 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 @@ SupportedTypeItem::Compare(const void* _a, const void* _b) // #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 @@ SupportedTypeListView::MessageReceived(BMessage* message) 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 @@ SupportedTypeListView::MessageReceived(BMessage* message) break; } } - + if (!found) { // add type AddItem(new SupportedTypeItem(type)); } } - + SortItems(&SupportedTypeItem::Compare); } else DropTargetListView::MessageReceived(message); @@ -233,17 +236,26 @@ SupportedTypeListView::AcceptsDrag(const BMessage* message) // #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 @@ ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entr 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 @@ ApplicationTypeWindow::ApplicationTypeWindow(BPoint position, const BEntry& entr 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 @@ ApplicationTypeWindow::MessageReceived(BMessage* message) { 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); diff --git a/src/preferences/filetypes/ApplicationTypesWindow.cpp b/src/preferences/filetypes/ApplicationTypesWindow.cpp index df017aead6..ba2432bed1 100644 --- a/src/preferences/filetypes/ApplicationTypesWindow.cpp +++ b/src/preferences/filetypes/ApplicationTypesWindow.cpp @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -60,7 +63,7 @@ const uint32 kMsgRemoveUninstalled = 'runs'; 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 @@ variety_to_text(uint32 variety) // #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(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()); + 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) + ); // 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,138 +160,115 @@ ProgressWindow::MessageReceived(BMessage* message) // #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) { + + 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(); + } + // Application list + BView* currentView = new BGroupView(B_VERTICAL, padding); - 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); - - 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); - - 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); + + BButton* button = new BButton("remove", TR("Remove uninstalled"), + new BMessage(kMsgRemoveUninstalled)); + + SetLayout(BGroupLayoutBuilder(B_HORIZONTAL)); // "Information" group - BFont font(be_bold_font); - font_height fontHeight; - font.GetHeight(&fontHeight); + 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); - 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); - - BRect innerRect = box->Bounds().InsetByCopy(8.0f, 6.0f); - float labelWidth = topView->StringWidth(TR("Description:")) + 4.0f; - - 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); - - 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); + 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) + ); // "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); - - 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); + 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) + ); BMimeType::StartWatching(this); _SetType(NULL); @@ -328,13 +300,15 @@ ApplicationTypesWindow::_RemoveUninstalled() 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(fTypeListView->FullListItemAt(i)); + MimeTypeItem* item = dynamic_cast + (fTypeListView->FullListItemAt(i)); progressWindow->PostMessage(B_UPDATE_STATUS_BAR); if (item == NULL) @@ -381,9 +355,9 @@ ApplicationTypesWindow::_RemoveUninstalled() 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 @@ ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate) 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 @@ ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate) fNameView->SetEnabled(enabled); fSignatureView->SetEnabled(enabled); fPathView->SetEnabled(enabled); - + fVersionView->SetEnabled(enabled); fDescriptionLabel->SetEnabled(enabled); @@ -491,14 +468,6 @@ ApplicationTypesWindow::_SetType(BMimeType* type, int32 forceUpdate) } -void -ApplicationTypesWindow::FrameResized(float width, float height) -{ - // This works around a flaw of BTextView - fDescriptionView->SetTextRect(fDescriptionView->Bounds()); -} - - void ApplicationTypesWindow::MessageReceived(BMessage* message) { @@ -537,10 +506,8 @@ ApplicationTypesWindow::MessageReceived(BMessage* message) } case kMsgEdit: - { fTypeListView->Invoke(); break; - } case kMsgRemoveUninstalled: _RemoveUninstalled(); @@ -551,8 +518,9 @@ ApplicationTypesWindow::MessageReceived(BMessage* message) const char* type; int32 which; if (message->FindString("be:type", &type) != B_OK - || message->FindInt32("be:which", &which) != B_OK) + || message->FindInt32("be:which", &which) != B_OK) { break; + } if (fCurrentType.Type() == NULL) break; diff --git a/src/preferences/filetypes/ApplicationTypesWindow.h b/src/preferences/filetypes/ApplicationTypesWindow.h index f8f0061225..99ca2db9d6 100644 --- a/src/preferences/filetypes/ApplicationTypesWindow.h +++ b/src/preferences/filetypes/ApplicationTypesWindow.h @@ -27,7 +27,6 @@ class ApplicationTypesWindow : public BWindow { ApplicationTypesWindow(const BMessage& settings); virtual ~ApplicationTypesWindow(); - virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage* message); virtual bool QuitRequested(); diff --git a/src/preferences/filetypes/AttributeListView.cpp b/src/preferences/filetypes/AttributeListView.cpp index 13f59189e4..b961d20076 100644 --- a/src/preferences/filetypes/AttributeListView.cpp +++ b/src/preferences/filetypes/AttributeListView.cpp @@ -71,7 +71,7 @@ name_for_type(BString& string, type_code type, const char* displayAs) buffer[4] = 0xff & (type); buffer[5] = '\''; buffer[6] = 0; - for (int16 i = 0;i < 4;i++) { + for (int16 i = 0; i < 4; i++) { if (buffer[i] < ' ') buffer[i] = '.'; } @@ -81,7 +81,7 @@ name_for_type(BString& string, type_code type, const char* displayAs) } -AttributeItem * +AttributeItem* create_attribute_item(BMessage& attributes, int32 index) { const char* publicName; @@ -235,9 +235,8 @@ AttributeItem::operator!=(const AttributeItem& other) const // #pragma mark - -AttributeListView::AttributeListView(BRect frame, const char* name, - uint32 resizingMode) - : BListView(frame, name, B_SINGLE_SELECTION_LIST, resizingMode, +AttributeListView::AttributeListView(const char* name) + : BListView(name, B_SINGLE_SELECTION_LIST, B_WILL_DRAW | B_NAVIGABLE | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS) { } diff --git a/src/preferences/filetypes/AttributeListView.h b/src/preferences/filetypes/AttributeListView.h index 3ee9323f85..39d885cb1a 100644 --- a/src/preferences/filetypes/AttributeListView.h +++ b/src/preferences/filetypes/AttributeListView.h @@ -50,7 +50,7 @@ class AttributeItem : public BStringItem { class AttributeListView : public BListView { public: - AttributeListView(BRect frame, const char* name, uint32 resizingMode); + AttributeListView(const char* name); virtual ~AttributeListView(); void SetTo(BMimeType* type); @@ -76,6 +76,6 @@ struct display_as_map { extern const struct display_as_map kDisplayAsMap[]; -AttributeItem *create_attribute_item(BMessage& attributes, int32 index); +AttributeItem* create_attribute_item(BMessage& attributes, int32 index); #endif // ATTRIBUTE_LIST_VIEW_H diff --git a/src/preferences/filetypes/AttributeWindow.cpp b/src/preferences/filetypes/AttributeWindow.cpp index 2729c33752..93f9784926 100644 --- a/src/preferences/filetypes/AttributeWindow.cpp +++ b/src/preferences/filetypes/AttributeWindow.cpp @@ -13,10 +13,14 @@ #include #include #include +#include +#include +#include #include #include #include #include +#include #include #include @@ -91,40 +95,30 @@ display_as_parameter(const char* special) AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, AttributeItem* attributeItem) - : BWindow(BRect(100, 100, 350, 200), TR("Attribute"), B_MODAL_WINDOW_LOOK, - B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE + : + BWindow(BRect(100, 100, 350, 200), TR("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 = 3.0f; + //if (be_control_look) + //padding = be_control_look->DefaultItemSpacing(); + 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", TR("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 = new BTextControl(TR("Attribute name:"), + fAttribute.PublicName(), NULL); + fPublicNameControl->SetModificationMessage( + new BMessage(kMsgAttributeUpdated)); 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", TR("Internal name:"), - fAttribute.Name(), NULL, B_FOLLOW_LEFT_RIGHT); - fAttributeControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); - fAttributeControl->SetDivider(labelWidth); + fAttributeControl = new BTextControl(TR("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 @@ -134,8 +128,6 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, textView->DisallowChar(disallowedCharacters[i]); } - topView->AddChild(fAttributeControl); - fTypeMenu = new BPopUpMenu("type"); BMenuItem* item = NULL; for (int32 i = 0; kTypeMap[i].name != NULL; i++) { @@ -149,27 +141,13 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, item->SetMarked(true); } - rect.OffsetBy(0.0f, rect.Height() + 4.0f); - BMenuField* menuField = new BMenuField(rect, "types", - TR("Type:"), fTypeMenu); - menuField->SetDivider(labelWidth); - menuField->SetAlignment(B_ALIGN_RIGHT); - menuField->GetPreferredSize(&width, &height); - menuField->ResizeTo(rect.Width(), height); - topView->AddChild(menuField); + BMenuField* typeMenuField = new BMenuField("types" , TR("Type:"), + fTypeMenu); + typeMenuField->SetAlignment(B_ALIGN_RIGHT); - 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", TR("Visible"), + fVisibleCheckBox = new BCheckBox("visible", TR("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++) { @@ -188,42 +166,29 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, item->SetMarked(true); } - rect.OffsetTo(8.0f, fVisibleCheckBox->Bounds().Height()); - rect.right -= 18.0f; - fDisplayAsMenuField = new BMenuField(rect, "display as", - TR("Display as:"), menu); - fDisplayAsMenuField->SetDivider(labelWidth); + fDisplayAsMenuField = new BMenuField("display as", + TR_CMT("Display as:", "Tracker offers different display modes for " + "attributes."), menu); fDisplayAsMenuField->SetAlignment(B_ALIGN_RIGHT); - fDisplayAsMenuField->ResizeTo(rect.Width(), height); - box->AddChild(fDisplayAsMenuField); - fEditableCheckBox = new BCheckBox(rect, "editable", TR("Editable"), - new BMessage(kMsgAttributeUpdated), B_FOLLOW_RIGHT); + fEditableCheckBox = new BCheckBox("editable", TR_CMT("Editable", + "If Tracker allows to edit this attribute."), + new BMessage(kMsgAttributeUpdated)); 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", TR("Special:"), - display_as_parameter(fAttribute.DisplayAs()), NULL, - B_FOLLOW_LEFT_RIGHT); - fSpecialControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); - fSpecialControl->SetDivider(labelWidth); + fSpecialControl = new BTextControl(TR("Special:"), + display_as_parameter(fAttribute.DisplayAs()), NULL); + fSpecialControl->SetModificationMessage( + new BMessage(kMsgAttributeUpdated)); 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", TR("Width:"), - text, NULL, B_FOLLOW_LEFT_RIGHT); - fWidthControl->SetModificationMessage(new BMessage(kMsgAttributeUpdated)); - fWidthControl->SetDivider(labelWidth); + fWidthControl = new BTextControl(TR_CMT("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 @@ -234,15 +199,16 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, } textView->SetMaxBytes(4); - box->AddChild(fWidthControl); - const struct alignment_map { int32 alignment; const char* name; } kAlignmentMap[] = { - {B_ALIGN_LEFT, TR("Left")}, - {B_ALIGN_RIGHT, TR("Right")}, - {B_ALIGN_CENTER, TR("Center")}, + {B_ALIGN_LEFT, TR_CMT("Left", "Attribute column alignment in " + "Tracker")}, + {B_ALIGN_RIGHT, TR_CMT("Right", "Attribute column alignment in " + "Tracker")}, + {B_ALIGN_CENTER, TR_CMT("Center", "Attribute column alignment in " + "Tracker")}, {0, NULL} }; @@ -258,36 +224,50 @@ AttributeWindow::AttributeWindow(FileTypesWindow* target, BMimeType& mimeType, item->SetMarked(true); } - rect.OffsetBy(0.0f, menuField->Bounds().Height() + 1.0f); - fAlignmentMenuField = new BMenuField(rect, "alignment", + fAlignmentMenuField = new BMenuField("alignment", TR("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 ? TR("Done") : TR("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 = new BButton("add", item ? TR("Done") : TR("Add"), + new BMessage(kMsgAccept)); fAcceptButton->SetEnabled(false); - topView->AddChild(fAcceptButton); - BButton* button = new BButton(rect, "cancel", TR("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); + BButton* cancelButton = new BButton("cancel", TR("Cancel"), + new BMessage(B_QUIT_REQUESTED)); - 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()); + BBox* visibleBox; + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) + .SetInsets(padding, padding, padding, padding) + .Add(BGridLayoutBuilder(padding, padding) + .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) + ) + .Add(visibleBox = new BBox(B_FANCY_BORDER, + BGridLayoutBuilder(padding, padding) + .Add(fDisplayAsMenuField->CreateLabelLayoutItem(), 0, 0) + .Add(fDisplayAsMenuField->CreateMenuBarLayoutItem(), 1, 0) + .Add(fEditableCheckBox, 3, 0) + .Add(fSpecialControl->CreateLabelLayoutItem(), 0, 1) + .Add(fSpecialControl->CreateTextViewLayoutItem(), 1, 1, 3) + .Add(fWidthControl->CreateLabelLayoutItem(), 0, 2) + .Add(fWidthControl->CreateTextViewLayoutItem(), 1, 2, 3) + .Add(fAlignmentMenuField->CreateLabelLayoutItem(), 0, 3) + .Add(fAlignmentMenuField->CreateMenuBarLayoutItem(), 1, 3, 3) + .SetInsets(padding, padding, padding, padding) + )) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(BSpaceLayoutItem::CreateGlue()) + .Add(BSpaceLayoutItem::CreateGlue()) + .Add(cancelButton) + .Add(fAcceptButton) + ) + ); + visibleBox->SetLabel(fVisibleCheckBox); fAcceptButton->MakeDefault(true); fPublicNameControl->MakeFocus(true); diff --git a/src/preferences/filetypes/DropTargetListView.cpp b/src/preferences/filetypes/DropTargetListView.cpp index f869e29ec1..85e00ea612 100644 --- a/src/preferences/filetypes/DropTargetListView.cpp +++ b/src/preferences/filetypes/DropTargetListView.cpp @@ -7,9 +7,9 @@ #include "DropTargetListView.h" -DropTargetListView::DropTargetListView(BRect frame, const char* name, - list_view_type type, uint32 resizeMask, uint32 flags) - : BListView(frame, name, type, resizeMask, flags), +DropTargetListView::DropTargetListView(const char* name, + list_view_type type, uint32 flags) + : BListView(name, type, flags), fDropTarget(false) { } diff --git a/src/preferences/filetypes/DropTargetListView.h b/src/preferences/filetypes/DropTargetListView.h index b510defe05..687ce27615 100644 --- a/src/preferences/filetypes/DropTargetListView.h +++ b/src/preferences/filetypes/DropTargetListView.h @@ -11,9 +11,8 @@ class DropTargetListView : public BListView { public: - DropTargetListView(BRect frame, const char* name, + DropTargetListView(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 ~DropTargetListView(); diff --git a/src/preferences/filetypes/ExtensionWindow.cpp b/src/preferences/filetypes/ExtensionWindow.cpp index c6ad4af22d..e5dc021348 100644 --- a/src/preferences/filetypes/ExtensionWindow.cpp +++ b/src/preferences/filetypes/ExtensionWindow.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include +#include #include #include #include @@ -110,25 +113,23 @@ replace_extension(BMimeType& type, const char* newExtension, ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type, const char* extension) : BWindow(BRect(100, 100, 350, 200), TR("Extension"), B_MODAL_WINDOW_LOOK, - B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE - | B_ASYNCHRONOUS_CONTROLS), + B_MODAL_SUBSET_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE + | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fTarget(target), fMimeType(type.Type()), fExtension(extension) { - 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); + SetLayout(new BGroupLayout(B_VERTICAL)); - rect.InsetBy(8.0f, 8.0f); - fExtensionControl = new BTextControl(rect, "extension", TR("Extension:"), extension, - NULL, B_FOLLOW_LEFT_RIGHT); - - float labelWidth = fExtensionControl->StringWidth(fExtensionControl->Label()) + 2.0f; - fExtensionControl->SetModificationMessage(new BMessage(kMsgExtensionUpdated)); - fExtensionControl->SetDivider(labelWidth); - fExtensionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); + float padding = 3.0f; + //if (be_control_look) + // padding = be_control_look->DefaultItemSpacing(); + // this seems to be very large! + + fExtensionControl = new BTextControl(TR("Extension:"), extension, NULL); + fExtensionControl->SetModificationMessage( + new BMessage(kMsgExtensionUpdated)); + fExtensionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); // filter out invalid characters that can't be part of an extension BTextView* textView = fExtensionControl->TextView(); @@ -137,30 +138,20 @@ ExtensionWindow::ExtensionWindow(FileTypesWindow* target, BMimeType& type, textView->DisallowChar(disallowedCharacters[i]); } - float width, height; - fExtensionControl->GetPreferredSize(&width, &height); - fExtensionControl->ResizeTo(rect.Width(), height); - topView->AddChild(fExtensionControl); - - fAcceptButton = new BButton(rect, "add", extension ? TR("Done") : TR("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 = new BButton(extension ? TR("Done") : TR("Add"), + new BMessage(kMsgAccept)); fAcceptButton->SetEnabled(false); - topView->AddChild(fAcceptButton); - BButton* button = new BButton(rect, "cancel", TR("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); + BButton* button = new BButton(TR("Cancel"), + new BMessage(B_QUIT_REQUESTED)); - ResizeTo(labelWidth * 4.0f + 24.0f, fExtensionControl->Bounds().Height() - + fAcceptButton->Bounds().Height() + 28.0f); - SetSizeLimits(button->Bounds().Width() + fAcceptButton->Bounds().Width() + 26.0f, - 32767.0f, Frame().Height(), Frame().Height()); + AddChild(BGridLayoutBuilder(padding, padding) + .Add(fExtensionControl->CreateLabelLayoutItem(), 0, 0) + .Add(fExtensionControl->CreateTextViewLayoutItem(), 1, 0) + .Add(fAcceptButton, 0, 1) + .Add(button, 1, 1) + .SetInsets(padding, padding, padding, padding) + ); // omit the leading dot if (fExtension.ByteAt(0) == '.') diff --git a/src/preferences/filetypes/FileTypeWindow.cpp b/src/preferences/filetypes/FileTypeWindow.cpp index 991363ef31..b897825b9b 100644 --- a/src/preferences/filetypes/FileTypeWindow.cpp +++ b/src/preferences/filetypes/FileTypeWindow.cpp @@ -15,13 +15,17 @@ #include #include #include +#include #include #include +#include +#include #include #include #include #include #include +#include #include #include @@ -45,35 +49,23 @@ const uint32 kMsgSamePreferredAppAsOpened = 'spaO'; FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) - : BWindow(BRect(0.0f, 0.0f, 200.0f, 200.0f).OffsetBySelf(position), + : + BWindow(BRect(0.0f, 0.0f, 200.0f, 200.0f).OffsetBySelf(position), TR("File type"), B_TITLED_WINDOW, - B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS) + B_NOT_V_RESIZABLE | B_NOT_ZOOMABLE | + B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS) { - 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; + // if (be_control_look) + // padding = be_control_look->DefaultItemSpacing(); + // too big! // "File Type" group + BBox* fileTypeBox = new BBox("file type BBox"); + fileTypeBox->SetLabel(TR("File type")); - BFont font(be_bold_font); - font_height fontHeight; - font.GetHeight(&fontHeight); - - rect.InsetBy(8.0f, 8.0f); - BBox* box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); - box->SetLabel(TR("File type")); - topView->AddChild(box); - - rect = box->Bounds(); - rect.InsetBy(8.0f, 4.0f + fontHeight.ascent + fontHeight.descent); - fTypeControl = new BTextControl(rect, "type", NULL, NULL, - new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT); - fTypeControl->SetDivider(0.0f); - float width, height; - fTypeControl->GetPreferredSize(&width, &height); - fTypeControl->ResizeTo(rect.Width(), height); - box->AddChild(fTypeControl); + fTypeControl = new BTextControl("type", NULL, "Type Control", + new BMessage(kMsgTypeEntered)); // filter out invalid characters that can't be part of a MIME type name BTextView* textView = fTypeControl->TextView(); @@ -82,55 +74,32 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) textView->DisallowChar(disallowedCharacters[i]); } - rect.OffsetBy(0.0f, fTypeControl->Bounds().Height() + 5.0f); - fSelectTypeButton = new BButton(rect, "select type", - TR("Select" B_UTF8_ELLIPSIS), - new BMessage(kMsgSelectType), B_FOLLOW_LEFT | B_FOLLOW_TOP); - fSelectTypeButton->ResizeToPreferred(); - box->AddChild(fSelectTypeButton); + fSelectTypeButton = new BButton("select type", + TR("Select" B_UTF8_ELLIPSIS), new BMessage(kMsgSelectType)); - rect.OffsetBy(fSelectTypeButton->Bounds().Width() + 8.0f, 0.0f); - fSameTypeAsButton = new BButton(rect, "same type as", - TR("Same as" B_UTF8_ELLIPSIS), - new BMessage(kMsgSameTypeAs), B_FOLLOW_LEFT | B_FOLLOW_TOP); - fSameTypeAsButton->ResizeToPreferred(); - box->AddChild(fSameTypeAsButton); + fSameTypeAsButton = new BButton("same type as", + TR("Same as" B_UTF8_ELLIPSIS), new BMessage(kMsgSameTypeAs)); - width = font.StringWidth("Icon") + 16.0f; - if (width < B_LARGE_ICON + 16.0f) - width = B_LARGE_ICON + 16.0f; - - height = fSelectTypeButton->Frame().bottom + 8.0f; - if (height < 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent) - height = 8.0f + B_LARGE_ICON + fontHeight.ascent + fontHeight.descent; - box->ResizeTo(box->Bounds().Width() - width - 8.0f, height); + fileTypeBox->AddChild(BGridLayoutBuilder(padding, padding) + .Add(fTypeControl, 0, 0, 2, 1) + .Add(fSelectTypeButton, 0, 1) + .Add(fSameTypeAsButton, 1, 1) + .SetInsets(padding, padding, padding, padding) + ); // "Icon" group - rect = box->Frame(); - 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"); - topView->AddChild(box); - - rect = BRect(8.0f, 0.0f, 7.0f + B_LARGE_ICON, B_LARGE_ICON - 1.0f); - rect.OffsetBy(0.0f, (box->Bounds().Height() - rect.Height()) / 2.0f); - if (rect.top < fontHeight.ascent + fontHeight.descent + 4.0f) - rect.top = fontHeight.ascent + fontHeight.descent + 4.0f; - fIconView = new IconView(rect, "icon"); - box->AddChild(fIconView); + BBox* iconBox = new BBox("icon BBox"); + iconBox->SetLabel(TR("Icon")); + fIconView = new IconView("icon"); + iconBox->AddChild(BGroupLayoutBuilder(B_HORIZONTAL) + .Add(fIconView) + .SetInsets(padding, padding, padding, padding)); // "Preferred Application" 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; - box = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); - box->SetLabel(TR("Preferred application")); - topView->AddChild(box); + BBox* preferredBox = new BBox("preferred BBox"); + preferredBox->SetLabel(TR("Preferred application")); BMenu* menu = new BPopUpMenu("preferred"); BMenuItem* item; @@ -138,43 +107,31 @@ FileTypeWindow::FileTypeWindow(BPoint position, const BMessage& refs) new BMessage(kMsgPreferredAppChosen))); item->SetMarked(true); - rect = fTypeControl->Frame(); - BView* constrainingView = new BView(rect, NULL, B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW); - constrainingView->SetViewColor(topView->ViewColor()); + fPreferredField = new BMenuField("preferred", NULL, menu); - fPreferredField = new BMenuField(rect.OffsetToCopy(B_ORIGIN), "preferred", - NULL, menu); - fPreferredField->GetPreferredSize(&width, &height); - fPreferredField->ResizeTo(rect.Width(), height); - constrainingView->ResizeTo(rect.Width(), height); - constrainingView->AddChild(fPreferredField); - // we embed the menu field in another view to make it behave like - // we want so that it can't obscure other elements with larger - // labels + fSelectAppButton = new BButton("select app", TR("Select" B_UTF8_ELLIPSIS), + new BMessage(kMsgSelectPreferredApp)); - box->AddChild(constrainingView); + fSameAppAsButton = new BButton("same app as", TR("Same as" B_UTF8_ELLIPSIS), + new BMessage(kMsgSamePreferredAppAs)); - rect.OffsetBy(0.0f, height + 5.0f); - fSelectAppButton = new BButton(rect, "select app", - TR("Select" B_UTF8_ELLIPSIS), - new BMessage(kMsgSelectPreferredApp), B_FOLLOW_LEFT | B_FOLLOW_TOP); - fSelectAppButton->ResizeToPreferred(); - box->AddChild(fSelectAppButton); + preferredBox->AddChild(BGridLayoutBuilder(padding, padding) + .Add(fPreferredField, 0, 0, 2, 1) + .Add(fSelectAppButton, 0, 1) + .Add(fSameAppAsButton, 1, 1) + .Add(BSpaceLayoutItem::CreateGlue(), 3, 0, 1, 2) + .SetInsets(padding, padding, padding, padding) + ); - rect.OffsetBy(fSelectAppButton->Bounds().Width() + 8.0f, 0.0f); - fSameAppAsButton = new BButton(rect, "same app as", - TR("Same as" B_UTF8_ELLIPSIS), - new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_LEFT | B_FOLLOW_TOP); - fSameAppAsButton->ResizeToPreferred(); - box->AddChild(fSameAppAsButton); - box->ResizeBy(0.0f, height - fTypeControl->Bounds().Height()); - - ResizeTo(fSameAppAsButton->Frame().right + 100.0f, box->Frame().bottom + 8.0f); - SetSizeLimits(fSameAppAsButton->Frame().right + iconBoxWidth + 32.0f, 32767.0f, - Bounds().Height(), Bounds().Height()); + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGridLayoutBuilder(padding, padding) + .Add(fileTypeBox, 0, 0, 1, 2) + .Add(iconBox, 1, 1, 1, 2) + .Add(preferredBox, 0, 2, 1, 2) + .SetInsets(padding, padding, padding, padding) + ); fTypeControl->MakeFocus(true); - BMimeType::StartWatching(this); _SetTo(refs); } @@ -190,6 +147,7 @@ BString FileTypeWindow::_Title(const BMessage& refs) { BString title; + entry_ref ref; if (refs.FindRef("refs", 1, &ref) == B_OK) { bool same = false; @@ -213,15 +171,18 @@ FileTypeWindow::_Title(const BMessage& refs) char name[B_FILE_NAME_LENGTH]; if (same && parent.GetName(name) == B_OK) { - title = TR("Multiple files from \""); - title.Append(name); - title.Append("\""); + char buffer[512]; + snprintf(buffer, sizeof(buffer), + TR("Multiple files from \"%s\" file type"), name); + title = buffer; } else - title = TR("[Multiple files]"); - } else if (refs.FindRef("refs", 0, &ref) == B_OK) - title = ref.name; + title = TR("[Multiple files] file types"); + } else if (refs.FindRef("refs", 0, &ref) == B_OK) { + char buffer[512]; + snprintf(buffer, sizeof(buffer), TR("%s file type"), ref.name); + title = buffer; + } - title.Append(" file type"); return title; } @@ -443,7 +404,8 @@ FileTypeWindow::MessageReceived(BMessage* message) case kMsgSamePreferredAppAs: { BMessage panel(kMsgOpenFilePanel); - panel.AddString("title", TR("Select same preferred application as")); + panel.AddString("title", + TR("Select same preferred application as")); panel.AddInt32("message", kMsgSamePreferredAppAsOpened); panel.AddMessenger("target", this); @@ -478,11 +440,9 @@ FileTypeWindow::MessageReceived(BMessage* message) break; if (which == B_MIME_TYPE_DELETED -#ifdef __HAIKU__ - || which == B_SUPPORTED_TYPES_CHANGED -#endif - ) + || which == B_SUPPORTED_TYPES_CHANGED) { _UpdatePreferredApps(); + } break; default: diff --git a/src/preferences/filetypes/FileTypes.cpp b/src/preferences/filetypes/FileTypes.cpp index 8e4bf9e131..c8c0ab8e9c 100644 --- a/src/preferences/filetypes/FileTypes.cpp +++ b/src/preferences/filetypes/FileTypes.cpp @@ -1,6 +1,6 @@ /* - * Copyright 2006-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2006-2007, Axel Dörfler, axeld@pinc-software.de. + * All rights reserved. Distributed under the terms of the MIT License. */ @@ -76,8 +76,8 @@ class FileTypes : public BApplication { BWindow *fApplicationTypesWindow; uint32 fWindowCount; uint32 fTypeWindowCount; - - BCatalog fCatalog; + + BCatalog fCatalog; }; @@ -221,7 +221,7 @@ FileTypes::RefsReceived(BMessage *message) ref.name, strerror(status)); (new BAlert(TR("FileTypes request"), - buffer, "Ok", NULL, NULL, + buffer, TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT))->Go(); message->RemoveData("refs", --index); @@ -287,7 +287,7 @@ FileTypes::ArgvReceived(int32 argc, char **argv) if ((status = entry.SetTo(path.Path(), false)) != B_OK || (status = entry.GetRef(&ref)) != B_OK) { - fprintf(stderr, TR("Could not open file \"%s\": %s\n"), + fprintf(stderr, "Could not open file \"%s\": %s\n", path.Path(), strerror(status)); continue; } @@ -356,7 +356,7 @@ FileTypes::MessageReceived(BMessage *message) // the open file panel sends us a message when it's done const char* subTitle; if (message->FindString("title", &subTitle) != B_OK) - subTitle = TR("Open File"); + subTitle = TR("Open file"); int32 what; if (message->FindInt32("message", &what) != B_OK) @@ -366,7 +366,7 @@ FileTypes::MessageReceived(BMessage *message) if (message->FindMessenger("target", &target) != B_OK) target = be_app_messenger; - BString title = "FileTypes"; + BString title = TR("FileTypes"); if (subTitle != NULL && subTitle[0]) { title.Append(": "); title.Append(subTitle); @@ -407,9 +407,12 @@ FileTypes::MessageReceived(BMessage *message) void FileTypes::AboutRequested() { - BAlert *alert = new BAlert("about", TR("FileTypes\n" - "\twritten by Axel Dörfler\n" - "\tCopyright 2006-2007, Haiku.\n"), TR("Ok")); + BString aboutText(TR("FileTypes")); + int32 titleLength = aboutText.Length(); + aboutText << "\n"; + aboutText << TR("\twritten by Axel Dörfler\n" + "\tCopyright 2006-2007, Haiku.\n"); + BAlert *alert = new BAlert("about", aboutText.String(), TR("OK")); BTextView *view = alert->TextView(); BFont font; @@ -418,7 +421,7 @@ FileTypes::AboutRequested() view->GetFont(&font); font.SetSize(18); font.SetFace(B_BOLD_FACE); - view->SetFontAndColor(0, 9, &font); + view->SetFontAndColor(0, titleLength, &font); alert->Go(); } @@ -454,12 +457,14 @@ void error_alert(const char* message, status_t status, alert_type type) { char warning[512]; - if (status != B_OK) - snprintf(warning, sizeof(warning), "%s:\n\t%s\n", message, strerror(status)); + if (status != B_OK) { + snprintf(warning, sizeof(warning), "%s:\n\t%s\n", message, + strerror(status)); + } - (new BAlert(TR("FileTypes Request"), + (new BAlert(TR("FileTypes request"), status == B_OK ? message : warning, - "Ok", NULL, NULL, B_WIDTH_AS_USUAL, type))->Go(); + TR("OK"), NULL, NULL, B_WIDTH_AS_USUAL, type))->Go(); } diff --git a/src/preferences/filetypes/FileTypesWindow.cpp b/src/preferences/filetypes/FileTypesWindow.cpp index 18a09dbe23..2a45fe196d 100644 --- a/src/preferences/filetypes/FileTypesWindow.cpp +++ b/src/preferences/filetypes/FileTypesWindow.cpp @@ -16,12 +16,16 @@ #include "PreferredAppMenu.h" #include "StringView.h" +#include #include #include #include #include #include #include +#include +#include +#include #include #include #include @@ -32,6 +36,8 @@ #include #include #include +#include +#include #include #include @@ -42,7 +48,7 @@ #undef TR_CONTEXT -#define TR_CONTEXT "FileType Window" +#define TR_CONTEXT "FileTypes Window" const uint32 kMsgTypeSelected = 'typs'; @@ -73,10 +79,10 @@ const uint32 kMsgDescriptionEntered = 'dsce'; const uint32 kMsgToggleIcons = 'tgic'; const uint32 kMsgToggleRule = 'tgrl'; + class TypeIconView : public IconView { public: - TypeIconView(BRect frame, const char* name, - int32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP); + TypeIconView(const char* name); virtual ~TypeIconView(); virtual void Draw(BRect updateRect); @@ -86,11 +92,11 @@ class TypeIconView : public IconView { virtual BRect BitmapRect() const; }; + class ExtensionListView : public DropTargetListView { public: - ExtensionListView(BRect frame, const char* name, + ExtensionListView(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 ~ExtensionListView(); @@ -107,8 +113,8 @@ class ExtensionListView : public DropTargetListView { // #pragma mark - -TypeIconView::TypeIconView(BRect frame, const char* name, int32 resizingMode) - : IconView(frame, name, resizingMode) +TypeIconView::TypeIconView(const char* name) + : IconView(name) { ShowEmptyFrame(false); } @@ -179,7 +185,8 @@ TypeIconView::GetPreferredSize(float* _width, float* _height) font_height fontHeight; GetFontHeight(&fontHeight); - *_height = IconSize() + 3.0f + ceilf(fontHeight.ascent + fontHeight.descent); + *_height = IconSize() + 3.0f + ceilf(fontHeight.ascent + + fontHeight.descent); } } @@ -195,7 +202,8 @@ TypeIconView::BitmapRect() const float width = StringWidth(TR("no icon")) + 8.0f; float height = ceilf(fontHeight.ascent + fontHeight.descent) + 6.0f; float x = (Bounds().Width() - width) / 2.0f; - float y = ceilf((IconSize() - fontHeight.ascent - fontHeight.descent) / 2.0f) - 3.0f; + float y = ceilf((IconSize() - fontHeight.ascent - fontHeight.descent) + / 2.0f) - 3.0f; return BRect(x, y, x + width, y + height); } @@ -208,9 +216,9 @@ TypeIconView::BitmapRect() const // #pragma mark - -ExtensionListView::ExtensionListView(BRect frame, const char* name, - list_view_type type, uint32 resizeMask, uint32 flags) - : DropTargetListView(frame, name, type, resizeMask, flags) +ExtensionListView::ExtensionListView(const char* name, + list_view_type type, uint32 flags) + : DropTargetListView(name, type, flags) { } @@ -277,8 +285,9 @@ ExtensionListView::SetType(BMimeType* type) FileTypesWindow::FileTypesWindow(const BMessage& settings) - : BWindow(_Frame(settings), "FileTypes", B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), + : + BWindow(_Frame(settings), TR("FileTypes"), B_TITLED_WINDOW, + B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fNewTypeWindow(NULL) { bool showIcons; @@ -288,10 +297,19 @@ FileTypesWindow::FileTypesWindow(const BMessage& settings) if (settings.FindBool("show_rule", &showRule) != B_OK) showRule = false; - // add the menu + SetLayout(new BGroupLayout(B_VERTICAL)); + float padding = 3.0f; + BAlignment labelAlignment = BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP); + if (be_control_look) { + // padding = be_control_look->DefaultItemSpacing(); + // this seems to be very large! + labelAlignment = be_control_look->DefaultLabelAlignment(); + } + BAlignment fullAlignment = + BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT); - BMenuBar* menuBar = new BMenuBar(BRect(0, 0, 0, 0), NULL); - AddChild(menuBar); + // add the menu + BMenuBar* menuBar = new BMenuBar(""); BMenu* menu = new BMenu(TR("File")); BMenuItem* item; @@ -300,11 +318,12 @@ FileTypesWindow::FileTypesWindow(const BMessage& settings) item->SetEnabled(false); BMenu* recentsMenu = BRecentFilesList::NewFileListMenu( - TR("Open" B_UTF8_ELLIPSIS), - NULL, NULL, be_app, 10, false, NULL, kSignature); + TR("Open" B_UTF8_ELLIPSIS), NULL, NULL, be_app, 10, false, NULL, + kSignature); item = new BMenuItem(recentsMenu, new BMessage(kMsgOpenFilePanel)); item->SetShortcut('O', B_COMMAND_KEY); menu->AddItem(item); + menu->AddItem(new BMenuItem(TR("Application types" B_UTF8_ELLIPSIS), new BMessage(kMsgOpenApplicationTypesWindow))); menu->AddSeparatorItem(); @@ -319,264 +338,187 @@ FileTypesWindow::FileTypesWindow(const BMessage& settings) menuBar->AddItem(menu); menu = new BMenu(TR("Settings")); - item = new BMenuItem(TR("Show icons in list"), new BMessage(kMsgToggleIcons)); + item = new BMenuItem(TR("Show icons in list"), + new BMessage(kMsgToggleIcons)); item->SetMarked(showIcons); item->SetTarget(this); menu->AddItem(item); - item = new BMenuItem(TR("Show recognition rule"), new BMessage(kMsgToggleRule)); + item = new BMenuItem(TR("Show recognition rule"), + new BMessage(kMsgToggleRule)); item->SetMarked(showRule); item->SetTarget(this); menu->AddItem(item); menuBar->AddItem(menu); + AddChild(menuBar); + menuBar->SetExplicitAlignment(BAlignment(B_ALIGN_LEFT, B_ALIGN_TOP)); + // MIME Types list + BButton* addTypeButton = new BButton("add", TR("Add" B_UTF8_ELLIPSIS), + new BMessage(kMsgAddType)); - 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); + fRemoveTypeButton = new BButton("remove", TR("Remove"), + new BMessage(kMsgRemoveType) ); - BButton* button = new BButton(rect, "add", TR("Add" B_UTF8_ELLIPSIS), - new BMessage(kMsgAddType), B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->MoveTo(8.0f, topView->Bounds().bottom - 8.0f - button->Bounds().Height()); - topView->AddChild(button); - - rect = button->Frame(); - rect.OffsetBy(rect.Width() + 8.0f, 0.0f); - fRemoveTypeButton = new BButton(rect, "remove", TR("Remove"), - new BMessage(kMsgRemoveType), B_FOLLOW_BOTTOM); - fRemoveTypeButton->ResizeToPreferred(); - topView->AddChild(fRemoveTypeButton); - - rect.bottom = rect.top - 10.0f; - rect.top = 10.0f; - rect.left = 10.0f; - rect.right -= B_V_SCROLL_BAR_WIDTH + 2.0f; - if (rect.right < 180) - rect.right = 180; - - fTypeListView = new MimeTypeListView(rect, "typeview", NULL, showIcons, false, - B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); + fTypeListView = new MimeTypeListView("typeview", NULL, showIcons, false); fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); - BScrollView* scrollView = new BScrollView("scrollview", fTypeListView, - B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - topView->AddChild(scrollView); + BScrollView* typeListScrollView = new BScrollView("scrollview", + fTypeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); // "Icon" group - font_height plainHeight; - be_plain_font->GetHeight(&plainHeight); - float height = ceilf(plainHeight.ascent + plainHeight.descent - + plainHeight.leading) + 2.0f; - - BFont font(be_bold_font); - float labelWidth = font.StringWidth(TR("Icon")); - font_height boldHeight; - font.GetHeight(&boldHeight); - - BRect innerRect; - fIconView = new TypeIconView(innerRect, "icon", - B_FOLLOW_LEFT | B_FOLLOW_V_CENTER); - fIconView->ResizeToPreferred(); - - rect.left = rect.right + 12.0f + B_V_SCROLL_BAR_WIDTH; - rect.right = rect.left + max_c(fIconView->Bounds().Width(), labelWidth) + 16.0f; - rect.bottom = rect.top + ceilf(boldHeight.ascent) - + max_c(fIconView->Bounds().Height(), - button->Bounds().Height() * 2.0f + height + 4.0f) + 12.0f; - rect.top -= 2.0f; - fIconBox = new BBox(rect); + fIconView = new TypeIconView("icon"); + fIconBox = new BBox("Icon BBox"); fIconBox->SetLabel(TR("Icon")); - topView->AddChild(fIconBox); - - innerRect.left = 8.0f; - innerRect.top = plainHeight.ascent + 3.0f - + (rect.Height() - boldHeight.ascent - fIconView->Bounds().Height()) / 2.0f; - if (innerRect.top + fIconView->Bounds().Height() > fIconBox->Bounds().Height() - 6.0f) - innerRect.top = fIconBox->Bounds().Height() - 6.0f - fIconView->Bounds().Height(); - fIconView->MoveTo(innerRect.LeftTop()); - fIconBox->AddChild(fIconView); + fIconBox->AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) + .Add(BSpaceLayoutItem::CreateGlue(), 1) + .Add(fIconView, 3) + .Add(BSpaceLayoutItem::CreateGlue(), 1) + .SetInsets(padding, padding, padding, padding) + ); // "File Recognition" group - BRect rightRect(rect); - rightRect.left = rect.right + 8.0f; - rightRect.right = topView->Bounds().Width() - 8.0f; - fRecognitionBox = new BBox(rightRect, NULL, B_FOLLOW_LEFT_RIGHT); + fRecognitionBox = new BBox("Recognition Box"); fRecognitionBox->SetLabel(TR("File recognition")); - topView->AddChild(fRecognitionBox); + fRecognitionBox->SetExplicitAlignment(fullAlignment); - innerRect = fRecognitionBox->Bounds().InsetByCopy(8.0f, 4.0f); - innerRect.top += ceilf(boldHeight.ascent); - fExtensionLabel = new StringView(innerRect, "extension", TR("Extensions:"), NULL); - fExtensionLabel->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); - fExtensionLabel->ResizeToPreferred(); - fRecognitionBox->AddChild(fExtensionLabel); + fExtensionLabel = new StringView(TR("Extensions:"), NULL); + fExtensionLabel->LabelView()->SetExplicitAlignment(labelAlignment); - innerRect.top += fExtensionLabel->Bounds().Height() + 2.0f; - innerRect.left = innerRect.right - button->StringWidth(TR("Remove")) - 16.0f; - innerRect.bottom = innerRect.top + button->Bounds().Height(); - fAddExtensionButton = new BButton(innerRect, "add ext", TR("Add" B_UTF8_ELLIPSIS), - new BMessage(kMsgAddExtension), B_FOLLOW_RIGHT); - fRecognitionBox->AddChild(fAddExtensionButton); + fAddExtensionButton = new BButton("add ext", TR("Add" B_UTF8_ELLIPSIS), + new BMessage(kMsgAddExtension)); - innerRect.OffsetBy(0, innerRect.Height() + 4.0f); - fRemoveExtensionButton = new BButton(innerRect, "remove ext", TR("Remove"), - new BMessage(kMsgRemoveExtension), B_FOLLOW_RIGHT); - fRecognitionBox->AddChild(fRemoveExtensionButton); + fRemoveExtensionButton = new BButton("remove ext", TR("Remove"), + new BMessage(kMsgRemoveExtension)); - innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; - innerRect.left = 10.0f; - innerRect.top = fAddExtensionButton->Frame().top + 2.0f; - innerRect.bottom = innerRect.bottom - 2.0f; - // take scrollview border into account - fExtensionListView = new ExtensionListView(innerRect, "listview ext", - B_SINGLE_SELECTION_LIST, B_FOLLOW_LEFT_RIGHT); - fExtensionListView->SetSelectionMessage(new BMessage(kMsgExtensionSelected)); - fExtensionListView->SetInvocationMessage(new BMessage(kMsgExtensionInvoked)); + fExtensionListView = new ExtensionListView("listview ext", + B_SINGLE_SELECTION_LIST); + fExtensionListView->SetSelectionMessage( + new BMessage(kMsgExtensionSelected)); + fExtensionListView->SetInvocationMessage( + new BMessage(kMsgExtensionInvoked)); - scrollView = new BScrollView("scrollview ext", fExtensionListView, - B_FOLLOW_LEFT_RIGHT, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - fRecognitionBox->AddChild(scrollView); + BScrollView* scrollView = new BScrollView("scrollview ext", + fExtensionListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - innerRect.left = 8.0f; - innerRect.top = innerRect.bottom + 10.0f; - innerRect.right = fRecognitionBox->Bounds().right - 8.0f; - innerRect.bottom = innerRect.top + 20.0f; - fRuleControl = new BTextControl(innerRect, "rule", TR("Rule:"), "", - new BMessage(kMsgRuleEntered), B_FOLLOW_LEFT_RIGHT); - //fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); - fRuleControl->SetDivider(fRuleControl->StringWidth(fRuleControl->Label()) + 6.0f); + fRuleControl = new BTextControl("rule", TR("Rule:"), "", + new BMessage(kMsgRuleEntered)); + fRuleControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); fRuleControl->Hide(); - fRecognitionBox->AddChild(fRuleControl); + + BView* recognitionBoxGrid = + BGridLayoutBuilder(padding, padding) + .Add(fExtensionLabel->LabelView(), 0, 0) + .Add(scrollView, 0, 1, 2, 3) + .Add(fAddExtensionButton, 2, 1) + .Add(fRemoveExtensionButton, 2, 2) + .Add(fRuleControl, 0, 4, 3, 1) + .SetInsets(padding, padding, padding, padding); + + recognitionBoxGrid->SetExplicitAlignment(fullAlignment); + fRecognitionBox->AddChild(recognitionBoxGrid); // "Description" group - rect.top = rect.bottom + 8.0f; - rect.bottom = rect.top + ceilf(boldHeight.ascent) + 24.0f; - rect.right = rightRect.right; - fDescriptionBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); + fDescriptionBox = new BBox("description BBox"); fDescriptionBox->SetLabel(TR("Description")); - topView->AddChild(fDescriptionBox); + fDescriptionBox->SetExplicitAlignment(fullAlignment); - innerRect = fDescriptionBox->Bounds().InsetByCopy(8.0f, 6.0f); - innerRect.top += ceilf(boldHeight.ascent); - innerRect.bottom = innerRect.top + button->Bounds().Height(); - fInternalNameView = new StringView(innerRect, "internal", TR("Internal name:"), "", - B_FOLLOW_LEFT_RIGHT); - labelWidth = fInternalNameView->StringWidth(fInternalNameView->Label()) + 2.0f; - fInternalNameView->SetDivider(labelWidth); + fInternalNameView = new StringView(TR("Internal name:"), NULL); fInternalNameView->SetEnabled(false); - fInternalNameView->ResizeToPreferred(); - fDescriptionBox->AddChild(fInternalNameView); + fTypeNameControl = new BTextControl("type", TR("Type name:"), "", + new BMessage(kMsgTypeEntered)); + fDescriptionControl = new BTextControl("description", TR("Description:"), + "", new BMessage(kMsgDescriptionEntered)); - innerRect.OffsetBy(0, fInternalNameView->Bounds().Height() + 5.0f); - fTypeNameControl = new BTextControl(innerRect, "type", TR("Type name:"), "", - new BMessage(kMsgTypeEntered), B_FOLLOW_LEFT_RIGHT); - fTypeNameControl->SetDivider(labelWidth); - fTypeNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); - fDescriptionBox->ResizeBy(0, fInternalNameView->Bounds().Height() - + fTypeNameControl->Bounds().Height() * 2.0f); - fDescriptionBox->AddChild(fTypeNameControl); + fDescriptionBox->AddChild(BGridLayoutBuilder(padding, padding) + .Add(fInternalNameView->LabelView(), 0, 0) + .Add(fInternalNameView->TextView(), 1, 0) + .Add(fTypeNameControl->CreateLabelLayoutItem(), 0, 1) + .Add(fTypeNameControl->CreateTextViewLayoutItem(), 1, 1, 2) + .Add(fDescriptionControl->CreateLabelLayoutItem(), 0, 2) + .Add(fDescriptionControl->CreateTextViewLayoutItem(), 1, 2, 2) + .SetInsets(padding, padding, padding, padding) + ); - innerRect.OffsetBy(0, fTypeNameControl->Bounds().Height() + 5.0f); - fDescriptionControl = new BTextControl(innerRect, "description", TR("Description:"), "", - new BMessage(kMsgDescriptionEntered), B_FOLLOW_LEFT_RIGHT); - fDescriptionControl->SetDivider(labelWidth); - fDescriptionControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); - fDescriptionBox->AddChild(fDescriptionControl); // "Preferred Application" group - rect = fDescriptionBox->Frame(); - rect.top = rect.bottom + 8.0f; - rect.bottom = rect.top + ceilf(boldHeight.ascent) - + button->Bounds().Height() + 14.0f; - fPreferredBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT); + fPreferredBox = new BBox("preferred BBox"); fPreferredBox->SetLabel(TR("Preferred application")); - topView->AddChild(fPreferredBox); - - innerRect = fPreferredBox->Bounds().InsetByCopy(8.0f, 6.0f); - innerRect.top += ceilf(boldHeight.ascent); - innerRect.left = innerRect.right - button->StringWidth( - TR("Same as" B_UTF8_ELLIPSIS)) - 24.0f; - innerRect.bottom = innerRect.top + button->Bounds().Height(); - fSameAsButton = new BButton(innerRect, "same as", - TR("Same as" B_UTF8_ELLIPSIS), - new BMessage(kMsgSamePreferredAppAs), B_FOLLOW_RIGHT); - fPreferredBox->AddChild(fSameAsButton); - - innerRect.OffsetBy(-innerRect.Width() - 6.0f, 0.0f); - fSelectButton = new BButton(innerRect, "select", TR("Select" B_UTF8_ELLIPSIS), - new BMessage(kMsgSelectPreferredApp), B_FOLLOW_RIGHT); - fPreferredBox->AddChild(fSelectButton); menu = new BPopUpMenu("preferred"); menu->AddItem(item = new BMenuItem(TR("None"), new BMessage(kMsgPreferredAppChosen))); item->SetMarked(true); + fPreferredField = new BMenuField("preferred", (char*)NULL, menu); - innerRect.right = innerRect.left - 6.0f; - innerRect.left = 8.0f; + fSelectButton = new BButton("select", TR("Select" B_UTF8_ELLIPSIS), + new BMessage(kMsgSelectPreferredApp)); - fPreferredField = new BMenuField(innerRect, "preferred", NULL, menu, true, - B_FOLLOW_LEFT_RIGHT); - float width; - fPreferredField->GetPreferredSize(&width, &height); - fPreferredField->ResizeTo(innerRect.Width(), height); - fPreferredField->MoveBy(0.0f, (innerRect.Height() - height) / 2.0f); + fSameAsButton = new BButton("same as", TR("Same as" B_UTF8_ELLIPSIS), + new BMessage(kMsgSamePreferredAppAs)); - fPreferredBox->AddChild(fPreferredField); + fPreferredBox->AddChild( + BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(fPreferredField) + .Add(fSelectButton) + .Add(fSameAsButton) + .SetInsets(padding, padding, padding, padding) + ); // "Extra Attributes" group - - rect.top = rect.bottom + 8.0f; - rect.bottom = topView->Bounds().Height() - 8.0f; - fAttributeBox = new BBox(rect, NULL, B_FOLLOW_LEFT_RIGHT - | B_FOLLOW_TOP_BOTTOM); + fAttributeBox = new BBox("Attribute Box"); fAttributeBox->SetLabel(TR("Extra attributes")); - topView->AddChild(fAttributeBox); - innerRect = fAttributeBox->Bounds().InsetByCopy(8.0f, 6.0f); - innerRect.top += ceilf(boldHeight.ascent); - innerRect.left = innerRect.right - button->StringWidth(TR("Remove")) - 16.0f; - innerRect.bottom = innerRect.top + button->Bounds().Height(); - fAddAttributeButton = new BButton(innerRect, "add attr", - TR("Add" B_UTF8_ELLIPSIS), new BMessage(kMsgAddAttribute), B_FOLLOW_RIGHT); - fAttributeBox->AddChild(fAddAttributeButton); + fAddAttributeButton = new BButton("add attr", + "Add" B_UTF8_ELLIPSIS, new BMessage(kMsgAddAttribute)); - innerRect.OffsetBy(0, innerRect.Height() + 4.0f); - fRemoveAttributeButton = new BButton(innerRect, "remove attr", TR("Remove"), - new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); - fAttributeBox->AddChild(fRemoveAttributeButton); -/* - innerRect.OffsetBy(0, innerRect.Height() + 4.0f); - button = new BButton(innerRect, "push attr", "Push Up", - new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT); - fAttributeBox->AddChild(button); -*/ - innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH; - innerRect.left = 10.0f; - innerRect.top = 8.0f + ceilf(boldHeight.ascent); - innerRect.bottom = fAttributeBox->Bounds().bottom - 10.0f; - // take scrollview border into account - fAttributeListView = new AttributeListView(innerRect, "listview attr", - B_FOLLOW_ALL); - fAttributeListView->SetSelectionMessage(new BMessage(kMsgAttributeSelected)); - fAttributeListView->SetInvocationMessage(new BMessage(kMsgAttributeInvoked)); + fRemoveAttributeButton = new BButton("remove attr", TR("Remove"), + new BMessage(kMsgRemoveAttribute)); - scrollView = new BScrollView("scrollview attr", fAttributeListView, - B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - fAttributeBox->AddChild(scrollView); + fAttributeListView = new AttributeListView("listview attr"); + fAttributeListView->SetSelectionMessage( + new BMessage(kMsgAttributeSelected)); + fAttributeListView->SetInvocationMessage( + new BMessage(kMsgAttributeInvoked)); - SetSizeLimits(rightRect.left + 72.0f + font.StringWidth("jpg") - + font.StringWidth(fRecognitionBox->Label()), 32767.0f, - rect.top + 2.0f * button->Bounds().Height() + boldHeight.ascent - + 32.0f + menuBar->Bounds().Height(), 32767.0f); + BScrollView* attributesScroller = new BScrollView("scrollview attr", + fAttributeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); + + fAttributeBox->AddChild(BGridLayoutBuilder(padding, padding) + .Add(attributesScroller, 0, 0, 2, 3) + .Add(fAddAttributeButton, 2, 0) + .Add(fRemoveAttributeButton, 2, 1) + .SetInsets(padding, padding, padding, padding) + ); + + + BView* topView = + BGroupLayoutBuilder(B_HORIZONTAL, padding) + .SetInsets(padding, padding, padding, padding) + .Add(BGroupLayoutBuilder(B_VERTICAL, padding) + .Add(typeListScrollView) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(addTypeButton).Add(fRemoveTypeButton) + ) + ) + // Right side + .Add(BGroupLayoutBuilder(B_VERTICAL, padding) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(fIconBox, 1).Add(fRecognitionBox, 3) + ) + .Add(fDescriptionBox) + .Add(fPreferredBox) + .Add(fAttributeBox, 5) + ); + + //topView->SetExplicitAlignment(fullAlignment); + //topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(topView); _SetType(NULL); _ShowSnifferRule(showRule); @@ -598,7 +540,7 @@ FileTypesWindow::_Frame(const BMessage& settings) const if (settings.FindRect("file_types_frame", &rect) == B_OK) return rect; - return BRect(80.0f, 80.0f, 600.0f, 480.0f); + return BRect(80.0f, 80.0f, 0.0f, 0.0f); } @@ -608,29 +550,10 @@ FileTypesWindow::_ShowSnifferRule(bool show) if (fRuleControl->IsHidden() == !show) return; - float minWidth, maxWidth, minHeight, maxHeight; - GetSizeLimits(&minWidth, &maxWidth, &minHeight, &maxHeight); - - float diff = fRuleControl->Bounds().Height() + 8.0f; - - if (!show) { + if (!show) fRuleControl->Hide(); - diff = -diff; - } - - // adjust other controls to make space or take it again - - fIconBox->ResizeBy(0.0f, diff); - fRecognitionBox->ResizeBy(0.0f, diff); - fDescriptionBox->MoveBy(0.0f, diff); - fPreferredBox->MoveBy(0.0f, diff); - fAttributeBox->MoveBy(0.0f, diff); - fAttributeBox->ResizeBy(0.0f, -diff); - - if (show) + else fRuleControl->Show(); - - SetSizeLimits(minWidth, maxWidth, minHeight + diff, maxHeight); } @@ -671,8 +594,10 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs) return; BString preferred; - if (retrieve_preferred_app(message, sameAs, fCurrentType.Type(), preferred) != B_OK) + if (retrieve_preferred_app(message, sameAs, fCurrentType.Type(), preferred) + != B_OK) { return; + } status_t status = fCurrentType.SetPreferredApp(preferred.String()); if (status != B_OK) @@ -683,7 +608,8 @@ FileTypesWindow::_AdoptPreferredApplication(BMessage* message, bool sameAs) void FileTypesWindow::_UpdatePreferredApps(BMimeType* type) { - update_preferred_app_menu(fPreferredField->Menu(), type, kMsgPreferredAppChosen); + update_preferred_app_menu(fPreferredField->Menu(), type, + kMsgPreferredAppChosen); } @@ -787,8 +713,9 @@ FileTypesWindow::_SetType(BMimeType* type, int32 forceUpdate) void FileTypesWindow::PlaceSubWindow(BWindow* window) { - window->MoveTo(Frame().left + (Frame().Width() - window->Frame().Width()) / 2.0f, - Frame().top + (Frame().Height() - window->Frame().Height()) / 2.0f); + window->MoveTo(Frame().left + (Frame().Width() - window->Frame().Width()) + / 2.0f, Frame().top + (Frame().Height() - window->Frame().Height()) + / 2.0f); } @@ -797,12 +724,14 @@ FileTypesWindow::MessageReceived(BMessage* message) { switch (message->what) { case B_SIMPLE_DATA: + { type_code type; if (message->GetInfo("refs", &type) == B_OK && type == B_REF_TYPE) { be_app->PostMessage(message); } break; + } case kMsgToggleIcons: { @@ -840,7 +769,8 @@ FileTypesWindow::MessageReceived(BMessage* message) { int32 index; if (message->FindInt32("index", &index) == B_OK) { - MimeTypeItem* item = (MimeTypeItem*)fTypeListView->ItemAt(index); + MimeTypeItem* item + = (MimeTypeItem*)fTypeListView->ItemAt(index); if (item != NULL) { BMimeType type(item->Type()); _SetType(&type); @@ -851,14 +781,14 @@ FileTypesWindow::MessageReceived(BMessage* message) } case kMsgAddType: - { if (fNewTypeWindow == NULL) { - fNewTypeWindow = new NewFileTypeWindow(this, fCurrentType.Type()); + fNewTypeWindow + = new NewFileTypeWindow(this, fCurrentType.Type()); fNewTypeWindow->Show(); } else fNewTypeWindow->Activate(); break; - } + case kMsgNewTypeWindowClosed: fNewTypeWindow = NULL; break; @@ -870,7 +800,7 @@ FileTypesWindow::MessageReceived(BMessage* message) BAlert* alert; if (fCurrentType.IsSupertypeOnly()) { - alert = new BPrivate::OverrideAlert(TR("FileTypes Request"), + alert = new BPrivate::OverrideAlert(TR("FileTypes request"), TR("Removing a super type cannot be reverted.\n" "All file types that belong to this super type " "will be lost!\n\n" @@ -879,17 +809,20 @@ FileTypesWindow::MessageReceived(BMessage* message) TR("Remove"), B_SHIFT_KEY, TR("Cancel"), 0, NULL, 0, B_WIDTH_AS_USUAL, B_STOP_ALERT); } else { - alert = new BAlert(TR("FileTypes Request"), + alert = new BAlert(TR("FileTypes request"), TR("Removing a file type cannot be reverted.\n" "Are you sure you want to remove it?"), - TR("Remove"), TR("Cancel"), NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT); + TR("Remove"), TR("Cancel"), NULL, B_WIDTH_AS_USUAL, + B_WARNING_ALERT); } if (alert->Go()) break; status_t status = fCurrentType.Delete(); - if (status != B_OK) - fprintf(stderr, TR("Could not remove file type: %s\n"), strerror(status)); + if (status != B_OK) { + fprintf(stderr, TR("Could not remove file type: %s\n"), + strerror(status)); + } break; } @@ -907,7 +840,8 @@ FileTypesWindow::MessageReceived(BMessage* message) { int32 index; if (message->FindInt32("index", &index) == B_OK) { - BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index); + BStringItem* item + = (BStringItem*)fExtensionListView->ItemAt(index); fRemoveExtensionButton->SetEnabled(item != NULL); } break; @@ -920,11 +854,13 @@ FileTypesWindow::MessageReceived(BMessage* message) int32 index; if (message->FindInt32("index", &index) == B_OK) { - BStringItem* item = (BStringItem*)fExtensionListView->ItemAt(index); + BStringItem* item + = (BStringItem*)fExtensionListView->ItemAt(index); if (item == NULL) break; - BWindow* window = new ExtensionWindow(this, fCurrentType, item->Text()); + BWindow* window + = new ExtensionWindow(this, fCurrentType, item->Text()); window->Show(); } break; @@ -958,7 +894,8 @@ FileTypesWindow::MessageReceived(BMessage* message) { // check rule BString parseError; - if (BMimeType::CheckSnifferRule(fRuleControl->Text(), &parseError) != B_OK) { + if (BMimeType::CheckSnifferRule(fRuleControl->Text(), + &parseError) != B_OK) { parseError.Prepend(TR("Recognition rule is not valid:\n\n")); error_alert(parseError.String()); } else @@ -1009,7 +946,8 @@ FileTypesWindow::MessageReceived(BMessage* message) case kMsgSamePreferredAppAs: { BMessage panel(kMsgOpenFilePanel); - panel.AddString("title", TR("Select same preferred application as")); + panel.AddString("title", TR("Select same preferred application " + "as")); panel.AddInt32("message", kMsgSamePreferredAppAsOpened); panel.AddMessenger("target", this); @@ -1026,7 +964,8 @@ FileTypesWindow::MessageReceived(BMessage* message) { int32 index; if (message->FindInt32("index", &index) == B_OK) { - AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index); + AttributeItem* item + = (AttributeItem*)fAttributeListView->ItemAt(index); fRemoveAttributeButton->SetEnabled(item != NULL); } break; @@ -1039,7 +978,8 @@ FileTypesWindow::MessageReceived(BMessage* message) int32 index; if (message->FindInt32("index", &index) == B_OK) { - AttributeItem* item = (AttributeItem*)fAttributeListView->ItemAt(index); + AttributeItem* item + = (AttributeItem*)fAttributeListView->ItemAt(index); if (item == NULL) break; @@ -1075,7 +1015,8 @@ FileTypesWindow::MessageReceived(BMessage* message) }; for (uint32 i = 0; i < - sizeof(kAttributeNames) / sizeof(kAttributeNames[0]); i++) { + sizeof(kAttributeNames) / sizeof(kAttributeNames[0]); + i++) { attributes.RemoveData(kAttributeNames[i], index); } @@ -1104,9 +1045,7 @@ FileTypesWindow::MessageReceived(BMessage* message) // this change could still affect our current type if (which == B_MIME_TYPE_DELETED -#ifdef __HAIKU__ || which == B_SUPPORTED_TYPES_CHANGED -#endif || which == B_PREFERRED_APP_CHANGED) _UpdatePreferredApps(&fCurrentType); } diff --git a/src/preferences/filetypes/FileTypesWindow.h b/src/preferences/filetypes/FileTypesWindow.h index f70121e0c1..8040211dab 100644 --- a/src/preferences/filetypes/FileTypesWindow.h +++ b/src/preferences/filetypes/FileTypesWindow.h @@ -20,9 +20,9 @@ class BTextControl; class AttributeListView; class ExtensionListView; -class TypeIconView; class MimeTypeListView; class StringView; +class TypeIconView; class FileTypesWindow : public BWindow { diff --git a/src/preferences/filetypes/IconView.cpp b/src/preferences/filetypes/IconView.cpp index 8ba031014c..d1f98d2fa1 100644 --- a/src/preferences/filetypes/IconView.cpp +++ b/src/preferences/filetypes/IconView.cpp @@ -7,15 +7,12 @@ #include "IconView.h" #include "MimeTypeListView.h" -#ifdef HAIKU_TARGET_PLATFORM_HAIKU -# include -# include -#endif - #include #include #include #include +#include +#include #include #include #include @@ -23,6 +20,7 @@ #include #include #include +#include #include #include @@ -36,7 +34,6 @@ using namespace std; -#ifdef HAIKU_TARGET_PLATFORM_HAIKU status_t icon_for_type(const BMimeType& type, uint8** _data, size_t* _size, icon_source* _source) @@ -93,7 +90,6 @@ icon_for_type(const BMimeType& type, uint8** _data, size_t* _size, return source != kNoIcon ? B_OK : B_ERROR; } -#endif status_t @@ -182,7 +178,6 @@ Icon::SetTo(const BAppFileInfo& info, const char* type) { Unset(); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU uint8* data; size_t size; if (info.GetIconForType(type, &data, &size) == B_OK) { @@ -190,7 +185,6 @@ Icon::SetTo(const BAppFileInfo& info, const char* type) AdoptData(data, size); return; } -#endif BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8); if (icon && info.GetIconForType(type, icon, B_LARGE_ICON) == B_OK) @@ -224,7 +218,6 @@ Icon::SetTo(const BMimeType& type, icon_source* _source) { Unset(); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU uint8* data; size_t size; if (icon_for_type(type, &data, &size, _source) == B_OK) { @@ -232,7 +225,6 @@ Icon::SetTo(const BMimeType& type, icon_source* _source) AdoptData(data, size); return; } -#endif BBitmap* icon = AllocateBitmap(B_LARGE_ICON, B_CMAP8); if (icon && icon_for_type(type, *icon, B_LARGE_ICON, _source) == B_OK) @@ -257,10 +249,8 @@ Icon::CopyTo(BAppFileInfo& info, const char* type, bool force) const status = info.SetIconForType(type, fLarge, B_LARGE_ICON); if (fMini != NULL || force) status = info.SetIconForType(type, fMini, B_MINI_ICON); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (fData != NULL || force) status = info.SetIconForType(type, fData, fSize); -#endif return status; } @@ -291,10 +281,8 @@ Icon::CopyTo(BMimeType& type, bool force) const status = type.SetIcon(fLarge, B_LARGE_ICON); if (fMini != NULL || force) status = type.SetIcon(fMini, B_MINI_ICON); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (fData != NULL || force) status = type.SetIcon(fData, fSize); -#endif return status; } @@ -316,10 +304,8 @@ Icon::CopyTo(BMessage& message) const if (status == B_OK) status = message.AddMessage("icon/mini", &archive); } -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (status == B_OK && fData != NULL) status = message.AddData("icon", B_VECTOR_ICON_TYPE, fData, fSize); -#endif return B_OK; } @@ -360,7 +346,6 @@ Icon::SetMini(const BBitmap* mini) void Icon::SetData(const uint8* data, size_t size) { -#ifdef HAIKU_TARGET_PLATFORM_HAIKU free(fData); fData = NULL; @@ -372,7 +357,6 @@ Icon::SetData(const uint8* data, size_t size) memcpy(fData, data, size); } } -#endif } @@ -447,10 +431,8 @@ Icon::GetIcon(BBitmap* bitmap) const if (bitmap == NULL) return B_BAD_VALUE; -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (fData != NULL && BIconUtils::GetVectorIcon(fData, fSize, bitmap) == B_OK) return B_OK; -#endif int32 width = bitmap->Bounds().IntegerWidth() + 1; @@ -508,11 +490,7 @@ Icon::AdoptData(uint8* data, size_t size) /*static*/ BBitmap* Icon::AllocateBitmap(int32 size, int32 space) { -#ifdef HAIKU_TARGET_PLATFORM_HAIKU int32 kSpace = B_RGBA32; -#else - int32 kSpace = B_CMAP8; -#endif if (space == -1) space = kSpace; @@ -530,8 +508,8 @@ Icon::AllocateBitmap(int32 size, int32 space) // #pragma mark - -IconView::IconView(BRect rect, const char* name, uint32 resizeMode, uint32 flags) - : BControl(rect, name, NULL, NULL, resizeMode, B_WILL_DRAW | flags), +IconView::IconView(const char* name, uint32 flags) + : BControl(name, NULL, NULL, B_WILL_DRAW | flags), fModificationMessage(NULL), fIconSize(B_LARGE_ICON), fIcon(NULL), @@ -588,9 +566,8 @@ IconView::MessageReceived(BMessage* message) const uint8* data = NULL; ssize_t size = 0; -#ifdef HAIKU_TARGET_PLATFORM_HAIKU - message->FindData("icon", B_VECTOR_ICON_TYPE, (const void**)&data, &size); -#endif + message->FindData("icon", B_VECTOR_ICON_TYPE, (const void**)&data, + &size); BMessage archive; if (message->FindMessage("icon/large", &archive) == B_OK) @@ -672,16 +649,13 @@ IconView::MessageReceived(BMessage* message) if (which == B_MIME_TYPE_DELETED || which == B_PREFERRED_APP_CHANGED -#ifdef __HAIKU__ || which == B_SUPPORTED_TYPES_CHANGED -#endif || which == B_ICON_FOR_TYPE_CHANGED) Update(); } break; } -#ifdef HAIKU_TARGET_PLATFORM_HAIKU case B_ICON_DATA_EDITED: { const uint8* data; @@ -693,7 +667,6 @@ IconView::MessageReceived(BMessage* message) _SetIcon(NULL, NULL, data, size); break; } -#endif default: BControl::MessageReceived(message); @@ -710,7 +683,8 @@ IconView::AcceptsDrag(const BMessage* message) type_code type; int32 count; - if (message->GetInfo("refs", &type, &count) == B_OK && count == 1 && type == B_REF_TYPE) { + if (message->GetInfo("refs", &type, &count) == B_OK && count == 1 + && type == B_REF_TYPE) { // if we're bound to an entry, check that no one drops this to us entry_ref ref; if (fHasRef && message->FindRef("refs", &ref) == B_OK && fRef == ref) @@ -719,11 +693,12 @@ IconView::AcceptsDrag(const BMessage* message) return true; } - if (message->GetInfo("icon/large", &type) == B_OK && type == B_MESSAGE_TYPE -#ifdef HAIKU_TARGET_PLATFORM_HAIKU - || message->GetInfo("icon", &type) == B_OK && type == B_VECTOR_ICON_TYPE -#endif - || message->GetInfo("icon/mini", &type) == B_OK && type == B_MESSAGE_TYPE) + if (message->GetInfo("icon/large", &type) == B_OK + && type == B_MESSAGE_TYPE + || message->GetInfo("icon", &type) == B_OK + && type == B_VECTOR_ICON_TYPE + || message->GetInfo("icon/mini", &type) == B_OK + && type == B_MESSAGE_TYPE) return true; return false; @@ -764,13 +739,10 @@ IconView::Draw(BRect updateRect) SetPenSize(2); BRect rect = BitmapRect(); // TODO: this is an incompatibility between R5 and Haiku and should be fixed! -#ifdef HAIKU_TARGET_PLATFORM_HAIKU +// (Necessary adjustment differs.) rect.left++; rect.top++; -#else - rect.right--; - rect.bottom--; -#endif + StrokeRect(rect); SetPenSize(1); } @@ -788,6 +760,29 @@ IconView::GetPreferredSize(float* _width, float* _height) } +BSize +IconView::MinSize() +{ + float width, height; + GetPreferredSize(&width, &height); + return BSize(width, height); +} + + +BSize +IconView::PreferredSize() +{ + return MinSize(); +} + + +BSize +IconView::MaxSize() +{ + return MinSize(); +} + + void IconView::MouseDown(BPoint where) { @@ -1075,7 +1070,6 @@ IconView::ShowIconHeap(bool show) BResources* resources = be_app->AppResources(); if (resources != NULL) { const void* data = NULL; -#ifdef HAIKU_TARGET_PLATFORM_HAIKU size_t size; data = resources->LoadResource('VICN', "icon heap", &size); if (data != NULL) { @@ -1089,7 +1083,6 @@ IconView::ShowIconHeap(bool show) data = NULL; } } -#endif // HAIKU_TARGET_PLATFORM_HAIKU if (data == NULL) { // no vector icon or failed to get bitmap // try bitmap icon @@ -1119,10 +1112,11 @@ IconView::ShowEmptyFrame(bool show) } -void +status_t IconView::SetTarget(const BMessenger& target) { fTarget = target; + return B_OK; } @@ -1134,7 +1128,7 @@ IconView::SetModificationMessage(BMessage* message) } -void +status_t IconView::Invoke(const BMessage* _message) { if (_message == NULL) @@ -1143,6 +1137,7 @@ IconView::Invoke(const BMessage* _message) BMessage message(*_message); fTarget.SendMessage(&message); } + return B_OK; } @@ -1178,8 +1173,6 @@ IconView::GetMimeType(BMimeType& type) const void IconView::_AddOrEditIcon() { - // this works only in Haiku! (the icon editor is built-in in R5's FileType) -#ifdef HAIKU_TARGET_PLATFORM_HAIKU BMessage message; if (fHasRef && fType.Type() == NULL) { // in ref mode, Icon-O-Matic can change the icon directly, and @@ -1216,7 +1209,6 @@ IconView::_AddOrEditIcon() } be_roster->Launch("application/x-vnd.haiku-icon_o_matic", &message); -#endif } @@ -1232,10 +1224,8 @@ IconView::_SetIcon(BBitmap* large, BBitmap* mini, const uint8* data, size_t size info.SetIconForType(fType.Type(), large, B_LARGE_ICON); if (mini != NULL || force) info.SetIconForType(fType.Type(), mini, B_MINI_ICON); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (data != NULL || force) info.SetIconForType(fType.Type(), data, size); -#endif } // the icon shown will be updated using node monitoring } else if (fHasType) { @@ -1243,10 +1233,8 @@ IconView::_SetIcon(BBitmap* large, BBitmap* mini, const uint8* data, size_t size fType.SetIcon(large, B_LARGE_ICON); if (mini != NULL || force) fType.SetIcon(mini, B_MINI_ICON); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (data != NULL || force) fType.SetIcon(data, size); -#endif // the icon shown will be updated automatically - we're watching // any changes to the MIME database } else if (fIconData != NULL) { @@ -1282,7 +1270,6 @@ IconView::_SetIcon(entry_ref* ref) if (file.InitCheck() != B_OK || info.InitCheck() != B_OK) return; -#ifdef HAIKU_TARGET_PLATFORM_HAIKU // try vector/PNG icon first uint8* data = NULL; size_t size = 0; @@ -1291,7 +1278,6 @@ IconView::_SetIcon(entry_ref* ref) free(data); return; } -#endif // try large/mini icons bool hasMini = false; @@ -1322,26 +1308,19 @@ IconView::_SetIcon(entry_ref* ref) return; BMimeType mimeType(type); -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (icon_for_type(mimeType, &data, &size) != B_OK) { // only try large/mini icons when there is no vector icon -#endif if (large != NULL && icon_for_type(mimeType, *large, B_LARGE_ICON) == B_OK) hasLarge = true; if (mini != NULL && icon_for_type(mimeType, *mini, B_MINI_ICON) == B_OK) hasMini = true; -#ifdef HAIKU_TARGET_PLATFORM_HAIKU } -#endif } -#ifdef HAIKU_TARGET_PLATFORM_HAIKU if (data != NULL) { _SetIcon(NULL, NULL, data, size); free(data); - } else -#endif - if (hasLarge || hasMini) + } else if (hasLarge || hasMini) _SetIcon(large, mini, NULL, 0); delete large; diff --git a/src/preferences/filetypes/IconView.h b/src/preferences/filetypes/IconView.h index c848701a38..f65ab1ced0 100644 --- a/src/preferences/filetypes/IconView.h +++ b/src/preferences/filetypes/IconView.h @@ -50,8 +50,8 @@ class Icon { Icon& operator=(const Icon& source); - void AdoptLarge(BBitmap *large); - void AdoptMini(BBitmap *mini); + void AdoptLarge(BBitmap* large); + void AdoptMini(BBitmap* mini); void AdoptData(uint8* data, size_t size); static BBitmap* AllocateBitmap(int32 size, int32 space = -1); @@ -63,11 +63,11 @@ class Icon { size_t fSize; }; +class BSize; + class IconView : public BControl { public: - IconView(BRect rect, const char* name, - uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_NAVIGABLE); + IconView(const char* name, uint32 flags = B_NAVIGABLE); virtual ~IconView(); virtual void AttachedToWindow(); @@ -76,6 +76,10 @@ class IconView : public BControl { virtual void Draw(BRect updateRect); virtual void GetPreferredSize(float* _width, float* _height); + virtual BSize MaxSize(); + virtual BSize MinSize(); + virtual BSize PreferredSize(); + virtual void MouseDown(BPoint where); virtual void MouseUp(BPoint where); virtual void MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage); @@ -92,9 +96,9 @@ class IconView : public BControl { void SetIconSize(int32 size); void ShowIconHeap(bool show); void ShowEmptyFrame(bool show); - void SetTarget(const BMessenger& target); + status_t SetTarget(const BMessenger& target); void SetModificationMessage(BMessage* message); - void Invoke(const BMessage* message = NULL); + status_t Invoke(const BMessage* message = NULL); ::Icon* Icon(); int32 IconSize() const { return fIconSize; } diff --git a/src/preferences/filetypes/MimeTypeListView.cpp b/src/preferences/filetypes/MimeTypeListView.cpp index 4749db6934..055c86f3f8 100644 --- a/src/preferences/filetypes/MimeTypeListView.cpp +++ b/src/preferences/filetypes/MimeTypeListView.cpp @@ -89,11 +89,7 @@ MimeTypeItem::DrawItem(BView* owner, BRect frame, bool complete) owner->FillRect(rect, B_SOLID_LOW); } -#ifdef HAIKU_TARGET_PLATFORM_HAIKU BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_RGBA32); -#else - BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_CMAP8); -#endif BMimeType mimeType(fType.String()); status_t status = icon_for_type(mimeType, bitmap, B_MINI_ICON); if (status < B_OK) { @@ -267,10 +263,9 @@ MimeTypeItem::CompareLabels(const BListItem* a, const BListItem* b) // #pragma mark - -MimeTypeListView::MimeTypeListView(BRect rect, const char* name, - const char* supertype, bool showIcons, bool applicationMode, - uint32 resizingMode) - : BOutlineListView(rect, name, B_SINGLE_SELECTION_LIST, resizingMode), +MimeTypeListView::MimeTypeListView(const char* name, + const char* supertype, bool showIcons, bool applicationMode) + : BOutlineListView(name, B_SINGLE_SELECTION_LIST), fSupertype(supertype), fShowIcons(showIcons), fApplicationMode(applicationMode) @@ -284,7 +279,8 @@ MimeTypeListView::~MimeTypeListView() void -MimeTypeListView::_CollectSubtypes(const char* supertype, MimeTypeItem* supertypeItem) +MimeTypeListView::_CollectSubtypes(const char* supertype, + MimeTypeItem* supertypeItem) { BMessage types; if (BMimeType::GetInstalledTypes(supertype, &types) != B_OK) @@ -324,7 +320,8 @@ MimeTypeListView::_CollectTypes() const char* supertype; int32 index = 0; - while (superTypes.FindString("super_types", index++, &supertype) == B_OK) { + while (superTypes.FindString("super_types", index++, &supertype) + == B_OK) { MimeTypeItem* supertypeItem = new MimeTypeItem(supertype); AddItem(supertypeItem); @@ -339,10 +336,7 @@ MimeTypeListView::_CollectTypes() void MimeTypeListView::_MakeTypesUnique(MimeTypeItem* underItem) { -#ifndef __HAIKU__ - if (fSupertype.Type() == NULL) -#endif - SortItemsUnder(underItem, underItem != NULL, &MimeTypeItem::Compare); + SortItemsUnder(underItem, underItem != NULL, &MimeTypeItem::Compare); bool lastItemSame = false; MimeTypeItem* last = NULL; @@ -494,18 +488,10 @@ MimeTypeListView::MessageReceived(BMessage* message) BMessage addType(kMsgAddType); addType.AddString("type", type); -#ifdef __HAIKU__ - if (BMessageRunner::StartSending(this, &addType, 200000ULL, 1) != B_OK) - _AddNewType(type); -#else - // TODO: free runner again! - BMessageRunner* runner = new BMessageRunner(this, &addType, - 200000ULL, 1); - if (runner->InitCheck() != B_OK) { - delete runner; + if (BMessageRunner::StartSending(this, &addType, 200000ULL, + 1) != B_OK) { _AddNewType(type); } -#endif break; } case B_MIME_TYPE_DELETED: @@ -520,8 +506,8 @@ MimeTypeListView::MessageReceived(BMessage* message) } case B_PREFERRED_APP_CHANGED: { - // try to add or remove this type (changing the preferred app - // might change visibility in our list) + // try to add or remove this type (changing the preferred + // app might change visibility in our list) _AddNewType(type); // supposed to fall through diff --git a/src/preferences/filetypes/MimeTypeListView.h b/src/preferences/filetypes/MimeTypeListView.h index ab10c60706..9d3f57c4b1 100644 --- a/src/preferences/filetypes/MimeTypeListView.h +++ b/src/preferences/filetypes/MimeTypeListView.h @@ -52,10 +52,9 @@ class MimeTypeItem : public BStringItem { class MimeTypeListView : public BOutlineListView { public: - MimeTypeListView(BRect rect, const char* name, + MimeTypeListView(const char* name, const char* supertype = NULL, bool showIcons = false, - bool applicationMode = false, - uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP); + bool applicationMode = false); virtual ~MimeTypeListView(); void SelectNewType(const char* type); diff --git a/src/preferences/filetypes/NewFileTypeWindow.cpp b/src/preferences/filetypes/NewFileTypeWindow.cpp index 15eae440ef..b45fb73496 100644 --- a/src/preferences/filetypes/NewFileTypeWindow.cpp +++ b/src/preferences/filetypes/NewFileTypeWindow.cpp @@ -10,12 +10,18 @@ #include #include +#include +#include +#include #include +#include #include #include #include #include +#include #include +#include #include #include @@ -33,19 +39,14 @@ const uint32 kMsgNameUpdated = 'nmup'; const uint32 kMsgAddType = 'atyp'; -NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, const char* currentType) - : BWindow(BRect(100, 100, 350, 200), TR("New file type"), B_TITLED_WINDOW, - B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), +NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, + const char* currentType) + : + BWindow(BRect(100, 100, 350, 200), TR("New file type"), B_MODAL_WINDOW, + B_NOT_ZOOMABLE | B_NOT_V_RESIZABLE | B_ASYNCHRONOUS_CONTROLS + | B_AUTO_UPDATE_SIZE_LIMITS ), fTarget(target) { - 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 labelWidth = be_plain_font->StringWidth(TR("Internal name:")) + 2.0f; - - rect.InsetBy(8.0f, 6.0f); fSupertypesMenu = new BPopUpMenu("supertypes"); BMenuItem* item; BMessage types; @@ -67,55 +68,54 @@ NewFileTypeWindow::NewFileTypeWindow(FileTypesWindow* target, const char* curren if (i > 1) fSupertypesMenu->AddSeparatorItem(); } + fSupertypesMenu->AddItem(new BMenuItem(TR("Add new group"), new BMessage(kMsgNewSupertypeChosen))); + BMenuField* typesMenuField = new BMenuField(NULL, fSupertypesMenu); - BMenuField* menuField = new BMenuField(rect, "supertypes", - TR("Group:"), fSupertypesMenu); - menuField->SetDivider(labelWidth); - menuField->SetAlignment(B_ALIGN_RIGHT); - float width, height; - menuField->GetPreferredSize(&width, &height); - menuField->ResizeTo(rect.Width(), height); - topView->AddChild(menuField); + BStringView* typesMenuLabel = new BStringView(NULL, TR("Group:")); + // Create a separate label view, otherwise things don't line up right + typesMenuLabel->SetAlignment(B_ALIGN_LEFT); + typesMenuLabel->SetExplicitAlignment( + BAlignment(B_ALIGN_LEFT, B_ALIGN_USE_FULL_HEIGHT)); - fNameControl = new BTextControl(rect, "internal", TR("Internal name:"), "", - NULL, B_FOLLOW_LEFT_RIGHT); + fNameControl = new BTextControl(TR("Internal name:"), "", NULL); fNameControl->SetModificationMessage(new BMessage(kMsgNameUpdated)); - fNameControl->SetDivider(labelWidth); - fNameControl->SetAlignment(B_ALIGN_RIGHT, B_ALIGN_LEFT); // filter out invalid characters that can't be part of a MIME type name - BTextView* textView = fNameControl->TextView(); + BTextView* nameControlTextView = fNameControl->TextView(); const char* disallowedCharacters = "/<>@,;:\"()[]?="; for (int32 i = 0; disallowedCharacters[i]; i++) { - textView->DisallowChar(disallowedCharacters[i]); + nameControlTextView->DisallowChar(disallowedCharacters[i]); } - fNameControl->GetPreferredSize(&width, &height); - fNameControl->ResizeTo(rect.Width(), height); - fNameControl->MoveTo(8.0f, 12.0f + menuField->Bounds().Height()); - topView->AddChild(fNameControl); + fAddButton = new BButton(TR("Add type"), new BMessage(kMsgAddType)); - fAddButton = new BButton(rect, "add", TR("Add type"), new BMessage(kMsgAddType), - B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - fAddButton->ResizeToPreferred(); - fAddButton->MoveTo(Bounds().Width() - 8.0f - fAddButton->Bounds().Width(), - Bounds().Height() - 8.0f - fAddButton->Bounds().Height()); - fAddButton->SetEnabled(false); - topView->AddChild(fAddButton); + float padding = 3.0f; + // if (be_control_look) + // padding = be_control_look->DefaultItemSpacing(); - BButton* button = new BButton(rect, "cancel", TR("Cancel"), - new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->MoveTo(fAddButton->Frame().left - 10.0f - button->Bounds().Width(), - fAddButton->Frame().top); - topView->AddChild(button); + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGridLayoutBuilder(padding, padding) + .SetInsets(padding, padding, padding, padding) + .Add(typesMenuLabel, 0, 0) + .Add(typesMenuField, 1, 0, 2) + .Add(fNameControl->CreateLabelLayoutItem(), 0, 1) + .Add(fNameControl->CreateTextViewLayoutItem(), 1, 1, 2) + .Add(BSpaceLayoutItem::CreateGlue(), 0, 2) + .Add(new BButton(TR("Cancel"), new BMessage(B_QUIT_REQUESTED)), 1, 2) + .Add(fAddButton, 2, 2) + .SetColumnWeight(0, 3) + ); - ResizeTo(labelWidth * 4.0f + 24.0f, fNameControl->Bounds().Height() - + menuField->Bounds().Height() + fAddButton->Bounds().Height() + 30.0f); - SetSizeLimits(button->Bounds().Width() + fAddButton->Bounds().Width() + 26.0f, - 32767.0f, Frame().Height(), Frame().Height()); + BAlignment fullSize = BAlignment(B_ALIGN_USE_FULL_WIDTH, + B_ALIGN_USE_FULL_HEIGHT); + typesMenuField->MenuBar()->SetExplicitAlignment(fullSize); + fNameControl->TextView()->SetExplicitAlignment(fullSize); + + BLayoutItem* nameControlLabelItem = fNameControl->CreateLabelLayoutItem(); + nameControlLabelItem->SetExplicitMinSize(nameControlLabelItem->MinSize()); + // stops fNameControl's label from truncating under certain conditions fAddButton->MakeDefault(true); fNameControl->MakeFocus(true); @@ -137,12 +137,14 @@ NewFileTypeWindow::MessageReceived(BMessage* message) fAddButton->SetLabel(TR("Add type")); fNameControl->SetLabel(TR("Internal name:")); fNameControl->MakeFocus(true); + InvalidateLayout(true); break; case kMsgNewSupertypeChosen: fAddButton->SetLabel(TR("Add group")); fNameControl->SetLabel(TR("Group name:")); fNameControl->MakeFocus(true); + InvalidateLayout(true); break; case kMsgNameUpdated: @@ -160,7 +162,8 @@ NewFileTypeWindow::MessageReceived(BMessage* message) BMenuItem* item = fSupertypesMenu->FindMarked(); if (item != NULL) { BString type; - if (fSupertypesMenu->IndexOf(item) != fSupertypesMenu->CountItems() - 1) { + if (fSupertypesMenu->IndexOf(item) + != fSupertypesMenu->CountItems() - 1) { // add normal type type = item->Label(); type.Append("/"); @@ -170,7 +173,7 @@ NewFileTypeWindow::MessageReceived(BMessage* message) BMimeType mimeType(type.String()); if (mimeType.IsInstalled()) { - error_alert(TR("This file type already exists.")); + error_alert(TR("This file type already exists")); break; } @@ -201,3 +204,5 @@ NewFileTypeWindow::QuitRequested() fTarget.SendMessage(kMsgNewTypeWindowClosed); return true; } + + diff --git a/src/preferences/filetypes/PreferredAppMenu.cpp b/src/preferences/filetypes/PreferredAppMenu.cpp index c94ba5ac32..424b9af7f8 100644 --- a/src/preferences/filetypes/PreferredAppMenu.cpp +++ b/src/preferences/filetypes/PreferredAppMenu.cpp @@ -9,15 +9,14 @@ #include #include +#include +#include #include #include #include #include #include -#include -#include - #include #include @@ -163,9 +162,11 @@ update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what, || item->Message()->FindString("signature", &signature) != B_OK) continue; - if (preferredFrom == NULL && !strcasecmp(signature, preferred) - || preferredFrom != NULL && !strcasecmp(signature, preferredFrom)) + if ((preferredFrom == NULL && !strcasecmp(signature, preferred)) + || (preferredFrom != NULL + && !strcasecmp(signature, preferredFrom))) { select = item; + } if (last == NULL || strcmp(last->Label(), item->Label())) { if (lastItemSame) @@ -191,8 +192,8 @@ update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what, // We don't select the item earlier, so that the menu field can // pick up the signature as well as label. select->SetMarked(true); - } else if (preferredFrom == NULL && preferred[0] - || preferredFrom && preferredFrom[0]) { + } else if ((preferredFrom == NULL && preferred[0]) + || (preferredFrom != NULL && preferredFrom[0])) { // The preferred application is not an application that support // this file type! BMenuItem* item = create_application_item(preferredFrom @@ -252,9 +253,9 @@ retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType, } if (!preferred[0]) { - error_alert(sameAs ? - TR("Could not retrieve preferred application of this file.") - : TR("Could not retrieve application signature.")); + error_alert(sameAs + ? TR("Could not retrieve preferred application of this file") + : TR("Could not retrieve application signature")); return B_ERROR; } @@ -287,9 +288,9 @@ retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType, "Are you sure you want to set it anyway?"), description[0] ? description : preferred); - BAlert* alert = new BAlert("FileTypes Request", warning, - TR("Set Preferred Application"), "Cancel", NULL, B_WIDTH_AS_USUAL, - B_WARNING_ALERT); + BAlert* alert = new BAlert(TR("FileTypes request"), warning, + TR("Set Preferred Application"), TR("Cancel"), NULL, + B_WIDTH_AS_USUAL, B_WARNING_ALERT); if (alert->Go() == 1) return B_ERROR; } diff --git a/src/preferences/filetypes/PreferredAppMenu.h b/src/preferences/filetypes/PreferredAppMenu.h index 93b76157b0..c15c0c582f 100644 --- a/src/preferences/filetypes/PreferredAppMenu.h +++ b/src/preferences/filetypes/PreferredAppMenu.h @@ -15,7 +15,8 @@ class BString; void update_preferred_app_menu(BMenu* menu, BMimeType* type, uint32 what, const char* preferredFrom = NULL); -status_t retrieve_preferred_app(BMessage* message, bool sameAs, const char* forType, - BString& preferredApp); + +status_t retrieve_preferred_app(BMessage* message, bool sameAs, + const char* forType, BString& preferredApp); #endif // PREFERRED_APP_MENU_H diff --git a/src/preferences/filetypes/StringView.cpp b/src/preferences/filetypes/StringView.cpp index e07d4ad900..c67ed7242a 100644 --- a/src/preferences/filetypes/StringView.cpp +++ b/src/preferences/filetypes/StringView.cpp @@ -4,220 +4,104 @@ */ +#include +#include +#include + #include "StringView.h" -StringView::StringView(BRect frame, const char* name, const char* label, - const char* text, uint32 resizeMask, uint32 flags) - : BView(frame, name, resizeMask, flags), - fLabel(label), - fText(text), - fLabelAlignment(B_ALIGN_RIGHT), - fTextAlignment(B_ALIGN_LEFT), - fEnabled(true) +StringView::StringView(const char* label, const char* text) + : + fView(NULL), + fLabel(new BStringView(NULL, label)), + fLabelItem(NULL), + fText(new BStringView(NULL, text)), + fTextItem(NULL) { - fDivider = StringWidth(label) + 4.0f; -} - - -StringView::~StringView() -{ -} - - -void -StringView::SetAlignment(alignment labelAlignment, alignment textAlignment) -{ - if (labelAlignment == fLabelAlignment && textAlignment == fTextAlignment) - return; - - fLabelAlignment = labelAlignment; - fTextAlignment = textAlignment; - - Invalidate(); -} - - -void -StringView::GetAlignment(alignment* _label, alignment* _text) const -{ - if (_label) - *_label = fLabelAlignment; - if (_text) - *_text = fTextAlignment; -} - - -void -StringView::SetDivider(float divider) -{ - fDivider = divider; - _UpdateText(); - - Invalidate(); -} - - -void -StringView::AttachedToWindow() -{ - if (Parent() != NULL) - SetViewColor(Parent()->ViewColor()); - else - SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - SetLowColor(ViewColor()); - _UpdateText(); -} - - -void -StringView::Draw(BRect updateRect) -{ - BRect rect = Bounds(); - - font_height fontHeight; - GetFontHeight(&fontHeight); - - float y = ceilf(fontHeight.ascent) + 1.0f; - float x; - -#if defined(HAIKU_TARGET_PLATFORM_BEOS) || defined(HAIKU_TARGET_PLATFORM_BONE) - rgb_color textColor = {0, 0, 0, 255}; -#else - rgb_color textColor = ui_color(B_CONTROL_TEXT_COLOR); -#endif - - SetHighColor(IsEnabled() ? textColor - : tint_color(ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT)); - - if (Label()) { - switch (fLabelAlignment) { - case B_ALIGN_RIGHT: - x = Divider() - StringWidth(Label()) - 3.0f; - break; - - case B_ALIGN_CENTER: - x = Divider() - StringWidth(Label()) / 2.0f; - break; - - default: - x = 1.0f; - break; - } - - DrawString(Label(), BPoint(x, y)); - } - - if (fTruncatedText.String() != NULL) { - switch (fTextAlignment) { - case B_ALIGN_RIGHT: - x = rect.Width() - StringWidth(fTruncatedText.String()); - break; - - case B_ALIGN_CENTER: - x = Divider() + (rect.Width() - Divider() - StringWidth(Label())) / 2.0f; - break; - - default: - x = Divider() + 3.0f; - break; - } - - DrawString(fTruncatedText.String(), BPoint(x, y)); - } -} - - -void -StringView::FrameResized(float width, float height) -{ - BString oldTruncated = fTruncatedText; - _UpdateText(); - - if (oldTruncated != fTruncatedText) { - // invalidate text portion only - BRect rect = Bounds(); - rect.left = Divider(); - Invalidate(rect); - } -} - - -void -StringView::ResizeToPreferred() -{ - float width, height; - GetPreferredSize(&width, &height); - - // Resize the width only for B_ALIGN_LEFT (if its large enough already, that is) - if (Bounds().Width() > width - && (fLabelAlignment != B_ALIGN_LEFT || fTextAlignment != B_ALIGN_LEFT)) - width = Bounds().Width(); - - BView::ResizeTo(width, height); -} - - -void -StringView::GetPreferredSize(float* _width, float* _height) -{ - if (!Text() && !Label()) { - BView::GetPreferredSize(_width, _height); - return; - } - - if (_width) - *_width = 7.0f + ceilf(StringWidth(Label()) + StringWidth(Text())); - - if (_height) { - font_height fontHeight; - GetFontHeight(&fontHeight); - *_height = ceilf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 2.0f; - } -} - - -void -StringView::SetEnabled(bool enabled) -{ - if (IsEnabled() == enabled) - return; - - fEnabled = enabled; - Invalidate(); } void StringView::SetLabel(const char* label) { - fLabel = label; - - // invalidate label portion only - BRect rect = Bounds(); - rect.right = Divider(); - Invalidate(rect); + fLabel->SetText(label); } void StringView::SetText(const char* text) { - fText = text; - - _UpdateText(); - - // invalidate text portion only - BRect rect = Bounds(); - rect.left = Divider(); - Invalidate(rect); + fText->SetText(text); } +BLayoutItem* +StringView::GetLabelLayoutItem() +{ + return fLabelItem; +} + + +BView* +StringView::LabelView() +{ return fLabel; } + + +BLayoutItem* +StringView::GetTextLayoutItem() +{ + return fTextItem; +} + + +BView* +StringView::TextView() +{ return fText; } + + void -StringView::_UpdateText() +StringView::SetEnabled(bool enabled) { - fTruncatedText = fText; - TruncateString(&fTruncatedText, B_TRUNCATE_MIDDLE, Bounds().Width() - Divider()); + + rgb_color color; + + if (!enabled) { + color = tint_color( + ui_color(B_PANEL_BACKGROUND_COLOR), B_DISABLED_LABEL_TINT); + } else + color = ui_color(B_CONTROL_TEXT_COLOR); + + fLabel->SetHighColor(color); + fText->SetHighColor(color); + fLabel->Invalidate(); + fText->Invalidate(); } + + +//cast operator BView* +StringView::operator BView*() +{ + if (fView) + return fView; + fView = new BGroupView(B_HORIZONTAL); + BLayout* layout = fView->GroupLayout(); + fLabelItem = layout->AddView(fLabel); + fTextItem = layout->AddView(fText); + return fView; +} + + +const char* +StringView::Label() const +{ + return fLabel->Text(); +} + + +const char* +StringView::Text() const +{ + return fText->Text(); +} + diff --git a/src/preferences/filetypes/StringView.h b/src/preferences/filetypes/StringView.h index f1f2399b63..6ba2158848 100644 --- a/src/preferences/filetypes/StringView.h +++ b/src/preferences/filetypes/StringView.h @@ -6,50 +6,37 @@ #define STRING_VIEW_H -#include -#include +class BLayoutItem; +class BGroupView; +class BStringView; - -class StringView : public BView { +class StringView { public: - StringView(BRect frame, const char* name, const char* label, - const char* text, uint32 resizeMask = B_FOLLOW_LEFT | B_FOLLOW_TOP, - uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS); - virtual ~StringView(); - - virtual void Draw(BRect updateRect); - virtual void AttachedToWindow(); - - virtual void FrameResized(float width, float height); - - virtual void GetPreferredSize(float* _width, float* _height); - virtual void ResizeToPreferred(); + StringView(const char* label, + const char* text); void SetEnabled(bool enabled); - bool IsEnabled() const { return fEnabled; } void SetLabel(const char* label); - const char* Label() const { return fLabel.String(); } - + const char* Label() const; void SetText(const char* text); - const char* Text() const { return fText.String(); } + const char* Text() const; - void SetDivider(float divider); - float Divider() const { return fDivider; } + BLayoutItem* GetLabelLayoutItem(); + BView* LabelView(); + BLayoutItem* GetTextLayoutItem(); + BView* TextView(); - void SetAlignment(alignment labelAlignment, alignment textAlignment); - void GetAlignment(alignment* _label, alignment* _text) const; + operator BView*(); private: - void _UpdateText(); - BString fLabel; - BString fText; - BString fTruncatedText; - float fDivider; - alignment fLabelAlignment; - alignment fTextAlignment; - bool fEnabled; + BGroupView* fView; + BStringView* fLabel; + BLayoutItem* fLabelItem; + BStringView* fText; + BLayoutItem* fTextItem; }; + #endif // STRING_VIEW_H diff --git a/src/preferences/filetypes/TypeListWindow.cpp b/src/preferences/filetypes/TypeListWindow.cpp index aea1f1c8de..336b3480ce 100644 --- a/src/preferences/filetypes/TypeListWindow.cpp +++ b/src/preferences/filetypes/TypeListWindow.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include @@ -16,58 +18,58 @@ #undef TR_CONTEXT -#define TR_CONTEXT "TypeListWindow" +#define TR_CONTEXT "Type List Window" const uint32 kMsgTypeSelected = 'tpsl'; const uint32 kMsgSelected = 'seld'; -TypeListWindow::TypeListWindow(const char* currentType, uint32 what, - BWindow* target) - : BWindow(BRect(100, 100, 360, 440), TR("Choose type"), B_MODAL_WINDOW, - B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS), +TypeListWindow::TypeListWindow(const char* currentType, + uint32 what, BWindow* target) + : + BWindow(BRect(100, 100, 360, 440), TR("Choose type"), B_MODAL_WINDOW, + B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fTarget(target), fWhat(what) { - 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; + //if (be_control_look) + // padding = be_control_look->DefaultItemSpacing(); + // seems too big - fSelectButton = new BButton(rect, "select", TR("Done"), - new BMessage(kMsgSelected), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - fSelectButton->ResizeToPreferred(); - fSelectButton->MoveTo(topView->Bounds().right - 8.0f - - fSelectButton->Bounds().Width(), - topView->Bounds().bottom - 8.0f - fSelectButton->Bounds().Height()); + fSelectButton = new BButton("select", TR("Done"), + new BMessage(kMsgSelected)); fSelectButton->SetEnabled(false); - topView->AddChild(fSelectButton); - BButton* button = new BButton(fSelectButton->Frame(), "cancel", TR("Cancel"), - new BMessage(B_CANCEL), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM); - button->ResizeToPreferred(); - button->MoveBy(-button->Bounds().Width() - 8.0f, 0.0f); - topView->AddChild(button); + BButton* button = new BButton("cancel", TR("Cancel"), + new BMessage(B_CANCEL)); fSelectButton->MakeDefault(true); - rect.bottom = button->Frame().top - 10.0f; - rect.top = 10.0f; - rect.left = 10.0f; - rect.right -= 10.0f + B_V_SCROLL_BAR_WIDTH; - fListView = new MimeTypeListView(rect, "typeview", NULL, true, false, - B_FOLLOW_ALL); + fListView = new MimeTypeListView("typeview", NULL, true, false); fListView->SetSelectionMessage(new BMessage(kMsgTypeSelected)); fListView->SetInvocationMessage(new BMessage(kMsgSelected)); BScrollView* scrollView = new BScrollView("scrollview", fListView, - B_FOLLOW_ALL, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - topView->AddChild(scrollView); + B_FRAME_EVENTS | B_WILL_DRAW, false, true); + + SetLayout(new BGroupLayout(B_VERTICAL)); + AddChild(BGroupLayoutBuilder(B_VERTICAL, padding) + .Add(scrollView) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, padding) + .Add(button) + .Add(fSelectButton) + ) + .SetInsets(padding, padding, padding, padding) + ); + + BAlignment buttonAlignment = + BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_VERTICAL_CENTER); + button->SetExplicitAlignment(buttonAlignment); + fSelectButton->SetExplicitAlignment(buttonAlignment); MoveTo(target->Frame().LeftTop() + BPoint(15.0f, 15.0f)); - SetSizeLimits(button->Bounds().Width() + fSelectButton->Bounds().Width() + 64.0f, 32767.0f, - fSelectButton->Bounds().Height() * 5.0f, 32767.0f); }