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