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