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