]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/button.cpp
allowing shaped windows again
[wxWidgets.git] / src / mac / carbon / button.cpp
... / ...
CommitLineData
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
9// Licence: wxWindows licence
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"
20
21#if !USE_SHARED_LIBRARY
22IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
23#endif
24
25#include "wx/mac/uma.h"
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{
34 m_macIsUserPane = FALSE ;
35
36 if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) )
37 return false;
38
39 m_label = label ;
40
41 Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ;
42 if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
43 {
44 verify_noerr ( CreatePushButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , (ControlRef*) &m_macControl ) ) ;
45 }
46 else
47 {
48 ControlButtonContentInfo info ;
49 info.contentType = kControlNoContent ;
50 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
51 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ;
52 }
53 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
54
55 MacPostControlCreate(pos,size) ;
56
57 return TRUE;
58}
59
60void wxButton::SetDefault()
61{
62 wxWindow *parent = GetParent();
63 wxButton *btnOldDefault = NULL;
64 if ( parent )
65 {
66 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
67 wxButton);
68 parent->SetDefaultItem(this);
69 }
70
71 Boolean inData;
72 if ( btnOldDefault && btnOldDefault->m_macControl )
73 {
74 inData = 0;
75 ::SetControlData( (ControlRef) btnOldDefault->m_macControl , kControlButtonPart ,
76 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
77 }
78 if ( (ControlRef) m_macControl )
79 {
80 inData = 1;
81 ::SetControlData( (ControlRef) m_macControl , kControlButtonPart ,
82 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
83 }
84}
85
86wxSize wxButton::DoGetBestSize() const
87{
88 wxSize sz = GetDefaultSize() ;
89
90 int charspace = 8 ;
91 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
92 {
93 sz.y = 20 ;
94 charspace = 10 ;
95 }
96 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
97 {
98 sz.y = 17 ;
99 charspace = 8 ;
100 }
101 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
102 {
103 sz.y = 15 ;
104 charspace = 8 ;
105 }
106
107 int wBtn = m_label.Length() * charspace + 12 ;
108
109 if (wBtn > sz.x) sz.x = wBtn;
110
111 return sz ;
112}
113
114wxSize wxButton::GetDefaultSize()
115{
116 int wBtn = 70 ;
117 int hBtn = 20 ;
118
119 return wxSize(wBtn, hBtn);
120}
121
122void wxButton::Command (wxCommandEvent & event)
123{
124 if ( (ControlRef) m_macControl )
125 {
126 HiliteControl( (ControlRef) m_macControl , kControlButtonPart ) ;
127 unsigned long finalTicks ;
128 Delay( 8 , &finalTicks ) ;
129 HiliteControl( (ControlRef) m_macControl , 0 ) ;
130 }
131 ProcessCommand (event);
132}
133
134wxInt32 wxButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) )
135{
136 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
137 event.SetEventObject(this);
138 ProcessCommand(event);
139 return noErr ;
140}
141