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