]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
Warning fix.
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "bmpbuttn.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/window.h"
19 #include "wx/bmpbuttn.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
23 #endif
24
25 #include "wx/mac/uma.h"
26 #include "wx/bitmap.h"
27
28 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 m_macIsUserPane = FALSE ;
35
36 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
37 // essentially creates an additional button
38 if ( !wxControl::Create(parent, id, pos, size,
39 style, validator, name) )
40 return false;
41
42 m_bmpNormal = bitmap;
43
44 if (style & wxBU_AUTODRAW)
45 {
46 m_marginX = wxDEFAULT_BUTTON_MARGIN;
47 m_marginY = wxDEFAULT_BUTTON_MARGIN;
48 }
49 else
50 {
51 m_marginX = 0;
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 == -1 )
62 width = newSize.x;
63 if ( height == -1 )
64 height = newSize.y;
65 }
66
67 m_bmpNormal = bitmap;
68
69 wxBitmapRefData * bmap = NULL ;
70
71 if ( m_bmpNormal.Ok() )
72 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
73
74 ControlButtonContentInfo info ;
75 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
76
77 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
78 m_peer = new wxMacControl() ;
79 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
80 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) ,
81 kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
82
83
84 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
85
86 MacPostControlCreate(pos,size) ;
87
88 return TRUE;
89 }
90
91 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
92 {
93 m_bmpNormal = bitmap;
94 InvalidateBestSize();
95
96 ControlButtonContentInfo info ;
97 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
98 if ( info.contentType != kControlNoContent )
99 {
100 m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ;
101 }
102 }
103
104
105 wxSize wxBitmapButton::DoGetBestSize() const
106 {
107 wxSize best;
108 if (m_bmpNormal.Ok())
109 {
110 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
111 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
112 }
113 return best;
114 }