]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/radiobut.cpp
rewrite to avoid unnecessary redraws
[wxWidgets.git] / src / mac / carbon / radiobut.cpp
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/radiobut.h"
17
18
19 IMPLEMENT_DYNAMIC_CLASS(wxRadioButton, wxControl)
20
21 #include <wx/mac/uma.h>
22
23 bool 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 {
30 Rect bounds ;
31 Str255 title ;
32
33 MacPreControlCreate( parent , id , label , pos , size ,style, validator , name , &bounds , title ) ;
34
35 m_macControl = UMANewControl( parent->GetMacRootWindow() , &bounds , title , false , 0 , 0 , 1,
36 kControlRadioButtonProc , (long) this ) ;
37
38 MacPostControlCreate() ;
39
40 m_cycle = this ;
41
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)
52 {
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();
60 }
61 AddInCycle( chief ) ;
62 }
63 return TRUE;
64 }
65
66 void wxRadioButton::SetValue(bool val)
67 {
68 int i;
69 wxRadioButton *cycle;
70 if ( GetControlValue( m_macControl ) == val )
71 return ;
72
73 ::SetControlValue( m_macControl , val ) ;
74 Refresh() ;
75 if (val)
76 {
77 cycle=this->NextInCycle();
78 if (cycle!=NULL) {
79 while (cycle!=this) {
80 cycle->SetValue(false);
81 cycle=cycle->NextInCycle();
82 }
83 }
84 }
85 }
86
87 bool wxRadioButton::GetValue() const
88 {
89 return ::GetControlValue( m_macControl ) ;
90 }
91
92 void wxRadioButton::Command (wxCommandEvent & event)
93 {
94 SetValue ( (event.GetInt() != 0) );
95 ProcessCommand (event);
96 }
97
98 void wxRadioButton::MacHandleControlClick( ControlHandle control , SInt16 controlpart )
99 {
100 SetValue(true) ;
101 wxCommandEvent event(wxEVT_COMMAND_RADIOBUTTON_SELECTED, m_windowId );
102 event.SetEventObject(this);
103 event.SetInt( GetValue() );
104 ProcessCommand(event);
105 }
106
107 wxRadioButton *wxRadioButton::AddInCycle(wxRadioButton *cycle)
108 {
109 wxRadioButton *next,*current;
110
111 if (cycle==NULL) {
112 m_cycle=this;
113 return(this);
114 }
115 else {
116 current=cycle;
117 while ((next=current->m_cycle)!=cycle)
118 current=current->m_cycle;
119 m_cycle=cycle;
120 current->m_cycle=this;
121 return(cycle);
122 }
123 }