Debian Codegraph @

sys/Gui_messages.cpp

raw symbols SCIP
1 /* Gui_messages.cpp
2 *
3 * Copyright (C) 1992-2018,2020-2026 Paul Boersma,
4 * 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 <time.h>
21
22 #include <assert.h>
23 #ifdef _WIN32
24 #include <windows.h>
25 #endif
26
27 #include "melder.h"cxx . . $ `<file>/melder/melder.h`/
28 #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/
29 #include "Gui.h"cxx . . $ `<file>/sys/Gui.h`/
30 #include "Interpreter.h"cxx . . $ `<file>/sys/Interpreter.h`/
31 #include "Script.h"cxx . . $ `<file>/sys/Script.h`/
32 #include "Notebook.h"cxx . . $ `<file>/sys/Notebook.h`/
33 #include "GuiTrust.h"cxx . . $ `<file>/sys/GuiTrust.h`/
34
35 //#include <QuartzCore/CoreAnimation.h>
36
37 /********** Exported variable. **********/
38
39 static GuiWindowcxx . . $ GuiWindow# Melder_topShellcxx . . $ Melder_topShell.;
40
41 /********** PROGRESS **********/
42
43 static bool theProgressCancelledcxx . . $ theProgressCancelled. = false;
44
45 static bool waitWhileProgresscxx . . $ waitWhileProgress(d0c6e8fcabfc7568). (double progress, conststring32cxx . . $ conststring32# message, GuiDialogcxx . . $ GuiDialog# dia,
46 GuiProgressBarcxx . . $ GuiProgressBar# scale, GuiLabelcxx . . $ GuiLabel# label1, GuiLabelcxx . . $ GuiLabel# label2, GuiButtoncxx . . $ GuiButton# cancelButton)
47 {
48 #if gtkcxx . . $ `sys/Gui.h:33:10`!
49 (void) cancelButton; // the Interrupt button has its own callback
50 // Wait for all pending events to be processed. If anybody knows how to inspect GTK's
51 // event queue for specific events, dump the code here, please.
52 // Until then, the button click attaches a g_object data key named "pressed" to the cancelButton
53 // which this function reads out in order to tell whether interruption has occurred
54 while (gtk_events_pending ()) {
55 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"event pending");
56 gtk_main_iteration ();
57 }
58 #elif motif
59 XEvent event;
60 while (PeekMessage (& event, 0, 0, 0, PM_REMOVE)) {
61 if (event. message == WM_KEYDOWN) {
62 /*
63 * Ignore all key-down messages, except Escape.
64 */
65 if (LOWORD (event. wParam) == VK_ESCAPE) {
66 XtUnmanageChild (dia -> d_widget);
67 return false; // don't continue
68 }
69 } else if (event. message == WM_LBUTTONDOWN) {
70 /*
71 * Ignore all mouse-down messages, except click in Interrupt button.
72 */
73 GuiObject me = (GuiObject) GetWindowLongPtr (event. hwnd, GWLP_USERDATA);
74 if (me == cancelButton -> d_widget) {
75 XtUnmanageChild (dia -> d_widget);
76 return false; // don't continue
77 }
78 } else if (event. message != WM_SYSKEYDOWN) {
79 /*
80 * Process paint messages etc.
81 */
82 DispatchMessage (& event);
83 }
84 }
85 #elif cocoa
86 (void) cancelButton; // the Interrupt button has its own callback
87 #endif
88 if (progress >= 1.0) {
89 GuiThing_hidecxx . . $ GuiThing_hide(20e88c25f0ba841). (dia);
90 } else {
91 if (progress <= 0.0)
92 progress = 0.0;
93 GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (dia); // TODO: prevent raising to the front
94 const char32cxx . . $ char32# *newline = str32chrcxx . . $ str32chr(328a9ede0fba853a). (message, U'\n');
95 if (newline) {
96 static MelderStringcxx . . $ MelderString# buffer;
97 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& buffer, message);
98 buffer.stringcxx . . $ MelderString#string. [newline - message] = U'\0';
99 GuiLabel_setTextcxx . . $ GuiLabel_setText(8fd1a6a47d1f7702). (label1, buffer.stringcxx . . $ MelderString#string.);
100 buffer.stringcxx . . $ MelderString#string. [newline - message] = U'\n';
101 GuiLabel_setTextcxx . . $ GuiLabel_setText(8fd1a6a47d1f7702). (label2, buffer.stringcxx . . $ MelderString#string. + (newline - message) + 1);
102 } else {
103 GuiLabel_setTextcxx . . $ GuiLabel_setText(8fd1a6a47d1f7702). (label1, message);
104 GuiLabel_setTextcxx . . $ GuiLabel_setText(8fd1a6a47d1f7702). (label2, U"");
105 }
106 #if gtkcxx . . $ `sys/Gui.h:33:10`!
107 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"update the progress bar");
108 GuiProgressBar_setValuecxx . . $ GuiProgressBar_setValue(3b26fd3168755f19). (scale, progress);
109 while (gtk_events_pending ()) {
110 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"event pending");
111 gtk_main_iteration ();
112 }
113 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"check whether the cancel button has the \"pressed\" key set");
114 if (g_object_steal_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (cancelButton -> d_widget), "pressed")) {
115 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"the cancel button has been pressed");
116 return false; // don't continue
117 }
118 #elif motif
119 GuiProgressBar_setValue (scale, progress);
120 GdiFlush ();
121 #elif cocoa
122 GuiProgressBar_setValue (scale, progress);
123 //[scale -> d_cocoaProgressBar displayIfNeeded];
124 //[CATransaction flush];
125 GuiShell_drain (scale -> d_shell, true, true);
126 if (theProgressCancelled) {
127 theProgressCancelled = false;
128 return false;
129 }
130 #endif
131 }
132 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"continue");
133 return true;
134 }
135
136 static GuiButtoncxx . . $ GuiButton# theProgressCancelButtoncxx . . $ theProgressCancelButton. = nullptr;
137
138 #if gtkcxx . . $ `sys/Gui.h:33:10`! || cocoacxx . . $ `sys/Gui.h:35:10`!
139 static void progress_dia_closecxx . . $ progress_dia_close(97cddd01752945f6). (Thingcxx . . $ Thing# /* boss */) {
140 theProgressCancelledcxx . . $ theProgressCancelled. = true;
141 #if gtkcxx . . $ `sys/Gui.h:33:10`!
142 g_object_set_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (theProgressCancelButton -> d_widget), "pressed", (gpointer) 1);
143 #endif
144 }
145 static void progress_cancel_btn_presscxx . . $ progress_cancel_btn_press(704a595e5d1ebb71). (Thingcxx . . $ Thing# /* boss */, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) {
146 theProgressCancelledcxx . . $ theProgressCancelled. = true;
147 #if gtkcxx . . $ `sys/Gui.h:33:10`!
148 g_object_set_data (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (theProgressCancelButton -> d_widget), "pressed", (gpointer) 1);
149 #endif
150 }
151 #endif
152
153 static void _Melder_dia_initcxx . . $ _Melder_dia_init(71fcb1e4401b62fe). (GuiDialogcxx . . $ GuiDialog# *dia, GuiProgressBarcxx . . $ GuiProgressBar# *scale, GuiLabelcxx . . $ GuiLabel# *label1, GuiLabelcxx . . $ GuiLabel# *label2, GuiButtoncxx . . $ GuiButton# *cancelButton, bool hasMonitor) {
154 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the dialog");
155 *dia = GuiDialog_createcxx . . $ GuiDialog_create(9df51e4563bc0c17). (Melder_topShellcxx . . $ Melder_topShell., 200, 100, 500, hasMonitor ? 530 : 200, U"Work in progress",
156 #if gtkcxx . . $ `sys/Gui.h:33:10`! || cocoacxx . . $ `sys/Gui.h:35:10`!
157 progress_dia_closecxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr,
158 #else
159 nullptr, nullptr,
160 #endif
161 GuiDialog_Modalitycxx . . $ GuiDialog_Modality#::MODELESScxx . . $ GuiDialog_Modality#MODELESS.
162 );
163
164 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the labels");
165 *label1 = GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (*dia, 3, 503, 0, Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"label1", 0);
166 *label2 = GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (*dia, 3, 503, 30, 30 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"label2", 0);
167
168 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the scale");
169 *scale = GuiProgressBar_createShowncxx . . $ GuiProgressBar_createShown(4389e933ae743354). (*dia, 3, -3, 70, 110, 0);
170
171 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"creating the cancel button");
172 *cancelButton = GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (*dia, 0, 500, 170, 170 + Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!,
173 U"Interrupt",
174 #if gtkcxx . . $ `sys/Gui.h:33:10`!
175 progress_cancel_btn_presscxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr,
176 #elif cocoa
177 progress_cancel_btn_press, nullptr,
178 #else
179 nullptr, nullptr,
180 #endif
181 0
182 );
183 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"end");
184 }
185
186 static void gui_progresscxx . . $ gui_progress(cd1f800970345287). (double progress, conststring32cxx . . $ conststring32# message) {
187 static double lastTime;
188 static GuiDialogcxx . . $ GuiDialog# dia = nullptr;
189 static GuiProgressBarcxx . . $ GuiProgressBar# scale = nullptr;
190 static GuiLabelcxx . . $ GuiLabel# label1 = nullptr, label2 = nullptr;
191 const double now = Melder_clockcxx . . $ Melder_clock(31fa7155c10fdd13). ();
192 if (progress <= 0.0 || progress >= 1.0 ||
193 now - lastTime > 0.25) // this time step must be much longer than the null-event waiting time
194 {
195 if (! dia)
196 _Melder_dia_initcxx . . $ _Melder_dia_init(71fcb1e4401b62fe). (& dia, & scale, & label1, & label2, & theProgressCancelButtoncxx . . $ theProgressCancelButton., false);
197 if (! waitWhileProgresscxx . . $ waitWhileProgress(d0c6e8fcabfc7568). (progress, message, dia, scale, label1, label2, theProgressCancelButtoncxx . . $ theProgressCancelButton.))
198 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Interrupted!");
199 lastTime = now;
200 }
201 }
202
203 static autoGraphicscxx . . $ autoGraphics# graphicscxx . . $ graphics.;
204
205 static void gui_drawingarea_cb_exposecxx . . $ gui_drawingarea_cb_expose(27f28a6e9e502c36). (Thingcxx . . $ Thing# /* boss */, GuiDrawingArea_ExposeEventcxx . . $ GuiDrawingArea_ExposeEvent# /* event */) {
206 if (! graphicscxx . . $ graphics.)
207 return;
208 Graphics_playcxx . . $ Graphics_play(381ee972040461e0). (graphicscxx . . $ graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), graphicscxx . . $ graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
209 }
210
211 static void * gui_monitorcxx . . $ gui_monitor(7223d092b5bdba8d). (double progress, conststring32cxx . . $ conststring32# message) {
212 static double lastTime;
213 static GuiDialogcxx . . $ GuiDialog# dia = nullptr;
214 static GuiProgressBarcxx . . $ GuiProgressBar# scale = nullptr;
215 static GuiDrawingAreacxx . . $ GuiDrawingArea# drawingArea = nullptr;
216 static GuiButtoncxx . . $ GuiButton# cancelButton = nullptr;
217 static GuiLabelcxx . . $ GuiLabel# label1 = nullptr, label2 = nullptr;
218 const double now = Melder_clockcxx . . $ Melder_clock(31fa7155c10fdd13). ();
219 if (progress <= 0.0 || progress >= 1.0 ||
220 now - lastTime > 0.25) // this time step must be much longer than the null-event waiting time
221 {
222 if (! dia) {
223 _Melder_dia_initcxx . . $ _Melder_dia_init(71fcb1e4401b62fe). (& dia, & scale, & label1, & label2, & cancelButton, true);
224 drawingArea = GuiDrawingArea_createShowncxx . . $ GuiDrawingArea_createShown(5a210e61ba6a237d). (dia, 0, 500, 230, 530,
225 gui_drawingarea_cb_exposecxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptr, 0);
226 GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (dia);
227 graphicscxx . . $ graphics. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Graphics_create_xmdrawingareacxx . . $ Graphics_create_xmdrawingarea(51b1c75797a7dddf). (drawingArea);
228 }
229 if (progress <= 0.0 && graphicscxx . . $ graphics.) {
230 Graphics_clearRecordingcxx . . $ Graphics_clearRecording(2d838ed765120c5d). (graphicscxx . . $ graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
231 Graphics_startRecordingcxx . . $ Graphics_startRecording(ce6516af4677a324). (graphicscxx . . $ graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
232 Graphics_clearWscxx . . $ Graphics_clearWs(2d838ed765120c5d). (graphicscxx . . $ graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
233 }
234 if (! waitWhileProgresscxx . . $ waitWhileProgress(d0c6e8fcabfc7568). (progress, message, dia, scale, label1, label2, cancelButton))
235 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Interrupted!");
236 lastTime = now;
237 if (progress == 0.0)
238 return graphicscxx . . $ graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).();
239 }
240 return nullptr;
241 }
242
243 #if cocoacxx . . $ `sys/Gui.h:35:10`!
244 static void mac_message (NSAlertStyle macAlertType, conststring32 message32) {
245 static char16 message16 [4000];
246 const integer messageLength = Melder_length (message32);
247 uinteger j = 0;
248 for (int i = 0; i < messageLength && j <= 4000 - 3; i ++) {
249 char32 kar = message32 [i];
250 if (kar <= 0x00'FFFF) {
251 message16 [j ++] = (char16) kar;
252 } else if (kar <= 0x10'FFFF) {
253 kar -= 0x01'0000;
254 message16 [j ++] = (char16) (0x00'D800 | (kar >> 10));
255 message16 [j ++] = (char16) (0x00'DC00 | (kar & 0x00'03FF));
256 }
257 }
258 message16 [j] = u'\0'; // append null byte because we are going to search this string
259
260 /*
261 Split up the message between header (will appear in bold) and rest.
262 The split is done at the first line break, except if the first line ends in a colon,
263 in which case the split is done at the second line break.
264 */
265 const char16 *lineBreak = & message16 [0];
266 for (; *lineBreak != u'\0'; lineBreak ++)
267 if (*lineBreak == u'\n')
268 break;
269 if (*lineBreak == u'\n' && lineBreak - message16 > 0 && lineBreak [-1] == u':')
270 for (lineBreak ++; *lineBreak != u'\0'; lineBreak ++)
271 if (*lineBreak == u'\n')
272 break;
273 uinteger lengthOfFirstSentence = (uinteger) (lineBreak - message16);
274 /*
275 Create an alert dialog with an icon that is appropriate for the level.
276 */
277 NSAlert *alert = [[NSAlert alloc] init];
278 [alert setAlertStyle: macAlertType];
279 if (macAlertType == NSCriticalAlertStyle)
280 [alert addButtonWithTitle: @"Crash"];
281 /*
282 Add the header in bold.
283 */
284 NSString *header = [[NSString alloc] initWithCharacters: (const unichar *) & message16 [0] length: lengthOfFirstSentence]; // note: init can change the object pointer!
285 if (header) { // make this very safe, because we can be at error time or at fatal time
286 [alert setMessageText: header];
287 [header release];
288 }
289 /*
290 Add the rest of the message in small type.
291 */
292 if (lengthOfFirstSentence < j) {
293 NSString *rest = [[NSString alloc] initWithCharacters: (const unichar *) & lineBreak [1] length: j - 1 - lengthOfFirstSentence];
294 if (rest) { // make this very safe, because we can be at error time or at crash time
295 [alert setInformativeText: rest];
296 [rest release];
297 }
298 }
299 /*
300 Display the alert dialog and synchronously wait for the user to click OK.
301 */
302 [alert runModal];
303 [alert release];
304 }
305 #endif
306
307 #define theMessageFund_SIZEcxx . . $ `sys/Gui_messages.cpp:307:9`! 100'000
308 static char * theMessageFundcxx . . $ theMessageFund. = nullptr;
309
310 static void gui_crashcxx . . $ gui_crash(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# message) {
311 freecxx . . $ free(bd21765a0afc8e3c). (theMessageFundcxx . . $ theMessageFund.);
312 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"PRAAT CRASH MESSAGE:\n", message, U"\n(END OF PRAAT CRASH MESSAGE)");
313 #if gtkcxx . . $ `sys/Gui.h:33:10`!
314 GuiObjectcxx . . $ GuiObject# dialog = gtk_message_dialog_new (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (Melder_topShell -> d_gtkWindow), GTK_DIALOG_DESTROY_WITH_PARENT,
315 GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE, "%s", Melder_peek32to8 (message));
316 gtk_dialog_add_buttons (GTK_DIALOGcxx . . $ `<external>/3867786087843934573/gtkdialog.h:90:9`! (dialog), "Crash", GTK_RESPONSE_OK, nullptr);
317 gtk_dialog_run (GTK_DIALOGcxx . . $ `<external>/3867786087843934573/gtkdialog.h:90:9`! (dialog));
318 gtk_widget_destroy (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (dialog));
319 #elif motif
320 MessageBox (nullptr, Melder_peek32toW (message), L"Crashing bug", MB_OK | MB_TOPMOST | MB_ICONSTOP);
321 #elif cocoa
322 mac_message (NSAlertStyleCritical, message);
323 SysError (11);
324 #endif
325 }
326
327 static void gui_errorcxx . . $ gui_error(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# message) {
328 const bool memoryIsLow = str32strcxx . . $ str32str(2de17cd8f7c584a6). (message, U"Out of memory");
329 if (memoryIsLow)
330 freecxx . . $ free(bd21765a0afc8e3c). (theMessageFundcxx . . $ theMessageFund.);
331 /*
332 It is not impossible that the program crashes during `gtk_dialog_run` or `MessageBox` or `runModal`,
333 especially if these are called at expose time.
334 Write the message to stdout just in case.
335 */
336 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"PRAAT ERROR MESSAGE:\n", message, U"(END OF PRAAT ERROR MESSAGE)");
337 #if gtkcxx . . $ `sys/Gui.h:33:10`!
338 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"create dialog");
339 GuiObjectcxx . . $ GuiObject# dialog = gtk_message_dialog_new (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (Melder_topShell -> d_gtkWindow), GTK_DIALOG_DESTROY_WITH_PARENT,
340 GTK_MESSAGE_WARNING, GTK_BUTTONS_OK, "%s", Melder_peek32to8 (message));
341 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"run dialog");
342 gtk_dialog_run (GTK_DIALOGcxx . . $ `<external>/3867786087843934573/gtkdialog.h:90:9`! (dialog));
343 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"destroy dialog");
344 gtk_widget_destroy (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (dialog));
345 #elif motif
346 MessageBox (nullptr, Melder_peek32toW (message), L"Message", MB_OK | MB_TOPMOST | MB_ICONWARNING); // or (HWND) XtWindow ((GuiObject) Melder_topShell)
347 #elif cocoa
348 mac_message (NSAlertStyleWarning, message);
349 #endif
350 if (memoryIsLow) {
351 theMessageFundcxx . . $ theMessageFund. = (char *) malloccxx . . $ malloc(9f008b2a9698428b). (theMessageFund_SIZEcxx . . $ `sys/Gui_messages.cpp:307:9`!);
352 if (! theMessageFundcxx . . $ theMessageFund.) {
353 #if gtkcxx . . $ `sys/Gui.h:33:10`!
354 GuiObjectcxx . . $ GuiObject# dialog = gtk_message_dialog_new (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (Melder_topShell -> d_gtkWindow), GTK_DIALOG_DESTROY_WITH_PARENT,
355 GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Praat is very low on memory.\nSave your work and quit Praat.\nIf you don't do that, Praat may crash.");
356 gtk_dialog_run (GTK_DIALOGcxx . . $ `<external>/3867786087843934573/gtkdialog.h:90:9`! (dialog));
357 gtk_widget_destroy (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (dialog));
358 #elif motif
359 MessageBox (nullptr, L"Praat is very low on memory.\nSave your work and quit Praat.\nIf you don't do that, Praat may crash.", L"Message", MB_OK);
360 #elif cocoa
361 mac_message (NSAlertStyleCritical, U"Praat is very low on memory.\nSave your work and quit Praat.\nIf you don't do that, Praat may crash.");
362 #endif
363 }
364 }
365 }
366
367 static void gui_warningcxx . . $ gui_warning(ff00d524ab0355ec). (conststring32cxx . . $ conststring32# message) {
368 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"PRAAT WARNING MESSAGE:\n", message, U"\n(END OF PRAAT WARNING MESSAGE)");
369 #if gtkcxx . . $ `sys/Gui.h:33:10`!
370 GuiObjectcxx . . $ GuiObject# dialog = gtk_message_dialog_new (GTK_WINDOWcxx . . $ `<external>/3777575239456597881/gtkwindow.h:40:9`! (Melder_topShell -> d_gtkWindow), GTK_DIALOG_DESTROY_WITH_PARENT,
371 GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", Melder_peek32to8 (message));
372 gtk_dialog_run (GTK_DIALOGcxx . . $ `<external>/3867786087843934573/gtkdialog.h:90:9`! (dialog));
373 gtk_widget_destroy (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (dialog));
374 #elif motif
375 MessageBox (nullptr, Melder_peek32toW (message), L"Warning", MB_OK | MB_TOPMOST | MB_ICONINFORMATION);
376 #elif cocoa
377 mac_message (NSAlertStyleInformational, message);
378 #endif
379 }
380
381 static void gui_trustcxx . . $ gui_trust(d5a4f5531b36fe83). (void *void_interpreter, conststring32cxx . . $ conststring32# action) {
382 Interpretercxx . . $ Interpreter# interpreter = (Interpretercxx . . $ Interpreter#) void_interpreter;
383 if (interpreter) {
384 Scriptcxx . . $ Script# script = interpreter -> scriptReferencecxx . . $ structInterpreter#scriptReference.;
385 Notebookcxx . . $ Notebook# notebook = interpreter -> notebookReferencecxx . . $ structInterpreter#notebookReference.;
386 if (script && script -> trustedcxx . . $ structScript#trusted. || notebook && notebook -> trustedcxx . . $ structNotebook#trusted.)
387 return; // the request should be granted
388 if (Melder_appVersioncxx . . $ Melder_appVersion(da6335ded91d79c2).() < 7000)
389 return; // no trust checking before Praat 7.0
390 conststring32cxx . . $ conststring32# paragraphs [1+5] = { };
391 if (script) {
392 paragraphs [1] = U"The script";
393 paragraphs [2] = Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"“", script -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"”");
394 } else if (notebook) {
395 paragraphs [1] = U"The notebook";
396 paragraphs [2] = Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"“", notebook -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"”");
397 } else
398 paragraphs [1] = U"Your untitled script or notebook";
399 paragraphs [3] = U"requests permission to:";
400 paragraphs [4] = action;
401 conststring32cxx . . $ conststring32# option1 = U"CANCEL\n(because I don’t want the requested action to happen)";
402 conststring32cxx . . $ conststring32# option2 =
403 script ?
404 U"Yes, I allow this script to perform the action that it requests\n(and ask me again next time)"
405 : notebook ?
406 U"Yes, I allow this notebook to perform the action that it requests\n(and ask me again next time)"
407 :
408 U"Yes, I allow this script or notebook to perform the action that it requests\n(and ask me again next time)";
409 conststring32cxx . . $ conststring32# option3 =
410 script ?
411 U"Yes, and I even allow this script to CONTROL MY COMPUTER from now on (i.e. to perform any action,\n"
412 "including saving, deleting, calling system commands, and internetting), because I FULLY TRUST\n"
413 "the skills and intentions of the authors of the script AND of all the scripts called by it."
414 : notebook ?
415 U"Yes, and I even allow this notebook to CONTROL MY COMPUTER from now on (i.e. to perform any action,\n"
416 "including saving, deleting, calling system commands, and internetting), because I FULLY TRUST\n"
417 "the skills and intentions of the authors of the notebook AND of all the scripts and notebooks called by it."
418 :
419 U"(The option to allow this script or notebook to control your computer will be available\n"
420 "after you save the script or notebook. Until then, clicking here will allow only this one action.)";
421 const integercxx . . $ integer# buttonClicked = GuiTrust_getcxx . . $ GuiTrust_get(46458cd14d966cec). (nullptr, nullptr,
422 paragraphs [1], paragraphs [2], paragraphs [3], paragraphs [4], paragraphs [5],
423 option1, option2, option3, nullptr, nullptr, interpreter
424 );
425 if (buttonClicked == 2)
426 return; // allow this one action
427 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (buttonClicked == 3);
428 if (script)
429 script -> trustedcxx . . $ structScript#trusted. = true;
430 else if (notebook)
431 notebook -> trustedcxx . . $ structNotebook#trusted. = true;
432 }
433 }
434
435 void Gui_injectMessageProcscxx . . $ Gui_injectMessageProcs(20efc9fbfef198b1). (GuiWindowcxx . . $ GuiWindow# parent) {
436 theMessageFundcxx . . $ theMessageFund. = (char *) malloccxx . . $ malloc(9f008b2a9698428b). (theMessageFund_SIZEcxx . . $ `sys/Gui_messages.cpp:307:9`!);
437 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`! (theMessageFund);
438 Melder_topShellcxx . . $ Melder_topShell. = parent;
439 Melder_setCrashProccxx . . $ Melder_setCrashProc(f441b548652834d9). (gui_crashcxx . . $ gui_crash(ff00d524ab0355ec).);
440 Melder_setErrorProccxx . . $ Melder_setErrorProc(f441b548652834d9). (gui_errorcxx . . $ gui_error(ff00d524ab0355ec).);
441 Melder_setWarningProccxx . . $ Melder_setWarningProc(f441b548652834d9). (gui_warningcxx . . $ gui_warning(ff00d524ab0355ec).);
442 Melder_setProgressProccxx . . $ Melder_setProgressProc(9bcb6c487d44e509). (gui_progresscxx . . $ gui_progress(cd1f800970345287).);
443 Melder_setMonitorProccxx . . $ Melder_setMonitorProc(1e842e40862c4d17). (gui_monitorcxx . . $ gui_monitor(7223d092b5bdba8d).);
444 Melder_setTrustProccxx . . $ Melder_setTrustProc(4ba6d3c60ee7960a). (gui_trustcxx . . $ gui_trust(d5a4f5531b36fe83).);
445 }
446
447 /* End of file Gui_messages.cpp */