]> git.saurik.com Git - wxWidgets.git/blame - src/os2/bmpbuttn.cpp
[ 1216436 ] cleanup 'shadow variable' warnings from gcc in headers.
[wxWidgets.git] / src / os2 / bmpbuttn.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: bmpbuttn.cpp
3// Purpose: wxBitmapButton
37f214d5 4// Author: David Webster
0e320a79 5// Modified by:
37f214d5 6// Created: 10/13/99
0e320a79 7// RCS-ID: $Id$
37f214d5 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
37f214d5
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
db16e5c3
DW
15#if wxUSE_BMPBUTTON
16
37f214d5 17#ifndef WX_PRECOMP
0e320a79 18#include "wx/bmpbuttn.h"
37f214d5
DW
19#endif
20
21#include "wx/os2/private.h"
22
0e320a79 23
0e320a79 24IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
0e320a79 25
37f214d5
DW
26#define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
27
db16e5c3
DW
28bool wxBitmapButton::Create(
29 wxWindow* pParent
30, wxWindowID vId
31, const wxBitmap& rBitmap
32, const wxPoint& rPos
33, const wxSize& rSize
34, long lStyle
db16e5c3 35, const wxValidator& rValidator
db16e5c3
DW
36, const wxString& rsName
37)
0e320a79 38{
db16e5c3
DW
39 m_bmpNormal = rBitmap;
40 SetName(rsName);
5d4b632b 41#if wxUSE_VALIDATORS
db16e5c3 42 SetValidator(rValidator);
5d4b632b 43#endif
37f214d5 44
db16e5c3 45 pParent->AddChild(this);
0e320a79 46
db16e5c3
DW
47 m_backgroundColour = pParent->GetBackgroundColour() ;
48 m_foregroundColour = pParent->GetForegroundColour() ;
49 m_windowStyle = lStyle;
0e320a79 50
db16e5c3 51 if (lStyle & wxBU_AUTODRAW)
37f214d5
DW
52 {
53 m_marginX = wxDEFAULT_BUTTON_MARGIN;
54 m_marginY = wxDEFAULT_BUTTON_MARGIN;
55 }
56
db16e5c3
DW
57 int nX = rPos.x;
58 int nY = rPos.y;
59 int nWidth = rSize.x;
60 int nHeight = rSize.y;
0e320a79 61
db16e5c3 62 if (vId == -1)
0e320a79
DW
63 m_windowId = NewControlId();
64 else
db16e5c3
DW
65 m_windowId = vId;
66
67 if (nWidth == -1 && rBitmap.Ok())
a5799260 68 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
db16e5c3
DW
69
70 if (nHeight == -1 && rBitmap.Ok())
a5799260 71 nHeight = rBitmap.GetHeight() + 4 * m_marginY;
db16e5c3
DW
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
0fba44b4 80 ,(PSZ)wxEmptyString
db16e5c3
DW
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 //
37f214d5 93 SubclassWin(m_hWnd);
db16e5c3
DW
94 SetFont(*wxSMALL_FONT);
95 SetSize( nX
96 ,nY
97 ,nWidth
98 ,nHeight
99 );
100 return TRUE;
101} // end of wxBitmapButton::Create
37f214d5 102
db16e5c3
DW
103bool wxBitmapButton::OS2OnDraw(
104 WXDRAWITEMSTRUCT* pItem
105)
0e320a79 106{
db16e5c3
DW
107 PUSERBUTTON pUser = (PUSERBUTTON)pItem;
108 bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;
0e320a79 109
db16e5c3 110 if (!pUser)
37f214d5 111 return FALSE;
37f214d5 112
db16e5c3 113 wxBitmap* pBitmap;
db16e5c3
DW
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;
37f214d5 125
db16e5c3 126 if (!pBitmap->Ok() )
37f214d5
DW
127 return FALSE;
128
37f214d5 129
db16e5c3 130 //
37f214d5 131 // Centre the bitmap in the control area
db16e5c3
DW
132 //
133 int nX = 0;
db16e5c3
DW
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)
37f214d5 145 {
db16e5c3
DW
146 nX1++;
147 nY1++;
37f214d5
DW
148 }
149
db16e5c3
DW
150 //
151 // Draw the button face
152 //
153 {
154 DrawFace( vDc
155 ,bIsSelected
156 );
157 }
37f214d5 158
db16e5c3
DW
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)
37f214d5 172 {
db16e5c3
DW
173 DrawButtonDisable( vDc
174 ,*pBitmap
175 );
37f214d5 176 }
db16e5c3 177 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
37f214d5 178 {
db16e5c3 179 DrawButtonFocus(vDc);
37f214d5 180 }
db16e5c3
DW
181 return TRUE;
182} // end of wxBitmapButton::OS2OnDraw
37f214d5 183
db16e5c3
DW
184void wxBitmapButton::DrawFace (
185 wxClientDC& rDC
186, bool bSel
187)
37f214d5 188{
db16e5c3
DW
189 //
190 // Set up drawing colors
191 //
a5799260
DW
192 wxPen vHiLitePen(wxColour(255, 255, 255), 2, wxSOLID); // White
193 wxPen vDarkShadowPen(wxColour(85, 85, 85), 2, wxSOLID);
db16e5c3
DW
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);
db16e5c3 205 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260
DW
206 ,rDC.m_vRclPaint.yTop - 1
207 ,rDC.m_vRclPaint.xRight - 1
208 ,rDC.m_vRclPaint.yTop - 1
db16e5c3
DW
209 );
210 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260 211 ,rDC.m_vRclPaint.yTop - 1
db16e5c3 212 ,rDC.m_vRclPaint.xLeft + 1
a5799260 213 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3
DW
214 );
215
a5799260 216 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
db16e5c3 217 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260 218 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3 219 ,rDC.m_vRclPaint.xRight - 1
a5799260 220 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3
DW
221 );
222 rDC.DrawLine( rDC.m_vRclPaint.xRight - 1
db16e5c3 223 ,rDC.m_vRclPaint.yTop - 1
a5799260
DW
224 ,rDC.m_vRclPaint.xRight - 1
225 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3 226 );
a5799260 227
db16e5c3
DW
228} // end of wxBitmapButton::DrawFace
229
230void wxBitmapButton::DrawButtonFocus (
231 wxClientDC& rDC
232)
37f214d5 233{
db16e5c3
DW
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
262void 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
37f214d5
DW
295
296void wxBitmapButton::SetDefault()
297{
298 wxButton::SetDefault();
299}
db16e5c3
DW
300
301#endif // ndef for wxUSE_BMPBUTTON
302