]>
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
7 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
16 #include "wx/bmpbuttn.h"
21 #include "wx/os2/dcclient.h"
22 #include "wx/os2/private.h"
25 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
27 bool wxBitmapButton::Create( wxWindow
* pParent
,
29 const wxBitmap
& rBitmap
,
33 const wxValidator
& rValidator
,
34 const wxString
& rsName
)
36 m_bitmaps
[State_Normal
] = rBitmap
;
39 SetValidator(rValidator
);
42 pParent
->AddChild(this);
44 m_backgroundColour
= pParent
->GetBackgroundColour() ;
45 m_foregroundColour
= pParent
->GetForegroundColour() ;
46 m_windowStyle
= lStyle
;
48 if (lStyle
& wxBU_AUTODRAW
)
50 m_marginX
= wxDEFAULT_BUTTON_MARGIN
;
51 m_marginY
= wxDEFAULT_BUTTON_MARGIN
;
57 int nHeight
= rSize
.y
;
60 m_windowId
= NewControlId();
64 if (nWidth
== wxDefaultCoord
&& rBitmap
.IsOk())
65 nWidth
= rBitmap
.GetWidth() + 4 * m_marginX
;
67 if (nHeight
== wxDefaultCoord
&& rBitmap
.IsOk())
68 nHeight
= rBitmap
.GetHeight() + 4 * m_marginY
;
70 ULONG ulOS2Style
= WS_VISIBLE
| WS_TABSTOP
| BS_USERBUTTON
;
72 if (m_windowStyle
& wxCLIP_SIBLINGS
)
73 ulOS2Style
|= WS_CLIPSIBLINGS
;
75 m_hWnd
= (WXHWND
)::WinCreateWindow( GetHwndOf(pParent
)
88 //Subclass again for purposes of dialog editing mode
91 SetFont(*wxSMALL_FONT
);
98 } // end of wxBitmapButton::Create
100 bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT
* pItem
)
102 PUSERBUTTON pUser
= (PUSERBUTTON
)pItem
;
103 bool bAutoDraw
= (GetWindowStyleFlag() & wxBU_AUTODRAW
) != 0;
109 bool bIsSelected
= pUser
->fsState
& BDS_HILITED
;
110 wxClientDC
vDc(this);
113 bitmap
= GetBitmapPressed();
114 else if (pUser
->fsState
& BDS_DEFAULT
)
115 bitmap
= GetBitmapFocus();
116 else if (pUser
->fsState
& BDS_DISABLED
)
117 bitmap
= GetBitmapDisabled();
121 bitmap
= GetBitmapLabel();
128 // Centre the bitmap in the control area
132 wxPMDCImpl
*impl
= (wxPMDCImpl
*) vDc
.GetImpl();
133 int nWidth
= impl
->m_vRclPaint
.xRight
- impl
->m_vRclPaint
.xLeft
;
134 int nHeight
= impl
->m_vRclPaint
.yTop
- impl
->m_vRclPaint
.yBottom
;
135 int nBmpWidth
= bitmap
.GetWidth();
136 int nBmpHeight
= bitmap
.GetHeight();
138 nX1
= (nWidth
- nBmpWidth
) / 2;
139 nY1
= (nHeight
- nBmpHeight
) / 2;
141 if (bIsSelected
&& bAutoDraw
)
148 // Draw the button face
150 DrawFace( vDc
, bIsSelected
);
155 vDc
.DrawBitmap( bitmap
, nX1
, nY1
, true );
158 // Draw focus / disabled state, if auto-drawing
160 if ((pUser
->fsState
== BDS_DISABLED
) && bAutoDraw
)
162 DrawButtonDisable( vDc
, bitmap
);
164 else if ((pUser
->fsState
== BDS_DEFAULT
) && bAutoDraw
)
166 DrawButtonFocus(vDc
);
169 } // end of wxBitmapButton::OS2OnDraw
171 void wxBitmapButton::DrawFace (wxClientDC
& rDC
, bool bSel
)
174 // Set up drawing colors
176 wxPen
vHiLitePen(*wxWHITE
, 2, wxSOLID
); // White
177 wxColour
gray85(85, 85, 85);
178 wxPen
vDarkShadowPen(gray85
, 2, wxSOLID
);
179 wxColour
vFaceColor(204, 204, 204); // Light Grey
182 // Draw the main button face
184 // This triggers a redraw and destroys the bottom & left focus border and
185 // doesn't seem to do anything useful.
186 // ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
190 // Note: DrawLine expects wxWidgets coordinate system so swap
192 rDC
.SetPen(bSel
? vDarkShadowPen
: vHiLitePen
);
193 wxPMDCImpl
*impl
= (wxPMDCImpl
*) rDC
.GetImpl();
195 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
+ 1
196 ,impl
->m_vRclPaint
.yBottom
+ 1
197 ,impl
->m_vRclPaint
.xRight
- 1
198 ,impl
->m_vRclPaint
.yBottom
+ 1
201 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
+ 1
202 ,impl
->m_vRclPaint
.yBottom
+ 1
203 ,impl
->m_vRclPaint
.xLeft
+ 1
204 ,impl
->m_vRclPaint
.yTop
- 1
207 rDC
.SetPen(bSel
? vHiLitePen
: vDarkShadowPen
);
209 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
+ 1
210 ,impl
->m_vRclPaint
.yTop
- 1
211 ,impl
->m_vRclPaint
.xRight
- 1
212 ,impl
->m_vRclPaint
.yTop
- 1
215 rDC
.DrawLine( impl
->m_vRclPaint
.xRight
- 1
216 ,impl
->m_vRclPaint
.yBottom
+ 1
217 ,impl
->m_vRclPaint
.xRight
- 1
218 ,impl
->m_vRclPaint
.yTop
- 1
221 } // end of wxBitmapButton::DrawFace
223 void wxBitmapButton::DrawButtonFocus (
227 wxPen
vBlackPen(*wxBLACK
, 2, wxSOLID
);
230 // Draw a thick black line around the outside of the button
231 // Note: DrawLine expects wxWidgets coordinate system so swap
233 rDC
.SetPen(vBlackPen
);
234 wxPMDCImpl
*impl
= (wxPMDCImpl
*) rDC
.GetImpl();
236 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
237 ,impl
->m_vRclPaint
.yBottom
238 ,impl
->m_vRclPaint
.xRight
239 ,impl
->m_vRclPaint
.yBottom
242 rDC
.DrawLine( impl
->m_vRclPaint
.xRight
243 ,impl
->m_vRclPaint
.yBottom
244 ,impl
->m_vRclPaint
.xRight
245 ,impl
->m_vRclPaint
.yTop
248 rDC
.DrawLine( impl
->m_vRclPaint
.xRight
249 ,impl
->m_vRclPaint
.yTop
250 ,impl
->m_vRclPaint
.xLeft
251 ,impl
->m_vRclPaint
.yTop
254 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
255 ,impl
->m_vRclPaint
.yTop
256 ,impl
->m_vRclPaint
.xLeft
257 ,impl
->m_vRclPaint
.yBottom
259 } // end of wxBitmapButton::DrawButtonFocus
261 void wxBitmapButton::DrawButtonDisable( wxClientDC
& rDC
,
264 wxPen
vGreyPen(wxT("GREY"), 2, wxSOLID
);
267 // Draw a thick black line around the outside of the button
268 // Note: DrawLine expects wxWidgets coordinate system so swap
270 rDC
.SetPen(vGreyPen
);
271 wxPMDCImpl
*impl
= (wxPMDCImpl
*) rDC
.GetImpl();
273 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
274 ,impl
->m_vRclPaint
.yBottom
275 ,impl
->m_vRclPaint
.xRight
276 ,impl
->m_vRclPaint
.yBottom
279 rDC
.DrawLine( impl
->m_vRclPaint
.xRight
280 ,impl
->m_vRclPaint
.yBottom
281 ,impl
->m_vRclPaint
.xRight
282 ,impl
->m_vRclPaint
.yTop
285 rDC
.DrawLine( impl
->m_vRclPaint
.xRight
286 ,impl
->m_vRclPaint
.yTop
287 ,impl
->m_vRclPaint
.xLeft
288 ,impl
->m_vRclPaint
.yTop
291 rDC
.DrawLine( impl
->m_vRclPaint
.xLeft
292 ,impl
->m_vRclPaint
.yTop
293 ,impl
->m_vRclPaint
.xLeft
294 ,impl
->m_vRclPaint
.yBottom
296 wxDisableBitmap(rBmp
, vGreyPen
.GetColour().GetPixel());
297 } // end of wxBitmapButton::DrawButtonDisable
299 #endif // ndef for wxUSE_BMPBUTTON