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