-
-
Notifications
You must be signed in to change notification settings - Fork 336
/
ExpressionPromptWindow.cpp
122 lines (97 loc) · 2.57 KB
/
ExpressionPromptWindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright 2014, Rene Gollent, rene@gollent.com.
* Distributed under the terms of the MIT License.
*/
#include "ExpressionPromptWindow.h"
#include <Button.h>
#include <LayoutBuilder.h>
#include <String.h>
#include <TextControl.h>
#include "MessageCodes.h"
ExpressionPromptWindow::ExpressionPromptWindow(BHandler* addTarget,
BHandler* closeTarget)
:
BWindow(BRect(), "Add Expression", B_FLOATING_WINDOW,
B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
fExpressionInput(NULL),
fCancelButton(NULL),
fAddButton(NULL),
fAddTarget(addTarget),
fCloseTarget(closeTarget)
{
}
ExpressionPromptWindow::~ExpressionPromptWindow()
{
}
ExpressionPromptWindow*
ExpressionPromptWindow::Create(BHandler* addTarget, BHandler* closeTarget)
{
ExpressionPromptWindow* self = new ExpressionPromptWindow(addTarget,
closeTarget);
try {
self->_Init();
} catch (...) {
delete self;
throw;
}
return self;
}
void
ExpressionPromptWindow::_Init()
{
fExpressionInput = new BTextControl("Expression:", NULL, NULL);
BLayoutItem* labelItem = fExpressionInput->CreateLabelLayoutItem();
BLayoutItem* inputItem = fExpressionInput->CreateTextViewLayoutItem();
inputItem->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET));
inputItem->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED, B_SIZE_UNSET));
labelItem->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BLayoutBuilder::Group<>(this, B_VERTICAL)
.SetInsets(B_USE_DEFAULT_SPACING)
.AddGroup(B_HORIZONTAL, 4.0f)
.Add(labelItem)
.Add(inputItem)
.End()
.AddGroup(B_HORIZONTAL, 4.0f)
.AddGlue()
.Add((fCancelButton = new BButton("Cancel",
new BMessage(B_QUIT_REQUESTED))))
.Add((fAddButton = new BButton("Add",
new BMessage(MSG_ADD_NEW_EXPRESSION))))
.End();
fExpressionInput->SetTarget(this);
fCancelButton->SetTarget(this);
fAddButton->SetTarget(this);
fAddButton->MakeDefault(true);
fExpressionInput->TextView()->MakeFocus(true);
}
void
ExpressionPromptWindow::Show()
{
CenterOnScreen();
BWindow::Show();
}
bool
ExpressionPromptWindow::QuitRequested()
{
BMessenger messenger(fCloseTarget);
messenger.SendMessage(MSG_EXPRESSION_PROMPT_WINDOW_CLOSED);
return BWindow::QuitRequested();
}
void
ExpressionPromptWindow::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_ADD_NEW_EXPRESSION:
{
BMessage addMessage(MSG_ADD_NEW_EXPRESSION);
addMessage.AddString("expression", fExpressionInput->Text());
addMessage.AddBool("persistent", true);
BMessenger(fAddTarget).SendMessage(&addMessage);
Quit();
break;
}
default:
BWindow::MessageReceived(message);
break;
}
}