]> git.saurik.com Git - wxWidgets.git/blame - src/motif/radiobut.cpp
Add virtual ~wxAnyScrollHelperBase() to fix compiler warning.
[wxWidgets.git] / src / motif / radiobut.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
355b4d3d 2// Name: src/motif/radiobut.cpp
4bb6408c
JS
3// Purpose: wxRadioButton
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
4bb6408c 7// Copyright: (c) Julian Smart
355b4d3d 8// Licence: wxWindows licence
4bb6408c
JS
9/////////////////////////////////////////////////////////////////////////////
10
1248b41f
MB
11// For compilers that support precompilation, includes "wx.h".
12#include "wx/wxprec.h"
13
4bb6408c 14#include "wx/radiobut.h"
de6185e2
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/utils.h"
18#endif
a4294b78 19
338dd992
JJ
20#ifdef __VMS__
21#pragma message disable nosimpint
22#endif
a4294b78
JS
23#include <Xm/ToggleB.h>
24#include <Xm/ToggleBG.h>
338dd992
JJ
25#ifdef __VMS__
26#pragma message enable nosimpint
27#endif
a4294b78 28
3096bd2f 29#include "wx/motif/private.h"
a4294b78
JS
30
31void wxRadioButtonCallback (Widget w, XtPointer clientData,
2d120f83 32 XmToggleButtonCallbackStruct * cbs);
4bb6408c 33
a4294b78
JS
34wxRadioButton::wxRadioButton()
35{
a4294b78
JS
36}
37
4bb6408c 38bool wxRadioButton::Create(wxWindow *parent, wxWindowID id,
2d120f83
JS
39 const wxString& label,
40 const wxPoint& pos,
41 const wxSize& size, long style,
42 const wxValidator& validator,
43 const wxString& name)
4bb6408c 44{
f96b10c2
MB
45 if( !CreateControl( parent, id, pos, size, style, validator, name ) )
46 return false;
105fbe1f 47 PreCreation();
31528cd3 48
a4294b78 49 Widget parentWidget = (Widget) parent->GetClientWidget();
73608949 50 Display* dpy = XtDisplay(parentWidget);
31528cd3 51
32cd189d 52 wxString label1(GetLabelText(label));
31528cd3 53
da494b40 54 wxXmString text( label1 );
31528cd3 55
a4294b78
JS
56 Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
57#if wxUSE_GADGETS
2d120f83 58 xmToggleButtonGadgetClass, parentWidget,
a4294b78 59#else
2d120f83 60 xmToggleButtonWidgetClass, parentWidget,
a4294b78 61#endif
73608949 62 wxFont::GetFontTag(), m_font.GetFontTypeC(dpy),
da494b40 63 XmNlabelString, text(),
2d120f83
JS
64 XmNfillOnSelect, True,
65 XmNindicatorType, XmONE_OF_MANY, // diamond-shape
66 NULL);
31528cd3 67
f96b10c2
MB
68 XtAddCallback (radioButtonWidget,
69 XmNvalueChangedCallback,
70 (XtCallbackProc)wxRadioButtonCallback,
71 (XtPointer)this);
31528cd3 72
a4294b78 73 m_mainWidget = (WXWidget) radioButtonWidget;
31528cd3 74
a4294b78 75 XtManageChild (radioButtonWidget);
31528cd3 76
105fbe1f 77 PostCreation();
f96b10c2
MB
78 AttachWidget (parent, m_mainWidget, (WXWidget) NULL,
79 pos.x, pos.y, size.x, size.y);
31528cd3 80
96be256b 81 //copied from mac/radiobut.cpp (from here till "return true;")
f37907ff 82 m_cycle = this ;
002ceb38 83
f37907ff
MB
84 if (HasFlag(wxRB_GROUP))
85 {
86 AddInCycle( NULL ) ;
87 }
88 else
89 {
90 /* search backward for last group start */
d3b9f782 91 wxRadioButton *chief = NULL;
ac32ba44 92 wxWindowList::compatibility_iterator node = parent->GetChildren().GetLast();
f37907ff
MB
93 while (node)
94 {
95 wxWindow *child = node->GetData();
96 if (child->IsKindOf( CLASSINFO( wxRadioButton ) ) )
97 {
98 chief = (wxRadioButton*) child;
99 if (child->HasFlag(wxRB_GROUP)) break;
100 }
101 node = node->GetPrevious();
102 }
103 AddInCycle( chief ) ;
104 }
96be256b 105 return true;
4bb6408c
JS
106}
107
108void wxRadioButton::SetValue(bool value)
109{
f37907ff
MB
110 if (GetValue() == value)
111 return;
112
96be256b
MB
113 m_inSetValue = true;
114 XmToggleButtonSetState ((Widget) m_mainWidget, (Boolean) value, False);
115 m_inSetValue = false;
f37907ff
MB
116
117 ClearSelections();
4bb6408c
JS
118}
119
120// Get single selection, for single choice list items
121bool wxRadioButton::GetValue() const
122{
a4294b78 123 return (XmToggleButtonGetState ((Widget) m_mainWidget) != 0);
4bb6408c
JS
124}
125
126void wxRadioButton::Command (wxCommandEvent & event)
127{
687706f5 128 SetValue ( (event.GetInt() != 0) );
2d120f83 129 ProcessCommand (event);
4bb6408c
JS
130}
131
0d57be45
JS
132void wxRadioButton::ChangeBackgroundColour()
133{
321db4b6 134 wxWindow::ChangeBackgroundColour();
9838df2c
JS
135
136 // What colour should this be?
f516d986 137 wxColour colour = *wxBLACK;
3e0071d9 138 WXPixel selectPixel = colour.AllocColour(XtDisplay((Widget)m_mainWidget));
9838df2c
JS
139
140 XtVaSetValues ((Widget) GetMainWidget(),
141 XmNselectColor, selectPixel,
142 NULL);
0d57be45
JS
143}
144
355b4d3d 145void wxRadioButtonCallback (Widget WXUNUSED(w), XtPointer clientData,
2d120f83 146 XmToggleButtonCallbackStruct * cbs)
a4294b78 147{
2d120f83
JS
148 if (!cbs->set)
149 return;
31528cd3 150
2d120f83
JS
151 wxRadioButton *item = (wxRadioButton *) clientData;
152 if (item->InSetValue())
153 return;
31528cd3 154
f37907ff
MB
155 //based on mac/radiobut.cpp
156 wxRadioButton* old = item->ClearSelections();
96be256b 157 item->SetValue(true);
f37907ff
MB
158
159 if ( old )
160 {
ce7fe42e 161 wxCommandEvent event(wxEVT_RADIOBUTTON,
f37907ff
MB
162 old->GetId() );
163 event.SetEventObject(old);
96be256b 164 event.SetInt( false );
f37907ff
MB
165 old->ProcessCommand(event);
166 }
ce7fe42e 167 wxCommandEvent event2(wxEVT_RADIOBUTTON, item->GetId() );
f37907ff 168 event2.SetEventObject(item);
96be256b 169 event2.SetInt( true );
f37907ff
MB
170 item->ProcessCommand(event2);
171}
172
173wxRadioButton* wxRadioButton::AddInCycle(wxRadioButton *cycle)
174{
f37907ff
MB
175 if (cycle == NULL)
176 {
177 m_cycle = this;
f37907ff
MB
178 }
179 else
180 {
002ceb38
VZ
181 wxRadioButton* current = cycle;
182 while ( current->m_cycle != cycle )
f37907ff
MB
183 current = current->m_cycle;
184 m_cycle = cycle;
185 current->m_cycle = this;
f37907ff 186 }
002ceb38
VZ
187
188 return cycle;
f37907ff 189}
31528cd3 190
f37907ff
MB
191wxRadioButton* wxRadioButton::ClearSelections()
192{
193 wxRadioButton* cycle = NextInCycle();
194 wxRadioButton* old = 0;
195
196 if (cycle)
197 {
198 while (cycle != this)
199 {
200 if ( cycle->GetValue() )
201 {
202 old = cycle;
96be256b 203 cycle->SetValue(false);
f37907ff
MB
204 }
205 cycle = cycle->NextInCycle();
206 }
207 }
208
209 return old;
a4294b78 210}
4bb6408c 211
f37907ff
MB
212void wxRadioButton::RemoveFromCycle()
213{
214 wxRadioButton* curr = NextInCycle();
215
216 while( curr )
217 {
218 if( curr->NextInCycle() == this )
219 {
220 curr->m_cycle = this->m_cycle;
221 return;
222 }
223
224 curr = curr->NextInCycle();
225 }
226}