]> git.saurik.com Git - wxWidgets.git/blame - src/mac/button.cpp
fix for GetParent() in wxTR_HIDE_ROOT case
[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
d8c736e5
GD
16#include "wx/defs.h"
17
e9576ca5 18#include "wx/button.h"
03e11df5 19#include "wx/panel.h"
e9576ca5 20
2f1ae414 21#if !USE_SHARED_LIBRARY
e9576ca5 22IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
2f1ae414 23#endif
e9576ca5 24
d497dca4 25#include "wx/mac/uma.h"
e9576ca5
SC
26// Button
27
519cb848 28
e9576ca5
SC
29bool 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{
519cb848
SC
35 Rect bounds ;
36 Str255 title ;
519cb848
SC
37
38 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
39
76a5e5d2 40 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
519cb848 41 kControlPushButtonProc , (long) this ) ;
76a5e5d2 42 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ;
519cb848
SC
43
44 MacPostControlCreate() ;
45
46 return TRUE;
e9576ca5
SC
47}
48
49void wxButton::SetDefault()
50{
e7549107
SC
51 wxWindow *parent = GetParent();
52 wxButton *btnOldDefault = NULL;
eddd3a9d 53 if ( parent )
e7549107 54 {
eddd3a9d 55 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 56 wxButton);
eddd3a9d 57 parent->SetDefaultItem(this);
e7549107 58 }
03e11df5 59
03e11df5
GD
60 Boolean inData;
61 if ( btnOldDefault && btnOldDefault->m_macControl )
62 {
63 inData = 0;
76a5e5d2 64 ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart ,
03e11df5
GD
65 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
66 }
76a5e5d2 67 if ( (ControlHandle) m_macControl )
03e11df5
GD
68 {
69 inData = 1;
76a5e5d2 70 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart ,
03e11df5
GD
71 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
72 }
e9576ca5
SC
73}
74
37e2cb08 75wxSize wxButton::DoGetBestSize() const
51abe921 76{
0a67a93b
SC
77 wxSize sz = GetDefaultSize() ;
78
2f1ae414
SC
79 int wBtn = m_label.Length() * 8 + 12 ;
80 int hBtn = 20 ;
81
0a67a93b
SC
82 if (wBtn > sz.x) sz.x = wBtn;
83 if (hBtn > sz.y) sz.y = hBtn;
84
85 return sz ;
51abe921
SC
86}
87
7c74e7fe
SC
88wxSize wxButton::GetDefaultSize()
89{
0a67a93b 90 int wBtn = 70 /* + 2 * m_macHorizontalBorder */ ;
2f1ae414 91 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
7c74e7fe
SC
92
93 return wxSize(wBtn, hBtn);
94}
95
519cb848 96void wxButton::Command (wxCommandEvent & event)
e9576ca5 97{
76a5e5d2 98 if ( (ControlHandle) m_macControl )
2f1ae414 99 {
76a5e5d2 100 HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ;
2f1ae414
SC
101 unsigned long finalTicks ;
102 Delay( 8 , &finalTicks ) ;
76a5e5d2 103 HiliteControl( (ControlHandle) m_macControl , 0 ) ;
2f1ae414 104 }
519cb848 105 ProcessCommand (event);
e9576ca5
SC
106}
107
76a5e5d2 108void wxButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart )
e9576ca5 109{
461a37f5
SC
110 if ( controlpart != kControlNoPart )
111 {
519cb848
SC
112 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
113 event.SetEventObject(this);
114 ProcessCommand(event);
461a37f5 115 }
e9576ca5
SC
116}
117