]> git.saurik.com Git - wxWidgets.git/blob - src/mac/button.cpp
added common regex
[wxWidgets.git] / src / mac / button.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: button.cpp
3 // Purpose: wxButton
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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
22 IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl)
23 #endif
24
25 #include <wx/mac/uma.h>
26 // Button
27
28
29 bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label,
30 const wxPoint& pos,
31 const wxSize& size, long style,
32 const wxValidator& validator,
33 const wxString& name)
34 {
35 Rect bounds ;
36 Str255 title ;
37
38 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
39
40 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 1,
41 kControlPushButtonProc , (long) this ) ;
42 wxASSERT_MSG( m_macControl != NULL , "No valid mac control" ) ;
43
44 MacPostControlCreate() ;
45
46 return TRUE;
47 }
48
49 void wxButton::SetDefault()
50 {
51 wxWindow *parent = GetParent();
52 wxButton *btnOldDefault = NULL;
53 wxPanel *panel = wxDynamicCast(parent, wxPanel);
54 if ( panel )
55 {
56 btnOldDefault = panel->GetDefaultItem();
57 panel->SetDefaultItem(this);
58 }
59
60 #ifdef __UNIX__
61 Boolean inData;
62 if ( btnOldDefault && btnOldDefault->m_macControl )
63 {
64 inData = 0;
65 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
66 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
67 }
68 if ( m_macControl )
69 {
70 inData = 1;
71 UMASetControlData( m_macControl , kControlButtonPart ,
72 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ;
73 }
74 #else
75 if ( btnOldDefault && btnOldDefault->m_macControl )
76 {
77 UMASetControlData( btnOldDefault->m_macControl , kControlButtonPart ,
78 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)0) ) ;
79 }
80 if ( m_macControl )
81 {
82 UMASetControlData( m_macControl , kControlButtonPart ,
83 kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)((Boolean)1) ) ;
84 }
85 #endif
86 }
87
88 wxSize wxButton::DoGetBestSize() const
89 {
90 wxSize sz = GetDefaultSize() ;
91
92 int wBtn = m_label.Length() * 8 + 12 ;
93 int hBtn = 20 ;
94
95 if (wBtn > sz.x) sz.x = wBtn;
96 if (hBtn > sz.y) sz.y = hBtn;
97
98 return sz ;
99 }
100
101 wxSize wxButton::GetDefaultSize()
102 {
103 int wBtn = 70 /* + 2 * m_macHorizontalBorder */ ;
104 int hBtn = 20 /* + 2 * m_macVerticalBorder */ ;
105
106 return wxSize(wBtn, hBtn);
107 }
108
109 void wxButton::Command (wxCommandEvent & event)
110 {
111 if ( m_macControl )
112 {
113 HiliteControl( m_macControl , kControlButtonPart ) ;
114 unsigned long finalTicks ;
115 Delay( 8 , &finalTicks ) ;
116 HiliteControl( m_macControl , 0 ) ;
117 }
118 ProcessCommand (event);
119 }
120
121 void wxButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
122 {
123 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId );
124 event.SetEventObject(this);
125 ProcessCommand(event);
126 }
127