]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/bmpbuttn.cpp
Honor value of SetMaxLength, at least when typing (pasting still circumvents it)...
[wxWidgets.git] / src / mac / carbon / bmpbuttn.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: bmpbuttn.cpp
3 // Purpose: wxBitmapButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "bmpbuttn.h"
14 #endif
15
16 #include "wx/window.h"
17 #include "wx/bmpbuttn.h"
18
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxBitmapButton, wxButton)
21 #endif
22
23 #include "wx/mac/uma.h"
24 #include "wx/bitmap.h"
25
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 {
32 m_macIsUserPane = FALSE ;
33
34 // since bitmapbuttonbase is subclass of button calling wxBitmapButtonBase::Create
35 // essentially creates an additional button
36 if ( !wxControl::Create(parent, id, pos, size,
37 style, validator, name) )
38 return false;
39
40 m_bmpNormal = bitmap;
41
42 if (style & wxBU_AUTODRAW)
43 {
44 m_marginX = wxDEFAULT_BUTTON_MARGIN;
45 m_marginY = wxDEFAULT_BUTTON_MARGIN;
46 }
47 else
48 {
49 m_marginX = 0;
50 m_marginY = 0;
51 }
52
53 int width = size.x;
54 int height = size.y;
55
56 if ( bitmap.Ok() )
57 {
58 wxSize newSize = DoGetBestSize();
59 if ( width == -1 )
60 width = newSize.x;
61 if ( height == -1 )
62 height = newSize.y;
63 }
64
65 m_bmpNormal = bitmap;
66
67 wxBitmapRefData * bmap = NULL ;
68
69 if ( m_bmpNormal.Ok() )
70 bmap = (wxBitmapRefData*) ( m_bmpNormal.GetRefData()) ;
71
72 ControlButtonContentInfo info ;
73 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
74
75 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
76 m_peer = new wxMacControl() ;
77 verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") ,
78 (( style & wxBU_AUTODRAW ) ? kControlBevelButtonSmallBevel : kControlBevelButtonNormalBevel ) ,
79 kControlBehaviorOffsetContents , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
80
81
82 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
83
84 MacPostControlCreate(pos,size) ;
85
86 return TRUE;
87 }
88
89 void wxBitmapButton::SetBitmapLabel(const wxBitmap& bitmap)
90 {
91 m_bmpNormal = bitmap;
92 InvalidateBestSize();
93
94 ControlButtonContentInfo info ;
95 wxMacCreateBitmapButton( &info , m_bmpNormal ) ;
96 if ( info.contentType != kControlNoContent )
97 {
98 m_peer->SetData( kControlButtonPart , kControlBevelButtonContentTag , info ) ;
99 }
100 }
101
102
103 wxSize 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 }