]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/button.cpp
support for raw ctrl shortcut
[wxWidgets.git] / src / osx / carbon / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/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 #include "wx/wxprec.h"
13
14 #include "wx/button.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/panel.h"
18 #include "wx/toplevel.h"
19 #include "wx/dcclient.h"
20 #endif
21
22 #include "wx/stockitem.h"
23
24 #include "wx/osx/private.h"
25
26 //
27 //
28 //
29
30 wxWidgetImplType* wxWidgetImpl::CreateButton( wxWindowMac* wxpeer,
31 wxWindowMac* parent,
32 wxWindowID id,
33 const wxString& label,
34 const wxPoint& pos,
35 const wxSize& size,
36 long WXUNUSED(style),
37 long WXUNUSED(extraStyle))
38 {
39 OSStatus err;
40 Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
41 wxMacControl* peer = new wxMacControl(wxpeer) ;
42 if ( id == wxID_HELP )
43 {
44 ControlButtonContentInfo info ;
45 info.contentType = kControlContentIconRef ;
46 GetIconRef(kOnSystemDisk, kSystemIconsCreator, kHelpIcon, &info.u.iconRef);
47 err = CreateRoundButtonControl(
48 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
49 &bounds, kControlRoundButtonNormalSize,
50 &info, peer->GetControlRefAddr() );
51 }
52 else if ( label.Find('\n' ) == wxNOT_FOUND && label.Find('\r' ) == wxNOT_FOUND)
53 {
54 // Button height is static in Mac, can't be changed, so we need to force it here
55 int maxHeight;
56 switch (wxpeer->GetWindowVariant() )
57 {
58 default:
59 wxFAIL_MSG( "unknown window variant" );
60 // fall through
61
62 case wxWINDOW_VARIANT_NORMAL:
63 case wxWINDOW_VARIANT_LARGE:
64 maxHeight = 20 ;
65 break;
66 case wxWINDOW_VARIANT_SMALL:
67 maxHeight = 17;
68 break;
69 case wxWINDOW_VARIANT_MINI:
70 maxHeight = 15;
71 }
72 bounds.bottom = bounds.top + maxHeight ;
73 wxpeer->SetMaxSize( wxSize( wxpeer->GetMaxWidth() , maxHeight ));
74 err = CreatePushButtonControl(
75 MAC_WXHWND(parent->MacGetTopLevelWindowRef()),
76 &bounds, CFSTR(""), peer->GetControlRefAddr() );
77 }
78 else
79 {
80 ControlButtonContentInfo info ;
81 info.contentType = kControlNoContent ;
82 err = CreateBevelButtonControl(
83 MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds, CFSTR(""),
84 kControlBevelButtonLargeBevel, kControlBehaviorPushbutton,
85 &info, 0, 0, 0, peer->GetControlRefAddr() );
86 }
87 verify_noerr( err );
88 return peer;
89 }
90
91 void wxMacControl::SetDefaultButton( bool isDefault )
92 {
93 SetData(kControlButtonPart , kControlPushButtonDefaultTag , (Boolean) isDefault ) ;
94 }
95
96 wxWidgetImplType* wxWidgetImpl::CreateDisclosureTriangle( wxWindowMac* wxpeer,
97 wxWindowMac* parent,
98 wxWindowID WXUNUSED(id),
99 const wxString& label,
100 const wxPoint& pos,
101 const wxSize& size,
102 long WXUNUSED(style),
103 long WXUNUSED(extraStyle))
104 {
105 Rect bounds = wxMacGetBoundsForControl( wxpeer , pos , size ) ;
106 wxMacControl* peer = new wxMacControl(wxpeer) ;
107
108 OSStatus err = CreateDisclosureTriangleControl(
109 MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds,
110 kControlDisclosureTrianglePointDefault,
111 wxCFStringRef( label ),
112 0, // closed
113 TRUE, // draw title
114 TRUE, // auto toggle back and forth
115 peer->GetControlRefAddr() );
116
117 verify_noerr( err );
118 return peer;
119 }
120
121