From 7b2ba073264ddfbc7d59d988120a320d22272963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 17 Jun 2012 20:01:42 +0200 Subject: [PATCH] The size control now actually sets the size instead of the offset. * SizeSlider::MaxPartitionSize() also now returns the size instead of the end offset. * Renamed CreateParamsPanel::_UpdateTextControl() to _UpdateSizeTextControl(). * Removed code duplication, and instead just call _UpdateSizeTextControl() twice. * Minor other cleanup. --- src/apps/drivesetup/CreateParamsPanel.cpp | 50 ++++++++++++----------- src/apps/drivesetup/CreateParamsPanel.h | 11 +++-- src/apps/drivesetup/Support.cpp | 5 ++- 3 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/apps/drivesetup/CreateParamsPanel.cpp b/src/apps/drivesetup/CreateParamsPanel.cpp index 337b0b5966..deeee1219a 100644 --- a/src/apps/drivesetup/CreateParamsPanel.cpp +++ b/src/apps/drivesetup/CreateParamsPanel.cpp @@ -1,15 +1,15 @@ /* - * Copyright 2008-20011 Haiku Inc. All rights reserved. + * Copyright 2008-2012 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: * Stephan Aßmus - * Bryce Groff - * Karsten Heimrich. + * Bryce Groff + * Karsten Heimrich */ + #include "CreateParamsPanel.h" -#include "Support.h" #include #include @@ -28,6 +28,8 @@ #include #include +#include "Support.h" + #undef B_TRANSLATION_CONTEXT #define B_TRANSLATION_CONTEXT "CreateParamsPanel" @@ -36,7 +38,8 @@ class CreateParamsPanel::EscapeFilter : public BMessageFilter { public: EscapeFilter(CreateParamsPanel* target) - : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), + : + BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), fPanel(target) { } @@ -85,7 +88,8 @@ enum { CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition, off_t offset, off_t size) - : BWindow(BRect(300.0, 200.0, 600.0, 300.0), 0, B_MODAL_WINDOW_LOOK, + : + BWindow(BRect(300.0, 200.0, 600.0, 300.0), 0, B_MODAL_WINDOW_LOOK, B_MODAL_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fEscapeFilter(new EscapeFilter(this)), @@ -140,20 +144,18 @@ CreateParamsPanel::MessageReceived(BMessage* message) fEditor->PartitionTypeChanged(type); } break; - + case MSG_SIZE_SLIDER: - _UpdateTextControl(); + _UpdateSizeTextControl(); break; - + case MSG_SIZE_TEXTCONTROL: { - BString sizeString; - sizeString = fSizeTextControl->Text(); - int32 sizeInt = atoi(sizeString.String()); - if (sizeInt >= 0 && sizeInt <= fSizeSlider->MaxPartitionSize()) - fSizeSlider->SetValue(sizeInt); + int32 size = atoi(fSizeTextControl->Text()); + if (size >= 0 && size <= fSizeSlider->MaxPartitionSize()) + fSizeSlider->SetValue(size + fSizeSlider->Offset()); else - _UpdateTextControl(); + _UpdateSizeTextControl(); break; } @@ -244,16 +246,15 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, 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); + + fSizeTextControl = new BTextControl("Size Control", "", "", 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)); + _UpdateSizeTextControl(); + fSizeTextControl->SetModificationMessage( + new BMessage(MSG_SIZE_TEXTCONTROL)); fNameTextControl = new BTextControl("Name Control", B_TRANSLATE("Partition name:"), "", NULL); @@ -295,7 +296,8 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, ) ); - status_t err = parent->GetParameterEditor(B_CREATE_PARAMETER_EDITOR, &fEditor); + status_t err = parent->GetParameterEditor(B_CREATE_PARAMETER_EDITOR, + &fEditor); if (err == B_OK && fEditor != NULL) AddChild(fEditor->View()); else @@ -316,9 +318,9 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset, void -CreateParamsPanel::_UpdateTextControl() +CreateParamsPanel::_UpdateSizeTextControl() { BString sizeString; - sizeString << fSizeSlider->Value(); + sizeString << fSizeSlider->Value() - fSizeSlider->Offset(); fSizeTextControl->SetText(sizeString.String()); } diff --git a/src/apps/drivesetup/CreateParamsPanel.h b/src/apps/drivesetup/CreateParamsPanel.h index 3896c0fbb0..eef3cc2011 100644 --- a/src/apps/drivesetup/CreateParamsPanel.h +++ b/src/apps/drivesetup/CreateParamsPanel.h @@ -1,5 +1,5 @@ /* - * Copyright 2008 Haiku Inc. All rights reserved. + * Copyright 2008-2012 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -15,13 +15,15 @@ #include #include + class BMenuField; class BTextControl; class SizeSlider; + class CreateParamsPanel : public BWindow { public: - CreateParamsPanel(BWindow* window, + CreateParamsPanel(BWindow* window, BPartition* parent, off_t offset, off_t size); virtual ~CreateParamsPanel(); @@ -38,9 +40,11 @@ private: void _CreateViewControls(BPartition* parent, off_t offset, off_t size); - void _UpdateTextControl(); + void _UpdateSizeTextControl(); +private: class EscapeFilter; + EscapeFilter* fEscapeFilter; sem_id fExitSemaphore; BWindow* fWindow; @@ -55,4 +59,5 @@ private: BTextControl* fSizeTextControl; }; + #endif // CREATE_PARAMS_PANEL_H diff --git a/src/apps/drivesetup/Support.cpp b/src/apps/drivesetup/Support.cpp index 23e19ac730..3b4f45bc81 100644 --- a/src/apps/drivesetup/Support.cpp +++ b/src/apps/drivesetup/Support.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 Haiku Inc. All rights reserved. + * Copyright 2002-2012 Haiku Inc. All rights reserved. * Distributed under the terms of the MIT license. * * Authors: @@ -9,6 +9,7 @@ * Bryce Groff */ + #include "Support.h" #include @@ -100,7 +101,7 @@ SizeSlider::SizeSlider(const char* name, const char* label, B_HORIZONTAL, B_TRIANGLE_THUMB), fStartOffset(minValue), fEndOffset(maxValue), - fMaxPartitionSize(maxValue) + fMaxPartitionSize(maxValue - minValue) { rgb_color fillColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR); UseFillColor(true, &fillColor);