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