]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
added missing consts and pass objects by const reference instead of by value (patch...
[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 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
67
68 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
69 m_peer = new wxMacControl( this ) ;
70 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
71 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) ,
72 kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
73
74 wxMacReleaseBitmapButton( &info ) ;
75 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
76
77 MacPostControlCreate(pos,size) ;
78
79 return TRUE;
80 }
81
82 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
83 {
84 m_bmpNormal = bitmap;
85 InvalidateBestSize();
86
87 ControlButtonContentInfo info ;
88 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
89 if ( info.contentType != kControlNoContent )
90 {
91 m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ;
92 }
93 wxMacReleaseBitmapButton( &info ) ;
94 }
95
96
97 wxSize wxBitmapButton::DoGetBestSize() const
98 {
99 wxSize best;
100 if (m_bmpNormal.Ok())
101 {
102 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
103 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
104 }
105 return best;
106 }
107
108 #endif