]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/button.cpp
SetValue is not adding a line if values does not exist
[wxWidgets.git] / src / mac / carbon / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose: wxButton
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 "button.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/button.h"
19 #include "wx/panel.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
23 #endif
24
25 #include "wx/mac/uma.h"
26 // Button
27
28 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 m_macIsUserPane = FALSE ;
35
36 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
39 m_label = label ;
40
41 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
42 m_peer = new wxMacControl() ;
43 if ( id == wxID_HELP )
44 {
45 ControlButtonContentInfo info ;
46 info.contentType = kControlContentIconRef ;
47 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
48 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , kControlRoundButtonNormalSize ,
49 &info , m_peer->GetControlRefAddr() ) );
50 }
51 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
52 {
53 #if TARGET_API_MAC_OSX
54 //Button height is static in Mac, can't be changed, so we need to force it here
55 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
56 {
57 bounds.bottom = bounds.top + 20 ;
58 m_maxHeight = 20 ;
59 }
60 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
61 {
62 bounds.bottom = bounds.top + 17 ;
63 m_maxHeight = 17 ;
64 }
65 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
66 {
67 bounds.bottom = bounds.top + 15 ;
68 m_maxHeight = 15 ;
69 }
70 #endif
71 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , m_peer->GetControlRefAddr() ) );
72 }
73 else
74 {
75 ControlButtonContentInfo info ;
76 info.contentType = kControlNoContent ;
77 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
78 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
79 }
80
81 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
82
83 MacPostControlCreate(pos,size) ;
84
85 return TRUE;
86 }
87
88 void wxButton::SetDefault()
89 {
90 wxWindow *parent = GetParent();
91 wxButton *btnOldDefault = NULL;
92 if ( parent )
93 {
94 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
95 wxButton);
96 parent->SetDefaultItem(this);
97 }
98
99 if ( btnOldDefault )
100 btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ;
101 m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ;
102 }
103
104 wxSize wxButton::DoGetBestSize() const
105 {
106 if ( GetId() == wxID_HELP )
107 return wxSize( 20 , 20 ) ;
108
109 wxSize sz = GetDefaultSize() ;
110
111 int charspace = 8 ;
112 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
113 {
114 sz.y = 20 ;
115 charspace = 10 ;
116 }
117 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
118 {
119 sz.y = 17 ;
120 charspace = 8 ;
121 }
122 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
123 {
124 sz.y = 15 ;
125 charspace = 8 ;
126 }
127
128 Rect bestsize = { 0 , 0 , 0 , 0 } ;
129 m_peer->GetBestRect( &bestsize ) ;
130
131 int wBtn;
132 if ( EmptyRect( &bestsize ) )
133 {
134 wBtn = m_label.Length() * charspace + 12 ;
135 }
136 else
137 {
138 wBtn = bestsize.right - bestsize.left ;
139 sz.y = bestsize.bottom - bestsize.top ;
140 }
141
142 if (wBtn > sz.x || ( GetWindowStyle() & wxBU_EXACTFIT) )
143 sz.x = wBtn;
144
145 return sz ;
146 }
147
148 wxSize wxButton::GetDefaultSize()
149 {
150 int wBtn = 70 ;
151 int hBtn = 20 ;
152
153 return wxSize(wBtn, hBtn);
154 }
155
156 void wxButton::Command (wxCommandEvent & event)
157 {
158 m_peer->Flash(kControlButtonPart) ;
159 ProcessCommand (event);
160 }
161
162 wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
163 {
164 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
165 event.SetEventObject(this);
166 ProcessCommand(event);
167 return noErr ;
168 }
169