* DialogWindow.h
* Copyright 2004 Michael Pfeiffer. All Rights Reserved.
*/
#include "DialogWindow.h"
#include <Messenger.h>
DialogWindow::DialogWindow(BRect frame,
const char *title,
window_type type,
uint32 flags,
uint32 workspace)
: BWindow(frame, title, type, flags, workspace)
, fPreviousResult(B_OK)
, fResult(NULL)
{
}
DialogWindow::DialogWindow(BRect frame,
const char *title,
window_look look,
window_feel feel,
uint32 flags,
uint32 workspace)
: BWindow(frame, title, look, feel, flags, workspace)
, fPreviousResult(B_OK)
, fResult(NULL)
{
}
void DialogWindow::MessageReceived(BMessage *msg)
{
if (msg->what == kGetThreadId) {
BMessage reply;
reply.AddInt32("thread_id", Thread());
msg->SendReply(&reply);
return;
}
BWindow::MessageReceived(msg);
}
status_t DialogWindow::Go()
{
BMessenger messenger(this, this);
volatile status_t result = fPreviousResult;
fResult = &result;
Show();
BMessage reply;
if (messenger.SendMessage(kGetThreadId, &reply) != B_OK) {
return B_ERROR;
}
thread_id windowThread;
if (reply.FindInt32("thread_id", &windowThread) != B_OK) {
return B_ERROR;
}
status_t status = B_ERROR;
wait_for_thread(windowThread, &status);
return result;
}
void DialogWindow::SetResult(status_t result)
{
if (fResult != NULL) {
*fResult = result;
} else {
fPreviousResult = result;
}
}