Debian Codegraph @

sys/GuiButton.cpp

raw symbols SCIP
1 /* GuiButton.cpp
2 *
3 * Copyright (C) 1993-2008,2010-2020,2024,2026 Paul Boersma,
4 * 2007-2008 Stefan de Konink, 2010 Franz Brausse, 2013 Tom Naughton
5 *
6 * This code is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or (at
9 * your option) any later version.
10 *
11 * This code is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this work. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/
21
22 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiButton, GuiControl, 0);
23
24 #if gtkcxx . . $ `sys/Gui.h:33:10`!
25 #define iam_buttoncxx . . $ `sys/GuiButton.cpp:25:10`! GuiButton me = (GuiButton) userData
26 #elif motif
27 #define iam_button GuiButton me = (GuiButton) widget -> userData
28 #elif cocoa
29 #define iam_button GuiButton me = (GuiButton) self -> d_userData
30 #endif
31
32 #if gtkcxx . . $ `sys/Gui.h:33:10`!
33 static void _GuiGtkButton_destroyCallbackcxx . . $ _GuiGtkButton_destroyCallback(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# /* widget */, gpointer userData) {
34 GuiButtoncxx . . $ GuiButton# me = (GuiButtoncxx . . $ GuiButton#) userData;
35 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"destroying GuiButton ", Melder_pointer (me));
36 forgetcxx . . $ `sys/Thing.h:158:9`! (me);
37 }
38 static void _GuiGtkButton_activateCallbackcxx . . $ _GuiGtkButton_activateCallback(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# widget, gpointer userData) {
39 GuiButtoncxx . . $ GuiButton# me = (GuiButtoncxx . . $ GuiButton#) userData;
40 structGuiButtonEventcxx . . $ structGuiButtonEvent# event { me, false, false, false };
41 if (mycxx . . $ `melder/melder.h:44:9`! d_activateCallbackcxx . . $ structGuiButton#d_activateCallback.) {
42 try {
43 mycxx . . $ `melder/melder.h:44:9`! d_activateCallbackcxx . . $ structGuiButton#d_activateCallback. (cxx . . $ MelderCallback#`operator()`(e7ade0e2880b4e44).mycxx . . $ `melder/melder.h:44:9`! d_activateBosscxx . . $ structGuiButton#d_activateBoss., & event);
44 } catch (MelderErrorcxx . . $ MelderError#) {
45 Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"Your click on button \"", Melder_peek8to32_u (gtk_widget_get_name (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (widget))), U"\" was not completely handled.");
46 }
47 }
48 }
49 #elif motif
50 void _GuiWinButton_destroy (GuiObject widget) {
51 iam_button;
52 if (widget == widget -> shell -> defaultButton)
53 widget -> shell -> defaultButton = nullptr; // remove dangling reference
54 if (widget == widget -> shell -> cancelButton)
55 widget -> shell -> cancelButton = nullptr; // remove dangling reference
56 _GuiNativeControl_destroy (widget);
57 forget (me); // NOTE: my widget is not destroyed here
58 }
59 void _GuiWinButton_handleClick (GuiObject widget) {
60 iam_button;
61 if (my d_activateCallback) {
62 structGuiButtonEvent event { me, false, false, false };
63 try {
64 my d_activateCallback (my d_activateBoss, & event);
65 } catch (MelderError) {
66 Melder_flushError (U"Your click on button \"", widget -> name.get(), U"\" was not completely handled.");
67 }
68 }
69 }
70 bool _GuiWinButton_tryToHandleShortcutKey (GuiObject widget) {
71 iam_button;
72 if (my d_activateCallback) {
73 structGuiButtonEvent event { me, false, false, false };
74 try {
75 my d_activateCallback (my d_activateBoss, & event);
76 } catch (MelderError) {
77 Melder_flushError (U"Your key click on button \"", widget -> name.get(), U"\" was not completely handled.");
78 }
79 return true;
80 }
81 return false;
82 }
83 #elif cocoa
84 @implementation GuiCocoaButton {
85 GuiButton d_userData;
86 }
87 - (void) dealloc { // override
88 GuiButton me = d_userData;
89 forget (me);
90 trace (U"deleting a button");
91 [super dealloc];
92 }
93 - (GuiThing) getUserData {
94 return d_userData;
95 }
96 - (void) setUserData: (GuiThing) userData {
97 Melder_assert (userData == nullptr || Thing_isa (userData, classGuiButton));
98 d_userData = static_cast <GuiButton> (userData);
99 }
100 - (void) _guiCocoaButton_activateCallback: (id) widget {
101 Melder_assert (self == widget); // sender (widget) and receiver (self) happen to be the same object
102 GuiButton me = d_userData;
103 if (my d_activateCallback) {
104 structGuiButtonEvent event { me, false, false, false };
105 try {
106 my d_activateCallback (my d_activateBoss, & event);
107 } catch (MelderError) {
108 Melder_flushError (U"Your click on button \"", my name.get(), U"\" was not completely handled.");
109 }
110 }
111 }
112 @end
113 #endif
114
115 static void gui_blocking_dialog_cb_okcxx . . $ gui_blocking_dialog_cb_ok(266b1bde308be32a). (GuiDialogcxx . . $ GuiDialog# me, GuiButtonEventcxx . . $ GuiButtonEvent# event) {
116 mycxx . . $ `melder/melder.h:44:9`! clickedButtonIdcxx . . $ structGuiDialog#clickedButtonId. = event -> buttoncxx . . $ structGuiButtonEvent#button. -> d_sequentalIdInDialogcxx . . $ structGuiButton#d_sequentalIdInDialog.;
117 #if gtkcxx . . $ `sys/Gui.h:33:10`!
118 gtk_dialog_response (GTK_DIALOGcxx . . $ `<external>/3867786087843934573/gtkdialog.h:90:9`! (mycxx . . $ `melder/melder.h:44:9`! d_gtkWindow), 0); // or `my clickedButtonId`, but return value of gtk_dialog_run is ignored
119 #elif cocoa
120 [NSApp stopModal];
121 #endif
122 }
123 GuiButtoncxx . . $ GuiButton# GuiButton_createcxx . . $ GuiButton_create(653ed9987c16d9c1). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom,
124 conststring32cxx . . $ conststring32# buttonText, GuiButton_ActivateCallbackcxx . . $ GuiButton_ActivateCallback# activateCallback, Thingcxx . . $ Thing# activateBoss, uint32cxx . . $ uint32# flags)
125 {
126 autoGuiButtoncxx . . $ autoGuiButton# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (GuiButton);
127 mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell. = parent -> d_shellcxx . . $ structGuiThing#d_shell.;
128 mycxx . . $ `melder/melder.h:44:9`! d_parentcxx . . $ structGuiThing#d_parent. = parent;
129 mycxx . . $ `melder/melder.h:44:9`! d_activateCallbackcxx . . $ structGuiButton#d_activateCallback. =cxx . . $ MelderCallback#`operator=`(6f93f31019f967b4). activateCallback;
130 mycxx . . $ `melder/melder.h:44:9`! d_activateBosscxx . . $ structGuiButton#d_activateBoss. = activateBoss;
131 if (! mycxx . . $ `melder/melder.h:44:9`! d_activateCallbackcxx . . $ structGuiButton#d_activateCallback.) {
132 /*
133 This must be a button in a blocking dialog.
134 */
135 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Thing_isa (mycxx . . $ `melder/melder.h:44:9`! d_shell, classGuiDialog));
136 GuiDialogcxx . . $ GuiDialog# dialog = (GuiDialogcxx . . $ GuiDialog#) mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell.;
137 mycxx . . $ `melder/melder.h:44:9`! d_activateCallbackcxx . . $ structGuiButton#d_activateCallback. =cxx . . $ MelderCallback#`operator=`(3c2129614fa50241). gui_blocking_dialog_cb_okcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).;
138 mycxx . . $ `melder/melder.h:44:9`! d_activateBosscxx . . $ structGuiButton#d_activateBoss. = dialog;
139 mycxx . . $ `melder/melder.h:44:9`! d_sequentalIdInDialogcxx . . $ structGuiButton#d_sequentalIdInDialog. = ++ dialog -> latestCreatedButtonIdcxx . . $ structGuiDialog#latestCreatedButtonId.;
140 if (flags & GuiButton_DEFAULTcxx . . $ `sys/Gui.h:467:9`!) {
141 dialog -> defaultButtonIdcxx . . $ structGuiDialog#defaultButtonId. = mycxx . . $ `melder/melder.h:44:9`! d_sequentalIdInDialogcxx . . $ structGuiButton#d_sequentalIdInDialog.;
142 dialog -> defaultButtoncxx . . $ structGuiDialog#defaultButton. = me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
143 }
144 }
145 #if gtkcxx . . $ `sys/Gui.h:33:10`!
146 mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_button_new_with_label (Melder_peek32to8 (buttonText));
147 gtk_button_set_relief (GTK_BUTTONcxx . . $ `<external>/6931860716604248467/gtkbutton.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), GTK_RELIEF_NORMAL);
148 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
149 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);
150 if (flags & GuiButton_DEFAULTcxx . . $ `sys/Gui.h:467:9`! || flags & GuiButton_ATTRACTIVEcxx . . $ `sys/Gui.h:470:9`!) {
151 gtk_widget_set_can_default (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), true);
152 GtkWidget *shell = gtk_widget_get_toplevel (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
153 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (shell);
154 gtk_window_set_default (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (shell), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
155 } else if (1) {
156 gtk_button_set_focus_on_click (GTK_BUTTONcxx . . $ `<external>/6931860716604248467/gtkbutton.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), false);
157 gtk_widget_set_can_default (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), false);
158 }
159 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`! (_GuiGtkButton_destroyCallback), me.get());
160 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (GTK_BUTTONcxx . . $ `<external>/6931860716604248467/gtkbutton.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "clicked", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkButton_activateCallback), me.get());
161 GtkWidget *internalLabel = gtk_bin_get_child (GTK_BINcxx . . $ `<external>/459452664920108032/gtkbin.h:38:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
162 if (GTK_IS_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:41:9`! (internalLabel))
163 gtk_label_set_justify (GTK_LABELcxx . . $ `<external>/2142028111988326349/gtklabel.h:39:9`! (internalLabel), GTK_JUSTIFY_CENTER);
164 // if (flags & GuiButton_CANCEL) {
165 // parent -> shell -> cancelButton = parent -> cancelButton = my widget;
166 // }
167 #elif motif
168 my d_widget = _Gui_initializeWidget (xmPushButtonWidgetClass, parent -> d_widget, buttonText);
169 _GuiObject_setUserData (my d_widget, me.get());
170 my d_widget -> window = CreateWindow (L"button", Melder_peek32toW (_GuiWin_expandAmpersands (my d_widget -> name.get())),
171 WS_CHILD
172 | ( flags & (GuiButton_DEFAULT | GuiButton_ATTRACTIVE) ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON )
173 | ( flags & GuiButton_MULTILINE ? BS_MULTILINE : 0 )
174 | WS_CLIPSIBLINGS,
175 my d_widget -> x, my d_widget -> y, my d_widget -> width, my d_widget -> height,
176 my d_widget -> parent -> window, (HMENU) 1, theGui.instance, nullptr
177 );
178 SetWindowLongPtr (my d_widget -> window, GWLP_USERDATA, (LONG_PTR) my d_widget);
179 SetWindowFont (my d_widget -> window, flags & GuiButton_DEFAULT ? theWinGuiBoldLabelFont () : theWinGuiNormalLabelFont (), false);
180 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
181 if (flags & GuiButton_DEFAULT || flags & GuiButton_ATTRACTIVE)
182 parent -> d_widget -> shell -> defaultButton = parent -> d_widget -> defaultButton = my d_widget;
183 if (flags & GuiButton_CANCEL)
184 parent -> d_widget -> shell -> cancelButton = parent -> d_widget -> cancelButton = my d_widget;
185 #elif cocoa
186 GuiCocoaButton *button = [[GuiCocoaButton alloc] init];
187 my name = Melder_dup_f (buttonText);
188 my d_widget = (GuiObject) button;
189 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
190 [button setUserData: me.get()];
191 [button setButtonType: NSMomentaryPushInButton];
192 if (bottom - top < 30)
193 [button setBezelStyle: NSBezelStylePush]; // fixed height, ...
194 else
195 [button setBezelStyle: NSBezelStyleFlexiblePush]; // ... custom height
196 [button setImagePosition: NSNoImage];
197 [button setBordered: YES];
198 static NSFont *theButtonFont;
199 if (! theButtonFont)
200 theButtonFont = [NSFont systemFontOfSize: 13.0];
201 [button setFont: theButtonFont];
202 [button setTitle: (NSString *) Melder_peek32toCfstring (buttonText)];
203 [button setTarget: (id) my d_widget];
204 [button setAction: @selector (_guiCocoaButton_activateCallback:)];
205 //[button setAutoresizingMask: NSViewNotSizable];
206 if (flags & GuiButton_DEFAULT) {
207 [button setKeyEquivalent: @"\r"];
208 [[button window] setDefaultButtonCell: [button cell]]; // does nothing (and doesn't help flexible push buttons)
209 }
210 if (flags & GuiButton_CANCEL)
211 [button setKeyEquivalent: [NSString stringWithFormat: @"%c", 27]]; // Escape key
212 if (flags & GuiButton_ATTRACTIVE) {
213 //[button setKeyEquivalent: @"\r"]; // slow!
214 [button highlight: YES]; // lasts only till it's clicked!
215 //[button setBezelStyle: NSThickerSquareBezelStyle];
216 //[button setFont: [NSFont boldSystemFontOfSize: 14.0]];
217 }
218 #endif
219 if (flags & GuiButton_INSENSITIVEcxx . . $ `sys/Gui.h:469:9`!)
220 GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), false);
221 return me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).();
222 }
223
224 GuiButtoncxx . . $ GuiButton# GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom,
225 conststring32cxx . . $ conststring32# buttonText, GuiButton_ActivateCallbackcxx . . $ GuiButton_ActivateCallback# activateCallback, Thingcxx . . $ Thing# activateBoss, uint32cxx . . $ uint32# flags)
226 {
227 GuiButtoncxx . . $ GuiButton# me = GuiButton_createcxx . . $ GuiButton_create(653ed9987c16d9c1). (parent, left, right, top, bottom, buttonText, activateCallback, activateBoss, flags);
228 GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (me);
229 return me;
230 }
231
232 void GuiButton_setTextcxx . . $ GuiButton_setText(42a3d8c158c8d112). (GuiButtoncxx . . $ GuiButton# me, conststring32cxx . . $ conststring32# text /* cattable */) {
233 #if gtkcxx . . $ `sys/Gui.h:33:10`!
234 gtk_button_set_label (GTK_BUTTONcxx . . $ `<external>/6931860716604248467/gtkbutton.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), Melder_peek32to8 (text));
235 #elif motif
236 my d_widget -> name = Melder_dup_f (text);
237 _GuiNativeControl_setTitle (my d_widget);
238 #elif cocoa
239 [(NSButton *) my d_widget setTitle: (NSString *) Melder_peek32toCfstring (text)];
240 #endif
241 }
242
243 /* End of file GuiButton.cpp */