]>
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 |
e40298d5 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "bmpbuttn.h" | |
14 | #endif | |
15 | ||
d8c736e5 | 16 | #include "wx/window.h" |
e9576ca5 SC |
17 | #include "wx/bmpbuttn.h" |
18 | ||
2f1ae414 | 19 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 20 | IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton) |
2f1ae414 | 21 | #endif |
e9576ca5 | 22 | |
d497dca4 | 23 | #include "wx/mac/uma.h" |
72055702 | 24 | #include "wx/bitmap.h" |
7c551d95 | 25 | |
e9576ca5 SC |
26 | bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap, |
27 | const wxPoint& pos, | |
28 | const wxSize& size, long style, | |
29 | const wxValidator& validator, | |
30 | const wxString& name) | |
31 | { | |
d460ed40 | 32 | m_bmpNormal = bitmap; |
7c551d95 | 33 | |
e9576ca5 SC |
34 | m_marginX = 0; |
35 | m_marginY = 0; | |
36 | ||
d460ed40 GD |
37 | // int x = pos.x; |
38 | // int y = pos.y; | |
e9576ca5 SC |
39 | int width = size.x; |
40 | int height = size.y; | |
41 | ||
42 | if (id == -1) | |
43 | m_windowId = NewControlId(); | |
44 | else | |
45 | m_windowId = id; | |
46 | ||
47 | if ( width == -1 && bitmap.Ok()) | |
e40298d5 | 48 | width = bitmap.GetWidth() + 2*m_marginX; |
e9576ca5 SC |
49 | |
50 | if ( height == -1 && bitmap.Ok()) | |
e40298d5 | 51 | height = bitmap.GetHeight() + 2*m_marginY; |
e9576ca5 | 52 | |
e40298d5 JS |
53 | Rect bounds ; |
54 | Str255 title ; | |
f125ccf2 | 55 | m_bmpNormal = bitmap; |
e40298d5 JS |
56 | wxBitmapRefData * bmap = NULL ; |
57 | ||
58 | if ( m_bmpNormal.Ok() ) | |
59 | bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ; | |
60 | ||
427ff662 | 61 | MacPreControlCreate( parent , id , wxEmptyString , pos , wxSize( width , height ) ,style, validator , name , &bounds , title ) ; |
7c551d95 | 62 | |
e40298d5 JS |
63 | m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , |
64 | kControlBehaviorOffsetContents + | |
65 | ( bmap && bmap->m_bitmapType == kMacBitmapTypeIcon ? | |
66 | kControlContentCIconHandle : kControlContentPictHandle ) , 0, | |
67 | (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevelProc : kControlBevelButtonNormalBevelProc ), (long) this ) ; | |
427ff662 | 68 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
e40298d5 JS |
69 | |
70 | ControlButtonContentInfo info ; | |
71 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
72 | if ( info.contentType != kControlNoContent ) | |
73 | { | |
74 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
be295828 | 75 | } |
e40298d5 | 76 | MacPostControlCreate() ; |
e9576ca5 | 77 | |
7c551d95 | 78 | return TRUE; |
e9576ca5 SC |
79 | } |
80 | ||
81 | void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap) | |
82 | { | |
d460ed40 | 83 | m_bmpNormal = bitmap; |
3dec57ad | 84 | |
d460ed40 GD |
85 | ControlButtonContentInfo info ; |
86 | wxMacCreateBitmapButton( &info , m_bmpNormal ) ; | |
87 | if ( info.contentType != kControlNoContent ) | |
88 | { | |
89 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , kControlBevelButtonContentTag , sizeof(info) , (char*) &info ) ; | |
3dec57ad | 90 | } |
e9576ca5 SC |
91 | } |
92 |