]>
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
;
128 SetValidator(rValidator
);
131 pParent
->AddChild(this);
132 SetBackgroundColour(pParent
->GetBackgroundColour()) ;
133 SetForegroundColour(pParent
->GetForegroundColour()) ;
135 m_nRangeMax
= nRange
;
137 m_windowStyle
= lStyle
;
140 m_windowId
= (int)NewControlId();
144 if (m_windowStyle
& wxCLIP_SIBLINGS
)
145 lMsStyle
|= WS_CLIPSIBLINGS
;
148 // OS/2 will use an edit control for this, since there is not a native gauge
149 // Other choices include using an armless slider but they are more difficult
150 // to control and manipulate
153 lMsStyle
= WS_VISIBLE
| ES_MARGIN
| ES_LEFT
| ES_READONLY
;
154 if (m_windowStyle
& wxCLIP_SIBLINGS
)
155 lMsStyle
|= WS_CLIPSIBLINGS
;
159 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
160 ,WC_ENTRYFIELD
// Window class
161 ,(PSZ
)NULL
// Initial Text
162 ,(ULONG
)lMsStyle
// Style flags
163 ,0L, 0L, 0L, 0L // Origin -- 0 size
164 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
165 ,HWND_TOP
// initial z position
166 ,(HMENU
)m_windowId
// Window identifier
167 ,NULL
// Slider control data
168 ,NULL
// no Presentation parameters
171 wxAssociateWinWithHandle( m_hWnd
174 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
175 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
176 SetFont(pParent
->GetFont());
186 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
188 } // end of wxGauge::Create
190 int wxGauge::GetBezelFace() const
193 } // end of wxGauge::GetBezelFace
195 int wxGauge::GetRange() const
198 } // end of wxGauge::GetRange
200 int wxGauge::GetShadowWidth() const
203 } // end of wxGauge::GetShadowWidth
205 int wxGauge::GetValue() const
208 } // end of wxGauge::GetValue
210 bool wxGauge::SetBackgroundColour(
211 const wxColour
& rColour
214 if (!wxControl::SetBackgroundColour(rColour
))
217 LONG lColor
= (LONG
)rColour
.GetPixel();
219 ::WinSetPresParam( GetHwnd()
225 } // end of wxGauge::SetBackgroundColour
227 void wxGauge::SetBezelFace(
231 } // end of wxGauge::SetBezelFace
233 bool wxGauge::SetForegroundColour(
234 const wxColour
& rColour
237 if (!wxControl::SetForegroundColour(rColour
))
240 LONG lColor
= (LONG
)rColour
.GetPixel();
242 ::WinSetPresParam( GetHwnd()
249 } // end of wxGauge::SetForegroundColour
251 void wxGauge::SetRange(
255 m_nRangeMax
= nRange
;
256 } // end of wxGauge::SetRange
258 void wxGauge::SetShadowWidth(
262 } // end of wxGauge::SetShadowWidth
264 void wxGauge::SetValue(
271 ::WinQueryWindowRect(GetHwnd(), &vRect
);
272 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
273 } // end of wxGauge::SetValue