2 * Copyright 2012-2013, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
5 #include "PromptWindow.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
),
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
)
36 .AddGroup(B_HORIZONTAL
)
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()
63 PromptWindow::MessageReceived(BMessage
* message
)
65 switch (message
->what
)
69 fMessage
->AddString("text", fTextControl
->TextView()->Text());
70 fTarget
.SendMessage(fMessage
);
71 PostMessage(B_QUIT_REQUESTED
);
75 BWindow::MessageReceived(message
);
83 PromptWindow::SetTarget(BMessenger messenger
)
91 PromptWindow::SetMessage(BMessage
* message
)