Author: aldeck Date: 2010-08-09 01:46:59 +0200 (Mon, 09 Aug 2010) New Revision: 37978 Changeset: http://dev.haiku-os.org/changeset/37978 Modified: haiku/trunk/src/kits/tracker/SettingsViews.cpp haiku/trunk/src/kits/tracker/SettingsViews.h haiku/trunk/src/kits/tracker/TrackerSettingsWindow.cpp haiku/trunk/src/kits/tracker/TrackerSettingsWindow.h Log: * Apply patch from Takashi Murai: use layouting for Tracker settings window/views. Slight modifications to the patch: Put back passing the view names (eventhough it seem useless atm). One or two small indenting issues. Implemented your todo (listview width adapts to the longest item). Thanks a lot. Modified: haiku/trunk/src/kits/tracker/SettingsViews.cpp =================================================================== --- haiku/trunk/src/kits/tracker/SettingsViews.cpp 2010-08-08 17:29:32 UTC (rev 37977) +++ haiku/trunk/src/kits/tracker/SettingsViews.cpp 2010-08-08 23:46:59 UTC (rev 37978) @@ -44,6 +44,8 @@ #include <Box.h> #include <Button.h> #include <Catalog.h> +#include <ControlLook.h> +#include <GroupLayoutBuilder.h> #include <Locale.h> #include <MenuField.h> #include <ColorControl.h> @@ -83,8 +85,9 @@ #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "libtracker" -SettingsView::SettingsView(BRect rect, const char *name) - : BView(rect, name, B_FOLLOW_ALL, 0) +SettingsView::SettingsView(const char* name) + : + BGroupView(name) { } @@ -165,59 +168,45 @@ // #pragma mark - -DesktopSettingsView::DesktopSettingsView(BRect rect) - : SettingsView(rect, "DesktopSettingsView") +DesktopSettingsView::DesktopSettingsView() + : + SettingsView("DesktopSettingsView") { - rect.OffsetTo(B_ORIGIN); - fShowDisksIconRadioButton = new BRadioButton(rect, "", + fShowDisksIconRadioButton = new BRadioButton("", B_TRANSLATE("Show Disks icon"), new BMessage(kShowDisksIconChanged)); - fShowDisksIconRadioButton->ResizeToPreferred(); - AddChild(fShowDisksIconRadioButton); - const float itemSpacing = fShowDisksIconRadioButton->Bounds().Height() + kItemExtraSpacing; - rect.OffsetBy(0, itemSpacing); - - fMountVolumesOntoDesktopRadioButton = new BRadioButton(rect, "", + fMountVolumesOntoDesktopRadioButton = new BRadioButton("", B_TRANSLATE("Show volumes on Desktop"), new BMessage(kVolumesOnDesktopChanged)); - AddChild(fMountVolumesOntoDesktopRadioButton); - fMountVolumesOntoDesktopRadioButton->ResizeToPreferred(); - rect.OffsetBy(20, itemSpacing); - - fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox(rect, "", + fMountSharedVolumesOntoDesktopCheckBox = new BCheckBox("", B_TRANSLATE("Show shared volumes on Desktop"), new BMessage(kVolumesOnDesktopChanged)); - AddChild(fMountSharedVolumesOntoDesktopCheckBox); - fMountSharedVolumesOntoDesktopCheckBox->ResizeToPreferred(); - rect.OffsetBy(-20, itemSpacing); - - rect = Bounds(); - rect.top = rect.bottom; - fMountButton = new BButton(rect, "", + fMountButton = new BButton("", B_TRANSLATE("Mount settings" B_UTF8_ELLIPSIS), - new BMessage(kRunAutomounterSettings), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - fMountButton->ResizeToPreferred(); - fMountButton->MoveBy(0, -fMountButton->Bounds().Height()); - AddChild(fMountButton); + new BMessage(kRunAutomounterSettings)); - fMountButton->SetTarget(be_app); -} + const float spacing = be_control_look->DefaultItemSpacing(); + BGroupLayoutBuilder(this) + .AddGroup(B_VERTICAL) + .Add(fShowDisksIconRadioButton) + .Add(fMountVolumesOntoDesktopRadioButton) + .AddGroup(B_VERTICAL) + .Add(fMountSharedVolumesOntoDesktopCheckBox) + .SetInsets(20, 0, 0, 0) + .End() + .AddGlue() + .AddGroup(B_HORIZONTAL) + .Add(fMountButton) + .AddGlue() + .End() + .End() + .SetInsets(spacing, spacing, spacing, spacing); -void -DesktopSettingsView::GetPreferredSize(float *_width, float *_height) -{ - if (_width != NULL) { - *_width = fMountSharedVolumesOntoDesktopCheckBox->Frame().right; - } - - if (_height != NULL) { - *_height = fMountSharedVolumesOntoDesktopCheckBox->Frame().bottom + 8 - + fMountButton->Bounds().Height(); - } + fMountButton->SetTarget(be_app); } @@ -414,67 +403,54 @@ // #pragma mark - -WindowsSettingsView::WindowsSettingsView(BRect rect) - : SettingsView(rect, "WindowsSettingsView") +WindowsSettingsView::WindowsSettingsView() + : + SettingsView("WindowsSettingsView") { - rect.OffsetTo(B_ORIGIN); - fShowFullPathInTitleBarCheckBox = new BCheckBox(rect, "", + fShowFullPathInTitleBarCheckBox = new BCheckBox("", B_TRANSLATE("Show folder location in title tab"), new BMessage(kWindowsShowFullPathChanged)); - fShowFullPathInTitleBarCheckBox->ResizeToPreferred(); - AddChild(fShowFullPathInTitleBarCheckBox); - const float itemSpacing = fShowFullPathInTitleBarCheckBox->Bounds().Height() + kItemExtraSpacing; - rect.OffsetBy(0, itemSpacing); - - fSingleWindowBrowseCheckBox = new BCheckBox(rect, "", + fSingleWindowBrowseCheckBox = new BCheckBox("", B_TRANSLATE("Single window navigation"), new BMessage(kSingleWindowBrowseChanged)); - fSingleWindowBrowseCheckBox->ResizeToPreferred(); - AddChild(fSingleWindowBrowseCheckBox); - rect.OffsetBy(20, itemSpacing); - - fShowNavigatorCheckBox = new BCheckBox(rect, "", + fShowNavigatorCheckBox = new BCheckBox("", B_TRANSLATE("Show navigator"), new BMessage(kShowNavigatorChanged)); - fShowNavigatorCheckBox->ResizeToPreferred(); - AddChild(fShowNavigatorCheckBox); - rect.OffsetBy(-20, itemSpacing); - - fOutlineSelectionCheckBox = new BCheckBox(rect, "", + fOutlineSelectionCheckBox = new BCheckBox("", B_TRANSLATE("Outline selection rectangle only"), new BMessage(kTransparentSelectionChanged)); - fOutlineSelectionCheckBox->ResizeToPreferred(); - AddChild(fOutlineSelectionCheckBox); - rect.OffsetBy(0, itemSpacing); - - fSortFolderNamesFirstCheckBox = new BCheckBox(rect, "", + fSortFolderNamesFirstCheckBox = new BCheckBox("", B_TRANSLATE("List folders first"), new BMessage(kSortFolderNamesFirstChanged)); - fSortFolderNamesFirstCheckBox->ResizeToPreferred(); - AddChild(fSortFolderNamesFirstCheckBox); - rect.OffsetBy(0, itemSpacing); - - fTypeAheadFilteringCheckBox = new BCheckBox(rect, "", + fTypeAheadFilteringCheckBox = new BCheckBox("", B_TRANSLATE("Enable type-ahead filtering"), new BMessage(kTypeAheadFilteringChanged)); - fTypeAheadFilteringCheckBox->ResizeToPreferred(); - AddChild(fTypeAheadFilteringCheckBox); -} + const float spacing = be_control_look->DefaultItemSpacing(); -void -WindowsSettingsView::GetPreferredSize(float *_width, float *_height) -{ - if (_width != NULL) - *_width = fOutlineSelectionCheckBox->Frame().right; - - if (_height != NULL) - *_height = fSortFolderNamesFirstCheckBox->Frame().bottom; + BGroupLayoutBuilder(this) + .AddGroup(B_VERTICAL) + .AddGroup(B_VERTICAL) + .Add(fShowFullPathInTitleBarCheckBox) + .Add(fSingleWindowBrowseCheckBox) + .End() + .AddGroup(B_VERTICAL) + .Add(fShowNavigatorCheckBox) + .SetInsets(20, 0, 0, 0) + .End() + .AddGroup(B_VERTICAL) + .Add(fOutlineSelectionCheckBox) + .Add(fSortFolderNamesFirstCheckBox) + .Add(fTypeAheadFilteringCheckBox) + .End() + .AddGlue() + .End() + .SetInsets(spacing, spacing, spacing, spacing); } @@ -719,23 +695,18 @@ // #pragma mark - -SpaceBarSettingsView::SpaceBarSettingsView(BRect rect) - : SettingsView(rect, "SpaceBarSettingsView") +SpaceBarSettingsView::SpaceBarSettingsView() + : + SettingsView("SpaceBarSettingsView") { - rect.OffsetTo(B_ORIGIN); - fSpaceBarShowCheckBox = new BCheckBox(rect, "", + fSpaceBarShowCheckBox = new BCheckBox("", B_TRANSLATE("Show space bars on volumes"), new BMessage(kUpdateVolumeSpaceBar)); - fSpaceBarShowCheckBox->ResizeToPreferred(); - AddChild(fSpaceBarShowCheckBox); - rect = fSpaceBarShowCheckBox->Frame(); - rect.OffsetBy(0, fSpaceBarShowCheckBox->Bounds().Height() + kItemExtraSpacing); - - BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING); + BPopUpMenu* menu = new BPopUpMenu(B_EMPTY_STRING); menu->SetFont(be_plain_font); - BMenuItem *item; + BMenuItem* item; menu->AddItem(item = new BMenuItem( B_TRANSLATE("Used space color"), new BMessage(kSpaceBarSwitchColor))); @@ -748,44 +719,30 @@ B_TRANSLATE("Warning space color"), new BMessage(kSpaceBarSwitchColor))); - BBox *box = new BBox(rect); - box->SetLabel(fColorPicker = new BMenuField(rect, NULL, NULL, menu)); - AddChild(box); + BBox* box = new BBox("box"); + box->SetLabel(fColorPicker = new BMenuField("menu", NULL, menu)); fColorControl = new BColorControl(BPoint(8, fColorPicker->Bounds().Height() + 8 + kItemExtraSpacing), B_CELLS_16x16, 1, "SpaceColorControl", new BMessage(kSpaceBarColorChanged)); fColorControl->SetValue(TrackerSettings().UsedSpaceColor()); - fColorControl->ResizeToPreferred(); box->AddChild(fColorControl); - box->ResizeTo(fColorControl->Bounds().Width() + 16, - fColorControl->Frame().bottom + 8); -} + const float spacing = be_control_look->DefaultItemSpacing(); + BGroupLayoutBuilder(this) + .AddGroup(B_VERTICAL) + .Add(fSpaceBarShowCheckBox) + .Add(box) + .AddGlue() + .End() + .SetInsets(spacing, spacing, spacing, spacing); -SpaceBarSettingsView::~SpaceBarSettingsView() -{ } -void -SpaceBarSettingsView::GetPreferredSize(float *_width, float *_height) +SpaceBarSettingsView::~SpaceBarSettingsView() { - BView* view = fColorControl->Parent(); - if (view == NULL) - BView::GetPreferredSize(_width, _height); - - if (_width != NULL) { - float width = fSpaceBarShowCheckBox->Bounds().Width(); - if (view->Bounds().Width() > width) - width = view->Bounds().Width(); - - *_width = width; - } - - if (_height != NULL) - *_height = view->Frame().bottom; } @@ -976,40 +933,28 @@ // #pragma mark - -TrashSettingsView::TrashSettingsView(BRect rect) - : SettingsView(rect, "TrashSettingsView") +TrashSettingsView::TrashSettingsView() + : + SettingsView("TrashSettingsView") { - rect.OffsetTo(B_ORIGIN); - fDontMoveFilesToTrashCheckBox = new BCheckBox(rect, "", + fDontMoveFilesToTrashCheckBox = new BCheckBox("", B_TRANSLATE("Don't move files to Trash"), new BMessage(kDontMoveFilesToTrashChanged)); - fDontMoveFilesToTrashCheckBox->ResizeToPreferred(); - AddChild(fDontMoveFilesToTrashCheckBox); - rect = fDontMoveFilesToTrashCheckBox->Frame(); - rect.OffsetBy(0, fDontMoveFilesToTrashCheckBox->Bounds().Height() + kItemExtraSpacing); - - fAskBeforeDeleteFileCheckBox = new BCheckBox(rect, "", + fAskBeforeDeleteFileCheckBox = new BCheckBox("", B_TRANSLATE("Ask before delete"), new BMessage(kAskBeforeDeleteFileChanged)); - fAskBeforeDeleteFileCheckBox->ResizeToPreferred(); - AddChild(fAskBeforeDeleteFileCheckBox); -} + const float spacing = be_control_look->DefaultItemSpacing(); -void -TrashSettingsView::GetPreferredSize(float *_width, float *_height) -{ - if (_width != NULL) { - float width = fDontMoveFilesToTrashCheckBox->Bounds().Width(); - if (width < fAskBeforeDeleteFileCheckBox->Bounds().Width()) - width = fAskBeforeDeleteFileCheckBox->Bounds().Width(); + BGroupLayoutBuilder(this) + .AddGroup(B_VERTICAL) + .Add(fDontMoveFilesToTrashCheckBox) + .Add(fAskBeforeDeleteFileCheckBox) + .AddGlue() + .End() + .SetInsets(spacing, spacing, spacing, spacing); - *_width = width; - } - - if (_height != NULL) - *_height = fAskBeforeDeleteFileCheckBox->Frame().bottom; } Modified: haiku/trunk/src/kits/tracker/SettingsViews.h =================================================================== --- haiku/trunk/src/kits/tracker/SettingsViews.h 2010-08-08 17:29:32 UTC (rev 37977) +++ haiku/trunk/src/kits/tracker/SettingsViews.h 2010-08-08 23:46:59 UTC (rev 37978) @@ -36,6 +36,7 @@ #define _SETTINGS_VIEWS #include <CheckBox.h> +#include <GroupView.h> #include <RadioButton.h> #include <TextControl.h> #include <ColorControl.h> @@ -51,9 +52,9 @@ namespace BPrivate { -class SettingsView : public BView { +class SettingsView : public BGroupView { public: - SettingsView(BRect frame, const char *name); + SettingsView(const char* name); virtual ~SettingsView(); virtual void SetDefaults(); @@ -64,16 +65,15 @@ virtual bool IsRevertable() const; protected: - typedef BView _inherited; + typedef BGroupView _inherited; }; class DesktopSettingsView : public SettingsView { public: - DesktopSettingsView(BRect frame); + DesktopSettingsView(); virtual void MessageReceived(BMessage *message); virtual void AttachedToWindow(); - virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); virtual bool IsDefaultable() const; @@ -102,11 +102,10 @@ class WindowsSettingsView : public SettingsView { public: - WindowsSettingsView(BRect frame); + WindowsSettingsView(); virtual void MessageReceived(BMessage *message); virtual void AttachedToWindow(); - virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); virtual bool IsDefaultable() const; @@ -134,15 +133,13 @@ typedef SettingsView _inherited; }; - class SpaceBarSettingsView : public SettingsView { public: - SpaceBarSettingsView(BRect frame); + SpaceBarSettingsView(); virtual ~SpaceBarSettingsView(); virtual void MessageReceived(BMessage *message); virtual void AttachedToWindow(); - virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); virtual bool IsDefaultable() const; @@ -167,11 +164,10 @@ class TrashSettingsView : public SettingsView { public: - TrashSettingsView(BRect frame); + TrashSettingsView(); virtual void MessageReceived(BMessage *message); virtual void AttachedToWindow(); - virtual void GetPreferredSize(float *_width, float *_height); virtual void SetDefaults(); virtual bool IsDefaultable() const; Modified: haiku/trunk/src/kits/tracker/TrackerSettingsWindow.cpp =================================================================== --- haiku/trunk/src/kits/tracker/TrackerSettingsWindow.cpp 2010-08-08 17:29:32 UTC (rev 37977) +++ haiku/trunk/src/kits/tracker/TrackerSettingsWindow.cpp 2010-08-08 23:46:59 UTC (rev 37978) @@ -33,13 +33,14 @@ */ #include <Catalog.h> +#include <ControlLook.h> +#include <LayoutBuilder.h> #include <Locale.h> #include "SettingsViews.h" #include "TrackerSettings.h" #include "TrackerSettingsWindow.h" -//#include <CheckBox.h> #include <ScrollView.h> @@ -73,77 +74,55 @@ BWindow(BRect(80, 80, 450, 350), B_TRANSLATE("Tracker preferences"), B_TITLED_WINDOW, B_NOT_MINIMIZABLE | B_NOT_RESIZABLE | B_NO_WORKSPACE_ACTIVATION | B_NOT_ANCHORED_ON_ACTIVATE - | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) + | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS) { - BRect rect = Bounds(); - BView *topView = new BView(rect, "Background", B_FOLLOW_ALL, 0); - topView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - AddChild(topView); + fSettingsTypeListView = new BListView("List View", B_SINGLE_SELECTION_LIST); - rect.InsetBy(10, 10); - rect.right = be_plain_font->StringWidth(B_TRANSLATE("Volume Icons")) - + rect.left + (float)B_V_SCROLL_BAR_WIDTH + 40.0f; - fSettingsTypeListView = new BListView(rect, "List View", B_SINGLE_SELECTION_LIST, - B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM); - BScrollView* scrollView = new BScrollView("scrollview", fSettingsTypeListView, - B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - topView->AddChild(scrollView); + BScrollView* scrollView = new BScrollView("scrollview", + fSettingsTypeListView, B_FRAME_EVENTS | B_WILL_DRAW, false, true); - rect = scrollView->Frame(); - rect.left = rect.right + 10; - rect.top = rect.bottom; - fDefaultsButton = new BButton(rect, "Defaults", B_TRANSLATE("Defaults"), - new BMessage(kDefaultsButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); - fDefaultsButton->ResizeToPreferred(); + fDefaultsButton = new BButton("Defaults", B_TRANSLATE("Defaults"), + new BMessage(kDefaultsButtonPressed)); fDefaultsButton->SetEnabled(false); - fDefaultsButton->MoveBy(0, -fDefaultsButton->Bounds().Height()); - rect = fDefaultsButton->Frame(); - rect.left = rect.right + 10; - fRevertButton = new BButton(rect, "Revert", B_TRANSLATE("Revert"), - new BMessage(kRevertButtonPressed), B_FOLLOW_LEFT | B_FOLLOW_BOTTOM); + fRevertButton = new BButton("Revert", B_TRANSLATE("Revert"), + new BMessage(kRevertButtonPressed)); fRevertButton->SetEnabled(false); - fRevertButton->ResizeToPreferred(); - rect = scrollView->Frame(); - rect.left = rect.right + 10; - rect.right = Bounds().right - 10; - rect.bottom = fDefaultsButton->Frame().top - 10; - fSettingsContainerBox = new BBox(rect, NULL, B_FOLLOW_ALL); - topView->AddChild(fSettingsContainerBox); - topView->AddChild(fDefaultsButton); - topView->AddChild(fRevertButton); + fSettingsContainerBox = new BBox("SettingsContainerBox"); + + const float spacing = be_control_look->DefaultItemSpacing(); - rect = _SettingsFrame(); + BLayoutBuilder::Group<>(this) + .AddGroup(B_HORIZONTAL, spacing) + .Add(scrollView) + .AddGroup(B_VERTICAL, spacing) + .Add(fSettingsContainerBox) + .AddGroup(B_HORIZONTAL, spacing) + .Add(fDefaultsButton) + .Add(fRevertButton) + .AddGlue() + .End() + .End() + .SetInsets(spacing, spacing, spacing, spacing) + .End(); fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Desktop"), - new DesktopSettingsView(rect))); + new DesktopSettingsView())); fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Windows"), - new WindowsSettingsView(rect))); + new WindowsSettingsView())); fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Trash"), - new TrashSettingsView(rect))); + new TrashSettingsView())); fSettingsTypeListView->AddItem(new SettingsItem(B_TRANSLATE("Volume icons"), - new SpaceBarSettingsView(rect))); + new SpaceBarSettingsView())); - // compute preferred view size + // constraint the listview width so that the longest item fits + float width = 0; + fSettingsTypeListView->GetPreferredSize(&width, NULL); + width += B_V_SCROLL_BAR_WIDTH; + fSettingsTypeListView->SetExplicitMinSize(BSize(width, 0)); + fSettingsTypeListView->SetExplicitMaxSize(BSize(width, B_SIZE_UNLIMITED)); - float minWidth = 0, minHeight = 0; - - for (int32 i = 0; i < fSettingsTypeListView->CountItems(); i++) { - SettingsView* view = ((SettingsItem *)fSettingsTypeListView->ItemAt(i))->View(); - - float width, height; - view->GetPreferredSize(&width, &height); - - if (minWidth < width) - minWidth = width; - if (minHeight < height) - minHeight = height; - } - - ResizeBy(max_c(minWidth - rect.Width(), 0), max_c(minHeight - rect.Height(), 0)); - // make sure window is large enough to contain all views - fSettingsTypeListView->SetSelectionMessage(new BMessage(kSettingsViewChanged)); fSettingsTypeListView->Select(0); } @@ -230,19 +209,6 @@ } -BRect -TrackerSettingsWindow::_SettingsFrame() -{ - font_height fontHeight; - be_bold_font->GetHeight(&fontHeight); - - BRect rect = fSettingsContainerBox->Bounds().InsetByCopy(8, 8); - rect.top += ceilf(fontHeight.ascent + fontHeight.descent); - - return rect; -} - - void TrackerSettingsWindow::_HandleChangedContents() { @@ -322,10 +288,6 @@ view->Hide(); fSettingsContainerBox->AddChild(view); - // Resize view after it has been attached to the window, so that - // it's resizing modes are respected - BRect rect = _SettingsFrame(); - view->ResizeTo(rect.Width(), rect.Height()); view->Show(); } } Modified: haiku/trunk/src/kits/tracker/TrackerSettingsWindow.h =================================================================== --- haiku/trunk/src/kits/tracker/TrackerSettingsWindow.h 2010-08-08 17:29:32 UTC (rev 37977) +++ haiku/trunk/src/kits/tracker/TrackerSettingsWindow.h 2010-08-08 23:46:59 UTC (rev 37978) @@ -57,7 +57,6 @@ private: SettingsView *_ViewAt(int32 i); - BRect _SettingsFrame(); void _HandleChangedContents(); void _HandlePressedDefaultsButton();