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