]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
Added const qualifier to char* in struct service_entry
[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() ;
49e3e2c2
SC
43 if ( id == wxID_HELP )
44 {
45 ControlButtonContentInfo info ;
46 info.contentType = kControlContentIconRef ;
47 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
48 verify_noerr ( CreateRoundButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , kControlRoundButtonNormalSize ,
49 &info , m_peer->GetControlRefAddr() ) );
50 }
51 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
eed9e479 52 {
5ca0d812 53 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , m_peer->GetControlRefAddr() ) );
eed9e479
SC
54 }
55 else
56 {
57 ControlButtonContentInfo info ;
58 info.contentType = kControlNoContent ;
59 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
5ca0d812 60 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
eed9e479 61 }
21fd5529
SC
62
63 wxASSERT_MSG( m_peer != NULL && m_peer->Ok() , wxT("No valid mac control") ) ;
e40298d5 64
facd6764 65 MacPostControlCreate(pos,size) ;
e40298d5 66
519cb848 67 return TRUE;
e9576ca5
SC
68}
69
70void wxButton::SetDefault()
71{
e7549107
SC
72 wxWindow *parent = GetParent();
73 wxButton *btnOldDefault = NULL;
eddd3a9d 74 if ( parent )
e7549107 75 {
eddd3a9d 76 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
c1fb8167 77 wxButton);
eddd3a9d 78 parent->SetDefaultItem(this);
e7549107 79 }
03e11df5 80
21fd5529
SC
81 if ( btnOldDefault )
82 btnOldDefault->m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 0 ) ;
83 m_peer->SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) 1 ) ;
e9576ca5
SC
84}
85
37e2cb08 86wxSize wxButton::DoGetBestSize() const
51abe921 87{
49e3e2c2
SC
88 if ( GetId() == wxID_HELP )
89 return wxSize( 20 , 20 ) ;
90
6d325d81
SC
91 wxSize sz = GetDefaultSize() ;
92
93 int charspace = 8 ;
94 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
95 {
96 sz.y = 20 ;
97 charspace = 10 ;
98 }
99 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
100 {
101 sz.y = 17 ;
102 charspace = 8 ;
103 }
104 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
105 {
106 sz.y = 15 ;
107 charspace = 8 ;
108 }
facd6764 109
6d325d81 110 Rect bestsize = { 0 , 0 , 0 , 0 } ;
5ca0d812 111 m_peer->GetBestRect( &bestsize ) ;
0a67a93b 112
23866d59 113 int wBtn;
6d325d81
SC
114 if ( EmptyRect( &bestsize ) )
115 {
23866d59 116 wBtn = m_label.Length() * charspace + 12 ;
6d325d81
SC
117 }
118 else
119 {
5ca0d812 120 wBtn = bestsize.right - bestsize.left ;
6d325d81
SC
121 sz.y = bestsize.bottom - bestsize.top ;
122 }
123
124 if (wBtn > sz.x || ( GetWindowStyle() & wxBU_EXACTFIT) )
125 sz.x = wBtn;
126
127 return sz ;
51abe921
SC
128}
129
7c74e7fe
SC
130wxSize wxButton::GetDefaultSize()
131{
0150a5b8 132 int wBtn = 70 ;
e40298d5 133 int hBtn = 20 ;
facd6764 134
7c74e7fe
SC
135 return wxSize(wBtn, hBtn);
136}
137
519cb848 138void wxButton::Command (wxCommandEvent & event)
e9576ca5 139{
21fd5529 140 m_peer->Flash(kControlButtonPart) ;
519cb848 141 ProcessCommand (event);
e9576ca5
SC
142}
143
4c37f124 144wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
e9576ca5 145{
4c37f124
SC
146 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
147 event.SetEventObject(this);
148 ProcessCommand(event);
149 return noErr ;
e9576ca5
SC
150}
151