]>
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
;
47 double dPixelToRange
= 0.0;
53 hPS
= ::WinBeginPaint( hWnd
59 ::WinQueryWindowRect(hWnd
, &vRect
);
60 ::GpiCreateLogColorTable( hPS
64 ,(LONG
)wxTheColourDatabase
->m_nSize
65 ,(PLONG
)wxTheColourDatabase
->m_palTable
67 ::GpiCreateLogColorTable( hPS
77 LONG lColor
= 0x00FFFFFF; // White
78 POINTL vPoint
= {vRect
.xLeft
+ 1, vRect
.yBottom
+ 1};
80 ::GpiSetColor(hPS
, lColor
);
81 ::GpiMove(hPS
, &vPoint
);
82 vPoint
.x
= vRect
.xRight
- 1;
83 ::GpiLine(hPS
, &vPoint
);
84 vPoint
.y
= vRect
.yTop
- 1;
85 ::GpiLine(hPS
, &vPoint
);
86 lColor
= 0x000C0C0C; // Darkish Grey to give depth feel
87 ::GpiSetColor(hPS
, lColor
);
88 vPoint
.x
= vRect
.xLeft
+ 1;
89 ::GpiLine(hPS
, &vPoint
);
90 vPoint
.y
= vRect
.yBottom
+ 1;
91 ::GpiLine(hPS
, &vPoint
);
92 vRect3
.xLeft
= vRect
.xLeft
+ 2;
93 vRect3
.xRight
= vRect
.xRight
- 2;
94 vRect3
.yTop
= vRect
.yTop
- 2;
95 vRect3
.yBottom
= vRect
.yBottom
+ 2;
97 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
)
99 dRange
= (double)(vRect3
.yTop
- vRect3
.yBottom
);
100 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
101 vRect2
.yTop
= (int)(pGauge
->GetValue() * dPixelToRange
);
102 vRect2
.yBottom
= vRect3
.yBottom
;
103 vRect2
.xLeft
= vRect3
.xLeft
;
104 vRect2
.xRight
= vRect3
.xRight
;
105 vRect3
.yBottom
= vRect2
.yTop
;
106 if (vRect3
.yBottom
<= 1)
108 ::WinFillRect(hPS
, &vRect3
, pGauge
->GetBackgroundColour().GetPixel());
109 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
113 dRange
= (double)(vRect3
.xRight
- vRect3
.xLeft
);
114 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
115 vRect2
.yTop
= vRect3
.yTop
;
116 vRect2
.yBottom
= vRect3
.yBottom
;
117 vRect2
.xLeft
= vRect3
.xLeft
;
118 vRect2
.xRight
= (int)(pGauge
->GetValue() * dPixelToRange
);
119 vRect3
.xLeft
= vRect2
.xRight
;
120 if (vRect3
.xLeft
<= 1)
122 ::WinFillRect(hPS
, &vRect3
, pGauge
->GetBackgroundColour().GetPixel());
123 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
128 return (fnWndProcGauge( hWnd
134 } // end of wxGaugeWndProc
136 bool wxGauge::Create(
140 , const wxPoint
& rPos
141 , const wxSize
& rSize
143 , const wxValidator
& rValidator
144 , const wxString
& rsName
149 int nWidth
= rSize
.x
;
150 int nHeight
= rSize
.y
;
156 SetValidator(rValidator
);
159 pParent
->AddChild(this);
160 m_backgroundColour
.Set(wxString("LIGHT GREY"));
161 m_foregroundColour
.Set(wxString("NAVY"));
163 m_nRangeMax
= nRange
;
165 m_windowStyle
= lStyle
;
168 m_windowId
= (int)NewControlId();
172 if (m_windowStyle
& wxCLIP_SIBLINGS
)
173 lMsStyle
|= WS_CLIPSIBLINGS
;
176 // OS/2 will use an edit control for this, since there is not a native gauge
177 // Other choices include using an armless slider but they are more difficult
178 // to control and manipulate
181 lMsStyle
= WS_VISIBLE
| ES_MARGIN
| ES_LEFT
| ES_READONLY
;
182 if (m_windowStyle
& wxCLIP_SIBLINGS
)
183 lMsStyle
|= WS_CLIPSIBLINGS
;
185 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
186 ,WC_ENTRYFIELD
// Window class
187 ,(PSZ
)NULL
// Initial Text
188 ,(ULONG
)lMsStyle
// Style flags
189 ,0L, 0L, 0L, 0L // Origin -- 0 size
190 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
191 ,HWND_TOP
// initial z position
192 ,(HMENU
)m_windowId
// Window identifier
193 ,NULL
// Slider control data
194 ,NULL
// no Presentation parameters
197 wxAssociateWinWithHandle( m_hWnd
200 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
201 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
202 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
205 wxFont
* pTextFont
= new wxFont( 10
220 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
223 } // end of wxGauge::Create
225 int wxGauge::GetBezelFace() const
228 } // end of wxGauge::GetBezelFace
230 int wxGauge::GetRange() const
233 } // end of wxGauge::GetRange
235 int wxGauge::GetShadowWidth() const
238 } // end of wxGauge::GetShadowWidth
240 int wxGauge::GetValue() const
243 } // end of wxGauge::GetValue
245 bool wxGauge::SetBackgroundColour(
246 const wxColour
& rColour
249 if (!wxControl::SetBackgroundColour(rColour
))
252 LONG lColor
= (LONG
)rColour
.GetPixel();
254 ::WinSetPresParam( GetHwnd()
260 } // end of wxGauge::SetBackgroundColour
262 void wxGauge::SetBezelFace(
266 } // end of wxGauge::SetBezelFace
268 bool wxGauge::SetForegroundColour(
269 const wxColour
& rColour
272 if (!wxControl::SetForegroundColour(rColour
))
275 LONG lColor
= (LONG
)rColour
.GetPixel();
277 ::WinSetPresParam( GetHwnd()
284 } // end of wxGauge::SetForegroundColour
286 void wxGauge::SetRange(
290 m_nRangeMax
= nRange
;
291 } // end of wxGauge::SetRange
293 void wxGauge::SetShadowWidth(
297 } // end of wxGauge::SetShadowWidth
299 void wxGauge::SetValue(
306 ::WinQueryWindowRect(GetHwnd(), &vRect
);
307 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
308 } // end of wxGauge::SetValue