]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
just added a comment
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
CommitLineData
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
SC
12#include "wx/wxprec.h"
13
179e085f
RN
14#if wxUSE_BMPBUTTON
15
d8c736e5 16#include "wx/window.h"
e9576ca5
SC
17#include "wx/bmpbuttn.h"
18
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
e9576ca5 20
d497dca4 21#include "wx/mac/uma.h"
72055702 22#include "wx/bitmap.h"
7c551d95 23
e9576ca5
SC
24bool 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{
facd6764
SC
30 m_macIsUserPane = FALSE ;
31
bf19e3f6
SC
32 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
33 // essentially creates an additional button
34 if ( !wxControl::Create(parent, id, pos, size,
b45ed7a2
VZ
35 style, validator, name) )
36 return false;
37
d460ed40 38 m_bmpNormal = bitmap;
7c551d95 39
827e7a48
RR
40 if (style & wxBU_AUTODRAW)
41 {
42 m_marginX = wxDEFAULT_BUTTON_MARGIN;
43 m_marginY = wxDEFAULT_BUTTON_MARGIN;
44 }
45 else
46 {
47 m_marginX = 0;
48 m_marginY = 0;
49 }
e9576ca5 50
e9576ca5
SC
51 int width = size.x;
52 int height = size.y;
53
c0831a3c
RD
54 if ( bitmap.Ok() )
55 {
56 wxSize newSize = DoGetBestSize();
57 if ( width == -1 )
58 width = newSize.x;
59 if ( height == -1 )
60 height = newSize.y;
61 }
e9576ca5 62
f125ccf2 63 m_bmpNormal = bitmap;
20b69855 64
4c37f124 65 ControlButtonContentInfo info ;
4c37f124 66
facd6764 67 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
b905d6cc 68 m_peer = new wxMacControl( this ) ;
d32be04c
SC
69
70#ifdef __WXMAC_OSX__
71 if ( HasFlag( wxBORDER_NONE ) )
72 {
73 wxMacCreateBitmapButton( &info , m_bmpNormal , kControlContentIconRef ) ;
74 verify_noerr ( CreateIconControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , &info , false , m_peer->GetControlRefAddr() ) );
75 }
76 else
77#endif
78 {
79 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
80 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
81 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) ,
82 kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
83 }
20b69855 84 wxMacReleaseBitmapButton( &info ) ;
21fd5529 85 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
e40298d5 86
facd6764 87 MacPostControlCreate(pos,size) ;
e9576ca5 88
7c551d95 89 return TRUE;
e9576ca5
SC
90}
91
92void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
93{
d460ed40 94 m_bmpNormal = bitmap;
9f884528 95 InvalidateBestSize();
3dec57ad 96
d460ed40 97 ControlButtonContentInfo info ;
d32be04c
SC
98#ifdef __WXMAC_OSX__
99 if ( HasFlag( wxBORDER_NONE ) )
100 {
101 wxMacCreateBitmapButton( &info , m_bmpNormal , kControlContentIconRef ) ;
102 if ( info.contentType != kControlNoContent )
103 {
104 m_peer->SetData( kControlIconPart , kControlIconContentTag , info ) ;
105 }
106 }
107 else
108#endif
d460ed40 109 {
d32be04c
SC
110 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
111 if ( info.contentType != kControlNoContent )
112 {
113 m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ;
114 }
3dec57ad 115 }
20b69855 116 wxMacReleaseBitmapButton( &info ) ;
e9576ca5
SC
117}
118
c0831a3c
RD
119
120wxSize wxBitmapButton::DoGetBestSize() const
121{
122 wxSize best;
123 if (m_bmpNormal.Ok())
124 {
125 best.x = m_bmpNormal.GetWidth() + 2*m_marginX;
126 best.y = m_bmpNormal.GetHeight() + 2*m_marginY;
127 }
128 return best;
129}
179e085f
RN
130
131#endif