]>
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 | ||
16 | #include "wx/bmpbuttn.h" | |
17 | ||
18 | #if !USE_SHARED_LIBRARY | |
19 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) | |
20 | #endif | |
21 | ||
7c551d95 SC |
22 | #include <wx/mac/uma.h> |
23 | ||
24 | PicHandle MakePict(GWorldPtr wp) ; | |
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 | m_macHorizontalBorder = 2 ; // additional pixels around the real control |
54 | m_macVerticalBorder = 2 ; | |
55 | Rect bounds ; | |
56 | Str255 title ; | |
57 | MacPreControlCreate( parent , id , "" , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; | |
58 | ||
59 | m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , | |
60 | kControlBehaviorOffsetContents + kControlContentPictHandle , 0, | |
61 | kControlBevelButtonNormalBevelProc , (long) this ) ; | |
62 | wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ; | |
63 | ||
64 | m_buttonBitmap = bitmap; | |
65 | PicHandle icon = NULL ; | |
66 | if ( m_buttonBitmap.Ok() ) | |
67 | { | |
68 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; | |
69 | if ( bmap->m_bitmapType == kMacBitmapTypePict ) | |
70 | icon = bmap->m_hPict ; | |
71 | else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) | |
72 | { | |
73 | icon = MakePict( bmap->m_hBitmap ) ; | |
74 | } | |
75 | } | |
76 | ControlButtonContentInfo info ; | |
77 | ||
78 | info.contentType = kControlContentPictHandle ; | |
79 | info.u.picture = icon ; | |
80 | ||
81 | UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
82 | ||
83 | MacPostControlCreate() ; | |
e9576ca5 | 84 | |
7c551d95 | 85 | return TRUE; |
e9576ca5 SC |
86 | } |
87 | ||
88 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
89 | { | |
90 | m_buttonBitmap = bitmap; | |
7c551d95 SC |
91 | PicHandle icon = NULL ; |
92 | if ( m_buttonBitmap.Ok() ) | |
93 | { | |
94 | wxBitmapRefData * bmap = (wxBitmapRefData*) ( m_buttonBitmap.GetRefData()) ; | |
95 | if ( bmap->m_bitmapType == kMacBitmapTypePict ) | |
96 | icon = bmap->m_hPict ; | |
97 | else if ( bmap->m_bitmapType == kMacBitmapTypeGrafWorld ) | |
98 | { | |
99 | icon = MakePict( bmap->m_hBitmap ) ; | |
100 | } | |
101 | } | |
102 | ControlButtonContentInfo info ; | |
103 | ||
104 | info.contentType = kControlContentPictHandle ; | |
105 | info.u.picture = icon ; | |
106 | ||
107 | UMASetControlData( m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
e9576ca5 SC |
108 | } |
109 |