]> git.saurik.com Git - wxWidgets.git/blob - src/os2/bmpbuttn.cpp
Doc fix
[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( wxWindow* pParent,
29 wxWindowID vId,
30 const wxBitmap& rBitmap,
31 const wxPoint& rPos,
32 const wxSize& rSize,
33 long lStyle,
34 const wxValidator& rValidator,
35 const wxString& rsName )
36 {
37 m_bmpNormal = rBitmap;
38 SetName(rsName);
39 #if wxUSE_VALIDATORS
40 SetValidator(rValidator);
41 #endif
42
43 pParent->AddChild(this);
44
45 m_backgroundColour = pParent->GetBackgroundColour() ;
46 m_foregroundColour = pParent->GetForegroundColour() ;
47 m_windowStyle = lStyle;
48
49 if (lStyle & wxBU_AUTODRAW)
50 {
51 m_marginX = wxDEFAULT_BUTTON_MARGIN;
52 m_marginY = wxDEFAULT_BUTTON_MARGIN;
53 }
54
55 int nX = rPos.x;
56 int nY = rPos.y;
57 int nWidth = rSize.x;
58 int nHeight = rSize.y;
59
60 if (vId == -1)
61 m_windowId = NewControlId();
62 else
63 m_windowId = vId;
64
65 if (nWidth == -1 && rBitmap.Ok())
66 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
67
68 if (nHeight == -1 && rBitmap.Ok())
69 nHeight = rBitmap.GetHeight() + 4 * m_marginY;
70
71 ULONG ulOS2Style = WS_VISIBLE | WS_TABSTOP | BS_USERBUTTON;
72
73 if (m_windowStyle & wxCLIP_SIBLINGS)
74 ulOS2Style |= WS_CLIPSIBLINGS;
75
76 m_hWnd = (WXHWND)::WinCreateWindow( GetHwndOf(pParent)
77 ,WC_BUTTON
78 ,(PSZ)wxEmptyString
79 ,ulOS2Style
80 ,0, 0, 0, 0
81 ,GetHwndOf(pParent)
82 ,HWND_TOP
83 ,m_windowId
84 ,NULL
85 ,NULL
86 );
87
88 //
89 //Subclass again for purposes of dialog editing mode
90 //
91 SubclassWin(m_hWnd);
92 SetFont(*wxSMALL_FONT);
93 SetSize( nX
94 ,nY
95 ,nWidth
96 ,nHeight
97 );
98 return true;
99 } // end of wxBitmapButton::Create
100
101 bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem)
102 {
103 PUSERBUTTON pUser = (PUSERBUTTON)pItem;
104 bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;
105
106 if (!pUser)
107 return FALSE;
108
109 wxBitmap* pBitmap;
110 bool bIsSelected = pUser->fsState & BDS_HILITED;
111 wxClientDC vDc(this);
112
113 if (bIsSelected && m_bmpSelected.Ok())
114 pBitmap = &m_bmpSelected;
115 else if ((pUser->fsState & BDS_DEFAULT) && m_bmpFocus.Ok())
116 pBitmap = &m_bmpFocus;
117 else if ((pUser->fsState & BDS_DISABLED) && m_bmpDisabled.Ok())
118 pBitmap = &m_bmpDisabled;
119 else
120 pBitmap = &m_bmpNormal;
121
122 if (!pBitmap->Ok() )
123 return FALSE;
124
125
126 //
127 // Centre the bitmap in the control area
128 //
129 int nX = 0;
130 int nX1 = 0;
131 int nY1 = 0;
132 int nWidth = vDc.m_vRclPaint.xRight - vDc.m_vRclPaint.xLeft;
133 int nHeight = vDc.m_vRclPaint.xRight - vDc.m_vRclPaint.xLeft;
134 int nBmpWidth = pBitmap->GetWidth();
135 int nBmpHeight = pBitmap->GetHeight();
136
137 nX1 = nX + (nWidth - nBmpWidth) / 2;
138 nY1 = nX + (nHeight - nBmpHeight) / 2;
139
140 if (bIsSelected && bAutoDraw)
141 {
142 nX1++;
143 nY1++;
144 }
145
146 //
147 // Draw the button face
148 //
149 {
150 DrawFace( vDc
151 ,bIsSelected
152 );
153 }
154
155 //
156 // Draw the bitmap
157 //
158 vDc.DrawBitmap( *pBitmap, 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
166 ,*pBitmap
167 );
168 }
169 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
170 {
171 DrawButtonFocus(vDc);
172 }
173 return true;
174 } // end of wxBitmapButton::OS2OnDraw
175
176 void wxBitmapButton::DrawFace (wxClientDC& rDC, bool bSel)
177 {
178 //
179 // Set up drawing colors
180 //
181 wxPen vHiLitePen(*wxWHITE, 2, wxSOLID); // White
182 wxColour gray85(85, 85, 85);
183 wxPen vDarkShadowPen(gray85, 2, wxSOLID);
184 wxColour vFaceColor(204, 204, 204); // Light Grey
185
186 //
187 // Draw the main button face
188 //
189 ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
190
191 //
192 // Draw the border
193 //
194 rDC.SetPen(bSel ? vDarkShadowPen : vHiLitePen);
195 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
196 ,rDC.m_vRclPaint.yTop - 1
197 ,rDC.m_vRclPaint.xRight - 1
198 ,rDC.m_vRclPaint.yTop - 1
199 );
200 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
201 ,rDC.m_vRclPaint.yTop - 1
202 ,rDC.m_vRclPaint.xLeft + 1
203 ,rDC.m_vRclPaint.yBottom + 1
204 );
205
206 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
207 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
208 ,rDC.m_vRclPaint.yBottom + 1
209 ,rDC.m_vRclPaint.xRight - 1
210 ,rDC.m_vRclPaint.yBottom + 1
211 );
212 rDC.DrawLine( rDC.m_vRclPaint.xRight - 1
213 ,rDC.m_vRclPaint.yTop - 1
214 ,rDC.m_vRclPaint.xRight - 1
215 ,rDC.m_vRclPaint.yBottom + 1
216 );
217
218 } // end of wxBitmapButton::DrawFace
219
220 void wxBitmapButton::DrawButtonFocus (
221 wxClientDC& rDC
222 )
223 {
224 wxPen vBlackPen(*wxBLACK, 2, wxSOLID);
225
226 //
227 // Draw a thick black line around the outside of the button
228 //
229 rDC.SetPen(vBlackPen);
230 rDC.DrawLine( rDC.m_vRclPaint.xLeft
231 ,rDC.m_vRclPaint.yTop
232 ,rDC.m_vRclPaint.xRight
233 ,rDC.m_vRclPaint.yTop
234 );
235 rDC.DrawLine( rDC.m_vRclPaint.xRight
236 ,rDC.m_vRclPaint.yTop
237 ,rDC.m_vRclPaint.xRight
238 ,rDC.m_vRclPaint.yBottom
239 );
240 rDC.DrawLine( rDC.m_vRclPaint.xRight
241 ,rDC.m_vRclPaint.yBottom
242 ,rDC.m_vRclPaint.xLeft
243 ,rDC.m_vRclPaint.yBottom
244 );
245 rDC.DrawLine( rDC.m_vRclPaint.xLeft
246 ,rDC.m_vRclPaint.yBottom
247 ,rDC.m_vRclPaint.xLeft
248 ,rDC.m_vRclPaint.yTop
249 );
250 } // end of wxBitmapButton::DrawButtonFocus
251
252 void wxBitmapButton::DrawButtonDisable( wxClientDC& rDC,
253 wxBitmap& rBmp )
254 {
255 wxPen vGreyPen(wxT("GREY"), 2, wxSOLID);
256
257 //
258 // Draw a thick black line around the outside of the button
259 //
260 rDC.SetPen(vGreyPen);
261 rDC.DrawLine( rDC.m_vRclPaint.xLeft
262 ,rDC.m_vRclPaint.yTop
263 ,rDC.m_vRclPaint.xRight
264 ,rDC.m_vRclPaint.yTop
265 );
266 rDC.DrawLine( rDC.m_vRclPaint.xRight
267 ,rDC.m_vRclPaint.yTop
268 ,rDC.m_vRclPaint.xRight
269 ,rDC.m_vRclPaint.yBottom
270 );
271 rDC.DrawLine( rDC.m_vRclPaint.xRight
272 ,rDC.m_vRclPaint.yBottom
273 ,rDC.m_vRclPaint.xLeft
274 ,rDC.m_vRclPaint.yBottom
275 );
276 rDC.DrawLine( rDC.m_vRclPaint.xLeft
277 ,rDC.m_vRclPaint.yBottom
278 ,rDC.m_vRclPaint.xLeft
279 ,rDC.m_vRclPaint.yTop
280 );
281 wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel());
282 } // end of wxBitmapButton::DrawButtonDisable
283
284 void wxBitmapButton::SetDefault()
285 {
286 wxButton::SetDefault();
287 }
288
289 #endif // ndef for wxUSE_BMPBUTTON