]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/button.cpp
fixed multiline wrap-around
[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 m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , "\p" , true , 0 , 0 , 1,
45 kControlPushButtonProc , (long) this ) ;
46 }
47 else
48 {
49 ControlButtonContentInfo info ;
50 info.contentType = kControlNoContent ;
51 verify_noerr(CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,CFSTR(""),
52 kControlBevelButtonLargeBevel , kControlBehaviorPushbutton , &info , 0 , 0 , 0 , (ControlRef*) &m_macControl ) ) ;
53 }
54 wxASSERT_MSG( (ControlRef) m_macControl != NULL , wxT("No valid mac control") ) ;
55
56 MacPostControlCreate(pos,size) ;
57
58 return TRUE;
59}
60
61void wxButton::SetDefault()
62{
63 wxWindow *parent = GetParent();
64 wxButton *btnOldDefault = NULL;
65 if ( parent )
66 {
67 btnOldDefault = wxDynamicCast(parent->GetDefaultItem(),
68 wxButton);
69 parent->SetDefaultItem(this);
70 }
71
72 Boolean inData;
73 if ( btnOldDefault && btnOldDefault->m_macControl )
74 {
75 inData = 0;
76 ::SetControlData( (ControlRef) btnOldDefault->m_macControl , kControlButtonPart ,
77 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
78 }
79 if ( (ControlRef) m_macControl )
80 {
81 inData = 1;
82 ::SetControlData( (ControlRef) m_macControl , kControlButtonPart ,
83 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
84 }
85}
86
87wxSize wxButton::DoGetBestSize() const
88{
89 wxSize sz = GetDefaultSize() ;
90
91 int charspace = 8 ;
92 if ( GetWindowVariant() == wxWINDOW_VARIANT_NORMAL || GetWindowVariant() == wxWINDOW_VARIANT_LARGE )
93 {
94 sz.y = 20 ;
95 charspace = 10 ;
96 }
97 else if ( GetWindowVariant() == wxWINDOW_VARIANT_SMALL )
98 {
99 sz.y = 17 ;
100 charspace = 8 ;
101 }
102 else if ( GetWindowVariant() == wxWINDOW_VARIANT_MINI )
103 {
104 sz.y = 15 ;
105 charspace = 8 ;
106 }
107
108 int wBtn = m_label.Length() * charspace + 12 ;
109
110 if (wBtn > sz.x) sz.x = wBtn;
111
112 return sz ;
113}
114
115wxSize wxButton::GetDefaultSize()
116{
117 int wBtn = 70 ;
118 int hBtn = 20 ;
119
120 return wxSize(wBtn, hBtn);
121}
122
123void wxButton::Command (wxCommandEvent & event)
124{
125 if ( (ControlRef) m_macControl )
126 {
127 HiliteControl( (ControlRef) m_macControl , kControlButtonPart ) ;
128 unsigned long finalTicks ;
129 Delay( 8 , &finalTicks ) ;
130 HiliteControl( (ControlRef) m_macControl , 0 ) ;
131 }
132 ProcessCommand (event);
133}
134
135void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) )
136{
137 if ( controlpart != kControlNoPart )
138 {
139 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
140 event.SetEventObject(this);
141 ProcessCommand(event);
142 }
143}
144