2 * Copyright 2014-2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
5 #include "ExpressionPromptWindow.h"
8 #include <LayoutBuilder.h>
10 #include <TextControl.h>
12 #include "AppMessageCodes.h"
15 ExpressionPromptWindow::ExpressionPromptWindow(BHandler
* addTarget
,
16 BHandler
* closeTarget
)
18 BWindow(BRect(), "Add Expression", B_FLOATING_WINDOW
,
19 B_AUTO_UPDATE_SIZE_LIMITS
| B_CLOSE_ON_ESCAPE
),
20 fExpressionInput(NULL
),
23 fAddTarget(addTarget
),
24 fCloseTarget(closeTarget
)
29 ExpressionPromptWindow::~ExpressionPromptWindow()
34 ExpressionPromptWindow
*
35 ExpressionPromptWindow::Create(BHandler
* addTarget
, BHandler
* closeTarget
)
37 ExpressionPromptWindow
* self
= new ExpressionPromptWindow(addTarget
,
53 ExpressionPromptWindow::_Init()
55 fExpressionInput
= new BTextControl("Expression:", NULL
, NULL
);
56 BLayoutItem
* labelItem
= fExpressionInput
->CreateLabelLayoutItem();
57 BLayoutItem
* inputItem
= fExpressionInput
->CreateTextViewLayoutItem();
58 inputItem
->SetExplicitMinSize(BSize(200.0, B_SIZE_UNSET
));
59 inputItem
->SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, B_SIZE_UNSET
));
60 labelItem
->View()->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
62 BLayoutBuilder::Group
<>(this, B_VERTICAL
)
63 .SetInsets(B_USE_DEFAULT_SPACING
)
64 .AddGroup(B_HORIZONTAL
, 4.0f
)
68 .AddGroup(B_HORIZONTAL
, 4.0f
)
70 .Add((fCancelButton
= new BButton("Cancel",
71 new BMessage(B_QUIT_REQUESTED
))))
72 .Add((fAddButton
= new BButton("Add",
73 new BMessage(MSG_ADD_NEW_EXPRESSION
))))
76 fExpressionInput
->SetTarget(this);
77 fCancelButton
->SetTarget(this);
78 fAddButton
->SetTarget(this);
79 fAddButton
->MakeDefault(true);
80 fExpressionInput
->TextView()->MakeFocus(true);
85 ExpressionPromptWindow::Show()
93 ExpressionPromptWindow::QuitRequested()
95 BMessenger
messenger(fCloseTarget
);
96 messenger
.SendMessage(MSG_EXPRESSION_PROMPT_WINDOW_CLOSED
);
98 return BWindow::QuitRequested();
103 ExpressionPromptWindow::MessageReceived(BMessage
* message
)
105 switch (message
->what
) {
106 case MSG_ADD_NEW_EXPRESSION
:
108 BMessage
addMessage(MSG_ADD_NEW_EXPRESSION
);
109 addMessage
.AddString("expression", fExpressionInput
->Text());
110 addMessage
.AddBool("persistent", true);
112 BMessenger(fAddTarget
).SendMessage(&addMessage
);
118 BWindow::MessageReceived(message
);