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.
This commit is contained in:
Axel Dörfler
2012-06-17 20:04:39 +02:00
parent 2ffea8e8a3
commit 7b2ba07326
3 changed files with 37 additions and 29 deletions
+26 -24
View File
@@ -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. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
* Stephan Aßmus <[email protected]> * Stephan Aßmus <[email protected]>
* Bryce Groff <[email protected]> * Bryce Groff <[email protected]>
* Karsten Heimrich. <[email protected]> * Karsten Heimrich <[email protected]>
*/ */
#include "CreateParamsPanel.h" #include "CreateParamsPanel.h"
#include "Support.h"
#include <Button.h> #include <Button.h>
#include <Catalog.h> #include <Catalog.h>
@@ -28,6 +28,8 @@
#include <Partition.h> #include <Partition.h>
#include <String.h> #include <String.h>
#include "Support.h"
#undef B_TRANSLATION_CONTEXT #undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "CreateParamsPanel" #define B_TRANSLATION_CONTEXT "CreateParamsPanel"
@@ -36,7 +38,8 @@
class CreateParamsPanel::EscapeFilter : public BMessageFilter { class CreateParamsPanel::EscapeFilter : public BMessageFilter {
public: public:
EscapeFilter(CreateParamsPanel* target) EscapeFilter(CreateParamsPanel* target)
: BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE), :
BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE),
fPanel(target) fPanel(target)
{ {
} }
@@ -85,7 +88,8 @@ enum {
CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition, CreateParamsPanel::CreateParamsPanel(BWindow* window, BPartition* partition,
off_t offset, off_t size) 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_MODAL_SUBSET_WINDOW_FEEL,
B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS),
fEscapeFilter(new EscapeFilter(this)), fEscapeFilter(new EscapeFilter(this)),
@@ -140,20 +144,18 @@ CreateParamsPanel::MessageReceived(BMessage* message)
fEditor->PartitionTypeChanged(type); fEditor->PartitionTypeChanged(type);
} }
break; break;
case MSG_SIZE_SLIDER: case MSG_SIZE_SLIDER:
_UpdateTextControl(); _UpdateSizeTextControl();
break; break;
case MSG_SIZE_TEXTCONTROL: case MSG_SIZE_TEXTCONTROL:
{ {
BString sizeString; int32 size = atoi(fSizeTextControl->Text());
sizeString = fSizeTextControl->Text(); if (size >= 0 && size <= fSizeSlider->MaxPartitionSize())
int32 sizeInt = atoi(sizeString.String()); fSizeSlider->SetValue(size + fSizeSlider->Offset());
if (sizeInt >= 0 && sizeInt <= fSizeSlider->MaxPartitionSize())
fSizeSlider->SetValue(sizeInt);
else else
_UpdateTextControl(); _UpdateSizeTextControl();
break; break;
} }
@@ -244,16 +246,15 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset,
offset, offset + size); offset, offset + size);
fSizeSlider->SetPosition(1.0); fSizeSlider->SetPosition(1.0);
fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER)); fSizeSlider->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER));
BString sizeText; fSizeTextControl = new BTextControl("Size Control", "", "", NULL);
sizeText << fSizeSlider->Value();
fSizeTextControl = new BTextControl("Size Control",
"", sizeText.String(), NULL);
for(int32 i = 0; i < 256; i++) for(int32 i = 0; i < 256; i++)
fSizeTextControl->TextView()->DisallowChar(i); fSizeTextControl->TextView()->DisallowChar(i);
for(int32 i = '0'; i <= '9'; i++) for(int32 i = '0'; i <= '9'; i++)
fSizeTextControl->TextView()->AllowChar(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", fNameTextControl = new BTextControl("Name Control",
B_TRANSLATE("Partition name:"), "", NULL); 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) if (err == B_OK && fEditor != NULL)
AddChild(fEditor->View()); AddChild(fEditor->View());
else else
@@ -316,9 +318,9 @@ CreateParamsPanel::_CreateViewControls(BPartition* parent, off_t offset,
void void
CreateParamsPanel::_UpdateTextControl() CreateParamsPanel::_UpdateSizeTextControl()
{ {
BString sizeString; BString sizeString;
sizeString << fSizeSlider->Value(); sizeString << fSizeSlider->Value() - fSizeSlider->Offset();
fSizeTextControl->SetText(sizeString.String()); fSizeTextControl->SetText(sizeString.String());
} }
+8 -3
View File
@@ -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. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -15,13 +15,15 @@
#include <PartitionParameterEditor.h> #include <PartitionParameterEditor.h>
#include <Partition.h> #include <Partition.h>
class BMenuField; class BMenuField;
class BTextControl; class BTextControl;
class SizeSlider; class SizeSlider;
class CreateParamsPanel : public BWindow { class CreateParamsPanel : public BWindow {
public: public:
CreateParamsPanel(BWindow* window, CreateParamsPanel(BWindow* window,
BPartition* parent, off_t offset, BPartition* parent, off_t offset,
off_t size); off_t size);
virtual ~CreateParamsPanel(); virtual ~CreateParamsPanel();
@@ -38,9 +40,11 @@ private:
void _CreateViewControls(BPartition* parent, void _CreateViewControls(BPartition* parent,
off_t offset, off_t size); off_t offset, off_t size);
void _UpdateTextControl(); void _UpdateSizeTextControl();
private:
class EscapeFilter; class EscapeFilter;
EscapeFilter* fEscapeFilter; EscapeFilter* fEscapeFilter;
sem_id fExitSemaphore; sem_id fExitSemaphore;
BWindow* fWindow; BWindow* fWindow;
@@ -55,4 +59,5 @@ private:
BTextControl* fSizeTextControl; BTextControl* fSizeTextControl;
}; };
#endif // CREATE_PARAMS_PANEL_H #endif // CREATE_PARAMS_PANEL_H
+3 -2
View File
@@ -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. * Distributed under the terms of the MIT license.
* *
* Authors: * Authors:
@@ -9,6 +9,7 @@
* Bryce Groff <[email protected]> * Bryce Groff <[email protected]>
*/ */
#include "Support.h" #include "Support.h"
#include <stdio.h> #include <stdio.h>
@@ -100,7 +101,7 @@ SizeSlider::SizeSlider(const char* name, const char* label,
B_HORIZONTAL, B_TRIANGLE_THUMB), B_HORIZONTAL, B_TRIANGLE_THUMB),
fStartOffset(minValue), fStartOffset(minValue),
fEndOffset(maxValue), fEndOffset(maxValue),
fMaxPartitionSize(maxValue) fMaxPartitionSize(maxValue - minValue)
{ {
rgb_color fillColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR); rgb_color fillColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
UseFillColor(true, &fillColor); UseFillColor(true, &fillColor);