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