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