]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/bmpbuttn.cpp
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"
17 #include "wx/bmpbuttn.h"
22 #include "wx/os2/private.h"
25 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton
, wxButton
)
27 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
29 bool wxBitmapButton::Create( wxWindow
* pParent
,
31 const wxBitmap
& rBitmap
,
35 const wxValidator
& rValidator
,
36 const wxString
& rsName
)
38 m_bmpNormal
= rBitmap
;
41 SetValidator(rValidator
);
44 pParent
->AddChild(this);
46 m_backgroundColour
= pParent
->GetBackgroundColour() ;
47 m_foregroundColour
= pParent
->GetForegroundColour() ;
48 m_windowStyle
= lStyle
;
50 if (lStyle
& wxBU_AUTODRAW
)
52 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
53 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
59 int nHeight
= rSize
.y
;
62 m_windowId
= NewControlId();
66 if (nWidth
== wxDefaultCoord
&& rBitmap
.Ok())
67 nWidth
= rBitmap
.GetWidth() + 4 * m_marginX
;
69 if (nHeight
== wxDefaultCoord
&& rBitmap
.Ok())
70 nHeight
= rBitmap
.GetHeight() + 4 * m_marginY
;
72 ULONG ulOS2Style
= WS_VISIBLE
| WS_TABSTOP
| BS_USERBUTTON
;
74 if (m_windowStyle
& wxCLIP_SIBLINGS
)
75 ulOS2Style
|= WS_CLIPSIBLINGS
;
77 m_hWnd
= (WXHWND
)::WinCreateWindow( GetHwndOf(pParent
)
90 //Subclass again for purposes of dialog editing mode
93 SetFont(*wxSMALL_FONT
);
100 } // end of wxBitmapButton::Create
102 bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT
* pItem
)
104 PUSERBUTTON pUser
= (PUSERBUTTON
)pItem
;
105 bool bAutoDraw
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0;
111 bool bIsSelected
= pUser
->fsState
& BDS_HILITED
;
112 wxClientDC
vDc(this);
114 if (bIsSelected
&& m_bmpSelected
.Ok())
115 pBitmap
= &m_bmpSelected
;
116 else if ((pUser
->fsState
& BDS_DEFAULT
) && m_bmpFocus
.Ok())
117 pBitmap
= &m_bmpFocus
;
118 else if ((pUser
->fsState
& BDS_DISABLED
) && m_bmpDisabled
.Ok())
119 pBitmap
= &m_bmpDisabled
;
121 pBitmap
= &m_bmpNormal
;
128 // Centre the bitmap in the control area
133 int nWidth
= vDc
.m_vRclPaint
.xRight
- vDc
.m_vRclPaint
.xLeft
;
134 int nHeight
= vDc
.m_vRclPaint
.xRight
- vDc
.m_vRclPaint
.xLeft
;
135 int nBmpWidth
= pBitmap
->GetWidth();
136 int nBmpHeight
= pBitmap
->GetHeight();
138 nX1
= nX
+ (nWidth
- nBmpWidth
) / 2;
139 nY1
= nX
+ (nHeight
- nBmpHeight
) / 2;
141 if (bIsSelected
&& bAutoDraw
)
148 // Draw the button face
159 vDc
.DrawBitmap( *pBitmap
, nX1
, nY1
, true );
162 // Draw focus / disabled state, if auto-drawing
164 if ((pUser
->fsState
== BDS_DISABLED
) && bAutoDraw
)
166 DrawButtonDisable( vDc
170 else if ((pUser
->fsState
== BDS_DEFAULT
) && bAutoDraw
)
172 DrawButtonFocus(vDc
);
175 } // end of wxBitmapButton::OS2OnDraw
177 void wxBitmapButton::DrawFace (wxClientDC
& rDC
, bool bSel
)
180 // Set up drawing colors
182 wxPen
vHiLitePen(*wxWHITE
, 2, wxSOLID
); // White
183 wxColour
gray85(85, 85, 85);
184 wxPen
vDarkShadowPen(gray85
, 2, wxSOLID
);
185 wxColour
vFaceColor(204, 204, 204); // Light Grey
188 // Draw the main button face
190 ::WinFillRect(rDC
.GetHPS(), &rDC
.m_vRclPaint
, vFaceColor
.GetPixel());
195 rDC
.SetPen(bSel
? vDarkShadowPen
: vHiLitePen
);
196 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
197 ,rDC
.m_vRclPaint
.yTop
- 1
198 ,rDC
.m_vRclPaint
.xRight
- 1
199 ,rDC
.m_vRclPaint
.yTop
- 1
201 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
202 ,rDC
.m_vRclPaint
.yTop
- 1
203 ,rDC
.m_vRclPaint
.xLeft
+ 1
204 ,rDC
.m_vRclPaint
.yBottom
+ 1
207 rDC
.SetPen(bSel
? vHiLitePen
: vDarkShadowPen
);
208 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
209 ,rDC
.m_vRclPaint
.yBottom
+ 1
210 ,rDC
.m_vRclPaint
.xRight
- 1
211 ,rDC
.m_vRclPaint
.yBottom
+ 1
213 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
- 1
214 ,rDC
.m_vRclPaint
.yTop
- 1
215 ,rDC
.m_vRclPaint
.xRight
- 1
216 ,rDC
.m_vRclPaint
.yBottom
+ 1
219 } // end of wxBitmapButton::DrawFace
221 void wxBitmapButton::DrawButtonFocus (
225 wxPen
vBlackPen(*wxBLACK
, 2, wxSOLID
);
228 // Draw a thick black line around the outside of the button
230 rDC
.SetPen(vBlackPen
);
231 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
232 ,rDC
.m_vRclPaint
.yTop
233 ,rDC
.m_vRclPaint
.xRight
234 ,rDC
.m_vRclPaint
.yTop
236 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
237 ,rDC
.m_vRclPaint
.yTop
238 ,rDC
.m_vRclPaint
.xRight
239 ,rDC
.m_vRclPaint
.yBottom
241 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
242 ,rDC
.m_vRclPaint
.yBottom
243 ,rDC
.m_vRclPaint
.xLeft
244 ,rDC
.m_vRclPaint
.yBottom
246 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
247 ,rDC
.m_vRclPaint
.yBottom
248 ,rDC
.m_vRclPaint
.xLeft
249 ,rDC
.m_vRclPaint
.yTop
251 } // end of wxBitmapButton::DrawButtonFocus
253 void wxBitmapButton::DrawButtonDisable( wxClientDC
& rDC
,
256 wxPen
vGreyPen(wxT("GREY"), 2, wxSOLID
);
259 // Draw a thick black line around the outside of the button
261 rDC
.SetPen(vGreyPen
);
262 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
263 ,rDC
.m_vRclPaint
.yTop
264 ,rDC
.m_vRclPaint
.xRight
265 ,rDC
.m_vRclPaint
.yTop
267 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
268 ,rDC
.m_vRclPaint
.yTop
269 ,rDC
.m_vRclPaint
.xRight
270 ,rDC
.m_vRclPaint
.yBottom
272 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
273 ,rDC
.m_vRclPaint
.yBottom
274 ,rDC
.m_vRclPaint
.xLeft
275 ,rDC
.m_vRclPaint
.yBottom
277 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
278 ,rDC
.m_vRclPaint
.yBottom
279 ,rDC
.m_vRclPaint
.xLeft
280 ,rDC
.m_vRclPaint
.yTop
282 wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel());
283 } // end of wxBitmapButton::DrawButtonDisable
285 void wxBitmapButton::SetDefault()
287 wxButton::SetDefault();
290 #endif // ndef for wxUSE_BMPBUTTON