]> git.saurik.com Git - wxWidgets.git/blame - src/os2/bmpbuttn.cpp
fixing and completing iPhone sound
[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{
2352862a 39 m_bitmaps[State_Normal] = rBitmap;
db16e5c3 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
2352862a 67 if (nWidth == wxDefaultCoord && rBitmap.IsOk())
a5799260 68 nWidth = rBitmap.GetWidth() + 4 * m_marginX;
db16e5c3 69
2352862a 70 if (nHeight == wxDefaultCoord && rBitmap.IsOk())
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
2352862a 111 wxBitmap bitmap;
910b0053
WS
112 bool bIsSelected = pUser->fsState & BDS_HILITED;
113 wxClientDC vDc(this);
db16e5c3 114
2352862a
VZ
115 if (bIsSelected)
116 bitmap = GetBitmapPressed();
117 else if (pUser->fsState & BDS_DEFAULT)
118 bitmap = GetBitmapFocus();
119 else if (pUser->fsState & BDS_DISABLED)
120 bitmap = GetBitmapDisabled();
37f214d5 121
2352862a
VZ
122 if (!bitmap.IsOk() )
123 {
124 bitmap = GetBitmapLabel();
125 if (!bitmap.IsOk() )
126 return false;
127 }
37f214d5 128
37f214d5 129
db16e5c3 130 //
37f214d5 131 // Centre the bitmap in the control area
db16e5c3 132 //
db16e5c3
DW
133 int nX1 = 0;
134 int nY1 = 0;
38400bb4
SN
135 wxPMDCImpl *impl = (wxPMDCImpl*) vDc.GetImpl();
136 int nWidth = impl->m_vRclPaint.xRight - impl->m_vRclPaint.xLeft;
137 int nHeight = impl->m_vRclPaint.yTop - impl->m_vRclPaint.yBottom;
2352862a
VZ
138 int nBmpWidth = bitmap.GetWidth();
139 int nBmpHeight = bitmap.GetHeight();
db16e5c3 140
2ef6ae9d
SN
141 nX1 = (nWidth - nBmpWidth) / 2;
142 nY1 = (nHeight - nBmpHeight) / 2;
db16e5c3
DW
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 //
2ef6ae9d 153 DrawFace( vDc, bIsSelected );
37f214d5 154
db16e5c3
DW
155 //
156 // Draw the bitmap
157 //
2352862a 158 vDc.DrawBitmap( bitmap, 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 {
2352862a 165 DrawButtonDisable( vDc, bitmap );
37f214d5 166 }
db16e5c3 167 else if ((pUser->fsState == BDS_DEFAULT) && bAutoDraw)
37f214d5 168 {
db16e5c3 169 DrawButtonFocus(vDc);
37f214d5 170 }
6670f564 171 return true;
db16e5c3 172} // end of wxBitmapButton::OS2OnDraw
37f214d5 173
6670f564 174void wxBitmapButton::DrawFace (wxClientDC& rDC, bool bSel)
37f214d5 175{
db16e5c3
DW
176 //
177 // Set up drawing colors
178 //
6670f564
WS
179 wxPen vHiLitePen(*wxWHITE, 2, wxSOLID); // White
180 wxColour gray85(85, 85, 85);
181 wxPen vDarkShadowPen(gray85, 2, wxSOLID);
182 wxColour vFaceColor(204, 204, 204); // Light Grey
db16e5c3
DW
183
184 //
185 // Draw the main button face
186 //
2ef6ae9d
SN
187 // This triggers a redraw and destroys the bottom & left focus border and
188 // doesn't seem to do anything useful.
189 // ::WinFillRect(rDC.GetHPS(), &rDC.m_vRclPaint, vFaceColor.GetPixel());
db16e5c3
DW
190
191 //
192 // Draw the border
2ef6ae9d 193 // Note: DrawLine expects wxWidgets coordinate system so swap
db16e5c3
DW
194 //
195 rDC.SetPen(bSel ? vDarkShadowPen : vHiLitePen);
38400bb4 196 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
2ef6ae9d 197 // top
38400bb4
SN
198 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
199 ,impl->m_vRclPaint.yBottom + 1
200 ,impl->m_vRclPaint.xRight - 1
201 ,impl->m_vRclPaint.yBottom + 1
db16e5c3 202 );
2ef6ae9d 203 // left
38400bb4
SN
204 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
205 ,impl->m_vRclPaint.yBottom + 1
206 ,impl->m_vRclPaint.xLeft + 1
207 ,impl->m_vRclPaint.yTop - 1
db16e5c3
DW
208 );
209
a5799260 210 rDC.SetPen(bSel ? vHiLitePen : vDarkShadowPen);
2ef6ae9d 211 // bottom
38400bb4
SN
212 rDC.DrawLine( impl->m_vRclPaint.xLeft + 1
213 ,impl->m_vRclPaint.yTop - 1
214 ,impl->m_vRclPaint.xRight - 1
215 ,impl->m_vRclPaint.yTop - 1
db16e5c3 216 );
2ef6ae9d 217 // right
38400bb4
SN
218 rDC.DrawLine( impl->m_vRclPaint.xRight - 1
219 ,impl->m_vRclPaint.yBottom + 1
220 ,impl->m_vRclPaint.xRight - 1
221 ,impl->m_vRclPaint.yTop - 1
db16e5c3 222 );
a5799260 223
db16e5c3
DW
224} // end of wxBitmapButton::DrawFace
225
226void wxBitmapButton::DrawButtonFocus (
227 wxClientDC& rDC
228)
37f214d5 229{
6670f564 230 wxPen vBlackPen(*wxBLACK, 2, wxSOLID);
db16e5c3
DW
231
232 //
233 // Draw a thick black line around the outside of the button
2ef6ae9d 234 // Note: DrawLine expects wxWidgets coordinate system so swap
db16e5c3
DW
235 //
236 rDC.SetPen(vBlackPen);
38400bb4 237 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
2ef6ae9d 238 // top
38400bb4
SN
239 rDC.DrawLine( impl->m_vRclPaint.xLeft
240 ,impl->m_vRclPaint.yBottom
241 ,impl->m_vRclPaint.xRight
242 ,impl->m_vRclPaint.yBottom
db16e5c3 243 );
2ef6ae9d 244 // right
38400bb4
SN
245 rDC.DrawLine( impl->m_vRclPaint.xRight
246 ,impl->m_vRclPaint.yBottom
247 ,impl->m_vRclPaint.xRight
248 ,impl->m_vRclPaint.yTop
db16e5c3 249 );
2ef6ae9d 250 // bottom
38400bb4
SN
251 rDC.DrawLine( impl->m_vRclPaint.xRight
252 ,impl->m_vRclPaint.yTop
253 ,impl->m_vRclPaint.xLeft
254 ,impl->m_vRclPaint.yTop
db16e5c3 255 );
2ef6ae9d 256 // left
38400bb4
SN
257 rDC.DrawLine( impl->m_vRclPaint.xLeft
258 ,impl->m_vRclPaint.yTop
259 ,impl->m_vRclPaint.xLeft
260 ,impl->m_vRclPaint.yBottom
db16e5c3
DW
261 );
262} // end of wxBitmapButton::DrawButtonFocus
263
6670f564
WS
264void wxBitmapButton::DrawButtonDisable( wxClientDC& rDC,
265 wxBitmap& rBmp )
db16e5c3 266{
6670f564 267 wxPen vGreyPen(wxT("GREY"), 2, wxSOLID);
db16e5c3
DW
268
269 //
270 // Draw a thick black line around the outside of the button
2ef6ae9d 271 // Note: DrawLine expects wxWidgets coordinate system so swap
db16e5c3
DW
272 //
273 rDC.SetPen(vGreyPen);
38400bb4 274 wxPMDCImpl *impl = (wxPMDCImpl*) rDC.GetImpl();
2ef6ae9d 275 // top
38400bb4
SN
276 rDC.DrawLine( impl->m_vRclPaint.xLeft
277 ,impl->m_vRclPaint.yBottom
278 ,impl->m_vRclPaint.xRight
279 ,impl->m_vRclPaint.yBottom
db16e5c3 280 );
2ef6ae9d 281 // right
38400bb4
SN
282 rDC.DrawLine( impl->m_vRclPaint.xRight
283 ,impl->m_vRclPaint.yBottom
284 ,impl->m_vRclPaint.xRight
285 ,impl->m_vRclPaint.yTop
db16e5c3 286 );
2ef6ae9d 287 // bottom
38400bb4
SN
288 rDC.DrawLine( impl->m_vRclPaint.xRight
289 ,impl->m_vRclPaint.yTop
290 ,impl->m_vRclPaint.xLeft
291 ,impl->m_vRclPaint.yTop
db16e5c3 292 );
2ef6ae9d 293 // left
38400bb4
SN
294 rDC.DrawLine( impl->m_vRclPaint.xLeft
295 ,impl->m_vRclPaint.yTop
296 ,impl->m_vRclPaint.xLeft
297 ,impl->m_vRclPaint.yBottom
db16e5c3
DW
298 );
299 wxDisableBitmap(rBmp, vGreyPen.GetColour().GetPixel());
300} // end of wxBitmapButton::DrawButtonDisable
37f214d5 301
db16e5c3 302#endif // ndef for wxUSE_BMPBUTTON