]>
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; |
facd6764 | 68 | |
e40298d5 JS |
69 | wxBitmapRefData * bmap = NULL ; |
70 | ||
71 | if ( m_bmpNormal.Ok() ) | |
72 | bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; | |
73 | ||
4c37f124 SC |
74 | ControlButtonContentInfo info ; |
75 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
76 | ||
facd6764 | 77 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
21fd5529 | 78 | m_peer = new wxMacControl() ; |
4c37f124 SC |
79 | verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , |
80 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) , | |
5ca0d812 | 81 | kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); |
4c37f124 | 82 | |
21fd5529 SC |
83 | |
84 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; | |
e40298d5 | 85 | |
facd6764 | 86 | MacPostControlCreate(pos,size) ; |
e9576ca5 | 87 | |
7c551d95 | 88 | return TRUE; |
e9576ca5 SC |
89 | } |
90 | ||
91 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
92 | { | |
d460ed40 | 93 | m_bmpNormal = bitmap; |
9f884528 | 94 | InvalidateBestSize(); |
3dec57ad | 95 | |
d460ed40 GD |
96 | ControlButtonContentInfo info ; |
97 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
98 | if ( info.contentType != kControlNoContent ) | |
99 | { | |
21fd5529 | 100 | m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ; |
3dec57ad | 101 | } |
e9576ca5 SC |
102 | } |
103 | ||
c0831a3c RD |
104 | |
105 | wxSize wxBitmapButton::DoGetBestSize() const | |
106 | { | |
107 | wxSize best; | |
108 | if (m_bmpNormal.Ok()) | |
109 | { | |
110 | best.x = m_bmpNormal.GetWidth() + 2*m_marginX; | |
111 | best.y = m_bmpNormal.GetHeight() + 2*m_marginY; | |
112 | } | |
113 | return best; | |
114 | } |