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