]>
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 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" | |
0e320a79 DW |
17 | #endif |
18 | ||
0371a691 | 19 | #include "wx/os2/private.h" |
0e320a79 DW |
20 | #include "wx/gauge.h" |
21 | ||
3c299c3a DW |
22 | static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL; |
23 | extern void wxAssociateWinWithHandle( HWND hWnd | |
24 | ,wxWindowOS2* pWin | |
25 | ); | |
0371a691 | 26 | |
0e320a79 | 27 | IMPLEMENT_DYNAMIC_CLASS(wxGauge, wxControl) |
0e320a79 | 28 | |
3c299c3a DW |
29 | MRESULT EXPENTRY wxGaugeWndProc( |
30 | HWND hWnd | |
31 | , UINT uMessage | |
32 | , MPARAM wParam | |
33 | , MPARAM lParam | |
34 | ) | |
0e320a79 | 35 | { |
3c299c3a DW |
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 ) | |
0371a691 | 49 | { |
3c299c3a DW |
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 | } | |
0371a691 | 98 | } |
3c299c3a DW |
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; | |
0371a691 | 125 | |
3c299c3a | 126 | SetName(rsName); |
5d4b632b | 127 | #if wxUSE_VALIDATORS |
3c299c3a | 128 | SetValidator(rValidator); |
5d4b632b | 129 | #endif |
3c299c3a DW |
130 | if (pParent) |
131 | pParent->AddChild(this); | |
132 | SetBackgroundColour(pParent->GetBackgroundColour()) ; | |
133 | SetForegroundColour(pParent->GetForegroundColour()) ; | |
0e320a79 | 134 | |
3c299c3a DW |
135 | m_nRangeMax = nRange; |
136 | m_nGaugePos = 0; | |
137 | m_windowStyle = lStyle; | |
0e320a79 | 138 | |
3c299c3a DW |
139 | if (vId == -1) |
140 | m_windowId = (int)NewControlId(); | |
0e320a79 | 141 | else |
3c299c3a DW |
142 | m_windowId = vId; |
143 | ||
144 | if (m_windowStyle & wxCLIP_SIBLINGS ) | |
145 | lMsStyle |= WS_CLIPSIBLINGS; | |
146 | ||
147 | // | |
148 | // OS/2 will use an edit control for this, since there is not a native gauge | |
149 | // Other choices include using an armless slider but they are more difficult | |
150 | // to control and manipulate | |
151 | // | |
152 | ||
153 | lMsStyle = WS_VISIBLE | ES_MARGIN | ES_LEFT | ES_READONLY; | |
154 | if (m_windowStyle & wxCLIP_SIBLINGS) | |
155 | lMsStyle |= WS_CLIPSIBLINGS; | |
156 | ||
157 | ||
158 | ||
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); | |
176 | SetFont(pParent->GetFont()); | |
177 | if (nWidth == -1L) | |
178 | nWidth = 50L; | |
179 | if (nHeight == -1L) | |
180 | nHeight = 28L; | |
181 | SetSize( nX | |
182 | ,nY | |
183 | ,nWidth | |
184 | ,nHeight | |
185 | ); | |
186 | ::WinShowWindow((HWND)GetHWND(), TRUE); | |
187 | return TRUE; | |
188 | } // end of wxGauge::Create | |
0e320a79 | 189 | |
3c299c3a | 190 | int wxGauge::GetBezelFace() const |
0e320a79 | 191 | { |
3c299c3a DW |
192 | return 0; |
193 | } // end of wxGauge::GetBezelFace | |
0e320a79 | 194 | |
3c299c3a | 195 | int wxGauge::GetRange() const |
0e320a79 | 196 | { |
3c299c3a DW |
197 | return m_nRangeMax; |
198 | } // end of wxGauge::GetRange | |
0e320a79 DW |
199 | |
200 | int wxGauge::GetShadowWidth() const | |
201 | { | |
0e320a79 | 202 | return 0; |
3c299c3a | 203 | } // end of wxGauge::GetShadowWidth |
0e320a79 DW |
204 | |
205 | int wxGauge::GetValue() const | |
206 | { | |
3c299c3a DW |
207 | return m_nGaugePos; |
208 | } // end of wxGauge::GetValue | |
0e320a79 | 209 | |
3c299c3a DW |
210 | bool wxGauge::SetBackgroundColour( |
211 | const wxColour& rColour | |
212 | ) | |
0371a691 | 213 | { |
3c299c3a | 214 | if (!wxControl::SetBackgroundColour(rColour)) |
0371a691 DW |
215 | return FALSE; |
216 | ||
3c299c3a | 217 | LONG lColor = (LONG)rColour.GetPixel(); |
0371a691 | 218 | |
3c299c3a DW |
219 | ::WinSetPresParam( GetHwnd() |
220 | ,PP_BACKGROUNDCOLOR | |
221 | ,sizeof(LONG) | |
222 | ,(PVOID)&lColor | |
223 | ); | |
0371a691 | 224 | return TRUE; |
3c299c3a | 225 | } // end of wxGauge::SetBackgroundColour |
0371a691 | 226 | |
3c299c3a DW |
227 | void wxGauge::SetBezelFace( |
228 | int WXUNUSED(nWidth) | |
229 | ) | |
0371a691 | 230 | { |
3c299c3a | 231 | } // end of wxGauge::SetBezelFace |
0371a691 | 232 | |
3c299c3a DW |
233 | bool wxGauge::SetForegroundColour( |
234 | const wxColour& rColour | |
235 | ) | |
236 | { | |
237 | if (!wxControl::SetForegroundColour(rColour)) | |
238 | return FALSE; | |
0371a691 | 239 | |
3c299c3a | 240 | LONG lColor = (LONG)rColour.GetPixel(); |
0371a691 | 241 | |
3c299c3a DW |
242 | ::WinSetPresParam( GetHwnd() |
243 | ,PP_FOREGROUNDCOLOR | |
244 | ,sizeof(LONG) | |
245 | ,(PVOID)&lColor | |
246 | ); | |
0371a691 | 247 | |
3c299c3a DW |
248 | return TRUE; |
249 | } // end of wxGauge::SetForegroundColour | |
0371a691 | 250 | |
3c299c3a DW |
251 | void wxGauge::SetRange( |
252 | int nRange | |
253 | ) | |
254 | { | |
255 | m_nRangeMax = nRange; | |
256 | } // end of wxGauge::SetRange | |
0371a691 | 257 | |
3c299c3a DW |
258 | void wxGauge::SetShadowWidth( |
259 | int WXUNUSED(nWidth) | |
260 | ) | |
261 | { | |
262 | } // end of wxGauge::SetShadowWidth | |
0371a691 | 263 | |
3c299c3a DW |
264 | void wxGauge::SetValue( |
265 | int nPos | |
266 | ) | |
267 | { | |
268 | RECT vRect; | |
0371a691 | 269 | |
3c299c3a DW |
270 | m_nGaugePos = nPos; |
271 | ::WinQueryWindowRect(GetHwnd(), &vRect); | |
272 | ::WinInvalidateRect(GetHwnd(), &vRect, FALSE); | |
273 | } // end of wxGauge::SetValue | |
0371a691 DW |
274 | |
275 |