]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/radiobut.cpp
wxFont can now raelly use the native fonts
[wxWidgets.git] / src / mac / 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 Rect bounds ;
34 Str255 title ;
35
36 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
37
38 m_macControl = ::NewControl( parent->MacGetRootWindow() , &bounds , title , false , 0 , 0 , 1,
39 kControlRadioButtonProc , (long) this ) ;
40
41 MacPostControlCreate() ;
42
43 m_cycle = this ;
44
45 if (HasFlag(wxRB_GROUP))
46 {
47 AddInCycle( NULL ) ;
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)
55 {
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();
63 }
64 AddInCycle( chief ) ;
65 }
66 return TRUE;
67}
68
69void wxRadioButton::SetValue(bool val)
70{
71 int i;
72 wxRadioButton *cycle;
73 if ( GetControlValue( m_macControl ) == val )
74 return ;
75
76 ::SetControlValue( m_macControl , val ) ;
77 if (val)
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}
88
89bool wxRadioButton::GetValue() const
90{
91 return ::GetControlValue( m_macControl ) ;
92}
93
94void wxRadioButton::Command (wxCommandEvent & event)
95{
96 SetValue ( (event.GetInt() != 0) );
97 ProcessCommand (event);
98}
99
100void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
101{
102 if ( GetValue() )
103 return ;
104
105 wxRadioButton *cycle, *old = NULL ;
106 cycle=this->NextInCycle();
107 if (cycle!=NULL) {
108 while (cycle!=this) {
109 if ( cycle->GetValue() ) {
110 old = cycle ;
111 cycle->SetValue(false);
112 }
113 cycle=cycle->NextInCycle();
114 }
115 }
116
117 SetValue(true) ;
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);
129}
130
131wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
132{
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 }
147}