]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
wxRadioBox fixed on mac
[wxWidgets.git] / src / mac / carbon / button.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
3// Purpose: wxButton
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "button.h"
14#endif
15
16#include "wx/button.h"
03e11df5 17#include "wx/panel.h"
e9576ca5 18
2f1ae414 19#if !USE_SHARED_LIBRARY
e9576ca5 20IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
2f1ae414 21#endif
e9576ca5 22
519cb848 23#include <wx/mac/uma.h>
e9576ca5
SC
24// Button
25
519cb848 26
e9576ca5
SC
27bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
28 const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator,
31 const wxString& name)
32{
519cb848
SC
33 Rect bounds ;
34 Str255 title ;
519cb848
SC
35
36 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
37
38 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1,
39 kControlPushButtonProc , (long) this ) ;
40 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
41
42 MacPostControlCreate() ;
43
44 return TRUE;
e9576ca5
SC
45}
46
47void wxButton::SetDefault()
48{
e7549107
SC
49 wxWindow *parent = GetParent();
50 wxButton *btnOldDefault = NULL;
51 wxPanel *panel = wxDynamicCast(parent, wxPanel);
52 if ( panel )
53 {
54 btnOldDefault = panel->GetDefaultItem();
55 panel->SetDefaultItem(this);
56 }
03e11df5
GD
57
58#ifdef __UNIX__
59 Boolean inData;
60 if ( btnOldDefault && btnOldDefault->m_macControl )
61 {
62 inData = 0;
63 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
64 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
65 }
66 if ( m_macControl )
67 {
68 inData = 1;
69 UMASetControlData( m_macControl , kControlButtonPart ,
70 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
71 }
72#else
73 if ( btnOldDefault && btnOldDefault->m_macControl )
74 {
75 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
76 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ;
77 }
78 if ( m_macControl )
79 {
80 UMASetControlData( m_macControl , kControlButtonPart ,
81 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ;
82 }
83#endif
e9576ca5
SC
84}
85
37e2cb08 86wxSize wxButton::DoGetBestSize() const
51abe921 87{
0a67a93b
SC
88 wxSize sz = GetDefaultSize() ;
89
2f1ae414
SC
90 int wBtn = m_label.Length() * 8 + 12 ;
91 int hBtn = 20 ;
92
0a67a93b
SC
93 if (wBtn > sz.x) sz.x = wBtn;
94 if (hBtn > sz.y) sz.y = hBtn;
95
96 return sz ;
51abe921
SC
97}
98
7c74e7fe
SC
99wxSize wxButton::GetDefaultSize()
100{
0a67a93b 101 int wBtn = 70 /* + 2 * m_macHorizontalBorder */ ;
2f1ae414 102 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
7c74e7fe
SC
103
104 return wxSize(wBtn, hBtn);
105}
106
519cb848 107void wxButton::Command (wxCommandEvent & event)
e9576ca5 108{
2f1ae414
SC
109 if ( m_macControl )
110 {
111 HiliteControl( m_macControl , kControlButtonPart ) ;
112 unsigned long finalTicks ;
113 Delay( 8 , &finalTicks ) ;
114 HiliteControl( m_macControl , 0 ) ;
115 }
519cb848 116 ProcessCommand (event);
e9576ca5
SC
117}
118
519cb848 119void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
e9576ca5 120{
519cb848
SC
121 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
122 event.SetEventObject(this);
123 ProcessCommand(event);
e9576ca5
SC
124}
125