]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
added adjustOrigin parameter to bounds calculation, added Freeze and Thaw implementation
[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
e40298d5 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 {
44 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1,
e40298d5 45 kControlPushButtonProc , (long) this ) ;
eed9e479
SC
46 }
47 else
48 {
49 ControlButtonContentInfo info ;
50 info.contentType = kControlNoContent ;
51 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
52 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ;
53 }
facd6764 54 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5 55
facd6764 56 MacPostControlCreate(pos,size) ;
e40298d5 57
519cb848 58 return TRUE;
e9576ca5
SC
59}
60
61void wxButton::SetDefault()
62{
e7549107
SC
63 wxWindow *parent = GetParent();
64 wxButton *btnOldDefault = NULL;
eddd3a9d 65 if ( parent )
e7549107 66 {
eddd3a9d 67 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 68 wxButton);
eddd3a9d 69 parent->SetDefaultItem(this);
e7549107 70 }
03e11df5 71
e40298d5
JS
72 Boolean inData;
73 if ( btnOldDefault && btnOldDefault->m_macControl )
74 {
75 inData = 0;
facd6764 76 ::SetControlData( (ControlRef) btnOldDefault->m_macControl , kControlButtonPart ,
e40298d5
JS
77 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
78 }
facd6764 79 if ( (ControlRef) m_macControl )
e40298d5
JS
80 {
81 inData = 1;
facd6764 82 ::SetControlData( (ControlRef) m_macControl , kControlButtonPart ,
e40298d5
JS
83 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
84 }
e9576ca5
SC
85}
86
37e2cb08 87wxSize wxButton::DoGetBestSize() const
51abe921 88{
0a67a93b
SC
89 wxSize sz = GetDefaultSize() ;
90
facd6764
SC
91 int charspace = 8 ;
92 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
93 {
94 sz.y = 20 ;
95 charspace = 10 ;
96 }
97 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
98 {
99 sz.y = 17 ;
100 charspace = 8 ;
101 }
102 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
103 {
104 sz.y = 15 ;
105 charspace = 8 ;
106 }
107
108 int wBtn = m_label.Length() * charspace + 12 ;
109
0a67a93b 110 if (wBtn > sz.x) sz.x = wBtn;
0a67a93b
SC
111
112 return sz ;
51abe921
SC
113}
114
7c74e7fe
SC
115wxSize wxButton::GetDefaultSize()
116{
0150a5b8 117 int wBtn = 70 ;
e40298d5 118 int hBtn = 20 ;
facd6764 119
7c74e7fe
SC
120 return wxSize(wBtn, hBtn);
121}
122
519cb848 123void wxButton::Command (wxCommandEvent & event)
e9576ca5 124{
facd6764 125 if ( (ControlRef) m_macControl )
eb22f2a6 126 {
facd6764 127 HiliteControl( (ControlRef) m_macControl , kControlButtonPart ) ;
eb22f2a6
GD
128 unsigned long finalTicks ;
129 Delay( 8 , &finalTicks ) ;
facd6764 130 HiliteControl( (ControlRef) m_macControl , 0 ) ;
eb22f2a6 131 }
519cb848 132 ProcessCommand (event);
e9576ca5
SC
133}
134
4b26b60f 135void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
e9576ca5 136{
eb22f2a6
GD
137 if ( controlpart != kControlNoPart )
138 {
139 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
140 event.SetEventObject(this);
141 ProcessCommand(event);
142 }
e9576ca5
SC
143}
144