2 * Copyright 2006-2011, Stephan Aßmus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
10 #include <LayoutBuilder.h>
12 #include <TextControl.h>
14 #include "NamePanel.h"
16 #undef B_TRANSLATION_CONTEXT
17 #define B_TRANSLATION_CONTEXT "LaunchBox"
26 NamePanel::NamePanel(const char* label
, const char* text
, BWindow
* window
,
27 BHandler
* target
, BMessage
* message
, const BSize
& size
)
29 Panel(BRect(B_ORIGIN
, size
), B_TRANSLATE("Name Panel"),
30 B_MODAL_WINDOW_LOOK
, B_MODAL_SUBSET_WINDOW_FEEL
,
31 B_ASYNCHRONOUS_CONTROLS
| B_NOT_V_RESIZABLE
32 | B_AUTO_UPDATE_SIZE_LIMITS
),
36 fSavedTargetWindowFeel(B_NORMAL_WINDOW_FEEL
)
38 BButton
* defaultButton
= new BButton(B_TRANSLATE("OK"),
39 new BMessage(MSG_PANEL_OK
));
40 BButton
* cancelButton
= new BButton(B_TRANSLATE("Cancel"),
41 new BMessage(MSG_PANEL_CANCEL
));
42 fNameTC
= new BTextControl(label
, text
, NULL
);
43 BLayoutItem
* inputItem
= fNameTC
->CreateTextViewLayoutItem();
44 inputItem
->SetExplicitMinSize(
45 BSize(fNameTC
->StringWidth("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
48 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 10)
52 .AddGroup(B_HORIZONTAL
, 5)
56 .Add(fNameTC
->CreateLabelLayoutItem())
64 .AddGroup(B_HORIZONTAL
, 5)
73 SetDefaultButton(defaultButton
);
74 fNameTC
->MakeFocus(true);
76 if (fWindow
!= NULL
&& fWindow
->Lock()) {
77 fSavedTargetWindowFeel
= fWindow
->Feel();
78 if (fSavedTargetWindowFeel
!= B_NORMAL_WINDOW_FEEL
)
79 fWindow
->SetFeel(B_NORMAL_WINDOW_FEEL
);
87 NamePanel::~NamePanel()
89 if (fSavedTargetWindowFeel
!= B_NORMAL_WINDOW_FEEL
90 && fWindow
!= NULL
&& fWindow
->Lock()) {
91 fWindow
->SetFeel(fSavedTargetWindowFeel
);
98 void NamePanel::MessageReceived(BMessage
* message
)
100 switch (message
->what
) {
101 case MSG_PANEL_CANCEL
:
107 BLooper
* looper
= fTarget
? fTarget
->Looper() : NULL
;
108 if (fMessage
&& looper
) {
109 BMessage
cloneMessage(*fMessage
);
110 cloneMessage
.AddString("name", fNameTC
->Text());
111 cloneMessage
.AddRect("frame", Frame());
112 looper
->PostMessage(&cloneMessage
, fTarget
);
118 Panel::MessageReceived(message
);