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