]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxGauge class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
17 #include "wx/scrolwin.h"
20 #include "wx/os2/private.h"
23 static WXFARPROC fnWndProcGauge
= (WXFARPROC
)NULL
;
24 extern void wxAssociateWinWithHandle( HWND hWnd
28 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
30 MRESULT EXPENTRY
wxGaugeWndProc(
37 wxGauge
* pGauge
= (wxGauge
*)::WinQueryWindowULong( hWnd
40 wxWindowOS2
* pWindow
= NULL
;
41 MRESULT rc
= (MRESULT
)0;
42 bool bProcessed
= FALSE
;
46 double dPixelToRange
= 0.0;
52 hPS
= ::WinBeginPaint( hWnd
58 ::WinQueryWindowRect(hWnd
, &vRect
);
59 ::GpiCreateLogColorTable( hPS
63 ,(LONG
)wxTheColourDatabase
->m_nSize
64 ,(PLONG
)wxTheColourDatabase
->m_palTable
66 ::GpiCreateLogColorTable( hPS
73 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
)
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());
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());
100 return (fnWndProcGauge( hWnd
106 } // end of wxGaugeWndProc
108 bool wxGauge::Create(
112 , const wxPoint
& rPos
113 , const wxSize
& rSize
116 , const wxValidator
& rValidator
118 , const wxString
& rsName
123 int nWidth
= rSize
.x
;
124 int nHeight
= rSize
.y
;
130 SetValidator(rValidator
);
133 pParent
->AddChild(this);
134 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
135 SetForegroundColour(pParent
->GetForegroundColour()) ;
137 m_nRangeMax
= nRange
;
139 m_windowStyle
= lStyle
;
142 m_windowId
= (int)NewControlId();
146 if (m_windowStyle
& wxCLIP_SIBLINGS
)
147 lMsStyle
|= WS_CLIPSIBLINGS
;
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
155 lMsStyle
= WS_VISIBLE
| ES_MARGIN
| ES_LEFT
| ES_READONLY
;
156 if (m_windowStyle
& wxCLIP_SIBLINGS
)
157 lMsStyle
|= WS_CLIPSIBLINGS
;
160 // If the parent is a scrolled window the controls must
161 // have this style or they will overlap the scrollbars
164 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
165 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
166 lMsStyle
|= WS_CLIPSIBLINGS
;
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
180 wxAssociateWinWithHandle( m_hWnd
183 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
184 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
185 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
188 SetFont(pParent
->GetFont());
198 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
200 } // end of wxGauge::Create
202 int wxGauge::GetBezelFace() const
205 } // end of wxGauge::GetBezelFace
207 int wxGauge::GetRange() const
210 } // end of wxGauge::GetRange
212 int wxGauge::GetShadowWidth() const
215 } // end of wxGauge::GetShadowWidth
217 int wxGauge::GetValue() const
220 } // end of wxGauge::GetValue
222 bool wxGauge::SetBackgroundColour(
223 const wxColour
& rColour
226 if (!wxControl::SetBackgroundColour(rColour
))
229 LONG lColor
= (LONG
)rColour
.GetPixel();
231 ::WinSetPresParam( GetHwnd()
237 } // end of wxGauge::SetBackgroundColour
239 void wxGauge::SetBezelFace(
243 } // end of wxGauge::SetBezelFace
245 bool wxGauge::SetForegroundColour(
246 const wxColour
& rColour
249 if (!wxControl::SetForegroundColour(rColour
))
252 LONG lColor
= (LONG
)rColour
.GetPixel();
254 ::WinSetPresParam( GetHwnd()
261 } // end of wxGauge::SetForegroundColour
263 void wxGauge::SetRange(
267 m_nRangeMax
= nRange
;
268 } // end of wxGauge::SetRange
270 void wxGauge::SetShadowWidth(
274 } // end of wxGauge::SetShadowWidth
276 void wxGauge::SetValue(
283 ::WinQueryWindowRect(GetHwnd(), &vRect
);
284 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
285 } // end of wxGauge::SetValue