]> git.saurik.com Git - wxWidgets.git/blame - src/os2/gauge.cpp
implemented menu drawing in the GTK theme
[wxWidgets.git] / src / os2 / gauge.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: gauge.cpp
3// Purpose: wxGauge class
0371a691 4// Author: David Webster
0e320a79 5// Modified by:
0371a691 6// Created: 10/06/99
0e320a79 7// RCS-ID: $Id$
0371a691
DW
8// Copyright: (c) David Webster
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
0371a691
DW
12#include "wx/wxprec.h"
13
14#ifndef WX_PRECOMP
15#include "wx/defs.h"
16#include "wx/utils.h"
a4a16252 17#include "wx/scrolwin.h"
0e320a79
DW
18#endif
19
0371a691 20#include "wx/os2/private.h"
0e320a79
DW
21#include "wx/gauge.h"
22
3c299c3a
DW
23static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL;
24extern void wxAssociateWinWithHandle( HWND hWnd
25 ,wxWindowOS2* pWin
26 );
0371a691 27
0e320a79 28IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl)
0e320a79 29
3c299c3a
DW
30MRESULT EXPENTRY wxGaugeWndProc(
31 HWND hWnd
32, UINT uMessage
33, MPARAM wParam
34, MPARAM lParam
35)
0e320a79 36{
3c299c3a
DW
37 wxGauge* pGauge = (wxGauge *)::WinQueryWindowULong( hWnd
38 ,QWL_USER
39 );
40 wxWindowOS2* pWindow = NULL;
41 MRESULT rc = (MRESULT)0;
42 bool bProcessed = FALSE;
43 HPS hPS;
44 RECTL vRect;
45 RECTL vRect2;
46 double dPixelToRange = 0.0;
47 double dRange = 0.0;
48
49 switch (uMessage )
0371a691 50 {
3c299c3a
DW
51 case WM_PAINT:
52 hPS = ::WinBeginPaint( hWnd
53 ,NULLHANDLE
54 ,&vRect
55 );
56 if(hPS)
57 {
58 ::WinQueryWindowRect(hWnd, &vRect);
59 ::GpiCreateLogColorTable( hPS
60 ,0L
61 ,LCOLF_CONSECRGB
62 ,0L
63 ,(LONG)wxTheColourDatabase->m_nSize
64 ,(PLONG)wxTheColourDatabase->m_palTable
65 );
66 ::GpiCreateLogColorTable( hPS
67 ,0L
68 ,LCOLF_RGB
69 ,0L
70 ,0L
71 ,NULL
72 );
73 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
74 {
75 dRange = (double)(vRect.yTop - vRect.yBottom);
76 dPixelToRange = dRange/(double)pGauge->GetRange();
77 vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange);
78 vRect2.yBottom = vRect.yBottom;
79 vRect2.xLeft = vRect.xLeft;
80 vRect2.xRight = vRect.xRight;
81 vRect.yBottom = vRect2.yTop;
82 ::WinFillRect(hPS, &vRect, pGauge->GetBackgroundColour().GetPixel());
83 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
84 }
85 else
86 {
87 dRange = (double)(vRect.xRight - vRect.xLeft);
88 dPixelToRange = dRange/(double)pGauge->GetRange();
89 vRect2.yTop = vRect.yTop;
90 vRect2.yBottom = vRect.yBottom;
91 vRect2.xLeft = vRect.xLeft;
92 vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange);
93 vRect.xLeft = vRect2.xRight;
94 ::WinFillRect(hPS, &vRect, pGauge->GetBackgroundColour().GetPixel());
95 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
96 }
97 ::WinEndPaint(hPS);
98 }
0371a691 99 }
3c299c3a
DW
100 return (fnWndProcGauge( hWnd
101 ,(ULONG)uMessage
102 ,(MPARAM)wParam
103 ,(MPARAM)lParam
104 )
105 );
106} // end of wxGaugeWndProc
107
108bool wxGauge::Create(
109 wxWindowOS2* pParent
110, wxWindowID vId
111, int nRange
112, const wxPoint& rPos
113, const wxSize& rSize
114, long lStyle
115#if wxUSE_VALIDATORS
116, const wxValidator& rValidator
117#endif
118, const wxString& rsName
119)
120{
121 int nX = rPos.x;
122 int nY = rPos.y;
123 int nWidth = rSize.x;
124 int nHeight = rSize.y;
125 long lMsStyle = 0L;
d8a3f66c 126 SWP vSwp;
0371a691 127
3c299c3a 128 SetName(rsName);
5d4b632b 129#if wxUSE_VALIDATORS
3c299c3a 130 SetValidator(rValidator);
5d4b632b 131#endif
3c299c3a
DW
132 if (pParent)
133 pParent->AddChild(this);
134 SetBackgroundColour(pParent->GetBackgroundColour()) ;
135 SetForegroundColour(pParent->GetForegroundColour()) ;
0e320a79 136
3c299c3a
DW
137 m_nRangeMax = nRange;
138 m_nGaugePos = 0;
139 m_windowStyle = lStyle;
0e320a79 140
3c299c3a
DW
141 if (vId == -1)
142 m_windowId = (int)NewControlId();
0e320a79 143 else
3c299c3a
DW
144 m_windowId = vId;
145
146 if (m_windowStyle & wxCLIP_SIBLINGS )
147 lMsStyle |= WS_CLIPSIBLINGS;
148
149 //
150 // OS/2 will use an edit control for this, since there is not a native gauge
151 // Other choices include using an armless slider but they are more difficult
152 // to control and manipulate
153 //
154
155 lMsStyle = WS_VISIBLE | ES_MARGIN | ES_LEFT | ES_READONLY;
156 if (m_windowStyle & wxCLIP_SIBLINGS)
157 lMsStyle |= WS_CLIPSIBLINGS;
158
3c299c3a
DW
159 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
160 ,WC_ENTRYFIELD // Window class
161 ,(PSZ)NULL // Initial Text
162 ,(ULONG)lMsStyle // Style flags
163 ,0L, 0L, 0L, 0L // Origin -- 0 size
164 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
165 ,HWND_TOP // initial z position
166 ,(HMENU)m_windowId // Window identifier
167 ,NULL // Slider control data
168 ,NULL // no Presentation parameters
169 );
170
171 wxAssociateWinWithHandle( m_hWnd
172 ,(wxWindowOS2*)this
173 );
174 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
175 fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc);
d8a3f66c
DW
176 ::WinQueryWindowPos(m_hWnd, &vSwp);
177 SetXComp(vSwp.x);
178 SetYComp(vSwp.y);
b3260bce
DW
179 wxFont* pTextFont = new wxFont( 10
180 ,wxMODERN
181 ,wxNORMAL
182 ,wxNORMAL
183 );
184 SetFont(*pTextFont);
3c299c3a
DW
185 if (nWidth == -1L)
186 nWidth = 50L;
187 if (nHeight == -1L)
188 nHeight = 28L;
189 SetSize( nX
190 ,nY
191 ,nWidth
192 ,nHeight
193 );
194 ::WinShowWindow((HWND)GetHWND(), TRUE);
b3260bce 195 delete pTextFont;
3c299c3a
DW
196 return TRUE;
197} // end of wxGauge::Create
0e320a79 198
3c299c3a 199int wxGauge::GetBezelFace() const
0e320a79 200{
3c299c3a
DW
201 return 0;
202} // end of wxGauge::GetBezelFace
0e320a79 203
3c299c3a 204int wxGauge::GetRange() const
0e320a79 205{
3c299c3a
DW
206 return m_nRangeMax;
207} // end of wxGauge::GetRange
0e320a79
DW
208
209int wxGauge::GetShadowWidth() const
210{
0e320a79 211 return 0;
3c299c3a 212} // end of wxGauge::GetShadowWidth
0e320a79
DW
213
214int wxGauge::GetValue() const
215{
3c299c3a
DW
216 return m_nGaugePos;
217} // end of wxGauge::GetValue
0e320a79 218
3c299c3a
DW
219bool wxGauge::SetBackgroundColour(
220 const wxColour& rColour
221)
0371a691 222{
3c299c3a 223 if (!wxControl::SetBackgroundColour(rColour))
0371a691
DW
224 return FALSE;
225
3c299c3a 226 LONG lColor = (LONG)rColour.GetPixel();
0371a691 227
3c299c3a
DW
228 ::WinSetPresParam( GetHwnd()
229 ,PP_BACKGROUNDCOLOR
230 ,sizeof(LONG)
231 ,(PVOID)&lColor
232 );
0371a691 233 return TRUE;
3c299c3a 234} // end of wxGauge::SetBackgroundColour
0371a691 235
3c299c3a
DW
236void wxGauge::SetBezelFace(
237 int WXUNUSED(nWidth)
238)
0371a691 239{
3c299c3a 240} // end of wxGauge::SetBezelFace
0371a691 241
3c299c3a
DW
242bool wxGauge::SetForegroundColour(
243 const wxColour& rColour
244)
245{
246 if (!wxControl::SetForegroundColour(rColour))
247 return FALSE;
0371a691 248
3c299c3a 249 LONG lColor = (LONG)rColour.GetPixel();
0371a691 250
3c299c3a
DW
251 ::WinSetPresParam( GetHwnd()
252 ,PP_FOREGROUNDCOLOR
253 ,sizeof(LONG)
254 ,(PVOID)&lColor
255 );
0371a691 256
3c299c3a
DW
257 return TRUE;
258} // end of wxGauge::SetForegroundColour
0371a691 259
3c299c3a
DW
260void wxGauge::SetRange(
261 int nRange
262)
263{
264 m_nRangeMax = nRange;
265} // end of wxGauge::SetRange
0371a691 266
3c299c3a
DW
267void wxGauge::SetShadowWidth(
268 int WXUNUSED(nWidth)
269)
270{
271} // end of wxGauge::SetShadowWidth
0371a691 272
3c299c3a
DW
273void wxGauge::SetValue(
274 int nPos
275)
276{
277 RECT vRect;
0371a691 278
3c299c3a
DW
279 m_nGaugePos = nPos;
280 ::WinQueryWindowRect(GetHwnd(), &vRect);
281 ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
282} // end of wxGauge::SetValue
0371a691
DW
283
284