]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
fix for wxStatusBar linking problems under wxMac
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bmpbuttn.cpp
3 // Purpose: wxBitmapButton
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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
25 PicHandle MakePict(GWorldPtr wp, GWorldPtr mask ) ;
26
27 bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
28 const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator,
31 const wxString& name)
32 {
33 m_buttonBitmap = bitmap;
34
35 m_marginX = 0;
36 m_marginY = 0;
37
38 int x = pos.x;
39 int y = pos.y;
40 int width = size.x;
41 int height = size.y;
42
43 if (id == -1)
44 m_windowId = NewControlId();
45 else
46 m_windowId = id;
47
48 if ( width == -1 && bitmap.Ok())
49 width = bitmap.GetWidth() + 2*m_marginX;
50
51 if ( height == -1 && bitmap.Ok())
52 height = bitmap.GetHeight() + 2*m_marginY;
53
54 Rect bounds ;
55 Str255 title ;
56 m_buttonBitmap = bitmap;
57 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
58
59 MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ;
60
61 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 ,
62 kControlBehaviorOffsetContents +
63 ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0,
64 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ;
65 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
66
67 ControlButtonContentInfo info ;
68
69
70 if ( m_buttonBitmap.Ok() )
71 {
72 if ( bmap->m_bitmapType == kMacBitmapTypePict ) {
73 info.contentType = kControlContentPictHandle ;
74 info.u.picture = bmap->m_hPict ;
75 }
76 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
77 {
78 info.contentType = kControlContentPictHandle ;
79 if ( m_buttonBitmap.GetMask() )
80 {
81 info.u.picture = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ;
82 }
83 else
84 {
85 info.u.picture = MakePict( bmap->m_hBitmap , NULL ) ;
86 }
87 }
88 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
89 {
90 info.contentType = kControlContentCIconHandle ;
91 info.u.cIconHandle = bmap->m_hIcon ;
92 }
93 }
94
95 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
96
97 MacPostControlCreate() ;
98
99 return TRUE;
100 }
101
102 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
103 {
104 ControlButtonContentInfo info ;
105 m_buttonBitmap = bitmap;
106
107 if ( m_buttonBitmap.Ok() )
108 {
109 wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ;
110 if ( bmap->m_bitmapType == kMacBitmapTypePict )
111 {
112 info.contentType = kControlContentPictHandle ;
113 info.u.picture = bmap->m_hPict ;
114 }
115 else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld )
116 {
117 info.contentType = kControlContentPictHandle ;
118 if ( m_buttonBitmap.GetMask() )
119 {
120 info.u.picture = MakePict( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() ) ;
121 }
122 else
123 {
124 info.u.picture = MakePict( bmap->m_hBitmap , NULL ) ;
125 }
126 }
127 else if ( bmap->m_bitmapType == kMacBitmapTypeIcon )
128 {
129 info.contentType = kControlContentCIconHandle ;
130 info.u.cIconHandle = bmap->m_hIcon ;
131 }
132
133 UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ;
134 }
135 }
136