]> git.saurik.com Git - wxWidgets.git/blob - src/mac/button.cpp
overwrote with src\wxBase.dsp
[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/defs.h"
17
18 #include "wx/button.h"
19 #include "wx/panel.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
23 #endif
24
25 #include <wx/mac/uma.h>
26 // Button
27
28
29 bool 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 {
35 Rect bounds ;
36 Str255 title ;
37
38 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
39
40 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 1,
41 kControlPushButtonProc , (long) this ) ;
42 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
43
44 MacPostControlCreate() ;
45
46 return TRUE;
47 }
48
49 void wxButton::SetDefault()
50 {
51 wxWindow *parent = GetParent();
52 wxButton *btnOldDefault = NULL;
53 wxPanel *panel = wxDynamicCast(parent, wxPanel);
54 if ( panel )
55 {
56 btnOldDefault = wxDynamicCast(panel->GetDefaultItem(),
57 wxButton);
58 panel->SetDefaultItem(this);
59 }
60
61 #ifdef __DARWIN__
62 Boolean inData;
63 if ( btnOldDefault && btnOldDefault->m_macControl )
64 {
65 inData = 0;
66 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
67 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
68 }
69 if ( m_macControl )
70 {
71 inData = 1;
72 UMASetControlData( m_macControl , kControlButtonPart ,
73 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
74 }
75 #else
76 if ( btnOldDefault && btnOldDefault->m_macControl )
77 {
78 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
79 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ;
80 }
81 if ( m_macControl )
82 {
83 UMASetControlData( m_macControl , kControlButtonPart ,
84 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ;
85 }
86 #endif
87 }
88
89 wxSize wxButton::DoGetBestSize() const
90 {
91 wxSize sz = GetDefaultSize() ;
92
93 int wBtn = m_label.Length() * 8 + 12 ;
94 int hBtn = 20 ;
95
96 if (wBtn > sz.x) sz.x = wBtn;
97 if (hBtn > sz.y) sz.y = hBtn;
98
99 return sz ;
100 }
101
102 wxSize wxButton::GetDefaultSize()
103 {
104 int wBtn = 70 /* + 2 * m_macHorizontalBorder */ ;
105 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
106
107 return wxSize(wBtn, hBtn);
108 }
109
110 void wxButton::Command (wxCommandEvent & event)
111 {
112 if ( m_macControl )
113 {
114 HiliteControl( m_macControl , kControlButtonPart ) ;
115 unsigned long finalTicks ;
116 Delay( 8 , &finalTicks ) ;
117 HiliteControl( m_macControl , 0 ) ;
118 }
119 ProcessCommand (event);
120 }
121
122 void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
123 {
124 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
125 event.SetEventObject(this);
126 ProcessCommand(event);
127 }
128