]> git.saurik.com Git - wxWidgets.git/blame - src/os2/bmpbuttn.cpp
removed now-unused wxSizer::GetMax/MinWindowSize helpers
[wxWidgets.git] / src / os2 / bmpbuttn.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
910b0053 2// Name: src/os2/bmpbuttn.cpp
0e320a79 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
0e320a79 17#include "wx/bmpbuttn.h"
910b0053
WS
18
19#ifndef WX_PRECOMP
37f214d5
DW
20#endif
21
38400bb4 22#include "wx/os2/dcclient.h"
37f214d5
DW
23#include "wx/os2/private.h"
24
0e320a79 25
0e320a79 26IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
0e320a79 27
37f214d5
DW
28#define BUTTON_HEIGHT_FACTOR (EDIT_CONTROL_FACTOR * 1.1)
29
6670f564
WS
30bool wxBitmapButton::Create( wxWindow* pParent,
31 wxWindowID vId,
32 const wxBitmap& rBitmap,
33 const wxPoint& rPos,
34 const wxSize& rSize,
35 long lStyle,
36 const wxValidator& rValidator,
37 const wxString& rsName )
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
910b0053
WS
57 int nX = rPos.x;
58 int nY = rPos.y;
59 int nWidth = rSize.x;
60 int nHeight = rSize.y;
0e320a79 61
910b0053 62 if (vId == wxID_ANY)
0e320a79
DW
63 m_windowId = NewControlId();
64 else
db16e5c3
DW
65 m_windowId = vId;
66
910b0053 67 if (nWidth == wxDefaultCoord && rBitmap.Ok())
a5799260 68 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
db16e5c3 69
910b0053 70 if (nHeight == wxDefaultCoord && 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 );
6670f564 100 return true;
db16e5c3 101} // end of wxBitmapButton::Create
37f214d5 102
6670f564 103bool wxBitmapButton::OS2OnDraw( WXDRAWITEMSTRUCT* pItem)
0e320a79 104{
910b0053
WS
105 PUSERBUTTON pUser = (PUSERBUTTON)pItem;
106 bool bAutoDraw = (GetWindowStyleFlag() & wxBU_AUTODRAW) != 0;
0e320a79 107
db16e5c3 108 if (!pUser)
910b0053 109 return false;
37f214d5 110
910b0053
WS
111 wxBitmap* pBitmap;
112 bool bIsSelected = pUser->fsState & BDS_HILITED;
113 wxClientDC vDc(this);
db16e5c3
DW
114
115 if (bIsSelected && m_bmpSelected.Ok())
116 pBitmap = &m_bmpSelected;
117 else if ((pUser->fsState & BDS_DEFAULT) && m_bmpFocus.Ok())
118 pBitmap = &m_bmpFocus;
119 else if ((pUser->fsState & BDS_DISABLED) && m_bmpDisabled.Ok())
120 pBitmap = &m_bmpDisabled;
121 else
122 pBitmap = &m_bmpNormal;
37f214d5 123
db16e5c3 124 if (!pBitmap->Ok() )
910b0053 125 return false;
37f214d5 126
37f214d5 127
db16e5c3 128 //
37f214d5 129 // Centre the bitmap in the control area
db16e5c3 130 //
db16e5c3
DW
131 int nX1 = 0;
132 int nY1 = 0;
38400bb4
SN
133 wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl();
134 int nWidth = impl->m_vRclPaint.xRight - impl->m_vRclPaint.xLeft;
135 int nHeight = impl->m_vRclPaint.yTop - impl->m_vRclPaint.yBottom;
db16e5c3
DW
136 int nBmpWidth = pBitmap->GetWidth();
137 int nBmpHeight = pBitmap->GetHeight();
138
2ef6ae9d
SN
139 nX1 = (nWidth - nBmpWidth) / 2;
140 nY1 = (nHeight - nBmpHeight) / 2;
db16e5c3
DW
141
142 if (bIsSelected && bAutoDraw)
37f214d5 143 {
db16e5c3
DW
144 nX1++;
145 nY1++;
37f214d5
DW
146 }
147
db16e5c3
DW
148 //
149 // Draw the button face
150 //
2ef6ae9d 151 DrawFace( vDc, bIsSelected );
37f214d5 152
db16e5c3
DW
153 //
154 // Draw the bitmap
155 //
6670f564 156 vDc.DrawBitmap( *pBitmap, nX1, nY1, true );
db16e5c3
DW
157
158 //
159 // Draw focus / disabled state, if auto-drawing
160 //
161 if ((pUser->fsState == BDS_DISABLED) && bAutoDraw)
37f214d5 162 {
2ef6ae9d 163 DrawButtonDisable( vDc, *pBitmap );
37f214d5 164 }
db16e5c3 165 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
37f214d5 166 {
db16e5c3 167 DrawButtonFocus(vDc);
37f214d5 168 }
6670f564 169 return true;
db16e5c3 170} // end of wxBitmapButton::OS2OnDraw
37f214d5 171
6670f564 172void wxBitmapButton::DrawFace (wxClientDC& rDC, bool bSel)
37f214d5 173{
db16e5c3
DW
174 //
175 // Set up drawing colors
176 //
6670f564
WS
177 wxPen vHiLitePen(*wxWHITE, 2, wxSOLID); // White
178 wxColour gray85(85, 85, 85);
179 wxPen vDarkShadowPen(gray85, 2, wxSOLID);
180 wxColour vFaceColor(204, 204, 204); // Light Grey
db16e5c3
DW
181
182 //
183 // Draw the main button face
184 //
2ef6ae9d
SN
185 // This triggers a redraw and destroys the bottom & left focus border and
186 // doesn't seem to do anything useful.
187 // ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
db16e5c3
DW
188
189 //
190 // Draw the border
2ef6ae9d 191 // Note: DrawLine expects wxWidgets coordinate system so swap
db16e5c3
DW
192 //
193 rDC.SetPen(bSel ? vDarkShadowPen : vHiLitePen);
38400bb4 194 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
2ef6ae9d 195 // top
38400bb4
SN
196 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
197 ,impl->m_vRclPaint.yBottom + 1
198 ,impl->m_vRclPaint.xRight - 1
199 ,impl->m_vRclPaint.yBottom + 1
db16e5c3 200 );
2ef6ae9d 201 // left
38400bb4
SN
202 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
203 ,impl->m_vRclPaint.yBottom + 1
204 ,impl->m_vRclPaint.xLeft + 1
205 ,impl->m_vRclPaint.yTop - 1
db16e5c3
DW
206 );
207
a5799260 208 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
2ef6ae9d 209 // bottom
38400bb4
SN
210 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
211 ,impl->m_vRclPaint.yTop - 1
212 ,impl->m_vRclPaint.xRight - 1
213 ,impl->m_vRclPaint.yTop - 1
db16e5c3 214 );
2ef6ae9d 215 // right
38400bb4
SN
216 rDC.DrawLine( impl->m_vRclPaint.xRight - 1
217 ,impl->m_vRclPaint.yBottom + 1
218 ,impl->m_vRclPaint.xRight - 1
219 ,impl->m_vRclPaint.yTop - 1
db16e5c3 220 );
a5799260 221
db16e5c3
DW
222} // end of wxBitmapButton::DrawFace
223
224void wxBitmapButton::DrawButtonFocus (
225 wxClientDC& rDC
226)
37f214d5 227{
6670f564 228 wxPen vBlackPen(*wxBLACK, 2, wxSOLID);
db16e5c3
DW
229
230 //
231 // Draw a thick black line around the outside of the button
2ef6ae9d 232 // Note: DrawLine expects wxWidgets coordinate system so swap
db16e5c3
DW
233 //
234 rDC.SetPen(vBlackPen);
38400bb4 235 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
2ef6ae9d 236 // top
38400bb4
SN
237 rDC.DrawLine( impl->m_vRclPaint.xLeft
238 ,impl->m_vRclPaint.yBottom
239 ,impl->m_vRclPaint.xRight
240 ,impl->m_vRclPaint.yBottom
db16e5c3 241 );
2ef6ae9d 242 // right
38400bb4
SN
243 rDC.DrawLine( impl->m_vRclPaint.xRight
244 ,impl->m_vRclPaint.yBottom
245 ,impl->m_vRclPaint.xRight
246 ,impl->m_vRclPaint.yTop
db16e5c3 247 );
2ef6ae9d 248 // bottom
38400bb4
SN
249 rDC.DrawLine( impl->m_vRclPaint.xRight
250 ,impl->m_vRclPaint.yTop
251 ,impl->m_vRclPaint.xLeft
252 ,impl->m_vRclPaint.yTop
db16e5c3 253 );
2ef6ae9d 254 // left
38400bb4
SN
255 rDC.DrawLine( impl->m_vRclPaint.xLeft
256 ,impl->m_vRclPaint.yTop
257 ,impl->m_vRclPaint.xLeft
258 ,impl->m_vRclPaint.yBottom
db16e5c3
DW
259 );
260} // end of wxBitmapButton::DrawButtonFocus
261
6670f564
WS
262void wxBitmapButton::DrawButtonDisable( wxClientDC& rDC,
263 wxBitmap& rBmp )
db16e5c3 264{
6670f564 265 wxPen vGreyPen(wxT("GREY"), 2, wxSOLID);
db16e5c3
DW
266
267 //
268 // Draw a thick black line around the outside of the button
2ef6ae9d 269 // Note: DrawLine expects wxWidgets coordinate system so swap
db16e5c3
DW
270 //
271 rDC.SetPen(vGreyPen);
38400bb4 272 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
2ef6ae9d 273 // top
38400bb4
SN
274 rDC.DrawLine( impl->m_vRclPaint.xLeft
275 ,impl->m_vRclPaint.yBottom
276 ,impl->m_vRclPaint.xRight
277 ,impl->m_vRclPaint.yBottom
db16e5c3 278 );
2ef6ae9d 279 // right
38400bb4
SN
280 rDC.DrawLine( impl->m_vRclPaint.xRight
281 ,impl->m_vRclPaint.yBottom
282 ,impl->m_vRclPaint.xRight
283 ,impl->m_vRclPaint.yTop
db16e5c3 284 );
2ef6ae9d 285 // bottom
38400bb4
SN
286 rDC.DrawLine( impl->m_vRclPaint.xRight
287 ,impl->m_vRclPaint.yTop
288 ,impl->m_vRclPaint.xLeft
289 ,impl->m_vRclPaint.yTop
db16e5c3 290 );
2ef6ae9d 291 // left
38400bb4
SN
292 rDC.DrawLine( impl->m_vRclPaint.xLeft
293 ,impl->m_vRclPaint.yTop
294 ,impl->m_vRclPaint.xLeft
295 ,impl->m_vRclPaint.yBottom
db16e5c3
DW
296 );
297 wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel());
298} // end of wxBitmapButton::DrawButtonDisable
37f214d5 299
db16e5c3 300#endif // ndef for wxUSE_BMPBUTTON