From 42ea87d59b6529411e0dc4a0683c3d055a927367 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 19 Sep 2011 20:01:38 +0000 Subject: [PATCH] Patch by "jwlh172": Added a text control to the partition creation panel of DriveSetup, to enter the partition size manually. Closes ticket #7991. Changes by myself: I've refactored updating the text control from the size slider and used that method also when the user somehow entered invalid input into the text control (untested). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42759 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/drivesetup/CreateParamsPanel.cpp | 40 ++++++++++++++++++++++- src/apps/drivesetup/CreateParamsPanel.h | 3 ++ src/apps/drivesetup/Support.cpp | 9 ++++- src/apps/drivesetup/Support.h | 2 ++ 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/apps/drivesetup/CreateParamsPanel.cpp b/src/apps/drivesetup/CreateParamsPanel.cpp index 76c6e008ad..771cd5231a 100644 --- a/src/apps/drivesetup/CreateParamsPanel.cpp +++ b/src/apps/drivesetup/CreateParamsPanel.cpp @@ -77,7 +77,9 @@ private: enum { MSG_OK = 'okok', MSG_CANCEL = 'cncl', - MSG_PARTITION_TYPE = 'type' + MSG_PARTITION_TYPE = 'type', + MSG_SIZE_SLIDER = 'ssld', + MSG_SIZE_TEXTCONTROL = 'stct' }; @@ -138,6 +140,22 @@ CreateParamsPanel::MessageReceived(BMessage* message) fEditor->PartitionTypeChanged(type); } break; + + case MSG_SIZE_SLIDER: + _UpdateTextControl(); + break; + + case MSG_SIZE_TEXTCONTROL: + { + BString sizeString; + sizeString = fSizeTextControl->Text(); + int32 sizeInt = atoi(sizeString.String()); + if (sizeInt >= 0 && sizeInt <= fSizeSlider->MaxPartitionSize()) + fSizeSlider->SetValue(sizeInt); + else + _UpdateTextControl(); + break; + } default: BWindow::MessageReceived(message); @@ -225,6 +243,17 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, fSizeSlider = new SizeSlider("Slider", B_TRANSLATE("Partition size"), NULL, offset, offset + size); fSizeSlider->SetPosition(1.0); + fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER)); + + BString sizeText; + sizeText << fSizeSlider->Value(); + fSizeTextControl = new BTextControl("Size Control", + "", sizeText.String(), NULL); + for(int32 i = 0; i < 256; i++) + fSizeTextControl->TextView()->DisallowChar(i); + for(int32 i = '0'; i <= '9'; i++) + fSizeTextControl->TextView()->AllowChar(i); + fSizeTextControl->SetModificationMessage(new BMessage(MSG_SIZE_TEXTCONTROL)); fNameTextControl = new BTextControl("Name Control", B_TRANSLATE("Partition name:"), "", NULL); @@ -257,6 +286,7 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, AddChild(BGroupLayoutBuilder(B_VERTICAL, spacing) .Add(fSizeSlider) + .Add(fSizeTextControl) .Add(BGridLayoutBuilder(0.0, 5.0) .Add(fNameTextControl->CreateLabelLayoutItem(), 0, 0) .Add(fNameTextControl->CreateTextViewLayoutItem(), 1, 0) @@ -284,3 +314,11 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); } + +void +CreateParamsPanel::_UpdateTextControl() +{ + BString sizeString; + sizeString << fSizeSlider->Value(); + fSizeTextControl->SetText(sizeString.String()); +} diff --git a/src/apps/drivesetup/CreateParamsPanel.h b/src/apps/drivesetup/CreateParamsPanel.h index 9b9221595f..3896c0fbb0 100644 --- a/src/apps/drivesetup/CreateParamsPanel.h +++ b/src/apps/drivesetup/CreateParamsPanel.h @@ -38,6 +38,8 @@ private: void _CreateViewControls(BPartition* parent, off_t offset, off_t size); + void _UpdateTextControl(); + class EscapeFilter; EscapeFilter* fEscapeFilter; sem_id fExitSemaphore; @@ -50,6 +52,7 @@ private: BMenuField* fTypeMenuField; BTextControl* fNameTextControl; SizeSlider* fSizeSlider; + BTextControl* fSizeTextControl; }; #endif // CREATE_PARAMS_PANEL_H diff --git a/src/apps/drivesetup/Support.cpp b/src/apps/drivesetup/Support.cpp index 49e59bdba7..1c913ed19c 100644 --- a/src/apps/drivesetup/Support.cpp +++ b/src/apps/drivesetup/Support.cpp @@ -99,7 +99,8 @@ SizeSlider::SizeSlider(const char* name, const char* label, BSlider(name, label, message, minValue, maxValue, B_HORIZONTAL, B_TRIANGLE_THUMB), fStartOffset(minValue), - fEndOffset(maxValue) + fEndOffset(maxValue), + fMaxPartitionSize(maxValue) { SetBarColor((rgb_color){ 0, 80, 255, 255 }); char minString[64]; @@ -143,3 +144,9 @@ SizeSlider::Offset() // headed slider is implemented. return fStartOffset; } + +int32 +SizeSlider::MaxPartitionSize() +{ + return fMaxPartitionSize; +} diff --git a/src/apps/drivesetup/Support.h b/src/apps/drivesetup/Support.h index 736ce4c011..9314446d67 100644 --- a/src/apps/drivesetup/Support.h +++ b/src/apps/drivesetup/Support.h @@ -51,10 +51,12 @@ public: virtual const char* UpdateText() const; int32 Size(); int32 Offset(); + int32 MaxPartitionSize(); private: off_t fStartOffset; off_t fEndOffset; + off_t fMaxPartitionSize; mutable char fStatusLabel[64]; };