]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
A little clarification
[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 #ifdef __GNUG__
13 #pragma implementation "bmpbuttn.h"
14 #endif
15
16 #include "wx/window.h"
17 #include "wx/bmpbuttn.h"
18
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
21 #endif
22
23 #include "wx/mac/uma.h"
24 #include "wx/bitmap.h"
25
26 wxBitmapButtonBase::wxBitmapButtonBase()
27 : m_bmpNormal(),
28 m_bmpSelected(),
29 m_bmpFocus(),
30 m_bmpDisabled(),
31 m_marginX(0),
32 m_marginY(0)
33 {
34 }
35
36 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
37 const wxPoint& pos,
38 const wxSize& size, long style,
39 const wxValidator& validator,
40 const wxString& name)
41 {
42 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
43 // essentially creates an additional button
44 if ( !wxControl::Create(parent, id, pos, size,
45 style, validator, name) )
46 return false;
47
48 m_bmpNormal = bitmap;
49
50 if (style & wxBU_AUTODRAW)
51 {
52 m_marginX = wxDEFAULT_BUTTON_MARGIN;
53 m_marginY = wxDEFAULT_BUTTON_MARGIN;
54 }
55 else
56 {
57 m_marginX = 0;
58 m_marginY = 0;
59 }
60
61 int width = size.x;
62 int height = size.y;
63
64 if ( width == -1 && bitmap.Ok())
65 width = bitmap.GetWidth() + 2*m_marginX;
66
67 if ( height == -1 && bitmap.Ok())
68 height = bitmap.GetHeight() + 2*m_marginY;
69
70 Rect bounds ;
71 Str255 title ;
72 m_bmpNormal = bitmap;
73 wxBitmapRefData * bmap = NULL ;
74
75 if ( m_bmpNormal.Ok() )
76 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
77
78 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
79
80 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
81 kControlBehaviorOffsetContents +
82 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
83 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
84 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
85 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
86
87 ControlButtonContentInfo info ;
88 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
89 if ( info.contentType != kControlNoContent )
90 {
91 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
92 }
93 MacPostControlCreate() ;
94
95 return TRUE;
96 }
97
98 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
99 {
100 m_bmpNormal = bitmap;
101
102 ControlButtonContentInfo info ;
103 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
104 if ( info.contentType != kControlNoContent )
105 {
106 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
107 }
108 }
109