]> git.saurik.com Git - wxWidgets.git/blob - src/mac/button.cpp
Added accelerators to Undo/Redo menu items
[wxWidgets.git] / src / mac / button.cpp
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"
17
18 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
20 #endif
21
22 #include <wx/mac/uma.h>
23 // Button
24
25
26 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
27 const wxPoint& pos,
28 const wxSize& size, long style,
29 const wxValidator& validator,
30 const wxString& name)
31 {
32 Rect bounds ;
33 Str255 title ;
34
35 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
36
37 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1,
38 kControlPushButtonProc , (long) this ) ;
39 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
40
41 MacPostControlCreate() ;
42
43 return TRUE;
44 }
45
46 void wxButton::SetDefault()
47 {
48 wxWindow *parent = GetParent();
49 wxButton *btnOldDefault = NULL;
50 wxPanel *panel = wxDynamicCast(parent, wxPanel);
51 if ( panel )
52 {
53 btnOldDefault = panel->GetDefaultItem();
54 panel->SetDefaultItem(this);
55 }
56
57 if ( btnOldDefault && btnOldDefault->m_macControl )
58 {
59 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ;
60 }
61 if ( m_macControl )
62 {
63 UMASetControlData( m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ;
64 }
65 }
66
67 wxSize wxButton::DoGetBestSize() const
68 {
69 int wBtn = m_label.Length() * 8 + 12 ;
70 int hBtn = 20 ;
71
72 if ( wBtn < 80 )
73 wBtn = 80 ;
74
75 return wxSize(wBtn, hBtn);
76 }
77
78 wxSize wxButton::GetDefaultSize()
79 {
80 int wBtn = 80 /* + 2 * m_macHorizontalBorder */ ;
81 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
82
83 return wxSize(wBtn, hBtn);
84 }
85
86 void wxButton::Command (wxCommandEvent & event)
87 {
88 if ( m_macControl )
89 {
90 HiliteControl( m_macControl , kControlButtonPart ) ;
91 unsigned long finalTicks ;
92 Delay( 8 , &finalTicks ) ;
93 HiliteControl( m_macControl , 0 ) ;
94 }
95 ProcessCommand (event);
96 }
97
98 void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
99 {
100 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
101 event.SetEventObject(this);
102 ProcessCommand(event);
103 }
104