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