]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBitmapButton
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
18 #include "wx/bmpbuttn.h"
21 #include "wx/os2/private.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
26 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
28 bool wxBitmapButton::Create(
31 , const wxBitmap
& rBitmap
36 , const wxValidator
& rValidator
38 , const wxString
& rsName
41 m_bmpNormal
= rBitmap
;
44 SetValidator(rValidator
);
47 pParent
->AddChild(this);
49 m_backgroundColour
= pParent
->GetBackgroundColour() ;
50 m_foregroundColour
= pParent
->GetForegroundColour() ;
51 m_windowStyle
= lStyle
;
53 if (lStyle
& wxBU_AUTODRAW
)
55 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
56 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
62 int nHeight
= rSize
.y
;
65 m_windowId
= NewControlId();
69 if (nWidth
== -1 && rBitmap
.Ok())
70 nWidth
= rBitmap
.GetWidth() + 2 * m_marginX
;
72 if (nHeight
== -1 && rBitmap
.Ok())
73 nHeight
= rBitmap
.GetHeight() + 2 * m_marginY
;
75 ULONG ulOS2Style
= WS_VISIBLE
| WS_TABSTOP
| BS_USERBUTTON
;
77 if (m_windowStyle
& wxCLIP_SIBLINGS
)
78 ulOS2Style
|= WS_CLIPSIBLINGS
;
80 m_hWnd
= (WXHWND
)::WinCreateWindow( GetHwndOf(pParent
)
93 //Subclass again for purposes of dialog editing mode
96 SetFont(*wxSMALL_FONT
);
103 } // end of wxBitmapButton::Create
105 bool wxBitmapButton::OS2OnDraw(
106 WXDRAWITEMSTRUCT
* pItem
109 PUSERBUTTON pUser
= (PUSERBUTTON
)pItem
;
110 bool bAutoDraw
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0;
117 bool bIsSelected
= pUser
->fsState
& BDS_HILITED
;
118 wxClientDC
vDc(this);
120 if (bIsSelected
&& m_bmpSelected
.Ok())
121 pBitmap
= &m_bmpSelected
;
122 else if ((pUser
->fsState
& BDS_DEFAULT
) && m_bmpFocus
.Ok())
123 pBitmap
= &m_bmpFocus
;
124 else if ((pUser
->fsState
& BDS_DISABLED
) && m_bmpDisabled
.Ok())
125 pBitmap
= &m_bmpDisabled
;
127 pBitmap
= &m_bmpNormal
;
134 // Centre the bitmap in the control area
140 int nWidth
= vDc
.m_vRclPaint
.xRight
- vDc
.m_vRclPaint
.xLeft
;
141 int nHeight
= vDc
.m_vRclPaint
.xRight
- vDc
.m_vRclPaint
.xLeft
;
142 int nBmpWidth
= pBitmap
->GetWidth();
143 int nBmpHeight
= pBitmap
->GetHeight();
145 nX1
= nX
+ (nWidth
- nBmpWidth
) / 2;
146 nY1
= nX
+ (nHeight
- nBmpHeight
) / 2;
148 if (bIsSelected
&& bAutoDraw
)
155 // Draw the button face
166 vDc
.DrawBitmap( *pBitmap
173 // Draw focus / disabled state, if auto-drawing
175 if ((pUser
->fsState
== BDS_DISABLED
) && bAutoDraw
)
177 DrawButtonDisable( vDc
181 else if ((pUser
->fsState
== BDS_DEFAULT
) && bAutoDraw
)
183 DrawButtonFocus(vDc
);
186 } // end of wxBitmapButton::OS2OnDraw
188 void wxBitmapButton::DrawFace (
194 // Set up drawing colors
196 wxPen
vHiLitePen(wxColour(255, 255, 255), 1, wxSOLID
); // White
197 wxPen
vLitePen(wxColour(223, 223, 223), 1, wxSOLID
); // Very Light Grey
198 wxPen
vShadowPen(wxColour(191, 191, 191), 1, wxSOLID
); // Medium Grey
199 wxPen
vDarkShadowPen(wxColour(128, 128, 128), 1, wxSOLID
);
200 wxColour
vFaceColor(wxColour(204, 204, 204)); // Light Grey
203 // Draw the main button face
205 ::WinFillRect(rDC
.GetHPS(), &rDC
.m_vRclPaint
, vFaceColor
.GetPixel());
210 rDC
.SetPen(bSel
? vDarkShadowPen
: vHiLitePen
);
211 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
212 ,rDC
.m_vRclPaint
.yTop
213 ,rDC
.m_vRclPaint
.xRight
- 1
214 ,rDC
.m_vRclPaint
.yTop
216 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
217 ,rDC
.m_vRclPaint
.yTop
+ 1
218 ,rDC
.m_vRclPaint
.xLeft
219 ,rDC
.m_vRclPaint
.yBottom
- 1
222 rDC
.SetPen(bSel
? vShadowPen
: vLitePen
);
223 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
224 ,rDC
.m_vRclPaint
.yTop
+ 1
225 ,rDC
.m_vRclPaint
.xRight
- 2
226 ,rDC
.m_vRclPaint
.yTop
+ 1
228 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
229 ,rDC
.m_vRclPaint
.yTop
+ 2
230 ,rDC
.m_vRclPaint
.xLeft
+ 1
231 ,rDC
.m_vRclPaint
.yBottom
- 2
234 rDC
.SetPen(bSel
? vLitePen
: vShadowPen
);
235 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
236 ,rDC
.m_vRclPaint
.yBottom
- 2
237 ,rDC
.m_vRclPaint
.xRight
- 1
238 ,rDC
.m_vRclPaint
.yBottom
- 2
240 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
- 2
241 ,rDC
.m_vRclPaint
.yBottom
- 3
242 ,rDC
.m_vRclPaint
.xRight
- 2
243 ,rDC
.m_vRclPaint
.yTop
246 rDC
.SetPen(bSel
? vDarkShadowPen
: vHiLitePen
);
247 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
248 ,rDC
.m_vRclPaint
.yBottom
- 1
249 ,rDC
.m_vRclPaint
.xRight
+ 2
250 ,rDC
.m_vRclPaint
.yBottom
- 1
252 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
- 1
253 ,rDC
.m_vRclPaint
.yBottom
- 2
254 ,rDC
.m_vRclPaint
.xRight
- 1
255 ,rDC
.m_vRclPaint
.yTop
- 1
257 } // end of wxBitmapButton::DrawFace
259 void wxBitmapButton::DrawButtonFocus (
263 wxPen
vBlackPen(wxColour(0, 0, 0), 2, wxSOLID
);
266 // Draw a thick black line around the outside of the button
268 rDC
.SetPen(vBlackPen
);
269 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
270 ,rDC
.m_vRclPaint
.yTop
271 ,rDC
.m_vRclPaint
.xRight
272 ,rDC
.m_vRclPaint
.yTop
274 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
275 ,rDC
.m_vRclPaint
.yTop
276 ,rDC
.m_vRclPaint
.xRight
277 ,rDC
.m_vRclPaint
.yBottom
279 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
280 ,rDC
.m_vRclPaint
.yBottom
281 ,rDC
.m_vRclPaint
.xLeft
282 ,rDC
.m_vRclPaint
.yBottom
284 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
285 ,rDC
.m_vRclPaint
.yBottom
286 ,rDC
.m_vRclPaint
.xLeft
287 ,rDC
.m_vRclPaint
.yTop
289 } // end of wxBitmapButton::DrawButtonFocus
291 void wxBitmapButton::DrawButtonDisable(
296 wxPen
vGreyPen(wxColour(128, 128, 128), 2, wxSOLID
);
299 // Draw a thick black line around the outside of the button
301 rDC
.SetPen(vGreyPen
);
302 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
303 ,rDC
.m_vRclPaint
.yTop
304 ,rDC
.m_vRclPaint
.xRight
305 ,rDC
.m_vRclPaint
.yTop
307 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
308 ,rDC
.m_vRclPaint
.yTop
309 ,rDC
.m_vRclPaint
.xRight
310 ,rDC
.m_vRclPaint
.yBottom
312 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
313 ,rDC
.m_vRclPaint
.yBottom
314 ,rDC
.m_vRclPaint
.xLeft
315 ,rDC
.m_vRclPaint
.yBottom
317 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
318 ,rDC
.m_vRclPaint
.yBottom
319 ,rDC
.m_vRclPaint
.xLeft
320 ,rDC
.m_vRclPaint
.yTop
322 wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel());
323 } // end of wxBitmapButton::DrawButtonDisable
325 void wxBitmapButton::SetDefault()
327 wxButton::SetDefault();
330 #endif // ndef for wxUSE_BMPBUTTON