]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: bmpbuttn.cpp | |
3 | // Purpose: wxBitmapButton | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
13 | #pragma implementation "bmpbuttn.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/wxprec.h" | |
17 | ||
18 | #if wxUSE_BMPBUTTON | |
19 | ||
20 | #include "wx/window.h" | |
21 | #include "wx/bmpbuttn.h" | |
22 | ||
23 | #if !USE_SHARED_LIBRARY | |
24 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) | |
25 | #endif | |
26 | ||
27 | #include "wx/mac/uma.h" | |
28 | #include "wx/bitmap.h" | |
29 | ||
30 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, | |
31 | const wxPoint& pos, | |
32 | const wxSize& size, long style, | |
33 | const wxValidator& validator, | |
34 | const wxString& name) | |
35 | { | |
36 | m_macIsUserPane = FALSE ; | |
37 | ||
38 | // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create | |
39 | // essentially creates an additional button | |
40 | if ( !wxControl::Create(parent, id, pos, size, | |
41 | style, validator, name) ) | |
42 | return false; | |
43 | ||
44 | m_bmpNormal = bitmap; | |
45 | ||
46 | if (style & wxBU_AUTODRAW) | |
47 | { | |
48 | m_marginX = wxDEFAULT_BUTTON_MARGIN; | |
49 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
50 | } | |
51 | else | |
52 | { | |
53 | m_marginX = 0; | |
54 | m_marginY = 0; | |
55 | } | |
56 | ||
57 | int width = size.x; | |
58 | int height = size.y; | |
59 | ||
60 | if ( bitmap.Ok() ) | |
61 | { | |
62 | wxSize newSize = DoGetBestSize(); | |
63 | if ( width == -1 ) | |
64 | width = newSize.x; | |
65 | if ( height == -1 ) | |
66 | height = newSize.y; | |
67 | } | |
68 | ||
69 | m_bmpNormal = bitmap; | |
70 | ||
71 | ControlButtonContentInfo info ; | |
72 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
73 | ||
74 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; | |
75 | m_peer = new wxMacControl( this ) ; | |
76 | verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , | |
77 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) , | |
78 | kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); | |
79 | ||
80 | wxMacReleaseBitmapButton( &info ) ; | |
81 | wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ; | |
82 | ||
83 | MacPostControlCreate(pos,size) ; | |
84 | ||
85 | return TRUE; | |
86 | } | |
87 | ||
88 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
89 | { | |
90 | m_bmpNormal = bitmap; | |
91 | InvalidateBestSize(); | |
92 | ||
93 | ControlButtonContentInfo info ; | |
94 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
95 | if ( info.contentType != kControlNoContent ) | |
96 | { | |
97 | m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ; | |
98 | } | |
99 | wxMacReleaseBitmapButton( &info ) ; | |
100 | } | |
101 | ||
102 | ||
103 | wxSize wxBitmapButton::DoGetBestSize() const | |
104 | { | |
105 | wxSize best; | |
106 | if (m_bmpNormal.Ok()) | |
107 | { | |
108 | best.x = m_bmpNormal.GetWidth() + 2*m_marginX; | |
109 | best.y = m_bmpNormal.GetHeight() + 2*m_marginY; | |
110 | } | |
111 | return best; | |
112 | } | |
113 | ||
114 | #endif |