]> git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
Compilation fix for ANSI build after r61898.
[wxWidgets.git] / src / os2 / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/bmpbuttn.cpp
3 // Purpose: wxBitmapButton
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/13/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #if wxUSE_BMPBUTTON
16
17 #include "wx/bmpbuttn.h"
18
19 #ifndef WX_PRECOMP
20 #endif
21
22 #include "wx/os2/dcclient.h"
23 #include "wx/os2/private.h"
24
25
26 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
27
28 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
29
30 bool wxBitmapButton::Create( wxWindow* pParent,
31 wxWindowID vId,
32 const wxBitmap& rBitmap,
33 const wxPoint& rPos,
34 const wxSize& rSize,
35 long lStyle,
36 const wxValidator& rValidator,
37 const wxString& rsName )
38 {
39 m_bitmaps[State_Normal] = rBitmap;
40 SetName(rsName);
41 #if wxUSE_VALIDATORS
42 SetValidator(rValidator);
43 #endif
44
45 pParent->AddChild(this);
46
47 m_backgroundColour = pParent->GetBackgroundColour() ;
48 m_foregroundColour = pParent->GetForegroundColour() ;
49 m_windowStyle = lStyle;
50
51 if (lStyle & wxBU_AUTODRAW)
52 {
53 m_marginX = wxDEFAULT_BUTTON_MARGIN;
54 m_marginY = wxDEFAULT_BUTTON_MARGIN;
55 }
56
57 int nX = rPos.x;
58 int nY = rPos.y;
59 int nWidth = rSize.x;
60 int nHeight = rSize.y;
61
62 if (vId == wxID_ANY)
63 m_windowId = NewControlId();
64 else
65 m_windowId = vId;
66
67 if (nWidth == wxDefaultCoord && rBitmap.IsOk())
68 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
69
70 if (nHeight == wxDefaultCoord && rBitmap.IsOk())
71 nHeight = rBitmap.GetHeight() + 4 * m_marginY;
72
73 ULONG ulOS2Style = WS_VISIBLE | WS_TABSTOP | BS_USERBUTTON;
74
75 if (m_windowStyle & wxCLIP_SIBLINGS)
76 ulOS2Style |= WS_CLIPSIBLINGS;
77
78 m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(pParent)
79 ,WC_BUTTON
80 ,(PSZ)wxEmptyString
81 ,ulOS2Style
82 ,0, 0, 0, 0
83 ,GetHwndOf(pParent)
84 ,HWND_TOP
85 ,m_windowId
86 ,NULL
87 ,NULL
88 );
89
90 //
91 //Subclass again for purposes of dialog editing mode
92 //
93 SubclassWin(m_hWnd);
94 SetFont(*wxSMALL_FONT);
95 SetSize( nX
96 ,nY
97 ,nWidth
98 ,nHeight
99 );
100 return true;
101 } // end of wxBitmapButton::Create
102
103 bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem)
104 {
105 PUSERBUTTON pUser = (PUSERBUTTON)pItem;
106 bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;
107
108 if (!pUser)
109 return false;
110
111 wxBitmap bitmap;
112 bool bIsSelected = pUser->fsState & BDS_HILITED;
113 wxClientDC vDc(this);
114
115 if (bIsSelected)
116 bitmap = GetBitmapPressed();
117 else if (pUser->fsState & BDS_DEFAULT)
118 bitmap = GetBitmapFocus();
119 else if (pUser->fsState & BDS_DISABLED)
120 bitmap = GetBitmapDisabled();
121
122 if (!bitmap.IsOk() )
123 {
124 bitmap = GetBitmapLabel();
125 if (!bitmap.IsOk() )
126 return false;
127 }
128
129
130 //
131 // Centre the bitmap in the control area
132 //
133 int nX1 = 0;
134 int nY1 = 0;
135 wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl();
136 int nWidth = impl->m_vRclPaint.xRight - impl->m_vRclPaint.xLeft;
137 int nHeight = impl->m_vRclPaint.yTop - impl->m_vRclPaint.yBottom;
138 int nBmpWidth = bitmap.GetWidth();
139 int nBmpHeight = bitmap.GetHeight();
140
141 nX1 = (nWidth - nBmpWidth) / 2;
142 nY1 = (nHeight - nBmpHeight) / 2;
143
144 if (bIsSelected && bAutoDraw)
145 {
146 nX1++;
147 nY1++;
148 }
149
150 //
151 // Draw the button face
152 //
153 DrawFace( vDc, bIsSelected );
154
155 //
156 // Draw the bitmap
157 //
158 vDc.DrawBitmap( bitmap, nX1, nY1, true );
159
160 //
161 // Draw focus / disabled state, if auto-drawing
162 //
163 if ((pUser->fsState == BDS_DISABLED) && bAutoDraw)
164 {
165 DrawButtonDisable( vDc, bitmap );
166 }
167 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
168 {
169 DrawButtonFocus(vDc);
170 }
171 return true;
172 } // end of wxBitmapButton::OS2OnDraw
173
174 void wxBitmapButton::DrawFace (wxClientDC& rDC, bool bSel)
175 {
176 //
177 // Set up drawing colors
178 //
179 wxPen vHiLitePen(*wxWHITE, 2, wxSOLID); // White
180 wxColour gray85(85, 85, 85);
181 wxPen vDarkShadowPen(gray85, 2, wxSOLID);
182 wxColour vFaceColor(204, 204, 204); // Light Grey
183
184 //
185 // Draw the main button face
186 //
187 // This triggers a redraw and destroys the bottom & left focus border and
188 // doesn't seem to do anything useful.
189 // ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
190
191 //
192 // Draw the border
193 // Note: DrawLine expects wxWidgets coordinate system so swap
194 //
195 rDC.SetPen(bSel ? vDarkShadowPen : vHiLitePen);
196 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
197 // top
198 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
199 ,impl->m_vRclPaint.yBottom + 1
200 ,impl->m_vRclPaint.xRight - 1
201 ,impl->m_vRclPaint.yBottom + 1
202 );
203 // left
204 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
205 ,impl->m_vRclPaint.yBottom + 1
206 ,impl->m_vRclPaint.xLeft + 1
207 ,impl->m_vRclPaint.yTop - 1
208 );
209
210 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
211 // bottom
212 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
213 ,impl->m_vRclPaint.yTop - 1
214 ,impl->m_vRclPaint.xRight - 1
215 ,impl->m_vRclPaint.yTop - 1
216 );
217 // right
218 rDC.DrawLine( impl->m_vRclPaint.xRight - 1
219 ,impl->m_vRclPaint.yBottom + 1
220 ,impl->m_vRclPaint.xRight - 1
221 ,impl->m_vRclPaint.yTop - 1
222 );
223
224 } // end of wxBitmapButton::DrawFace
225
226 void wxBitmapButton::DrawButtonFocus (
227 wxClientDC& rDC
228 )
229 {
230 wxPen vBlackPen(*wxBLACK, 2, wxSOLID);
231
232 //
233 // Draw a thick black line around the outside of the button
234 // Note: DrawLine expects wxWidgets coordinate system so swap
235 //
236 rDC.SetPen(vBlackPen);
237 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
238 // top
239 rDC.DrawLine( impl->m_vRclPaint.xLeft
240 ,impl->m_vRclPaint.yBottom
241 ,impl->m_vRclPaint.xRight
242 ,impl->m_vRclPaint.yBottom
243 );
244 // right
245 rDC.DrawLine( impl->m_vRclPaint.xRight
246 ,impl->m_vRclPaint.yBottom
247 ,impl->m_vRclPaint.xRight
248 ,impl->m_vRclPaint.yTop
249 );
250 // bottom
251 rDC.DrawLine( impl->m_vRclPaint.xRight
252 ,impl->m_vRclPaint.yTop
253 ,impl->m_vRclPaint.xLeft
254 ,impl->m_vRclPaint.yTop
255 );
256 // left
257 rDC.DrawLine( impl->m_vRclPaint.xLeft
258 ,impl->m_vRclPaint.yTop
259 ,impl->m_vRclPaint.xLeft
260 ,impl->m_vRclPaint.yBottom
261 );
262 } // end of wxBitmapButton::DrawButtonFocus
263
264 void wxBitmapButton::DrawButtonDisable( wxClientDC& rDC,
265 wxBitmap& rBmp )
266 {
267 wxPen vGreyPen(wxT("GREY"), 2, wxSOLID);
268
269 //
270 // Draw a thick black line around the outside of the button
271 // Note: DrawLine expects wxWidgets coordinate system so swap
272 //
273 rDC.SetPen(vGreyPen);
274 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
275 // top
276 rDC.DrawLine( impl->m_vRclPaint.xLeft
277 ,impl->m_vRclPaint.yBottom
278 ,impl->m_vRclPaint.xRight
279 ,impl->m_vRclPaint.yBottom
280 );
281 // right
282 rDC.DrawLine( impl->m_vRclPaint.xRight
283 ,impl->m_vRclPaint.yBottom
284 ,impl->m_vRclPaint.xRight
285 ,impl->m_vRclPaint.yTop
286 );
287 // bottom
288 rDC.DrawLine( impl->m_vRclPaint.xRight
289 ,impl->m_vRclPaint.yTop
290 ,impl->m_vRclPaint.xLeft
291 ,impl->m_vRclPaint.yTop
292 );
293 // left
294 rDC.DrawLine( impl->m_vRclPaint.xLeft
295 ,impl->m_vRclPaint.yTop
296 ,impl->m_vRclPaint.xLeft
297 ,impl->m_vRclPaint.yBottom
298 );
299 wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel());
300 } // end of wxBitmapButton::DrawButtonDisable
301
302 #endif // ndef for wxUSE_BMPBUTTON