]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/bmpbuttn.cpp
workaround for BCC bug - use #defines instead of enums
[wxWidgets.git] / src / mac / classic / 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 // 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 Rect bounds ;
64 Str255 title ;
65 m_bmpNormal = bitmap;
66 wxBitmapRefData * bmap = NULL ;
67
68 if ( m_bmpNormal.Ok() )
69 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
70
71 MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
72
73 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 ,
74 kControlBehaviorOffsetContents +
75 ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ?
76 kControlContentCIconHandle : kControlContentPictHandle ) , 0,
77 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
78 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
79
80 ControlButtonContentInfo info ;
81 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
82 if ( info.contentType != kControlNoContent )
83 {
84 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
85 }
86 MacPostControlCreate() ;
87
88 return TRUE;
89 }
90
91 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
92 {
93 m_bmpNormal = bitmap;
94
95 ControlButtonContentInfo info ;
96 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
97 if ( info.contentType != kControlNoContent )
98 {
99 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
100 }
101 }
102
103
104 wxSize wxBitmapButton::DoGetBestSize() const
105 {
106 wxSize best;
107 if (m_bmpNormal.Ok())
108 {
109 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
110 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
111 }
112 return best;
113 }