]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
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 | ||
d8c736e5 | 16 | #include "wx/window.h" |
e9576ca5 SC |
17 | #include "wx/bmpbuttn.h" |
18 | ||
2f1ae414 | 19 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 20 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
2f1ae414 | 21 | #endif |
e9576ca5 | 22 | |
d497dca4 | 23 | #include "wx/mac/uma.h" |
72055702 | 24 | #include "wx/bitmap.h" |
7c551d95 | 25 | |
e9576ca5 SC |
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 | m_buttonBitmap = bitmap; | |
7c551d95 | 33 | |
e9576ca5 SC |
34 | m_marginX = 0; |
35 | m_marginY = 0; | |
36 | ||
37 | int x = pos.x; | |
38 | int y = pos.y; | |
39 | int width = size.x; | |
40 | int height = size.y; | |
41 | ||
42 | if (id == -1) | |
43 | m_windowId = NewControlId(); | |
44 | else | |
45 | m_windowId = id; | |
46 | ||
47 | if ( width == -1 && bitmap.Ok()) | |
48 | width = bitmap.GetWidth() + 2*m_marginX; | |
49 | ||
50 | if ( height == -1 && bitmap.Ok()) | |
51 | height = bitmap.GetHeight() + 2*m_marginY; | |
52 | ||
7c551d95 SC |
53 | Rect bounds ; |
54 | Str255 title ; | |
3dec57ad SC |
55 | m_buttonBitmap = bitmap; |
56 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; | |
57 | ||
7c551d95 SC |
58 | MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; |
59 | ||
72055702 | 60 | m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , |
3dec57ad SC |
61 | kControlBehaviorOffsetContents + |
62 | ( bmap->m_bitmapType == kMacBitmapTypeIcon ? kControlContentCIconHandle : kControlContentPictHandle ) , 0, | |
37e2cb08 | 63 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; |
7c551d95 SC |
64 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; |
65 | ||
3dec57ad SC |
66 | ControlButtonContentInfo info ; |
67 | ||
68 | ||
7c551d95 SC |
69 | if ( m_buttonBitmap.Ok() ) |
70 | { | |
3dec57ad | 71 | if ( bmap->m_bitmapType == kMacBitmapTypePict ) { |
72055702 SC |
72 | info.contentType = kControlContentPictHandle ; |
73 | info.u.picture = bmap->m_hPict ; | |
3dec57ad | 74 | } |
7c551d95 SC |
75 | else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) |
76 | { | |
2f1ae414 SC |
77 | if ( m_buttonBitmap.GetMask() ) |
78 | { | |
72055702 SC |
79 | info.contentType = kControlContentCIconHandle ; |
80 | info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() , | |
81 | 8 , 16 ) ; | |
2f1ae414 SC |
82 | } |
83 | else | |
84 | { | |
72055702 SC |
85 | info.contentType = kControlContentCIconHandle ; |
86 | info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL , | |
87 | 8 , 16 ) ; | |
2f1ae414 | 88 | } |
7c551d95 | 89 | } |
3dec57ad SC |
90 | else if ( bmap->m_bitmapType == kMacBitmapTypeIcon ) |
91 | { | |
92 | info.contentType = kControlContentCIconHandle ; | |
93 | info.u.cIconHandle = bmap->m_hIcon ; | |
94 | } | |
7c551d95 | 95 | } |
7c551d95 | 96 | |
72055702 | 97 | ::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; |
7c551d95 SC |
98 | |
99 | MacPostControlCreate() ; | |
e9576ca5 | 100 | |
7c551d95 | 101 | return TRUE; |
e9576ca5 SC |
102 | } |
103 | ||
104 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
105 | { | |
3dec57ad | 106 | ControlButtonContentInfo info ; |
e9576ca5 | 107 | m_buttonBitmap = bitmap; |
3dec57ad | 108 | |
7c551d95 SC |
109 | if ( m_buttonBitmap.Ok() ) |
110 | { | |
111 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; | |
72055702 SC |
112 | if ( bmap->m_bitmapType == kMacBitmapTypePict ) { |
113 | info.contentType = kControlContentPictHandle ; | |
114 | info.u.picture = bmap->m_hPict ; | |
3dec57ad | 115 | } |
7c551d95 SC |
116 | else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) |
117 | { | |
2f1ae414 SC |
118 | if ( m_buttonBitmap.GetMask() ) |
119 | { | |
72055702 SC |
120 | info.contentType = kControlContentCIconHandle ; |
121 | info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , m_buttonBitmap.GetMask()->GetMaskBitmap() , | |
122 | 8 , 16 ) ; | |
2f1ae414 SC |
123 | } |
124 | else | |
125 | { | |
72055702 SC |
126 | info.contentType = kControlContentCIconHandle ; |
127 | info.u.cIconHandle = wxMacCreateCIcon( bmap->m_hBitmap , NULL , | |
128 | 8 , 16 ) ; | |
2f1ae414 | 129 | } |
7c551d95 | 130 | } |
3dec57ad SC |
131 | else if ( bmap->m_bitmapType == kMacBitmapTypeIcon ) |
132 | { | |
133 | info.contentType = kControlContentCIconHandle ; | |
134 | info.u.cIconHandle = bmap->m_hIcon ; | |
135 | } | |
72055702 | 136 | |
3dec57ad | 137 | |
72055702 | 138 | ::SetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; |
3dec57ad | 139 | } |
e9576ca5 SC |
140 | } |
141 |