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