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