2 * Copyright (c) 1999-2000, Eric Moon.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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"
37 #include <TextControl.h>
39 __USE_CORTEX_NAMESPACE
41 // ---------------------------------------------------------------- //
43 class MomentaryTextControl
:
45 typedef BTextControl _inherited
;
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
);
62 virtual void AllAttached() {
63 TextView()->SelectAll();
65 // size parent to fit me
73 virtual void MouseDown(
76 if(Bounds().Contains(point
))
77 _inherited::MouseDown(point
);
80 // // +++++ shouldn't an out-of-bounds click send the changed value?
81 // BMessenger(Window()).SendMessage(B_QUIT_REQUESTED);
88 if(numBytes
== 1 && *bytes
== B_ESCAPE
) {
89 BWindow
* w
= Window(); // +++++ maui/2 workaround
90 BMessenger(w
).SendMessage(B_QUIT_REQUESTED
);
96 // ---------------------------------------------------------------- //
98 // ---------------------------------------------------------------- //
100 // ---------------------------------------------------------------- //
102 TextControlFloater::~TextControlFloater() {
104 delete m_cancelMessage
;
107 TextControlFloater::TextControlFloater(
112 const BMessenger
& target
,
114 BMessage
* cancelMessage
) :
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
,
123 m_cancelMessage(cancelMessage
),
124 m_sentUpdate(false) {
126 m_control
= new MomentaryTextControl(
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();
144 m_control
->MakeFocus();
149 // ---------------------------------------------------------------- //
151 // ---------------------------------------------------------------- //
153 void TextControlFloater::WindowActivated(
157 // +++++ will the message get sent first?
161 // ---------------------------------------------------------------- //
163 // ---------------------------------------------------------------- //
165 void TextControlFloater::MessageReceived(
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
);
177 switch(message
->what
) {
179 _inherited::MessageReceived(message
);
183 bool TextControlFloater::QuitRequested() {
184 if(!m_sentUpdate
&& m_cancelMessage
)
185 m_target
.SendMessage(m_cancelMessage
);
190 // END -- TextControlFloater.cpp --