]>
Commit | Line | Data |
---|---|---|
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 | 8 | // Copyright: (c) David Webster |
65571936 | 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 |
23 | static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL; |
24 | extern void wxAssociateWinWithHandle( HWND hWnd | |
25 | ,wxWindowOS2* pWin | |
26 | ); | |
0371a691 | 27 | |
0e320a79 | 28 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) |
0e320a79 | 29 | |
3c299c3a DW |
30 | MRESULT 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 | ); | |
3c299c3a DW |
40 | HPS hPS; |
41 | RECTL vRect; | |
42 | RECTL vRect2; | |
b720b24d | 43 | RECTL vRect3; |
3c299c3a DW |
44 | double dPixelToRange = 0.0; |
45 | double dRange = 0.0; | |
46 | ||
47 | switch (uMessage ) | |
0371a691 | 48 | { |
3c299c3a DW |
49 | case WM_PAINT: |
50 | hPS = ::WinBeginPaint( hWnd | |
51 | ,NULLHANDLE | |
52 | ,&vRect | |
53 | ); | |
54 | if(hPS) | |
55 | { | |
56 | ::WinQueryWindowRect(hWnd, &vRect); | |
57 | ::GpiCreateLogColorTable( hPS | |
58 | ,0L | |
59 | ,LCOLF_CONSECRGB | |
60 | ,0L | |
61 | ,(LONG)wxTheColourDatabase->m_nSize | |
62 | ,(PLONG)wxTheColourDatabase->m_palTable | |
63 | ); | |
64 | ::GpiCreateLogColorTable( hPS | |
65 | ,0L | |
66 | ,LCOLF_RGB | |
67 | ,0L | |
68 | ,0L | |
69 | ,NULL | |
70 | ); | |
b720b24d DW |
71 | // |
72 | // Draw the guage box | |
73 | // | |
74 | LONG lColor = 0x00FFFFFF; // White | |
75 | POINTL vPoint = {vRect.xLeft + 1, vRect.yBottom + 1}; | |
76 | ||
77 | ::GpiSetColor(hPS, lColor); | |
78 | ::GpiMove(hPS, &vPoint); | |
79 | vPoint.x = vRect.xRight - 1; | |
80 | ::GpiLine(hPS, &vPoint); | |
81 | vPoint.y = vRect.yTop - 1; | |
82 | ::GpiLine(hPS, &vPoint); | |
83 | lColor = 0x000C0C0C; // Darkish Grey to give depth feel | |
84 | ::GpiSetColor(hPS, lColor); | |
85 | vPoint.x = vRect.xLeft + 1; | |
86 | ::GpiLine(hPS, &vPoint); | |
87 | vPoint.y = vRect.yBottom + 1; | |
88 | ::GpiLine(hPS, &vPoint); | |
89 | vRect3.xLeft = vRect.xLeft + 2; | |
90 | vRect3.xRight = vRect.xRight - 2; | |
91 | vRect3.yTop = vRect.yTop - 2; | |
92 | vRect3.yBottom = vRect.yBottom + 2; | |
93 | ||
3c299c3a DW |
94 | if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL) |
95 | { | |
b720b24d | 96 | dRange = (double)(vRect3.yTop - vRect3.yBottom); |
3c299c3a DW |
97 | dPixelToRange = dRange/(double)pGauge->GetRange(); |
98 | vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange); | |
b720b24d DW |
99 | vRect2.yBottom = vRect3.yBottom; |
100 | vRect2.xLeft = vRect3.xLeft; | |
101 | vRect2.xRight = vRect3.xRight; | |
102 | vRect3.yBottom = vRect2.yTop; | |
103 | if (vRect3.yBottom <= 1) | |
104 | vRect3.yBottom = 2; | |
105 | ::WinFillRect(hPS, &vRect3, pGauge->GetBackgroundColour().GetPixel()); | |
3c299c3a DW |
106 | ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel()); |
107 | } | |
108 | else | |
109 | { | |
b720b24d | 110 | dRange = (double)(vRect3.xRight - vRect3.xLeft); |
3c299c3a | 111 | dPixelToRange = dRange/(double)pGauge->GetRange(); |
b720b24d DW |
112 | vRect2.yTop = vRect3.yTop; |
113 | vRect2.yBottom = vRect3.yBottom; | |
114 | vRect2.xLeft = vRect3.xLeft; | |
3c299c3a | 115 | vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange); |
b720b24d DW |
116 | vRect3.xLeft = vRect2.xRight; |
117 | if (vRect3.xLeft <= 1) | |
118 | vRect3.xLeft = 2; | |
119 | ::WinFillRect(hPS, &vRect3, pGauge->GetBackgroundColour().GetPixel()); | |
3c299c3a DW |
120 | ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel()); |
121 | } | |
122 | ::WinEndPaint(hPS); | |
123 | } | |
0371a691 | 124 | } |
3c299c3a DW |
125 | return (fnWndProcGauge( hWnd |
126 | ,(ULONG)uMessage | |
127 | ,(MPARAM)wParam | |
128 | ,(MPARAM)lParam | |
129 | ) | |
130 | ); | |
131 | } // end of wxGaugeWndProc | |
132 | ||
133 | bool wxGauge::Create( | |
134 | wxWindowOS2* pParent | |
135 | , wxWindowID vId | |
136 | , int nRange | |
137 | , const wxPoint& rPos | |
138 | , const wxSize& rSize | |
139 | , long lStyle | |
3c299c3a | 140 | , const wxValidator& rValidator |
3c299c3a DW |
141 | , const wxString& rsName |
142 | ) | |
143 | { | |
144 | int nX = rPos.x; | |
145 | int nY = rPos.y; | |
146 | int nWidth = rSize.x; | |
147 | int nHeight = rSize.y; | |
148 | long lMsStyle = 0L; | |
d8a3f66c | 149 | SWP vSwp; |
0371a691 | 150 | |
3c299c3a | 151 | SetName(rsName); |
5d4b632b | 152 | #if wxUSE_VALIDATORS |
3c299c3a | 153 | SetValidator(rValidator); |
5d4b632b | 154 | #endif |
3c299c3a DW |
155 | if (pParent) |
156 | pParent->AddChild(this); | |
b720b24d DW |
157 | m_backgroundColour.Set(wxString("LIGHT GREY")); |
158 | m_foregroundColour.Set(wxString("NAVY")); | |
0e320a79 | 159 | |
3c299c3a DW |
160 | m_nRangeMax = nRange; |
161 | m_nGaugePos = 0; | |
162 | m_windowStyle = lStyle; | |
0e320a79 | 163 | |
3c299c3a DW |
164 | if (vId == -1) |
165 | m_windowId = (int)NewControlId(); | |
0e320a79 | 166 | else |
3c299c3a DW |
167 | m_windowId = vId; |
168 | ||
169 | if (m_windowStyle & wxCLIP_SIBLINGS ) | |
170 | lMsStyle |= WS_CLIPSIBLINGS; | |
171 | ||
172 | // | |
173 | // OS/2 will use an edit control for this, since there is not a native gauge | |
174 | // Other choices include using an armless slider but they are more difficult | |
175 | // to control and manipulate | |
176 | // | |
177 | ||
178 | lMsStyle = WS_VISIBLE | ES_MARGIN | ES_LEFT | ES_READONLY; | |
179 | if (m_windowStyle & wxCLIP_SIBLINGS) | |
180 | lMsStyle |= WS_CLIPSIBLINGS; | |
181 | ||
3c299c3a DW |
182 | m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle |
183 | ,WC_ENTRYFIELD // Window class | |
184 | ,(PSZ)NULL // Initial Text | |
185 | ,(ULONG)lMsStyle // Style flags | |
186 | ,0L, 0L, 0L, 0L // Origin -- 0 size | |
187 | ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent | |
188 | ,HWND_TOP // initial z position | |
189 | ,(HMENU)m_windowId // Window identifier | |
190 | ,NULL // Slider control data | |
191 | ,NULL // no Presentation parameters | |
192 | ); | |
193 | ||
194 | wxAssociateWinWithHandle( m_hWnd | |
195 | ,(wxWindowOS2*)this | |
196 | ); | |
197 | ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); | |
198 | fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc); | |
d8a3f66c DW |
199 | ::WinQueryWindowPos(m_hWnd, &vSwp); |
200 | SetXComp(vSwp.x); | |
201 | SetYComp(vSwp.y); | |
b3260bce DW |
202 | wxFont* pTextFont = new wxFont( 10 |
203 | ,wxMODERN | |
204 | ,wxNORMAL | |
205 | ,wxNORMAL | |
206 | ); | |
207 | SetFont(*pTextFont); | |
3c299c3a DW |
208 | if (nWidth == -1L) |
209 | nWidth = 50L; | |
210 | if (nHeight == -1L) | |
211 | nHeight = 28L; | |
212 | SetSize( nX | |
213 | ,nY | |
214 | ,nWidth | |
215 | ,nHeight | |
216 | ); | |
217 | ::WinShowWindow((HWND)GetHWND(), TRUE); | |
b3260bce | 218 | delete pTextFont; |
3c299c3a DW |
219 | return TRUE; |
220 | } // end of wxGauge::Create | |
0e320a79 | 221 | |
3c299c3a | 222 | int wxGauge::GetBezelFace() const |
0e320a79 | 223 | { |
3c299c3a DW |
224 | return 0; |
225 | } // end of wxGauge::GetBezelFace | |
0e320a79 | 226 | |
3c299c3a | 227 | int wxGauge::GetRange() const |
0e320a79 | 228 | { |
3c299c3a DW |
229 | return m_nRangeMax; |
230 | } // end of wxGauge::GetRange | |
0e320a79 DW |
231 | |
232 | int wxGauge::GetShadowWidth() const | |
233 | { | |
0e320a79 | 234 | return 0; |
3c299c3a | 235 | } // end of wxGauge::GetShadowWidth |
0e320a79 DW |
236 | |
237 | int wxGauge::GetValue() const | |
238 | { | |
3c299c3a DW |
239 | return m_nGaugePos; |
240 | } // end of wxGauge::GetValue | |
0e320a79 | 241 | |
3c299c3a DW |
242 | bool wxGauge::SetBackgroundColour( |
243 | const wxColour& rColour | |
244 | ) | |
0371a691 | 245 | { |
3c299c3a | 246 | if (!wxControl::SetBackgroundColour(rColour)) |
0371a691 DW |
247 | return FALSE; |
248 | ||
3c299c3a | 249 | LONG lColor = (LONG)rColour.GetPixel(); |
0371a691 | 250 | |
3c299c3a DW |
251 | ::WinSetPresParam( GetHwnd() |
252 | ,PP_BACKGROUNDCOLOR | |
253 | ,sizeof(LONG) | |
254 | ,(PVOID)&lColor | |
255 | ); | |
0371a691 | 256 | return TRUE; |
3c299c3a | 257 | } // end of wxGauge::SetBackgroundColour |
0371a691 | 258 | |
3c299c3a DW |
259 | void wxGauge::SetBezelFace( |
260 | int WXUNUSED(nWidth) | |
261 | ) | |
0371a691 | 262 | { |
3c299c3a | 263 | } // end of wxGauge::SetBezelFace |
0371a691 | 264 | |
3c299c3a DW |
265 | bool wxGauge::SetForegroundColour( |
266 | const wxColour& rColour | |
267 | ) | |
268 | { | |
269 | if (!wxControl::SetForegroundColour(rColour)) | |
270 | return FALSE; | |
0371a691 | 271 | |
3c299c3a | 272 | LONG lColor = (LONG)rColour.GetPixel(); |
0371a691 | 273 | |
3c299c3a DW |
274 | ::WinSetPresParam( GetHwnd() |
275 | ,PP_FOREGROUNDCOLOR | |
276 | ,sizeof(LONG) | |
277 | ,(PVOID)&lColor | |
278 | ); | |
0371a691 | 279 | |
3c299c3a DW |
280 | return TRUE; |
281 | } // end of wxGauge::SetForegroundColour | |
0371a691 | 282 | |
3c299c3a DW |
283 | void wxGauge::SetRange( |
284 | int nRange | |
285 | ) | |
286 | { | |
287 | m_nRangeMax = nRange; | |
288 | } // end of wxGauge::SetRange | |
0371a691 | 289 | |
3c299c3a DW |
290 | void wxGauge::SetShadowWidth( |
291 | int WXUNUSED(nWidth) | |
292 | ) | |
293 | { | |
294 | } // end of wxGauge::SetShadowWidth | |
0371a691 | 295 | |
3c299c3a DW |
296 | void wxGauge::SetValue( |
297 | int nPos | |
298 | ) | |
299 | { | |
300 | RECT vRect; | |
0371a691 | 301 | |
3c299c3a DW |
302 | m_nGaugePos = nPos; |
303 | ::WinQueryWindowRect(GetHwnd(), &vRect); | |
304 | ::WinInvalidateRect(GetHwnd(), &vRect, FALSE); | |
305 | } // end of wxGauge::SetValue | |
0371a691 DW |
306 | |
307 |