wxMac completed so far, generic listctrl extension
[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/button.h"
17
18 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
20 #endif
21
22 #include <wx/mac/uma.h>
23 // Button
24
25
26 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
27 const wxPoint& pos,
28 const wxSize& size, long style,
29 const wxValidator& validator,
30 const wxString& name)
31 {
32 Rect bounds ;
33 Str255 title ;
34 m_macHorizontalBorder = 2 ; // additional pixels around the real control
35 m_macVerticalBorder = 2 ;
36
37 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
38
39 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , true , 0 , 0 , 1,
40 kControlPushButtonProc , (long) this ) ;
41 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
42
43 MacPostControlCreate() ;
44
45 return TRUE;
46 }
47
48 void wxButton::SetDefault()
49 {
50 wxWindow *parent = GetParent();
51 wxButton *btnOldDefault = NULL;
52 wxPanel *panel = wxDynamicCast(parent, wxPanel);
53 if ( panel )
54 {
55 btnOldDefault = panel->GetDefaultItem();
56 panel->SetDefaultItem(this);
57 }
58
59 if ( btnOldDefault && btnOldDefault->m_macControl )
60 {
61 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ;
62 }
63 if ( m_macControl )
64 {
65 UMASetControlData( m_macControl , kControlButtonPart , kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ;
66 }
67 }
68
69 wxSize wxButton::DoGetBestSize()
70 {
71 int wBtn = m_label.Length() * 8 + 12 + 2 * m_macHorizontalBorder;
72 int hBtn = 13 + 2 * m_macVerticalBorder;
73
74 return wxSize(wBtn, hBtn);
75 }
76
77 wxSize wxButton::GetDefaultSize()
78 {
79 int wBtn = 15 * 8 + 12 + 2 * 2;
80 int hBtn = 13 + 2 * 2;
81
82 return wxSize(wBtn, hBtn);
83 }
84
85 void wxButton::Command (wxCommandEvent & event)
86 {
87 ProcessCommand (event);
88 }
89
90 void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
91 {
92 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
93 event.SetEventObject(this);
94 ProcessCommand(event);
95 }
96