]>
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
;
160 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
161 ,WC_ENTRYFIELD
// Window class
162 ,(PSZ
)NULL
// Initial Text
163 ,(ULONG
)lMsStyle
// Style flags
164 ,0L, 0L, 0L, 0L // Origin -- 0 size
165 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
166 ,HWND_TOP
// initial z position
167 ,(HMENU
)m_windowId
// Window identifier
168 ,NULL
// Slider control data
169 ,NULL
// no Presentation parameters
172 wxAssociateWinWithHandle( m_hWnd
175 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
176 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
177 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
180 SetFont(pParent
->GetFont());
190 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
192 } // end of wxGauge::Create
194 int wxGauge::GetBezelFace() const
197 } // end of wxGauge::GetBezelFace
199 int wxGauge::GetRange() const
202 } // end of wxGauge::GetRange
204 int wxGauge::GetShadowWidth() const
207 } // end of wxGauge::GetShadowWidth
209 int wxGauge::GetValue() const
212 } // end of wxGauge::GetValue
214 bool wxGauge::SetBackgroundColour(
215 const wxColour
& rColour
218 if (!wxControl::SetBackgroundColour(rColour
))
221 LONG lColor
= (LONG
)rColour
.GetPixel();
223 ::WinSetPresParam( GetHwnd()
229 } // end of wxGauge::SetBackgroundColour
231 void wxGauge::SetBezelFace(
235 } // end of wxGauge::SetBezelFace
237 bool wxGauge::SetForegroundColour(
238 const wxColour
& rColour
241 if (!wxControl::SetForegroundColour(rColour
))
244 LONG lColor
= (LONG
)rColour
.GetPixel();
246 ::WinSetPresParam( GetHwnd()
253 } // end of wxGauge::SetForegroundColour
255 void wxGauge::SetRange(
259 m_nRangeMax
= nRange
;
260 } // end of wxGauge::SetRange
262 void wxGauge::SetShadowWidth(
266 } // end of wxGauge::SetShadowWidth
268 void wxGauge::SetValue(
275 ::WinQueryWindowRect(GetHwnd(), &vRect
);
276 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
277 } // end of wxGauge::SetValue