]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/gauge.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/gauge.cpp
3 // Purpose: wxGauge class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/scrolwin.h"
23 #include "wx/os2/private.h"
25 static WXFARPROC fnWndProcGauge
= (WXFARPROC
)NULL
;
26 extern void wxAssociateWinWithHandle( HWND hWnd
30 IMPLEMENT_DYNAMIC_CLASS(wxGauge
, wxControl
)
32 MRESULT EXPENTRY
wxGaugeWndProc( HWND hWnd
,
37 wxGauge
* pGauge
= (wxGauge
*)::WinQueryWindowULong( hWnd
44 double dPixelToRange
= 0.0;
50 hPS
= ::WinBeginPaint( hWnd
56 ::WinQueryWindowRect(hWnd
, &vRect
);
57 ::GpiCreateLogColorTable( hPS
61 ,(LONG
)wxTheColourDatabase
->m_nSize
62 ,(PLONG
)wxTheColourDatabase
->m_palTable
64 ::GpiCreateLogColorTable( hPS
74 LONG lColor
= 0x00FFFFFF; // White
75 POINTL vPoint
= {vRect
.xLeft
+ 1, vRect
.yBottom
+ 1};
77 ::GpiSetColor(hPS
, lColor
);
78 ::GpiMove(hPS
, &vPoint
);
79 vPoint
.x
= vRect
.xRight
- 1;
80 ::GpiLine(hPS
, &vPoint
);
81 vPoint
.y
= vRect
.yTop
- 1;
82 ::GpiLine(hPS
, &vPoint
);
83 lColor
= 0x000C0C0C; // Darkish Grey to give depth feel
84 ::GpiSetColor(hPS
, lColor
);
85 vPoint
.x
= vRect
.xLeft
+ 1;
86 ::GpiLine(hPS
, &vPoint
);
87 vPoint
.y
= vRect
.yBottom
+ 1;
88 ::GpiLine(hPS
, &vPoint
);
89 vRect3
.xLeft
= vRect
.xLeft
+ 2;
90 vRect3
.xRight
= vRect
.xRight
- 2;
91 vRect3
.yTop
= vRect
.yTop
- 2;
92 vRect3
.yBottom
= vRect
.yBottom
+ 2;
94 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
)
96 dRange
= (double)(vRect3
.yTop
- vRect3
.yBottom
);
97 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
98 vRect2
.yTop
= (int)(pGauge
->GetValue() * dPixelToRange
);
99 vRect2
.yBottom
= vRect3
.yBottom
;
100 vRect2
.xLeft
= vRect3
.xLeft
;
101 vRect2
.xRight
= vRect3
.xRight
;
102 vRect3
.yBottom
= vRect2
.yTop
;
103 if (vRect3
.yBottom
<= 1)
105 ::WinFillRect(hPS
, &vRect3
, pGauge
->GetBackgroundColour().GetPixel());
106 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
110 dRange
= (double)(vRect3
.xRight
- vRect3
.xLeft
);
111 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
112 vRect2
.yTop
= vRect3
.yTop
;
113 vRect2
.yBottom
= vRect3
.yBottom
;
114 vRect2
.xLeft
= vRect3
.xLeft
;
115 vRect2
.xRight
= (int)(pGauge
->GetValue() * dPixelToRange
);
116 vRect3
.xLeft
= vRect2
.xRight
;
117 if (vRect3
.xLeft
<= 1)
119 ::WinFillRect(hPS
, &vRect3
, pGauge
->GetBackgroundColour().GetPixel());
120 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
125 return (fnWndProcGauge( hWnd
131 } // end of wxGaugeWndProc
133 bool wxGauge::Create( wxWindowOS2
* pParent
,
139 const wxValidator
& rValidator
,
140 const wxString
& rsName
)
144 int nWidth
= rSize
.x
;
145 int nHeight
= rSize
.y
;
151 SetValidator(rValidator
);
154 pParent
->AddChild(this);
155 m_backgroundColour
.Set(wxString(wxT("LIGHT GREY")));
156 m_foregroundColour
.Set(wxString(wxT("NAVY")));
158 m_nRangeMax
= nRange
;
160 m_windowStyle
= lStyle
;
163 m_windowId
= (int)NewControlId();
167 if (m_windowStyle
& wxCLIP_SIBLINGS
)
168 lMsStyle
|= WS_CLIPSIBLINGS
;
171 // OS/2 will use an edit control for this, since there is not a native gauge
172 // Other choices include using an armless slider but they are more difficult
173 // to control and manipulate
176 lMsStyle
= WS_VISIBLE
| ES_MARGIN
| ES_LEFT
| ES_READONLY
;
177 if (m_windowStyle
& wxCLIP_SIBLINGS
)
178 lMsStyle
|= WS_CLIPSIBLINGS
;
180 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
181 ,WC_ENTRYFIELD
// Window class
182 ,(PSZ
)NULL
// Initial Text
183 ,(ULONG
)lMsStyle
// Style flags
184 ,0L, 0L, 0L, 0L // Origin -- 0 size
185 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
186 ,HWND_TOP
// initial z position
187 ,(HMENU
)m_windowId
// Window identifier
188 ,NULL
// Slider control data
189 ,NULL
// no Presentation parameters
192 wxAssociateWinWithHandle( m_hWnd
195 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
196 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
197 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
200 wxFont
* pTextFont
= new wxFont( 10
215 m_nWidth
= nWidth
; // Save for GetBestSize
217 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
220 } // end of wxGauge::Create
222 int wxGauge::GetBezelFace() const
225 } // end of wxGauge::GetBezelFace
227 int wxGauge::GetRange() const
230 } // end of wxGauge::GetRange
232 int wxGauge::GetShadowWidth() const
235 } // end of wxGauge::GetShadowWidth
237 int wxGauge::GetValue() const
240 } // end of wxGauge::GetValue
242 bool wxGauge::SetBackgroundColour( const wxColour
& rColour
)
244 if (!wxControl::SetBackgroundColour(rColour
))
247 LONG lColor
= (LONG
)rColour
.GetPixel();
249 ::WinSetPresParam( GetHwnd()
255 } // end of wxGauge::SetBackgroundColour
257 void wxGauge::SetBezelFace( int WXUNUSED(nWidth
) )
259 } // end of wxGauge::SetBezelFace
261 bool wxGauge::SetForegroundColour( const wxColour
& rColour
)
263 if (!wxControl::SetForegroundColour(rColour
))
266 LONG lColor
= (LONG
)rColour
.GetPixel();
268 ::WinSetPresParam( GetHwnd()
275 } // end of wxGauge::SetForegroundColour
277 void wxGauge::SetRange( int nRange
)
279 m_nRangeMax
= nRange
;
280 } // end of wxGauge::SetRange
282 void wxGauge::SetShadowWidth( int WXUNUSED(nWidth
) )
284 } // end of wxGauge::SetShadowWidth
286 void wxGauge::SetValue( int nPos
)
291 ::WinQueryWindowRect(GetHwnd(), &vRect
);
292 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
293 } // end of wxGauge::SetValue
295 wxSize
wxGauge::DoGetBestSize() const
297 return wxSize(m_nWidth
,m_nHeight
);
300 #endif // wxUSE_GAUGE