libroot/posix/stdio: Remove unused portions.
[haiku.git] / src / apps / drivesetup / CreateParametersPanel.cpp
blobe08d5ca7fb183f0dde608628020c488abc6ec088
1 /*
2 * Copyright 2008-2013 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
5 * Authors:
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"
15 #include <Button.h>
16 #include <Catalog.h>
17 #include <ControlLook.h>
18 #include <DiskDeviceTypes.h>
19 #include <MenuField.h>
20 #include <MenuItem.h>
21 #include <MessageFilter.h>
22 #include <PopUpMenu.h>
23 #include <String.h>
24 #include <TextControl.h>
25 #include <Variant.h>
27 #include "Support.h"
30 #undef B_TRANSLATION_CONTEXT
31 #define B_TRANSLATION_CONTEXT "CreateParametersPanel"
34 enum {
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()
59 status_t
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
64 // a BMessage
66 BMessage storage;
67 status_t status = ChangeParametersPanel::Go(name, type, parameters,
68 storage);
69 if (status != B_OK)
70 return status;
72 // Return the value back as bytes.
73 size = storage.GetInt64("size", 0);
74 offset = storage.GetInt64("offset", 0);
76 return B_OK;
80 void
81 CreateParametersPanel::MessageReceived(BMessage* message)
83 switch (message->what) {
84 case MSG_SIZE_SLIDER:
85 _UpdateSizeTextControl();
86 break;
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);
93 else
94 _UpdateSizeTextControl();
95 break;
98 default:
99 ChangeParametersPanel::MessageReceived(message);
104 bool
105 CreateParametersPanel::NeedsEditor() const
107 return false;
111 status_t
112 CreateParametersPanel::ParametersReceived(const BString& parameters,
113 BMessage& storage)
115 // Return the value back as bytes.
116 status_t status = storage.SetInt64("size", fSizeSlider->Size());
117 if (status == B_OK)
118 status = storage.SetInt64("offset", fSizeSlider->Offset());
120 if (status != B_OK)
121 return status;
123 return ChangeParametersPanel::ParametersReceived(parameters, storage);
127 void
128 CreateParametersPanel::AddControls(BLayoutBuilder::Group<>& builder,
129 BView* editorView)
131 builder
132 .Add(fSizeSlider)
133 .Add(fSizeTextControl);
135 ChangeParametersPanel::AddControls(builder, editorView);
139 void
140 CreateParametersPanel::_CreateCreateControls(BPartition* parent, off_t offset,
141 off_t size)
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"));
166 void
167 CreateParametersPanel::_UpdateSizeTextControl()
169 BString sizeString;
170 sizeString << fSizeSlider->Size() / kMegaByte;
171 fSizeTextControl->SetText(sizeString.String());