]>
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() + 4 * m_marginX
;
72 if (nHeight
== -1 && rBitmap
.Ok())
73 nHeight
= rBitmap
.GetHeight() + 4 * 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), 2, wxSOLID
); // White
197 wxPen
vDarkShadowPen(wxColour(85, 85, 85), 2, wxSOLID
);
198 wxColour
vFaceColor(wxColour(204, 204, 204)); // Light Grey
201 // Draw the main button face
203 ::WinFillRect(rDC
.GetHPS(), &rDC
.m_vRclPaint
, vFaceColor
.GetPixel());
208 rDC
.SetPen(bSel
? vDarkShadowPen
: vHiLitePen
);
209 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
210 ,rDC
.m_vRclPaint
.yTop
- 1
211 ,rDC
.m_vRclPaint
.xRight
- 1
212 ,rDC
.m_vRclPaint
.yTop
- 1
214 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
215 ,rDC
.m_vRclPaint
.yTop
- 1
216 ,rDC
.m_vRclPaint
.xLeft
+ 1
217 ,rDC
.m_vRclPaint
.yBottom
+ 1
220 rDC
.SetPen(bSel
? vHiLitePen
: vDarkShadowPen
);
221 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
222 ,rDC
.m_vRclPaint
.yBottom
+ 1
223 ,rDC
.m_vRclPaint
.xRight
- 1
224 ,rDC
.m_vRclPaint
.yBottom
+ 1
226 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
- 1
227 ,rDC
.m_vRclPaint
.yTop
- 1
228 ,rDC
.m_vRclPaint
.xRight
- 1
229 ,rDC
.m_vRclPaint
.yBottom
+ 1
232 } // end of wxBitmapButton::DrawFace
234 void wxBitmapButton::DrawButtonFocus (
238 wxPen
vBlackPen(wxColour(0, 0, 0), 2, wxSOLID
);
241 // Draw a thick black line around the outside of the button
243 rDC
.SetPen(vBlackPen
);
244 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
245 ,rDC
.m_vRclPaint
.yTop
246 ,rDC
.m_vRclPaint
.xRight
247 ,rDC
.m_vRclPaint
.yTop
249 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
250 ,rDC
.m_vRclPaint
.yTop
251 ,rDC
.m_vRclPaint
.xRight
252 ,rDC
.m_vRclPaint
.yBottom
254 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
255 ,rDC
.m_vRclPaint
.yBottom
256 ,rDC
.m_vRclPaint
.xLeft
257 ,rDC
.m_vRclPaint
.yBottom
259 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
260 ,rDC
.m_vRclPaint
.yBottom
261 ,rDC
.m_vRclPaint
.xLeft
262 ,rDC
.m_vRclPaint
.yTop
264 } // end of wxBitmapButton::DrawButtonFocus
266 void wxBitmapButton::DrawButtonDisable(
271 wxPen
vGreyPen(wxColour(128, 128, 128), 2, wxSOLID
);
274 // Draw a thick black line around the outside of the button
276 rDC
.SetPen(vGreyPen
);
277 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
278 ,rDC
.m_vRclPaint
.yTop
279 ,rDC
.m_vRclPaint
.xRight
280 ,rDC
.m_vRclPaint
.yTop
282 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
283 ,rDC
.m_vRclPaint
.yTop
284 ,rDC
.m_vRclPaint
.xRight
285 ,rDC
.m_vRclPaint
.yBottom
287 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
288 ,rDC
.m_vRclPaint
.yBottom
289 ,rDC
.m_vRclPaint
.xLeft
290 ,rDC
.m_vRclPaint
.yBottom
292 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
293 ,rDC
.m_vRclPaint
.yBottom
294 ,rDC
.m_vRclPaint
.xLeft
295 ,rDC
.m_vRclPaint
.yTop
297 wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel());
298 } // end of wxBitmapButton::DrawButtonDisable
300 void wxBitmapButton::SetDefault()
302 wxButton::SetDefault();
305 #endif // ndef for wxUSE_BMPBUTTON