]>
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 | ||
3d1a4878 | 21 | #include "wx/wxprec.h" |
eabe6af8 SC |
22 | |
23 | #if wxUSE_TOGGLEBTN | |
24 | ||
3d1a4878 | 25 | #include "wx/tglbtn.h" |
eabe6af8 SC |
26 | #include "wx/mac/uma.h" |
27 | // Button | |
28 | ||
29 | static const int kMacOSXHorizontalBorder = 2 ; | |
30 | static const int kMacOSXVerticalBorder = 4 ; | |
31 | ||
32 | // ---------------------------------------------------------------------------- | |
33 | // macros | |
34 | // ---------------------------------------------------------------------------- | |
35 | ||
36 | IMPLEMENT_DYNAMIC_CLASS(wxToggleButton, wxControl) | |
37 | DEFINE_EVENT_TYPE(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED) | |
38 | ||
39 | // ============================================================================ | |
40 | // implementation | |
41 | // ============================================================================ | |
42 | ||
43 | // ---------------------------------------------------------------------------- | |
44 | // wxToggleButton | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
47 | // Single check box item | |
48 | bool wxToggleButton::Create(wxWindow *parent, wxWindowID id, | |
49 | const wxString& label, | |
50 | const wxPoint& pos, | |
51 | const wxSize& size, long style, | |
52 | const wxValidator& validator, | |
53 | const wxString& name) | |
54 | { | |
facd6764 SC |
55 | m_macIsUserPane = FALSE ; |
56 | ||
eabe6af8 SC |
57 | if ( !wxControl::Create(parent, id, pos, size, style, validator, name) ) |
58 | return false; | |
eabe6af8 | 59 | |
facd6764 | 60 | m_label = label ; |
eabe6af8 | 61 | |
facd6764 | 62 | Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; |
4c37f124 | 63 | |
b905d6cc | 64 | m_peer = new wxMacControl(this) ; |
4c37f124 | 65 | verify_noerr ( CreateBevelButtonControl( MAC_WXHWND(parent->MacGetTopLevelWindowRef()) , &bounds , CFSTR("") , |
5ca0d812 | 66 | kControlBevelButtonNormalBevel , kControlBehaviorToggles , NULL , 0 , 0 , 0 , m_peer->GetControlRefAddr() ) ); |
21fd5529 | 67 | |
eabe6af8 | 68 | |
facd6764 | 69 | MacPostControlCreate(pos,size) ; |
eabe6af8 SC |
70 | |
71 | return TRUE; | |
72 | } | |
73 | ||
74 | wxSize wxToggleButton::DoGetBestSize() const | |
75 | { | |
76 | int wBtn = 70 ; | |
77 | int hBtn = 20 ; | |
78 | ||
b635e17f | 79 | int lBtn = m_label.Length() * 8 + 12 ; |
eabe6af8 SC |
80 | if (lBtn > wBtn) |
81 | wBtn = lBtn; | |
82 | ||
eabe6af8 SC |
83 | return wxSize ( wBtn , hBtn ) ; |
84 | } | |
85 | ||
86 | void wxToggleButton::SetValue(bool val) | |
87 | { | |
5ca0d812 | 88 | m_peer->SetValue( val ) ; |
eabe6af8 SC |
89 | } |
90 | ||
91 | bool wxToggleButton::GetValue() const | |
92 | { | |
5ca0d812 | 93 | return m_peer->GetValue() ; |
eabe6af8 SC |
94 | } |
95 | ||
96 | void wxToggleButton::Command(wxCommandEvent & event) | |
97 | { | |
98 | SetValue((event.GetInt() != 0)); | |
99 | ProcessCommand(event); | |
100 | } | |
101 | ||
4c37f124 | 102 | wxInt32 wxToggleButton::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) |
eabe6af8 | 103 | { |
4c37f124 SC |
104 | wxCommandEvent event(wxEVT_COMMAND_TOGGLEBUTTON_CLICKED, m_windowId); |
105 | event.SetInt(GetValue()); | |
106 | event.SetEventObject(this); | |
107 | ProcessCommand(event); | |
108 | return noErr ; | |
eabe6af8 SC |
109 | } |
110 | ||
111 | #endif // wxUSE_TOGGLEBTN | |
112 |