]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/button.cpp
d11c858561efeabd10f14af4378b73b43c1928bc
[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 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33 {
34 m_macIsUserPane = FALSE ;
35
36 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
39 m_label = label ;
40
41 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
42 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1,
43 kControlPushButtonProc , (long) this ) ;
44 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
45
46 MacPostControlCreate(pos,size) ;
47
48 return TRUE;
49 }
50
51 void wxButton::SetDefault()
52 {
53 wxWindow *parent = GetParent();
54 wxButton *btnOldDefault = NULL;
55 if ( parent )
56 {
57 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
58 wxButton);
59 parent->SetDefaultItem(this);
60 }
61
62 Boolean inData;
63 if ( btnOldDefault && btnOldDefault->m_macControl )
64 {
65 inData = 0;
66 ::SetControlData( (ControlRef) btnOldDefault->m_macControl , kControlButtonPart ,
67 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
68 }
69 if ( (ControlRef) m_macControl )
70 {
71 inData = 1;
72 ::SetControlData( (ControlRef) m_macControl , kControlButtonPart ,
73 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
74 }
75 }
76
77 wxSize wxButton::DoGetBestSize() const
78 {
79 wxSize sz = GetDefaultSize() ;
80
81 int charspace = 8 ;
82 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
83 {
84 sz.y = 20 ;
85 charspace = 10 ;
86 }
87 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
88 {
89 sz.y = 17 ;
90 charspace = 8 ;
91 }
92 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
93 {
94 sz.y = 15 ;
95 charspace = 8 ;
96 }
97
98 int wBtn = m_label.Length() * charspace + 12 ;
99
100 if (wBtn > sz.x) sz.x = wBtn;
101
102 return sz ;
103 }
104
105 wxSize wxButton::GetDefaultSize()
106 {
107 int wBtn = 70 ;
108 int hBtn = 20 ;
109
110 return wxSize(wBtn, hBtn);
111 }
112
113 void wxButton::Command (wxCommandEvent & event)
114 {
115 if ( (ControlRef) m_macControl )
116 {
117 HiliteControl( (ControlRef) m_macControl , kControlButtonPart ) ;
118 unsigned long finalTicks ;
119 Delay( 8 , &finalTicks ) ;
120 HiliteControl( (ControlRef) m_macControl , 0 ) ;
121 }
122 ProcessCommand (event);
123 }
124
125 void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
126 {
127 if ( controlpart != kControlNoPart )
128 {
129 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
130 event.SetEventObject(this);
131 ProcessCommand(event);
132 }
133 }
134