]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/classic/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 | #ifdef __BORLANDC__ | |
15 | #pragma hdrstop | |
16 | #endif | |
17 | ||
18 | #include "wx/button.h" | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/panel.h" | |
22 | #endif | |
23 | ||
24 | #include "wx/stockitem.h" | |
25 | ||
26 | IMPLEMENT_DYNAMIC_CLASS(wxButton, wxControl) | |
27 | ||
28 | #include "wx/mac/uma.h" | |
29 | // Button | |
30 | ||
31 | static const int kMacOSXHorizontalBorder = 2 ; | |
32 | static const int kMacOSXVerticalBorder = 4 ; | |
33 | ||
34 | bool wxButton::Create(wxWindow *parent, wxWindowID id, const wxString& lbl, | |
35 | const wxPoint& pos, | |
36 | const wxSize& size, long style, | |
37 | const wxValidator& validator, | |
38 | const wxString& name) | |
39 | { | |
40 | wxString label(lbl); | |
41 | if (label.empty() && wxIsStockID(id)) | |
42 | label = wxGetStockLabel(id); | |
43 | ||
44 | if ( !wxButtonBase::Create(parent, id, pos, size, style, validator, name) ) | |
45 | return false; | |
46 | ||
47 | Rect bounds ; | |
48 | Str255 title ; | |
49 | ||
50 | if ( UMAHasAquaLayout() ) | |
51 | { | |
52 | m_macHorizontalBorder = kMacOSXHorizontalBorder; | |
53 | m_macVerticalBorder = kMacOSXVerticalBorder; | |
54 | } | |
55 | ||
56 | MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ; | |
57 | ||
58 | m_macControl = (WXWidget) ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1, | |
59 | kControlPushButtonProc , (long) this ) ; | |
60 | wxASSERT_MSG( (ControlHandle) m_macControl != NULL , wxT("No valid mac control") ) ; | |
61 | ||
62 | MacPostControlCreate() ; | |
63 | ||
64 | return true; | |
65 | } | |
66 | ||
67 | void wxButton::SetDefault() | |
68 | { | |
69 | wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); | |
70 | wxButton *btnOldDefault = NULL; | |
71 | if ( tlw ) | |
72 | { | |
73 | btnOldDefault = wxDynamicCast(tlw->GetDefaultItem(), wxButton); | |
74 | tlw->SetDefaultItem(this); | |
75 | } | |
76 | ||
77 | Boolean inData; | |
78 | if ( btnOldDefault && btnOldDefault->m_macControl ) | |
79 | { | |
80 | inData = 0; | |
81 | ::SetControlData( (ControlHandle) btnOldDefault->m_macControl , kControlButtonPart , | |
82 | kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; | |
83 | } | |
84 | if ( (ControlHandle) m_macControl ) | |
85 | { | |
86 | inData = 1; | |
87 | ::SetControlData( (ControlHandle) m_macControl , kControlButtonPart , | |
88 | kControlPushButtonDefaultTag , sizeof( Boolean ) , (char*)(&inData) ) ; | |
89 | } | |
90 | } | |
91 | ||
92 | wxSize wxButton::DoGetBestSize() const | |
93 | { | |
94 | wxSize sz = GetDefaultSize() ; | |
95 | ||
96 | int wBtn = m_label.length() * 8 + 12 + 2 * kMacOSXHorizontalBorder ; | |
97 | ||
98 | if (wBtn > sz.x) sz.x = wBtn; | |
99 | ||
100 | return sz ; | |
101 | } | |
102 | ||
103 | wxSize wxButton::GetDefaultSize() | |
104 | { | |
105 | int wBtn = 70 ; | |
106 | int hBtn = 20 ; | |
107 | ||
108 | if ( UMAHasAquaLayout() ) | |
109 | { | |
110 | wBtn += 2 * kMacOSXHorizontalBorder ; | |
111 | hBtn += 2 * kMacOSXVerticalBorder ; | |
112 | } | |
113 | ||
114 | return wxSize(wBtn, hBtn); | |
115 | } | |
116 | ||
117 | void wxButton::Command (wxCommandEvent & event) | |
118 | { | |
119 | if ( (ControlHandle) m_macControl ) | |
120 | { | |
121 | HiliteControl( (ControlHandle) m_macControl , kControlButtonPart ) ; | |
122 | unsigned long finalTicks ; | |
123 | Delay( 8 , &finalTicks ) ; | |
124 | HiliteControl( (ControlHandle) m_macControl , 0 ) ; | |
125 | } | |
126 | ProcessCommand (event); | |
127 | } | |
128 | ||
129 | void wxButton::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 controlpart , bool WXUNUSED(mouseStillDown) ) | |
130 | { | |
131 | if ( controlpart != kControlNoPart ) | |
132 | { | |
133 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, m_windowId ); | |
134 | event.SetEventObject(this); | |
135 | ProcessCommand(event); | |
136 | } | |
137 | } |