]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/bmpbuttn.cpp
work w/o bitmap button
[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 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "bmpbuttn.h"
14#endif
15
a8e9860d
SC
16#include "wx/wxprec.h"
17
179e085f
RN
18#if wxUSE_BMPBUTTON
19
d8c736e5 20#include "wx/window.h"
e9576ca5
SC
21#include "wx/bmpbuttn.h"
22
2f1ae414 23#if !USE_SHARED_LIBRARY
e9576ca5 24IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
2f1ae414 25#endif
e9576ca5 26
d497dca4 27#include "wx/mac/uma.h"
72055702 28#include "wx/bitmap.h"
7c551d95 29
e9576ca5
SC
30bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id, const wxBitmap& bitmap,
31 const wxPoint& pos,
32 const wxSize& size, long style,
33 const wxValidator& validator,
34 const wxString& name)
35{
facd6764
SC
36 m_macIsUserPane = FALSE ;
37
bf19e3f6
SC
38 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
39 // essentially creates an additional button
40 if ( !wxControl::Create(parent, id, pos, size,
b45ed7a2
VZ
41 style, validator, name) )
42 return false;
43
d460ed40 44 m_bmpNormal = bitmap;
7c551d95 45
827e7a48
RR
46 if (style & wxBU_AUTODRAW)
47 {
48 m_marginX = wxDEFAULT_BUTTON_MARGIN;
49 m_marginY = wxDEFAULT_BUTTON_MARGIN;
50 }
51 else
52 {
53 m_marginX = 0;
54 m_marginY = 0;
55 }
e9576ca5 56
e9576ca5
SC
57 int width = size.x;
58 int height = size.y;
59
c0831a3c
RD
60 if ( bitmap.Ok() )
61 {
62 wxSize newSize = DoGetBestSize();
63 if ( width == -1 )
64 width = newSize.x;
65 if ( height == -1 )
66 height = newSize.y;
67 }
e9576ca5 68
f125ccf2 69 m_bmpNormal = bitmap;
20b69855 70
4c37f124
SC
71 ControlButtonContentInfo info ;
72 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
73
facd6764 74 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
b905d6cc 75 m_peer = new wxMacControl( this ) ;
4c37f124
SC
76 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
77 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) ,
5ca0d812 78 kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
4c37f124 79
20b69855 80 wxMacReleaseBitmapButton( &info ) ;
21fd5529 81 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
e40298d5 82
facd6764 83 MacPostControlCreate(pos,size) ;
e9576ca5 84
7c551d95 85 return TRUE;
e9576ca5
SC
86}
87
88void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
89{
d460ed40 90 m_bmpNormal = bitmap;
9f884528 91 InvalidateBestSize();
3dec57ad 92
d460ed40
GD
93 ControlButtonContentInfo info ;
94 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
95 if ( info.contentType != kControlNoContent )
96 {
21fd5529 97 m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ;
3dec57ad 98 }
20b69855 99 wxMacReleaseBitmapButton( &info ) ;
e9576ca5
SC
100}
101
c0831a3c
RD
102
103wxSize 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}
179e085f
RN
113
114#endif