]> git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
Fix for when Set is called with wxSameAs to behave just like calling SameAs()
[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 //
160 // If the parent is a scrolled window the controls must
161 // have this style or they will overlap the scrollbars
162 //
163 if (pParent)
164 if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
165 pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
166 lMsStyle |= WS_CLIPSIBLINGS;
167
168 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
169 ,WC_ENTRYFIELD // Window class
170 ,(PSZ)NULL // Initial Text
171 ,(ULONG)lMsStyle // Style flags
172 ,0L, 0L, 0L, 0L // Origin -- 0 size
173 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
174 ,HWND_TOP // initial z position
175 ,(HMENU)m_windowId // Window identifier
176 ,NULL // Slider control data
177 ,NULL // no Presentation parameters
178 );
179
180 wxAssociateWinWithHandle( m_hWnd
181 ,(wxWindowOS2*)this
182 );
183 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
184 fnWndProcGauge = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxGaugeWndProc);
185 ::WinQueryWindowPos(m_hWnd, &vSwp);
186 SetXComp(vSwp.x);
187 SetYComp(vSwp.y);
188 SetFont(pParent->GetFont());
189 if (nWidth == -1L)
190 nWidth = 50L;
191 if (nHeight == -1L)
192 nHeight = 28L;
193 SetSize( nX
194 ,nY
195 ,nWidth
196 ,nHeight
197 );
198 ::WinShowWindow((HWND)GetHWND(), TRUE);
199 return TRUE;
200 } // end of wxGauge::Create
201
202 int wxGauge::GetBezelFace() const
203 {
204 return 0;
205 } // end of wxGauge::GetBezelFace
206
207 int wxGauge::GetRange() const
208 {
209 return m_nRangeMax;
210 } // end of wxGauge::GetRange
211
212 int wxGauge::GetShadowWidth() const
213 {
214 return 0;
215 } // end of wxGauge::GetShadowWidth
216
217 int wxGauge::GetValue() const
218 {
219 return m_nGaugePos;
220 } // end of wxGauge::GetValue
221
222 bool wxGauge::SetBackgroundColour(
223 const wxColour& rColour
224 )
225 {
226 if (!wxControl::SetBackgroundColour(rColour))
227 return FALSE;
228
229 LONG lColor = (LONG)rColour.GetPixel();
230
231 ::WinSetPresParam( GetHwnd()
232 ,PP_BACKGROUNDCOLOR
233 ,sizeof(LONG)
234 ,(PVOID)&lColor
235 );
236 return TRUE;
237 } // end of wxGauge::SetBackgroundColour
238
239 void wxGauge::SetBezelFace(
240 int WXUNUSED(nWidth)
241 )
242 {
243 } // end of wxGauge::SetBezelFace
244
245 bool wxGauge::SetForegroundColour(
246 const wxColour& rColour
247 )
248 {
249 if (!wxControl::SetForegroundColour(rColour))
250 return FALSE;
251
252 LONG lColor = (LONG)rColour.GetPixel();
253
254 ::WinSetPresParam( GetHwnd()
255 ,PP_FOREGROUNDCOLOR
256 ,sizeof(LONG)
257 ,(PVOID)&lColor
258 );
259
260 return TRUE;
261 } // end of wxGauge::SetForegroundColour
262
263 void wxGauge::SetRange(
264 int nRange
265 )
266 {
267 m_nRangeMax = nRange;
268 } // end of wxGauge::SetRange
269
270 void wxGauge::SetShadowWidth(
271 int WXUNUSED(nWidth)
272 )
273 {
274 } // end of wxGauge::SetShadowWidth
275
276 void wxGauge::SetValue(
277 int nPos
278 )
279 {
280 RECT vRect;
281
282 m_nGaugePos = nPos;
283 ::WinQueryWindowRect(GetHwnd(), &vRect);
284 ::WinInvalidateRect(GetHwnd(), &vRect, FALSE);
285 } // end of wxGauge::SetValue
286
287