OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
popupgad.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------//
2// ObjectWindows 1998 Copyright by Yura Bidus //
3// //
4// Used code and ideas from Dieter Windau and Joseph Parrello //
5// //
6// EMail: dieter.windau@usa.net //
7// Web: http://members.aol.com/softengage/index.htm //
8// E-Mail : joparrello@geocities.com, joparrel@tin.it //
9// Web: http://space.tin.it/computer/giparrel //
10// //
11// Revision 1.5 //
12// Edited by Bidus Yura //
13// Date 11/19/98 //
14// //
15// THIS CLASS AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF //
16// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO //
17// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //
18// PARTICULAR PURPOSE. //
19// //
20// Implementation of class TPopupButtonGadget, TPopupMenuGadget. //
21//----------------------------------------------------------------------------//
22#include <owl/pch.h>
23
24#include <owl/celarray.h>
25#include <owl/gadgetwi.h>
26#include <owl/uihelper.h>
27#include <owl/popupgad.h>
28#include <cassert>
29
30namespace owl {
31
34
35//------------------------------------------------------------------------------
36//
37
38namespace
39{
40
41inline int F2Arr(int arrow, int width)
42{
43 return arrow == -1 ? width*1/4 : arrow;
44}
45
46inline int Arr2F(int arrow, int width)
47{
48 return arrow == -1 ? width*1/3 : arrow;
49}
50
51//
52// Utility RAII class to indicate that a popup is active.
53// Ensures that the popup flag is reset on exceptions.
54// Note that this structure is not safe for multi-threading.
55// See TPopupButtonGadget::BeginPressed for usage.
56//
57class TPopupGuard
58{
59public:
60
61 TPopupGuard()
62 {
63 assert(!Flag);
64 Flag = true;
65 }
66
67 ~TPopupGuard()
68 {
69 assert(Flag);
70 Flag = false;
71 }
72
73 TPopupGuard(const TPopupGuard&) = delete;
74 TPopupGuard(TPopupGuard&&) = delete;
75 auto operator =(const TPopupGuard&) -> TPopupGuard& = delete;
76 auto operator =(TPopupGuard&&) -> TPopupGuard& = delete;
77
78 static auto IsPopupActive() -> bool {return Flag;}
79
80private:
81
82 static bool Flag;
83
84};
85
86bool TPopupGuard::Flag = false;
87
88} // anonymous namespace
89
90//
91// class TPopupButtonGadget
92// ~~~~~ ~~~~~~~~~~~~~~~~~~
93//
95 TStyle style, TPopupType poptype, TType type, bool enabled, TState state,
97:
100 PopupType(poptype),
101 PopFlags(0),
102 ArrowWidth(static_cast<uint>(-1))
103{
104}
105
106//
107// GetDesiredSize
108//
109void
111{
113
114 if (PopupType != Normal)
115 size.cx += Arr2F(ArrowWidth, size.cx);
116}
117
118//
119void
121{
123
124 BitmapOrigin.x = BitmapOrigin.x - F2Arr(ArrowWidth, rect.Width())/2;
125}
126
127//
128//
129//
130void
132{
133 PRECONDITION(Window);
134
135 int arrowwidth = F2Arr(ArrowWidth, Bounds.Width());
137
139 Bounds.right -= arrowwidth;
140
141 PaintBorder(dc);
142
144 Bounds.right += arrowwidth;
145
148
149 if (PopupType != Normal)
150 faceRect.right -= arrowwidth;
151
153
154 if(Style&sText)
155 PaintText(dc, textRect, Text);
156 if(Style&sBitmap)
157 PaintFace(dc, btnRect);
158
159 if (PopupType != Normal)
160 faceRect.right += arrowwidth;
161
164
165 if (PopupType != Normal)
166 PaintArrow(dc, faceRect);
167}
168
169
170// Paint the separator between button and down arrow
171//
172void
174{
176
177 TRect boundsRect = TRect(TPoint(0,0),Bounds.Size());
178 boundsRect.left = boundsRect.right - F2Arr(ArrowWidth, Bounds.Width());
179
181 if (xpstyle)
182 {
183 bool ok = GetEnabled();
184 bool down = ok && PopFlags & ArrowPressed;
185 bool hover = ok && (IsHaveMouse() || GetGadgetWindow()->GadgetGetCaptured() == this);
187 if (down || hover)
189 }
190 else // !xpstyle
191 {
193
194 // Paint pressed/raised border around down arrow
195 //
196 if (flat)
197 {
198 if (GetEnabled())
199 {
203 else if (IsHaveMouse() || GetGadgetWindow()->GadgetGetCaptured() == this)
206 }
207 }
208 else // !flat
209 {
213 }
214 }
215}
216
217// Paint the down arrow
218//
219void
221{
222 PRECONDITION (Window);
223
224 // Paint pressed border around down arrow
225 //
227
228 TPoint dstPt(innerRect.right - F2Arr(ArrowWidth,Bounds.Width())/2 - (flat?1:2),
229 innerRect.top + (innerRect.Height()-4)/2);
230
231 if(PopFlags&ArrowPressed)// || Pressed)
232 dstPt.x++,dstPt.y++;
233
234 //Y.B!!! Have to be rewritten
235 // Paint down arrow
237 if (!GetEnabled())
239 TPen pen3(col);
240 dc.SelectObject(pen3);
241 dc.MoveTo(dstPt.x, dstPt.y);
242 dc.LineTo(dstPt.x+5, dstPt.y);
243 dc.MoveTo(dstPt.x+1, dstPt.y+1);
244 dc.LineTo(dstPt.x+4, dstPt.y+1);
245 dc.SetPixel(dstPt.x+2, dstPt.y+2, col);
246 if (!GetEnabled() && !flat) {
250 }
251 dc.RestorePen();
252}
253
254
255// Invoked by mouse-down & mouse enter events. sets member data "Pressed"
256// to true and highlights the button
257//
258void
260{
262 if (TPopupGuard::IsPopupActive()) return;
263
264 if (PopupType != DownArrowAction) {
266 if (TrackMouse)
268 TPopupGuard guard;
269 PopupAction();
270 }
271 else {
272 if ((PopFlags&HasCapture) == 0 &&
273 (PopFlags&ArrowPressed) == 0 &&
274 TRect(Bounds.right-Bounds.left-F2Arr(ArrowWidth, Bounds.Width()), 0,
275 Bounds.right-Bounds.left,Bounds.bottom-Bounds.top).Contains(p)){
276
277 Pressed = false;
278 SetInMouse(true);
280 Invalidate();
281 Update();
282 if(TrackMouse)
284 TPopupGuard guard;
285 PopupAction();
286 }
287 else
289 }
290}
291
292// Invoked by mouse exit events. sets member data "Pressed" to false and
293// paints the button in its current state
294//
295void
297{
298 if (TPopupGuard::IsPopupActive()) return;
299
300 if (Pressed)
302}
303
304// Captures the mouse if "TrackMouse" is set.
305//
306void
308{
309 if (TPopupGuard::IsPopupActive()) return;
310
312 if (Pressed)
314}
315
316// Releases the mouse capture if "TrackMouse" is set.
317//
318void
320{
321 if (TPopupGuard::IsPopupActive()) return;
322
324 PopFlags &= ~HasCapture;
325}
326
328{
329 if (TPopupGuard::IsPopupActive()) return;
330
331 SetInMouse(true);
333 Invalidate();
334 Update();
335 if (TrackMouse)
337 TPopupGuard guard;
338 PopupAction();
339}
340
341// Start the PopupAction if the user click
342// 1) into the button if PopupType != DownArrowAction
343// 2) into the arrow if PopupType == DownArrowAction
344// This function only restore button state, overwrite them with functionality,
345// but don't forget to call inherited one
346//
347void
349{
351 PopFlags &= ~ArrowPressed;
352 Invalidate();
353 Update();
354 }
355 else{
356 TPoint p;
357 CancelPressed(p, true);
358 }
359}
360
361
362//
363// class TPopupMenuGadget
364// ~~~~~ ~~~~~~~~~~~~~~~~
365//
366
368
369//
370//
371//
374 bool enabled, TState state, bool sharedGlyph, uint numChars)
375:
378 CmdTarget(window)
379{
380 PopupMenu = new TPopupMenu(menu);
381}
382
383//
384// Delete the allocated popup menu.
385//
390
391//
392//
393//
394void
396{
397 TRect rect = GetBounds();
398
399 TPoint p1(rect.TopLeft());
400 Window->ClientToScreen(p1);
401
402 TPoint p2(rect.BottomRight());
403 Window->ClientToScreen(p2);
405 tpm.cbSize = sizeof(TPMPARAMS);
406 tpm.rcExclude.top = p1.y;
407 tpm.rcExclude.left = 0;
408 tpm.rcExclude.bottom = p2.y;
409 tpm.rcExclude.right = 32000;
411
412 if(!IsWindow(Window->GetHandle()))
413 return;
414
416}
417
418} // OWL namespace
419//==============================================================================
Definition of a bitmap Cel array class.
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
TState
TState enumerates the three button positions during which the button can be pressed: up (0),...
Definition buttonga.h:80
TType
Enumerates the types of button gadgets.
Definition buttonga.h:69
void LButtonUp(uint modKeys, const TPoint &p) override
Handle the mouse left button up & leave the pressed state.
Definition buttonga.cpp:754
void PaintBorder(TDC &dc) override
Definition buttonga.cpp:472
virtual void CancelPressed(const TPoint &p, bool mstate=false)
Cancel pressed state, repaint & end menuselect state.
Definition buttonga.cpp:592
virtual void PaintFace(TDC &dc, const TRect &rect)
Paints the face of the button.
Definition buttonga.cpp:514
void LButtonDown(uint modKeys, const TPoint &p) override
Overrides TGadget member function and responds to a left mouse button click by calling BeginPressed.
Definition buttonga.cpp:683
virtual void BeginPressed(const TPoint &p)
Begin button pressed state, repaint & enter menuselect state.
Definition buttonga.cpp:574
Derived from TButtonGadget, TButtonTextGadget represents buttons with bitmap and text,...
Definition btntextg.h:45
virtual void Layout(TRect &srcRect, TRect &textRect, TRect &btnRect)
Layout button and text in the control area.
Definition btntextg.cpp:394
virtual void SetBounds(const TRect &rect)
If (Style & sBitmap) calls TButtonGadget::SetBounds; otherwise calls TGadget::SetBounds to set the bo...
Definition btntextg.cpp:344
TStyle
TStyle contains values that defines how gadget will be displayed:
Definition btntextg.h:62
@ sBitmap
Only the bitmap is displayed.
Definition btntextg.h:63
@ sText
Only text is displayed.
Definition btntextg.h:64
virtual void PaintText(TDC &dc, TRect &rect, const tstring &text)
Paint Text.
Definition btntextg.cpp:453
virtual void GetDesiredSize(TSize &size)
Calls TButtonGadget::GetDesiredSize if (Style & sBitmap); calls TGadget::GetDesiredSize and adds the ...
Definition btntextg.cpp:303
Class wrapper for management of color values.
Definition color.h:245
static const TColor SysBtnText
The symbolic system color value for the text on buttons.
Definition color.h:342
static const TColor Sys3dHilight
The symbolic system color value for highlighted 3-dimensional display elements (for edges facing the ...
Definition color.h:344
static const TColor Sys3dShadow
The symbolic system color value for the shadow regions of 3-dimensional display elements (for edges f...
Definition color.h:340
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
bool MoveTo(int x, int y)
Moves the current position of this DC to the given x- and y-coordinates or to the given point.
Definition dc.h:1690
TColor SetPixel(int x, int y, const TColor &color)
Sets the color of the pixel at the given location to the given color and returns the pixel's previous...
Definition dc.h:2394
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
void RestorePen()
Restores the original GDI pen object to this DC.
Definition dc.cpp:220
bool LineTo(int x, int y)
Draws a line on this DC using the current pen object.
Definition dc.h:2148
bool IsHaveMouse() const
Return true if mouse inside gadget.
Definition gadget.h:485
TRect & GetBounds()
Returns the boundary rectangle for the gadget.
Definition gadget.h:440
void Invalidate(bool erase=true)
Used to invalidate the active (usually nonborder) portion of the gadget, Invalidate calls InvalidateR...
Definition gadget.cpp:408
void GetInnerRect(TRect &rect)
Computes the area of the gadget's rectangle excluding the borders and margins.
Definition gadget.cpp:514
void SetInMouse(bool state)
Sets if mouse inside gadget or not.
Definition gadget.h:491
TGadgetWindow * GetGadgetWindow()
Return a pointer to the owning or parent window for the gadget.
Definition gadget.h:536
bool GetEnabled() const
Determines whether keyboard and mouse input have been enabled for the specified gadget.
Definition gadget.h:458
void Update()
Paint now if possible.
Definition gadget.cpp:417
TGadget * GadgetGetCaptured()
Retrieves gadget with capture.
Definition gadgetwi.h:476
static uint GetFlatStyle()
Returns the flat style.
Definition gadgetwi.h:459
@ FlatXPTheme
Windows XP theme styles.
Definition gadgetwi.h:198
@ FlatStandard
Flat style IE 3.0 - base style.
Definition gadgetwi.h:194
void GadgetReleaseCapture(TGadget &gadget)
Releases the capture so that other windows can receive mouse messages.
Definition gadgetwi.cpp:286
The TMenu class encapsulates window menus.
Definition menu.h:77
TPen is derived from TGdiObject.
Definition gdiobjec.h:138
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
@ Normal
Normal button style.
Definition popupgad.h:48
@ DownArrowAction
Separator between left area and down arrow.
Definition popupgad.h:52
TPopupButtonGadget(int id, TResId glyphResIdOrIndex, TStyle style=sBitmapText, TPopupType poptype=DownArrowAction, TType type=Command, bool enabled=false, TState state=Up, bool sharedGlyph=false, uint numChars=4)
Definition popupgad.cpp:94
virtual void PaintArrowButton(TDC &dc)
Definition popupgad.cpp:173
void BeginPressed(const TPoint &p) override
Definition popupgad.cpp:259
void GetDesiredSize(TSize &size) override
Definition popupgad.cpp:110
virtual void PaintArrow(TDC &dc, const TRect &rect)
Definition popupgad.cpp:220
void LButtonDown(uint modKeys, const TPoint &point) override
Definition popupgad.cpp:307
void SetBounds(const TRect &rect) override
Definition popupgad.cpp:120
void CancelPressed(const TPoint &p, bool mstate=false) override
Definition popupgad.cpp:296
void Paint(TDC &dc) override
Definition popupgad.cpp:131
virtual void PopupAction()
Start the PopupAction if the user click.
Definition popupgad.cpp:348
void LButtonUp(uint modKeys, const TPoint &point) override
Definition popupgad.cpp:319
void RButtonDown(uint modKeys, const TPoint &) override
Definition popupgad.cpp:327
TPopupMenu * PopupMenu
Definition popupgad.h:142
static uint Flags
Definition popupgad.h:144
virtual void PopupAction()
Definition popupgad.cpp:395
TPopupMenuGadget(TMenu &menu, TWindow *window, int id, TResId glyphResIdOrIndex, TStyle style=sBitmapText, TPopupType poptype=DownArrowAction, TType type=Command, bool enabled=false, TState state=Up, bool sharedGlyph=false, uint numChars=4)
Definition popupgad.cpp:372
TPopupMenu creates an empty pop-up menu to add to an existing window or pop-up menu.
Definition menu.h:189
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
bool Contains(const TPoint &point) const
Returns true if the given point lies within this rectangle; otherwise, it returns false.
Definition geometry.h:1200
The tagSIZE struct is defined as.
Definition geometry.h:234
Assists in drawing borders of many styles.
Definition uihelper.h:270
@ Flat
Flat instead of 3d for use in non-3d windows.
Definition uihelper.h:290
@ Soft
Soft edge look for buttons.
Definition uihelper.h:288
TEdge
Enumeration describing the type of edge to be drawn.
Definition uihelper.h:315
@ RaisedInner
Raised inner edge only.
Definition uihelper.h:318
@ SunkenOuter
Sunken outer edge only.
Definition uihelper.h:317
@ EdgeSunken
Both inner & outer sunken.
Definition uihelper.h:323
@ EdgeRaised
Both inner & outer raised.
Definition uihelper.h:322
void Paint(TDC &dc) const
Paints this UIBorder object onto a given device context.
Definition uiborder.cpp:112
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
Definition of TGadgetList, TGadgetWindow & TGadgetWindowFont A list holding gadgets,...
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned int uint
Definition number.h:25
Definition of classes TPopupButtonGadget and TPopupMenuGadget.
Definition of the UI Helper Classes: TUIHandle, TUIBorder, TUIFace, TUIPart.