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