]> git.saurik.com Git - wxWidgets.git/blame - src/os2/bmpbuttn.cpp
Fixed #1338966.
[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
6670f564
WS
28bool 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 )
0e320a79 36{
db16e5c3
DW
37 m_bmpNormal = rBitmap;
38 SetName(rsName);
5d4b632b 39#if wxUSE_VALIDATORS
db16e5c3 40 SetValidator(rValidator);
5d4b632b 41#endif
37f214d5 42
db16e5c3 43 pParent->AddChild(this);
0e320a79 44
db16e5c3
DW
45 m_backgroundColour = pParent->GetBackgroundColour() ;
46 m_foregroundColour = pParent->GetForegroundColour() ;
47 m_windowStyle = lStyle;
0e320a79 48
db16e5c3 49 if (lStyle & wxBU_AUTODRAW)
37f214d5
DW
50 {
51 m_marginX = wxDEFAULT_BUTTON_MARGIN;
52 m_marginY = wxDEFAULT_BUTTON_MARGIN;
53 }
54
db16e5c3
DW
55 int nX = rPos.x;
56 int nY = rPos.y;
57 int nWidth = rSize.x;
58 int nHeight = rSize.y;
0e320a79 59
db16e5c3 60 if (vId == -1)
0e320a79
DW
61 m_windowId = NewControlId();
62 else
db16e5c3
DW
63 m_windowId = vId;
64
65 if (nWidth == -1 && rBitmap.Ok())
a5799260 66 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
db16e5c3
DW
67
68 if (nHeight == -1 && rBitmap.Ok())
a5799260 69 nHeight = rBitmap.GetHeight() + 4 * m_marginY;
db16e5c3
DW
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
0fba44b4 78 ,(PSZ)wxEmptyString
db16e5c3
DW
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 //
37f214d5 91 SubclassWin(m_hWnd);
db16e5c3
DW
92 SetFont(*wxSMALL_FONT);
93 SetSize( nX
94 ,nY
95 ,nWidth
96 ,nHeight
97 );
6670f564 98 return true;
db16e5c3 99} // end of wxBitmapButton::Create
37f214d5 100
6670f564 101bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem)
0e320a79 102{
db16e5c3
DW
103 PUSERBUTTON pUser = (PUSERBUTTON)pItem;
104 bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;
0e320a79 105
db16e5c3 106 if (!pUser)
37f214d5 107 return FALSE;
37f214d5 108
db16e5c3 109 wxBitmap* pBitmap;
db16e5c3
DW
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;
37f214d5 121
db16e5c3 122 if (!pBitmap->Ok() )
37f214d5
DW
123 return FALSE;
124
37f214d5 125
db16e5c3 126 //
37f214d5 127 // Centre the bitmap in the control area
db16e5c3
DW
128 //
129 int nX = 0;
db16e5c3
DW
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)
37f214d5 141 {
db16e5c3
DW
142 nX1++;
143 nY1++;
37f214d5
DW
144 }
145
db16e5c3
DW
146 //
147 // Draw the button face
148 //
149 {
150 DrawFace( vDc
151 ,bIsSelected
152 );
153 }
37f214d5 154
db16e5c3
DW
155 //
156 // Draw the bitmap
157 //
6670f564 158 vDc.DrawBitmap( *pBitmap, nX1, nY1, true );
db16e5c3
DW
159
160 //
161 // Draw focus / disabled state, if auto-drawing
162 //
163 if ((pUser->fsState == BDS_DISABLED) && bAutoDraw)
37f214d5 164 {
db16e5c3
DW
165 DrawButtonDisable( vDc
166 ,*pBitmap
167 );
37f214d5 168 }
db16e5c3 169 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
37f214d5 170 {
db16e5c3 171 DrawButtonFocus(vDc);
37f214d5 172 }
6670f564 173 return true;
db16e5c3 174} // end of wxBitmapButton::OS2OnDraw
37f214d5 175
6670f564 176void wxBitmapButton::DrawFace (wxClientDC& rDC, bool bSel)
37f214d5 177{
db16e5c3
DW
178 //
179 // Set up drawing colors
180 //
6670f564
WS
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
db16e5c3
DW
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);
db16e5c3 195 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260
DW
196 ,rDC.m_vRclPaint.yTop - 1
197 ,rDC.m_vRclPaint.xRight - 1
198 ,rDC.m_vRclPaint.yTop - 1
db16e5c3
DW
199 );
200 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260 201 ,rDC.m_vRclPaint.yTop - 1
db16e5c3 202 ,rDC.m_vRclPaint.xLeft + 1
a5799260 203 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3
DW
204 );
205
a5799260 206 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
db16e5c3 207 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260 208 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3 209 ,rDC.m_vRclPaint.xRight - 1
a5799260 210 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3
DW
211 );
212 rDC.DrawLine( rDC.m_vRclPaint.xRight - 1
db16e5c3 213 ,rDC.m_vRclPaint.yTop - 1
a5799260
DW
214 ,rDC.m_vRclPaint.xRight - 1
215 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3 216 );
a5799260 217
db16e5c3
DW
218} // end of wxBitmapButton::DrawFace
219
220void wxBitmapButton::DrawButtonFocus (
221 wxClientDC& rDC
222)
37f214d5 223{
6670f564 224 wxPen vBlackPen(*wxBLACK, 2, wxSOLID);
db16e5c3
DW
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
6670f564
WS
252void wxBitmapButton::DrawButtonDisable( wxClientDC& rDC,
253 wxBitmap& rBmp )
db16e5c3 254{
6670f564 255 wxPen vGreyPen(wxT("GREY"), 2, wxSOLID);
db16e5c3
DW
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
37f214d5
DW
283
284void wxBitmapButton::SetDefault()
285{
286 wxButton::SetDefault();
287}
db16e5c3
DW
288
289#endif // ndef for wxUSE_BMPBUTTON