btrfs: Attempt to fix GCC2 build.
[haiku.git] / src / apps / cortex / support / TextControlFloater.cpp
blobe49e94f2b811d885d5fae3679aed97452b4f74a9
1 /*
2 * Copyright (c) 1999-2000, Eric Moon.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions, and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 // TextControlFloater.cpp
34 #include "TextControlFloater.h"
36 #include <Debug.h>
37 #include <TextControl.h>
39 __USE_CORTEX_NAMESPACE
41 // ---------------------------------------------------------------- //
43 class MomentaryTextControl :
44 public BTextControl {
45 typedef BTextControl _inherited;
47 public:
48 MomentaryTextControl(
49 BRect frame,
50 const char* name,
51 const char* label,
52 const char* text,
53 BMessage* message,
54 uint32 resizingMode=B_FOLLOW_LEFT|B_FOLLOW_TOP,
55 uint32 flags=B_WILL_DRAW|B_NAVIGABLE) :
56 BTextControl(frame, name, label, text, message, resizingMode, flags) {
58 SetEventMask(B_POINTER_EVENTS|B_KEYBOARD_EVENTS);
61 public:
62 virtual void AllAttached() {
63 TextView()->SelectAll();
65 // size parent to fit me
66 Window()->ResizeTo(
67 Bounds().Width(),
68 Bounds().Height());
70 Window()->Show();
73 virtual void MouseDown(
74 BPoint point) {
76 if(Bounds().Contains(point))
77 _inherited::MouseDown(point);
79 Invoke();
80 // // +++++ shouldn't an out-of-bounds click send the changed value?
81 // BMessenger(Window()).SendMessage(B_QUIT_REQUESTED);
84 virtual void KeyDown(
85 const char* bytes,
86 int32 numBytes) {
88 if(numBytes == 1 && *bytes == B_ESCAPE) {
89 BWindow* w = Window(); // +++++ maui/2 workaround
90 BMessenger(w).SendMessage(B_QUIT_REQUESTED);
91 return;
96 // ---------------------------------------------------------------- //
98 // ---------------------------------------------------------------- //
99 // dtor/ctors
100 // ---------------------------------------------------------------- //
102 TextControlFloater::~TextControlFloater() {
103 if(m_cancelMessage)
104 delete m_cancelMessage;
107 TextControlFloater::TextControlFloater(
108 BRect frame,
109 alignment align,
110 const BFont* font,
111 const char* text,
112 const BMessenger& target,
113 BMessage* message,
114 BMessage* cancelMessage) :
115 BWindow(
116 frame, //.InsetBySelf(-3.0,-3.0), // expand frame to counteract control border
117 "TextControlFloater",
118 B_NO_BORDER_WINDOW_LOOK,
119 B_FLOATING_APP_WINDOW_FEEL,
121 m_target(target),
122 m_message(message),
123 m_cancelMessage(cancelMessage),
124 m_sentUpdate(false) {
126 m_control = new MomentaryTextControl(
127 Bounds(),
128 "textControl",
130 text,
131 message,
132 B_FOLLOW_ALL_SIDES);
134 Run();
135 Lock();
137 m_control->TextView()->SetFontAndColor(font);
138 m_control->TextView()->SetAlignment(align);
139 m_control->SetDivider(0.0);
141 m_control->SetViewColor(B_TRANSPARENT_COLOR);
142 m_control->TextView()->SelectAll();
143 AddChild(m_control);
144 m_control->MakeFocus();
146 Unlock();
149 // ---------------------------------------------------------------- //
150 // BWindow
151 // ---------------------------------------------------------------- //
153 void TextControlFloater::WindowActivated(
154 bool activated) {
156 if(!activated)
157 // +++++ will the message get sent first?
158 Quit();
161 // ---------------------------------------------------------------- //
162 // BHandler
163 // ---------------------------------------------------------------- //
165 void TextControlFloater::MessageReceived(
166 BMessage* message) {
168 if(message->what == m_message->what) {
169 // done; relay message to final target
170 message->AddString("_value", m_control->TextView()->Text());
171 m_target.SendMessage(message);
172 m_sentUpdate = true;
173 Quit();
174 return;
177 switch(message->what) {
178 default:
179 _inherited::MessageReceived(message);
183 bool TextControlFloater::QuitRequested() {
184 if(!m_sentUpdate && m_cancelMessage)
185 m_target.SendMessage(m_cancelMessage);
187 return true;
190 // END -- TextControlFloater.cpp --