]>
Commit | Line | Data |
---|---|---|
2646f485 SC |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
2646f485 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "bmpbuttn.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/window.h" | |
17 | #include "wx/bmpbuttn.h" | |
18 | ||
2646f485 | 19 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
2646f485 SC |
20 | |
21 | #include "wx/mac/uma.h" | |
22 | #include "wx/bitmap.h" | |
23 | ||
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 | { | |
30 | // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create | |
31 | // essentially creates an additional button | |
32 | if ( !wxControl::Create(parent, id, pos, size, | |
33 | style, validator, name) ) | |
34 | return false; | |
35 | ||
36 | m_bmpNormal = bitmap; | |
37 | ||
38 | if (style & wxBU_AUTODRAW) | |
39 | { | |
40 | m_marginX = wxDEFAULT_BUTTON_MARGIN; | |
41 | m_marginY = wxDEFAULT_BUTTON_MARGIN; | |
42 | } | |
43 | else | |
44 | { | |
45 | m_marginX = 0; | |
46 | m_marginY = 0; | |
47 | } | |
48 | ||
49 | int width = size.x; | |
50 | int height = size.y; | |
51 | ||
52 | if ( bitmap.Ok() ) | |
53 | { | |
54 | wxSize newSize = DoGetBestSize(); | |
55 | if ( width == -1 ) | |
56 | width = newSize.x; | |
57 | if ( height == -1 ) | |
58 | height = newSize.y; | |
59 | } | |
60 | ||
61 | Rect bounds ; | |
62 | Str255 title ; | |
63 | m_bmpNormal = bitmap; | |
64 | wxBitmapRefData * bmap = NULL ; | |
65 | ||
66 | if ( m_bmpNormal.Ok() ) | |
67 | bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; | |
68 | ||
69 | MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; | |
70 | ||
6bc3b8e9 | 71 | m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , |
2646f485 SC |
72 | kControlBehaviorOffsetContents + |
73 | ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ? | |
74 | kControlContentCIconHandle : kControlContentPictHandle ) , 0, | |
75 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; | |
76 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; | |
77 | ||
78 | ControlButtonContentInfo info ; | |
79 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
80 | if ( info.contentType != kControlNoContent ) | |
81 | { | |
82 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
83 | } | |
84 | MacPostControlCreate() ; | |
85 | ||
86 | return TRUE; | |
87 | } | |
88 | ||
89 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
90 | { | |
91 | m_bmpNormal = bitmap; | |
9f884528 | 92 | InvalidateBestSize(); |
2646f485 SC |
93 | |
94 | ControlButtonContentInfo info ; | |
95 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
96 | if ( info.contentType != kControlNoContent ) | |
97 | { | |
98 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
99 | } | |
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 | } |