]> git.saurik.com Git - wxWidgets.git/blame - src/mac/radiobut.cpp
GTK_TOOLBAR_BOTH_HORIZ is GTK 2 only (it would have been nice if the patch mentioned...
[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
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "radiobut.h"
14#endif
15
d8c736e5 16#include "wx/defs.h"
e9576ca5 17
d8c736e5 18#include "wx/radiobut.h"
079c842c 19
d8c736e5 20#if !USE_SHARED_LIBRARY
e9576ca5 21IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
d8c736e5 22#endif
079c842c 23
d497dca4 24#include "wx/mac/uma.h"
1dd52151 25
e9576ca5 26bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
e40298d5 27 const wxString& label,
e9576ca5
SC
28 const wxPoint& pos,
29 const wxSize& size, long style,
30 const wxValidator& validator,
31 const wxString& name)
32{
e40298d5
JS
33 Rect bounds ;
34 Str255 title ;
35
36 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
e9576ca5 37
e40298d5
JS
38 m_macControl = ::NewControl( MAC_WXHWND(parent->MacGetRootWindow()) , &bounds , title , false , 0 , 0 , 1,
39 kControlRadioButtonProc , (long) this ) ;
40
41 MacPostControlCreate() ;
e9576ca5 42
aa6c945b 43 m_cycle = this ;
c503ab84 44
0a67a93b
SC
45 if (HasFlag(wxRB_GROUP))
46 {
e40298d5 47 AddInCycle( NULL ) ;
0a67a93b
SC
48 }
49 else
50 {
51 /* search backward for last group start */
52 wxRadioButton *chief = (wxRadioButton*) NULL;
53 wxWindowList::Node *node = parent->GetChildren().GetLast();
54 while (node)
079c842c 55 {
0a67a93b
SC
56 wxWindow *child = node->GetData();
57 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
58 {
59 chief = (wxRadioButton*) child;
60 if (child->HasFlag(wxRB_GROUP)) break;
61 }
62 node = node->GetPrevious();
079c842c 63 }
0a67a93b
SC
64 AddInCycle( chief ) ;
65 }
66 return TRUE;
e9576ca5
SC
67}
68
1dd52151 69void wxRadioButton::SetValue(bool val)
e9576ca5 70{
e40298d5
JS
71 wxRadioButton *cycle;
72 if ( GetControl32BitValue( (ControlHandle) m_macControl ) == val )
73 return ;
74
467e3168 75 ::SetControl32BitValue( (ControlHandle) m_macControl , val ) ;
2f1ae414
SC
76 if (val)
77 {
e40298d5
JS
78 cycle=this->NextInCycle();
79 if (cycle!=NULL) {
80 while (cycle!=this) {
81 cycle->SetValue(false);
82 cycle=cycle->NextInCycle();
83 }
84 }
85 }
73969f3f 86 MacRedrawControl() ;
e9576ca5
SC
87}
88
e9576ca5
SC
89bool wxRadioButton::GetValue() const
90{
467e3168 91 return ::GetControl32BitValue( (ControlHandle) m_macControl ) ;
e9576ca5
SC
92}
93
94void wxRadioButton::Command (wxCommandEvent & event)
95{
1dd52151 96 SetValue ( (event.GetInt() != 0) );
e9576ca5
SC
97 ProcessCommand (event);
98}
99
4b26b60f 100void wxRadioButton::MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool WXUNUSED(mouseStillDown))
1dd52151 101{
f0822896
SC
102 if ( GetValue() )
103 return ;
104
e40298d5 105 wxRadioButton *cycle, *old = NULL ;
f0822896
SC
106 cycle=this->NextInCycle();
107 if (cycle!=NULL) {
e40298d5
JS
108 while (cycle!=this) {
109 if ( cycle->GetValue() ) {
110 old = cycle ;
111 cycle->SetValue(false);
112 }
113 cycle=cycle->NextInCycle();
114 }
f0822896
SC
115 }
116
e40298d5 117 SetValue(true) ;
f0822896
SC
118
119 if ( old ) {
120 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, old->m_windowId );
121 event.SetEventObject(old);
122 event.SetInt( false );
123 old->ProcessCommand(event);
124 }
125 wxCommandEvent event2(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
126 event2.SetEventObject(this);
127 event2.SetInt( true );
128 ProcessCommand(event2);
1dd52151
UJ
129}
130
131wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
132{
e40298d5
JS
133 wxRadioButton *next,*current;
134
135 if (cycle==NULL) {
136 m_cycle=this;
137 return(this);
138 }
139 else {
140 current=cycle;
141 while ((next=current->m_cycle)!=cycle)
142 current=current->m_cycle;
143 m_cycle=cycle;
144 current->m_cycle=this;
145 return(cycle);
146 }
1dd52151 147}