]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: bmpbuttn.cpp | |
3 | // Purpose: wxBitmapButton | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
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 | { | |
facd6764 SC |
32 | m_macIsUserPane = FALSE ; |
33 | ||
bf19e3f6 SC |
34 | // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create |
35 | // essentially creates an additional button | |
36 | if ( !wxControl::Create(parent, id, pos, size, | |
b45ed7a2 VZ |
37 | style, validator, name) ) |
38 | return false; | |
39 | ||
d460ed40 | 40 | m_bmpNormal = bitmap; |
7c551d95 | 41 | |
827e7a48 RR |
42 | if (style & wxBU_AUTODRAW) |
43 | { | |
44 | m_marginX = wxDEFAULT_BUTTON_MARGIN; | |
45 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
46 | } | |
47 | else | |
48 | { | |
49 | m_marginX = 0; | |
50 | m_marginY = 0; | |
51 | } | |
e9576ca5 | 52 | |
e9576ca5 SC |
53 | int width = size.x; |
54 | int height = size.y; | |
55 | ||
c0831a3c RD |
56 | if ( bitmap.Ok() ) |
57 | { | |
58 | wxSize newSize = DoGetBestSize(); | |
59 | if ( width == -1 ) | |
60 | width = newSize.x; | |
61 | if ( height == -1 ) | |
62 | height = newSize.y; | |
63 | } | |
e9576ca5 | 64 | |
f125ccf2 | 65 | m_bmpNormal = bitmap; |
facd6764 | 66 | |
e40298d5 JS |
67 | wxBitmapRefData * bmap = NULL ; |
68 | ||
69 | if ( m_bmpNormal.Ok() ) | |
70 | bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; | |
71 | ||
4c37f124 SC |
72 | ControlButtonContentInfo info ; |
73 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
74 | ||
facd6764 | 75 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
4c37f124 SC |
76 | verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , |
77 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) , | |
78 | kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ; | |
79 | ||
facd6764 | 80 | wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ; |
e40298d5 | 81 | |
facd6764 | 82 | MacPostControlCreate(pos,size) ; |
e9576ca5 | 83 | |
7c551d95 | 84 | return TRUE; |
e9576ca5 SC |
85 | } |
86 | ||
87 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
88 | { | |
d460ed40 | 89 | m_bmpNormal = bitmap; |
3dec57ad | 90 | |
d460ed40 GD |
91 | ControlButtonContentInfo info ; |
92 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
93 | if ( info.contentType != kControlNoContent ) | |
94 | { | |
facd6764 | 95 | ::SetControlData( (ControlRef) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; |
3dec57ad | 96 | } |
e9576ca5 SC |
97 | } |
98 | ||
c0831a3c RD |
99 | |
100 | wxSize wxBitmapButton::DoGetBestSize() const | |
101 | { | |
102 | wxSize best; | |
103 | if (m_bmpNormal.Ok()) | |
104 | { | |
105 | best.x = m_bmpNormal.GetWidth() + 2*m_marginX; | |
106 | best.y = m_bmpNormal.GetHeight() + 2*m_marginY; | |
107 | } | |
108 | return best; | |
109 | } |