]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
when memory dumps out debug info, lookups can go wrong, since the list is not there...
[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 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
27 const wxPoint& pos,
28 const wxSize& size, long style,
29 const wxValidator& validator,
30 const wxString& name)
31 {
32 if ( !wxBitmapButtonBase::Create(parent, id, _T(""), pos, size,
33 style, validator, name) )
34 return false;
35
36 m_bmpNormal = bitmap;
37
38 if (style & wxBU_AUTODRAW)
39 {
40 m_marginX = wxDEFAULT_BUTTON_MARGIN;
41 m_marginY = wxDEFAULT_BUTTON_MARGIN;
42 }
43 else
44 {
45 m_marginX = 0;
46 m_marginY = 0;
47 }
48
49 int width = size.x;
50 int height = size.y;
51
52 if ( width == -1 && bitmap.Ok())
53 width = bitmap.GetWidth() + 2*m_marginX;
54
55 if ( height == -1 && bitmap.Ok())
56 height = bitmap.GetHeight() + 2*m_marginY;
57
58 Rect bounds ;
59 Str255 title ;
60 m_bmpNormal = bitmap;
61 wxBitmapRefData * bmap = NULL ;
62
63 if ( m_bmpNormal.Ok() )
64 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
65
66 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
67
68 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
69 kControlBehaviorOffsetContents +
70 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
71 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
72 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
73 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
74
75 ControlButtonContentInfo info ;
76 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
77 if ( info.contentType != kControlNoContent )
78 {
79 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
80 }
81 MacPostControlCreate() ;
82
83 return TRUE;
84 }
85
86 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
87 {
88 m_bmpNormal = bitmap;
89
90 ControlButtonContentInfo info ;
91 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
92 if ( info.contentType != kControlNoContent )
93 {
94 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
95 }
96 }
97