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