]>
Commit | Line | Data |
---|---|---|
eabe6af8 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/mac/tglbtn.cpp | |
3 | // Purpose: Definition of the wxToggleButton class, which implements a | |
4 | // toggle button under wxMac. | |
5 | // Author: Stefan Csomor | |
6 | // Modified by: | |
7 | // Created: 08.02.01 | |
8 | // RCS-ID: $Id$ | |
92e6d869 SC |
9 | // Copyright: (c) Stefan Csomor |
10 | // License: wxWindows license | |
eabe6af8 SC |
11 | ///////////////////////////////////////////////////////////////////////////// |
12 | ||
13 | // ============================================================================ | |
14 | // declatations | |
15 | // ============================================================================ | |
16 | ||
17 | // ---------------------------------------------------------------------------- | |
18 | // headers | |
19 | // ---------------------------------------------------------------------------- | |
20 | ||
21 | #ifdef __GNUG__ | |
22 | #pragma implementation "button.h" | |
23 | #endif | |
24 | ||
25 | #include "wx/defs.h" | |
26 | #include "wx/tglbtn.h" | |
27 | ||
28 | #if wxUSE_TOGGLEBTN | |
29 | ||
30 | #include "wx/mac/uma.h" | |
31 | // Button | |
32 | ||
33 | static const int kMacOSXHorizontalBorder = 2 ; | |
34 | static const int kMacOSXVerticalBorder = 4 ; | |
35 | ||
36 | // ---------------------------------------------------------------------------- | |
37 | // macros | |
38 | // ---------------------------------------------------------------------------- | |
39 | ||
40 | IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) | |
41 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) | |
42 | ||
43 | // ============================================================================ | |
44 | // implementation | |
45 | // ============================================================================ | |
46 | ||
47 | // ---------------------------------------------------------------------------- | |
48 | // wxToggleButton | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
51 | // Single check box item | |
52 | bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, | |
53 | const wxString& label, | |
54 | const wxPoint& pos, | |
55 | const wxSize& size, long style, | |
56 | const wxValidator& validator, | |
57 | const wxString& name) | |
58 | { | |
facd6764 SC |
59 | m_macIsUserPane = FALSE ; |
60 | ||
eabe6af8 SC |
61 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) |
62 | return false; | |
eabe6af8 | 63 | |
facd6764 | 64 | m_label = label ; |
eabe6af8 | 65 | |
facd6764 | 66 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
4c37f124 | 67 | |
21fd5529 | 68 | m_peer = new wxMacControl() ; |
4c37f124 | 69 | verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , |
5ca0d812 | 70 | kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); |
21fd5529 | 71 | |
eabe6af8 | 72 | |
facd6764 | 73 | MacPostControlCreate(pos,size) ; |
eabe6af8 SC |
74 | |
75 | return TRUE; | |
76 | } | |
77 | ||
78 | wxSize wxToggleButton::DoGetBestSize() const | |
79 | { | |
80 | int wBtn = 70 ; | |
81 | int hBtn = 20 ; | |
82 | ||
b635e17f | 83 | int lBtn = m_label.Length() * 8 + 12 ; |
eabe6af8 SC |
84 | if (lBtn > wBtn) |
85 | wBtn = lBtn; | |
86 | ||
eabe6af8 SC |
87 | return wxSize ( wBtn , hBtn ) ; |
88 | } | |
89 | ||
90 | void wxToggleButton::SetValue(bool val) | |
91 | { | |
5ca0d812 | 92 | m_peer->SetValue( val ) ; |
eabe6af8 SC |
93 | } |
94 | ||
95 | bool wxToggleButton::GetValue() const | |
96 | { | |
5ca0d812 | 97 | return m_peer->GetValue() ; |
eabe6af8 SC |
98 | } |
99 | ||
100 | void wxToggleButton::Command(wxCommandEvent & event) | |
101 | { | |
102 | SetValue((event.GetInt() != 0)); | |
103 | ProcessCommand(event); | |
104 | } | |
105 | ||
4c37f124 | 106 | wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
eabe6af8 | 107 | { |
4c37f124 SC |
108 | wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); |
109 | event.SetInt(GetValue()); | |
110 | event.SetEventObject(this); | |
111 | ProcessCommand(event); | |
112 | return noErr ; | |
eabe6af8 SC |
113 | } |
114 | ||
115 | #endif // wxUSE_TOGGLEBTN | |
116 |