DriveSetup: Implement optimal zoom for main window

* Fixes #6265 and #8672.

- GCI 2013
This commit is contained in:
Freeman Lou
2013-12-01 22:54:36 +01:00
committed by Siarzhuk Zharski
parent abc7fddf07
commit 491bbe7797
4 changed files with 78 additions and 8 deletions
+57 -6
View File
@@ -35,12 +35,14 @@
#include <PartitioningInfo.h> #include <PartitioningInfo.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <ScrollBar.h>
#include <Volume.h> #include <Volume.h>
#include <VolumeRoster.h> #include <VolumeRoster.h>
#include <tracker_private.h> #include <tracker_private.h>
#include "ChangeParametersPanel.h" #include "ChangeParametersPanel.h"
#include "ColumnListView.h"
#include "CreateParametersPanel.h" #include "CreateParametersPanel.h"
#include "DiskView.h" #include "DiskView.h"
#include "InitParametersPanel.h" #include "InitParametersPanel.h"
@@ -199,12 +201,12 @@ private:
MainWindow::MainWindow() MainWindow::MainWindow()
: :
BWindow(BRect(50, 50, 600, 500), B_TRANSLATE_SYSTEM_NAME("DriveSetup"), BWindow(BRect(50, 50, 600, 500), B_TRANSLATE_SYSTEM_NAME("DriveSetup"),
B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE), B_DOCUMENT_WINDOW, B_ASYNCHRONOUS_CONTROLS),
fCurrentDisk(NULL), fCurrentDisk(NULL),
fCurrentPartitionID(-1), fCurrentPartitionID(-1),
fSpaceIDMap() fSpaceIDMap()
{ {
BMenuBar* menuBar = new BMenuBar(Bounds(), "root menu"); fMenuBar = new BMenuBar(Bounds(), "root menu");
// create all the menu items // create all the menu items
fWipeMenuItem = new BMenuItem(B_TRANSLATE("Wipe (not implemented)"), fWipeMenuItem = new BMenuItem(B_TRANSLATE("Wipe (not implemented)"),
@@ -245,7 +247,7 @@ MainWindow::MainWindow()
// fDiskMenu->AddItem(fSurfaceTestMenuItem); // fDiskMenu->AddItem(fSurfaceTestMenuItem);
fDiskMenu->AddItem(fRescanMenuItem); fDiskMenu->AddItem(fRescanMenuItem);
menuBar->AddItem(fDiskMenu); fMenuBar->AddItem(fDiskMenu);
// Parition menu // Parition menu
fPartitionMenu = new BMenu(B_TRANSLATE("Partition")); fPartitionMenu = new BMenu(B_TRANSLATE("Partition"));
@@ -265,9 +267,9 @@ MainWindow::MainWindow()
fPartitionMenu->AddSeparatorItem(); fPartitionMenu->AddSeparatorItem();
fPartitionMenu->AddItem(fMountAllMenuItem); fPartitionMenu->AddItem(fMountAllMenuItem);
menuBar->AddItem(fPartitionMenu); fMenuBar->AddItem(fPartitionMenu);
AddChild(menuBar); AddChild(fMenuBar);
// Partition / Drives context menu // Partition / Drives context menu
fContextMenu = new BPopUpMenu("Partition"); fContextMenu = new BPopUpMenu("Partition");
@@ -295,7 +297,7 @@ MainWindow::MainWindow()
// add DiskView // add DiskView
BRect r(Bounds()); BRect r(Bounds());
r.top = menuBar->Frame().bottom + 1; r.top = fMenuBar->Frame().bottom + 1;
r.bottom = floorf(r.top + r.Height() * 0.33); r.bottom = floorf(r.top + r.Height() * 0.33);
fDiskView = new DiskView(r, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, fDiskView = new DiskView(r, B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP,
fSpaceIDMap); fSpaceIDMap);
@@ -427,6 +429,10 @@ MainWindow::MessageReceived(BMessage* message)
break; break;
} }
case MSG_UPDATE_ZOOM_LIMITS:
_UpdateWindowZoomLimits();
break;
default: default:
BWindow::MessageReceived(message); BWindow::MessageReceived(message);
break; break;
@@ -540,6 +546,8 @@ MainWindow::_ScanDrives()
} else { } else {
_UpdateMenus(NULL, -1, -1); _UpdateMenus(NULL, -1, -1);
} }
PostMessage(MSG_UPDATE_ZOOM_LIMITS);
} }
@@ -1358,3 +1366,46 @@ MainWindow::_ChangeParameters(BDiskDevice* disk, partition_id selectedPartition)
_ScanDrives(); _ScanDrives();
fDiskView->ForceUpdate(); fDiskView->ForceUpdate();
} }
float
MainWindow::_ColumnListViewHeight(BColumnListView* list, BRow* currentRow)
{
float height = 0;
int32 rows = list->CountRows(currentRow);
for (int32 i = 0; i < rows; i++) {
BRow* row = list->RowAt(i, currentRow);
height += row->Height() + 1;
if (row->IsExpanded() && list->CountRows(row) > 0)
height += _ColumnListViewHeight(list, row);
}
return height;
}
void
MainWindow::_UpdateWindowZoomLimits()
{
float maxHeight = 0;
int32 numColumns = fListView->CountColumns();
BRow* parentRow = NULL;
BColumn* column = NULL;
maxHeight += _ColumnListViewHeight(fListView, NULL);
float maxWidth = fListView->LatchWidth();
for (int32 i = 0; i < numColumns; i++) {
column = fListView->ColumnAt(i);
maxWidth += column->Width();
}
parentRow = fListView->RowAt(0, NULL);
maxHeight += B_H_SCROLL_BAR_HEIGHT;
maxHeight += 1.5 * parentRow->Height(); // the label row
maxHeight += fDiskView->Bounds().Height();
maxHeight += fMenuBar->Bounds().Height();
maxWidth += 1.5 * B_V_SCROLL_BAR_WIDTH; // scroll bar & borders
SetZoomLimits(maxWidth, maxHeight);
}
+11 -2
View File
@@ -17,16 +17,20 @@
#include "Support.h" #include "Support.h"
class BColumnListView;
class BDiskDevice; class BDiskDevice;
class BPartition;
class BMenu; class BMenu;
class BMenuBar;
class BMenuItem; class BMenuItem;
class BPartition;
class BRow;
class DiskView; class DiskView;
class PartitionListView; class PartitionListView;
enum { enum {
MSG_SELECTED_PARTITION_ID = 'spid' MSG_SELECTED_PARTITION_ID = 'spid',
MSG_UPDATE_ZOOM_LIMITS = 'uzls'
}; };
@@ -74,6 +78,9 @@ private:
partition_id selectedPartition); partition_id selectedPartition);
void _ChangeParameters(BDiskDevice* disk, void _ChangeParameters(BDiskDevice* disk,
partition_id selectedPartition); partition_id selectedPartition);
float _ColumnListViewHeight(BColumnListView* list,
BRow* currentRow);
void _UpdateWindowZoomLimits();
private: private:
BDiskDeviceRoster fDiskDeviceRoster; BDiskDeviceRoster fDiskDeviceRoster;
@@ -91,6 +98,8 @@ private:
BMenu* fPartitionMenu; BMenu* fPartitionMenu;
BMenu* fFormatMenu; BMenu* fFormatMenu;
BMenuBar* fMenuBar;
BMenuItem* fWipeMenuItem; BMenuItem* fWipeMenuItem;
BMenuItem* fEjectMenuItem; BMenuItem* fEjectMenuItem;
BMenuItem* fSurfaceTestMenuItem; BMenuItem* fSurfaceTestMenuItem;
+9
View File
@@ -20,6 +20,7 @@
#include <driver_settings.h> #include <driver_settings.h>
#include "Support.h" #include "Support.h"
#include "MainWindow.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
@@ -384,6 +385,14 @@ PartitionListView::InitiateDrag(BPoint rowPoint, bool wasSelected)
} }
void
PartitionListView::ExpandOrCollapse(BRow* row, bool expand)
{
BColumnListView::ExpandOrCollapse(row, expand);
Window()->PostMessage(MSG_UPDATE_ZOOM_LIMITS);
}
PartitionListRow* PartitionListRow*
PartitionListView::FindRow(partition_id id, PartitionListRow* parent) PartitionListView::FindRow(partition_id id, PartitionListRow* parent)
{ {
+1
View File
@@ -97,6 +97,7 @@ public:
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual bool InitiateDrag(BPoint rowPoint, bool wasSelected); virtual bool InitiateDrag(BPoint rowPoint, bool wasSelected);
virtual void ExpandOrCollapse(BRow* row, bool expand);
PartitionListRow* FindRow(partition_id id, PartitionListRow* FindRow(partition_id id,
PartitionListRow* parent = NULL); PartitionListRow* parent = NULL);