]> git.saurik.com Git - wxWidgets.git/blame - src/osx/radiobut_osx.cpp
Fix exporting clipboard data to primary selection in wxGTK.
[wxWidgets.git] / src / osx / radiobut_osx.cpp
CommitLineData
e53b3d16
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
4// Author: AUTHOR
5// Modified by: JS Lair (99/11/15) adding the cyclic group notion for radiobox
6// Created: ??/??/98
b5b208a1 7// RCS-ID: $Id$
e53b3d16
SC
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_RADIOBTN
15
16#include "wx/radiobut.h"
17#include "wx/osx/private.h"
18
e53b3d16
SC
19bool wxRadioButton::Create( wxWindow *parent,
20 wxWindowID id,
21 const wxString& label,
22 const wxPoint& pos,
23 const wxSize& size,
24 long style,
25 const wxValidator& validator,
26 const wxString& name )
27{
28 m_macIsUserPane = false;
29
30 if ( !wxControl::Create( parent, id, pos, size, style, validator, name ) )
31 return false;
32
33 m_labelOrig = m_label = label;
34
35 m_peer = wxWidgetImpl::CreateRadioButton( this, parent, id, label, pos, size, style, GetExtraStyle() );
36
37 MacPostControlCreate( pos, size );
38
39 m_cycle = this;
40
41 if (HasFlag( wxRB_GROUP ))
42 {
43 AddInCycle( NULL );
44 }
45 else
46 {
47 // search backward for last group start
48 wxRadioButton *chief = NULL;
49 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
50 while (node)
51 {
52 wxWindow *child = node->GetData();
53 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ))
54 {
55 chief = (wxRadioButton*)child;
56 if (child->HasFlag( wxRB_GROUP ))
57 break;
58 }
59
60 node = node->GetPrevious();
61 }
62
63 AddInCycle( chief );
64 }
65
66 return true;
67}
68
69wxRadioButton::~wxRadioButton()
70{
71 RemoveFromCycle();
72}
73
74void wxRadioButton::SetValue(bool val)
75{
76 wxRadioButton *cycle;
77 if (m_peer->GetValue() == val)
78 return;
79
80 m_peer->SetValue( val );
81 if (val)
82 {
83 cycle = this->NextInCycle();
84 if (cycle != NULL)
85 {
86 while (cycle != this)
87 {
88 cycle->SetValue( false );
89 cycle = cycle->NextInCycle();
90 }
91 }
92 }
93}
94
95bool wxRadioButton::GetValue() const
96{
c4021a79 97 return m_peer->GetValue() != 0;
e53b3d16
SC
98}
99
100void wxRadioButton::Command(wxCommandEvent& event)
101{
102 SetValue( (event.GetInt() != 0) );
103 ProcessCommand( event );
104}
105
0faf03bf 106bool wxRadioButton::OSXHandleClicked( double WXUNUSED(timestampsec) )
e53b3d16 107{
524c47aa
SC
108 if ( !m_peer->ButtonClickDidStateChange() )
109 {
110 // if already set -> no action
111 if (GetValue())
112 return true;
113 }
e53b3d16
SC
114
115 wxRadioButton *cycle;
116 cycle = this->NextInCycle();
117 if (cycle != NULL)
118 {
119 while (cycle != this)
120 {
121 if (cycle->GetValue())
122 cycle->SetValue( false );
123
124 cycle = cycle->NextInCycle();
125 }
126 }
127
128 SetValue( true );
129
130 wxCommandEvent event2( wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
131 event2.SetEventObject( this );
132 event2.SetInt( true );
133 ProcessCommand( event2 );
134
135 return true;
136}
137
138wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
139{
140 wxRadioButton *current;
141
142 if (cycle == NULL)
143 {
144 m_cycle = this;
145 }
146 else
147 {
148 current = cycle;
149 while (current->m_cycle != cycle)
150 current = current->m_cycle;
151
152 m_cycle = cycle;
153 current->m_cycle = this;
154 }
155
156 return m_cycle;
157}
158
159void wxRadioButton::RemoveFromCycle()
03647350 160{
e53b3d16
SC
161 if ((m_cycle == NULL) || (m_cycle == this))
162 return;
163
164 // Find the previous one and make it point to the next one
165 wxRadioButton* prev = this;
166 while (prev->m_cycle != this)
167 prev = prev->m_cycle;
168
169 prev->m_cycle = m_cycle;
170}
171
172#endif