]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: button.cpp | |
3 | // Purpose: wxButton | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e40298d5 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "button.h" | |
14 | #endif | |
15 | ||
d8c736e5 GD |
16 | #include "wx/defs.h" |
17 | ||
e9576ca5 | 18 | #include "wx/button.h" |
03e11df5 | 19 | #include "wx/panel.h" |
e9576ca5 | 20 | |
2f1ae414 | 21 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 22 | IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) |
2f1ae414 | 23 | #endif |
e9576ca5 | 24 | |
d497dca4 | 25 | #include "wx/mac/uma.h" |
e9576ca5 SC |
26 | // Button |
27 | ||
5ea02ed5 DS |
28 | static const int kMacOSXHorizontalBorder = 2 ; |
29 | static const int kMacOSXVerticalBorder = 4 ; | |
519cb848 | 30 | |
1169a919 JS |
31 | wxButtonBase::wxButtonBase() |
32 | { | |
33 | } | |
34 | ||
e9576ca5 SC |
35 | bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, |
36 | const wxPoint& pos, | |
37 | const wxSize& size, long style, | |
38 | const wxValidator& validator, | |
39 | const wxString& name) | |
40 | { | |
b45ed7a2 VZ |
41 | if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) ) |
42 | return false; | |
43 | ||
e40298d5 JS |
44 | Rect bounds ; |
45 | Str255 title ; | |
0150a5b8 SC |
46 | |
47 | if ( UMAHasAquaLayout() ) | |
48 | { | |
49 | m_macHorizontalBorder = kMacOSXHorizontalBorder; | |
50 | m_macVerticalBorder = kMacOSXVerticalBorder; | |
51 | } | |
e40298d5 JS |
52 | |
53 | MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; | |
54 | ||
55 | m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, | |
56 | kControlPushButtonProc , (long) this ) ; | |
427ff662 | 57 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; |
e40298d5 JS |
58 | |
59 | MacPostControlCreate() ; | |
60 | ||
519cb848 | 61 | return TRUE; |
e9576ca5 SC |
62 | } |
63 | ||
64 | void wxButton::SetDefault() | |
65 | { | |
e7549107 SC |
66 | wxWindow *parent = GetParent(); |
67 | wxButton *btnOldDefault = NULL; | |
eddd3a9d | 68 | if ( parent ) |
e7549107 | 69 | { |
eddd3a9d | 70 | btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), |
c1fb8167 | 71 | wxButton); |
eddd3a9d | 72 | parent->SetDefaultItem(this); |
e7549107 | 73 | } |
03e11df5 | 74 | |
e40298d5 JS |
75 | Boolean inData; |
76 | if ( btnOldDefault && btnOldDefault->m_macControl ) | |
77 | { | |
78 | inData = 0; | |
79 | ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart , | |
80 | kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; | |
81 | } | |
82 | if ( (ControlHandle) m_macControl ) | |
83 | { | |
84 | inData = 1; | |
85 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , | |
86 | kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; | |
87 | } | |
e9576ca5 SC |
88 | } |
89 | ||
37e2cb08 | 90 | wxSize wxButton::DoGetBestSize() const |
51abe921 | 91 | { |
0a67a93b SC |
92 | wxSize sz = GetDefaultSize() ; |
93 | ||
0150a5b8 | 94 | int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ; |
e40298d5 | 95 | |
0a67a93b | 96 | if (wBtn > sz.x) sz.x = wBtn; |
0a67a93b SC |
97 | |
98 | return sz ; | |
51abe921 SC |
99 | } |
100 | ||
7c74e7fe SC |
101 | wxSize wxButton::GetDefaultSize() |
102 | { | |
0150a5b8 | 103 | int wBtn = 70 ; |
e40298d5 | 104 | int hBtn = 20 ; |
0150a5b8 SC |
105 | |
106 | if ( UMAHasAquaLayout() ) | |
107 | { | |
108 | wBtn += 2 * kMacOSXHorizontalBorder ; | |
109 | hBtn += 2 * kMacOSXVerticalBorder ; | |
110 | } | |
7c74e7fe SC |
111 | |
112 | return wxSize(wBtn, hBtn); | |
113 | } | |
114 | ||
519cb848 | 115 | void wxButton::Command (wxCommandEvent & event) |
e9576ca5 | 116 | { |
eb22f2a6 GD |
117 | if ( (ControlHandle) m_macControl ) |
118 | { | |
119 | HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ; | |
120 | unsigned long finalTicks ; | |
121 | Delay( 8 , &finalTicks ) ; | |
122 | HiliteControl( (ControlHandle) m_macControl , 0 ) ; | |
123 | } | |
519cb848 | 124 | ProcessCommand (event); |
e9576ca5 SC |
125 | } |
126 | ||
4b26b60f | 127 | void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) ) |
e9576ca5 | 128 | { |
eb22f2a6 GD |
129 | if ( controlpart != kControlNoPart ) |
130 | { | |
131 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId ); | |
132 | event.SetEventObject(this); | |
133 | ProcessCommand(event); | |
134 | } | |
e9576ca5 SC |
135 | } |
136 |