]> git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
Clipboard usage fixes inspired by Tinderbox logs.
[wxWidgets.git] / src / os2 / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifndef WX_PRECOMP
18 #include "wx/bmpbuttn.h"
19 #endif
20
21 #include "wx/os2/private.h"
22
23
24 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
25
26 #define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
27
28 bool wxBitmapButton::Create(
29 wxWindow* pParent
30 , wxWindowID vId
31 , const wxBitmap& rBitmap
32 , const wxPoint& rPos
33 , const wxSize& rSize
34 , long lStyle
35 , const wxValidator& rValidator
36 , const wxString& rsName
37 )
38 {
39 m_bmpNormal = 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 == -1)
63 m_windowId = NewControlId();
64 else
65 m_windowId = vId;
66
67 if (nWidth == -1 && rBitmap.Ok())
68 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
69
70 if (nHeight == -1 && rBitmap.Ok())
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(
104 WXDRAWITEMSTRUCT* pItem
105 )
106 {
107 PUSERBUTTON pUser = (PUSERBUTTON)pItem;
108 bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;
109
110 if (!pUser)
111 return FALSE;
112
113 wxBitmap* pBitmap;
114 bool bIsSelected = pUser->fsState & BDS_HILITED;
115 wxClientDC vDc(this);
116
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;
123 else
124 pBitmap = &m_bmpNormal;
125
126 if (!pBitmap->Ok() )
127 return FALSE;
128
129
130 //
131 // Centre the bitmap in the control area
132 //
133 int nX = 0;
134 int nX1 = 0;
135 int nY1 = 0;
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();
140
141 nX1 = nX + (nWidth - nBmpWidth) / 2;
142 nY1 = nX + (nHeight - nBmpHeight) / 2;
143
144 if (bIsSelected && bAutoDraw)
145 {
146 nX1++;
147 nY1++;
148 }
149
150 //
151 // Draw the button face
152 //
153 {
154 DrawFace( vDc
155 ,bIsSelected
156 );
157 }
158
159 //
160 // Draw the bitmap
161 //
162 vDc.DrawBitmap( *pBitmap
163 ,nX1
164 ,nY1
165 ,TRUE
166 );
167
168 //
169 // Draw focus / disabled state, if auto-drawing
170 //
171 if ((pUser->fsState == BDS_DISABLED) && bAutoDraw)
172 {
173 DrawButtonDisable( vDc
174 ,*pBitmap
175 );
176 }
177 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
178 {
179 DrawButtonFocus(vDc);
180 }
181 return TRUE;
182 } // end of wxBitmapButton::OS2OnDraw
183
184 void wxBitmapButton::DrawFace (
185 wxClientDC& rDC
186 , bool bSel
187 )
188 {
189 //
190 // Set up drawing colors
191 //
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
195
196 //
197 // Draw the main button face
198 //
199 ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
200
201 //
202 // Draw the border
203 //
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
209 );
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
214 );
215
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
221 );
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
226 );
227
228 } // end of wxBitmapButton::DrawFace
229
230 void wxBitmapButton::DrawButtonFocus (
231 wxClientDC& rDC
232 )
233 {
234 wxPen vBlackPen(wxColour(0, 0, 0), 2, wxSOLID);
235
236 //
237 // Draw a thick black line around the outside of the button
238 //
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
244 );
245 rDC.DrawLine( rDC.m_vRclPaint.xRight
246 ,rDC.m_vRclPaint.yTop
247 ,rDC.m_vRclPaint.xRight
248 ,rDC.m_vRclPaint.yBottom
249 );
250 rDC.DrawLine( rDC.m_vRclPaint.xRight
251 ,rDC.m_vRclPaint.yBottom
252 ,rDC.m_vRclPaint.xLeft
253 ,rDC.m_vRclPaint.yBottom
254 );
255 rDC.DrawLine( rDC.m_vRclPaint.xLeft
256 ,rDC.m_vRclPaint.yBottom
257 ,rDC.m_vRclPaint.xLeft
258 ,rDC.m_vRclPaint.yTop
259 );
260 } // end of wxBitmapButton::DrawButtonFocus
261
262 void wxBitmapButton::DrawButtonDisable(
263 wxClientDC& rDC
264 , wxBitmap& rBmp
265 )
266 {
267 wxPen vGreyPen(wxColour(128, 128, 128), 2, wxSOLID);
268
269 //
270 // Draw a thick black line around the outside of the button
271 //
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
277 );
278 rDC.DrawLine( rDC.m_vRclPaint.xRight
279 ,rDC.m_vRclPaint.yTop
280 ,rDC.m_vRclPaint.xRight
281 ,rDC.m_vRclPaint.yBottom
282 );
283 rDC.DrawLine( rDC.m_vRclPaint.xRight
284 ,rDC.m_vRclPaint.yBottom
285 ,rDC.m_vRclPaint.xLeft
286 ,rDC.m_vRclPaint.yBottom
287 );
288 rDC.DrawLine( rDC.m_vRclPaint.xLeft
289 ,rDC.m_vRclPaint.yBottom
290 ,rDC.m_vRclPaint.xLeft
291 ,rDC.m_vRclPaint.yTop
292 );
293 wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel());
294 } // end of wxBitmapButton::DrawButtonDisable
295
296 void wxBitmapButton::SetDefault()
297 {
298 wxButton::SetDefault();
299 }
300
301 #endif // ndef for wxUSE_BMPBUTTON
302