]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
Darwin has commandline args.
[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
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
519cb848 28
e9576ca5
SC
29bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
30 const wxPoint& pos,
31 const wxSize& size, long style,
32 const wxValidator& validator,
33 const wxString& name)
34{
519cb848
SC
35 Rect bounds ;
36 Str255 title ;
519cb848
SC
37
38 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
39
72055702 40 m_macControl = ::NewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 1,
519cb848
SC
41 kControlPushButtonProc , (long) this ) ;
42 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
43
44 MacPostControlCreate() ;
45
46 return TRUE;
e9576ca5
SC
47}
48
49void wxButton::SetDefault()
50{
e7549107
SC
51 wxWindow *parent = GetParent();
52 wxButton *btnOldDefault = NULL;
53 wxPanel *panel = wxDynamicCast(parent, wxPanel);
54 if ( panel )
55 {
c1fb8167
SC
56 btnOldDefault = wxDynamicCast(panel->GetDefaultItem(),
57 wxButton);
e7549107
SC
58 panel->SetDefaultItem(this);
59 }
03e11df5 60
03e11df5
GD
61 Boolean inData;
62 if ( btnOldDefault && btnOldDefault->m_macControl )
63 {
64 inData = 0;
72055702 65 ::SetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
03e11df5
GD
66 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
67 }
68 if ( m_macControl )
69 {
70 inData = 1;
72055702 71 ::SetControlData( m_macControl , kControlButtonPart ,
03e11df5
GD
72 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
73 }
e9576ca5
SC
74}
75
37e2cb08 76wxSize wxButton::DoGetBestSize() const
51abe921 77{
0a67a93b
SC
78 wxSize sz = GetDefaultSize() ;
79
2f1ae414
SC
80 int wBtn = m_label.Length() * 8 + 12 ;
81 int hBtn = 20 ;
82
0a67a93b
SC
83 if (wBtn > sz.x) sz.x = wBtn;
84 if (hBtn > sz.y) sz.y = hBtn;
85
86 return sz ;
51abe921
SC
87}
88
7c74e7fe
SC
89wxSize wxButton::GetDefaultSize()
90{
0a67a93b 91 int wBtn = 70 /* + 2 * m_macHorizontalBorder */ ;
2f1ae414 92 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
7c74e7fe
SC
93
94 return wxSize(wBtn, hBtn);
95}
96
519cb848 97void wxButton::Command (wxCommandEvent & event)
e9576ca5 98{
2f1ae414
SC
99 if ( m_macControl )
100 {
101 HiliteControl( m_macControl , kControlButtonPart ) ;
102 unsigned long finalTicks ;
103 Delay( 8 , &finalTicks ) ;
104 HiliteControl( m_macControl , 0 ) ;
105 }
519cb848 106 ProcessCommand (event);
e9576ca5
SC
107}
108
519cb848 109void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
e9576ca5 110{
461a37f5
SC
111 if ( controlpart != kControlNoPart )
112 {
519cb848
SC
113 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
114 event.SetEventObject(this);
115 ProcessCommand(event);
461a37f5 116 }
e9576ca5
SC
117}
118