btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / debugger / user_interface / gui / utility_windows / ExpressionPromptWindow.cpp
blob554081786b04b9f2eb72da6ecdf7dd4911914092
1 /*
2 * Copyright 2014-2016, Rene Gollent, rene@gollent.com.
3 * Distributed under the terms of the MIT License.
4 */
5 #include "ExpressionPromptWindow.h"
7 #include <Button.h>
8 #include <LayoutBuilder.h>
9 #include <String.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),
21 fCancelButton(NULL),
22 fAddButton(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,
38 closeTarget);
40 try {
41 self->_Init();
42 } catch (...) {
43 delete self;
44 throw;
47 return self;
52 void
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)
65 .Add(labelItem)
66 .Add(inputItem)
67 .End()
68 .AddGroup(B_HORIZONTAL, 4.0f)
69 .AddGlue()
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))))
74 .End();
76 fExpressionInput->SetTarget(this);
77 fCancelButton->SetTarget(this);
78 fAddButton->SetTarget(this);
79 fAddButton->MakeDefault(true);
80 fExpressionInput->TextView()->MakeFocus(true);
84 void
85 ExpressionPromptWindow::Show()
87 CenterOnScreen();
88 BWindow::Show();
92 bool
93 ExpressionPromptWindow::QuitRequested()
95 BMessenger messenger(fCloseTarget);
96 messenger.SendMessage(MSG_EXPRESSION_PROMPT_WINDOW_CLOSED);
98 return BWindow::QuitRequested();
102 void
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);
113 Quit();
114 break;
117 default:
118 BWindow::MessageReceived(message);
119 break;