]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
add wxTLW::UseNativeDecorations[ByDefault]() to allow the programmer to control wheth...
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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,
28 wxWindowID id, const wxBitmap& bitmap,
29 const wxPoint& pos,
30 const wxSize& size,
31 long style,
32 const wxValidator& validator,
33 const wxString& name )
34 {
35 m_macIsUserPane = false;
36
37 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
38 // essentially creates an additional button
39 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
40 return false;
41
42 m_bmpNormal = bitmap;
43
44 if ( style & wxBU_AUTODRAW )
45 {
46 m_marginX =
47 m_marginY = wxDEFAULT_BUTTON_MARGIN;
48 }
49 else
50 {
51 m_marginX =
52 m_marginY = 0;
53 }
54
55 int width = size.x;
56 int height = size.y;
57
58 if ( bitmap.Ok() )
59 {
60 wxSize newSize = DoGetBestSize();
61 if ( width == wxDefaultCoord )
62 width = newSize.x;
63 if ( height == wxDefaultCoord )
64 height = newSize.y;
65 }
66
67 m_bmpNormal = bitmap;
68
69 OSStatus err = noErr;
70 ControlButtonContentInfo info;
71
72 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
73 m_peer = new wxMacControl( this );
74
75 #ifdef __WXMAC_OSX__
76 if ( HasFlag( wxBORDER_NONE ) )
77 {
78 wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef );
79 err = CreateIconControl(
80 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
81 &bounds, &info, false, m_peer->GetControlRefAddr() );
82 }
83 else
84 #endif
85 {
86 wxMacCreateBitmapButton( &info, m_bmpNormal );
87 err = CreateBevelButtonControl(
88 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""),
89 ((style & wxBU_AUTODRAW) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ),
90 kControlBehaviorOffsetContents, &info, 0, 0, 0, m_peer->GetControlRefAddr() );
91 }
92
93 verify_noerr( err );
94
95 wxMacReleaseBitmapButton( &info );
96 wxASSERT_MSG( m_peer != NULL && m_peer->Ok(), wxT("No valid native Mac control") );
97
98 MacPostControlCreate( pos, size );
99
100 return true;
101 }
102
103 void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
104 {
105 m_bmpNormal = bitmap;
106 InvalidateBestSize();
107
108 ControlButtonContentInfo info;
109
110 #ifdef __WXMAC_OSX__
111 if ( HasFlag( wxBORDER_NONE ) )
112 {
113 wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef );
114 if ( info.contentType != kControlNoContent )
115 m_peer->SetData( kControlIconPart, kControlIconContentTag, info );
116 }
117 else
118 #endif
119 {
120 wxMacCreateBitmapButton( &info, m_bmpNormal );
121 if ( info.contentType != kControlNoContent )
122 m_peer->SetData( kControlButtonPart, kControlBevelButtonContentTag, info );
123 }
124
125 wxMacReleaseBitmapButton( &info );
126 }
127
128 wxSize wxBitmapButton::DoGetBestSize() const
129 {
130 wxSize best;
131
132 best.x = 2 * m_marginX;
133 best.y = 2 * m_marginY;
134 if ( m_bmpNormal.Ok() )
135 {
136 best.x += m_bmpNormal.GetWidth();
137 best.y += m_bmpNormal.GetHeight();
138 }
139
140 return best;
141 }
142
143 #endif