From a206dee38ea6adfa82f4cfeae22fe748deaf0477 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 2 Feb 2013 00:53:30 +0100 Subject: [PATCH] DriveSetup: improved default window size. * The default width will no longer make the parameters and partition type columns visible. * Fixed default size of those two columns -- I did not notice that the column state was being restored before, and thought it would just be another oddity of BColumnListView :-) * Since MainWindow maintains its size pretty much itself, the constructor no longer gets a BRect. * The window will now also be resized vertically to make space for all the partitions (only affects first launch without settings file). * Also made the window a bit higher by default. --- src/apps/drivesetup/DriveSetup.cpp | 4 +-- src/apps/drivesetup/MainWindow.cpp | 35 +++++++++++++++++---------- src/apps/drivesetup/MainWindow.h | 2 +- src/apps/drivesetup/PartitionList.cpp | 15 ++++++++++-- src/apps/drivesetup/PartitionList.h | 2 ++ 5 files changed, 40 insertions(+), 18 deletions(-) diff --git a/src/apps/drivesetup/DriveSetup.cpp b/src/apps/drivesetup/DriveSetup.cpp index bff334f172..e3220c1ece 100644 --- a/src/apps/drivesetup/DriveSetup.cpp +++ b/src/apps/drivesetup/DriveSetup.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 Haiku Inc. All rights reserved. + * Copyright 2002-2013 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -36,7 +36,7 @@ DriveSetup::~DriveSetup() void DriveSetup::ReadyToRun() { - fWindow = new MainWindow(BRect(50, 50, 600, 450)); + fWindow = new MainWindow(); if (_RestoreSettings() != B_OK) fWindow->ApplyDefaultSettings(); fWindow->Show(); diff --git a/src/apps/drivesetup/MainWindow.cpp b/src/apps/drivesetup/MainWindow.cpp index 2cd67d7d82..6660cd512a 100644 --- a/src/apps/drivesetup/MainWindow.cpp +++ b/src/apps/drivesetup/MainWindow.cpp @@ -3,11 +3,11 @@ * Distributed under the terms of the MIT license. * * Authors: - * Erik Jaesler * Ithamar R. Adema - * Ingo Weinhold * Stephan Aßmus * Axel Dörfler, axeld@pinc-software.de. + * Erik Jaesler + * Ingo Weinhold */ @@ -193,10 +193,10 @@ enum { // #pragma mark - -MainWindow::MainWindow(BRect frame) +MainWindow::MainWindow() : - BWindow(frame, B_TRANSLATE_SYSTEM_NAME("DriveSetup"), B_DOCUMENT_WINDOW, - B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE), + BWindow(BRect(50, 50, 600, 500), B_TRANSLATE_SYSTEM_NAME("DriveSetup"), + B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE), fCurrentDisk(NULL), fCurrentPartitionID(-1), fSpaceIDMap() @@ -440,17 +440,26 @@ MainWindow::ApplyDefaultSettings() fListView->ResizeAllColumnsToPreferred(); // Adjust window size for convenience - float enlargeBy = fListView->PreferredSize().width + BScreen screen(this); + float windowWidth = Frame().Width(); + float windowHeight = Frame().Height(); + + float enlargeWidthBy = fListView->PreferredSize().width - fListView->Bounds().Width(); - if (enlargeBy > 0.0f) { - BScreen screen(this); - float windowWidth = Frame().Width() + enlargeBy; - if (windowWidth > screen.Frame().Width() - 20.0f) - windowWidth = screen.Frame().Width() - 20.0f; + float enlargeHeightBy = fListView->PreferredSize().height + - fListView->Bounds().Height(); - ResizeTo(windowWidth, Frame().Height()); - } + if (enlargeWidthBy > 0.0f) + windowWidth += enlargeWidthBy; + if (enlargeHeightBy > 0.0f) + windowHeight += enlargeHeightBy; + if (windowWidth > screen.Frame().Width() - 20.0f) + windowWidth = screen.Frame().Width() - 20.0f; + if (windowHeight > screen.Frame().Height() - 20.0f) + windowHeight = screen.Frame().Height() - 20.0f; + + ResizeTo(windowWidth, windowHeight); CenterOnScreen(); Unlock(); diff --git a/src/apps/drivesetup/MainWindow.h b/src/apps/drivesetup/MainWindow.h index 048ac27a03..26c7df420b 100644 --- a/src/apps/drivesetup/MainWindow.h +++ b/src/apps/drivesetup/MainWindow.h @@ -31,7 +31,7 @@ enum { class MainWindow : public BWindow { public: - MainWindow(BRect frame); + MainWindow(); virtual ~MainWindow(); // BWindow interface diff --git a/src/apps/drivesetup/PartitionList.cpp b/src/apps/drivesetup/PartitionList.cpp index 378e289f68..098b2d3f37 100644 --- a/src/apps/drivesetup/PartitionList.cpp +++ b/src/apps/drivesetup/PartitionList.cpp @@ -341,9 +341,9 @@ PartitionListView::PartitionListView(const BRect& frame, uint32 resizeMode) B_TRUNCATE_MIDDLE), kMountedAtColumn); AddColumn(new PartitionColumn(B_TRANSLATE("Size"), 100, 50, 500, B_TRUNCATE_END, B_ALIGN_RIGHT), kSizeColumn); - AddColumn(new PartitionColumn(B_TRANSLATE("Parameters"), 200, 50, 500, + AddColumn(new PartitionColumn(B_TRANSLATE("Parameters"), 100, 50, 500, B_TRUNCATE_END), kParametersColumn); - AddColumn(new PartitionColumn(B_TRANSLATE("Partition type"), 100, 50, 500, + AddColumn(new PartitionColumn(B_TRANSLATE("Partition type"), 200, 50, 500, B_TRUNCATE_END), kPartitionTypeColumn); SetSortingEnabled(false); @@ -466,6 +466,17 @@ PartitionListView::AddSpace(partition_id parentID, partition_id id, } +BSize +PartitionListView::PreferredSize() +{ + // Remove default size for parameters + partition type column + BSize size = BColumnListView::PreferredSize(); + size.width -= ColumnAt(kParametersColumn)->Width() + + ColumnAt(kPartitionTypeColumn)->Width(); + return size; +} + + int32 PartitionListView::_InsertIndexForOffset(PartitionListRow* parent, off_t offset) const diff --git a/src/apps/drivesetup/PartitionList.h b/src/apps/drivesetup/PartitionList.h index 8ed7952025..acc0374b50 100644 --- a/src/apps/drivesetup/PartitionList.h +++ b/src/apps/drivesetup/PartitionList.h @@ -104,6 +104,8 @@ public: PartitionListRow* AddSpace(partition_id parent, partition_id id, off_t offset, off_t size); + virtual BSize PreferredSize(); + private: int32 _InsertIndexForOffset(PartitionListRow* parent, off_t offset) const;