Added the GUI part of the dialog. Now it is fully functional (maybe not nice, but functional ;-).

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2822 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2003-02-24 00:44:38 +00:00
parent d4ebd51785
commit 0f04e70bd8
2 changed files with 140 additions and 10 deletions

View File

@ -3,14 +3,27 @@
// by the OpenBeOS license.
//---------------------------------------------------------------------
#include <algobase.h>
#include <new.h>
#include <stdio.h>
#include <string.h>
#include <Button.h>
#include <DiskScannerAddOn.h>
#include <Screen.h>
#include <View.h>
#include "PartitioningDialog.h"
enum {
MSG_OK = 'okay',
MSG_CANCEL = 'cncl',
};
// constructor
PartitioningDialog::PartitioningDialog(BRect dialogCenter)
: BWindow(BRect(0, 0, 1, 1), "Partitioning Parameters", B_TITLED_WINDOW,
: BWindow(BRect(100, 100, 100, 100), "Partitioning Parameters",
B_TITLED_WINDOW,
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
fEditor(NULL),
fEditorView(NULL),
@ -30,22 +43,51 @@ PartitioningDialog::PartitioningDialog(BRect dialogCenter)
// destructor
PartitioningDialog::~PartitioningDialog()
{
if (fEditorView)
fEditorView->RemoveSelf();
if (fBlocker >= 0)
delete_sem(fBlocker);
}
// MessageReceived
void
PartitioningDialog::MessageReceived(BMessage *message)
{
switch (message->what) {
case MSG_OK:
{
if (fEditor->EditingDone()) {
if (fCancelled)
*fCancelled = false;
Quit();
}
break;
}
case MSG_CANCEL:
if (fCancelled)
*fCancelled = true;
Quit();
break;
default:
BWindow::MessageReceived(message);
break;
}
}
// QuitRequested
bool
PartitioningDialog::QuitRequested()
{
if (fCancelled)
*fCancelled = true;
return true;
}
// Go
status_t
PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
{
status_t error = (editor ? B_OK : B_BAD_VALUE);
// set the parameter editor and view
if (error == B_OK) {
fEditor = editor;
fEditorView = editor->View();
if (!fEditorView)
error = B_ERROR;
}
status_t error = _Init(editor);
bool wasRun = false;
// fire up the window
if (error == B_OK) {
@ -53,7 +95,7 @@ PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
sem_id blocker = fBlocker;
bool cancelled = true;
fCancelled = &cancelled;
Run();
Show();
wasRun = true;
acquire_sem(blocker);
if (cancelled)
@ -69,3 +111,85 @@ PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
return error;
}
// _Init
status_t
PartitioningDialog::_Init(BDiskScannerParameterEditor *editor)
{
status_t error = (editor ? B_OK : B_BAD_VALUE);
// set the parameter editor and view
if (error == B_OK) {
fEditor = editor;
fEditorView = editor->View();
if (!fEditorView)
error = B_ERROR;
}
// setup views
if (error == B_OK) {
BView *mainView = new(nothrow) BView(BRect(0, 0, 1, 1), "main",
B_FOLLOW_ALL, 0);
BMessage *okMessage = new BMessage(MSG_OK);
BMessage *cancelMessage = new BMessage(MSG_CANCEL);
BButton *okButton = new (nothrow) BButton(
BRect(0, 0, 1, 1), "ok", "OK", okMessage,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
BButton *cancelButton = new (nothrow) BButton(
BRect(0, 0, 1, 1), "cancel", "Cancel", cancelMessage,
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
if (okMessage && cancelMessage && okButton && cancelButton) {
// add the views to the hierarchy
mainView->AddChild(fEditorView);
mainView->AddChild(okButton);
mainView->AddChild(cancelButton);
AddChild(mainView);
// set the buttons' preferred size
float buttonWidth = 0;
float buttonHeight = 0;
okButton->GetPreferredSize(&buttonWidth, &buttonHeight);
okButton->ResizeTo(buttonWidth, buttonHeight);
cancelButton->GetPreferredSize(&buttonWidth, &buttonHeight);
cancelButton->ResizeTo(buttonWidth, buttonHeight);
// setup their positions and sizes
int32 hSpacing = 10;
int32 vSpacing = 10;
BRect editorRect = fEditorView->Bounds();
BRect okRect = okButton->Bounds();
BRect cancelRect = cancelButton->Bounds();
// compute width and size of the main view
int32 width = max(editorRect.IntegerWidth() + 1,
okRect.IntegerWidth() + 1 + hSpacing
+ cancelRect.IntegerWidth() + 1)
+ 2 * hSpacing;
int32 height = editorRect.IntegerHeight() + 1
+ max(okRect.IntegerHeight(),
cancelRect.IntegerHeight()) + 1
+ 3 * vSpacing;
mainView->ResizeTo(width - 1, height -1);
ResizeTo(width - 1, height -1);
// set location of the editor view
fEditorView->MoveTo((width - editorRect.IntegerWidth() - 1) / 2,
vSpacing - 1);
fEditorView->ResizeTo(editorRect.Width(), editorRect.Height());
// set the location of the buttons
float buttonTop = 2 * vSpacing + editorRect.IntegerHeight();
float buttonLeft = width - hSpacing - okRect.IntegerWidth();
okButton->MoveTo(buttonLeft, buttonTop);
buttonLeft -= hSpacing + cancelRect.IntegerWidth();
cancelButton->MoveTo(buttonLeft, buttonTop);
} else {
// cleanup on error
error = B_NO_MEMORY;
if (!okButton && okMessage)
delete okMessage;
if (!cancelButton && cancelMessage)
delete cancelMessage;
if (okButton)
delete okButton;
if (cancelButton)
delete cancelButton;
if (mainView)
delete mainView;
}
}
return error;
}

View File

@ -18,8 +18,14 @@ public:
PartitioningDialog(BRect dialogCenter);
virtual ~PartitioningDialog();
virtual void MessageReceived(BMessage *message);
virtual bool QuitRequested();
status_t Go(BDiskScannerParameterEditor *editor, bool *cancelled);
private:
status_t _Init(BDiskScannerParameterEditor *editor);
private:
BDiskScannerParameterEditor *fEditor;
BView *fEditorView;