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