]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
we must turn off AA for XOR etc.
[wxWidgets.git] / src / mac / carbon / button.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
8e609c82 2// Name: src/mac/carbon/button.cpp
e9576ca5 3// Purpose: wxButton
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
8e609c82 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
a8e9860d 12#include "wx/wxprec.h"
d8c736e5 13
e9576ca5 14#include "wx/button.h"
8e609c82
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/panel.h"
b84aec03 18 #include "wx/toplevel.h"
8e609c82
WS
19#endif
20
5f7bcb48 21#include "wx/stockitem.h"
e9576ca5 22
25eb6881
DS
23#include "wx/mac/uma.h"
24
e9576ca5 25IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
e9576ca5 26
e9576ca5 27
25eb6881
DS
28bool wxButton::Create(wxWindow *parent,
29 wxWindowID id,
30 const wxString& lbl,
31 const wxPoint& pos,
32 const wxSize& size,
33 long style,
34 const wxValidator& validator,
35 const wxString& name)
e9576ca5 36{
5f7bcb48
VS
37 wxString label(lbl);
38 if (label.empty() && wxIsStockID(id))
39 label = wxGetStockLabel(id);
25eb6881
DS
40
41 m_macIsUserPane = false ;
42
b45ed7a2
VZ
43 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
44 return false;
25eb6881 45
facd6764 46 m_label = label ;
e40298d5 47
2e91d506 48 OSStatus err;
facd6764 49 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
b905d6cc 50 m_peer = new wxMacControl(this) ;
49e3e2c2
SC
51 if ( id == wxID_HELP )
52 {
53 ControlButtonContentInfo info ;
54 info.contentType = kControlContentIconRef ;
55 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
2e91d506
DS
56 err = CreateRoundButtonControl(
57 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
58 &bounds, kControlRoundButtonNormalSize,
59 &info, m_peer->GetControlRefAddr() );
49e3e2c2
SC
60 }
61 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
eed9e479 62 {
2a4c6734 63#if TARGET_API_MAC_OSX
25eb6881 64 // Button height is static in Mac, can't be changed, so we need to force it here
2a4c6734
SC
65 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
66 {
67 bounds.bottom = bounds.top + 20 ;
68 m_maxHeight = 20 ;
69 }
70 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
71 {
72 bounds.bottom = bounds.top + 17 ;
73 m_maxHeight = 17 ;
74 }
75 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
76 {
77 bounds.bottom = bounds.top + 15 ;
78 m_maxHeight = 15 ;
79 }
80#endif
25eb6881 81
2e91d506
DS
82 err = CreatePushButtonControl(
83 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
84 &bounds, CFSTR(""), m_peer->GetControlRefAddr() );
eed9e479
SC
85 }
86 else
87 {
88 ControlButtonContentInfo info ;
89 info.contentType = kControlNoContent ;
2e91d506
DS
90 err = CreateBevelButtonControl(
91 MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""),
92 kControlBevelButtonLargeBevel, kControlBehaviorPushbutton,
93 &info, 0, 0, 0, m_peer->GetControlRefAddr() );
eed9e479 94 }
25eb6881 95
2e91d506 96 verify_noerr( err );
25eb6881
DS
97 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid Mac control") ) ;
98
2e91d506 99 MacPostControlCreate( pos, size );
25eb6881
DS
100
101 return true;
e9576ca5
SC
102}
103
104void wxButton::SetDefault()
105{
6c20e8f8 106 wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
e7549107 107 wxButton *btnOldDefault = NULL;
6c20e8f8 108 if ( tlw )
e7549107 109 {
6c20e8f8
VZ
110 btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton);
111 tlw->SetDefaultItem(this);
e7549107 112 }
03e11df5 113
21fd5529
SC
114 if ( btnOldDefault )
115 btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ;
25eb6881 116
21fd5529 117 m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ;
e9576ca5
SC
118}
119
37e2cb08 120wxSize wxButton::DoGetBestSize() const
51abe921 121{
49e3e2c2
SC
122 if ( GetId() == wxID_HELP )
123 return wxSize( 20 , 20 ) ;
6d325d81 124
25eb6881 125 wxSize sz = GetDefaultSize() ;
6d325d81 126 int charspace = 8 ;
25eb6881
DS
127
128 switch (GetWindowVariant())
6d325d81 129 {
f3078f07
DS
130 case wxWINDOW_VARIANT_NORMAL:
131 case wxWINDOW_VARIANT_LARGE:
25eb6881
DS
132 sz.y = 20 ;
133 charspace = 10 ;
134 break;
135
f3078f07 136 case wxWINDOW_VARIANT_SMALL:
25eb6881
DS
137 sz.y = 17 ;
138 break;
139
f3078f07 140 case wxWINDOW_VARIANT_MINI:
25eb6881
DS
141 sz.y = 15 ;
142 break;
143
144 default:
145 break;
6d325d81 146 }
25eb6881 147
6d325d81 148 Rect bestsize = { 0 , 0 , 0 , 0 } ;
5ca0d812 149 m_peer->GetBestRect( &bestsize ) ;
8e609c82 150
23866d59 151 int wBtn;
6d325d81
SC
152 if ( EmptyRect( &bestsize ) )
153 {
8e609c82 154 wBtn = m_label.length() * charspace + 12 ;
6d325d81
SC
155 }
156 else
157 {
5ca0d812 158 wBtn = bestsize.right - bestsize.left ;
6d325d81
SC
159 sz.y = bestsize.bottom - bestsize.top ;
160 }
25eb6881 161
8e609c82 162 if ((wBtn > sz.x) || ( GetWindowStyle() & wxBU_EXACTFIT))
6d325d81
SC
163 sz.x = wBtn;
164
165 return sz ;
51abe921
SC
166}
167
7c74e7fe
SC
168wxSize wxButton::GetDefaultSize()
169{
8e609c82 170 int wBtn = 70 ;
e40298d5 171 int hBtn = 20 ;
25eb6881 172
7c74e7fe
SC
173 return wxSize(wBtn, hBtn);
174}
175
519cb848 176void wxButton::Command (wxCommandEvent & event)
e9576ca5 177{
21fd5529 178 m_peer->Flash(kControlButtonPart) ;
25eb6881 179 ProcessCommand(event);
e9576ca5
SC
180}
181
8e609c82 182wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
e9576ca5 183{
2e91d506 184 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId);
4c37f124
SC
185 event.SetEventObject(this);
186 ProcessCommand(event);
25eb6881
DS
187
188 return noErr;
e9576ca5 189}