RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / kits / shared / PromptWindow.cpp
blob7e7715b81031741f62c3bb9b03716f43b735c5c1
1 /*
2 * Copyright 2012-2013, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "PromptWindow.h"
7 #include <Button.h>
8 #include <Catalog.h>
9 #include <LayoutBuilder.h>
10 #include <StringView.h>
11 #include <TextControl.h>
14 static const uint32 kAcceptInput = 'acin';
17 PromptWindow::PromptWindow(const char* title, const char* label,
18 const char* info, BMessenger target, BMessage* message)
20 BWindow(BRect(), title, B_FLOATING_WINDOW, B_NOT_RESIZABLE
21 | B_NOT_ZOOMABLE | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
22 fTarget(target),
23 fMessage(message)
25 fInfoView = new BStringView("info", info);
26 fTextControl = new BTextControl("promptcontrol", label, NULL,
27 new BMessage(kAcceptInput));
28 BButton* cancelButton = new BButton("Cancel", new
29 BMessage(B_QUIT_REQUESTED));
30 BButton* acceptButton = new BButton("Accept", new
31 BMessage(kAcceptInput));
32 BLayoutBuilder::Group<>(this, B_VERTICAL)
33 .SetInsets(B_USE_DEFAULT_SPACING)
34 .Add(fInfoView)
35 .Add(fTextControl)
36 .AddGroup(B_HORIZONTAL)
37 .AddGlue()
38 .Add(cancelButton)
39 .Add(acceptButton)
40 .End()
41 .End();
43 if (info == NULL)
44 fInfoView->Hide();
46 fTextControl->TextView()->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET));
47 fTextControl->SetTarget(this);
48 acceptButton->SetTarget(this);
49 cancelButton->SetTarget(this);
50 fTextControl->MakeFocus(true);
52 SetDefaultButton(acceptButton);
56 PromptWindow::~PromptWindow()
58 delete fMessage;
62 void
63 PromptWindow::MessageReceived(BMessage* message)
65 switch (message->what)
67 case kAcceptInput:
69 fMessage->AddString("text", fTextControl->TextView()->Text());
70 fTarget.SendMessage(fMessage);
71 PostMessage(B_QUIT_REQUESTED);
73 default:
75 BWindow::MessageReceived(message);
76 break;
82 status_t
83 PromptWindow::SetTarget(BMessenger messenger)
85 fTarget = messenger;
86 return B_OK;
90 status_t
91 PromptWindow::SetMessage(BMessage* message)
93 delete fMessage;
94 fMessage = message;
95 return B_OK;