]> git.saurik.com Git - wxWidgets.git/blame - src/os2/bmpbuttn.cpp
Use the size value passed to the ctor to set the window's minimum size.
[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
DW
8// Copyright: (c) David Webster
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
80 ,wxT("")
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
DW
113 wxBitmap* pBitmap;
114 RECTL vRect;
115 bool bIsSelected = pUser->fsState & BDS_HILITED;
116 wxClientDC vDc(this);
117
118 if (bIsSelected && m_bmpSelected.Ok())
119 pBitmap = &m_bmpSelected;
120 else if ((pUser->fsState & BDS_DEFAULT) && m_bmpFocus.Ok())
121 pBitmap = &m_bmpFocus;
122 else if ((pUser->fsState & BDS_DISABLED) && m_bmpDisabled.Ok())
123 pBitmap = &m_bmpDisabled;
124 else
125 pBitmap = &m_bmpNormal;
37f214d5 126
db16e5c3 127 if (!pBitmap->Ok() )
37f214d5
DW
128 return FALSE;
129
37f214d5 130
db16e5c3 131 //
37f214d5 132 // Centre the bitmap in the control area
db16e5c3
DW
133 //
134 int nX = 0;
135 int nY = 0;
136 int nX1 = 0;
137 int nY1 = 0;
138 int nWidth = vDc.m_vRclPaint.xRight - vDc.m_vRclPaint.xLeft;
139 int nHeight = vDc.m_vRclPaint.xRight - vDc.m_vRclPaint.xLeft;
140 int nBmpWidth = pBitmap->GetWidth();
141 int nBmpHeight = pBitmap->GetHeight();
142
143 nX1 = nX + (nWidth - nBmpWidth) / 2;
144 nY1 = nX + (nHeight - nBmpHeight) / 2;
145
146 if (bIsSelected && bAutoDraw)
37f214d5 147 {
db16e5c3
DW
148 nX1++;
149 nY1++;
37f214d5
DW
150 }
151
db16e5c3
DW
152 //
153 // Draw the button face
154 //
155 {
156 DrawFace( vDc
157 ,bIsSelected
158 );
159 }
37f214d5 160
db16e5c3
DW
161 //
162 // Draw the bitmap
163 //
164 vDc.DrawBitmap( *pBitmap
165 ,nX1
166 ,nY1
167 ,TRUE
168 );
169
170 //
171 // Draw focus / disabled state, if auto-drawing
172 //
173 if ((pUser->fsState == BDS_DISABLED) && bAutoDraw)
37f214d5 174 {
db16e5c3
DW
175 DrawButtonDisable( vDc
176 ,*pBitmap
177 );
37f214d5 178 }
db16e5c3 179 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
37f214d5 180 {
db16e5c3 181 DrawButtonFocus(vDc);
37f214d5 182 }
db16e5c3
DW
183 return TRUE;
184} // end of wxBitmapButton::OS2OnDraw
37f214d5 185
db16e5c3
DW
186void wxBitmapButton::DrawFace (
187 wxClientDC& rDC
188, bool bSel
189)
37f214d5 190{
db16e5c3
DW
191 //
192 // Set up drawing colors
193 //
a5799260
DW
194 wxPen vHiLitePen(wxColour(255, 255, 255), 2, wxSOLID); // White
195 wxPen vDarkShadowPen(wxColour(85, 85, 85), 2, wxSOLID);
db16e5c3
DW
196 wxColour vFaceColor(wxColour(204, 204, 204)); // Light Grey
197
198 //
199 // Draw the main button face
200 //
201 ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
202
203 //
204 // Draw the border
205 //
206 rDC.SetPen(bSel ? vDarkShadowPen : vHiLitePen);
db16e5c3 207 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260
DW
208 ,rDC.m_vRclPaint.yTop - 1
209 ,rDC.m_vRclPaint.xRight - 1
210 ,rDC.m_vRclPaint.yTop - 1
db16e5c3
DW
211 );
212 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260 213 ,rDC.m_vRclPaint.yTop - 1
db16e5c3 214 ,rDC.m_vRclPaint.xLeft + 1
a5799260 215 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3
DW
216 );
217
a5799260 218 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
db16e5c3 219 rDC.DrawLine( rDC.m_vRclPaint.xLeft + 1
a5799260 220 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3 221 ,rDC.m_vRclPaint.xRight - 1
a5799260 222 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3
DW
223 );
224 rDC.DrawLine( rDC.m_vRclPaint.xRight - 1
db16e5c3 225 ,rDC.m_vRclPaint.yTop - 1
a5799260
DW
226 ,rDC.m_vRclPaint.xRight - 1
227 ,rDC.m_vRclPaint.yBottom + 1
db16e5c3 228 );
a5799260 229
db16e5c3
DW
230} // end of wxBitmapButton::DrawFace
231
232void wxBitmapButton::DrawButtonFocus (
233 wxClientDC& rDC
234)
37f214d5 235{
db16e5c3
DW
236 wxPen vBlackPen(wxColour(0, 0, 0), 2, wxSOLID);
237
238 //
239 // Draw a thick black line around the outside of the button
240 //
241 rDC.SetPen(vBlackPen);
242 rDC.DrawLine( rDC.m_vRclPaint.xLeft
243 ,rDC.m_vRclPaint.yTop
244 ,rDC.m_vRclPaint.xRight
245 ,rDC.m_vRclPaint.yTop
246 );
247 rDC.DrawLine( rDC.m_vRclPaint.xRight
248 ,rDC.m_vRclPaint.yTop
249 ,rDC.m_vRclPaint.xRight
250 ,rDC.m_vRclPaint.yBottom
251 );
252 rDC.DrawLine( rDC.m_vRclPaint.xRight
253 ,rDC.m_vRclPaint.yBottom
254 ,rDC.m_vRclPaint.xLeft
255 ,rDC.m_vRclPaint.yBottom
256 );
257 rDC.DrawLine( rDC.m_vRclPaint.xLeft
258 ,rDC.m_vRclPaint.yBottom
259 ,rDC.m_vRclPaint.xLeft
260 ,rDC.m_vRclPaint.yTop
261 );
262} // end of wxBitmapButton::DrawButtonFocus
263
264void wxBitmapButton::DrawButtonDisable(
265 wxClientDC& rDC
266, wxBitmap& rBmp
267)
268{
269 wxPen vGreyPen(wxColour(128, 128, 128), 2, wxSOLID);
270
271 //
272 // Draw a thick black line around the outside of the button
273 //
274 rDC.SetPen(vGreyPen);
275 rDC.DrawLine( rDC.m_vRclPaint.xLeft
276 ,rDC.m_vRclPaint.yTop
277 ,rDC.m_vRclPaint.xRight
278 ,rDC.m_vRclPaint.yTop
279 );
280 rDC.DrawLine( rDC.m_vRclPaint.xRight
281 ,rDC.m_vRclPaint.yTop
282 ,rDC.m_vRclPaint.xRight
283 ,rDC.m_vRclPaint.yBottom
284 );
285 rDC.DrawLine( rDC.m_vRclPaint.xRight
286 ,rDC.m_vRclPaint.yBottom
287 ,rDC.m_vRclPaint.xLeft
288 ,rDC.m_vRclPaint.yBottom
289 );
290 rDC.DrawLine( rDC.m_vRclPaint.xLeft
291 ,rDC.m_vRclPaint.yBottom
292 ,rDC.m_vRclPaint.xLeft
293 ,rDC.m_vRclPaint.yTop
294 );
295 wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel());
296} // end of wxBitmapButton::DrawButtonDisable
37f214d5
DW
297
298void wxBitmapButton::SetDefault()
299{
300 wxButton::SetDefault();
301}
db16e5c3
DW
302
303#endif // ndef for wxUSE_BMPBUTTON
304