btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / terminal / SetTitleDialog.cpp
blob563f518f27db91233bcd712890f54a2cff7ae040
1 /*
2 * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include "SetTitleDialog.h"
9 #include <Button.h>
10 #include <Catalog.h>
11 #include <LayoutBuilder.h>
12 #include <TextControl.h>
15 static const uint32 kMessageOK = 'okok';
16 static const uint32 kMessageDefault = 'dflt';
17 static const uint32 kMessageTitleChanged = 'chng';
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "Terminal SetTitleWindow"
24 // #pragma mark - SetTitleDialog
27 SetTitleDialog::SetTitleDialog(const char* dialogTitle, const char* label,
28 const char* toolTip)
30 BWindow(BRect(0, 0, 0, 0), dialogTitle, B_BORDERED_WINDOW_LOOK,
31 B_FLOATING_APP_WINDOW_FEEL,
32 B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE),
33 fListener(NULL),
34 fTitle(),
35 fOldTitleUserDefined(false),
36 fTitleUserDefined(false)
38 BLayoutBuilder::Group<>(this, B_VERTICAL)
39 .SetInsets(10, 10, 10, 10)
40 .Add(fTitleTextControl = new BTextControl("title", label, "", NULL))
41 .AddGroup(B_HORIZONTAL)
42 .Add(fDefaultButton = new BButton("defaultButton",
43 B_TRANSLATE("Use default"), new BMessage(kMessageDefault)))
44 .AddGlue()
45 .Add(fCancelButton = new BButton("cancelButton",
46 B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED)))
47 .Add(fOKButton = new BButton("okButton", B_TRANSLATE("OK"),
48 new BMessage(kMessageOK)));
50 fTitleTextControl->SetToolTip(toolTip);
52 fOKButton->MakeDefault(true);
54 UpdateSizeLimits();
55 // as a courtesy to our creator, who might want to place us
59 SetTitleDialog::~SetTitleDialog()
61 if (fListener != NULL) {
62 // reset to old title
63 fListener->TitleChanged(this, fOldTitle, fOldTitleUserDefined);
65 Listener* listener = fListener;
66 fListener = NULL;
67 listener->SetTitleDialogDone(this);
72 void
73 SetTitleDialog::Go(const BString& title, bool titleUserDefined,
74 Listener* listener)
76 fTitle = fOldTitle = title;
77 fTitleUserDefined = fOldTitleUserDefined = titleUserDefined;
79 fDefaultButton->SetEnabled(titleUserDefined);
81 fTitleTextControl->SetText(fTitle);
82 fTitleTextControl->SetModificationMessage(
83 new BMessage(kMessageTitleChanged));
84 fTitleTextControl->MakeFocus(true);
86 fListener = listener;
88 Show();
92 void
93 SetTitleDialog::Finish()
95 if (Listener* listener = fListener) {
96 fListener = NULL;
97 listener->SetTitleDialogDone(this);
100 PostMessage(B_QUIT_REQUESTED);
104 void
105 SetTitleDialog::MessageReceived(BMessage* message)
107 switch (message->what) {
108 case kMessageDefault:
109 if (fListener != NULL)
110 fListener->TitleChanged(this, BString(), false);
111 // We're done now, fall through...
113 case kMessageOK:
114 Finish();
115 break;
117 case kMessageTitleChanged:
118 fTitle = fTitleTextControl->Text();
119 fTitleUserDefined = true;
121 fDefaultButton->SetEnabled(true);
123 if (fListener != NULL)
124 fListener->TitleChanged(this, fTitle, fTitleUserDefined);
125 break;
127 default:
128 BWindow::MessageReceived(message);
129 break;
135 // #pragma mark - SetTitleDialog
138 SetTitleDialog::Listener::~Listener()