]> git.saurik.com Git - wxWidgets.git/blame - src/mac/button.cpp
Use the wxStaticBox::GetBordersForSizer method to get border information
[wxWidgets.git] / src / mac / 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{
e40298d5
JS
37 Rect bounds ;
38 Str255 title ;
0150a5b8
SC
39
40 if ( UMAHasAquaLayout() )
41 {
42 m_macHorizontalBorder = kMacOSXHorizontalBorder;
43 m_macVerticalBorder = kMacOSXVerticalBorder;
44 }
e40298d5
JS
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 ) ;
427ff662 50 wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ;
e40298d5
JS
51
52 MacPostControlCreate() ;
53
519cb848 54 return TRUE;
e9576ca5
SC
55}
56
57void wxButton::SetDefault()
58{
e7549107
SC
59 wxWindow *parent = GetParent();
60 wxButton *btnOldDefault = NULL;
eddd3a9d 61 if ( parent )
e7549107 62 {
eddd3a9d 63 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 64 wxButton);
eddd3a9d 65 parent->SetDefaultItem(this);
e7549107 66 }
03e11df5 67
e40298d5
JS
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 }
e9576ca5
SC
81}
82
37e2cb08 83wxSize wxButton::DoGetBestSize() const
51abe921 84{
0a67a93b
SC
85 wxSize sz = GetDefaultSize() ;
86
0150a5b8 87 int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ;
e40298d5 88
0a67a93b 89 if (wBtn > sz.x) sz.x = wBtn;
0a67a93b
SC
90
91 return sz ;
51abe921
SC
92}
93
7c74e7fe
SC
94wxSize wxButton::GetDefaultSize()
95{
0150a5b8 96 int wBtn = 70 ;
e40298d5 97 int hBtn = 20 ;
0150a5b8
SC
98
99 if ( UMAHasAquaLayout() )
100 {
101 wBtn += 2 * kMacOSXHorizontalBorder ;
102 hBtn += 2 * kMacOSXVerticalBorder ;
103 }
7c74e7fe
SC
104
105 return wxSize(wBtn, hBtn);
106}
107
519cb848 108void wxButton::Command (wxCommandEvent & event)
e9576ca5 109{
eb22f2a6
GD
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 }
519cb848 117 ProcessCommand (event);
e9576ca5
SC
118}
119
eb22f2a6 120void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart )
e9576ca5 121{
eb22f2a6
GD
122 if ( controlpart != kControlNoPart )
123 {
124 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
125 event.SetEventObject(this);
126 ProcessCommand(event);
127 }
e9576ca5
SC
128}
129