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