Debian Codegraph @

sys/GuiRadioButton.cpp

raw symbols SCIP
1 /* GuiRadioButton.cpp
2 *
3 * Copyright (C) 1993-2018,2024 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 * pb 2007/12/26 extracted from Motif
21 * sdk 2007/12/27 gtk
22 * pb 2010/05/15 prevented procreation of valueChanged events in GuiRadioButton_setValue
23 * pb 2010/06/14 HandleControlClick
24 * pb 2010/11/28 removed Motif
25 * pb 2011/04/06 C++
26 */
27
28 #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/
29
30 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiRadioButton, GuiControl, 0);
31
32 #if motifcxx . . $ `sys/Gui.h:34:10`!
33 #define iam_radiobutton \
34 Melder_assert (widget -> widgetClass == xmToggleButtonWidgetClass); \
35 GuiRadioButton me = (GuiRadioButton) widget -> userData
36 #else
37 #define iam_radiobuttoncxx . . $ `sys/GuiRadioButton.cpp:37:10`! \
38 GuiRadioButton me = (GuiRadioButton) _GuiObject_getUserData (widget)
39 #endif
40
41 static int _GuiRadioButton_getPositioncxx . . $ _GuiRadioButton_getPosition(9408214c2a607c77). (GuiRadioButtoncxx . . $ GuiRadioButton# me) {
42 int position = 1;
43 while (mycxx . . $ `melder/melder.h:44:9`! d_previouscxx . . $ structGuiRadioButton#d_previous.) {
44 position ++;
45 me = mycxx . . $ `melder/melder.h:44:9`! d_previouscxx . . $ structGuiRadioButton#d_previous.;
46 }
47 return position;
48 }
49
50 #if gtkcxx . . $ `sys/Gui.h:33:10`!
51 static void _GuiGtkRadioButton_destroyCallbackcxx . . $ _GuiGtkRadioButton_destroyCallback(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# widget, gpointer void_me) {
52 (void) widget;
53 iamcxx . . $ `melder/melder.h:50:9`! (GuiRadioButton);
54 forgetcxx . . $ `sys/Thing.h:158:9`! (me);
55 }
56 static void _GuiGtkRadioButton_handleTogglecxx . . $ _GuiGtkRadioButton_handleToggle(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# widget, gpointer void_me) {
57 iamcxx . . $ `melder/melder.h:50:9`! (GuiRadioButton);
58 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"enter");
59 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTONcxx . . $ `<external>/15753648026364605063/gtktogglebutton.h:39:9`! (widget))) {
60 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"on");
61 if (mycxx . . $ `melder/melder.h:44:9`! d_valueChangedCallbackcxx . . $ structGuiRadioButton#d_valueChangedCallback. && ! mycxx . . $ `melder/melder.h:44:9`! d_blockValueChangedCallbackscxx . . $ structGuiControl#d_blockValueChangedCallbacks.) {
62 struct structGuiRadioButtonEventcxx . . $ structGuiRadioButtonEvent# event { me };
63 event. positioncxx . . $ structGuiRadioButtonEvent#position. = _GuiRadioButton_getPositioncxx . . $ _GuiRadioButton_getPosition(9408214c2a607c77). (me);
64 mycxx . . $ `melder/melder.h:44:9`! d_valueChangedCallbackcxx . . $ structGuiRadioButton#d_valueChangedCallback. (cxx . . $ MelderCallback#`operator()`(e7ade0e2880b4e44).mycxx . . $ `melder/melder.h:44:9`! d_valueChangedBosscxx . . $ structGuiRadioButton#d_valueChangedBoss., & event);
65 }
66 }
67 }
68 #elif motif
69 void _GuiWinRadioButton_destroy (GuiObject widget) {
70 iam_radiobutton;
71 _GuiNativeControl_destroy (widget);
72 forget (me); // NOTE: my widget is not destroyed here
73 }
74 void _GuiWinRadioButton_handleClick (GuiObject widget) {
75 iam_radiobutton;
76 Button_SetCheck (widget -> window, BST_CHECKED);
77 /*
78 * Deselect the sister buttons.
79 */
80 for (GuiRadioButton sibling = my d_previous; sibling != nullptr; sibling = sibling -> d_previous) {
81 Button_SetCheck (sibling -> d_widget -> window, BST_UNCHECKED);
82 }
83 for (GuiRadioButton sibling = my d_next; sibling != nullptr; sibling = sibling -> d_next) {
84 Button_SetCheck (sibling -> d_widget -> window, BST_UNCHECKED);
85 }
86 if (my d_valueChangedCallback) {
87 struct structGuiRadioButtonEvent event { me };
88 event. position = _GuiRadioButton_getPosition (me);
89 my d_valueChangedCallback (my d_valueChangedBoss, & event);
90 }
91 }
92 #elif cocoa
93 @implementation GuiCocoaRadioButton {
94 GuiRadioButton d_userData;
95 }
96 - (void) dealloc { // override
97 GuiRadioButton me = d_userData;
98 forget (me);
99 trace (U"deleting a radio button");
100 [super dealloc];
101 }
102 - (GuiThing) getUserData {
103 return d_userData;
104 }
105 - (void) setUserData: (GuiThing) userData {
106 Melder_assert (userData == nullptr || Thing_isa (userData, classGuiRadioButton));
107 d_userData = static_cast <GuiRadioButton> (userData);
108 }
109 - (void) _guiCocoaRadioButton_activateCallback: (id) widget {
110 trace (U"enter");
111 Melder_assert (self == widget); // sender (widget) and receiver (self) happen to be the same object
112 GuiRadioButton me = d_userData;
113 /*
114 * Deselect the sister buttons.
115 */
116 for (GuiRadioButton sibling = my d_previous; sibling != nullptr; sibling = sibling -> d_previous) {
117 [sibling -> d_cocoaRadioButton setState: NSOffState];
118 }
119 for (GuiRadioButton sibling = my d_next; sibling != nullptr; sibling = sibling -> d_next) {
120 [sibling -> d_cocoaRadioButton setState: NSOffState];
121 }
122 if (my d_valueChangedCallback) {
123 Melder_assert (! my d_blockValueChangedCallbacks);
124 struct structGuiRadioButtonEvent event { me };
125 event. position = _GuiRadioButton_getPosition (me);
126 my d_valueChangedCallback (my d_valueChangedBoss, & event);
127 }
128 }
129 @end
130 #endif
131
132 static GuiRadioButtoncxx . . $ GuiRadioButton# latestRadioButtoncxx . . $ latestRadioButton. = nullptr;
133
134 void GuiRadioGroup_begincxx . . $ GuiRadioGroup_begin(49f6e7a06ebc5aa8). () {
135 latestRadioButtoncxx . . $ latestRadioButton. = nullptr;
136 }
137
138 void GuiRadioGroup_endcxx . . $ GuiRadioGroup_end(49f6e7a06ebc5aa8). () {
139 latestRadioButtoncxx . . $ latestRadioButton. = nullptr;
140 }
141
142 GuiRadioButtoncxx . . $ GuiRadioButton# GuiRadioButton_createcxx . . $ GuiRadioButton_create(6b1e2d4d89108d7e). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom,
143 conststring32cxx . . $ conststring32# buttonText, GuiRadioButtonCallbackcxx . . $ GuiRadioButtonCallback# valueChangedCallback, Thingcxx . . $ Thing# valueChangedBoss, uint32cxx . . $ uint32# flags)
144 {
145 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin: text %", buttonText);
146 autoGuiRadioButtoncxx . . $ autoGuiRadioButton# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (GuiRadioButton);
147 mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell. = parent -> d_shellcxx . . $ structGuiThing#d_shell.;
148 mycxx . . $ `melder/melder.h:44:9`! d_parentcxx . . $ structGuiThing#d_parent. = parent;
149 mycxx . . $ `melder/melder.h:44:9`! d_valueChangedCallbackcxx . . $ structGuiRadioButton#d_valueChangedCallback. =cxx . . $ MelderCallback#`operator=`(7d2ee3b083302762). valueChangedCallback;
150 mycxx . . $ `melder/melder.h:44:9`! d_valueChangedBosscxx . . $ structGuiRadioButton#d_valueChangedBoss. = valueChangedBoss;
151 mycxx . . $ `melder/melder.h:44:9`! d_previouscxx . . $ structGuiRadioButton#d_previous. = latestRadioButtoncxx . . $ latestRadioButton.;
152 mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiRadioButton#d_next. = nullptr;
153 #if gtkcxx . . $ `sys/Gui.h:33:10`!
154 mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_radio_button_new_with_label_from_widget (latestRadioButtoncxx . . $ latestRadioButton. ? GTK_RADIO_BUTTONcxx . . $ `<external>/3115651446838247977/gtkradiobutton.h:39:9`! (latestRadioButton -> d_widget) : nullptr, Melder_peek32to8 (buttonText));
155 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
156 mycxx . . $ `melder/melder.h:44:9`! v_positionInFormcxx . . $ structGuiControl#v_positionInForm(6e76d3e0dab57625). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., left, right, top, bottom, parent);
157 if (flags & GuiRadioButton_SETcxx . . $ `sys/Gui.h:1006:9`!) {
158 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTONcxx . . $ `<external>/15753648026364605063/gtktogglebutton.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), true);
159 } else {
160 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTONcxx . . $ `<external>/15753648026364605063/gtktogglebutton.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), false);
161 }
162 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "destroy", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkRadioButton_destroyCallback), me.get());
163 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (GTK_TOGGLE_BUTTONcxx . . $ `<external>/15753648026364605063/gtktogglebutton.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "toggled", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkRadioButton_handleToggle), me.get());
164 #elif motif
165 my d_widget = _Gui_initializeWidget (xmToggleButtonWidgetClass, parent -> d_widget, buttonText);
166 _GuiObject_setUserData (my d_widget, me.get());
167 my d_widget -> isRadioButton = true;
168 my d_widget -> window = CreateWindow (L"button", Melder_peek32toW (_GuiWin_expandAmpersands (buttonText)),
169 WS_CHILD
170 | ( my d_widget -> parent -> radioBehavior ? BS_AUTORADIOBUTTON : BS_RADIOBUTTON )
171 | WS_CLIPSIBLINGS,
172 my d_widget -> x, my d_widget -> y, my d_widget -> width, my d_widget -> height,
173 my d_widget -> parent -> window, (HMENU) 1, theGui.instance, nullptr);
174 SetWindowLongPtr (my d_widget -> window, GWLP_USERDATA, (LONG_PTR) my d_widget);
175 SetWindowFont (my d_widget -> window, theWinGuiNormalLabelFont (), false);
176 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
177 if (flags & GuiRadioButton_SET) {
178 Button_SetCheck (my d_widget -> window, BST_CHECKED);
179 }
180 #elif cocoa
181 my d_cocoaRadioButton = [[GuiCocoaRadioButton alloc] init];
182 my d_widget = my d_cocoaRadioButton;
183 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
184 [my d_cocoaRadioButton setUserData: me.get()];
185 [my d_cocoaRadioButton setButtonType: NSRadioButton];
186 if (true) {
187 /*
188 HACK:
189 The button's state will be under our control,
190 instead of automatically changing under the user's clicks on the neighbours.
191 Make the button therefore behave as a switch button but look as a radio button.
192 */
193 NSImage *image = [my d_cocoaRadioButton image], *alternateImage = [my d_cocoaRadioButton alternateImage];
194 [my d_cocoaRadioButton setButtonType: NSSwitchButton];
195 [my d_cocoaRadioButton setImage: image];
196 [my d_cocoaRadioButton setAlternateImage: alternateImage];
197 }
198 [my d_cocoaRadioButton setTitle: (NSString *) Melder_peek32toCfstring (buttonText)];
199 if (flags & GuiCheckButton_SET) {
200 [my d_cocoaRadioButton setState: NSOnState];
201 }
202 [my d_cocoaRadioButton setTarget: my d_cocoaRadioButton];
203 [my d_cocoaRadioButton setAction: @selector (_guiCocoaRadioButton_activateCallback:)];
204 #elif cocoa
205 /*
206 An alternate way to implement the single-button hack.
207 */
208 NSRect matrixRect = NSMakeRect (20.0, 20.0, 125.0, 125.0);
209 my d_cocoaRadioButton = [[GuiCocoaRadioButton alloc] initWithFrame:matrixRect];
210 [my d_cocoaRadioButton setUserData: me.get()];
211 [my d_cocoaRadioButton setButtonType: NSRadioButton];
212 [my d_cocoaRadioButton setTitle: (NSString *) Melder_peek32toCfstring (buttonText)];
213 NSMatrix *radioMatrix = [[NSMatrix alloc] initWithFrame: matrixRect mode: NSRadioModeMatrix
214 prototype: (NSCell *) [my d_cocoaRadioButton cell] numberOfRows: 1 numberOfColumns: 1];
215 my d_widget = (GuiObject) radioMatrix; //my d_cocoaRadioButton;
216 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
217 [radioMatrix addSubview: my d_cocoaRadioButton];
218 [my d_cocoaRadioButton setUserData: me.get()];
219 [my d_cocoaRadioButton setButtonType: NSRadioButton];
220 [my d_cocoaRadioButton setTitle: (NSString *) Melder_peek32toCfstring (buttonText)];
221 if (flags & GuiCheckButton_SET) {
222 [my d_cocoaRadioButton setState: NSOnState];
223 }
224 [my d_cocoaRadioButton setTarget: my d_cocoaRadioButton];
225 [my d_cocoaRadioButton setAction: @selector (_guiCocoaRadioButton_activateCallback:)];
226 #endif
227 if (flags & GuiRadioButton_INSENSITIVEcxx . . $ `sys/Gui.h:1007:9`!) {
228 GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), false);
229 }
230 if (mycxx . . $ `melder/melder.h:44:9`! d_previouscxx . . $ structGuiRadioButton#d_previous.) {
231 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! d_previous);
232 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! d_previous -> classInfo == classGuiRadioButton);
233 mycxx . . $ `melder/melder.h:44:9`! d_previouscxx . . $ structGuiRadioButton#d_previous. -> d_nextcxx . . $ structGuiRadioButton#d_next. = me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
234 }
235 latestRadioButtoncxx . . $ latestRadioButton. = me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
236 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"end");
237 return me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).();
238 }
239
240 GuiRadioButtoncxx . . $ GuiRadioButton# GuiRadioButton_createShowncxx . . $ GuiRadioButton_createShown(6b1e2d4d89108d7e). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom,
241 conststring32cxx . . $ conststring32# buttonText, GuiRadioButtonCallbackcxx . . $ GuiRadioButtonCallback# valueChangedCallback, Thingcxx . . $ Thing# valueChangedBoss, uint32cxx . . $ uint32# flags)
242 {
243 GuiRadioButtoncxx . . $ GuiRadioButton# me = GuiRadioButton_createcxx . . $ GuiRadioButton_create(6b1e2d4d89108d7e). (parent, left, right, top, bottom, buttonText, valueChangedCallback, valueChangedBoss, flags);
244 GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (me);
245 return me;
246 }
247
248 bool GuiRadioButton_getValuecxx . . $ GuiRadioButton_getValue(529b6fd83844103f). (GuiRadioButtoncxx . . $ GuiRadioButton# me) {
249 bool value = false;
250 #if gtkcxx . . $ `sys/Gui.h:33:10`!
251 value = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTONcxx . . $ `<external>/15753648026364605063/gtktogglebutton.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)); // gtk_check_button inherits from gtk_toggle_button
252 #elif motif
253 value = (Button_GetState (my d_widget -> window) & 0x0003) == BST_CHECKED;
254 #elif cocoa
255 value = [my d_cocoaRadioButton state] == NSOnState;
256 #endif
257 return value;
258 }
259
260 void GuiRadioButton_setcxx . . $ GuiRadioButton_set(669e3d212ae3e4fb). (GuiRadioButtoncxx . . $ GuiRadioButton# me) {
261 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"enter");
262 GuiControlBlockValueChangedCallbackscxx . . $ GuiControlBlockValueChangedCallbacks# blockcxx . . $ GuiControlBlockValueChangedCallbacks#GuiControlBlockValueChangedCallbacks(1363d6663f95c9c7). (me); // the value should be set without calling the valueChanged callback (crucial on GTK)
263 #if gtkcxx . . $ `sys/Gui.h:33:10`!
264 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTONcxx . . $ `<external>/15753648026364605063/gtktogglebutton.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), true);
265 #elif motif
266 Button_SetCheck (my d_widget -> window, BST_CHECKED);
267 /*
268 * Deselect the sister buttons.
269 */
270 for (GuiRadioButton sibling = my d_previous; sibling != nullptr; sibling = sibling -> d_previous) {
271 Button_SetCheck (sibling -> d_widget -> window, BST_UNCHECKED);
272 }
273 for (GuiRadioButton sibling = my d_next; sibling != nullptr; sibling = sibling -> d_next) {
274 Button_SetCheck (sibling -> d_widget -> window, BST_UNCHECKED);
275 }
276 #elif cocoa
277 [my d_cocoaRadioButton setState: NSOnState];
278 /*
279 * Deselect the sister buttons.
280 */
281 for (GuiRadioButton sibling = my d_previous; sibling != nullptr; sibling = sibling -> d_previous) {
282 [sibling -> d_cocoaRadioButton setState: NSOffState];
283 }
284 for (GuiRadioButton sibling = my d_next; sibling != nullptr; sibling = sibling -> d_next) {
285 [sibling -> d_cocoaRadioButton setState: NSOffState];
286 }
287 #endif
288 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"exit");
289 }
290
291 /* End of file GuiRadioButton.cpp */