]>
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 | ||
a8e9860d SC |
12 | #include "wx/wxprec.h" |
13 | ||
179e085f RN |
14 | #if wxUSE_BMPBUTTON |
15 | ||
d8c736e5 | 16 | #include "wx/window.h" |
e9576ca5 SC |
17 | #include "wx/bmpbuttn.h" |
18 | ||
e9576ca5 | 19 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
e9576ca5 | 20 | |
d497dca4 | 21 | #include "wx/mac/uma.h" |
72055702 | 22 | #include "wx/bitmap.h" |
7c551d95 | 23 | |
e9576ca5 SC |
24 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, |
25 | const wxPoint& pos, | |
26 | const wxSize& size, long style, | |
27 | const wxValidator& validator, | |
28 | const wxString& name) | |
29 | { | |
facd6764 SC |
30 | m_macIsUserPane = FALSE ; |
31 | ||
bf19e3f6 SC |
32 | // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create |
33 | // essentially creates an additional button | |
34 | if ( !wxControl::Create(parent, id, pos, size, | |
b45ed7a2 VZ |
35 | style, validator, name) ) |
36 | return false; | |
37 | ||
d460ed40 | 38 | m_bmpNormal = bitmap; |
7c551d95 | 39 | |
827e7a48 RR |
40 | if (style & wxBU_AUTODRAW) |
41 | { | |
42 | m_marginX = wxDEFAULT_BUTTON_MARGIN; | |
43 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
44 | } | |
45 | else | |
46 | { | |
47 | m_marginX = 0; | |
48 | m_marginY = 0; | |
49 | } | |
e9576ca5 | 50 | |
e9576ca5 SC |
51 | int width = size.x; |
52 | int height = size.y; | |
53 | ||
c0831a3c RD |
54 | if ( bitmap.Ok() ) |
55 | { | |
56 | wxSize newSize = DoGetBestSize(); | |
57 | if ( width == -1 ) | |
58 | width = newSize.x; | |
59 | if ( height == -1 ) | |
60 | height = newSize.y; | |
61 | } | |
e9576ca5 | 62 | |
f125ccf2 | 63 | m_bmpNormal = bitmap; |
20b69855 | 64 | |
4c37f124 SC |
65 | ControlButtonContentInfo info ; |
66 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
67 | ||
facd6764 | 68 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
b905d6cc | 69 | m_peer = new wxMacControl( this ) ; |
4c37f124 SC |
70 | verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , |
71 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) , | |
5ca0d812 | 72 | kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); |
4c37f124 | 73 | |
20b69855 | 74 | wxMacReleaseBitmapButton( &info ) ; |
21fd5529 | 75 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; |
e40298d5 | 76 | |
facd6764 | 77 | MacPostControlCreate(pos,size) ; |
e9576ca5 | 78 | |
7c551d95 | 79 | return TRUE; |
e9576ca5 SC |
80 | } |
81 | ||
82 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
83 | { | |
d460ed40 | 84 | m_bmpNormal = bitmap; |
9f884528 | 85 | InvalidateBestSize(); |
3dec57ad | 86 | |
d460ed40 GD |
87 | ControlButtonContentInfo info ; |
88 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
89 | if ( info.contentType != kControlNoContent ) | |
90 | { | |
21fd5529 | 91 | m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ; |
3dec57ad | 92 | } |
20b69855 | 93 | wxMacReleaseBitmapButton( &info ) ; |
e9576ca5 SC |
94 | } |
95 | ||
c0831a3c RD |
96 | |
97 | wxSize wxBitmapButton::DoGetBestSize() const | |
98 | { | |
99 | wxSize best; | |
100 | if (m_bmpNormal.Ok()) | |
101 | { | |
102 | best.x = m_bmpNormal.GetWidth() + 2*m_marginX; | |
103 | best.y = m_bmpNormal.GetHeight() + 2*m_marginY; | |
104 | } | |
105 | return best; | |
106 | } | |
179e085f RN |
107 | |
108 | #endif |