2 * Copyright 2008-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
6 * Stephan Aßmus <superstippi@gmx.de>
7 * Axel Dörfler, axeld@pinc-software.de.
8 * Bryce Groff <bgroff@hawaii.edu>
9 * Karsten Heimrich <host.haiku@gmx.de>
13 #include "CreateParametersPanel.h"
17 #include <ControlLook.h>
18 #include <DiskDeviceTypes.h>
19 #include <MenuField.h>
21 #include <MessageFilter.h>
22 #include <PopUpMenu.h>
24 #include <TextControl.h>
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "CreateParametersPanel"
35 MSG_PARTITION_TYPE
= 'type',
36 MSG_SIZE_SLIDER
= 'ssld',
37 MSG_SIZE_TEXTCONTROL
= 'stct'
40 static const uint32 kMegaByte
= 0x100000;
43 CreateParametersPanel::CreateParametersPanel(BWindow
* window
,
44 BPartition
* partition
, off_t offset
, off_t size
)
46 ChangeParametersPanel(window
)
48 _CreateCreateControls(partition
, offset
, size
);
50 Init(B_CREATE_PARAMETER_EDITOR
, "", partition
);
54 CreateParametersPanel::~CreateParametersPanel()
60 CreateParametersPanel::Go(off_t
& offset
, off_t
& size
, BString
& name
,
61 BString
& type
, BString
& parameters
)
63 // The object will be deleted in Go(), so we need to get the values via
67 status_t status
= ChangeParametersPanel::Go(name
, type
, parameters
,
72 // Return the value back as bytes.
73 size
= storage
.GetInt64("size", 0);
74 offset
= storage
.GetInt64("offset", 0);
81 CreateParametersPanel::MessageReceived(BMessage
* message
)
83 switch (message
->what
) {
85 _UpdateSizeTextControl();
88 case MSG_SIZE_TEXTCONTROL
:
90 off_t size
= strtoll(fSizeTextControl
->Text(), NULL
, 10) * kMegaByte
;
91 if (size
>= 0 && size
<= fSizeSlider
->MaxPartitionSize())
92 fSizeSlider
->SetSize(size
);
94 _UpdateSizeTextControl();
99 ChangeParametersPanel::MessageReceived(message
);
105 CreateParametersPanel::NeedsEditor() const
112 CreateParametersPanel::ParametersReceived(const BString
& parameters
,
115 // Return the value back as bytes.
116 status_t status
= storage
.SetInt64("size", fSizeSlider
->Size());
118 status
= storage
.SetInt64("offset", fSizeSlider
->Offset());
123 return ChangeParametersPanel::ParametersReceived(parameters
, storage
);
128 CreateParametersPanel::AddControls(BLayoutBuilder::Group
<>& builder
,
133 .Add(fSizeTextControl
);
135 ChangeParametersPanel::AddControls(builder
, editorView
);
140 CreateParametersPanel::_CreateCreateControls(BPartition
* parent
, off_t offset
,
143 // Setup the controls
144 // TODO: use a lower granularity for smaller disks -- but this would
145 // require being able to parse arbitrary size strings with unit
146 fSizeSlider
= new SizeSlider("Slider", B_TRANSLATE("Partition size"), NULL
,
147 offset
, size
, kMegaByte
);
148 fSizeSlider
->SetPosition(1.0);
149 fSizeSlider
->SetModificationMessage(new BMessage(MSG_SIZE_SLIDER
));
151 fSizeTextControl
= new BTextControl("Size Control", "", "", NULL
);
152 for(int32 i
= 0; i
< 256; i
++)
153 fSizeTextControl
->TextView()->DisallowChar(i
);
154 for(int32 i
= '0'; i
<= '9'; i
++)
155 fSizeTextControl
->TextView()->AllowChar(i
);
156 _UpdateSizeTextControl();
157 fSizeTextControl
->SetModificationMessage(
158 new BMessage(MSG_SIZE_TEXTCONTROL
));
160 CreateChangeControls(parent
);
162 fOkButton
->SetLabel(B_TRANSLATE("Create"));
167 CreateParametersPanel::_UpdateSizeTextControl()
170 sizeString
<< fSizeSlider
->Size() / kMegaByte
;
171 fSizeTextControl
->SetText(sizeString
.String());