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