]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/gaugemsw.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGaugeMSW class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "gauge.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
30 #include "wx/msw/gaugemsw.h"
31 #include "wx/msw/private.h"
33 /* gas gauge graph control messages--class "zYzGauge" */
34 #define ZYZG_SETRANGE (WM_USER + 0)
35 #define ZYZG_GETRANGE (WM_USER + 1)
36 #define ZYZG_SETPOSITION (WM_USER + 2)
37 #define ZYZG_GETPOSITION (WM_USER + 3)
38 #define ZYZG_SETORIENTATION (WM_USER + 4)
39 #define ZYZG_GETORIENTATION (WM_USER + 5)
40 #define ZYZG_SETFGCOLOR (WM_USER + 6)
41 #define ZYZG_GETFGCOLOR (WM_USER + 7)
42 #define ZYZG_SETBKCOLOR (WM_USER + 8)
43 #define ZYZG_GETBKCOLOR (WM_USER + 9)
44 #define ZYZG_SETWIDTH3D (WM_USER + 10)
45 #define ZYZG_GETWIDTH3D (WM_USER + 11)
46 #define ZYZG_SETBEZELFACE (WM_USER + 12)
47 #define ZYZG_GETBEZELFACE (WM_USER + 13)
48 #define ZYZG_SETDELTAPOS (WM_USER + 14)
51 /* orientations for ZYZG_WW_ORIENTATION */
52 #define ZYZG_ORIENT_LEFTTORIGHT 0
53 #define ZYZG_ORIENT_RIGHTTOLEFT 1
54 #define ZYZG_ORIENT_BOTTOMTOTOP 2
55 #define ZYZG_ORIENT_TOPTOBOTTOM 3
58 #define ZYZGS_3D 0x8000L /* control will be 3D */
60 /* public function prototypes */
61 BOOL FAR PASCAL
gaugeInit(HINSTANCE hInstance
);
63 #if !USE_SHARED_LIBRARY
64 IMPLEMENT_DYNAMIC_CLASS(wxGaugeMSW
, wxControl
)
67 bool wxGaugeMSW::Create(wxWindow
*parent
, wxWindowID id
,
72 const wxValidator
& validator
,
75 static bool wxGaugeMSWInitialised
= FALSE
;
77 if ( !wxGaugeMSWInitialised
)
79 if (!gaugeInit((HINSTANCE
) wxGetInstance()))
80 wxFatalError("Cannot initalize Gauge library");
81 wxGaugeMSWInitialised
= TRUE
;
85 SetValidator(validator
);
87 if (parent
) parent
->AddChild(this);
91 SetBackgroundColour(parent
->GetBackgroundColour()) ;
92 SetForegroundColour(parent
->GetForegroundColour()) ;
94 m_windowStyle
= style
;
97 m_windowId
= (int)NewControlId();
106 long msFlags
= WS_CHILD
| WS_VISIBLE
| WS_TABSTOP
;
110 CreateWindowEx(MakeExtendedStyle(m_windowStyle
), T("zYzGauge"), NULL
, msFlags
,
111 0, 0, 0, 0, (HWND
) parent
->GetHWND(), (HMENU
)m_windowId
,
112 wxGetInstance(), NULL
);
114 m_hWnd
= (WXHWND
)wx_button
;
116 // Subclass again for purposes of dialog editing mode
117 SubclassWin((WXHWND
)wx_button
);
121 if (m_windowStyle
& wxGA_HORIZONTAL
)
122 wOrient
= ZYZG_ORIENT_LEFTTORIGHT
;
124 wOrient
= ZYZG_ORIENT_BOTTOMTOTOP
;
126 SendMessage(wx_button
, ZYZG_SETORIENTATION
, wOrient
, 0);
127 SendMessage(wx_button
, ZYZG_SETRANGE
, range
, 0);
129 SendMessage(GetHwnd(), ZYZG_SETFGCOLOR
, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue()));
130 SendMessage(GetHwnd(), ZYZG_SETBKCOLOR
, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue()));
132 SetFont(parent
->GetFont());
138 SetSize(x
, y
, width
, height
);
140 ShowWindow(GetHwnd(), SW_SHOW
);
145 void wxGaugeMSW::SetShadowWidth(int w
)
147 SendMessage(GetHwnd(), ZYZG_SETWIDTH3D
, w
, 0);
150 void wxGaugeMSW::SetBezelFace(int w
)
152 SendMessage(GetHwnd(), ZYZG_SETBEZELFACE
, w
, 0);
155 void wxGaugeMSW::SetRange(int r
)
159 SendMessage(GetHwnd(), ZYZG_SETRANGE
, r
, 0);
162 void wxGaugeMSW::SetValue(int pos
)
166 SendMessage(GetHwnd(), ZYZG_SETPOSITION
, pos
, 0);
169 int wxGaugeMSW::GetShadowWidth(void) const
171 return (int) SendMessage(GetHwnd(), ZYZG_GETWIDTH3D
, 0, 0);
174 int wxGaugeMSW::GetBezelFace(void) const
176 return (int) SendMessage(GetHwnd(), ZYZG_GETBEZELFACE
, 0, 0);
179 int wxGaugeMSW::GetRange(void) const
181 return (int) SendMessage(GetHwnd(), ZYZG_GETRANGE
, 0, 0);
184 int wxGaugeMSW::GetValue(void) const
186 return (int) SendMessage(GetHwnd(), ZYZG_GETPOSITION
, 0, 0);
189 bool wxGaugeMSW::SetForegroundColour(const wxColour
& col
)
191 if ( !wxControl::SetForegroundColour(col
) )
194 SendMessage(GetHwnd(), ZYZG_SETFGCOLOR
, 0, RGB(col
.Red(), col
.Green(), col
.Blue()));
199 bool wxGaugeMSW::SetBackgroundColour(const wxColour
& col
)
201 if ( !wxControl::SetBackgroundColour(col
) )
204 SendMessage(GetHwnd(), ZYZG_SETBKCOLOR
, 0, RGB(col
.Red(), col
.Green(), col
.Blue()));
213 * This module contains functions for creating nifty 3D borders
214 * around controls like zYzGauge.
217 * 3/14/91 cjp put in this comment
218 * 6/19/92 cjp touched it a bit
223 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
225 // You have a royalty-free right to use, modify, reproduce and
226 // distribute the Sample Files (and/or any modified version) in
227 // any way you find useful, provided that you agree that
228 // Microsoft has no warranty obligations or liability for any
229 // Sample Application Files which are modified.
233 /* get the includes we need */
236 /* misc. control flag defines */
237 #define DRAW3D_IN 0x0001
238 #define DRAW3D_OUT 0x0002
240 #define DRAW3D_TOPLINE 0x0004
241 #define DRAW3D_BOTTOMLINE 0x0008
242 #define DRAW3D_LEFTLINE 0x0010
243 #define DRAW3D_RIGHTLINE 0x0020
246 /* public function prototypes */
247 void FAR PASCAL
Draw3DFaceFrame(HDC
, LPRECT
, WORD
);
248 void FAR PASCAL
Draw3DRect(HDC
, LPRECT
, WORD
, WORD
);
249 void FAR PASCAL
Draw3DLine(HDC
, WORD
, WORD
, WORD
, WORD
, WORD
);
252 /** void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth)
255 * This function draws a flat frame with the current button-face
259 * HDC hdc : The DC to draw into.
261 * LPRECT rc : The containing rect for the new frame.
263 * WORD wWidth : The width of the frame to draw.
265 * RETURN (void FAR PASCAL):
266 * The frame will have been drawn into the DC.
272 void FAR PASCAL
Draw3DFaceFrame(HDC hdc
, LPRECT rc
, WORD wWidth
)
277 /* don't go through a bunch of work if we don't have to */
281 /* set up color to be button-face color--so it may not be gray */
282 rgbOld
= SetBkColor(hdc
, GetSysColor(COLOR_BTNFACE
));
284 /* perform CopyRect w/o bloody windows style overhead */
290 rc1
.bottom
= rc
->top
+ wWidth
;
291 rc1
.right
= rc
->right
;
294 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
297 rc1
.left
= rc
->right
- wWidth
;
298 rc1
.bottom
= rc
->bottom
;
300 /* blast this part now */
301 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
305 rc1
.right
= rc
->left
+ wWidth
;
307 /* and another part */
308 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
311 rc1
.right
= rc
->right
;
312 rc1
.top
= rc
->bottom
- wWidth
;
315 ExtTextOut(hdc
, rc1
.left
, rc1
.top
, ETO_OPAQUE
, &rc1
, NULL
, 0, NULL
);
317 /* restore the old bk color */
318 SetBkColor(hdc
, rgbOld
);
319 } /* Draw3DFaceFrame() */
322 /** void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD)
325 * Draws a 3D rectangle that is shaded. wFlags can be used to
326 * control how the rectangle looks.
329 * HDC hdc : Handle to the device context that will be
330 * used to display the rectangle.
332 * RECT rect : A rectangle describing the dimensions of
333 * the rectangle in device coordinates.
335 * WORD wShadowWidth : Width of the shadow in device coordinates.
337 * WORD wFlags : The following flags may be passed to describe
338 * the style of the rectangle:
340 * DRAW3D_IN : The shadow is drawn such that
341 * the box appears to be sunk in to the screen.
342 * This is default if 0 is passed.
344 * DRAW3D_OUT : The shadow is drawn such that
345 * the box appears to be sticking out of the
348 * RETURN (void FAR PASCAL):
349 * The 3D looking rectangle will have been drawn into the DC.
355 void FAR PASCAL
Draw3DRect(HDC hdc
, LPRECT lpRect
,
356 WORD wShadowWidth
, WORD wFlags
)
358 /* sanity check--don't work if you don't have to! */
359 if (!wShadowWidth
|| !RectVisible(hdc
, lpRect
))
362 /* draw the top line */
363 Draw3DLine(hdc
, lpRect
->left
, lpRect
->top
,
364 lpRect
->right
- lpRect
->left
,
365 wShadowWidth
, DRAW3D_TOPLINE
| wFlags
);
368 Draw3DLine(hdc
, lpRect
->right
, lpRect
->top
,
369 lpRect
->bottom
- lpRect
->top
,
370 wShadowWidth
, DRAW3D_RIGHTLINE
| wFlags
);
373 Draw3DLine(hdc
, lpRect
->left
, lpRect
->bottom
,
374 lpRect
->right
- lpRect
->left
,
375 wShadowWidth
, DRAW3D_BOTTOMLINE
| wFlags
);
378 Draw3DLine(hdc
, lpRect
->left
, lpRect
->top
,
379 lpRect
->bottom
- lpRect
->top
,
380 wShadowWidth
, DRAW3D_LEFTLINE
| wFlags
);
384 /** void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen,
387 * Draws a 3D line that can be used to make a 3D box.
390 * HDC hdc : Handle to the device context that will be
391 * used to display the 3D line.
393 * WORD x, y : Coordinates of the beginning of the line.
394 * These coordinates are in device units and
395 * represent the _outside_ most point. Horiz-
396 * ontal lines are drawn from left to right and
397 * vertical lines are drawn from top to bottom.
399 * WORD wShadowWidth : Width of the shadow in device coordinates.
401 * WORD wFlags : The following flags may be passed to
402 * describe the style of the 3D line:
404 * DRAW3D_IN : The shadow is drawn such that
405 * the box appears to be sunk in to the screen.
406 * This is default if 0 is passed.
408 * DRAW3D_OUT : The shadow is drawn such that
409 * the box appears to be sticking out of the
412 * DRAW3D_TOPLINE, _BOTTOMLINE, _LEFTLINE, and
413 * _RIGHTLINE : Specifies that a "top",
414 * "Bottom", "Left", or"Right" line is to be
417 * RETURN (void FAR PASCAL):
418 * The line will have been drawn into the DC.
424 void FAR PASCAL
Draw3DLine(HDC hdc
, WORD x
, WORD y
, WORD nLen
,
425 WORD wShadowWidth
, WORD wFlags
)
430 POINT Point
[ 4 ]; /* define a polgon with 4 points */
432 /* if width is zero, don't do nothin'! */
436 /* define shape of polygon--origin is always the same */
440 /* To do this we'll simply draw a polygon with four sides, using
441 * the appropriate brush. I dare you to ask me why this isn't a
444 if (wFlags
& DRAW3D_TOPLINE
)
446 /* across to right */
447 Point
[1].x
= x
+ nLen
- (wShadowWidth
== 1 ? 1 : 0);
451 Point
[2].x
= x
+ nLen
- wShadowWidth
;
452 Point
[2].y
= y
+ wShadowWidth
;
454 /* accross to left */
455 Point
[3].x
= x
+ wShadowWidth
;
456 Point
[3].y
= y
+ wShadowWidth
;
458 /* select 'dark' brush if 'in'--'light' for 'out' */
459 fDark
= (wFlags
& DRAW3D_IN
) ? TRUE
: FALSE
;
462 /* possibly the bottom? */
463 else if (wFlags
& DRAW3D_BOTTOMLINE
)
465 /* across to right */
466 Point
[1].x
= x
+ nLen
;
470 Point
[2].x
= x
+ nLen
- wShadowWidth
;
471 Point
[2].y
= y
- wShadowWidth
;
473 /* accross to left */
474 Point
[3].x
= x
+ wShadowWidth
;
475 Point
[3].y
= y
- wShadowWidth
;
477 /* select 'light' brush if 'in' */
478 fDark
= (wFlags
& DRAW3D_IN
) ? FALSE
: TRUE
;
481 /* ok, it's gotta be left? */
482 else if (wFlags
& DRAW3D_LEFTLINE
)
486 Point
[1].y
= y
+ nLen
- (wShadowWidth
== 1 ? 1 : 0);
489 Point
[2].x
= x
+ wShadowWidth
;
490 Point
[2].y
= y
+ nLen
- wShadowWidth
;
493 Point
[3].x
= x
+ wShadowWidth
;
494 Point
[3].y
= y
+ wShadowWidth
;
496 /* select 'dark' brush if 'in'--'light' for 'out' */
497 fDark
= (wFlags
& DRAW3D_IN
) ? TRUE
: FALSE
;
500 /* well maybe it's for the right side? */
501 else if (wFlags
& DRAW3D_RIGHTLINE
)
505 Point
[1].y
= y
+ nLen
;
508 Point
[2].x
= x
- wShadowWidth
;
509 Point
[2].y
= y
+ nLen
- wShadowWidth
;
512 Point
[3].x
= x
- wShadowWidth
;
513 Point
[3].y
= y
+ wShadowWidth
;
515 /* select 'light' brush if 'in' */
516 fDark
= (wFlags
& DRAW3D_IN
) ? FALSE
: TRUE
;
522 /* select NULL_PEN for no borders */
523 hOldPen
= (HPEN
) SelectObject(hdc
, GetStockObject(NULL_PEN
));
525 /* select the appropriate color for the fill */
527 hOldBrush
= (HBRUSH
) SelectObject(hdc
, GetStockObject(GRAY_BRUSH
));
529 hOldBrush
= (HBRUSH
) SelectObject(hdc
, GetStockObject(WHITE_BRUSH
));
531 /* finally, draw the dern thing */
532 Polygon(hdc
, (LPPOINT
)&Point
, 4);
534 /* restore what we killed */
535 SelectObject(hdc
, hOldBrush
);
536 SelectObject(hdc
, hOldPen
);
544 * Yet another 'Gas Gauge Custom Control.' This control gives you
545 * a 'progress bar' class (named zYzGauge) for use in your applications.
546 * You can set the range, position, font, color, orientation, and 3d
547 * effect of the gauge by sending messages to the control.
549 * Before you can use this control, you MUST first export the window
550 * procedure for the control (or define it with the _export keyword):
552 * EXPORTS gaugeWndProc
554 * You then need initialize the class before you use it:
556 * if (!gaugeInit(hInstance))
557 * die a horrible death
561 * The colors used by the control default to black and white if you
562 * are running on a mono-display. They default to blue and white
563 * if you are on a color display. You enable the 3D effect by setting
564 * the ZYZGS_3D style flag in the styles field of the control (like
565 * any other control).
567 * To select your own colors, you can send the ZYZG_SETFGCOLOR and
568 * ZYZG_SETBKCOLOR messages to set the foreground (percent done) and
569 * background (percent not done) colors. The lParam is the RGB()
570 * value--wParam is ignored.
572 * In all of the following ZYZG_??? messages, the arguments are
573 * WORDS. If you are setting parameters, the value is sent as
574 * the wParam (lParam is ignored). If you are getting parameters,
575 * the value is returned as a LONG and should be cast to a *signed*
578 * To set the depth of the 3D effect (if enabled), you can send the
579 * ZYZG_SETBEZELFACE and ZYZG_SETWIDTH3D messages. The bezel face
580 * is the flat top on the 3D border--its color will be that of the
581 * button-face. The 3D width is the width of the bezel itself; inside
582 * and outside. The light color is white, the dark color is gray.
583 * Both widths *can* be zero--both default to 2 which looks to me.
585 * The range of the control can be set by sending the ZYZG_SETRANGE
586 * message to the control. It can be any integer from 1 to 32767.
587 * What this specifies is the number of pieces that create a whole.
588 * The default is 100. You can get the current range setting by
589 * sending the ZYZG_GETRANGE message to the control.
591 * The position (number of pieces out of the whole have been used) is
592 * set with the ZYZG_SETPOSITION message. It can be any integer from
593 * 0 to the current range setting of the control--it will be clipped
594 * if the position is out of bounds. The default position is 0. You
595 * can get the current position at any time with the ZYZG_GETPOSITION
598 * You can also set the range using a delta from the current range.
599 * This is done by sending the ZYZG_SETDELTAPOS message with wParam
600 * set to a _signed_ integer value within the range of the control.
602 * The font used for the percentage text can be set using the standard
603 * WM_SETFONT message. You can get the current font at any time with
604 * the WM_GETFONT message.
606 * The orientation can be left to right, right to left, bottom to top,
607 * or top to bottom. Whatever suits your needs. You set this by
608 * sending the ZYZG_ORIENTATION message to the control with one of
609 * the following values (default is ZYZG_ORIENT_LEFTTORIGHT):
611 * ZYZG_ORIENT_LEFTTORIGHT (0)
612 * ZYZG_ORIENT_RIGHTTOLEFT (1)
613 * ZYZG_ORIENT_BOTTOMTOTOP (2)
614 * ZYZG_ORIENT_TOPTOBOTTOM (3)
617 * 3/12/91 cjp put in this comment
618 * 6/19/92 cjp touched it a bit
623 // (C) Copyright Microsoft Corp. 1992. All rights reserved.
625 // You have a royalty-free right to use, modify, reproduce and
626 // distribute the Sample Files (and/or any modified version) in
627 // any way you find useful, provided that you agree that
628 // Microsoft has no warranty obligations or liability for any
629 // Sample Application Files which are modified.
633 /* get the includes we need */
634 #if !defined(__GNUWIN32__) && !defined(__SALFORDC__)
640 // #include "zyz3d.h"
641 // #include "zyzgauge.h"
644 /* static global variables */
645 static wxChar gszzYzGaugeClass
[] = T("zYzGauge");
648 /* window word position definitions */
649 #define ZYZG_WW_PZYZGAUGE 0
650 /* #define ZYZG_WW_EXTRABYTES 2 */
651 #define ZYZG_WW_EXTRABYTES 4
654 /* control block structure typedef */
655 typedef struct tZYZGAUGE
661 WORD wWidthBezelFace
;
666 } ZYZGAUGE
, *PZYZGAUGE
, FAR
*LPZYZGAUGE
;
669 /* some default values for the control */
670 #define ZYZG_DEF_RANGE 100
671 #define ZYZG_DEF_POSITION 0
672 #define ZYZG_DEF_ORIENTATION ZYZG_ORIENT_LEFTTORIGHT
673 #define ZYZG_DEF_WIDTH3D 2
674 #define ZYZG_DEF_BEZELFACE 2
678 /* the default settings for drawing colors--display dependent */
679 static DWORD rgbDefTextColor
;
680 static DWORD rgbDefBkColor
;
681 static BOOL fSupport3D
;
683 #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not
684 #define APIENTRY FAR PASCAL
690 #define _EXPORT _export
691 typedef signed short int SHORT
;
694 /* internal function prototypes */
695 static void PASCAL
gaugePaint(HWND
, HDC
);
696 /* LRESULT FAR PASCAL */
697 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
701 /** BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance)
704 * Registers the window class for the zYzGauge control. Performs
705 * other initialization for the zYzGauge text control. This must
706 * be done before the zYzGauge control is used--or it will fail
707 * and your dialog box will not open!
710 * HINSTANCE hInstance : Instance handle to register class with.
713 * The return value is TRUE if the zYzGauge class was successfully
714 * registered. It is FALSE if the initialization fails.
720 //#pragma alloc_text(init, gaugeInit)
722 BOOL FAR PASCAL
gaugeInit(HINSTANCE hInstance
)
724 static BOOL fRegistered
= FALSE
;
728 /* assume already registered if not first instance */
732 /* fill in the class structure for the zyzgauge control */
733 wc
.hCursor
= LoadCursor(NULL
, IDC_ARROW
);
735 wc
.lpszMenuName
= NULL
;
736 wc
.lpszClassName
= gszzYzGaugeClass
;
737 wc
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
738 wc
.hInstance
= hInstance
;
741 wc
.style
= CS_GLOBALCLASS
| CS_HREDRAW
| CS_VREDRAW
;
743 wc
.style
= CS_HREDRAW
| CS_VREDRAW
;
746 wc
.lpfnWndProc
= gaugeWndProc
;
748 wc
.cbWndExtra
= ZYZG_WW_EXTRABYTES
;
750 /* attempt to register it--return FALSE if fail */
751 if (!RegisterClass(&wc
))
754 /* Get a DC to determine whether device is mono or not, and set
755 * default foreground/background colors as appropriate.
757 hdc
= CreateIC(T("DISPLAY"), NULL
, NULL
, 0L) ;
760 /* check for mono-display */
761 if ((GetDeviceCaps(hdc
, BITSPIXEL
) == 1) &&
762 (GetDeviceCaps(hdc
, PLANES
) == 1))
764 /* using a mono DC--white foreground, black background */
765 rgbDefTextColor
= RGB(255, 255, 255);
766 rgbDefBkColor
= RGB(0, 0, 0);
769 /* good! we have color: blue foreground, white background */
772 rgbDefTextColor
= RGB(0, 0, 255);
773 rgbDefBkColor
= RGB(255, 255, 255);
776 /* need at _least_ 8 for two shades of gray (>=VGA) */
777 fSupport3D
= (GetDeviceCaps(hdc
, NUMCOLORS
) >= 8) ? TRUE
: FALSE
;
779 /* get rid of the DC (IC) */
783 /* uh-oh... can't get DC (IC)... fail */
786 /* unregister the class */
787 UnregisterClass(gszzYzGaugeClass
, hInstance
);
792 return (fRegistered
= TRUE
);
796 /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
799 * This function is responsible for painting the zYzGauge control.
802 * HWND hwnd : The window handle for the gauge.
804 * HDC hdc : The DC for the gauge's window.
807 * The control will have been painted.
813 static void PASCAL
gaugePaint(HWND hwnd
, HDC hdc
)
822 WORD dx
, dy
, wGomerX
, wGomerY
;
823 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead,
824 * which needs a SIZE* parameter */
825 #if defined(__WIN32__)
829 /* get pointer to the control's control block */
830 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
831 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
833 /* set the colors into for the gauge into the control */
834 SetTextColor(hdc
, pgauge
->rgbTextColor
);
835 SetBkColor(hdc
, pgauge
->rgbBkColor
);
837 /* draw black rectangle for gauge */
838 GetClientRect(hwnd
, &rc1
);
840 /* draw a black border on the _outside_ */
841 FrameRect(hdc
, &rc1
, (HBRUSH
) GetStockObject(BLACK_BRUSH
));
843 /* we want to draw _just inside_ the black border */
844 InflateRect(&rc1
, -1, -1);
846 /* one line thick so far... */
847 // Offset = (WORD) 1;
849 /* for 3D stuff, we need to have at least two shades of gray */
850 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
852 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_OUT
);
853 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
855 Draw3DFaceFrame(hdc
, &rc1
, pgauge
->wWidthBezelFace
);
856 InflateRect(&rc1
, ~(pgauge
->wWidthBezelFace
), ~(pgauge
->wWidthBezelFace
));
858 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_IN
);
859 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
861 /* draw a black border on the _inside_ */
862 FrameRect(hdc
, &rc1
, (HBRUSH
) GetStockObject(BLACK_BRUSH
));
864 /* we want to draw _just inside_ the black border */
865 InflateRect(&rc1
, -1, -1);
867 /* add all the other pixels into the border width */
868 Offset
+= (2 * pgauge
->wWidth3D
) + pgauge
->wWidthBezelFace
+ 1;
871 /* dup--one rc for 'how much filled', one rc for 'how much empty' */
874 /* get the range--make sure it's a valid range */
875 if ((iRange
= pgauge
->wRange
) <= 0)
878 /* get the position--greater than 100% would be bad */
879 if ((iPos
= pgauge
->wPosition
) > iRange
)
882 /* compute the actual size of the gauge */
883 dx
= rc1
.right
- rc1
.left
;
884 dy
= rc1
.bottom
- rc1
.top
;
885 wGomerX
= (WORD
)((DWORD
)iPos
* dx
/ iRange
);
886 wGomerY
= (WORD
)((DWORD
)iPos
* dy
/ iRange
);
888 /* get the orientation and munge rects accordingly */
889 switch (pgauge
->wOrientation
)
891 case ZYZG_ORIENT_RIGHTTOLEFT
:
892 rc1
.left
= rc2
.right
= rc1
.right
- wGomerX
;
895 case ZYZG_ORIENT_BOTTOMTOTOP
:
896 rc1
.top
= rc2
.bottom
= rc1
.bottom
- wGomerY
;
899 case ZYZG_ORIENT_TOPTOBOTTOM
:
900 rc1
.bottom
= rc2
.top
+= wGomerY
;
904 rc1
.right
= rc2
.left
+= wGomerX
;
908 /* select the correct font */
909 hFont
= (HFONT
) SelectObject(hdc
, pgauge
->hFont
);
911 /* build up a string to blit out--ie the meaning of life: "42%" */
912 wsprintf(ach
, T("%3d%%"), (WORD
)((DWORD
)iPos
* 100 / iRange
));
913 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */
914 #if defined(__WIN32__)
915 GetTextExtentPoint(hdc
, ach
, wGomerX
= lstrlen(ach
), &size
);
918 dwExtent
= GetTextExtent(hdc
, ach
, wGomerX
= lstrlen(ach
));
922 /* Draw the finished (ie the percent done) side of box. If
923 * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut
924 * draws the meaning of life (42%) bar.
926 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
927 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
928 ETO_OPAQUE
| ETO_CLIPPED
, &rc2
, ach
, wGomerX
, NULL
);
930 /* Reverse fore and back colors for drawing the undone (ie the non-
931 * finished) side of the box.
933 SetBkColor(hdc
, pgauge
->rgbTextColor
);
934 SetTextColor(hdc
, pgauge
->rgbBkColor
);
936 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
937 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
938 ETO_OPAQUE
| ETO_CLIPPED
, &rc1
, ach
, wGomerX
, NULL
);
940 /* unselect the font */
941 SelectObject(hdc
, hFont
);
945 /** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
948 * This is the control's window procedure. Its purpose is to handle
949 * special messages for this custom control.
951 * The special control messages for the gauge control are:
953 * ZYZG_SETRANGE : Sets the range of the gauge. In other
954 * words, the number of parts that make a
957 * ZYZG_GETRANGE : Returns the current range of the gauge.
959 * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
960 * can be one of the ZYZG_ORIENT_?? msgs.
962 * ZYZG_GETORIENTATION : Gets the current orientation of the
965 * ZYZG_SETPOSITION : Sets the current position of the gauge.
966 * In other words, how many pieces of the
967 * whole have been used.
969 * ZYZG_GETPOSITION : Gets the current position of the gauge.
971 * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
974 * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
976 * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
978 * ZYZG_SETBKCOLOR : Sets the background (percent not done)
981 * ZYZG_GETBKCOLOR : Gets the background (percent not done)
984 * WM_SETFONT : Sets the font to use for the percentage
987 * WM_GETFONT : Gets the current font in use by the
994 /* LRESULT FAR PASCAL */
996 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1003 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
1004 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
1006 /* break to get DefWindowProc() */
1010 /* need to allocate a control block */
1011 // pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
1012 pgauge
= (PZYZGAUGE
)malloc(sizeof(ZYZGAUGE
));
1016 /* hang on to this control block */
1017 // SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
1018 SetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
, (LONG
)pgauge
);
1020 /* fill control block with defaults */
1021 pgauge
->wRange
= ZYZG_DEF_RANGE
;
1022 pgauge
->wPosition
= ZYZG_DEF_POSITION
;
1023 pgauge
->wOrientation
= ZYZG_DEF_ORIENTATION
;
1024 pgauge
->wWidth3D
= ZYZG_DEF_WIDTH3D
;
1025 pgauge
->wWidthBezelFace
= ZYZG_DEF_BEZELFACE
;
1026 pgauge
->rgbTextColor
= rgbDefTextColor
;
1027 pgauge
->rgbBkColor
= rgbDefBkColor
;
1029 /* use system font */
1030 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)NULL
, 0L);
1032 /* go to DefWindowProc() to finish the job */
1036 /* get rid of the control's memory */
1038 // LocalFree((HANDLE)pgauge);
1042 case ZYZG_GETPOSITION
:
1043 return (pgauge
->wPosition
);
1046 return (pgauge
->wRange
);
1048 case ZYZG_GETORIENTATION
:
1049 return (pgauge
->wOrientation
);
1051 case ZYZG_GETWIDTH3D
:
1052 return (pgauge
->wWidth3D
);
1054 case ZYZG_GETBEZELFACE
:
1055 return (pgauge
->wWidthBezelFace
);
1057 case ZYZG_GETBKCOLOR
:
1058 return (pgauge
->rgbTextColor
);
1060 case ZYZG_GETFGCOLOR
:
1061 return (pgauge
->rgbBkColor
);
1063 case ZYZG_SETBKCOLOR
:
1064 pgauge
->rgbBkColor
= lParam
;
1067 case ZYZG_SETFGCOLOR
:
1068 pgauge
->rgbTextColor
= lParam
;
1072 case ZYZG_SETPOSITION
:
1073 pgauge
->wPosition
= wParam
;
1076 GetClientRect(hwnd
, &rc
);
1077 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
1079 wParam
= (2 * pgauge
->wWidth3D
) +
1080 pgauge
->wWidthBezelFace
+ 2;
1086 InflateRect(&rc
, ~(wParam
), ~(wParam
));
1087 InvalidateRect(hwnd
, &rc
, FALSE
);
1092 pgauge
->wRange
= wParam
;
1093 goto zyzgForceRepaint
;
1095 case ZYZG_SETORIENTATION
:
1096 pgauge
->wOrientation
= wParam
;
1097 goto zyzgForceRepaint
;
1099 case ZYZG_SETWIDTH3D
:
1100 pgauge
->wWidth3D
= wParam
;
1103 InvalidateRect(hwnd
, NULL
, FALSE
);
1107 case ZYZG_SETBEZELFACE
:
1108 pgauge
->wWidthBezelFace
= wParam
;
1109 goto zyzgForceRepaint3D
;
1111 case ZYZG_SETDELTAPOS
:
1112 /* Watcom doesn't like the following line so removing typecasts */
1113 /* (int)pgauge->wPosition += (int)wParam; */
1114 pgauge
->wPosition
+= wParam
;
1115 goto zyzgForceRepaint
;
1118 BeginPaint(hwnd
, &ps
);
1119 gaugePaint(hwnd
, ps
.hdc
);
1120 EndPaint(hwnd
, &ps
);
1124 hFont
= pgauge
->hFont
;
1126 /* if system font, then return NULL handle */
1127 return (long)((hFont
== GetStockObject(SYSTEM_FONT
)) ? NULL
: hFont
);
1130 /* if NULL hFont, use system font */
1131 hFont
= (HFONT
)wParam
;
1133 hFont
= (HFONT
) GetStockObject(SYSTEM_FONT
);
1135 pgauge
->hFont
= hFont
;
1137 /* redraw if indicated in message */
1140 InvalidateRect(hwnd
, NULL
, TRUE
);
1146 /* let the dialog mangler take care of this message */
1147 return (DefWindowProc(hwnd
, uMsg
, wParam
, lParam
));
1148 } /* gaugeWndProc() */
1151 /** EOF: zyzgauge.c **/
1153 #endif // wxUSE_GAUGE