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