X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da87a1ca42a81c7b7b69cb013eb52d09cd5c1b70..4a46a5df879c4f820d0a0a435b34c7d5e4793991:/src/msw/gaugemsw.cpp?ds=sidebyside diff --git a/src/msw/gaugemsw.cpp b/src/msw/gaugemsw.cpp index 2edc0586e2..380a30e516 100644 --- a/src/msw/gaugemsw.cpp +++ b/src/msw/gaugemsw.cpp @@ -6,7 +6,7 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -22,9 +22,10 @@ #ifndef WX_PRECOMP #include "wx/defs.h" +#include "wx/utils.h" #endif -#if USE_GAUGE +#if wxUSE_GAUGE #include "wx/msw/gaugemsw.h" #include "wx/msw/private.h" @@ -59,15 +60,13 @@ /* public function prototypes */ BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance); -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxGaugeMSW, wxControl) -#endif -bool wxGaugeMSW::Create(wxWindow *parent, const wxWindowID id, - const int range, +bool wxGaugeMSW::Create(wxWindow *parent, wxWindowID id, + int range, const wxPoint& pos, const wxSize& size, - const long style, + long style, const wxValidator& validator, const wxString& name) { @@ -75,26 +74,29 @@ bool wxGaugeMSW::Create(wxWindow *parent, const wxWindowID id, if ( !wxGaugeMSWInitialised ) { - if (!gaugeInit((HWND) wxGetInstance())) - wxFatalError("Cannot initalize Gauge library"); - wxGaugeMSWInitialised = TRUE; + if (!gaugeInit((HINSTANCE) wxGetInstance())) + wxFatalError("Cannot initalize Gauge library"); + wxGaugeMSWInitialised = TRUE; } SetName(name); +#if wxUSE_VALIDATORS SetValidator(validator); +#endif // wxUSE_VALIDATORS if (parent) parent->AddChild(this); m_rangeMax = range; + m_gaugePos = 0; - SetBackgroundColour(parent->GetDefaultBackgroundColour()) ; - SetForegroundColour(parent->GetDefaultForegroundColour()) ; + SetBackgroundColour(parent->GetBackgroundColour()) ; + SetForegroundColour(parent->GetForegroundColour()) ; m_windowStyle = style; if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -102,10 +104,16 @@ bool wxGaugeMSW::Create(wxWindow *parent, const wxWindowID id, int height = size.y; long msFlags = WS_CHILD | WS_VISIBLE | WS_TABSTOP; - msFlags |= ZYZGS_3D; + bool want3D; + WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D); + if (want3D) + msFlags |= ZYZGS_3D; + + if ( m_windowStyle & wxCLIP_SIBLINGS ) + msFlags |= WS_CLIPSIBLINGS; HWND wx_button = - CreateWindowEx(MakeExtendedStyle(m_windowStyle), "zYzGauge", NULL, msFlags, + CreateWindowEx(MakeExtendedStyle(m_windowStyle), wxT("zYzGauge"), NULL, msFlags, 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, wxGetInstance(), NULL); @@ -120,14 +128,17 @@ bool wxGaugeMSW::Create(wxWindow *parent, const wxWindowID id, wOrient = ZYZG_ORIENT_LEFTTORIGHT; else wOrient = ZYZG_ORIENT_BOTTOMTOTOP; - + SendMessage(wx_button, ZYZG_SETORIENTATION, wOrient, 0); SendMessage(wx_button, ZYZG_SETRANGE, range, 0); - SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); - SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, PALETTERGB(GetForegroundColour().Red(), GetForegroundColour().Green(), GetForegroundColour().Blue())); + SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, PALETTERGB(GetBackgroundColour().Red(), GetBackgroundColour().Green(), GetBackgroundColour().Blue())); + + //SetBezelFace(1); + //SetShadowWidth(1); - SetFont(* parent->GetFont()); + SetFont(parent->GetFont()); if (width == -1) width = 50; @@ -135,109 +146,79 @@ bool wxGaugeMSW::Create(wxWindow *parent, const wxWindowID id, height = 50; SetSize(x, y, width, height); - ShowWindow((HWND) GetHWND(), SW_SHOW); + ShowWindow(GetHwnd(), SW_SHOW); return TRUE; } -void wxGaugeMSW::SetSize(const int x, const int y, const int width, const int height, const int sizeFlags) +void wxGaugeMSW::SetShadowWidth(int w) { - int currentX, currentY; - GetPosition(¤tX, ¤tY); - int x1 = x; - int y1 = y; - int w1 = width; - int h1 = height; - - if (x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - x1 = currentX; - if (y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) - y1 = currentY; - - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - - // Deal with default size (using -1 values) - if (w1<=0) - w1 = DEFAULT_ITEM_WIDTH; - - if (h1<=0) - h1 = DEFAULT_ITEM_HEIGHT; - - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - -#if WXWIN_COMPATIBILITY - GetEventHandler()->OldOnSize(width, height); -#else - wxSizeEvent event(wxSize(width, height), m_windowId); - event.eventObject = this; - GetEventHandler()->ProcessEvent(event); -#endif + SendMessage(GetHwnd(), ZYZG_SETWIDTH3D, w, 0); } -void wxGaugeMSW::SetShadowWidth(const int w) +void wxGaugeMSW::SetBezelFace(int w) { - SendMessage((HWND) GetHWND(), ZYZG_SETWIDTH3D, w, 0); + SendMessage(GetHwnd(), ZYZG_SETBEZELFACE, w, 0); } -void wxGaugeMSW::SetBezelFace(const int w) -{ - SendMessage((HWND) GetHWND(), ZYZG_SETBEZELFACE, w, 0); -} - -void wxGaugeMSW::SetRange(const int r) +void wxGaugeMSW::SetRange(int r) { m_rangeMax = r; - SendMessage((HWND) GetHWND(), ZYZG_SETRANGE, r, 0); + SendMessage(GetHwnd(), ZYZG_SETRANGE, r, 0); } -void wxGaugeMSW::SetValue(const int pos) +void wxGaugeMSW::SetValue(int pos) { m_gaugePos = pos; - SendMessage((HWND) GetHWND(), ZYZG_SETPOSITION, pos, 0); + SendMessage(GetHwnd(), ZYZG_SETPOSITION, pos, 0); } int wxGaugeMSW::GetShadowWidth(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETWIDTH3D, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETWIDTH3D, 0, 0); } int wxGaugeMSW::GetBezelFace(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETBEZELFACE, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETBEZELFACE, 0, 0); } int wxGaugeMSW::GetRange(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETRANGE, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETRANGE, 0, 0); } int wxGaugeMSW::GetValue(void) const { - return (int) SendMessage((HWND) GetHWND(), ZYZG_GETPOSITION, 0, 0); + return (int) SendMessage(GetHwnd(), ZYZG_GETPOSITION, 0, 0); } -void wxGaugeMSW::SetForegroundColour(const wxColour& col) +bool wxGaugeMSW::SetForegroundColour(const wxColour& col) { - m_foregroundColour = col ; - SendMessage((HWND) GetHWND(), ZYZG_SETFGCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); + if ( !wxControl::SetForegroundColour(col) ) + return FALSE; + + SendMessage(GetHwnd(), ZYZG_SETFGCOLOR, 0, PALETTERGB(col.Red(), col.Green(), col.Blue())); + + return TRUE; } -void wxGaugeMSW::SetBackgroundColour(const wxColour& col) +bool wxGaugeMSW::SetBackgroundColour(const wxColour& col) { - m_backgroundColour = col ; - SendMessage((HWND) GetHWND(), ZYZG_SETBKCOLOR, 0, RGB(col.Red(), col.Green(), col.Blue())); + if ( !wxControl::SetBackgroundColour(col) ) + return FALSE; + + SendMessage(GetHwnd(), ZYZG_SETBKCOLOR, 0, PALETTERGB(col.Red(), col.Green(), col.Blue())); + + return TRUE; } /** zyz3d.c * - * DESCRIPTION: + * DESCRIPTION: * This module contains functions for creating nifty 3D borders * around controls like zYzGauge. * @@ -279,7 +260,7 @@ void FAR PASCAL Draw3DLine(HDC, WORD, WORD, WORD, WORD, WORD); /** void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth) * - * DESCRIPTION: + * DESCRIPTION: * This function draws a flat frame with the current button-face * color. * @@ -349,7 +330,7 @@ void FAR PASCAL Draw3DFaceFrame(HDC hdc, LPRECT rc, WORD wWidth) /** void FAR PASCAL Draw3DRect(HDC, LPRECT, WORD, WORD) * - * DESCRIPTION: + * DESCRIPTION: * Draws a 3D rectangle that is shaded. wFlags can be used to * control how the rectangle looks. * @@ -411,7 +392,7 @@ void FAR PASCAL Draw3DRect(HDC hdc, LPRECT lpRect, /** void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, * - * DESCRIPTION: + * DESCRIPTION: * Draws a 3D line that can be used to make a 3D box. * * ARGUMENTS: @@ -450,7 +431,7 @@ void FAR PASCAL Draw3DRect(HDC hdc, LPRECT lpRect, ** cjp */ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, - WORD wShadowWidth, WORD wFlags) + WORD wShadowWidth, WORD wFlags) { HBRUSH hOldBrush; HPEN hOldPen; @@ -465,7 +446,7 @@ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, Point[0].x = x; Point[0].y = y; - /* To do this we'll simply draw a polygon with four sides, using + /* To do this we'll simply draw a polygon with four sides, using * the appropriate brush. I dare you to ask me why this isn't a * switch/case! */ @@ -524,7 +505,7 @@ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, /* select 'dark' brush if 'in'--'light' for 'out' */ fDark = (wFlags & DRAW3D_IN) ? TRUE : FALSE; } - + /* well maybe it's for the right side? */ else if (wFlags & DRAW3D_RIGHTLINE) { @@ -548,13 +529,13 @@ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, else return; /* select NULL_PEN for no borders */ - hOldPen = SelectObject(hdc, GetStockObject(NULL_PEN)); + hOldPen = (HPEN) SelectObject(hdc, GetStockObject(NULL_PEN)); /* select the appropriate color for the fill */ if (fDark) - hOldBrush = SelectObject(hdc, GetStockObject(GRAY_BRUSH)); + hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(GRAY_BRUSH)); else - hOldBrush = SelectObject(hdc, GetStockObject(WHITE_BRUSH)); + hOldBrush = (HBRUSH) SelectObject(hdc, GetStockObject(WHITE_BRUSH)); /* finally, draw the dern thing */ Polygon(hdc, (LPPOINT)&Point, 4); @@ -568,7 +549,7 @@ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, /** zyzgauge.c * - * DESCRIPTION: + * DESCRIPTION: * Yet another 'Gas Gauge Custom Control.' This control gives you * a 'progress bar' class (named zYzGauge) for use in your applications. * You can set the range, position, font, color, orientation, and 3d @@ -659,7 +640,7 @@ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, /* get the includes we need */ -#ifndef __GNUWIN32__ +#if !defined(__GNUWIN32__) && !defined(__SALFORDC__) #include #endif #include @@ -670,8 +651,8 @@ void FAR PASCAL Draw3DLine(HDC hdc, WORD x, WORD y, WORD nLen, /* static global variables */ -static char gszzYzGaugeClass[] = "zYzGauge"; - +static wxChar gszzYzGaugeClass[] = wxT("zYzGauge"); + /* window word position definitions */ #define ZYZG_WW_PZYZGAUGE 0 @@ -708,10 +689,10 @@ static DWORD rgbDefTextColor; static DWORD rgbDefBkColor; static BOOL fSupport3D; -#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not +#if !defined(APIENTRY) // NT defines APIENTRY, 3.x not #define APIENTRY FAR PASCAL #endif - + #ifdef __WIN32__ #define _EXPORT /**/ #else @@ -728,7 +709,7 @@ LRESULT APIENTRY _EXPORT gaugeWndProc(HWND, UINT, WPARAM, LPARAM); /** BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) * - * DESCRIPTION: + * DESCRIPTION: * Registers the window class for the zYzGauge control. Performs * other initialization for the zYzGauge text control. This must * be done before the zYzGauge control is used--or it will fail @@ -752,7 +733,7 @@ BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) static BOOL fRegistered = FALSE; WNDCLASS wc; HDC hdc; - + /* assume already registered if not first instance */ if (fRegistered) return (TRUE); @@ -782,7 +763,8 @@ BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) /* Get a DC to determine whether device is mono or not, and set * default foreground/background colors as appropriate. */ - if ((hdc = CreateIC("DISPLAY", NULL, NULL, 0L))) + hdc = CreateIC(wxT("DISPLAY"), NULL, NULL, 0L) ; + if (hdc) { /* check for mono-display */ if ((GetDeviceCaps(hdc, BITSPIXEL) == 1) && @@ -794,7 +776,7 @@ BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) } /* good! we have color: blue foreground, white background */ - else + else { rgbDefTextColor = RGB(0, 0, 255); rgbDefBkColor = RGB(255, 255, 255); @@ -822,7 +804,7 @@ BOOL FAR PASCAL gaugeInit(HINSTANCE hInstance) /** static void PASCAL gaugePaint(HWND hwnd, HDC hdc) * - * DESCRIPTION: + * DESCRIPTION: * This function is responsible for painting the zYzGauge control. * * ARGUMENTS: @@ -845,7 +827,7 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) DWORD dwExtent; RECT rc1, rc2; HFONT hFont; - char ach[ 6 ]; + wxChar ach[ 6 ]; WORD dx, dy, wGomerX, wGomerY; /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead, * which needs a SIZE* parameter */ @@ -865,7 +847,7 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) GetClientRect(hwnd, &rc1); /* draw a black border on the _outside_ */ - FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH)); + FrameRect(hdc, &rc1, (HBRUSH) GetStockObject(BLACK_BRUSH)); /* we want to draw _just inside_ the black border */ InflateRect(&rc1, -1, -1); @@ -877,16 +859,16 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) if ((GetWindowLong(hwnd, GWL_STYLE) & ZYZGS_3D) && fSupport3D) { Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_OUT); - InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); + InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); Draw3DFaceFrame(hdc, &rc1, pgauge->wWidthBezelFace); - InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace)); + InflateRect(&rc1, ~(pgauge->wWidthBezelFace), ~(pgauge->wWidthBezelFace)); Draw3DRect(hdc, &rc1, pgauge->wWidth3D, DRAW3D_IN); - InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); + InflateRect(&rc1, ~(pgauge->wWidth3D), ~(pgauge->wWidth3D)); /* draw a black border on the _inside_ */ - FrameRect(hdc, &rc1, GetStockObject(BLACK_BRUSH)); + FrameRect(hdc, &rc1, (HBRUSH) GetStockObject(BLACK_BRUSH)); /* we want to draw _just inside_ the black border */ InflateRect(&rc1, -1, -1); @@ -894,7 +876,7 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) /* add all the other pixels into the border width */ Offset += (2 * pgauge->wWidth3D) + pgauge->wWidthBezelFace + 1; } - + /* dup--one rc for 'how much filled', one rc for 'how much empty' */ rc2 = rc1; @@ -933,17 +915,17 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) } /* switch () */ /* select the correct font */ - hFont = SelectObject(hdc, pgauge->hFont); + hFont = (HFONT) SelectObject(hdc, pgauge->hFont); /* build up a string to blit out--ie the meaning of life: "42%" */ - wsprintf(ach, "%3d%%", (WORD)((DWORD)iPos * 100 / iRange)); + wsprintf(ach, wxT("%3d%%"), (WORD)((DWORD)iPos * 100 / iRange)); /* Win32s has no GetTextExtent(); let's try GetTextExtentPoint() instead */ #if defined(__WIN32__) GetTextExtentPoint(hdc, ach, wGomerX = lstrlen(ach), &size); dwExtent = size.cx; #else dwExtent = GetTextExtent(hdc, ach, wGomerX = lstrlen(ach)); -#endif +#endif /* Draw the finished (ie the percent done) side of box. If @@ -967,11 +949,11 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) /* unselect the font */ SelectObject(hdc, hFont); } /* gaugePaint() */ - + /** LRESULT FAR PASCAL gaugeWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) * - * DESCRIPTION: + * DESCRIPTION: * This is the control's window procedure. Its purpose is to handle * special messages for this custom control. * @@ -986,7 +968,7 @@ static void PASCAL gaugePaint(HWND hwnd, HDC hdc) * ZYZG_SETORIENTATION : Sets the orientation of the gauge. This * can be one of the ZYZG_ORIENT_?? msgs. * - * ZYZG_GETORIENTATION : Gets the current orientation of the + * ZYZG_GETORIENTATION : Gets the current orientation of the * gauge. * * ZYZG_SETPOSITION : Sets the current position of the gauge. @@ -1110,7 +1092,7 @@ zyzgForceRepaint: else wParam = 1; - InflateRect(&rc, ~(wParam), ~(wParam)); + InflateRect(&rc, ~(wParam), ~(wParam)); InvalidateRect(hwnd, &rc, FALSE); UpdateWindow(hwnd); return (0L); @@ -1155,8 +1137,9 @@ zyzgForceRepaint3D: case WM_SETFONT: /* if NULL hFont, use system font */ - if (!(hFont = (HFONT)wParam)) - hFont = GetStockObject(SYSTEM_FONT); + hFont = (HFONT)wParam ; + if (!hFont) + hFont = (HFONT) GetStockObject(SYSTEM_FONT); pgauge->hFont = hFont; @@ -1176,4 +1159,4 @@ zyzgForceRepaint3D: /** EOF: zyzgauge.c **/ -#endif // USE_GAUGE +#endif // wxUSE_GAUGE