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