]> git.saurik.com Git - wxWidgets.git/blame - src/mac/button.cpp
give frame a reasonable default size if none specified
[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
2f1ae414 18#if !USE_SHARED_LIBRARY
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
2f1ae414 20#endif
e9576ca5 21
519cb848 22#include <wx/mac/uma.h>
e9576ca5
SC
23// Button
24
519cb848 25
e9576ca5
SC
26bool 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{
519cb848
SC
32 Rect bounds ;
33 Str255 title ;
519cb848
SC
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 68{
2f1ae414
SC
69 int wBtn = m_label.Length() * 8 + 12 ;
70 int hBtn = 20 ;
71
72 if ( wBtn < 80 )
73 wBtn = 80 ;
51abe921
SC
74
75 return wxSize(wBtn, hBtn);
76}
77
7c74e7fe
SC
78wxSize wxButton::GetDefaultSize()
79{
2f1ae414
SC
80 int wBtn = 80 /* + 2 * m_macHorizontalBorder */ ;
81 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
7c74e7fe
SC
82
83 return wxSize(wBtn, hBtn);
84}
85
519cb848 86void wxButton::Command (wxCommandEvent & event)
e9576ca5 87{
2f1ae414
SC
88 if ( m_macControl )
89 {
90 HiliteControl( m_macControl , kControlButtonPart ) ;
91 unsigned long finalTicks ;
92 Delay( 8 , &finalTicks ) ;
93 HiliteControl( m_macControl , 0 ) ;
94 }
519cb848 95 ProcessCommand (event);
e9576ca5
SC
96}
97
519cb848 98void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
e9576ca5 99{
519cb848
SC
100 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
101 event.SetEventObject(this);
102 ProcessCommand(event);
e9576ca5
SC
103}
104