Debian Codegraph @

sys/GuiText.cpp

raw symbols SCIP
1 /* GuiText.cpp
2 *
3 * Copyright (C) 1993-2026 Paul Boersma, 2013 Tom Naughton
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 3 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 #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/
20 #include <locale.h>
21
22 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (GuiText, GuiControl, 0);
23
24 #if motifcxx . . $ `sys/Gui.h:34:10`!
25 #define iam_text \
26 Melder_assert (widget -> widgetClass == xmTextWidgetClass); \
27 GuiText me = (GuiText) widget -> userData
28 #else
29 #define iam_textcxx . . $ `sys/GuiText.cpp:29:10`! \
30 GuiText me = (GuiText) _GuiObject_getUserData (widget)
31 #endif
32
33 #if motifcxx . . $ `sys/Gui.h:34:10`!
34
35 static HFONT font10, font12, font14, font18, font24;
36
37 /*
38 * (1) KEYBOARD FOCUS
39 *
40 * (1.1) In Motif, the native GUI system handles all that we want:
41 * every window with text widgets has one text focus widget,
42 * which will receive global text focus when the window is activated.
43 * The global text focus is visible to the user.
44 * The focus changes whenever the user clicks in a text widget that does not have focus.
45 *
46 * (1.2) In Windows, the native GUI system handles almost all of the above.
47 * The exception is that windows have no own text focus widgets;
48 * there is only a single global text focus. This means that when the user
49 * clicks on a non-active window, none of the text widgets in this window
50 * will automatically receive text focus. Yet, the user expects automatic text focus behaviour
51 * (click a window, then type immediately) in text edit windows (like Praat's script editor)
52 * and in windows that have a single text widget (like Praat's TextGrid editor).
53 * For this reason, the WM_COMMAND message handler in Gui.c intercepts the EN_SETFOCUS notification.
54 * This handler calls _GuiText_handleFocusReception (), which records
55 * the new text focus widget in its window. When a window is activated,
56 * we set the global focus explicitly to this window's own text focus widget,
57 * by calling _GuiText_setTheTextFocus ().
58 *
59 * (1.3) On Macintosh, we have to handle all of this explicitly.
60 *
61 * (1.4) On Win and Mac, we implement a feature not available in Motif:
62 * the use of Command-X, Command-C, and Command-V to cut, copy, and paste in text widgets,
63 * even in dialogs, where there are no menus for which these three commands could be keyboard shortcuts.
64 * For this reason, _GuiText_handleFocusReception () also stores the global text focus,
65 * so that the keyboard shortcut handler in Gui.c knows what widget to cut from, copy from, or paste into.
66 * (It is true that Windows itself stores the global text focus, but this is not always a text widget;
67 * we want it to always be a text widget, e.g. in the TextGrid editor it is always the text widget,
68 * never the drawing area, that receives key strokes. In Motif, we will have to program this text
69 * preference explicitly; see the discussion in FunctionEditor.cpp.)
70 */
71
72 void _GuiText_handleFocusReception (GuiObject widget) {
73 /*
74 * On Windows, this is called:
75 * 1. on a user click in a text widget: WM_COMMAND -> EN_SETFOCUS;
76 * 2. on window activation: _GuiText_setTheTextFocus () -> SetFocus -> WM_COMMAND -> EN_SETFOCUS;
77 * 3. on a user click in a push button or toggle button, which would otherwise draw the
78 * focus away from the text widgets: WM_COMMAND -> _GuiText_setTheTextFocus ().
79 *
80 * On Macintosh, this is called:
81 * 1. on a user click in a text widget: handleControlClick & handleTextEditClick -> _GuiText_setTheTextFocus ();
82 * 2. on window activation: handleActivateEvent -> _GuiText_setTheTextFocus ().
83 */
84 widget -> shell -> textFocus = widget; /* see (1.2) */
85 theGui.textFocus = widget; /* see (1.4) */
86 }
87
88 void _GuiText_handleFocusLoss (GuiObject widget) {
89 /*
90 * me is going out of sight;
91 * it must stop having global focus.
92 */
93 /*
94 * On Windows, this is called:
95 * 1. on window deactivation
96 * 2. on window closure
97 * 3. on text unmanaging
98 * 4. on window unmanaging
99 *
100 * On Macintosh, this is called:
101 * 1. on window deactivation
102 * 2. on window closure
103 * 3. on text unmanaging
104 * 4. on window unmanaging
105 */
106 if (widget == theGui.textFocus)
107 theGui.textFocus = nullptr;
108 }
109
110 void _GuiText_setTheTextFocus (GuiObject widget) {
111 if (! widget || theGui.textFocus == widget
112 || ! widget -> managed) return; // perhaps not-yet-managed; test: open Praat's DataEditor with a Sound, then type
113 #if gtk
114 gtk_widget_grab_focus (GTK_WIDGET (widget)); // not used: gtk is not 1 when motif is 1
115 #elif motif
116 SetFocus (widget -> window); // will send an EN_SETFOCUS notification, which will call _GuiText_handleFocusReception ()
117 #endif
118 }
119
120 /*
121 * CHANGE NOTIFICATION
122 */
123 void _GuiText_handleValueChanged (GuiObject widget) {
124 iam_text;
125 if (my d_changedCallback) {
126 struct structGuiTextEvent event { me };
127 my d_changedCallback (my d_changedBoss, & event);
128 }
129 }
130
131 void _GuiText_unmanage (GuiObject widget) {
132 _GuiText_handleFocusLoss (widget);
133 _GuiNativeControl_hide (widget);
134 /*
135 * The caller will set the unmanage flag to zero, and remanage the parent.
136 */
137 }
138
139 /*
140 * VISIBILITY
141 */
142
143 void _GuiWinText_destroy (GuiObject widget) {
144 if (widget == theGui.textFocus)
145 theGui.textFocus = nullptr; // remove dangling reference
146 if (widget == widget -> shell -> textFocus)
147 widget -> shell -> textFocus = nullptr; // remove dangling reference
148 iam_text;
149 DestroyWindow (widget -> window);
150 forget (me); // NOTE: my widget is not destroyed here
151 }
152 void _GuiWinText_map (GuiObject widget) {
153 iam_text;
154 ShowWindow (widget -> window, SW_SHOW);
155 }
156
157 static integer NativeText_getLength (GuiObject widget) {
158 return Edit_GetTextLength (widget -> window); // in UTF-16 code units
159 }
160
161 /*
162 * SELECTION
163 */
164
165 static bool NativeText_getSelectionRange (GuiObject widget, integer *out_left, integer *out_right) {
166 Melder_assert (MEMBER (widget, Text));
167 DWORD left, right;
168 SendMessage (widget -> window, EM_GETSEL, (WPARAM) & left, (LPARAM) & right);
169 if (out_left) *out_left = left;
170 if (out_right) *out_right = right;
171 return right > left;
172 }
173
174 /*
175 * PACKAGE
176 */
177
178 void _GuiText_init () {
179 }
180
181 void _GuiText_exit () {
182 }
183
184 #endif
185
186 #if gtkcxx . . $ `sys/Gui.h:33:10`! || motifcxx . . $ `sys/Gui.h:34:10`!
187 /*
188 * Undo/Redo history functions
189 */
190
191 static void _GuiText_deletecxx . . $ _GuiText_delete(f75b42a5630b157f). (GuiObjectcxx . . $ GuiObject# widget, int from_pos, int to_pos) {
192 #if gtkcxx . . $ `sys/Gui.h:33:10`!
193 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
194 gtk_editable_delete_text (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (widget), from_pos, to_pos);
195 } else {
196 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (widget));
197 GtkTextIter from_it, to_it;
198 gtk_text_buffer_get_iter_at_offset (buffer, & from_it, from_pos);
199 gtk_text_buffer_get_iter_at_offset (buffer, & to_it, to_pos);
200 gtk_text_buffer_delete_interactive (buffer, & from_it, & to_it,
201 gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (widget)));
202 gtk_text_buffer_place_cursor (buffer, & to_it);
203 }
204 #elif motif
205 #endif
206 }
207
208 static void _GuiText_insertcxx . . $ _GuiText_insert(dae3cef7367273a9). (GuiObjectcxx . . $ GuiObject# widget, int from_pos, int to_pos, const history_datacxx . . $ history_data# text) {
209 #if gtkcxx . . $ `sys/Gui.h:33:10`!
210 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
211 gint from_pos_gint = from_pos;
212 gtk_editable_insert_text (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (widget), text, to_pos - from_pos, & from_pos_gint);
213 } else {
214 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (widget));
215 GtkTextIter it;
216 gtk_text_buffer_get_iter_at_offset (buffer, & it, from_pos);
217 gtk_text_buffer_insert_interactive (buffer, & it, text, to_pos - from_pos,
218 gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (widget)));
219 gtk_text_buffer_get_iter_at_offset (buffer, & it, to_pos);
220 gtk_text_buffer_place_cursor (buffer, & it);
221 }
222 #elif motif
223 #endif
224 }
225
226 /* Tests the previous elements of the history for mergability with the one to insert given via parameters.
227 * If successful, it returns a pointer to the last valid entry in the merged history list, otherwise
228 * returns nullptr.
229 * Specifically the function expands the previous insert/delete event(s)
230 * - with the current, if current also is an insert/delete event and the ranges of previous and current event match
231 * - with the previous delete and current insert event, in case the ranges of both event-pairs respectively match
232 */
233 static history_entrycxx . . $ history_entry# * history_addAndMergecxx . . $ history_addAndMerge(3aacf034df226b46). (GuiTextcxx . . $ GuiText# me, history_datacxx . . $ history_data# text_new, integercxx . . $ integer# first, integercxx . . $ integer# last, bool deleted) {
234 history_entrycxx . . $ history_entry# *he = nullptr;
235
236 if (! mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.)
237 return nullptr;
238
239 if (mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->type_delcxx . . $ history_entry#type_del. == deleted) {
240 // extend the last history event by this one
241 if (mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->firstcxx . . $ history_entry#first. == last) {
242 // most common for backspace key presses
243 he = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
244 text_new = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2). (text_new, sizeof (*text_new) * (he->lastcxx . . $ history_entry#last. - first + 1));
245 memcpy (text_new + last - first, he->textcxx . . $ history_entry#text., sizeof (*text_new) * (he->lastcxx . . $ history_entry#last. - he->firstcxx . . $ history_entry#first. + 1));
246 freecxx . . $ free(bd21765a0afc8e3c). (he->textcxx . . $ history_entry#text.);
247 he->textcxx . . $ history_entry#text. = text_new;
248 he->firstcxx . . $ history_entry#first. = first;
249
250 } else if (mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->lastcxx . . $ history_entry#last. == first) {
251 // most common for ordinary text insertion
252 he = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
253 he->textcxx . . $ history_entry#text. = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2). (he->textcxx . . $ history_entry#text., sizeof (*he->textcxx . . $ history_entry#text.) * (last - he->firstcxx . . $ history_entry#first. + 1));
254 memcpy (he->textcxx . . $ history_entry#text. + he->lastcxx . . $ history_entry#last. - he->firstcxx . . $ history_entry#first., text_new, sizeof (*he->textcxx . . $ history_entry#text.) * (last - first + 1));
255 freecxx . . $ free(bd21765a0afc8e3c). (text_new);
256 he->lastcxx . . $ history_entry#last. = last;
257
258 } else if (deleted && mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->firstcxx . . $ history_entry#first. == first) {
259 // most common for delete key presses
260 he = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
261 he->textcxx . . $ history_entry#text. = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2). (he->textcxx . . $ history_entry#text., sizeof (*he->textcxx . . $ history_entry#text.) * (last - first + he->lastcxx . . $ history_entry#last. - he->firstcxx . . $ history_entry#first. + 1));
262 memcpy (he->textcxx . . $ history_entry#text. + he->lastcxx . . $ history_entry#last. - he->firstcxx . . $ history_entry#first., text_new, sizeof (*he->textcxx . . $ history_entry#text.) * (last - first + 1));
263 freecxx . . $ free(bd21765a0afc8e3c). (text_new);
264 he->lastcxx . . $ history_entry#last. = last + he->lastcxx . . $ history_entry#last. - he->firstcxx . . $ history_entry#first.;
265 }
266 } else {
267 // prev->type_del != deleted, no simple expansion possible, check for double expansion
268 if (! deleted && mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->prevcxx . . $ history_entry#prev. && mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->prevcxx . . $ history_entry#prev.->prevcxx . . $ history_entry#prev.) {
269 history_entrycxx . . $ history_entry# *del_one = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
270 history_entrycxx . . $ history_entry# *ins_mult = del_one->prevcxx . . $ history_entry#prev.;
271 history_entrycxx . . $ history_entry# *del_mult = ins_mult->prevcxx . . $ history_entry#prev.;
272 integercxx . . $ integer# from1 = del_mult->firstcxx . . $ history_entry#first., to1 = del_mult->lastcxx . . $ history_entry#last.;
273 integercxx . . $ integer# from2 = ins_mult->firstcxx . . $ history_entry#first., to2 = ins_mult->lastcxx . . $ history_entry#last.;
274 integercxx . . $ integer# from3 = del_one->firstcxx . . $ history_entry#first., to3 = del_one->lastcxx . . $ history_entry#last.;
275 if (from3 == first && to3 == last && from2 == from1 && to2 == to1 && to1 == first &&
276 ! ins_mult->type_delcxx . . $ history_entry#type_del. && del_mult->type_delcxx . . $ history_entry#type_del.) {
277 // most common for overwriting text
278 /* So the layout is as follows:
279 *
280 * del_mult ins_mult del_one current (parameters)
281 * [del, from1, to1, "uvw"] [ins, from1, to1, "abc"] [del, to1, to3, "x"] [ins, to1, to3, "d"]
282 * n >= 1 characters n characters 1 character 1 character
283 *
284 * So merge those four events into two events by expanding del_mult by del_one and ins_mult by current */
285 del_mult->textcxx . . $ history_entry#text. = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2). (del_mult->textcxx . . $ history_entry#text., sizeof (*del_mult->textcxx . . $ history_entry#text.) * (to3 - from1 + 1));
286 ins_mult->textcxx . . $ history_entry#text. = (char *) realloccxx . . $ realloc(42b2a9dd8f084bf2). (ins_mult->textcxx . . $ history_entry#text., sizeof (*ins_mult->textcxx . . $ history_entry#text.) * (to3 - from1 + 1));
287 memcpy (del_mult->textcxx . . $ history_entry#text. + to1 - from1, del_one->textcxx . . $ history_entry#text., sizeof (*del_mult->textcxx . . $ history_entry#text.) * (to3 - to1 + 1));
288 memcpy (ins_mult->textcxx . . $ history_entry#text. + to1 - from1, text_new , sizeof (*del_mult->textcxx . . $ history_entry#text.) * (to3 - to1 + 1));
289 del_mult->lastcxx . . $ history_entry#last. = to3;
290 ins_mult->lastcxx . . $ history_entry#last. = to3;
291 freecxx . . $ free(bd21765a0afc8e3c). (del_one->textcxx . . $ history_entry#text.);
292 freecxx . . $ free(bd21765a0afc8e3c). (del_one);
293 freecxx . . $ free(bd21765a0afc8e3c). (text_new);
294 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. = he = ins_mult;
295 }
296 }
297 }
298
299 return he;
300 }
301
302 /* Inserts a new history action, thereby removing any remaining 'redo' steps;
303 * text_new a newly allocated string that will be freed by a history function
304 * (history_add or history_clear)
305 */
306 static void history_addcxx . . $ history_add(6ba78be973af3ee1). (GuiTextcxx . . $ GuiText# me, history_datacxx . . $ history_data# text_new, integercxx . . $ integer# first, integercxx . . $ integer# last, bool deleted) {
307
308 // delete all newer entries; from here on there is no 'Redo' until the next 'Undo' is performed
309 history_entrycxx . . $ history_entry# *old_hnext = mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next., *hnext;
310 while (old_hnext) {
311 hnext = old_hnext->nextcxx . . $ history_entry#next.;
312 freecxx . . $ free(bd21765a0afc8e3c). (old_hnext->textcxx . . $ history_entry#text.);
313 freecxx . . $ free(bd21765a0afc8e3c). (old_hnext);
314 old_hnext = hnext;
315 }
316 mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next. = nullptr;
317
318 history_entrycxx . . $ history_entry# *he = history_addAndMergecxx . . $ history_addAndMerge(3aacf034df226b46). (me, text_new, first, last, deleted);
319 if (! he) {
320 he = (history_entrycxx . . $ history_entry# *) malloccxx . . $ malloc(9f008b2a9698428b). (sizeof *he);
321 he->firstcxx . . $ history_entry#first. = first;
322 he->lastcxx . . $ history_entry#last. = last;
323 he->type_delcxx . . $ history_entry#type_del. = deleted;
324 he->textcxx . . $ history_entry#text. = text_new;
325
326 he->prevcxx . . $ history_entry#prev. = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
327 he->nextcxx . . $ history_entry#next. = nullptr;
328 if (mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.)
329 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->nextcxx . . $ history_entry#next. = he;
330 }
331 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. = he;
332 he->nextcxx . . $ history_entry#next. = nullptr;
333
334 if (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item.) GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item., true);
335 if (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item.) GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item., false);
336 }
337
338 static bool history_has_undocxx . . $ history_has_undo(67d3b309776c224d). (GuiTextcxx . . $ GuiText# me) {
339 return !! mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
340 }
341
342 static bool history_has_redocxx . . $ history_has_redo(67d3b309776c224d). (GuiTextcxx . . $ GuiText# me) {
343 return !! mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next.;
344 }
345
346 static void history_docxx . . $ history_do(365f281d9ebaace7). (GuiTextcxx . . $ GuiText# me, bool undo) {
347 history_entrycxx . . $ history_entry# *he = undo ? mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. : mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next.;
348 if (! he) // TODO: this function should not be called in that case
349 return;
350
351 mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change. = 1;
352 if (undo ^ he->type_delcxx . . $ history_entry#type_del.) {
353 _GuiText_deletecxx . . $ _GuiText_delete(f75b42a5630b157f). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., he->firstcxx . . $ history_entry#first., he->lastcxx . . $ history_entry#last.);
354 } else {
355 _GuiText_insertcxx . . $ _GuiText_insert(dae3cef7367273a9). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., he->firstcxx . . $ history_entry#first., he->lastcxx . . $ history_entry#last., he->textcxx . . $ history_entry#text.);
356 }
357 mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change. = 0;
358
359 if (undo) {
360 mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next. = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
361 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.->prevcxx . . $ history_entry#prev.;
362 } else {
363 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. = mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next.;
364 mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next. = mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next.->nextcxx . . $ history_entry#next.;
365 }
366
367 if (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item.) GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item., history_has_undocxx . . $ history_has_undo(67d3b309776c224d). (me));
368 if (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item.) GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item., history_has_redocxx . . $ history_has_redo(67d3b309776c224d). (me));
369 }
370
371 static void history_clearcxx . . $ history_clear(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
372 history_entrycxx . . $ history_entry# *h1, *h2;
373
374 h1 = mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev.;
375 while (h1) {
376 h2 = h1->prevcxx . . $ history_entry#prev.;
377 freecxx . . $ free(bd21765a0afc8e3c). (h1->textcxx . . $ history_entry#text.);
378 freecxx . . $ free(bd21765a0afc8e3c). (h1);
379 h1 = h2;
380 }
381 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. = nullptr;
382
383 h1 = mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next.;
384 while (h1) {
385 h2 = h1->nextcxx . . $ history_entry#next.;
386 freecxx . . $ free(bd21765a0afc8e3c). (h1->textcxx . . $ history_entry#text.);
387 freecxx . . $ free(bd21765a0afc8e3c). (h1);
388 h1 = h2;
389 }
390 mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next. = nullptr;
391
392 if (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item.) GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item., false);
393 if (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item.) GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item., false);
394 }
395 #endif
396
397 /*
398 * CALLBACKS
399 */
400
401 #if gtkcxx . . $ `sys/Gui.h:33:10`!
402 static void _GuiGtkEntry_history_delete_cbcxx . . $ _GuiGtkEntry_history_delete_cb(da13fd2a7597ea74). (GtkEditable *ed, gint from, gint to, gpointer void_me) {
403 iamcxx . . $ `melder/melder.h:50:9`! (GuiText);
404 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin");
405 if (mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change.) return;
406 history_addcxx . . $ history_add(6ba78be973af3ee1). (me, gtk_editable_get_chars (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (ed), from, to), from, to, 1);
407 }
408
409 static void _GuiGtkEntry_history_insert_cbcxx . . $ _GuiGtkEntry_history_insert_cb(487063c0c27fb77e). (GtkEditable *ed, gchar *utf8_text, gint len, gint *from, gpointer void_me) {
410 (void) ed;
411 iamcxx . . $ `melder/melder.h:50:9`! (GuiText);
412 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin");
413 if (mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change.) return;
414 gchar *text = (gchar *) malloccxx . . $ malloc(9f008b2a9698428b). (sizeof (gchar) * (len + 1));
415 strcpy (text, utf8_text);
416 history_addcxx . . $ history_add(6ba78be973af3ee1). (me, text, *from, *from + len, 0);
417 }
418
419 static void _GuiGtkTextBuf_history_delete_cbcxx . . $ _GuiGtkTextBuf_history_delete_cb(36ebf68ab89425dd). (GtkTextBuffer *buffer, GtkTextIter *from, GtkTextIter *to, gpointer void_me) {
420 iamcxx . . $ `melder/melder.h:50:9`! (GuiText);
421 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin");
422 if (mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change.) return;
423 int from_pos = gtk_text_iter_get_offset (from);
424 int to_pos = gtk_text_iter_get_offset (to);
425 history_addcxx . . $ history_add(6ba78be973af3ee1). (me, gtk_text_buffer_get_text (buffer, from, to, false), from_pos, to_pos, 1);
426 }
427
428 static void _GuiGtkTextBuf_history_insert_cbcxx . . $ _GuiGtkTextBuf_history_insert_cb(fe27d4ef0bd8e65b). (GtkTextBuffer *buffer, GtkTextIter *from, gchar *utf8_text, gint len, gpointer void_me) {
429 (void) buffer;
430 iamcxx . . $ `melder/melder.h:50:9`! (GuiText);
431 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin");
432 if (mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change.) return;
433 int from_pos = gtk_text_iter_get_offset (from);
434 gchar *text = (gchar *) malloccxx . . $ malloc(9f008b2a9698428b). (sizeof (gchar) * (len + 1));
435 strcpy (text, utf8_text);
436 history_addcxx . . $ history_add(6ba78be973af3ee1). (me, text, from_pos, from_pos + len, 0);
437 }
438
439 static void _GuiGtkText_valueChangedCallbackcxx . . $ _GuiGtkText_valueChangedCallback(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# widget, gpointer void_me) {
440 iamcxx . . $ `melder/melder.h:50:9`! (GuiText);
441 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin");
442 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (me);
443 if (mycxx . . $ `melder/melder.h:44:9`! d_changedCallbackcxx . . $ structGuiText#d_changedCallback.) {
444 struct structGuiTextEventcxx . . $ structGuiTextEvent# event { me };
445 mycxx . . $ `melder/melder.h:44:9`! d_changedCallbackcxx . . $ structGuiText#d_changedCallback. (cxx . . $ MelderCallback#`operator()`(e7ade0e2880b4e44).mycxx . . $ `melder/melder.h:44:9`! d_changedBosscxx . . $ structGuiText#d_changedBoss., & event);
446 }
447 }
448
449 static void _GuiGtkText_destroyCallbackcxx . . $ _GuiGtkText_destroyCallback(6c58c5e2437d25a2). (GuiObjectcxx . . $ GuiObject# widget, gpointer void_me) {
450 (void) widget;
451 iamcxx . . $ `melder/melder.h:50:9`! (GuiText);
452 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (me);
453 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! classInfo == classGuiText);
454 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"begin");
455 if (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item.) {
456 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"undo");
457 //g_object_unref (my d_undo_item -> d_widget);
458 }
459 if (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item.) {
460 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"redo");
461 //g_object_unref (my d_redo_item -> d_widget);
462 }
463 mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item. = nullptr;
464 mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item. = nullptr;
465 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"history");
466 history_clearcxx . . $ history_clear(9d8ddf5c89937cf2). (me);
467 forgetcxx . . $ `sys/Thing.h:158:9`! (me);
468 }
469 #elif motif
470 #elif cocoa
471 @implementation GuiCocoaTextField {
472 GuiText d_userData;
473 }
474 - (void) dealloc { // override
475 GuiText me = self -> d_userData;
476 forget (me);
477 trace (U"deleting a text field");
478 [super dealloc];
479 }
480 - (GuiThing) getUserData {
481 return self -> d_userData;
482 }
483 - (void) setUserData: (GuiThing) userData {
484 Melder_assert (userData == nullptr || Thing_isa (userData, classGuiText));
485 d_userData = static_cast <GuiText> (userData);
486 }
487 - (void) textDidChange: (NSNotification *) notification {
488 (void) notification;
489 GuiText me = self -> d_userData;
490 if (me && my d_changedCallback) {
491 struct structGuiTextEvent event { me };
492 my d_changedCallback (my d_changedBoss, & event);
493 }
494 }
495 - (BOOL) control: (NSControl *) control textView: (NSTextView *) fieldEditor doCommandBySelector: (SEL) commandSelector {
496 //Melder_casual (U"command in a text field");
497 if (commandSelector == @selector (insertNewline:)) {
498 //Melder_casual (U"attempt to insert a new line in a text field");
499 const bool weWantToInterpretAnEnterAsANewline = ((false)); // perhaps at some point replace by a condition that makes sense
500 if (weWantToInterpretAnEnterAsANewline) {
501 [fieldEditor insertNewlineIgnoringFieldEditor: nil];
502 return YES;
503 }
504 }
505 /*
506 The same can be done for insertTab.
507 But tabs are captured at a lower level, in our `sendEvent` (see GuiMenu.cpp).
508 (last checked 2021-12-04)
509 */
510 return NO;
511 }
512 @end
513 @implementation GuiCocoaTextView {
514 GuiText d_userData;
515 }
516 - (void) dealloc { // override
517 GuiText me = self -> d_userData;
518 forget (me);
519 trace (U"deleting a text view");
520 [super dealloc];
521 }
522 - (GuiThing) getUserData {
523 return self -> d_userData;
524 }
525 - (void) setUserData: (GuiThing) userData {
526 Melder_assert (userData == nullptr || Thing_isa (userData, classGuiText));
527 self -> d_userData = static_cast <GuiText> (userData);
528 }
529 /*
530 The NSTextViewDelegate protocol.
531 While NSTextDelegate simply has textDidChange:, that method doesn't seem to always respond when the text is changed programmatically.
532 Hence the addition of textView:shouldChangeTextInRange.
533 It's not unthinkable that some changes could appear twice.
534 */
535 - (void) textDidChange: (NSNotification *) notification { // method doesn't seem to respond when the text is changed programmatically
536 (void) notification;
537 GuiText me = self -> d_userData;
538 if (me && my d_changedCallback) {
539 struct structGuiTextEvent event { me };
540 my d_changedCallback (my d_changedBoss, & event);
541 }
542 }
543 - (BOOL) textView: (NSTextView *) aTextView shouldChangeTextInRange: (NSRange) affectedCharRange replacementString: (NSString *) replacementString {
544 (void) aTextView;
545 (void) affectedCharRange;
546 (void) replacementString;
547 trace (U"changing text to: ", Melder_peek8to32_u ([replacementString UTF8String]));
548 GuiText me = self -> d_userData;
549 if (me && my d_changedCallback) {
550 struct structGuiTextEvent event { me };
551 my d_changedCallback (my d_changedBoss, & event);
552 }
553 return YES;
554 }
555 - (BOOL) textView: (NSTextView *) fieldEditor doCommandBySelector: (SEL) commandSelector {
556 if (commandSelector == @selector (insertNewline:)) {
557 GuiText me = self -> d_userData;
558 if (me && Thing_isa (me, classGuiText)) {
559 /*
560 DESIRED BEHAVIOUR OF `ENTER` IN A TEXT WIDGET
561
562 Whether an Enter typed into a text widget should generate a newline
563 should depends on whether the text widget wraps or not.
564 If the text widget wraps, then that means that new lines will be automatically
565 created once the user types across the right-hand margin. In such cases,
566 there is little need for "Enter" to mean 'newline'; instead, the Enter key
567 should then be used to activate an OK button (in a dialog) or activating
568 a menu command with an Enter shortcut (in a window); the user can still
569 insert a newline by typing Option-Enter.
570 If the text widget does not wrap, typed text can move across the right-hand
571 margin (presumably, there will be a horizontal scrollbar). In such cases,
572 the user expects to be able to type Enter to obtain a newline.
573 */
574 if (my flags & GuiText_ANYWRAP) {
575 /*
576 If left alone, the Enter key will cause the TextView to lose focus,
577 but the Enter will not be sent on to an OK button or use as a menu command shortcut.
578 For that to happen, the user will have to type the Enter key a second time.
579 That is unexpected for most users (though Apple may have regarded this as desired behaviour).
580 We therefore make sure that the focus-releasing Enter
581 will already invoke the OK button or the menu command shortcut.
582 */
583 NSEvent *nsEvent = [NSApp currentEvent];
584 if (Thing_isa (my d_shell, classGuiWindow)) {
585 /*
586 Reroute Enter key presses from any multiline text view to the menu item that has a shortcut for them.
587 Note that implementing this here rather than in `sendEvent` (see GuiMenu.cpp)
588 allows Japanese keyboards to select characters.
589 */
590 GuiWindow window = (GuiWindow) my d_shell;
591 if (! ([nsEvent modifierFlags] & (NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask | NSControlKeyMask)) && window -> d_enterCallback) {
592 try {
593 structGuiMenuItemEvent event { nullptr, false, false, false };
594 window -> d_enterCallback (window -> d_enterBoss, & event);
595 } catch (MelderError) {
596 Melder_flushError (U"Enter key not completely handled.");
597 }
598 return YES;
599 }
600 } else if (Thing_isa (my d_shell, classGuiDialog)) {
601 /*
602 Reroute Enter key presses from any multiline text view to the default button.
603 Note that implementing this here rather than in `sendEvent` (see GuiMenu.cpp)
604 allows Japanese keyboards to select characters.
605 */
606 GuiDialog dialog = (GuiDialog) my d_shell;
607 if (! ([nsEvent modifierFlags] & (NSAlternateKeyMask | NSShiftKeyMask | NSCommandKeyMask | NSControlKeyMask)) && dialog -> d_defaultCallback) {
608 try {
609 dialog -> d_defaultCallback (dialog -> d_defaultBoss);
610 } catch (MelderError) {
611 Melder_flushError (U"Default button not completely handled.");
612 }
613 return YES;
614 }
615 }
616 } else {
617 /*
618 The following correct behaviour can be checked in fields that do not wrap,
619 i.e. in vector fields, matrix fields and string array fields,
620 for instance in `Create simple Matrix from values...`.
621 */
622 [fieldEditor insertNewlineIgnoringFieldEditor: self];
623 return YES;
624 }
625 }
626 return NO;
627 }
628 return NO;
629 }
630 - (BOOL) becomeFirstResponder {
631 /*
632 We have to select the whole text if:
633 - we are in a dialog and we got here because the user typed a Tab
634 - we are in a dialog and we got here because the user clicked a menu command
635 But not if:
636 - we are in a GuiWindow (such as the TextGrid window or the script window)
637 - we are in a dialog and we got here because the user clicked inside our text (this would flash)
638 */
639 GuiText me = self -> d_userData;
640 if (me && Thing_isa (me, classGuiText) && my d_shell -> classInfo == classGuiDialog) {
641 NSEvent *nsEvent = [NSApp currentEvent];
642 const bool isTabOrSomeKeyboardShortcut = ( [nsEvent type] == NSKeyDown );
643 const bool isClickOutsideUs = ( [nsEvent window] != my d_shell -> d_cocoaShell );
644 if (isTabOrSomeKeyboardShortcut || isClickOutsideUs) {
645 NSUInteger textLength = [[my d_cocoaTextView textStorage] length];
646 [my d_cocoaTextView setSelectedRange: NSMakeRange (0, textLength)];
647 }
648 }
649 [super becomeFirstResponder];
650 return YES;
651 }
652 - (BOOL) resignFirstResponder {
653 GuiText me = self -> d_userData;
654 if (me && Thing_isa (me, classGuiText) && my d_shell -> classInfo == classGuiDialog)
655 [my d_cocoaTextView setSelectedRange: NSMakeRange (0, 0)]; // make selection invisible when another text field is in focus
656 [super resignFirstResponder];
657 return YES;
658 }
659 @end
660 #endif
661
662 GuiTextcxx . . $ GuiText# GuiText_createcxx . . $ GuiText_create(8bcb1f2be7fc31ee). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom, uint32cxx . . $ uint32# flags) {
663 autoGuiTextcxx . . $ autoGuiText# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (GuiText);
664 mycxx . . $ `melder/melder.h:44:9`! d_shellcxx . . $ structGuiThing#d_shell. = parent -> d_shellcxx . . $ structGuiThing#d_shell.;
665 mycxx . . $ `melder/melder.h:44:9`! d_parentcxx . . $ structGuiThing#d_parent. = parent;
666 mycxx . . $ `melder/melder.h:44:9`! flagscxx . . $ structGuiText#flags. = flags;
667 #if gtkcxx . . $ `sys/Gui.h:33:10`!
668 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"before creating a GTK text widget: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr)));
669 if (flags & GuiText_SCROLLEDcxx . . $ `sys/Gui.h:1123:9`!) {
670 GuiObjectcxx . . $ GuiObject# scrolled = gtk_scrolled_window_new (nullptr, nullptr);
671 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOWcxx . . $ `<external>/15242555379300173687/gtkscrolledwindow.h:38:9`! (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
672 mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_text_view_new ();
673 gtk_text_view_set_monospace (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), true);
674 constexpr int spacing = 28;
675 PangoTabArray *tabs = pango_tab_array_new_with_positions (50, true,
676 PANGO_TAB_LEFT, 1 * spacing,
677 PANGO_TAB_LEFT, 2 * spacing,
678 PANGO_TAB_LEFT, 3 * spacing,
679 PANGO_TAB_LEFT, 4 * spacing,
680 PANGO_TAB_LEFT, 5 * spacing,
681 PANGO_TAB_LEFT, 6 * spacing,
682 PANGO_TAB_LEFT, 7 * spacing,
683 PANGO_TAB_LEFT, 8 * spacing,
684 PANGO_TAB_LEFT, 9 * spacing,
685 PANGO_TAB_LEFT, 10 * spacing,
686 PANGO_TAB_LEFT, 11 * spacing,
687 PANGO_TAB_LEFT, 12 * spacing,
688 PANGO_TAB_LEFT, 13 * spacing,
689 PANGO_TAB_LEFT, 14 * spacing,
690 PANGO_TAB_LEFT, 15 * spacing,
691 PANGO_TAB_LEFT, 16 * spacing,
692 PANGO_TAB_LEFT, 17 * spacing,
693 PANGO_TAB_LEFT, 18 * spacing,
694 PANGO_TAB_LEFT, 19 * spacing,
695 PANGO_TAB_LEFT, 20 * spacing,
696 PANGO_TAB_LEFT, 21 * spacing,
697 PANGO_TAB_LEFT, 22 * spacing,
698 PANGO_TAB_LEFT, 23 * spacing,
699 PANGO_TAB_LEFT, 24 * spacing,
700 PANGO_TAB_LEFT, 25 * spacing,
701 PANGO_TAB_LEFT, 26 * spacing,
702 PANGO_TAB_LEFT, 27 * spacing,
703 PANGO_TAB_LEFT, 28 * spacing,
704 PANGO_TAB_LEFT, 29 * spacing,
705 PANGO_TAB_LEFT, 30 * spacing,
706 PANGO_TAB_LEFT, 31 * spacing,
707 PANGO_TAB_LEFT, 32 * spacing,
708 PANGO_TAB_LEFT, 33 * spacing,
709 PANGO_TAB_LEFT, 34 * spacing,
710 PANGO_TAB_LEFT, 35 * spacing,
711 PANGO_TAB_LEFT, 36 * spacing,
712 PANGO_TAB_LEFT, 37 * spacing,
713 PANGO_TAB_LEFT, 38 * spacing,
714 PANGO_TAB_LEFT, 39 * spacing,
715 PANGO_TAB_LEFT, 40 * spacing,
716 PANGO_TAB_LEFT, 41 * spacing,
717 PANGO_TAB_LEFT, 42 * spacing,
718 PANGO_TAB_LEFT, 43 * spacing,
719 PANGO_TAB_LEFT, 44 * spacing,
720 PANGO_TAB_LEFT, 45 * spacing,
721 PANGO_TAB_LEFT, 46 * spacing,
722 PANGO_TAB_LEFT, 47 * spacing,
723 PANGO_TAB_LEFT, 48 * spacing,
724 PANGO_TAB_LEFT, 49 * spacing,
725 PANGO_TAB_LEFT, 50 * spacing
726 );
727 gtk_text_view_set_tabs (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), tabs);
728 gtk_container_add (GTK_CONTAINERcxx . . $ `<external>/462093496598485868/gtkcontainer.h:38:9`! (scrolled), GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
729 gtk_widget_show (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (scrolled));
730 gtk_text_view_set_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), ! (flags & GuiText_NONEDITABLEcxx . . $ `sys/Gui.h:1127:9`!));
731 const GtkWrapMode gtkWrapMode =
732 ( flags & GuiText_CHARWRAPcxx . . $ `sys/Gui.h:1124:9`! ? GTK_WRAP_CHAR : flags & GuiText_INKWRAPcxx . . $ `sys/Gui.h:1125:9`! ? GTK_WRAP_WORD_CHAR : GTK_WRAP_NONE );
733 gtk_text_view_set_wrap_mode (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), gtkWrapMode);
734 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
735 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (buffer), "delete-range", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkTextBuf_history_delete_cb), me.get());
736 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (buffer), "insert-text", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkTextBuf_history_insert_cb), me.get());
737 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (buffer), "changed", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkText_valueChangedCallback), me.get());
738 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
739 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (scrolled, me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
740 mycxx . . $ `melder/melder.h:44:9`! v_positionInFormcxx . . $ structGuiControl#v_positionInForm(6e76d3e0dab57625). (scrolled, left, right, top, bottom, parent);
741 } else {
742 mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget. = gtk_entry_new ();
743 gtk_editable_set_editable (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), ! (flags & GuiText_NONEDITABLEcxx . . $ `sys/Gui.h:1127:9`!));
744 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), "delete-text", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkEntry_history_delete_cb), me.get());
745 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), "insert-text", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkEntry_history_insert_cb), me.get());
746 g_signal_connectcxx . . $ `<external>/15952772511652638895/gsignal.h:548:9`! (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), "changed", G_CALLBACKcxx . . $ `<external>/16473872192229286895/gclosure.h:73:9`! (_GuiGtkText_valueChangedCallback), me.get());
747 //gtk_widget_set_can_default (my d_widget, false);
748 _GuiObject_setUserDatacxx . . $ _GuiObject_setUserData(6c58c5e2437d25a2). (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget., me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
749 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);
750 gtk_entry_set_activates_default (GTK_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:49:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), true);
751 }
752 tracecxx . . $ `melder/melder_debug.h:60:10`! (U"after creating a GTK text widget: locale is ", Melder_peek8to32_u (setlocale (LC_ALLcxx . . $ `<external>/3736975272097309885/locale.h:41:9`!, nullptr)));
753 mycxx . . $ `melder/melder.h:44:9`! d_prevcxx . . $ structGuiText#d_prev. = nullptr;
754 mycxx . . $ `melder/melder.h:44:9`! d_nextcxx . . $ structGuiText#d_next. = nullptr;
755 mycxx . . $ `melder/melder.h:44:9`! d_history_changecxx . . $ structGuiText#d_history_change. = 0;
756 mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item. = nullptr;
757 mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item. = nullptr;
758 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`! (_GuiGtkText_destroyCallback), me.get());
759 #elif motif
760 my d_widget = _Gui_initializeWidget (xmTextWidgetClass, parent -> d_widget, flags & GuiText_SCROLLED ? U"scrolledText" : U"text");
761 _GuiObject_setUserData (my d_widget, me.get());
762 my d_editable = (flags & GuiText_NONEDITABLE) == 0;
763 my d_widget -> window = CreateWindow (L"edit", nullptr, WS_CHILD | WS_BORDER
764 | ( flags & GuiText_ANYWRAP ? ES_AUTOVSCROLL : ES_AUTOHSCROLL )
765 | ES_MULTILINE | WS_CLIPSIBLINGS
766 | ( flags & GuiText_SCROLLED ? WS_VSCROLL | ( flags & GuiText_ANYWRAP ? 0 : WS_HSCROLL ) : 0 ),
767 my d_widget -> x, my d_widget -> y, my d_widget -> width, my d_widget -> height,
768 my d_widget -> parent -> window, (HMENU) 1, theGui.instance, nullptr);
769 SetWindowLongPtr (my d_widget -> window, GWLP_USERDATA, (LONG_PTR) my d_widget);
770 if (! font10) {
771 font10 = CreateFont (13, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0/*FIXED_PITCH | FF_MODERN*/, /*L"Doulos SIL"*/L"Courier New");
772 font12 = CreateFont (16, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0/*FIXED_PITCH | FF_MODERN*/, /*L"Doulos SIL"*/L"Courier New");
773 font14 = CreateFont (19, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0/*FIXED_PITCH | FF_MODERN*/, /*L"Doulos SIL"*/L"Courier New");
774 font18 = CreateFont (24, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0/*FIXED_PITCH | FF_MODERN*/, /*L"Doulos SIL"*/L"Courier New");
775 font24 = CreateFont (32, 0, 0, 0, 0, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 0/*FIXED_PITCH | FF_MODERN*/, /*L"Doulos SIL"*/L"Courier New");
776 }
777 SetWindowFont (my d_widget -> window, font12 /*theScrolledHint ? font : GetStockFont (ANSI_VAR_FONT)*/, false);
778 Edit_LimitText (my d_widget -> window, 0);
779 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
780 /*
781 The first created text widget shall attract the input focus.
782 */
783 if (! my d_widget -> shell -> textFocus)
784 my d_widget -> shell -> textFocus = my d_widget; // even if not-yet-managed. But in that case it will not receive global focus
785 #elif cocoa
786 if (flags & GuiText_SCROLLED) {
787 my d_cocoaScrollView = [[GuiCocoaScrolledWindow alloc] init];
788 [my d_cocoaScrollView setUserData: nullptr]; // because those user data can only be GuiScrolledWindow
789 my d_widget = my d_cocoaScrollView;
790 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
791 [my d_cocoaScrollView setBorderType: NSBezelBorder];
792 [my d_cocoaScrollView setHasHorizontalScroller: ! (flags & GuiText_ANYWRAP)];
793 [my d_cocoaScrollView setHasVerticalScroller: YES];
794 if (my d_shell -> classInfo == classGuiDialog)
795 [my d_cocoaScrollView setFocusRingType: NSFocusRingTypeExterior];
796 //[my d_cocoaScrollView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
797 NSSize contentSize = [my d_cocoaScrollView contentSize];
798 my d_cocoaTextView = [[GuiCocoaTextView alloc] initWithFrame: NSMakeRect (0, 0, contentSize. width, contentSize. height)];
799 [my d_cocoaTextView setUserData: me.get()];
800 if (Melder_systemVersion < 101100) {
801 [my d_cocoaTextView setMinSize: NSMakeSize (0.0, contentSize.height)];
802 } else {
803 [my d_cocoaTextView setMinSize: NSMakeSize (contentSize. width, contentSize.height)]; // El Capitan Developer Beta 2
804 }
805 [my d_cocoaTextView setMaxSize: NSMakeSize (FLT_MAX, FLT_MAX)];
806 if ((true)) {
807 /*
808 The Info window and the Script window have the problem that if a tab occurs after 336 points,
809 the text breaks to the next line.
810 The probable cause is found in NSParagraphStyle:
811 (1) "The NSTextTab objects, sorted by location, define the tab stops for the paragraph style.
812 The default value is an array of 12 left-aligned tabs at 28-point intervals."
813 (2) The default value of defaultTabInterval ("Tabs after the last specified in tabStops are
814 placed at integer multiples of this distance (if positive).") is 0.0,
815 probably meaning that the next tab stop has to be sought on the next line.
816 We therefore try to prevent the unwanted line break by setting defaultTabInterval to 29.2,
817 which seems to correspond to four 62.5%-wide fixed-width 12-point Menlo characters (but actually 60.8%-wide; last checked 2023-05-20).
818 */
819 //NSMutableParagraphStyle *paragraphStyle = [[my d_cocoaTextView defaultParagraphStyle] mutableCopy]; // this one doesn't work (in 10.14.6)
820 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
821 [paragraphStyle setParagraphStyle: [my d_cocoaTextView defaultParagraphStyle]]; // should be superfluous
822 [paragraphStyle setDefaultTabInterval: 29.2]; // this already sets the number of tab stops to infinite...
823 [paragraphStyle setTabStops: [NSArray array]]; // ... and this empties the current tab stops, effectively setting all to 29.2 points from the leftmost on
824 if (!! (flags & GuiText_CHARWRAP))
825 [paragraphStyle setLineBreakMode: NSLineBreakByCharWrapping];
826 else if (!! (flags & GuiText_INKWRAP))
827 [paragraphStyle setLineBreakMode: NSLineBreakByWordWrapping];
828 [my d_cocoaTextView setDefaultParagraphStyle: paragraphStyle];
829 [paragraphStyle release];
830 /*
831 The trick above works only when we insert text by setString, not when we edit the text manually.
832 However, we can correctly edit manually *after* setString has been called with a non-empty string (see below).
833 */
834 /*
835 We can experiment with setting additional tab stops at 400 and 500 points.
836 */
837 //[paragraphStyle setTabStops: [NSArray array]];
838 //NSDictionary *emptyDictionary = [[NSDictionary alloc] init];
839 //NSTextTab *tab400 = [[NSTextTab alloc] initWithTextAlignment: NSTextAlignmentLeft location: 400.0 options: emptyDictionary];
840 //NSTextTab *tab400 = [[NSTextTab alloc] initWithType: NSLeftTabStopType location: 400.0];
841 //[paragraphStyle addTabStop: tab400];
842 //NSTextTab *tab500 = [[NSTextTab alloc] initWithTextAlignment: NSTextAlignmentLeft location: 500.0 options: emptyDictionary];
843 //NSTextTab *tab500 = [[NSTextTab alloc] initWithType: NSLeftTabStopType location: 500.0];
844 //[paragraphStyle addTabStop: tab500];
845 /*
846 We can experiment with attributed strings.
847 This won't work here, perhaps because the length of the string, and hence the "range", will change later.
848 */
849 //NSMutableDictionary *attributes = [[NSMutableDictionary alloc] init];
850 //[attributes setObject: paragraphStyle forKey: NSParagraphStyleAttributeName];
851 //[[my d_cocoaTextView textStorage] addAttributes: attributes range: NSMakeRange (0, [[[my d_cocoaTextView textStorage] string] length])];
852 }
853 [my d_cocoaTextView setVerticallyResizable: YES];
854 [my d_cocoaTextView setHorizontallyResizable: YES];
855 //[my d_cocoaTextView setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable];
856 if (! (flags & GuiText_ANYWRAP))
857 [[my d_cocoaTextView textContainer] setContainerSize: NSMakeSize (FLT_MAX, FLT_MAX)];
858 [[my d_cocoaTextView textContainer] setWidthTracksTextView: NO];
859 [my d_cocoaScrollView setDocumentView: my d_cocoaTextView]; // the scroll view will own the text view?
860 [my d_cocoaTextView release]; // so we release the text view itself
861 if (! (flags & GuiText_ANYWRAP))
862 [[my d_cocoaScrollView window] makeFirstResponder: my d_cocoaTextView]; // in dialog
863 if (flags & GuiText_ANYWRAP) {
864 my d_macFontSize = 13.0;
865 static NSFont *theSystemTextFont;
866 if (! theSystemTextFont)
867 theSystemTextFont = [[NSFont systemFontOfSize: 13.0] retain];
868 [my d_cocoaTextView setFont: theSystemTextFont];
869 } else {
870 my d_macFontSize = 12.0;
871 static NSFont *theFixedWidthTextFont;
872 if (! theFixedWidthTextFont)
873 theFixedWidthTextFont = [[NSFont fontWithName: @"Menlo" size: 12.0] retain];
874 [my d_cocoaTextView setFont: theFixedWidthTextFont];
875 }
876 [my d_cocoaTextView setAllowsUndo: YES];
877 [my d_cocoaTextView turnOffLigatures: nil];
878 [my d_cocoaTextView setSmartInsertDeleteEnabled: NO];
879 [my d_cocoaTextView setAutomaticQuoteSubstitutionEnabled: NO];
880 [my d_cocoaTextView setAutomaticTextReplacementEnabled: NO];
881 [my d_cocoaTextView setAutomaticDashSubstitutionEnabled: NO];
882 [my d_cocoaTextView setDelegate: my d_cocoaTextView];
883 if (my d_shell -> classInfo == classGuiDialog)
884 [my d_cocoaTextView setFieldEditor: YES];
885 /*
886 Regrettably, we have to implement the following HACK
887 to prevent tab-based line breaks even when editing manually.
888 */
889 [my d_cocoaTextView setString: @" "];
890 [my d_cocoaTextView setString: @""];
891 } else {
892 my d_widget = [[GuiCocoaTextField alloc] init];
893 my v_positionInForm (my d_widget, left, right, top, bottom, parent);
894 [(GuiCocoaTextField *) my d_widget setUserData: me.get()];
895 [(NSTextField *) my d_widget setEditable: YES];
896 static NSFont *theTextFont;
897 if (! theTextFont)
898 theTextFont = [[NSFont systemFontOfSize: 13.0] retain];
899 [(NSTextField *) my d_widget setFont: theTextFont];
900 [(NSTextField *) my d_widget setDelegate: (id) my d_widget]; // needed only for `doCommandBySelector`?
901 }
902 #endif
903
904 return me.releaseToAmbiguousOwnercxx . . $ autoSomeThing#releaseToAmbiguousOwner(258ee1c9e0a18a5c).();
905 }
906
907 GuiTextcxx . . $ GuiText# GuiText_createShowncxx . . $ GuiText_createShown(8bcb1f2be7fc31ee). (GuiFormcxx . . $ GuiForm# parent, int left, int right, int top, int bottom, uint32cxx . . $ uint32# flags) {
908 GuiTextcxx . . $ GuiText# me = GuiText_createcxx . . $ GuiText_create(8bcb1f2be7fc31ee). (parent, left, right, top, bottom, flags);
909 GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (me);
910 return me;
911 }
912
913 void GuiText_copycxx . . $ GuiText_copy(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
914 #if gtkcxx . . $ `sys/Gui.h:33:10`!
915 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
916 gtk_editable_copy_clipboard (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
917 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
918 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
919 GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARDcxx . . $ `<external>/2490323037302672991/gdkselection.h:59:9`!);
920 gtk_text_buffer_copy_clipboard (buffer, cb);
921 }
922 #elif motif
923 if (! NativeText_getSelectionRange (my d_widget, nullptr, nullptr))
924 return;
925 SendMessage (my d_widget -> window, WM_COPY, 0, 0);
926 #elif cocoa
927 if (my d_cocoaTextView) {
928 [my d_cocoaTextView copy: nil];
929 } else {
930 [[[(GuiCocoaTextField *) my d_widget window] fieldEditor: NO forObject: nil] copy: nil];
931 }
932 #endif
933 }
934
935 void GuiText_cutcxx . . $ GuiText_cut(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
936 #if gtkcxx . . $ `sys/Gui.h:33:10`!
937 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
938 gtk_editable_cut_clipboard (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
939 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
940 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
941 GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARDcxx . . $ `<external>/2490323037302672991/gdkselection.h:59:9`!);
942 gtk_text_buffer_cut_clipboard (buffer, cb, gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
943 }
944 #elif motif
945 if (! my d_editable || ! NativeText_getSelectionRange (my d_widget, nullptr, nullptr))
946 return;
947 SendMessage (my d_widget -> window, WM_CUT, 0, 0); // this will send the EN_CHANGE message, hence no need to call the valueChangedCallbacks
948 UpdateWindow (my d_widget -> window);
949 #elif cocoa
950 if (my d_cocoaTextView) {
951 [my d_cocoaTextView cut: nil];
952 } else {
953 [[[(GuiCocoaTextField *) my d_widget window] fieldEditor: NO forObject: nil] cut: nil];
954 }
955 #endif
956 }
957
958 autostring32cxx . . $ autostring32# GuiText_getSelectioncxx . . $ GuiText_getSelection(9a61f82c13ba8ebc). (GuiTextcxx . . $ GuiText# me) {
959 #if gtkcxx . . $ `sys/Gui.h:33:10`!
960 // first = gtk_text_iter_get_offset (& start);
961 // last = gtk_text_iter_get_offset (& end);
962 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
963 gint start, end;
964 gtk_editable_get_selection_bounds (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & start, & end);
965 if (end > start) { // at least one character selected?
966 gchar *text = gtk_editable_get_chars (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), start, end);
967 autostring32cxx . . $ autostring32# result = Melder_8to32_ecxx . . $ Melder_8to32_e(f01fe69d6ed2498b). (text);
968 g_free (text);
969 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
970 }
971 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
972 GtkTextBuffer *textBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
973 if (gtk_text_buffer_get_has_selection (textBuffer)) { // at least one character selected?
974 GtkTextIter start, end;
975 gtk_text_buffer_get_selection_bounds (textBuffer, & start, & end);
976 gchar *text = gtk_text_buffer_get_text (textBuffer, & start, & end, true);
977 autostring32cxx . . $ autostring32# result = Melder_8to32_ecxx . . $ Melder_8to32_e(f01fe69d6ed2498b). (text);
978 g_free (text);
979 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
980 }
981 }
982 #elif motif
983 integer startW, endW;
984 (void) NativeText_getSelectionRange (my d_widget, & startW, & endW);
985 if (endW > startW) { // at least one character selected?
986 /*
987 Get all text.
988 */
989 integer lengthW = NativeText_getLength (my d_widget); // in UTF-16 code units
990 WCHAR *bufferW = Melder_malloc_f (WCHAR, lengthW + 1);
991 GetWindowTextW (my d_widget -> window, bufferW, lengthW + 1);
992 /*
993 Zoom in on selection.
994 */
995 lengthW = endW - startW;
996 memmove (bufferW, bufferW + startW, lengthW * sizeof (WCHAR)); // not because of realloc, but because of free!
997 bufferW [lengthW] = U'\0';
998 autostring32 result = Melder_dup_f (Melder_peekWto32 (bufferW));
999 (void) Melder_killReturns_inplace (result.get()); // AFTER zooming!
1000 return result;
1001 }
1002 #elif cocoa
1003 integer start, end;
1004 autostring32 selection = GuiText_getStringAndSelectionPosition (me, & start, & end);
1005 integer length = end - start;
1006 if (length > 0) {
1007 autostring32 result (length, true);
1008 memcpy (result.get(), & selection [start], integer_to_uinteger_a (length) * sizeof (char32));
1009 result [length] = U'\0';
1010 (void) Melder_killReturns_inplace (result.get());
1011 return result;
1012 }
1013 #endif
1014 return autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).(); // zero characters selected
1015 }
1016
1017 autostring32cxx . . $ autostring32# GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (GuiTextcxx . . $ GuiText# me) {
1018 integercxx . . $ integer# first, last;
1019 return GuiText_getStringAndSelectionPositioncxx . . $ GuiText_getStringAndSelectionPosition(2d4f5aac9640119d). (me, & first, & last);
1020 }
1021
1022 autostring32cxx . . $ autostring32# GuiText_getStringAndSelectionPositioncxx . . $ GuiText_getStringAndSelectionPosition(2d4f5aac9640119d). (GuiTextcxx . . $ GuiText# me, integercxx . . $ integer# *first, integercxx . . $ integer# *last) {
1023 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1024 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
1025 gint first_gint, last_gint;
1026 gtk_editable_get_selection_bounds (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & first_gint, & last_gint); // expressed in Unicode code points!
1027 *first = first_gint;
1028 *last = last_gint;
1029 return Melder_8to32_ecxx . . $ Melder_8to32_e(f01fe69d6ed2498b). (gtk_entry_get_text (GTK_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:49:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1030 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
1031 GtkTextBuffer *textBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1032 GtkTextIter start, end;
1033 gtk_text_buffer_get_start_iter (textBuffer, & start);
1034 gtk_text_buffer_get_end_iter (textBuffer, & end);
1035 gchar *text = gtk_text_buffer_get_text (textBuffer, & start, & end, true); // TODO: Hidden chars ook maar doen he?
1036 autostring32cxx . . $ autostring32# result = Melder_8to32_ecxx . . $ Melder_8to32_e(f01fe69d6ed2498b). (text);
1037 g_free (text);
1038 gtk_text_buffer_get_selection_bounds (textBuffer, & start, & end);
1039 *first = gtk_text_iter_get_offset (& start);
1040 *last = gtk_text_iter_get_offset (& end);
1041 return resultcxx . . $ _autostring#_autostring(39021ecceedcc7d2).;
1042 }
1043 return autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).();
1044 #elif motif
1045 integer lengthW = NativeText_getLength (my d_widget);
1046 autostringW bufferW (lengthW , true);
1047 GetWindowTextW (my d_widget -> window, bufferW.get(), lengthW + 1);
1048 integer firstW, lastW;
1049 (void) NativeText_getSelectionRange (my d_widget, & firstW, & lastW);
1050
1051 integer differenceFirst = 0;
1052 for (integer i = 0; i < firstW; i ++) {
1053 if (bufferW [i] == 13 && (bufferW [i + 1] == L'\n' || bufferW [i + 1] == 0x0085))
1054 differenceFirst ++;
1055 if (bufferW [i] >= 0xDC00 && bufferW [i] <= 0xDFFF)
1056 differenceFirst ++;
1057 }
1058 *first = firstW - differenceFirst;
1059
1060 integer differenceLast = differenceFirst;
1061 for (integer i = firstW; i < lastW; i ++) {
1062 if (bufferW [i] == 13 && (bufferW [i + 1] == L'\n' || bufferW [i + 1] == 0x0085))
1063 differenceLast ++;
1064 if (bufferW [i] >= 0xDC00 && bufferW [i] <= 0xDFFF)
1065 differenceLast ++;
1066 }
1067 *last = lastW - differenceLast;
1068
1069 autostring32 result = Melder_dup_f (Melder_peekWto32 (bufferW.get()));
1070 (void) Melder_killReturns_inplace (result.get());
1071 return result;
1072 #elif cocoa
1073 NSString *nsString = ( my d_cocoaTextView ?
1074 [my d_cocoaTextView string] :
1075 [(NSTextField *) my d_widget stringValue] );
1076 autostring16 buffer16 = Melder_32to16 (Melder_peek8to32_u ([nsString UTF8String]));
1077 NSText *nsText = ( my d_cocoaTextView ?
1078 my d_cocoaTextView :
1079 [[(NSTextField *) my d_widget window] fieldEditor: NO forObject: nil] );
1080 NSRange nsRange = [nsText selectedRange];
1081 *first = uinteger_to_integer_a (nsRange. location);
1082 *last = *first + uinteger_to_integer_a (nsRange. length);
1083 /*
1084 The UTF-16 string may contain sequences of carriage return and newline,
1085 for instance whenever a text has been copy-pasted from Microsoft Word,
1086 in which case the carriage return has to be deleted and `first` and/or `last`
1087 may have to be decremented.
1088 */
1089 integer differenceFirst = 0;
1090 for (integer i = 0; i < *first; i ++) {
1091 if (buffer16 [i] == 13 && (buffer16 [i + 1] == L'\n' || buffer16 [i + 1] == 0x0085))
1092 differenceFirst ++;
1093 if (buffer16 [i] >= 0xDC00 && buffer16 [i] <= 0xDFFF)
1094 differenceFirst ++;
1095 }
1096 integer differenceLast = differenceFirst;
1097 for (integer i = *first; i < *last; i ++) {
1098 if (buffer16 [i] == 13 && (buffer16 [i + 1] == L'\n' || buffer16 [i + 1] == 0x0085))
1099 differenceLast ++;
1100 if (buffer16 [i] >= 0xDC00 && buffer16 [i] <= 0xDFFF)
1101 differenceLast ++;
1102 }
1103 *first -= differenceFirst;
1104 *last -= differenceLast;
1105 autostring32 result = Melder_dup_f (Melder_peek16to32 (buffer16.get()));
1106 (void) Melder_killReturns_inplace (result.get());
1107 return result;
1108 #else
1109 return autostring32();
1110 #endif
1111 }
1112
1113 void GuiText_pastecxx . . $ GuiText_paste(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
1114 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1115 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
1116 gtk_editable_paste_clipboard (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1117 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
1118 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1119 GtkClipboard *cb = gtk_clipboard_get (GDK_SELECTION_CLIPBOARDcxx . . $ `<external>/2490323037302672991/gdkselection.h:59:9`!);
1120 gtk_text_buffer_paste_clipboard (buffer, cb, nullptr, gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1121 }
1122 #elif motif
1123 if (! my d_editable)
1124 return;
1125 SendMessage (my d_widget -> window, WM_PASTE, 0, 0); // this will send the EN_CHANGE message, hence no need to call the valueChangedCallbacks
1126 UpdateWindow (my d_widget -> window);
1127 #elif cocoa
1128 if (my d_cocoaTextView) {
1129 trace (U"Pasting to text view.");
1130 [my d_cocoaTextView pasteAsPlainText: nil];
1131 } else {
1132 trace (U"Pasting to text field.");
1133 [(NSTextView *) [[(GuiCocoaTextField *) my d_widget window] fieldEditor: NO forObject: nil] pasteAsPlainText: nil];
1134 }
1135 #endif
1136 }
1137
1138 void GuiText_redocxx . . $ GuiText_redo(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
1139 #if gtkcxx . . $ `sys/Gui.h:33:10`! || motifcxx . . $ `sys/Gui.h:34:10`!
1140 history_docxx . . $ history_do(365f281d9ebaace7). (me, 0);
1141 #elif cocoa
1142 if (my d_cocoaTextView) {
1143 [[my d_cocoaTextView undoManager] redo];
1144 }
1145 #endif
1146 }
1147
1148 void GuiText_removecxx . . $ GuiText_remove(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
1149 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1150 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
1151 gtk_editable_delete_selection (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1152 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
1153 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1154 gtk_text_buffer_delete_selection (buffer, true, gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1155 }
1156 #elif motif
1157 if (! my d_editable || ! NativeText_getSelectionRange (my d_widget, nullptr, nullptr)) return;
1158 SendMessage (my d_widget -> window, WM_CLEAR, 0, 0); // this will send the EN_CHANGE message, hence no need to call the valueChangedCallbacks
1159 UpdateWindow (my d_widget -> window);
1160 #elif cocoa
1161 if (my d_cocoaTextView) {
1162 [my d_cocoaTextView delete: nil];
1163 }
1164 #endif
1165 }
1166
1167 void GuiText_replacecxx . . $ GuiText_replace(27ef96c8abc2c4e2). (GuiTextcxx . . $ GuiText# me, integercxx . . $ integer# from_pos, integercxx . . $ integer# to_pos, conststring32cxx . . $ conststring32# text) {
1168 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1169 const gchar *newText = Melder_peek32to8 (text);
1170 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
1171 gtk_editable_delete_text (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), from_pos, to_pos);
1172 gint from_pos_gint = from_pos;
1173 gtk_editable_insert_text (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), newText, g_utf8_strlen (newText, -1), & from_pos_gint);
1174 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
1175 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1176 GtkTextIter from_it, to_it;
1177 gtk_text_buffer_get_iter_at_offset (buffer, & from_it, from_pos);
1178 gtk_text_buffer_get_iter_at_offset (buffer, & to_it, to_pos);
1179 gtk_text_buffer_delete_interactive (buffer, & from_it, & to_it,
1180 gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1181 gtk_text_buffer_insert_interactive (buffer, & from_it, newText, g_utf8_strlen (newText, -1),
1182 gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1183 }
1184 #elif motif
1185 Melder_assert (MEMBER (my d_widget, Text));
1186 autostring32 winText (2 * Melder_length (text), true); // all newlines
1187 char32 *to = & winText [0];
1188 /*
1189 Replace all LF with CR/LF.
1190 */
1191 for (const char32 *from = & text [0]; *from != U'\0'; from ++, to ++)
1192 if (*from == U'\n') { *to = 13; * ++ to = U'\n'; } else *to = *from;
1193 *to = U'\0';
1194 /*
1195 We DON'T replace any text without selecting it, so we can deselect any other text,
1196 thus allowing ourselves to select [from_pos, to_pos] and use the REPLACESEL message.
1197 */
1198 GuiText_setSelection (me, from_pos, to_pos);
1199 Edit_ReplaceSel (my d_widget -> window, Melder_peek32toW (winText.get()));
1200 UpdateWindow (my d_widget -> window);
1201 #elif cocoa
1202 if (my d_cocoaTextView) {
1203 integer numberOfLeadingHighUnicodeValues = 0, numberOfSelectedHighUnicodeValues = 0;
1204 {// scope
1205 autostring32 oldText = GuiText_getString (me);
1206 for (integer i = 0; i < from_pos; i ++) if (oldText [i] > 0xFFFF) numberOfLeadingHighUnicodeValues ++;
1207 for (integer i = from_pos; i < to_pos; i ++) if (oldText [i] > 0xFFFF) numberOfSelectedHighUnicodeValues ++;
1208 }
1209 from_pos += numberOfLeadingHighUnicodeValues;
1210 to_pos += numberOfLeadingHighUnicodeValues + numberOfSelectedHighUnicodeValues;
1211 NSRange nsRange = NSMakeRange (integer_to_uinteger_a (from_pos), integer_to_uinteger_a (to_pos - from_pos));
1212 NSString *nsString = (NSString *) Melder_peek32toCfstring (text);
1213 [my d_cocoaTextView shouldChangeTextInRange: nsRange replacementString: nsString]; // ignore the returned BOOL: only interested in the side effect of having undo support
1214 [[my d_cocoaTextView textStorage] replaceCharactersInRange: nsRange withString: nsString]; // this messes up the widget...
1215 [my d_cocoaTextView setFont: [NSFont fontWithName: @"Menlo" size: my d_macFontSize]]; // ... so we reapply the font size (HACK 2021-05-07)
1216 [my d_cocoaTextView setTextColor: [NSColor textColor]]; // ... and the foreground colour as well (HACK 2021-05-07)
1217 }
1218 #endif
1219 }
1220
1221 void GuiText_scrollToSelectioncxx . . $ GuiText_scrollToSelection(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
1222 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1223 GtkTextBuffer *textBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1224 GtkTextIter start, end;
1225 gtk_text_buffer_get_selection_bounds (textBuffer, & start, & end);
1226 //GtkTextMark *mark = gtk_text_buffer_create_mark (textBuffer, nullptr, & start, true);
1227 gtk_text_view_scroll_to_iter (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), & start, 0.1, false, 0.0, 0.0);
1228 //gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (my d_widget), mark, 0.1, false, 0.0, 0.0);
1229 #elif motif
1230 Edit_ScrollCaret (my d_widget -> window);
1231 #elif cocoa
1232 if (my d_cocoaTextView)
1233 [my d_cocoaTextView scrollRangeToVisible: [my d_cocoaTextView selectedRange]];
1234 #endif
1235 }
1236
1237 void GuiText_setChangedCallbackcxx . . $ GuiText_setChangedCallback(1197bbfc2caa0b9d). (GuiTextcxx . . $ GuiText# me, GuiText_ChangedCallbackcxx . . $ GuiText_ChangedCallback# changedCallback, Thingcxx . . $ Thing# changedBoss) {
1238 mycxx . . $ `melder/melder.h:44:9`! d_changedCallbackcxx . . $ structGuiText#d_changedCallback. =cxx . . $ MelderCallback#`operator=`(af7555d5fabd54cd). changedCallback;
1239 mycxx . . $ `melder/melder.h:44:9`! d_changedBosscxx . . $ structGuiText#d_changedBoss. = changedBoss;
1240 }
1241
1242 void GuiText_setFontSizecxx . . $ GuiText_setFontSize(c15d57e615da0df1). (GuiTextcxx . . $ GuiText# me, double size) {
1243 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1244 GtkStyleContext *styleContext = gtk_widget_get_style_context (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1245 const PangoFontDescription *fontDesc = gtk_style_context_get_font (styleContext, GTK_STATE_FLAG_NORMAL);
1246 PangoFontDescription *copy = pango_font_description_copy (fontDesc);
1247 pango_font_description_set_absolute_size (copy, size * PANGO_SCALEcxx . . $ `<external>/16549852590339199443/pango-types.h:96:9`!);
1248 gtk_widget_override_font (GTK_WIDGETcxx . . $ `<external>/6031079988677191796/gtkwidget.h:58:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), copy);
1249 pango_font_description_free (copy);
1250 #elif motif
1251 // a trick to update the window. BUG: why doesn't UpdateWindow seem to suffice?
1252 integer first, last;
1253 autostring32 text = GuiText_getStringAndSelectionPosition (me, & first, & last);
1254 GuiText_setString (me, U""); // erase all
1255 UpdateWindow (my d_widget -> window);
1256 if (size <= 10.0)
1257 SetWindowFont (my d_widget -> window, font10, false);
1258 else if (size <= 12.0)
1259 SetWindowFont (my d_widget -> window, font12, false);
1260 else if (size <= 14.0)
1261 SetWindowFont (my d_widget -> window, font14, false);
1262 else if (size <= 18.0)
1263 SetWindowFont (my d_widget -> window, font18, false);
1264 else
1265 SetWindowFont (my d_widget -> window, font24, false);
1266 GuiText_setString (me, text.get());
1267 GuiText_setSelection (me, first, last);
1268 UpdateWindow (my d_widget -> window);
1269 #elif cocoa
1270 my d_macFontSize = size;
1271 if (my d_cocoaTextView)
1272 [my d_cocoaTextView setFont: [NSFont fontWithName: @"Menlo" size: size]];
1273 #endif
1274 }
1275
1276 void GuiText_setRedoItemcxx . . $ GuiText_setRedoItem(fe305b70bc020e42). (GuiTextcxx . . $ GuiText# me, GuiMenuItemcxx . . $ GuiMenuItem# item) {
1277 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1278 if (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item.)
1279 //g_object_unref (my d_redo_item -> d_widget);
1280 mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item. = item;
1281 if (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item.) {
1282 //g_object_ref (my d_redo_item -> d_widget);
1283 GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_redo_itemcxx . . $ structGuiText#d_redo_item., history_has_redocxx . . $ history_has_redo(67d3b309776c224d). (me));
1284 }
1285 #elif motif
1286 #elif cocoa
1287 #endif
1288 }
1289
1290 void GuiText_setSelectioncxx . . $ GuiText_setSelection(e06f404191ddd8ec). (GuiTextcxx . . $ GuiText# me, integercxx . . $ integer# first, integercxx . . $ integer# last) {
1291 if (mycxx . . $ `melder/melder.h:44:9`! d_widgetcxx . . $ structGuiThing#d_widget.) {
1292 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1293 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
1294 gtk_editable_select_region (GTK_EDITABLEcxx . . $ `<external>/4224848447960380008/gtkeditable.h:39:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), first, last);
1295 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (G_OBJECTcxx . . $ `<external>/1341695927569185362/gobject.h:54:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
1296 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1297 GtkTextIter from_it, to_it;
1298 gtk_text_buffer_get_iter_at_offset (buffer, & from_it, first);
1299 gtk_text_buffer_get_iter_at_offset (buffer, & to_it, last);
1300 gtk_text_buffer_select_range (buffer, & from_it, & to_it);
1301 }
1302 #elif motif
1303 autostring32 text = GuiText_getString (me);
1304 if (first < 0) first = 0;
1305 if (last < 0) last = 0;
1306 const integer length = Melder_length (text.get());
1307 if (first >= length) first = length;
1308 if (last >= length) last = length;
1309 /*
1310 * 'first' and 'last' are the positions of the selection in the text when separated by LF alone.
1311 * We have to convert this to the positions that the selection has in a text separated by CR/LF sequences.
1312 */
1313 integer numberOfLeadingLineBreaks = 0, numberOfSelectedLineBreaks = 0;
1314 for (integer i = 0; i < first; i ++) if (text [i] == U'\n') numberOfLeadingLineBreaks ++;
1315 for (integer i = first; i < last; i ++) if (text [i] == U'\n') numberOfSelectedLineBreaks ++;
1316 /*
1317 On Windows, characters are counted in UTF-16 units, whereas 'first' and 'last' are in UTF-32 units. Convert.
1318 */
1319 integer numberOfLeadingHighUnicodeValues = 0, numberOfSelectedHighUnicodeValues = 0;
1320 for (integer i = 0; i < first; i ++)
1321 if (text [i] > 0xFFFF)
1322 numberOfLeadingHighUnicodeValues ++;
1323 for (integer i = first; i < last; i ++)
1324 if (text [i] > 0xFFFF)
1325 numberOfSelectedHighUnicodeValues ++;
1326
1327 first += numberOfLeadingLineBreaks;
1328 last += numberOfLeadingLineBreaks + numberOfSelectedLineBreaks;
1329 first += numberOfLeadingHighUnicodeValues;
1330 last += numberOfLeadingHighUnicodeValues + numberOfSelectedHighUnicodeValues;
1331
1332 Edit_SetSel (my d_widget -> window, first, last);
1333 UpdateWindow (my d_widget -> window);
1334 #elif cocoa
1335 /*
1336 On Cocoa, characters are counted in UTF-16 units, whereas 'first' and 'last' are in UTF-32 units. Convert.
1337 */
1338 autostring32 text = GuiText_getString (me);
1339 /*
1340 The following line is needed in case GuiText_getString removed carriage returns.
1341 */
1342 GuiText_setString (me, text.get());
1343 integer numberOfLeadingHighUnicodeValues = 0, numberOfSelectedHighUnicodeValues = 0;
1344 for (integer i = 0; i < first; i ++)
1345 if (text [i] > 0xFFFF)
1346 numberOfLeadingHighUnicodeValues ++;
1347 for (integer i = first; i < last; i ++)
1348 if (text [i] > 0xFFFF)
1349 numberOfSelectedHighUnicodeValues ++;
1350 first += numberOfLeadingHighUnicodeValues;
1351 last += numberOfLeadingHighUnicodeValues + numberOfSelectedHighUnicodeValues;
1352
1353 if (my d_cocoaTextView) {
1354 [my d_cocoaTextView setSelectedRange: NSMakeRange (integer_to_uinteger_a (first), integer_to_uinteger_a (last - first))];
1355 }
1356 #endif
1357 }
1358 }
1359
1360 void GuiText_setStringcxx . . $ GuiText_setString(d44acbd60ea2b9be). (GuiTextcxx . . $ GuiText# me, conststring32cxx . . $ conststring32# text, bool undoable) {
1361 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1362 if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget) == GTK_TYPE_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:48:9`!) {
1363 gtk_entry_set_text (GTK_ENTRYcxx . . $ `<external>/10768811112622010133/gtkentry.h:49:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget), Melder_peek32to8 (text));
1364 } else if (G_OBJECT_TYPEcxx . . $ `<external>/1341695927569185362/gobject.h:98:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget) == GTK_TYPE_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:39:9`!) {
1365 GtkTextBuffer *textBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget));
1366 const gchar *textUtf8 = Melder_peek32to8 (text);
1367 //gtk_text_buffer_set_text (textBuffer, textUtf8, strlen (textUtf8)); // length in bytes!
1368 GtkTextIter start, end;
1369 gtk_text_buffer_get_start_iter (textBuffer, & start);
1370 gtk_text_buffer_get_end_iter (textBuffer, & end);
1371 gtk_text_buffer_delete_interactive (textBuffer, & start, & end, gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1372 gtk_text_buffer_insert_interactive (textBuffer, & start, textUtf8, strlen (textUtf8), gtk_text_view_get_editable (GTK_TEXT_VIEWcxx . . $ `<external>/2195107948809326674/gtktextview.h:40:9`! (mycxx . . $ `melder/melder.h:44:9`! d_widget)));
1373 }
1374 #elif motif
1375 autostring32 winText (2 * Melder_length (text), true); // all new lines
1376 char32 *to = & winText [0];
1377 /*
1378 Replace all LF with CR/LF.
1379 */
1380 for (const char32 *from = & text [0]; *from != U'\0'; from ++, to ++)
1381 if (*from == U'\n') {
1382 *to = 13;
1383 * ++ to = U'\n';
1384 } else {
1385 *to = *from;
1386 }
1387 *to = U'\0';
1388 SetWindowTextW (my d_widget -> window, Melder_peek32toW (winText.get()));
1389 UpdateWindow (my d_widget -> window);
1390 #elif cocoa
1391 trace (U"title");
1392 if (my d_cocoaTextView) {
1393 NSRange nsRange = NSMakeRange (0, [[my d_cocoaTextView textStorage] length]);
1394 NSString *nsString = (NSString *) Melder_peek32toCfstring (text);
1395 if (undoable)
1396 [my d_cocoaTextView shouldChangeTextInRange: nsRange replacementString: nsString]; // to make this action undoable
1397 //[[my d_cocoaTextView textStorage] replaceCharactersInRange: nsRange withString: nsString];
1398 if ((true)) {
1399 [my d_cocoaTextView setString: nsString];
1400 } else {
1401 NSMutableParagraphStyle * aMutableParagraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
1402 [aMutableParagraphStyle setTabStops: [NSArray array]];
1403 NSTextTab *tab400 = [[NSTextTab alloc] initWithType: NSLeftTabStopType location: 400.0];
1404 [aMutableParagraphStyle addTabStop: tab400];
1405 NSTextTab *tab500 = [[NSTextTab alloc] initWithType: NSLeftTabStopType location: 500.0];
1406 [aMutableParagraphStyle addTabStop: tab500];
1407 NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString: nsString];
1408 [attributedString addAttribute: NSParagraphStyleAttributeName value: aMutableParagraphStyle range: NSMakeRange (0, [nsString length])];
1409 [[my d_cocoaTextView textStorage] setAttributedString: attributedString];
1410 }
1411 [my d_cocoaTextView scrollRangeToVisible: NSMakeRange ([[my d_cocoaTextView textStorage] length], 0)]; // to the end
1412 //[[my d_cocoaTextView window] setViewsNeedDisplay: YES];
1413 //[[my d_cocoaTextView window] display];
1414 } else {
1415 [(NSTextField *) my d_widget setStringValue: (NSString *) Melder_peek32toCfstring (text)];
1416 }
1417 #endif
1418 }
1419
1420 void GuiText_setUndoItemcxx . . $ GuiText_setUndoItem(fe305b70bc020e42). (GuiTextcxx . . $ GuiText# me, GuiMenuItemcxx . . $ GuiMenuItem# item) {
1421 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1422 if (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item.) {
1423 //g_object_unref (my d_undo_item -> d_widget);
1424 }
1425 mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item. = item;
1426 if (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item.) {
1427 //g_object_ref (my d_undo_item -> d_widget);
1428 GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (mycxx . . $ `melder/melder.h:44:9`! d_undo_itemcxx . . $ structGuiText#d_undo_item., history_has_undocxx . . $ history_has_undo(67d3b309776c224d). (me));
1429 }
1430 #elif motif
1431 #elif cocoa
1432 #endif
1433 }
1434
1435 void GuiText_undocxx . . $ GuiText_undo(9d8ddf5c89937cf2). (GuiTextcxx . . $ GuiText# me) {
1436 #if gtkcxx . . $ `sys/Gui.h:33:10`!
1437 history_docxx . . $ history_do(365f281d9ebaace7). (me, 1);
1438 #elif motif
1439 #elif cocoa
1440 if (my d_cocoaTextView) {
1441 [[my d_cocoaTextView undoManager] undo];
1442 }
1443 #endif
1444 }
1445
1446 /* End of file GuiText.cpp */