]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
SetParam should be explicit
[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
65571936 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
28bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
29 const wxPoint& pos,
30 const wxSize& size, long style,
31 const wxValidator& validator,
32 const wxString& name)
33{
facd6764
SC
34 m_macIsUserPane = FALSE ;
35
b45ed7a2
VZ
36 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
e40298d5 38
facd6764 39 m_label = label ;
e40298d5 40
facd6764 41 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
21fd5529 42 m_peer = new wxMacControl() ;
eed9e479
SC
43 if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
44 {
21fd5529 45 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , *m_peer ) );
eed9e479
SC
46 }
47 else
48 {
49 ControlButtonContentInfo info ;
50 info.contentType = kControlNoContent ;
51 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
21fd5529 52 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , *m_peer ) );
eed9e479 53 }
21fd5529
SC
54
55 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
e40298d5 56
facd6764 57 MacPostControlCreate(pos,size) ;
e40298d5 58
519cb848 59 return TRUE;
e9576ca5
SC
60}
61
62void wxButton::SetDefault()
63{
e7549107
SC
64 wxWindow *parent = GetParent();
65 wxButton *btnOldDefault = NULL;
eddd3a9d 66 if ( parent )
e7549107 67 {
eddd3a9d 68 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 69 wxButton);
eddd3a9d 70 parent->SetDefaultItem(this);
e7549107 71 }
03e11df5 72
21fd5529
SC
73 if ( btnOldDefault )
74 btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ;
75 m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ;
e9576ca5
SC
76}
77
37e2cb08 78wxSize wxButton::DoGetBestSize() const
51abe921 79{
0a67a93b
SC
80 wxSize sz = GetDefaultSize() ;
81
facd6764
SC
82 int charspace = 8 ;
83 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
84 {
85 sz.y = 20 ;
86 charspace = 10 ;
87 }
88 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
89 {
90 sz.y = 17 ;
91 charspace = 8 ;
92 }
93 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
94 {
95 sz.y = 15 ;
96 charspace = 8 ;
97 }
98
99 int wBtn = m_label.Length() * charspace + 12 ;
100
0a67a93b 101 if (wBtn > sz.x) sz.x = wBtn;
0a67a93b
SC
102
103 return sz ;
51abe921
SC
104}
105
7c74e7fe
SC
106wxSize wxButton::GetDefaultSize()
107{
0150a5b8 108 int wBtn = 70 ;
e40298d5 109 int hBtn = 20 ;
facd6764 110
7c74e7fe
SC
111 return wxSize(wBtn, hBtn);
112}
113
519cb848 114void wxButton::Command (wxCommandEvent & event)
e9576ca5 115{
21fd5529 116 m_peer->Flash(kControlButtonPart) ;
519cb848 117 ProcessCommand (event);
e9576ca5
SC
118}
119
4c37f124 120wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
e9576ca5 121{
4c37f124
SC
122 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
123 event.SetEventObject(this);
124 ProcessCommand(event);
125 return noErr ;
e9576ca5
SC
126}
127