]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/button.cpp
* In _GSocket_Get_Mac_Socket(), do not call CFSocketSetSocketFlags to turn
[wxWidgets.git] / src / mac / carbon / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose: wxButton
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
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 static const int kMacOSXHorizontalBorder = 2 ;
29 static const int kMacOSXVerticalBorder = 4 ;
30
31 wxButtonBase::wxButtonBase()
32 {
33 }
34
35 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
36 const wxPoint& pos,
37 const wxSize& size, long style,
38 const wxValidator& validator,
39 const wxString& name)
40 {
41 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
42 return false;
43
44 Rect bounds ;
45 Str255 title ;
46
47 if ( UMAHasAquaLayout() )
48 {
49 m_macHorizontalBorder = kMacOSXHorizontalBorder;
50 m_macVerticalBorder = kMacOSXVerticalBorder;
51 }
52
53 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
54
55 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
56 kControlPushButtonProc , (long) this ) ;
57 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
58
59 MacPostControlCreate() ;
60
61 return TRUE;
62 }
63
64 void wxButton::SetDefault()
65 {
66 wxWindow *parent = GetParent();
67 wxButton *btnOldDefault = NULL;
68 if ( parent )
69 {
70 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
71 wxButton);
72 parent->SetDefaultItem(this);
73 }
74
75 Boolean inData;
76 if ( btnOldDefault && btnOldDefault->m_macControl )
77 {
78 inData = 0;
79 ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart ,
80 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
81 }
82 if ( (ControlHandle) m_macControl )
83 {
84 inData = 1;
85 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart ,
86 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
87 }
88 }
89
90 wxSize wxButton::DoGetBestSize() const
91 {
92 wxSize sz = GetDefaultSize() ;
93
94 int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ;
95
96 if (wBtn > sz.x) sz.x = wBtn;
97
98 return sz ;
99 }
100
101 wxSize wxButton::GetDefaultSize()
102 {
103 int wBtn = 70 ;
104 int hBtn = 20 ;
105
106 if ( UMAHasAquaLayout() )
107 {
108 wBtn += 2 * kMacOSXHorizontalBorder ;
109 hBtn += 2 * kMacOSXVerticalBorder ;
110 }
111
112 return wxSize(wBtn, hBtn);
113 }
114
115 void wxButton::Command (wxCommandEvent & event)
116 {
117 if ( (ControlHandle) m_macControl )
118 {
119 HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ;
120 unsigned long finalTicks ;
121 Delay( 8 , &finalTicks ) ;
122 HiliteControl( (ControlHandle) m_macControl , 0 ) ;
123 }
124 ProcessCommand (event);
125 }
126
127 void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
128 {
129 if ( controlpart != kControlNoPart )
130 {
131 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
132 event.SetEventObject(this);
133 ProcessCommand(event);
134 }
135 }
136