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:
@@ -3,14 +3,27 @@
|
|||||||
// by the OpenBeOS license.
|
// by the OpenBeOS license.
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
|
#include <algobase.h>
|
||||||
|
#include <new.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <Button.h>
|
||||||
#include <DiskScannerAddOn.h>
|
#include <DiskScannerAddOn.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
#include <View.h>
|
||||||
|
|
||||||
#include "PartitioningDialog.h"
|
#include "PartitioningDialog.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
MSG_OK = 'okay',
|
||||||
|
MSG_CANCEL = 'cncl',
|
||||||
|
};
|
||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
PartitioningDialog::PartitioningDialog(BRect dialogCenter)
|
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),
|
B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE),
|
||||||
fEditor(NULL),
|
fEditor(NULL),
|
||||||
fEditorView(NULL),
|
fEditorView(NULL),
|
||||||
@@ -30,22 +43,51 @@ PartitioningDialog::PartitioningDialog(BRect dialogCenter)
|
|||||||
// destructor
|
// destructor
|
||||||
PartitioningDialog::~PartitioningDialog()
|
PartitioningDialog::~PartitioningDialog()
|
||||||
{
|
{
|
||||||
|
if (fEditorView)
|
||||||
|
fEditorView->RemoveSelf();
|
||||||
if (fBlocker >= 0)
|
if (fBlocker >= 0)
|
||||||
delete_sem(fBlocker);
|
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
|
// Go
|
||||||
status_t
|
status_t
|
||||||
PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
|
PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
|
||||||
{
|
{
|
||||||
status_t error = (editor ? B_OK : B_BAD_VALUE);
|
status_t error = _Init(editor);
|
||||||
// set the parameter editor and view
|
|
||||||
if (error == B_OK) {
|
|
||||||
fEditor = editor;
|
|
||||||
fEditorView = editor->View();
|
|
||||||
if (!fEditorView)
|
|
||||||
error = B_ERROR;
|
|
||||||
}
|
|
||||||
bool wasRun = false;
|
bool wasRun = false;
|
||||||
// fire up the window
|
// fire up the window
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
@@ -53,7 +95,7 @@ PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
|
|||||||
sem_id blocker = fBlocker;
|
sem_id blocker = fBlocker;
|
||||||
bool cancelled = true;
|
bool cancelled = true;
|
||||||
fCancelled = &cancelled;
|
fCancelled = &cancelled;
|
||||||
Run();
|
Show();
|
||||||
wasRun = true;
|
wasRun = true;
|
||||||
acquire_sem(blocker);
|
acquire_sem(blocker);
|
||||||
if (cancelled)
|
if (cancelled)
|
||||||
@@ -69,3 +111,85 @@ PartitioningDialog::Go(BDiskScannerParameterEditor *editor, bool *_cancelled)
|
|||||||
return error;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,14 @@ public:
|
|||||||
PartitioningDialog(BRect dialogCenter);
|
PartitioningDialog(BRect dialogCenter);
|
||||||
virtual ~PartitioningDialog();
|
virtual ~PartitioningDialog();
|
||||||
|
|
||||||
|
virtual void MessageReceived(BMessage *message);
|
||||||
|
virtual bool QuitRequested();
|
||||||
|
|
||||||
status_t Go(BDiskScannerParameterEditor *editor, bool *cancelled);
|
status_t Go(BDiskScannerParameterEditor *editor, bool *cancelled);
|
||||||
|
|
||||||
|
private:
|
||||||
|
status_t _Init(BDiskScannerParameterEditor *editor);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BDiskScannerParameterEditor *fEditor;
|
BDiskScannerParameterEditor *fEditor;
|
||||||
BView *fEditorView;
|
BView *fEditorView;
|
||||||
|
|||||||
Reference in New Issue
Block a user