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 // ValControlSegment.cpp
36 #include "ValControlSegment.h"
37 #include "ValControl.h"
43 __USE_CORTEX_NAMESPACE
46 ValControlSegment::ValControlSegment(underline_style underlineStyle
)
47 :BView(BRect(), "ValControlSegment", B_FOLLOW_LEFT
|B_FOLLOW_TOP
,
48 B_WILL_DRAW
|B_FRAME_EVENTS
),
49 fDragScaleFactor(fDefDragScaleFactor
),
51 fUnderlineStyle(underlineStyle
),
59 ValControlSegment::~ValControlSegment()
65 ValControlSegment::_Init()
71 const double ValControlSegment::fDefDragScaleFactor
= 4;
76 ValControlSegment::parent() const
78 return dynamic_cast<ValControl
*>(Parent());
83 //// send message -> segment to my left
84 //void ValControlSegment::sendMessageLeft(BMessage* pMsg) {
87 // BMessenger m(m_pLeft);
90 // m.SendMessage(pMsg);
95 // init mouse tracking
97 ValControlSegment::trackMouse(BPoint point
, track_flags flags
)
102 SetMouseEventMask(B_POINTER_EVENTS
,
103 B_LOCK_WINDOW_FOCUS
| B_NO_POINTER_HISTORY
);
108 ValControlSegment::setTracking(bool tracking
)
110 fTracking
= tracking
;
115 ValControlSegment::isTracking() const
122 ValControlSegment::dragScaleFactor() const
124 return fDragScaleFactor
;
128 // -------------------------------------------------------- //
129 // default hook implementations
130 // -------------------------------------------------------- //
133 ValControlSegment::sizeUnderline(float* outLeft
, float* outRight
)
136 *outRight
= Bounds().right
;
141 ValControlSegment::AttachedToWindow()
143 // if(parent()->backBuffer())
144 // SetViewColor(B_TRANSPARENT_COLOR);
146 // adopt parent's view color
147 SetViewColor(parent()->ViewColor());
152 ValControlSegment::Draw(BRect updateRect
)
154 if (fUnderlineStyle
== NO_UNDERLINE
)
157 // +++++ move to layout function
158 float fY
= parent()->baselineOffset() + 1;
160 rgb_color white
= {255,255,255,255};
161 rgb_color blue
= {0,0,255,255};
162 rgb_color gray
= {140,140,140,255};
163 rgb_color old
= HighColor();
166 if(parent()->IsEnabled() && parent()->IsFocus())
171 if (fXUnderlineRight
<= fXUnderlineLeft
)
172 sizeUnderline(&fXUnderlineLeft
, &fXUnderlineRight
);
175 // "### ValControlSegment::Draw(): underline spans %.1f, %.1f\n",
176 // fXUnderlineLeft, fXUnderlineRight));
178 StrokeLine(BPoint(fXUnderlineLeft
, fY
),
179 BPoint(fXUnderlineRight
, fY
),
180 (fUnderlineStyle
== DOTTED_UNDERLINE
) ? B_MIXED_COLORS
:
187 ValControlSegment::FrameResized(float width
, float height
)
189 _Inherited::FrameResized(width
, height
);
192 // "### ValControlSegment::FrameResized(%.1f,%.1f)\n",
193 // fWidth, fHeight));
194 sizeUnderline(&fXUnderlineLeft
, &fXUnderlineRight
);
199 ValControlSegment::MouseDown(BPoint point
)
201 if (!parent()->IsEnabled())
204 parent()->MakeFocus();
208 GetMouse(&point
, &nButton
);
209 if (!(nButton
& B_PRIMARY_MOUSE_BUTTON
))
213 bigtime_t doubleClickInterval
;
214 if (get_click_speed(&doubleClickInterval
) < B_OK
) {
215 PRINT(("* ValControlSegment::MouseDown():\n"
216 " get_click_speed() failed."));
220 bigtime_t now
= system_time();
221 if (now
- fLastClickTime
< doubleClickInterval
) {
227 // hand off to parent control
228 parent()->showEditField();
229 fLastClickTime
= 0LL;
233 fLastClickTime
= now
;
237 trackMouse(point
, TRACK_VERTICAL
);
242 ValControlSegment::MouseMoved(BPoint point
, uint32 transit
,
243 const BMessage
* dragMessage
)
245 if (!parent()->IsEnabled())
248 if (!isTracking() || fPrevPoint
== point
)
251 // float fXDelta = fTrackFlags & TRACK_HORIZONTAL ?
252 // point.x - fPrevPoint.x : 0.0;
253 float fYDelta
= fTrackFlags
& TRACK_VERTICAL
?
254 point
.y
- fPrevPoint
.y
: 0.0;
256 // printf("MouseMoved(): %2f,%2f\n",
257 // fXDelta, fYDelta);
261 // +++++ config'able x/y response would be nice...
262 float fRemaining
= handleDragUpdate(fYDelta
);
265 fPrevPoint
.y
-= fRemaining
;
270 ValControlSegment::MouseUp(BPoint point
)
280 ValControlSegment::MessageReceived(BMessage
* message
)
282 switch(message
->what
) {
284 _Inherited::MessageReceived(message
);
289 // -------------------------------------------------------- //
290 // archiving/instantiation
291 // -------------------------------------------------------- //
293 ValControlSegment::ValControlSegment(BMessage
* archive
)
297 archive
->FindInt32("ulStyle", (int32
*)&fUnderlineStyle
);
302 ValControlSegment::Archive(BMessage
* archive
, bool deep
) const
304 _Inherited::Archive(archive
, deep
);
306 archive
->AddInt32("ulStyle", fUnderlineStyle
);