]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
made Update be window local (before was updating the entire window), ScrollWindow...
[wxWidgets.git] / src / mac / carbon / button.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: button.cpp
3// Purpose: wxButton
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
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
0150a5b8
SC
28static const int kMacOSXHorizontalBorder = 1 ;
29static const int kMacOSXVerticalBorder = 1 ;
519cb848 30
e9576ca5
SC
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{
b45ed7a2
VZ
37 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
38 return false;
39
e40298d5
JS
40 Rect bounds ;
41 Str255 title ;
0150a5b8
SC
42
43 if ( UMAHasAquaLayout() )
44 {
45 m_macHorizontalBorder = kMacOSXHorizontalBorder;
46 m_macVerticalBorder = kMacOSXVerticalBorder;
47 }
e40298d5
JS
48
49 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
50
51 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
52 kControlPushButtonProc , (long) this ) ;
427ff662 53 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5
JS
54
55 MacPostControlCreate() ;
56
519cb848 57 return TRUE;
e9576ca5
SC
58}
59
60void wxButton::SetDefault()
61{
e7549107
SC
62 wxWindow *parent = GetParent();
63 wxButton *btnOldDefault = NULL;
eddd3a9d 64 if ( parent )
e7549107 65 {
eddd3a9d 66 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 67 wxButton);
eddd3a9d 68 parent->SetDefaultItem(this);
e7549107 69 }
03e11df5 70
e40298d5
JS
71 Boolean inData;
72 if ( btnOldDefault && btnOldDefault->m_macControl )
73 {
74 inData = 0;
75 ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart ,
76 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
77 }
78 if ( (ControlHandle) m_macControl )
79 {
80 inData = 1;
81 ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart ,
82 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
83 }
e9576ca5
SC
84}
85
37e2cb08 86wxSize wxButton::DoGetBestSize() const
51abe921 87{
0a67a93b
SC
88 wxSize sz = GetDefaultSize() ;
89
0150a5b8 90 int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ;
e40298d5 91
0a67a93b 92 if (wBtn > sz.x) sz.x = wBtn;
0a67a93b
SC
93
94 return sz ;
51abe921
SC
95}
96
7c74e7fe
SC
97wxSize wxButton::GetDefaultSize()
98{
0150a5b8 99 int wBtn = 70 ;
e40298d5 100 int hBtn = 20 ;
0150a5b8
SC
101
102 if ( UMAHasAquaLayout() )
103 {
104 wBtn += 2 * kMacOSXHorizontalBorder ;
105 hBtn += 2 * kMacOSXVerticalBorder ;
106 }
7c74e7fe
SC
107
108 return wxSize(wBtn, hBtn);
109}
110
519cb848 111void wxButton::Command (wxCommandEvent & event)
e9576ca5 112{
eb22f2a6
GD
113 if ( (ControlHandle) m_macControl )
114 {
115 HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ;
116 unsigned long finalTicks ;
117 Delay( 8 , &finalTicks ) ;
118 HiliteControl( (ControlHandle) m_macControl , 0 ) ;
119 }
519cb848 120 ProcessCommand (event);
e9576ca5
SC
121}
122
4b26b60f 123void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
e9576ca5 124{
eb22f2a6
GD
125 if ( controlpart != kControlNoPart )
126 {
127 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
128 event.SetEventObject(this);
129 ProcessCommand(event);
130 }
e9576ca5
SC
131}
132