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