* Another work in progress of converting the BootManager to use the layout API;

most pages do now, albeit it's not perfect yet due to issues with BTextView,
  and BScrollView that make them very inconvenient to use with the layout API.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40126 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2011-01-05 20:05:09 +00:00
parent 23281fb2c1
commit 197f59b07d
12 changed files with 186 additions and 365 deletions
+27 -27
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -224,15 +224,15 @@ WizardPageView*
BootManagerController::CreatePage(int32 state, WizardView* wizard)
{
WizardPageView* page = NULL;
BRect frame(0, 0, 300, 300);
BRect frame(0, 0, 300, 250);
switch (state) {
case kStateEntry:
page = new EntryPage(&fSettings, frame, "entry");
page = new EntryPage(&fSettings, "entry");
wizard->SetPreviousButtonHidden(true);
break;
case kStateErrorEntry:
page = _CreateErrorEntryPage(frame);
page = _CreateErrorEntryPage();
wizard->SetPreviousButtonHidden(true);
wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Done", "Button"));
break;
@@ -241,21 +241,21 @@ BootManagerController::CreatePage(int32 state, WizardView* wizard)
wizard->SetPreviousButtonHidden(false);
break;
case kStateMBRSaved:
page = _CreateMBRSavedPage(frame);
page = _CreateMBRSavedPage();
break;
case kStatePartitions:
page = new PartitionsPage(&fSettings, frame, "partitions");
page = new PartitionsPage(&fSettings, "partitions");
wizard->SetPreviousButtonHidden(false);
break;
case kStateDefaultPartitions:
page = new DefaultPartitionPage(&fSettings, frame, "default");
break;
case kStateInstallSummary:
page = _CreateInstallSummaryPage(frame);
page = _CreateInstallSummaryPage();
wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Next", "Button"));
break;
case kStateInstalled:
page = _CreateInstalledPage(frame);
page = _CreateInstalledPage();
wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Done", "Button"));
break;
case kStateUninstall:
@@ -265,7 +265,7 @@ BootManagerController::CreatePage(int32 state, WizardView* wizard)
break;
case kStateUninstalled:
// TODO prevent overwriting MBR after clicking "Previous"
page = _CreateUninstalledPage(frame);
page = _CreateUninstalledPage();
wizard->SetNextButtonLabel(B_TRANSLATE_COMMENT("Done", "Button"));
break;
}
@@ -275,7 +275,7 @@ BootManagerController::CreatePage(int32 state, WizardView* wizard)
WizardPageView*
BootManagerController::_CreateErrorEntryPage(BRect frame)
BootManagerController::_CreateErrorEntryPage()
{
BString description;
@@ -293,7 +293,7 @@ BootManagerController::_CreateErrorEntryPage(BRect frame)
"table!");
}
return new DescriptionPage(frame, "errorEntry", description.String(), true);
return new DescriptionPage("errorEntry", description.String(), true);
}
@@ -305,7 +305,7 @@ BootManagerController::_CreateSaveMBRPage(BRect frame)
fSettings.FindString("disk", &disk);
description << B_TRANSLATE_COMMENT("Backup Master Boot Record", "Title")
<< "\n\n" << B_TRANSLATE("The Master Boot Record (MBR) of the boot "
<< "\n" << B_TRANSLATE("The Master Boot Record (MBR) of the boot "
"device:\n"
"\t%s\n"
"will now be saved to disk. Please select a file to "
@@ -322,7 +322,7 @@ BootManagerController::_CreateSaveMBRPage(BRect frame)
WizardPageView*
BootManagerController::_CreateMBRSavedPage(BRect frame)
BootManagerController::_CreateMBRSavedPage()
{
BString description;
BString file;
@@ -330,29 +330,29 @@ BootManagerController::_CreateMBRSavedPage(BRect frame)
if (fSaveMBRStatus == B_OK) {
description << B_TRANSLATE_COMMENT("Old Master Boot Record saved",
"Title") << "\n\n"
"Title") << "\n"
<< B_TRANSLATE("The old Master Boot Record was successfully "
"saved to %s.") << "\n";
} else {
description << B_TRANSLATE_COMMENT("Old Master Boot Record Saved "
"failure", "Title") << "\n\n"
"failure", "Title") << "\n"
<< B_TRANSLATE("The old Master Boot Record could not be saved "
"to %s") << "\n";
}
description.ReplaceFirst("%s", file);
return new DescriptionPage(frame, "summary", description.String(), true);
return new DescriptionPage("summary", description.String(), true);
}
WizardPageView*
BootManagerController::_CreateInstallSummaryPage(BRect frame)
BootManagerController::_CreateInstallSummaryPage()
{
BString description;
BString disk;
fSettings.FindString("disk", &disk);
description << B_TRANSLATE_COMMENT("Summary", "Title") << "\n\n"
description << B_TRANSLATE_COMMENT("Summary", "Title") << "\n"
<< B_TRANSLATE("About to write the following boot menu to the boot "
"disk (%s). Please verify the information below before continuing.")
<< "\n\n";
@@ -377,29 +377,29 @@ BootManagerController::_CreateInstallSummaryPage(BRect frame)
description << name << "\t(" << path << ")\n";
}
return new DescriptionPage(frame, "summary", description.String(), true);
return new DescriptionPage("summary", description.String(), true);
}
WizardPageView*
BootManagerController::_CreateInstalledPage(BRect frame)
BootManagerController::_CreateInstalledPage()
{
BString description;
if (fWriteBootMenuStatus == B_OK) {
description << B_TRANSLATE_COMMENT("Installation of boot menu "
"completed", "Title") << "\n\n"
"completed", "Title") << "\n"
<< B_TRANSLATE("The boot manager has been successfully installed "
"on your system.");
} else {
description << B_TRANSLATE_COMMENT("Installation of boot menu failed",
"Title") << "\n\n"
"Title") << "\n"
<< B_TRANSLATE("An error occurred writing the boot menu. "
"The Master Boot Record might be destroyed, "
"you should restore the MBR now!");
}
return new DescriptionPage(frame, "done", description, true);
return new DescriptionPage("done", description, true);
}
@@ -419,7 +419,7 @@ BootManagerController::_CreateUninstallPage(BRect frame)
WizardPageView*
BootManagerController::_CreateUninstalledPage(BRect frame)
BootManagerController::_CreateUninstalledPage()
{
BString description;
BString disk;
@@ -429,16 +429,16 @@ BootManagerController::_CreateUninstalledPage(BRect frame)
if (fRestoreMBRStatus == B_OK) {
description << B_TRANSLATE_COMMENT("Uninstallation of boot menu "
"completed", "Title") << "\n\n"
"completed", "Title") << "\n"
<< B_TRANSLATE("The Master Boot Record of the boot device "
"(%DISK) has been successfully restored from %FILE.");
description.ReplaceFirst("%DISK", disk);
description.ReplaceFirst("%FILE", file);
} else {
description << B_TRANSLATE_COMMENT("Uninstallation of boot menu "
"failed", "Title") << "\n\n"
"failed", "Title") << "\n"
<< B_TRANSLATE("The Master Boot Record could not be restored!");
}
return new DescriptionPage(frame, "summary", description.String(), true);
return new DescriptionPage("summary", description.String(), true);
}
+6 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -62,13 +62,13 @@ private:
bool _SaveMBR();
bool _RestoreMBR();
WizardPageView* _CreateErrorEntryPage(BRect frame);
WizardPageView* _CreateErrorEntryPage();
WizardPageView* _CreateSaveMBRPage(BRect frame);
WizardPageView* _CreateMBRSavedPage(BRect frame);
WizardPageView* _CreateInstallSummaryPage(BRect frame);
WizardPageView* _CreateInstalledPage(BRect frame);
WizardPageView* _CreateMBRSavedPage();
WizardPageView* _CreateInstallSummaryPage();
WizardPageView* _CreateInstalledPage();
WizardPageView* _CreateUninstallPage(BRect frame);
WizardPageView* _CreateUninstalledPage(BRect frame);
WizardPageView* _CreateUninstalledPage();
BMessage fSettings;
BootDrive* fBootDrive;
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -164,14 +164,13 @@ DefaultPartitionPage::_BuildUI()
BRect rect(Bounds());
BString text;
text <<
B_TRANSLATE_COMMENT("Default Partition", "Title") << "\n\n" <<
B_TRANSLATE("Please specify a default partition and a timeout.\n"
"The boot menu will load the default partition after "
"the timeout unless you select another partition. You "
"can also have the boot menu wait indefinitely for you "
"to select a partition.\n"
"Keep the 'ALT' key pressed to disable the timeout at boot time.");
text << B_TRANSLATE_COMMENT("Default Partition", "Title") << "\n"
<< B_TRANSLATE("Please specify a default partition and a timeout.\n"
"The boot menu will load the default partition after "
"the timeout unless you select another partition. You "
"can also have the boot menu wait indefinitely for you "
"to select a partition.\n"
"Keep the 'ALT' key pressed to disable the timeout at boot time.");
fDescription = CreateDescription(rect, "description", text);
MakeHeading(fDescription);
+10 -26
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -11,15 +11,15 @@
#include <string.h>
#include <LayoutBuilder.h>
#include <RadioButton.h>
#include <TextView.h>
DescriptionPage::DescriptionPage(BRect frame, const char* name,
DescriptionPage::DescriptionPage(const char* name,
const char* description, bool hasHeading)
:
WizardPageView(NULL, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
WizardPageView(NULL, name)
{
_BuildUI(description, hasHeading);
}
@@ -30,32 +30,16 @@ DescriptionPage::~DescriptionPage()
}
void
DescriptionPage::FrameResized(float width, float height)
{
WizardPageView::FrameResized(width, height);
_Layout();
}
void
DescriptionPage::_BuildUI(const char* description, bool hasHeading)
{
BRect rect(Bounds());
fDescription = CreateDescription(rect, "description", description);
fDescription = CreateDescription("description", description);
if (hasHeading)
MakeHeading(fDescription);
fDescription->SetTabWidth(85);
AddChild(fDescription);
fDescription->SetTabWidth(120);
_Layout();
SetLayout(new BGroupLayout(B_VERTICAL));
BLayoutBuilder::Group<>((BGroupLayout*)GetLayout())
.Add(fDescription);
}
void
DescriptionPage::_Layout()
{
LayoutDescriptionVertically(fDescription);
}
+3 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -16,19 +16,16 @@ class BTextView;
class DescriptionPage : public WizardPageView {
public:
DescriptionPage(BRect frame, const char* name,
DescriptionPage(const char* name,
const char* description, bool hasHeading);
virtual ~DescriptionPage();
virtual void FrameResized(float width, float height);
private:
void _BuildUI(const char* description,
bool hasHeading);
void _Layout();
private:
BTextView* fDescription;
BTextView* fDescription;
};
+38 -68
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -12,7 +12,7 @@
#include <string.h>
#include <Catalog.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include <RadioButton.h>
#include <TextView.h>
@@ -21,10 +21,9 @@
#define B_TRANSLATE_CONTEXT "EntryPage"
EntryPage::EntryPage(BMessage* settings, BRect frame, const char* name)
EntryPage::EntryPage(BMessage* settings, const char* name)
:
WizardPageView(settings, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
WizardPageView(settings, name)
{
_BuildUI();
}
@@ -35,86 +34,57 @@ EntryPage::~EntryPage()
}
void
EntryPage::FrameResized(float width, float height)
{
WizardPageView::FrameResized(width, height);
_Layout();
}
void
EntryPage::PageCompleted()
{
fSettings->ReplaceBool("install", fInstall->Value() != 0);
fSettings->ReplaceBool("install", fInstallButton->Value() != 0);
}
void
EntryPage::_BuildUI()
{
BRect rect(Bounds());
fInstall = new BRadioButton(rect, "install",
"",
new BMessage('null'));
AddChild(fInstall);
fInstall->ResizeToPreferred();
BRect textRect(rect);
textRect.left = fInstall->Frame().right
+ be_control_look->DefaultItemSpacing();
fInstallButton = new BRadioButton("install", NULL, NULL);
BString text;
text <<
B_TRANSLATE_COMMENT("Install boot menu", "Title") << "\n\n" <<
B_TRANSLATE("Choose this option to install a boot menu, "
"allowing you to select which operating "
"system to boot when you turn on your "
"computer.") << "\n";
fInstallText = CreateDescription(textRect, "installText", text);
text << B_TRANSLATE_COMMENT("Install boot menu", "Title") << "\n"
<< B_TRANSLATE("Choose this option to install a boot menu, "
"allowing you to select which operating "
"system to boot when you turn on your "
"computer.") << "\n";
fInstallText = CreateDescription("installText", text);
MakeHeading(fInstallText);
AddChild(fInstallText);
fUninstall = new BRadioButton(rect, "uninstall",
"",
new BMessage('null'));
AddChild(fUninstall);
fUninstall->ResizeToPreferred();
fUninstallButton = new BRadioButton("uninstall", NULL, NULL);
text.Truncate(0);
text <<
B_TRANSLATE_COMMENT("Uninstall boot menu", "Title") << "\n\n" <<
B_TRANSLATE("Choose this option to remove the boot menu "
"previously installed by this program.\n");
fUninstallText = CreateDescription(textRect, "uninstallText", text);
text << B_TRANSLATE_COMMENT("Uninstall boot menu", "Title") << "\n"
<< B_TRANSLATE("Choose this option to remove the boot menu "
"previously installed by this program.\n");
fUninstallText = CreateDescription("uninstallText", text);
MakeHeading(fUninstallText);
AddChild(fUninstallText);
bool install;
fSettings->FindBool("install", &install);
SetLayout(new BGroupLayout(B_VERTICAL));
if (install)
fInstall->SetValue(1);
BLayoutBuilder::Group<>((BGroupLayout*)GetLayout())
.AddGroup(B_HORIZONTAL, 0)
.AddGroup(B_VERTICAL, 0, 0)
.Add(fInstallButton)
.AddGlue()
.End()
.Add(fInstallText, 1)
.End()
.AddGroup(B_HORIZONTAL, 0)
.AddGroup(B_VERTICAL, 0, 0)
.Add(fUninstallButton)
.AddGlue()
.End()
.Add(fUninstallText)
.End()
.AddGlue();
if (fSettings->FindBool("install"))
fInstallButton->SetValue(1);
else
fUninstall->SetValue(1);
_Layout();
fUninstallButton->SetValue(1);
}
void
EntryPage::_Layout()
{
LayoutDescriptionVertically(fInstallText);
float left = fUninstall->Frame().left;
float top = fInstallText->Frame().bottom;
fUninstall->MoveTo(left, top);
left = fUninstallText->Frame().left;
fUninstallText->MoveTo(left, top);
LayoutDescriptionVertically(fUninstallText);
}
+4 -8
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -18,22 +18,18 @@ class BTextView;
class EntryPage : public WizardPageView {
public:
EntryPage(BMessage* settings, BRect frame,
const char* name);
EntryPage(BMessage* settings, const char* name);
virtual ~EntryPage();
virtual void FrameResized(float width, float height);
virtual void PageCompleted();
private:
void _BuildUI();
void _Layout();
private:
BRadioButton* fInstall;
BRadioButton* fInstallButton;
BTextView* fInstallText;
BRadioButton* fUninstall;
BRadioButton* fUninstallButton;
BTextView* fUninstallText;
};
+52 -199
View File
@@ -1,8 +1,9 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, <[email protected]>
* Michael Pfeiffer, [email protected]
* Ingo Weinhold <[email protected]>
*/
@@ -16,12 +17,16 @@
#include <Catalog.h>
#include <CheckBox.h>
#include <ControlLook.h>
#include <LayoutBuilder.h>
#include <RadioButton.h>
#include <ScrollView.h>
#include <SeparatorView.h>
#include <StringView.h>
#include <TextControl.h>
#include <TextView.h>
#include <StringForSize.h>
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "PartitionsPage"
@@ -31,11 +36,9 @@ const uint32 kMessageShow = 'show';
const uint32 kMessageName = 'name';
PartitionsPage::PartitionsPage(BMessage* settings, BRect frame,
const char* name)
PartitionsPage::PartitionsPage(BMessage* settings, const char* name)
:
WizardPageView(settings, frame, name, B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE)
WizardPageView(settings, name)
{
_BuildUI();
}
@@ -74,7 +77,8 @@ PartitionsPage::PageCompleted()
partition.ReplaceBool("show", control->Value() == 1);
} else if (kMessageName == message->what &&
dynamic_cast<BTextControl*>(control) != NULL) {
partition.ReplaceString("name", ((BTextControl*)control)->Text());
partition.ReplaceString("name",
((BTextControl*)control)->Text());
}
fSettings->ReplaceMessage("partition", index, &partition);
@@ -83,129 +87,49 @@ PartitionsPage::PageCompleted()
}
void
PartitionsPage::FrameResized(float width, float height)
{
WizardPageView::FrameResized(width, height);
_Layout();
}
void
PartitionsPage::_BuildUI()
{
const float kTextDistance = be_control_look->DefaultItemSpacing();
BRect rect(Bounds());
BString text;
text << B_TRANSLATE_COMMENT("Partitions", "Title") << "\n\n"
text << B_TRANSLATE_COMMENT("Partitions", "Title") << "\n"
<< B_TRANSLATE("The following partitions were detected. Please "
"check the box next to the partitions to be included "
"in the boot menu. You can also set the names of the "
"partitions as you would like them to appear in the "
"boot menu.");
fDescription = CreateDescription(rect, "description", text);
fDescription = CreateDescription("description", text);
MakeHeading(fDescription);
AddChild(fDescription);
LayoutDescriptionVertically(fDescription);
rect.left = fDescription->Frame().left + 1;
rect.top = fDescription->Frame().bottom + kTextDistance;
rect.right -= B_V_SCROLL_BAR_WIDTH;
rect.bottom -= B_H_SCROLL_BAR_HEIGHT + 3;
fPartitions = new BView(rect, "partitions", B_FOLLOW_ALL, B_WILL_DRAW);
fPartitionsScrollView = new BScrollView("scrollView", fPartitions,
B_FOLLOW_ALL, 0, true, true);
fPartitionsScrollView->SetViewColor(ViewColor());
AddChild(fPartitionsScrollView);
fPartitions = new BGridView("partitions", 0,
be_control_look->DefaultItemSpacing() / 3);
BLayoutBuilder::Grid<>(fPartitions)
.SetInsets(B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING,
B_USE_DEFAULT_SPACING, B_USE_DEFAULT_SPACING)
.SetColumnWeight(0, 0)
.SetColumnWeight(1, 1)
.SetColumnWeight(2, 0.5)
.SetColumnWeight(3, 0.5);
_FillPartitionsView(fPartitions);
_Layout();
}
BScrollView* scrollView = new BScrollView("scrollView", fPartitions, 0,
false, true);
SetLayout(new BGroupLayout(B_VERTICAL));
void
PartitionsPage::_Layout()
{
LayoutDescriptionVertically(fDescription);
const float kTextDistance = be_control_look->DefaultItemSpacing();
float left = fPartitionsScrollView->Frame().left;
float top = fDescription->Frame().bottom + kTextDistance;
fPartitionsScrollView->MoveTo(left, top);
float width = fPartitionsScrollView->Frame().Width();
float height = Bounds().bottom - top;
fPartitionsScrollView->ResizeTo(width, height);
// update scroll bar range and proportion
BScrollBar* scrollbar = fPartitionsScrollView->ScrollBar(B_HORIZONTAL);
float viewWidth = fPartitions->Bounds().IntegerWidth();
float max = fPartitionsWidth - viewWidth;
if (max < 0)
max = 0;
scrollbar->SetRange(0, max);
float proportion;
if (fPartitionsWidth <= viewWidth)
proportion = 1.0;
else
proportion = viewWidth / fPartitionsWidth;
scrollbar->SetProportion(proportion);
scrollbar = fPartitionsScrollView->ScrollBar(B_VERTICAL);
float viewHeight = fPartitions->Bounds().IntegerHeight();
max = fPartitionsHeight - viewHeight;
if (max < 0)
max = 0;
scrollbar->SetRange(0, max);
if (fPartitionsHeight <= viewHeight)
proportion = 1.0;
else
proportion = viewHeight / fPartitionsHeight;
scrollbar->SetProportion(proportion);
BLayoutBuilder::Group<>((BGroupLayout*)GetLayout())
.Add(fDescription)
.Add(scrollView);
}
void
PartitionsPage::_FillPartitionsView(BView* view)
{
const int32 inset = 1;
font_height fontHeight;
be_plain_font->GetHeight(&fontHeight);
int32 textControlHeight;
{
BTextControl control(BRect(0, 0, 100, 100), "", "", "", NULL);
control.ResizeToPreferred();
textControlHeight = control.Bounds().IntegerHeight();
}
const int32 textHeight = (int32)(fontHeight.ascent + fontHeight.descent);
const int32 height = (int32)(2*inset
+ max_c(textControlHeight, textHeight));
const int32 kDistance = (int32)(ceil(be_plain_font->StringWidth("x")));
// show | name | type | size | path
int32 showWidth = 0;
int32 nameWidth = 0;
int32 typeWidth = 0;
int32 sizeWidth = 0;
int32 pathWidth = 0;
_ComputeColumnWidths(showWidth, nameWidth, typeWidth, sizeWidth, pathWidth);
int32 totalWidth = showWidth + nameWidth + typeWidth + sizeWidth
+ pathWidth + 2 * inset + 4 * kDistance;
int32 rowNumber = 0;
BRect frame(view->Bounds());
frame.bottom = frame.top + height;
frame.right = frame.left + 65000;
BMessage message;
for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK;
i++, rowNumber++) {
@@ -221,123 +145,52 @@ PartitionsPage::_FillPartitionsView(BView* view)
message.FindString("path", &path);
message.FindInt64("size", &size);
// create row for partition data
BView* row = new BView(frame, "row", B_FOLLOW_TOP | B_FOLLOW_LEFT, 0);
view->AddChild(row);
frame.OffsetBy(0, height + 1);
// check box
BRect rect(row->Bounds());
rect.InsetBy(inset, inset);
rect.right = rect.left + showWidth;
BCheckBox* checkBox = new BCheckBox(rect, "show", "",
BCheckBox* checkBox = new BCheckBox("show", "",
_CreateControlMessage(kMessageShow, i));
if (show)
checkBox->SetValue(1);
// center vertically
checkBox->ResizeToPreferred();
const int32 showHeight = checkBox->Bounds().IntegerHeight();
if (showHeight < height)
checkBox->MoveTo(inset, (int)((height - showHeight + 1) / 2));
row->AddChild(checkBox);
rect.OffsetBy(showWidth + kDistance, 0);
// name
rect.right = rect.left + nameWidth;
BTextControl* nameControl = new BTextControl(rect, "name", "",
BTextControl* nameControl = new BTextControl("name", "",
name.String(), _CreateControlMessage(kMessageName, i));
nameControl->SetDivider(0);
row->AddChild(nameControl);
rect.OffsetBy(nameWidth + kDistance, 0);
// type
rect.right = rect.left + typeWidth;
BStringView* typeView = new BStringView(rect, "type", type.String());
row->AddChild(typeView);
rect.OffsetBy(typeWidth + kDistance, 0);
// size
BString sizeText;
_CreateSizeText(size, &sizeText);
rect.right = rect.left + sizeWidth;
BStringView* sizeView = new BStringView(rect, "type",
sizeText.String());
sizeView->SetAlignment(B_ALIGN_RIGHT);
row->AddChild(sizeView);
rect.OffsetBy(sizeWidth + kDistance, 0);
sizeText << ", " << type.String();
BStringView* typeView = new BStringView("type", sizeText.String());
typeView->SetExplicitAlignment(
BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));
// path
rect.right = rect.left + pathWidth;
BStringView* pathView = new BStringView(rect, "path", path.String());
row->AddChild(pathView);
}
BStringView* pathView = new BStringView("path", path.String());
pathView->SetExplicitAlignment(
BAlignment(B_ALIGN_LEFT, B_ALIGN_VERTICAL_UNSET));
fPartitionsWidth = totalWidth;
fPartitionsHeight = frame.top;
}
if (rowNumber > 0) {
BLayoutBuilder::Grid<>((BGridLayout*)view->GetLayout())
.Add(new BSeparatorView(B_HORIZONTAL), 0, rowNumber, 4, 1)
.SetRowWeight(rowNumber, 0);
rowNumber++;
}
void
PartitionsPage::_ComputeColumnWidths(int32& showWidth, int32& nameWidth,
int32& typeWidth, int32& sizeWidth, int32& pathWidth)
{
BCheckBox checkBox(BRect(0, 0, 100, 100), "show", "", new BMessage());
checkBox.ResizeToPreferred();
showWidth = checkBox.Bounds().IntegerWidth();
// reserve space for about 16 characters
nameWidth = (int32)ceil(be_plain_font->StringWidth("oooooooooooooooo"));
const int32 kStringViewInsets = 2;
BMessage message;
for (int32 i = 0; fSettings->FindMessage("partition", i, &message) == B_OK;
i++) {
// get partition data
BString type;
BString path;
int64 size;
message.FindString("type", &type);
message.FindString("path", &path);
message.FindInt64("size", &size);
BString sizeText;
_CreateSizeText(size, &sizeText);
int32 width = (int32)ceil(be_plain_font->StringWidth(type.String()))
+ kStringViewInsets;
if (typeWidth < width)
typeWidth = width;
width = (int32)ceil(be_plain_font->StringWidth(path.String()))
+ kStringViewInsets;
if (pathWidth < width)
pathWidth = width;
width = (int32)ceil(be_plain_font->StringWidth(sizeText.String()))
+ kStringViewInsets;
if (sizeWidth < width)
sizeWidth = width;
BLayoutBuilder::Grid<>((BGridLayout*)view->GetLayout())
.Add(checkBox, 0, rowNumber, 1, 2)
.Add(nameControl, 1, rowNumber, 1, 2)
.Add(BSpaceLayoutItem::CreateHorizontalStrut(10), 2, rowNumber)
.Add(typeView, 3, rowNumber)
.Add(pathView, 3, ++rowNumber)
.SetRowWeight(rowNumber, 1);
}
}
void
PartitionsPage::_CreateSizeText(int64 _size, BString* text)
PartitionsPage::_CreateSizeText(int64 size, BString* text)
{
const char* suffixes[] = {
"", "K", "M", "G", "T", NULL
};
double size = _size;
int index = 0;
while (size > 1024 && suffixes[index + 1]) {
size /= 1024;
index++;
}
char buffer[128];
snprintf(buffer, sizeof(buffer), "%.2f%s", size, suffixes[index]);
*text = buffer;
char buffer[256];
*text = string_for_size(size, buffer, sizeof(buffer));
}
+4 -12
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -12,37 +12,29 @@
#include "WizardPageView.h"
class BGridView;
class BTextView;
class BScrollView;
class PartitionsPage : public WizardPageView {
public:
PartitionsPage(BMessage* settings, BRect frame,
PartitionsPage(BMessage* settings,
const char* name);
virtual ~PartitionsPage();
virtual void PageCompleted();
virtual void FrameResized(float width, float height);
private:
void _BuildUI();
void _Layout();
void _FillPartitionsView(BView* view);
void _CreateSizeText(int64 size, BString* text);
BMessage* _CreateControlMessage(uint32 what,
int32 partitionIndex);
void _ComputeColumnWidths(int32& showWidth,
int32& nameWidth, int32& typeWidth,
int32& sizeWidth, int32& pathWidth);
private:
BTextView* fDescription;
BView* fPartitions;
BScrollView* fPartitionsScrollView;
float fPartitionsWidth;
float fPartitionsHeight;
BGridView* fPartitions;
};
+6 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -9,6 +9,10 @@
#include "TestBootDrive.h"
#include <stdio.h>
#include <String.h>
TestBootDrive::TestBootDrive()
{
@@ -98,4 +102,5 @@ status_t
TestBootDrive::GetDisplayText(const char* text, BString& displayText)
{
displayText = text;
return B_OK;
}
+23 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -25,6 +25,15 @@ WizardPageView::WizardPageView(BMessage* settings, BRect frame,
}
WizardPageView::WizardPageView(BMessage* settings, const char* name)
:
BView(name, B_WILL_DRAW),
fSettings(settings)
{
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
}
WizardPageView::~WizardPageView()
{
}
@@ -52,6 +61,19 @@ WizardPageView::CreateDescription(BRect frame, const char* name,
}
BTextView*
WizardPageView::CreateDescription(const char* name,
const char* description)
{
BTextView* view = new BTextView("text");
view->MakeEditable(false);
view->SetViewColor(ViewColor());
view->SetStylable(true);
view->SetText(description);
return view;
}
void
WizardPageView::MakeHeading(BTextView* view)
{
@@ -61,7 +83,6 @@ WizardPageView::MakeHeading(BTextView* view)
int indexFirstLineEnd = firstLineEnd - text;
BFont font;
view->GetFont(&font);
font.SetSize(ceil(font.Size() * 1.2));
font.SetFace(B_BOLD_FACE);
view->SetFontAndColor(0, indexFirstLineEnd, &font);
}
+5 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2008-2010, Haiku, Inc. All rights reserved.
* Copyright 2008-2011, Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -21,12 +21,16 @@ public:
const char* name,
uint32 resizingMode = B_FOLLOW_ALL,
uint32 flags = B_WILL_DRAW);
WizardPageView(BMessage* settings,
const char* name);
virtual ~WizardPageView();
virtual void PageCompleted();
virtual BTextView* CreateDescription(BRect frame, const char* name,
const char* description);
virtual BTextView* CreateDescription(const char* name,
const char* description);
virtual void MakeHeading(BTextView* view);
virtual void LayoutDescriptionVertically(BTextView* view);