]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
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 | ||
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 | ||
0150a5b8 SC |
28 | static const int kMacOSXHorizontalBorder = 1 ; |
29 | static const int kMacOSXVerticalBorder = 1 ; | |
519cb848 | 30 | |
e9576ca5 SC |
31 | bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& label, |
32 | const wxPoint& pos, | |
33 | const wxSize& size, long style, | |
34 | const wxValidator& validator, | |
35 | const wxString& name) | |
36 | { | |
519cb848 SC |
37 | Rect bounds ; |
38 | Str255 title ; | |
0150a5b8 SC |
39 | |
40 | if ( UMAHasAquaLayout() ) | |
41 | { | |
42 | m_macHorizontalBorder = kMacOSXHorizontalBorder; | |
43 | m_macVerticalBorder = kMacOSXVerticalBorder; | |
44 | } | |
519cb848 SC |
45 | |
46 | MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; | |
47 | ||
76a5e5d2 | 48 | m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, |
519cb848 | 49 | kControlPushButtonProc , (long) this ) ; |
76a5e5d2 | 50 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , "No valid mac control" ) ; |
519cb848 SC |
51 | |
52 | MacPostControlCreate() ; | |
0150a5b8 | 53 | |
519cb848 | 54 | return TRUE; |
e9576ca5 SC |
55 | } |
56 | ||
57 | void wxButton::SetDefault() | |
58 | { | |
e7549107 SC |
59 | wxWindow *parent = GetParent(); |
60 | wxButton *btnOldDefault = NULL; | |
eddd3a9d | 61 | if ( parent ) |
e7549107 | 62 | { |
eddd3a9d | 63 | btnOldDefault = wxDynamicCast(parent->GetDefaultItem(), |
c1fb8167 | 64 | wxButton); |
eddd3a9d | 65 | parent->SetDefaultItem(this); |
e7549107 | 66 | } |
03e11df5 | 67 | |
03e11df5 GD |
68 | Boolean inData; |
69 | if ( btnOldDefault && btnOldDefault->m_macControl ) | |
70 | { | |
71 | inData = 0; | |
76a5e5d2 | 72 | ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart , |
03e11df5 GD |
73 | kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; |
74 | } | |
76a5e5d2 | 75 | if ( (ControlHandle) m_macControl ) |
03e11df5 GD |
76 | { |
77 | inData = 1; | |
76a5e5d2 | 78 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , |
03e11df5 GD |
79 | kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; |
80 | } | |
e9576ca5 SC |
81 | } |
82 | ||
37e2cb08 | 83 | wxSize wxButton::DoGetBestSize() const |
51abe921 | 84 | { |
0a67a93b SC |
85 | wxSize sz = GetDefaultSize() ; |
86 | ||
0150a5b8 | 87 | int wBtn = m_label.Length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ; |
2f1ae414 | 88 | |
0a67a93b | 89 | if (wBtn > sz.x) sz.x = wBtn; |
0a67a93b SC |
90 | |
91 | return sz ; | |
51abe921 SC |
92 | } |
93 | ||
7c74e7fe SC |
94 | wxSize wxButton::GetDefaultSize() |
95 | { | |
0150a5b8 SC |
96 | int wBtn = 70 ; |
97 | int hBtn = 20 ; | |
98 | ||
99 | if ( UMAHasAquaLayout() ) | |
100 | { | |
101 | wBtn += 2 * kMacOSXHorizontalBorder ; | |
102 | hBtn += 2 * kMacOSXVerticalBorder ; | |
103 | } | |
7c74e7fe SC |
104 | |
105 | return wxSize(wBtn, hBtn); | |
106 | } | |
107 | ||
519cb848 | 108 | void wxButton::Command (wxCommandEvent & event) |
e9576ca5 | 109 | { |
eb22f2a6 GD |
110 | if ( (ControlHandle) m_macControl ) |
111 | { | |
112 | HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ; | |
113 | unsigned long finalTicks ; | |
114 | Delay( 8 , &finalTicks ) ; | |
115 | HiliteControl( (ControlHandle) m_macControl , 0 ) ; | |
116 | } | |
519cb848 | 117 | ProcessCommand (event); |
e9576ca5 SC |
118 | } |
119 | ||
eb22f2a6 | 120 | void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart ) |
e9576ca5 | 121 | { |
eb22f2a6 GD |
122 | if ( controlpart != kControlNoPart ) |
123 | { | |
124 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId ); | |
125 | event.SetEventObject(this); | |
126 | ProcessCommand(event); | |
127 | } | |
e9576ca5 SC |
128 | } |
129 |