]>
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
35 , const wxValidator
& rValidator
36 , const wxString
& rsName
39 m_bmpNormal
= rBitmap
;
42 SetValidator(rValidator
);
45 pParent
->AddChild(this);
47 m_backgroundColour
= pParent
->GetBackgroundColour() ;
48 m_foregroundColour
= pParent
->GetForegroundColour() ;
49 m_windowStyle
= lStyle
;
51 if (lStyle
& wxBU_AUTODRAW
)
53 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
54 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
60 int nHeight
= rSize
.y
;
63 m_windowId
= NewControlId();
67 if (nWidth
== -1 && rBitmap
.Ok())
68 nWidth
= rBitmap
.GetWidth() + 4 * m_marginX
;
70 if (nHeight
== -1 && rBitmap
.Ok())
71 nHeight
= rBitmap
.GetHeight() + 4 * m_marginY
;
73 ULONG ulOS2Style
= WS_VISIBLE
| WS_TABSTOP
| BS_USERBUTTON
;
75 if (m_windowStyle
& wxCLIP_SIBLINGS
)
76 ulOS2Style
|= WS_CLIPSIBLINGS
;
78 m_hWnd
= (WXHWND
)::WinCreateWindow( GetHwndOf(pParent
)
91 //Subclass again for purposes of dialog editing mode
94 SetFont(*wxSMALL_FONT
);
101 } // end of wxBitmapButton::Create
103 bool wxBitmapButton::OS2OnDraw(
104 WXDRAWITEMSTRUCT
* pItem
107 PUSERBUTTON pUser
= (PUSERBUTTON
)pItem
;
108 bool bAutoDraw
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0;
114 bool bIsSelected
= pUser
->fsState
& BDS_HILITED
;
115 wxClientDC
vDc(this);
117 if (bIsSelected
&& m_bmpSelected
.Ok())
118 pBitmap
= &m_bmpSelected
;
119 else if ((pUser
->fsState
& BDS_DEFAULT
) && m_bmpFocus
.Ok())
120 pBitmap
= &m_bmpFocus
;
121 else if ((pUser
->fsState
& BDS_DISABLED
) && m_bmpDisabled
.Ok())
122 pBitmap
= &m_bmpDisabled
;
124 pBitmap
= &m_bmpNormal
;
131 // Centre the bitmap in the control area
136 int nWidth
= vDc
.m_vRclPaint
.xRight
- vDc
.m_vRclPaint
.xLeft
;
137 int nHeight
= vDc
.m_vRclPaint
.xRight
- vDc
.m_vRclPaint
.xLeft
;
138 int nBmpWidth
= pBitmap
->GetWidth();
139 int nBmpHeight
= pBitmap
->GetHeight();
141 nX1
= nX
+ (nWidth
- nBmpWidth
) / 2;
142 nY1
= nX
+ (nHeight
- nBmpHeight
) / 2;
144 if (bIsSelected
&& bAutoDraw
)
151 // Draw the button face
162 vDc
.DrawBitmap( *pBitmap
169 // Draw focus / disabled state, if auto-drawing
171 if ((pUser
->fsState
== BDS_DISABLED
) && bAutoDraw
)
173 DrawButtonDisable( vDc
177 else if ((pUser
->fsState
== BDS_DEFAULT
) && bAutoDraw
)
179 DrawButtonFocus(vDc
);
182 } // end of wxBitmapButton::OS2OnDraw
184 void wxBitmapButton::DrawFace (
190 // Set up drawing colors
192 wxPen
vHiLitePen(wxColour(255, 255, 255), 2, wxSOLID
); // White
193 wxPen
vDarkShadowPen(wxColour(85, 85, 85), 2, wxSOLID
);
194 wxColour
vFaceColor(wxColour(204, 204, 204)); // Light Grey
197 // Draw the main button face
199 ::WinFillRect(rDC
.GetHPS(), &rDC
.m_vRclPaint
, vFaceColor
.GetPixel());
204 rDC
.SetPen(bSel
? vDarkShadowPen
: vHiLitePen
);
205 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
206 ,rDC
.m_vRclPaint
.yTop
- 1
207 ,rDC
.m_vRclPaint
.xRight
- 1
208 ,rDC
.m_vRclPaint
.yTop
- 1
210 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
211 ,rDC
.m_vRclPaint
.yTop
- 1
212 ,rDC
.m_vRclPaint
.xLeft
+ 1
213 ,rDC
.m_vRclPaint
.yBottom
+ 1
216 rDC
.SetPen(bSel
? vHiLitePen
: vDarkShadowPen
);
217 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
+ 1
218 ,rDC
.m_vRclPaint
.yBottom
+ 1
219 ,rDC
.m_vRclPaint
.xRight
- 1
220 ,rDC
.m_vRclPaint
.yBottom
+ 1
222 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
- 1
223 ,rDC
.m_vRclPaint
.yTop
- 1
224 ,rDC
.m_vRclPaint
.xRight
- 1
225 ,rDC
.m_vRclPaint
.yBottom
+ 1
228 } // end of wxBitmapButton::DrawFace
230 void wxBitmapButton::DrawButtonFocus (
234 wxPen
vBlackPen(wxColour(0, 0, 0), 2, wxSOLID
);
237 // Draw a thick black line around the outside of the button
239 rDC
.SetPen(vBlackPen
);
240 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
241 ,rDC
.m_vRclPaint
.yTop
242 ,rDC
.m_vRclPaint
.xRight
243 ,rDC
.m_vRclPaint
.yTop
245 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
246 ,rDC
.m_vRclPaint
.yTop
247 ,rDC
.m_vRclPaint
.xRight
248 ,rDC
.m_vRclPaint
.yBottom
250 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
251 ,rDC
.m_vRclPaint
.yBottom
252 ,rDC
.m_vRclPaint
.xLeft
253 ,rDC
.m_vRclPaint
.yBottom
255 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
256 ,rDC
.m_vRclPaint
.yBottom
257 ,rDC
.m_vRclPaint
.xLeft
258 ,rDC
.m_vRclPaint
.yTop
260 } // end of wxBitmapButton::DrawButtonFocus
262 void wxBitmapButton::DrawButtonDisable(
267 wxPen
vGreyPen(wxColour(128, 128, 128), 2, wxSOLID
);
270 // Draw a thick black line around the outside of the button
272 rDC
.SetPen(vGreyPen
);
273 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
274 ,rDC
.m_vRclPaint
.yTop
275 ,rDC
.m_vRclPaint
.xRight
276 ,rDC
.m_vRclPaint
.yTop
278 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
279 ,rDC
.m_vRclPaint
.yTop
280 ,rDC
.m_vRclPaint
.xRight
281 ,rDC
.m_vRclPaint
.yBottom
283 rDC
.DrawLine( rDC
.m_vRclPaint
.xRight
284 ,rDC
.m_vRclPaint
.yBottom
285 ,rDC
.m_vRclPaint
.xLeft
286 ,rDC
.m_vRclPaint
.yBottom
288 rDC
.DrawLine( rDC
.m_vRclPaint
.xLeft
289 ,rDC
.m_vRclPaint
.yBottom
290 ,rDC
.m_vRclPaint
.xLeft
291 ,rDC
.m_vRclPaint
.yTop
293 wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel());
294 } // end of wxBitmapButton::DrawButtonDisable
296 void wxBitmapButton::SetDefault()
298 wxButton::SetDefault();
301 #endif // ndef for wxUSE_BMPBUTTON