]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
added clientcontext variable to Open Transport initialisation
[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{
2f1ae414
SC
88 int wBtn = m_label.Length() * 8 + 12 ;
89 int hBtn = 20 ;
90
91 if ( wBtn < 80 )
92 wBtn = 80 ;
51abe921
SC
93
94 return wxSize(wBtn, hBtn);
95}
96
7c74e7fe
SC
97wxSize wxButton::GetDefaultSize()
98{
2f1ae414
SC
99 int wBtn = 80 /* + 2 * m_macHorizontalBorder */ ;
100 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
7c74e7fe
SC
101
102 return wxSize(wBtn, hBtn);
103}
104
519cb848 105void wxButton::Command (wxCommandEvent & event)
e9576ca5 106{
2f1ae414
SC
107 if ( m_macControl )
108 {
109 HiliteControl( m_macControl , kControlButtonPart ) ;
110 unsigned long finalTicks ;
111 Delay( 8 , &finalTicks ) ;
112 HiliteControl( m_macControl , 0 ) ;
113 }
519cb848 114 ProcessCommand (event);
e9576ca5
SC
115}
116
519cb848 117void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
e9576ca5 118{
519cb848
SC
119 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
120 event.SetEventObject(this);
121 ProcessCommand(event);
e9576ca5
SC
122}
123