]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
LocalToGlobal/GlobalToLocal Conversions with Carbon API, cleanup, hittesting correcte...
[wxWidgets.git] / src / mac / carbon / button.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
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
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "button.h"
14#endif
15
d8c736e5
GD
16#include "wx/defs.h"
17
e9576ca5 18#include "wx/button.h"
03e11df5 19#include "wx/panel.h"
e9576ca5 20
2f1ae414 21#if !USE_SHARED_LIBRARY
e9576ca5 22IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
2f1ae414 23#endif
e9576ca5 24
d497dca4 25#include "wx/mac/uma.h"
e9576ca5
SC
26// Button
27
28bool 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{
facd6764
SC
34 m_macIsUserPane = FALSE ;
35
b45ed7a2
VZ
36 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
e40298d5 38
facd6764 39 m_label = label ;
e40298d5 40
facd6764 41 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
eed9e479
SC
42 if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
43 {
4c37f124 44 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , (ControlRef*) &m_macControl ) ) ;
eed9e479
SC
45 }
46 else
47 {
48 ControlButtonContentInfo info ;
49 info.contentType = kControlNoContent ;
50 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
51 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ;
52 }
facd6764 53 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5 54
facd6764 55 MacPostControlCreate(pos,size) ;
e40298d5 56
519cb848 57 return TRUE;
e9576ca5
SC
58}
59
60void wxButton::SetDefault()
61{
e7549107
SC
62 wxWindow *parent = GetParent();
63 wxButton *btnOldDefault = NULL;
eddd3a9d 64 if ( parent )
e7549107 65 {
eddd3a9d 66 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 67 wxButton);
eddd3a9d 68 parent->SetDefaultItem(this);
e7549107 69 }
03e11df5 70
e40298d5
JS
71 Boolean inData;
72 if ( btnOldDefault && btnOldDefault->m_macControl )
73 {
74 inData = 0;
facd6764 75 ::SetControlData( (ControlRef) btnOldDefault->m_macControl , kControlButtonPart ,
e40298d5
JS
76 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
77 }
facd6764 78 if ( (ControlRef) m_macControl )
e40298d5
JS
79 {
80 inData = 1;
facd6764 81 ::SetControlData( (ControlRef) m_macControl , kControlButtonPart ,
e40298d5
JS
82 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
83 }
e9576ca5
SC
84}
85
37e2cb08 86wxSize wxButton::DoGetBestSize() const
51abe921 87{
0a67a93b
SC
88 wxSize sz = GetDefaultSize() ;
89
facd6764
SC
90 int charspace = 8 ;
91 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
92 {
93 sz.y = 20 ;
94 charspace = 10 ;
95 }
96 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
97 {
98 sz.y = 17 ;
99 charspace = 8 ;
100 }
101 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
102 {
103 sz.y = 15 ;
104 charspace = 8 ;
105 }
106
107 int wBtn = m_label.Length() * charspace + 12 ;
108
0a67a93b 109 if (wBtn > sz.x) sz.x = wBtn;
0a67a93b
SC
110
111 return sz ;
51abe921
SC
112}
113
7c74e7fe
SC
114wxSize wxButton::GetDefaultSize()
115{
0150a5b8 116 int wBtn = 70 ;
e40298d5 117 int hBtn = 20 ;
facd6764 118
7c74e7fe
SC
119 return wxSize(wBtn, hBtn);
120}
121
519cb848 122void wxButton::Command (wxCommandEvent & event)
e9576ca5 123{
facd6764 124 if ( (ControlRef) m_macControl )
eb22f2a6 125 {
facd6764 126 HiliteControl( (ControlRef) m_macControl , kControlButtonPart ) ;
eb22f2a6
GD
127 unsigned long finalTicks ;
128 Delay( 8 , &finalTicks ) ;
facd6764 129 HiliteControl( (ControlRef) m_macControl , 0 ) ;
eb22f2a6 130 }
519cb848 131 ProcessCommand (event);
e9576ca5
SC
132}
133
4c37f124 134wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
e9576ca5 135{
4c37f124
SC
136 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
137 event.SetEventObject(this);
138 ProcessCommand(event);
139 return noErr ;
e9576ca5
SC
140}
141