]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
create stock GDI objects on demand; use const with GDI objects appropriately (patch...
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
cc374a2f 2// Name: src/mac/carbon/bmpbuttn.cpp
e9576ca5 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
cc374a2f
DS
24bool wxBitmapButton::Create( wxWindow *parent,
25 wxWindowID id, const wxBitmap& bitmap,
26 const wxPoint& pos,
27 const wxSize& size,
28 long style,
29 const wxValidator& validator,
30 const wxString& name )
e9576ca5 31{
cc374a2f
DS
32 m_macIsUserPane = false;
33
bf19e3f6
SC
34 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
35 // essentially creates an additional button
cc374a2f 36 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
b45ed7a2
VZ
37 return false;
38
d460ed40 39 m_bmpNormal = bitmap;
cc374a2f
DS
40
41 if ( style & wxBU_AUTODRAW )
827e7a48 42 {
cc374a2f 43 m_marginX =
827e7a48
RR
44 m_marginY = wxDEFAULT_BUTTON_MARGIN;
45 }
46 else
47 {
cc374a2f 48 m_marginX =
827e7a48
RR
49 m_marginY = 0;
50 }
e9576ca5 51
e9576ca5
SC
52 int width = size.x;
53 int height = size.y;
54
c0831a3c
RD
55 if ( bitmap.Ok() )
56 {
57 wxSize newSize = DoGetBestSize();
58 if ( width == -1 )
59 width = newSize.x;
60 if ( height == -1 )
61 height = newSize.y;
62 }
e9576ca5 63
f125ccf2 64 m_bmpNormal = bitmap;
4c37f124 65
cc374a2f
DS
66 OSStatus err = noErr;
67 ControlButtonContentInfo info;
68
69 Rect bounds = wxMacGetBoundsForControl( this, pos, size );
70 m_peer = new wxMacControl( this );
d32be04c
SC
71
72#ifdef __WXMAC_OSX__
73 if ( HasFlag( wxBORDER_NONE ) )
74 {
cc374a2f
DS
75 wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef );
76 err = CreateIconControl(
77 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
78 &bounds, &info, false, m_peer->GetControlRefAddr() );
d32be04c
SC
79 }
80 else
81#endif
82 {
cc374a2f
DS
83 wxMacCreateBitmapButton( &info, m_bmpNormal );
84 err = CreateBevelButtonControl(
85 MAC_WXHWND(parent->MacGetTopLevelWindowRef()), &bounds, CFSTR(""),
86 ((style & wxBU_AUTODRAW) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ),
87 kControlBehaviorOffsetContents, &info, 0, 0, 0, m_peer->GetControlRefAddr() );
d32be04c 88 }
e9576ca5 89
cc374a2f
DS
90 verify_noerr( err );
91
92 wxMacReleaseBitmapButton( &info );
93 wxASSERT_MSG( m_peer != NULL && m_peer->Ok(), wxT("No valid native Mac control") );
94
95 MacPostControlCreate( pos, size );
96
97 return true;
e9576ca5
SC
98}
99
cc374a2f 100void wxBitmapButton::SetBitmapLabel( const wxBitmap& bitmap )
e9576ca5 101{
d460ed40 102 m_bmpNormal = bitmap;
9f884528 103 InvalidateBestSize();
3dec57ad 104
cc374a2f
DS
105 ControlButtonContentInfo info;
106
d32be04c
SC
107#ifdef __WXMAC_OSX__
108 if ( HasFlag( wxBORDER_NONE ) )
109 {
cc374a2f 110 wxMacCreateBitmapButton( &info, m_bmpNormal, kControlContentIconRef );
d32be04c 111 if ( info.contentType != kControlNoContent )
cc374a2f 112 m_peer->SetData( kControlIconPart, kControlIconContentTag, info );
d32be04c
SC
113 }
114 else
115#endif
d460ed40 116 {
cc374a2f 117 wxMacCreateBitmapButton( &info, m_bmpNormal );
d32be04c 118 if ( info.contentType != kControlNoContent )
cc374a2f 119 m_peer->SetData( kControlButtonPart, kControlBevelButtonContentTag, info );
3dec57ad 120 }
e9576ca5 121
cc374a2f
DS
122 wxMacReleaseBitmapButton( &info );
123}
c0831a3c
RD
124
125wxSize wxBitmapButton::DoGetBestSize() const
126{
127 wxSize best;
cc374a2f
DS
128
129 best.x = 2 * m_marginX;
130 best.y = 2 * m_marginY;
131 if ( m_bmpNormal.Ok() )
c0831a3c 132 {
cc374a2f
DS
133 best.x += m_bmpNormal.GetWidth();
134 best.y += m_bmpNormal.GetHeight();
c0831a3c 135 }
cc374a2f 136
c0831a3c
RD
137 return best;
138}
179e085f
RN
139
140#endif