]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/os2/gauge.cpp
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / src / os2 / gauge.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/os2/gauge.cpp
3// Purpose: wxGauge class
4// Author: David Webster
5// Modified by:
6// Created: 10/06/99
7// Copyright: (c) David Webster
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#if wxUSE_GAUGE
14
15#include "wx/gauge.h"
16
17#ifndef WX_PRECOMP
18 #include "wx/utils.h"
19 #include "wx/scrolwin.h"
20#endif
21
22#include "wx/os2/private.h"
23
24static WXFARPROC fnWndProcGauge = (WXFARPROC)NULL;
25extern void wxAssociateWinWithHandle( HWND hWnd
26 ,wxWindowOS2* pWin
27 );
28
29MRESULT EXPENTRY wxGaugeWndProc( HWND hWnd,
30 UINT uMessage,
31 MPARAM wParam,
32 MPARAM lParam )
33{
34 wxGauge* pGauge = (wxGauge *)::WinQueryWindowULong( hWnd
35 ,QWL_USER
36 );
37 HPS hPS;
38 RECTL vRect;
39 RECTL vRect2;
40 RECTL vRect3;
41 double dPixelToRange = 0.0;
42 double dRange = 0.0;
43
44 switch (uMessage )
45 {
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 );
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
91 if (pGauge->GetWindowStyleFlag() & wxGA_VERTICAL)
92 {
93 dRange = (double)(vRect3.yTop - vRect3.yBottom);
94 dPixelToRange = dRange/(double)pGauge->GetRange();
95 vRect2.yTop = (int)(pGauge->GetValue() * dPixelToRange);
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());
103 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
104 }
105 else
106 {
107 dRange = (double)(vRect3.xRight - vRect3.xLeft);
108 dPixelToRange = dRange/(double)pGauge->GetRange();
109 vRect2.yTop = vRect3.yTop;
110 vRect2.yBottom = vRect3.yBottom;
111 vRect2.xLeft = vRect3.xLeft;
112 vRect2.xRight = (int)(pGauge->GetValue() * dPixelToRange);
113 vRect3.xLeft = vRect2.xRight;
114 if (vRect3.xLeft <= 1)
115 vRect3.xLeft = 2;
116 ::WinFillRect(hPS, &vRect3, pGauge->GetBackgroundColour().GetPixel());
117 ::WinFillRect(hPS, &vRect2, pGauge->GetForegroundColour().GetPixel());
118 }
119 ::WinEndPaint(hPS);
120 }
121 }
122 return (fnWndProcGauge( hWnd
123 ,(ULONG)uMessage
124 ,(MPARAM)wParam
125 ,(MPARAM)lParam
126 )
127 );
128} // end of wxGaugeWndProc
129
130bool 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 )
138{
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;
145
146 SetName(rsName);
147#if wxUSE_VALIDATORS
148 SetValidator(rValidator);
149#endif
150 if (pParent)
151 pParent->AddChild(this);
152 m_backgroundColour.Set(wxString(wxT("LIGHT GREY")));
153 m_foregroundColour.Set(wxString(wxT("NAVY")));
154
155 m_nRangeMax = nRange;
156 m_nGaugePos = 0;
157 m_windowStyle = lStyle;
158
159 if (vId == wxID_ANY)
160 m_windowId = (int)NewControlId();
161 else
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
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);
194 ::WinQueryWindowPos(m_hWnd, &vSwp);
195 SetXComp(vSwp.x);
196 SetYComp(vSwp.y);
197 wxFont* pTextFont = new wxFont( 10
198 ,wxMODERN
199 ,wxNORMAL
200 ,wxNORMAL
201 );
202 SetFont(*pTextFont);
203 if (nWidth == -1L)
204 nWidth = 50L;
205 if (nHeight == -1L)
206 nHeight = 28L;
207 SetSize( nX
208 ,nY
209 ,nWidth
210 ,nHeight
211 );
212 m_nWidth = nWidth; // Save for GetBestSize
213 m_nHeight = nHeight;
214 ::WinShowWindow((HWND)GetHWND(), TRUE);
215 delete pTextFont;
216 return true;
217} // end of wxGauge::Create
218
219int wxGauge::GetBezelFace() const
220{
221 return 0;
222} // end of wxGauge::GetBezelFace
223
224int wxGauge::GetRange() const
225{
226 return m_nRangeMax;
227} // end of wxGauge::GetRange
228
229int wxGauge::GetShadowWidth() const
230{
231 return 0;
232} // end of wxGauge::GetShadowWidth
233
234int wxGauge::GetValue() const
235{
236 return m_nGaugePos;
237} // end of wxGauge::GetValue
238
239bool wxGauge::SetBackgroundColour( const wxColour& rColour )
240{
241 if (!wxControl::SetBackgroundColour(rColour))
242 return false;
243
244 LONG lColor = (LONG)rColour.GetPixel();
245
246 ::WinSetPresParam( GetHwnd()
247 ,PP_BACKGROUNDCOLOR
248 ,sizeof(LONG)
249 ,(PVOID)&lColor
250 );
251 return true;
252} // end of wxGauge::SetBackgroundColour
253
254void wxGauge::SetBezelFace( int WXUNUSED(nWidth) )
255{
256} // end of wxGauge::SetBezelFace
257
258bool wxGauge::SetForegroundColour( const wxColour& rColour )
259{
260 if (!wxControl::SetForegroundColour(rColour))
261 return false;
262
263 LONG lColor = (LONG)rColour.GetPixel();
264
265 ::WinSetPresParam( GetHwnd()
266 ,PP_FOREGROUNDCOLOR
267 ,sizeof(LONG)
268 ,(PVOID)&lColor
269 );
270
271 return true;
272} // end of wxGauge::SetForegroundColour
273
274void wxGauge::SetRange( int nRange )
275{
276 m_nRangeMax = nRange;
277} // end of wxGauge::SetRange
278
279void wxGauge::SetShadowWidth( int WXUNUSED(nWidth) )
280{
281} // end of wxGauge::SetShadowWidth
282
283void wxGauge::SetValue( int nPos )
284{
285 RECT vRect;
286
287 m_nGaugePos = nPos;
288 ::WinQueryWindowRect(GetHwnd(), &vRect);
289 ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
290} // end of wxGauge::SetValue
291
292wxSize wxGauge::DoGetBestSize() const
293{
294 return wxSize(m_nWidth,m_nHeight);
295}
296
297#endif // wxUSE_GAUGE