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