]>
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 if ((hdc
= CreateIC(_T("DISPLAY"), NULL
, NULL
, 0L)))
759 /* check for mono-display */
760 if ((GetDeviceCaps(hdc
, BITSPIXEL
) == 1) &&
761 (GetDeviceCaps(hdc
, PLANES
) == 1))
763 /* using a mono DC--white foreground, black background */
764 rgbDefTextColor
= RGB(255, 255, 255);
765 rgbDefBkColor
= RGB(0, 0, 0);
768 /* good! we have color: blue foreground, white background */
771 rgbDefTextColor
= RGB(0, 0, 255);
772 rgbDefBkColor
= RGB(255, 255, 255);
775 /* need at _least_ 8 for two shades of gray (>=VGA) */
776 fSupport3D
= (GetDeviceCaps(hdc
, NUMCOLORS
) >= 8) ? TRUE
: FALSE
;
778 /* get rid of the DC (IC) */
782 /* uh-oh... can't get DC (IC)... fail */
785 /* unregister the class */
786 UnregisterClass(gszzYzGaugeClass
, hInstance
);
791 return (fRegistered
= TRUE
);
795 /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc)
798 * This function is responsible for painting the zYzGauge control.
801 * HWND hwnd : The window handle for the gauge.
803 * HDC hdc : The DC for the gauge's window.
806 * The control will have been painted.
812 static void PASCAL
gaugePaint(HWND hwnd
, HDC hdc
)
821 WORD dx
, dy
, wGomerX
, wGomerY
;
822 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead,
823 * which needs a SIZE* parameter */
824 #if defined(__WIN32__)
828 /* get pointer to the control's control block */
829 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
830 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
832 /* set the colors into for the gauge into the control */
833 SetTextColor(hdc
, pgauge
->rgbTextColor
);
834 SetBkColor(hdc
, pgauge
->rgbBkColor
);
836 /* draw black rectangle for gauge */
837 GetClientRect(hwnd
, &rc1
);
839 /* draw a black border on the _outside_ */
840 FrameRect(hdc
, &rc1
, (HBRUSH
) GetStockObject(BLACK_BRUSH
));
842 /* we want to draw _just inside_ the black border */
843 InflateRect(&rc1
, -1, -1);
845 /* one line thick so far... */
846 // Offset = (WORD) 1;
848 /* for 3D stuff, we need to have at least two shades of gray */
849 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
851 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_OUT
);
852 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
854 Draw3DFaceFrame(hdc
, &rc1
, pgauge
->wWidthBezelFace
);
855 InflateRect(&rc1
, ~(pgauge
->wWidthBezelFace
), ~(pgauge
->wWidthBezelFace
));
857 Draw3DRect(hdc
, &rc1
, pgauge
->wWidth3D
, DRAW3D_IN
);
858 InflateRect(&rc1
, ~(pgauge
->wWidth3D
), ~(pgauge
->wWidth3D
));
860 /* draw a black border on the _inside_ */
861 FrameRect(hdc
, &rc1
, (HBRUSH
) GetStockObject(BLACK_BRUSH
));
863 /* we want to draw _just inside_ the black border */
864 InflateRect(&rc1
, -1, -1);
866 /* add all the other pixels into the border width */
867 Offset
+= (2 * pgauge
->wWidth3D
) + pgauge
->wWidthBezelFace
+ 1;
870 /* dup--one rc for 'how much filled', one rc for 'how much empty' */
873 /* get the range--make sure it's a valid range */
874 if ((iRange
= pgauge
->wRange
) <= 0)
877 /* get the position--greater than 100% would be bad */
878 if ((iPos
= pgauge
->wPosition
) > iRange
)
881 /* compute the actual size of the gauge */
882 dx
= rc1
.right
- rc1
.left
;
883 dy
= rc1
.bottom
- rc1
.top
;
884 wGomerX
= (WORD
)((DWORD
)iPos
* dx
/ iRange
);
885 wGomerY
= (WORD
)((DWORD
)iPos
* dy
/ iRange
);
887 /* get the orientation and munge rects accordingly */
888 switch (pgauge
->wOrientation
)
890 case ZYZG_ORIENT_RIGHTTOLEFT
:
891 rc1
.left
= rc2
.right
= rc1
.right
- wGomerX
;
894 case ZYZG_ORIENT_BOTTOMTOTOP
:
895 rc1
.top
= rc2
.bottom
= rc1
.bottom
- wGomerY
;
898 case ZYZG_ORIENT_TOPTOBOTTOM
:
899 rc1
.bottom
= rc2
.top
+= wGomerY
;
903 rc1
.right
= rc2
.left
+= wGomerX
;
907 /* select the correct font */
908 hFont
= (HFONT
) SelectObject(hdc
, pgauge
->hFont
);
910 /* build up a string to blit out--ie the meaning of life: "42%" */
911 wsprintf(ach
, _T("%3d%%"), (WORD
)((DWORD
)iPos
* 100 / iRange
));
912 /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */
913 #if defined(__WIN32__)
914 GetTextExtentPoint(hdc
, ach
, wGomerX
= lstrlen(ach
), &size
);
917 dwExtent
= GetTextExtent(hdc
, ach
, wGomerX
= lstrlen(ach
));
921 /* Draw the finished (ie the percent done) side of box. If
922 * ZYZG_WW_POSITION is 42, (in range of 0 to 100) this ExtTextOut
923 * draws the meaning of life (42%) bar.
925 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
926 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
927 ETO_OPAQUE
| ETO_CLIPPED
, &rc2
, ach
, wGomerX
, NULL
);
929 /* Reverse fore and back colors for drawing the undone (ie the non-
930 * finished) side of the box.
932 SetBkColor(hdc
, pgauge
->rgbTextColor
);
933 SetTextColor(hdc
, pgauge
->rgbBkColor
);
935 ExtTextOut(hdc
, (dx
- LOWORD(dwExtent
)) / 2 + Offset
,
936 (dy
- HIWORD(dwExtent
)) / 2 + Offset
,
937 ETO_OPAQUE
| ETO_CLIPPED
, &rc1
, ach
, wGomerX
, NULL
);
939 /* unselect the font */
940 SelectObject(hdc
, hFont
);
944 /** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
947 * This is the control's window procedure. Its purpose is to handle
948 * special messages for this custom control.
950 * The special control messages for the gauge control are:
952 * ZYZG_SETRANGE : Sets the range of the gauge. In other
953 * words, the number of parts that make a
956 * ZYZG_GETRANGE : Returns the current range of the gauge.
958 * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This
959 * can be one of the ZYZG_ORIENT_?? msgs.
961 * ZYZG_GETORIENTATION : Gets the current orientation of the
964 * ZYZG_SETPOSITION : Sets the current position of the gauge.
965 * In other words, how many pieces of the
966 * whole have been used.
968 * ZYZG_GETPOSITION : Gets the current position of the gauge.
970 * ZYZG_SETDELTAPOS : Sets the position of the gauge +/- the
973 * ZYZG_SETFGCOLOR : Sets the foreground (percent done) color.
975 * ZYZG_GETFGCOLOR : Gets the foreground (percent done) color.
977 * ZYZG_SETBKCOLOR : Sets the background (percent not done)
980 * ZYZG_GETBKCOLOR : Gets the background (percent not done)
983 * WM_SETFONT : Sets the font to use for the percentage
986 * WM_GETFONT : Gets the current font in use by the
993 /* LRESULT FAR PASCAL */
995 LRESULT APIENTRY _EXPORT
gaugeWndProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
1002 // pgauge = (PZYZGAUGE)GetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE);
1003 pgauge
= (PZYZGAUGE
)GetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
);
1005 /* break to get DefWindowProc() */
1009 /* need to allocate a control block */
1010 // pgauge = (PZYZGAUGE)LocalAlloc(LPTR, sizeof(ZYZGAUGE));
1011 pgauge
= (PZYZGAUGE
)malloc(sizeof(ZYZGAUGE
));
1015 /* hang on to this control block */
1016 // SetWindowWord(hwnd, ZYZG_WW_PZYZGAUGE, (WORD)pgauge);
1017 SetWindowLong(hwnd
, ZYZG_WW_PZYZGAUGE
, (LONG
)pgauge
);
1019 /* fill control block with defaults */
1020 pgauge
->wRange
= ZYZG_DEF_RANGE
;
1021 pgauge
->wPosition
= ZYZG_DEF_POSITION
;
1022 pgauge
->wOrientation
= ZYZG_DEF_ORIENTATION
;
1023 pgauge
->wWidth3D
= ZYZG_DEF_WIDTH3D
;
1024 pgauge
->wWidthBezelFace
= ZYZG_DEF_BEZELFACE
;
1025 pgauge
->rgbTextColor
= rgbDefTextColor
;
1026 pgauge
->rgbBkColor
= rgbDefBkColor
;
1028 /* use system font */
1029 SendMessage(hwnd
, WM_SETFONT
, (WPARAM
)NULL
, 0L);
1031 /* go to DefWindowProc() to finish the job */
1035 /* get rid of the control's memory */
1037 // LocalFree((HANDLE)pgauge);
1041 case ZYZG_GETPOSITION
:
1042 return (pgauge
->wPosition
);
1045 return (pgauge
->wRange
);
1047 case ZYZG_GETORIENTATION
:
1048 return (pgauge
->wOrientation
);
1050 case ZYZG_GETWIDTH3D
:
1051 return (pgauge
->wWidth3D
);
1053 case ZYZG_GETBEZELFACE
:
1054 return (pgauge
->wWidthBezelFace
);
1056 case ZYZG_GETBKCOLOR
:
1057 return (pgauge
->rgbTextColor
);
1059 case ZYZG_GETFGCOLOR
:
1060 return (pgauge
->rgbBkColor
);
1062 case ZYZG_SETBKCOLOR
:
1063 pgauge
->rgbBkColor
= lParam
;
1066 case ZYZG_SETFGCOLOR
:
1067 pgauge
->rgbTextColor
= lParam
;
1071 case ZYZG_SETPOSITION
:
1072 pgauge
->wPosition
= wParam
;
1075 GetClientRect(hwnd
, &rc
);
1076 if ((GetWindowLong(hwnd
, GWL_STYLE
) & ZYZGS_3D
) && fSupport3D
)
1078 wParam
= (2 * pgauge
->wWidth3D
) +
1079 pgauge
->wWidthBezelFace
+ 2;
1085 InflateRect(&rc
, ~(wParam
), ~(wParam
));
1086 InvalidateRect(hwnd
, &rc
, FALSE
);
1091 pgauge
->wRange
= wParam
;
1092 goto zyzgForceRepaint
;
1094 case ZYZG_SETORIENTATION
:
1095 pgauge
->wOrientation
= wParam
;
1096 goto zyzgForceRepaint
;
1098 case ZYZG_SETWIDTH3D
:
1099 pgauge
->wWidth3D
= wParam
;
1102 InvalidateRect(hwnd
, NULL
, FALSE
);
1106 case ZYZG_SETBEZELFACE
:
1107 pgauge
->wWidthBezelFace
= wParam
;
1108 goto zyzgForceRepaint3D
;
1110 case ZYZG_SETDELTAPOS
:
1111 /* Watcom doesn't like the following line so removing typecasts */
1112 /* (int)pgauge->wPosition += (int)wParam; */
1113 pgauge
->wPosition
+= wParam
;
1114 goto zyzgForceRepaint
;
1117 BeginPaint(hwnd
, &ps
);
1118 gaugePaint(hwnd
, ps
.hdc
);
1119 EndPaint(hwnd
, &ps
);
1123 hFont
= pgauge
->hFont
;
1125 /* if system font, then return NULL handle */
1126 return (long)((hFont
== GetStockObject(SYSTEM_FONT
)) ? NULL
: hFont
);
1129 /* if NULL hFont, use system font */
1130 if (!(hFont
= (HFONT
)wParam
))
1131 hFont
= (HFONT
) GetStockObject(SYSTEM_FONT
);
1133 pgauge
->hFont
= hFont
;
1135 /* redraw if indicated in message */
1138 InvalidateRect(hwnd
, NULL
, TRUE
);
1144 /* let the dialog mangler take care of this message */
1145 return (DefWindowProc(hwnd
, uMsg
, wParam
, lParam
));
1146 } /* gaugeWndProc() */
1149 /** EOF: zyzgauge.c **/
1151 #endif // wxUSE_GAUGE