]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
19 #include "wx/scrolwin.h"
22 #include "wx/os2/private.h"
24 static WXFARPROC fnWndProcGauge
= (WXFARPROC
)NULL
;
25 extern void wxAssociateWinWithHandle( HWND hWnd
29 MRESULT EXPENTRY
wxGaugeWndProc( HWND hWnd
,
34 wxGauge
* pGauge
= (wxGauge
*)::WinQueryWindowULong( hWnd
41 double dPixelToRange
= 0.0;
47 hPS
= ::WinBeginPaint( hWnd
53 ::WinQueryWindowRect(hWnd
, &vRect
);
54 ::GpiCreateLogColorTable( hPS
58 ,(LONG
)wxTheColourDatabase
->m_nSize
59 ,(PLONG
)wxTheColourDatabase
->m_palTable
61 ::GpiCreateLogColorTable( hPS
71 LONG lColor
= 0x00FFFFFF; // White
72 POINTL vPoint
= {vRect
.xLeft
+ 1, vRect
.yBottom
+ 1};
74 ::GpiSetColor(hPS
, lColor
);
75 ::GpiMove(hPS
, &vPoint
);
76 vPoint
.x
= vRect
.xRight
- 1;
77 ::GpiLine(hPS
, &vPoint
);
78 vPoint
.y
= vRect
.yTop
- 1;
79 ::GpiLine(hPS
, &vPoint
);
80 lColor
= 0x000C0C0C; // Darkish Grey to give depth feel
81 ::GpiSetColor(hPS
, lColor
);
82 vPoint
.x
= vRect
.xLeft
+ 1;
83 ::GpiLine(hPS
, &vPoint
);
84 vPoint
.y
= vRect
.yBottom
+ 1;
85 ::GpiLine(hPS
, &vPoint
);
86 vRect3
.xLeft
= vRect
.xLeft
+ 2;
87 vRect3
.xRight
= vRect
.xRight
- 2;
88 vRect3
.yTop
= vRect
.yTop
- 2;
89 vRect3
.yBottom
= vRect
.yBottom
+ 2;
91 if (pGauge
->GetWindowStyleFlag() & wxGA_VERTICAL
)
93 dRange
= (double)(vRect3
.yTop
- vRect3
.yBottom
);
94 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
95 vRect2
.yTop
= (int)(pGauge
->GetValue() * dPixelToRange
);
96 vRect2
.yBottom
= vRect3
.yBottom
;
97 vRect2
.xLeft
= vRect3
.xLeft
;
98 vRect2
.xRight
= vRect3
.xRight
;
99 vRect3
.yBottom
= vRect2
.yTop
;
100 if (vRect3
.yBottom
<= 1)
102 ::WinFillRect(hPS
, &vRect3
, pGauge
->GetBackgroundColour().GetPixel());
103 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
107 dRange
= (double)(vRect3
.xRight
- vRect3
.xLeft
);
108 dPixelToRange
= dRange
/(double)pGauge
->GetRange();
109 vRect2
.yTop
= vRect3
.yTop
;
110 vRect2
.yBottom
= vRect3
.yBottom
;
111 vRect2
.xLeft
= vRect3
.xLeft
;
112 vRect2
.xRight
= (int)(pGauge
->GetValue() * dPixelToRange
);
113 vRect3
.xLeft
= vRect2
.xRight
;
114 if (vRect3
.xLeft
<= 1)
116 ::WinFillRect(hPS
, &vRect3
, pGauge
->GetBackgroundColour().GetPixel());
117 ::WinFillRect(hPS
, &vRect2
, pGauge
->GetForegroundColour().GetPixel());
122 return (fnWndProcGauge( hWnd
128 } // end of wxGaugeWndProc
130 bool wxGauge::Create( wxWindowOS2
* pParent
,
136 const wxValidator
& rValidator
,
137 const wxString
& rsName
)
141 int nWidth
= rSize
.x
;
142 int nHeight
= rSize
.y
;
148 SetValidator(rValidator
);
151 pParent
->AddChild(this);
152 m_backgroundColour
.Set(wxString(wxT("LIGHT GREY")));
153 m_foregroundColour
.Set(wxString(wxT("NAVY")));
155 m_nRangeMax
= nRange
;
157 m_windowStyle
= lStyle
;
160 m_windowId
= (int)NewControlId();
164 if (m_windowStyle
& wxCLIP_SIBLINGS
)
165 lMsStyle
|= WS_CLIPSIBLINGS
;
168 // OS/2 will use an edit control for this, since there is not a native gauge
169 // Other choices include using an armless slider but they are more difficult
170 // to control and manipulate
173 lMsStyle
= WS_VISIBLE
| ES_MARGIN
| ES_LEFT
| ES_READONLY
;
174 if (m_windowStyle
& wxCLIP_SIBLINGS
)
175 lMsStyle
|= WS_CLIPSIBLINGS
;
177 m_hWnd
= (WXHWND
)::WinCreateWindow( (HWND
)GetHwndOf(pParent
) // Parent window handle
178 ,WC_ENTRYFIELD
// Window class
179 ,(PSZ
)NULL
// Initial Text
180 ,(ULONG
)lMsStyle
// Style flags
181 ,0L, 0L, 0L, 0L // Origin -- 0 size
182 ,(HWND
)GetHwndOf(pParent
) // owner window handle (same as parent
183 ,HWND_TOP
// initial z position
184 ,(HMENU
)m_windowId
// Window identifier
185 ,NULL
// Slider control data
186 ,NULL
// no Presentation parameters
189 wxAssociateWinWithHandle( m_hWnd
192 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
193 fnWndProcGauge
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxGaugeWndProc
);
194 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
197 wxFont
* pTextFont
= new wxFont( 10
212 m_nWidth
= nWidth
; // Save for GetBestSize
214 ::WinShowWindow((HWND
)GetHWND(), TRUE
);
217 } // end of wxGauge::Create
219 int wxGauge::GetBezelFace() const
222 } // end of wxGauge::GetBezelFace
224 int wxGauge::GetRange() const
227 } // end of wxGauge::GetRange
229 int wxGauge::GetShadowWidth() const
232 } // end of wxGauge::GetShadowWidth
234 int wxGauge::GetValue() const
237 } // end of wxGauge::GetValue
239 bool wxGauge::SetBackgroundColour( const wxColour
& rColour
)
241 if (!wxControl::SetBackgroundColour(rColour
))
244 LONG lColor
= (LONG
)rColour
.GetPixel();
246 ::WinSetPresParam( GetHwnd()
252 } // end of wxGauge::SetBackgroundColour
254 void wxGauge::SetBezelFace( int WXUNUSED(nWidth
) )
256 } // end of wxGauge::SetBezelFace
258 bool wxGauge::SetForegroundColour( const wxColour
& rColour
)
260 if (!wxControl::SetForegroundColour(rColour
))
263 LONG lColor
= (LONG
)rColour
.GetPixel();
265 ::WinSetPresParam( GetHwnd()
272 } // end of wxGauge::SetForegroundColour
274 void wxGauge::SetRange( int nRange
)
276 m_nRangeMax
= nRange
;
277 } // end of wxGauge::SetRange
279 void wxGauge::SetShadowWidth( int WXUNUSED(nWidth
) )
281 } // end of wxGauge::SetShadowWidth
283 void wxGauge::SetValue( int nPos
)
288 ::WinQueryWindowRect(GetHwnd(), &vRect
);
289 ::WinInvalidateRect(GetHwnd(), &vRect
, FALSE
);
290 } // end of wxGauge::SetValue
292 wxSize
wxGauge::DoGetBestSize() const
294 return wxSize(m_nWidth
,m_nHeight
);
297 #endif // wxUSE_GAUGE