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