]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/button.cpp
Got rid of some wierd VisualAge debug nonsense that had appeared in this after the...
[wxWidgets.git] / src / mac / carbon / 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 #include "wx/panel.h"
18
19 #if !USE_SHARED_LIBRARY
20 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
21 #endif
22
23 #include <wx/mac/uma.h>
24 // Button
25
26
27 bool 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 {
33 Rect bounds ;
34 Str255 title ;
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;
45 }
46
47 void wxButton::SetDefault()
48 {
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 }
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
84 }
85
86 wxSize wxButton::DoGetBestSize() const
87 {
88 int wBtn = m_label.Length() * 8 + 12 ;
89 int hBtn = 20 ;
90
91 if ( wBtn < 80 )
92 wBtn = 80 ;
93
94 return wxSize(wBtn, hBtn);
95 }
96
97 wxSize wxButton::GetDefaultSize()
98 {
99 int wBtn = 80 /* + 2 * m_macHorizontalBorder */ ;
100 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
101
102 return wxSize(wBtn, hBtn);
103 }
104
105 void wxButton::Command (wxCommandEvent & event)
106 {
107 if ( m_macControl )
108 {
109 HiliteControl( m_macControl , kControlButtonPart ) ;
110 unsigned long finalTicks ;
111 Delay( 8 , &finalTicks ) ;
112 HiliteControl( m_macControl , 0 ) ;
113 }
114 ProcessCommand (event);
115 }
116
117 void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
118 {
119 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
120 event.SetEventObject(this);
121 ProcessCommand(event);
122 }
123