]> git.saurik.com Git - wxWidgets.git/blame - src/mac/radiobut.cpp
applied patch for compilation with gcc 3.0
[wxWidgets.git] / src / mac / radiobut.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: radiobut.cpp
3// Purpose: wxRadioButton
4// Author: AUTHOR
1dd52151 5// Modified by: JS Lair (99/11/15) adding the cyclic groupe notion for radiobox
e9576ca5
SC
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "radiobut.h"
14#endif
15
16#include "wx/radiobut.h"
17
079c842c 18
e9576ca5 19IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
079c842c 20
1dd52151
UJ
21#include <wx/mac/uma.h>
22
e9576ca5
SC
23bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
24 const wxString& label,
25 const wxPoint& pos,
26 const wxSize& size, long style,
27 const wxValidator& validator,
28 const wxString& name)
29{
1dd52151
UJ
30 Rect bounds ;
31 Str255 title ;
32
1dd52151 33 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
e9576ca5 34
fdaf613a 35 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 1,
1dd52151
UJ
36 kControlRadioButtonProc , (long) this ) ;
37
38 MacPostControlCreate() ;
e9576ca5 39
aa6c945b 40 m_cycle = this ;
c503ab84 41
0a67a93b
SC
42 if (HasFlag(wxRB_GROUP))
43 {
44 AddInCycle( NULL ) ;
45 }
46 else
47 {
48 /* search backward for last group start */
49 wxRadioButton *chief = (wxRadioButton*) NULL;
50 wxWindowList::Node *node = parent->GetChildren().GetLast();
51 while (node)
079c842c 52 {
0a67a93b
SC
53 wxWindow *child = node->GetData();
54 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
55 {
56 chief = (wxRadioButton*) child;
57 if (child->HasFlag(wxRB_GROUP)) break;
58 }
59 node = node->GetPrevious();
079c842c 60 }
0a67a93b
SC
61 AddInCycle( chief ) ;
62 }
63 return TRUE;
e9576ca5
SC
64}
65
1dd52151 66void wxRadioButton::SetValue(bool val)
e9576ca5 67{
1dd52151
UJ
68 int i;
69 wxRadioButton *cycle;
fdaf613a
SC
70 if ( GetControlValue( m_macControl ) == val )
71 return ;
72
1dd52151 73 ::SetControlValue( m_macControl , val ) ;
2f1ae414
SC
74 if (val)
75 {
1dd52151
UJ
76 cycle=this->NextInCycle();
77 if (cycle!=NULL) {
78 while (cycle!=this) {
79 cycle->SetValue(false);
80 cycle=cycle->NextInCycle();
81 }
82 }
83 }
493c9f6b
SC
84 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
85 event.SetEventObject(this);
86 event.SetInt( GetValue() );
87 ProcessCommand(event);
e9576ca5
SC
88}
89
e9576ca5
SC
90bool wxRadioButton::GetValue() const
91{
1dd52151 92 return ::GetControlValue( m_macControl ) ;
e9576ca5
SC
93}
94
95void wxRadioButton::Command (wxCommandEvent & event)
96{
1dd52151 97 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
98 ProcessCommand (event);
99}
100
1dd52151
UJ
101void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
102{
fdaf613a 103 SetValue(true) ;
1dd52151
UJ
104}
105
106wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
107{
108 wxRadioButton *next,*current;
109
110 if (cycle==NULL) {
111 m_cycle=this;
112 return(this);
113 }
114 else {
115 current=cycle;
0a67a93b
SC
116 while ((next=current->m_cycle)!=cycle)
117 current=current->m_cycle;
1dd52151
UJ
118 m_cycle=cycle;
119 current->m_cycle=this;
120 return(cycle);
121 }
122}