]>
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
;
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 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
179 wxFont
* pTextFont
= new wxFont( 10
194 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
197 } // end of wxGauge::Create
199 int wxGauge::GetBezelFace() const
202 } // end of wxGauge::GetBezelFace
204 int wxGauge::GetRange() const
207 } // end of wxGauge::GetRange
209 int wxGauge::GetShadowWidth() const
212 } // end of wxGauge::GetShadowWidth
214 int wxGauge::GetValue() const
217 } // end of wxGauge::GetValue
219 bool wxGauge::SetBackgroundColour(
220 const wxColour
& rColour
223 if (!wxControl::SetBackgroundColour(rColour
))
226 LONG lColor
= (LONG
)rColour
.GetPixel();
228 ::WinSetPresParam( GetHwnd()
234 } // end of wxGauge::SetBackgroundColour
236 void wxGauge::SetBezelFace(
240 } // end of wxGauge::SetBezelFace
242 bool wxGauge::SetForegroundColour(
243 const wxColour
& rColour
246 if (!wxControl::SetForegroundColour(rColour
))
249 LONG lColor
= (LONG
)rColour
.GetPixel();
251 ::WinSetPresParam( GetHwnd()
258 } // end of wxGauge::SetForegroundColour
260 void wxGauge::SetRange(
264 m_nRangeMax
= nRange
;
265 } // end of wxGauge::SetRange
267 void wxGauge::SetShadowWidth(
271 } // end of wxGauge::SetShadowWidth
273 void wxGauge::SetValue(
280 ::WinQueryWindowRect(GetHwnd(), &vRect
);
281 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
282 } // end of wxGauge::SetValue