]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/bmpbuttn.cpp
Restore a use case that was lost with the last set of updates, using a
[wxWidgets.git] / src / mac / classic / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/bmpbuttn.cpp
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_BMPBUTTON
15
16 #include "wx/bmpbuttn.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/window.h"
20 #include "wx/bitmap.h"
21 #endif
22
23 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
24
25 #include "wx/mac/uma.h"
26
27 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
28 const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator,
31 const wxString& name)
32 {
33 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
34 // essentially creates an additional button
35 if ( !wxControl::Create(parent, id, pos, size,
36 style, validator, name) )
37 return false;
38
39 m_bmpNormal = bitmap;
40
41 if (style & wxBU_AUTODRAW)
42 {
43 m_marginX = wxDEFAULT_BUTTON_MARGIN;
44 m_marginY = wxDEFAULT_BUTTON_MARGIN;
45 }
46 else
47 {
48 m_marginX = 0;
49 m_marginY = 0;
50 }
51
52 int width = size.x;
53 int height = size.y;
54
55 if ( bitmap.Ok() )
56 {
57 wxSize newSize = DoGetBestSize();
58 if ( width == -1 )
59 width = newSize.x;
60 if ( height == -1 )
61 height = newSize.y;
62 }
63
64 Rect bounds ;
65 Str255 title ;
66 m_bmpNormal = bitmap;
67 wxBitmapRefData * bmap = NULL ;
68
69 if ( m_bmpNormal.Ok() )
70 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
71
72 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
73
74 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
75 kControlBehaviorOffsetContents +
76 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
77 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
78 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
79 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
80
81 ControlButtonContentInfo info ;
82 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
83 if ( info.contentType != kControlNoContent )
84 {
85 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
86 }
87 MacPostControlCreate() ;
88
89 return true;
90 }
91
92 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
93 {
94 m_bmpNormal = bitmap;
95 InvalidateBestSize();
96
97 ControlButtonContentInfo info ;
98 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
99 if ( info.contentType != kControlNoContent )
100 {
101 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
102 }
103 }
104
105
106 wxSize wxBitmapButton::DoGetBestSize() const
107 {
108 wxSize best;
109 if (m_bmpNormal.Ok())
110 {
111 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
112 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
113 }
114 return best;
115 }
116
117 #endif // wxUSE_BMPBUTTON