]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/button.cpp
Fix so sound looping will stop, courtesy of Ryan Norton.
[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 {
5ca0d812 45 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , m_peer->GetControlRefAddr() ) );
eed9e479
SC
46 }
47 else
48 {
49 ControlButtonContentInfo info ;
50 info.contentType = kControlNoContent ;
51 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
5ca0d812 52 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) );
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{
6d325d81
SC
80 wxSize sz = GetDefaultSize() ;
81
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 }
facd6764 98
6d325d81 99 Rect bestsize = { 0 , 0 , 0 , 0 } ;
5ca0d812 100 m_peer->GetBestRect( &bestsize ) ;
0a67a93b 101
23866d59 102 int wBtn;
6d325d81
SC
103 if ( EmptyRect( &bestsize ) )
104 {
23866d59 105 wBtn = m_label.Length() * charspace + 12 ;
6d325d81
SC
106 }
107 else
108 {
5ca0d812 109 wBtn = bestsize.right - bestsize.left ;
6d325d81
SC
110 sz.y = bestsize.bottom - bestsize.top ;
111 }
112
113 if (wBtn > sz.x || ( GetWindowStyle() & wxBU_EXACTFIT) )
114 sz.x = wBtn;
115
116 return sz ;
51abe921
SC
117}
118
7c74e7fe
SC
119wxSize wxButton::GetDefaultSize()
120{
0150a5b8 121 int wBtn = 70 ;
e40298d5 122 int hBtn = 20 ;
facd6764 123
7c74e7fe
SC
124 return wxSize(wBtn, hBtn);
125}
126
519cb848 127void wxButton::Command (wxCommandEvent & event)
e9576ca5 128{
21fd5529 129 m_peer->Flash(kControlButtonPart) ;
519cb848 130 ProcessCommand (event);
e9576ca5
SC
131}
132
4c37f124 133wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
e9576ca5 134{
4c37f124
SC
135 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
136 event.SetEventObject(this);
137 ProcessCommand(event);
138 return noErr ;
e9576ca5
SC
139}
140