]>
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"
19 #include "wx/os2/private.h"
22 static WXFARPROC fnWndProcGauge
= (WXFARPROC
)NULL
;
23 extern void wxAssociateWinWithHandle( HWND hWnd
27 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
29 MRESULT EXPENTRY
wxGaugeWndProc(
36 wxGauge
* pGauge
= (wxGauge
*)::WinQueryWindowULong( hWnd
39 wxWindowOS2
* pWindow
= NULL
;
40 MRESULT rc
= (MRESULT
)0;
41 bool bProcessed
= FALSE
;
45 double dPixelToRange
= 0.0;
51 hPS
= ::WinBeginPaint( hWnd
57 ::WinQueryWindowRect(hWnd
, &vRect
);
58 ::GpiCreateLogColorTable( hPS
62 ,(LONG
)wxTheColourDatabase
->m_nSize
63 ,(PLONG
)wxTheColourDatabase
->m_palTable
65 ::GpiCreateLogColorTable( hPS
72 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
)
74 dRange
= (double)(vRect
.yTop
- vRect
.yBottom
);
75 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
76 vRect2
.yTop
= (int)(pGauge
->GetValue() * dPixelToRange
);
77 vRect2
.yBottom
= vRect
.yBottom
;
78 vRect2
.xLeft
= vRect
.xLeft
;
79 vRect2
.xRight
= vRect
.xRight
;
80 vRect
.yBottom
= vRect2
.yTop
;
81 ::WinFillRect(hPS
, &vRect
, pGauge
->GetBackgroundColour().GetPixel());
82 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
86 dRange
= (double)(vRect
.xRight
- vRect
.xLeft
);
87 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
88 vRect2
.yTop
= vRect
.yTop
;
89 vRect2
.yBottom
= vRect
.yBottom
;
90 vRect2
.xLeft
= vRect
.xLeft
;
91 vRect2
.xRight
= (int)(pGauge
->GetValue() * dPixelToRange
);
92 vRect
.xLeft
= vRect2
.xRight
;
93 ::WinFillRect(hPS
, &vRect
, pGauge
->GetBackgroundColour().GetPixel());
94 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
99 return (fnWndProcGauge( hWnd
105 } // end of wxGaugeWndProc
107 bool wxGauge::Create(
111 , const wxPoint
& rPos
112 , const wxSize
& rSize
115 , const wxValidator
& rValidator
117 , const wxString
& rsName
122 int nWidth
= rSize
.x
;
123 int nHeight
= rSize
.y
;
129 SetValidator(rValidator
);
132 pParent
->AddChild(this);
133 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
134 SetForegroundColour(pParent
->GetForegroundColour()) ;
136 m_nRangeMax
= nRange
;
138 m_windowStyle
= lStyle
;
141 m_windowId
= (int)NewControlId();
145 if (m_windowStyle
& wxCLIP_SIBLINGS
)
146 lMsStyle
|= WS_CLIPSIBLINGS
;
149 // OS/2 will use an edit control for this, since there is not a native gauge
150 // Other choices include using an armless slider but they are more difficult
151 // to control and manipulate
154 lMsStyle
= WS_VISIBLE
| ES_MARGIN
| ES_LEFT
| ES_READONLY
;
155 if (m_windowStyle
& wxCLIP_SIBLINGS
)
156 lMsStyle
|= WS_CLIPSIBLINGS
;
159 // If the parent is a scrolled window the controls must
160 // have this style or they will overlap the scrollbars
163 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
164 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
165 lMsStyle
|= WS_CLIPSIBLINGS
;
167 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
168 ,WC_ENTRYFIELD
// Window class
169 ,(PSZ
)NULL
// Initial Text
170 ,(ULONG
)lMsStyle
// Style flags
171 ,0L, 0L, 0L, 0L // Origin -- 0 size
172 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
173 ,HWND_TOP
// initial z position
174 ,(HMENU
)m_windowId
// Window identifier
175 ,NULL
// Slider control data
176 ,NULL
// no Presentation parameters
179 wxAssociateWinWithHandle( m_hWnd
182 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
183 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
184 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
187 SetFont(pParent
->GetFont());
197 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
199 } // end of wxGauge::Create
201 int wxGauge::GetBezelFace() const
204 } // end of wxGauge::GetBezelFace
206 int wxGauge::GetRange() const
209 } // end of wxGauge::GetRange
211 int wxGauge::GetShadowWidth() const
214 } // end of wxGauge::GetShadowWidth
216 int wxGauge::GetValue() const
219 } // end of wxGauge::GetValue
221 bool wxGauge::SetBackgroundColour(
222 const wxColour
& rColour
225 if (!wxControl::SetBackgroundColour(rColour
))
228 LONG lColor
= (LONG
)rColour
.GetPixel();
230 ::WinSetPresParam( GetHwnd()
236 } // end of wxGauge::SetBackgroundColour
238 void wxGauge::SetBezelFace(
242 } // end of wxGauge::SetBezelFace
244 bool wxGauge::SetForegroundColour(
245 const wxColour
& rColour
248 if (!wxControl::SetForegroundColour(rColour
))
251 LONG lColor
= (LONG
)rColour
.GetPixel();
253 ::WinSetPresParam( GetHwnd()
260 } // end of wxGauge::SetForegroundColour
262 void wxGauge::SetRange(
266 m_nRangeMax
= nRange
;
267 } // end of wxGauge::SetRange
269 void wxGauge::SetShadowWidth(
273 } // end of wxGauge::SetShadowWidth
275 void wxGauge::SetValue(
282 ::WinQueryWindowRect(GetHwnd(), &vRect
);
283 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
284 } // end of wxGauge::SetValue