Debian Codegraph @

sys/HyperPage.cpp

raw symbols SCIP
1 /* HyperPage.cpp
2 *
3 * Copyright (C) 1996-2026 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 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 "HyperPage.h"
20 #include "Printer.h"
21 #include "machine.h"
22 #include "GuiP.h"
23
24 #include "praat.h"
25 #include "EditorM.h"
26
27 Thing_implement (HyperPage, Editor, 0);
28
29 #include "Prefs_define.h"
30 #include "HyperPage_prefs.h"
31 #include "Prefs_install.h"
32 #include "HyperPage_prefs.h"
33 #include "Prefs_copyToInstance.h"
34 #include "HyperPage_prefs.h"
35
36 #define PAGE_HEIGHT 320.0
37 #define SCREEN_HEIGHT 18.0
38 #define PAPER_TOP 12.0
39 #define TOP_MARGIN 0.8
40 #define PAPER_BOTTOM (13.0 - (double) thePrinter. paperHeight / thePrinter. resolution)
41 #define BOTTOM_MARGIN 0.5
42 static double resolution;
43
44 /********** class HyperLink **********/
45
46 Thing_implement (HyperLink, Daata, 0);
47
48 autoHyperLink HyperLink_create (conststring32 name, double x1DC, double x2DC, double y1DC, double y2DC) {
49 autoHyperLink me = Thing_new (HyperLink);
50 Thing_setName (me.get(), name);
51 my x1DC = x1DC, my x2DC = x2DC, my y1DC = y1DC, my y2DC = y2DC;
52 return me;
53 }
54
55 static void saveHistory (HyperPage me, conststring32 title) {
56 if (! title)
57 return;
58
59 /*
60 The page title will be saved at the top. Go there.
61 */
62 while (my historyPointer < 19 && my history [my historyPointer]. page)
63 my historyPointer ++;
64
65 /*
66 If the page title to be saved is already at the top, ignore it.
67 */
68 if (my history [my historyPointer]. page) {
69 if (str32equ (my history [my historyPointer]. page.get(), title)) return;
70 } else if (my historyPointer > 0 && str32equ (my history [my historyPointer - 1]. page.get(), title)) {
71 my historyPointer --;
72 return;
73 }
74
75 /*
76 If the history buffer is full, shift it.
77 */
78 if (my historyPointer == 19 && my history [my historyPointer]. page) {
79 for (int i = 0; i < 19; i ++)
80 my history [i] = std::move (my history [i + 1]);
81 my history [19]. page. reset();
82 }
83
84 /*
85 Add the page title to the top of the history list.
86 */
87 my history [my historyPointer]. page = Melder_dup_f (title);
88 }
89
90 /********************************************************************************
91 *
92 * Before drawing or printing.
93 *
94 */
95
96 void HyperPage_initSheetOfPaper (HyperPage me) {
97 int reflect = my mirror && (my d_printingPageNumber & 1) == 0;
98 conststring32 leftHeader = reflect ? my outsideHeader : my insideHeader;
99 conststring32 rightHeader = reflect ? my insideHeader : my outsideHeader;
100 conststring32 leftFooter = reflect ? my outsideFooter : my insideFooter;
101 conststring32 rightFooter = reflect ? my insideFooter : my outsideFooter;
102
103 my d_y = PAPER_TOP - TOP_MARGIN;
104 my d_x = 0.0;
105 my previousBottomSpacing = 0.0;
106 Graphics_setFont (my ps, kGraphics_font::TIMES);
107 Graphics_setFontSize (my ps, 12);
108 Graphics_setFontStyle (my ps, Graphics_ITALIC);
109 if (leftHeader) {
110 Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_TOP);
111 Graphics_text (my ps, 0.7, PAPER_TOP, leftHeader);
112 }
113 if (my middleHeader) {
114 Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_TOP);
115 Graphics_text (my ps, 0.7 + 3, PAPER_TOP, my middleHeader);
116 }
117 if (rightHeader) {
118 Graphics_setTextAlignment (my ps, Graphics_RIGHT, Graphics_TOP);
119 Graphics_text (my ps, 0.7 + 6, PAPER_TOP, rightHeader);
120 }
121 if (leftFooter) {
122 Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
123 Graphics_text (my ps, 0.7, PAPER_BOTTOM, leftFooter);
124 }
125 if (my middleFooter) {
126 Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_BOTTOM);
127 Graphics_text (my ps, 0.7 + 3, PAPER_BOTTOM, my middleFooter);
128 }
129 if (rightFooter) {
130 Graphics_setTextAlignment (my ps, Graphics_RIGHT, Graphics_BOTTOM);
131 Graphics_text (my ps, 0.7 + 6, PAPER_BOTTOM, rightFooter);
132 }
133 Graphics_setFontStyle (my ps, Graphics_NORMAL);
134 if (my d_printingPageNumber)
135 Graphics_text (my ps, 0.7 + ( reflect ? 0 : 6 ), PAPER_BOTTOM, my d_printingPageNumber);
136 Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
137 }
138
139 static void updateVerticalScrollBar (HyperPage me);
140
141 void HyperPage_any (HyperPage me, conststring32 text, kGraphics_font font, double size, int style, double minFooterDistance,
142 double x, double secondIndent, double topSpacing, double bottomSpacing, uint32 method)
143 {
144 if (my rightMargin == 0.0)
145 return; // no infinite heights please
146 const double heightGuess = size * (1.2/72) * ((integer) size * Melder_length (text) / (int) (my rightMargin * 150));
147
148 if (! my printing) {
149 Graphics_Link *paragraphLinks;
150 int numberOfParagraphLinks, ilink;
151 if (my entryHint && (method & HyperPage_USE_ENTRY_HINT) && str32equ (text, my entryHint.get()))
152 my entryPosition = my d_y;
153 my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0;
154 my d_y -= size * (1.2/72);
155 my d_x = x;
156
157 if (/* my d_y > PAGE_HEIGHT + 2.0 + heightGuess || */ my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) {
158 my d_y -= heightGuess;
159 } else {
160 Graphics_setFont (my graphics.get(), font);
161 Graphics_setFontSize (my graphics.get(), size);
162 //if (method & HyperPage_EXECUTABLE)
163 // Graphics_setColour (my graphics.get(), Melder_GREEN);
164 //else
165 // Graphics_setColour (my graphics.get(), Melder_BLACK);
166 Graphics_setWrapWidth (my graphics.get(), my rightMargin - x - 0.1);
167 Graphics_setSecondIndent (my graphics.get(), secondIndent);
168 Graphics_setFontStyle (my graphics.get(), style);
169 Graphics_text (my graphics.get(), my d_x, my d_y, text);
170 numberOfParagraphLinks = Graphics_getLinks (& paragraphLinks);
171 for (ilink = 1; ilink <= numberOfParagraphLinks; ilink ++) {
172 autoHyperLink link = HyperLink_create (paragraphLinks [ilink]. name,
173 paragraphLinks [ilink]. x1, paragraphLinks [ilink]. x2,
174 paragraphLinks [ilink]. y1, paragraphLinks [ilink]. y2
175 );
176 my links. addItem_move (link.move());
177 }
178 if (method & HyperPage_ADD_BORDER) {
179 Graphics_setLineWidth (my graphics.get(), 2.0);
180 Graphics_line (my graphics.get(), 0.0, my d_y, my rightMargin, my d_y);
181 Graphics_setLineWidth (my graphics.get(), 1.0);
182 }
183 /*
184 The text may have wrapped.
185 Ask the Graphics manager by how much, and update our text position accordingly.
186 */
187 my d_y = Graphics_inqTextY (my graphics.get());
188 }
189 } else {
190 Graphics_setFont (my ps, font);
191 Graphics_setFontSize (my ps, size);
192 my d_y -= ( my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0 );
193 my d_y -= size * (1.2/72);
194 if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance + size * (1.2/72) * (Melder_length (text) / (6.0 * 10))) {
195 Graphics_nextSheetOfPaper (my ps);
196 if (my d_printingPageNumber != 0)
197 my d_printingPageNumber ++;
198 HyperPage_initSheetOfPaper (me);
199 Graphics_setFont (my ps, font);
200 Graphics_setFontSize (my ps, size);
201 my d_y -= size * (1.2/72);
202 }
203 my d_x = 0.7 + x;
204 Graphics_setWrapWidth (my ps, 6.0 - x);
205 Graphics_setSecondIndent (my ps, secondIndent);
206 Graphics_setFontStyle (my ps, style);
207 Graphics_text (my ps, my d_x, my d_y, text);
208 if (method & HyperPage_ADD_BORDER) {
209 Graphics_setLineWidth (my ps, 3.0);
210 /*Graphics_line (my ps, 0.7, my d_y, 6.7, my d_y);*/
211 Graphics_line (my ps, 0.7, my d_y + size * (1.2/72) + 0.07, 6.7, my d_y + size * (1.2/72) + 0.07);
212 Graphics_setLineWidth (my ps, 1.0);
213 }
214 my d_y = Graphics_inqTextY (my ps);
215 }
216 my previousBottomSpacing = bottomSpacing;
217 }
218
219 void HyperPage_pageTitle (HyperPage me, conststring32 title) {
220 HyperPage_any (me, title, my instancePref_font(), my instancePref_fontSize() * 2.0, 0,
221 2.0, 0.0, 0.0, my printing ? 0.4/2 : 0.2/2, 0.3/2, HyperPage_ADD_BORDER);
222 }
223 void HyperPage_intro (HyperPage me, conststring32 text) {
224 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.03, 0.0, 0.1, 0.1, 0);
225 }
226 void HyperPage_entry (HyperPage me, conststring32 title) {
227 HyperPage_any (me, title, my instancePref_font(), my instancePref_fontSize() * 1.4, Graphics_BOLD, 0.5, 0.0, 0.0, 0.25/1.4, 0.1/1.4, HyperPage_USE_ENTRY_HINT);
228 }
229 void HyperPage_subheader (HyperPage me, conststring32 title) {
230 HyperPage_any (me, title, my instancePref_font(), my instancePref_fontSize() * 1.2, Graphics_BOLD, 0.4, 0.0, 0.0, 0.25/1.2, 0.1/1.2, HyperPage_USE_ENTRY_HINT);
231 }
232 void HyperPage_paragraph (HyperPage me, conststring32 text) {
233 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.03, 0.0, 0.1, 0.1, 0);
234 }
235 void HyperPage_listItem (HyperPage me, conststring32 text) {
236 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.30, 0.2, 0.0, 0.0, 0);
237 }
238 void HyperPage_listItem1 (HyperPage me, conststring32 text) {
239 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.57, 0.2, 0.0, 0.0, 0);
240 }
241 void HyperPage_listItem2 (HyperPage me, conststring32 text) {
242 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.84, 0.2, 0.0, 0.0, 0);
243 }
244 void HyperPage_listItem3 (HyperPage me, conststring32 text) {
245 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 1.11, 0.2, 0.0, 0.0, 0);
246 }
247 void HyperPage_listTag (HyperPage me, conststring32 text) {
248 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.2, 0.03, 0.0, 0.1, 0.03, 0);
249 }
250 void HyperPage_listTag1 (HyperPage me, conststring32 text) {
251 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.2, 0.50, 0.0, 0.05, 0.03, 0);
252 }
253 void HyperPage_listTag2 (HyperPage me, conststring32 text) {
254 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.2, 0.97, 0.0, 0.03, 0.03, 0);
255 }
256 void HyperPage_listTag3 (HyperPage me, conststring32 text) {
257 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.2, 1.44, 0.0, 0.03, 0.03, 0);
258 }
259 void HyperPage_definition (HyperPage me, conststring32 text) {
260 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.5, 0.0, 0.03, 0.1, 0);
261 }
262 void HyperPage_definition1 (HyperPage me, conststring32 text) {
263 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.97, 0.0, 0.03, 0.05, 0);
264 }
265 void HyperPage_definition2 (HyperPage me, conststring32 text) {
266 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 1.44, 0.0, 0.03, 0.03, 0);
267 }
268 void HyperPage_definition3 (HyperPage me, conststring32 text) {
269 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 1.93, 0.0, 0.03, 0.03, 0);
270 }
271 void HyperPage_code0 (HyperPage me, conststring32 text) {
272 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 0.0, 0.5, 0.0, 0.0, 0);
273 }
274 void HyperPage_code (HyperPage me, conststring32 text) {
275 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 0.3, 0.5, 0.0, 0.0, HyperPage_EXECUTABLE);
276 }
277 void HyperPage_code1 (HyperPage me, conststring32 text) {
278 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 0.6, 0.5, 0.0, 0.0, 0);
279 }
280 void HyperPage_code2 (HyperPage me, conststring32 text) {
281 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 0.9, 0.5, 0.0, 0.0, 0);
282 }
283 void HyperPage_code3 (HyperPage me, conststring32 text) {
284 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 1.2, 0.5, 0.0, 0.0, 0);
285 }
286 void HyperPage_code4 (HyperPage me, conststring32 text) {
287 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 1.5, 0.5, 0.0, 0.0, 0);
288 }
289 void HyperPage_code5 (HyperPage me, conststring32 text) {
290 HyperPage_any (me, text, kGraphics_font::COURIER, my instancePref_fontSize() * 0.86, 0, 0.0, 1.8, 0.5, 0.0, 0.0, 0);
291 }
292 void HyperPage_caption (HyperPage me, conststring32 text) {
293 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize() * 0.86, 0, 0.0, 0.5, 0.5, 0.0, 0.2, 0);
294 }
295 void HyperPage_quote (HyperPage me, conststring32 text) {
296 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize() * 0.86, 0, 0.0, 0.5, 0.0, 0.1, 0.1, 0);
297 }
298 void HyperPage_quote1 (HyperPage me, conststring32 text) {
299 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize() * 0.86, 0, 0.0, 1.0, 0.0, 0.1, 0.1, 0);
300 }
301 void HyperPage_quote2 (HyperPage me, conststring32 text) {
302 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize() * 0.86, 0, 0.0, 1.5, 0.0, 0.1, 0.1, 0);
303 }
304 void HyperPage_quote3 (HyperPage me, conststring32 text) {
305 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize() * 0.86, 0, 0.0, 2.0, 0.0, 0.1, 0.1, 0);
306 }
307 void HyperPage_prototype (HyperPage me, conststring32 text) {
308 HyperPage_any (me, text, my instancePref_font(), my instancePref_fontSize(), 0, 0.0, 0.03, 0.5, 0.0, 0.0, 0);
309 }
310 void HyperPage_formula (HyperPage me, conststring32 formula) {
311 constexpr double topSpacing = 0.2, bottomSpacing = 0.2, minFooterDistance = 0.0;
312 const kGraphics_font font = my instancePref_font();
313 const double size = my instancePref_fontSize();
314 if (! my printing) {
315 my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0;
316 my d_y -= size * (1.2/72);
317 if (my d_y > PAGE_HEIGHT + 2.0 || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) {
318 } else {
319 Graphics_setFont (my graphics.get(), font);
320 Graphics_setFontStyle (my graphics.get(), 0);
321 Graphics_setFontSize (my graphics.get(), size);
322 Graphics_setWrapWidth (my graphics.get(), 0.0);
323 Graphics_setTextAlignment (my graphics.get(), Graphics_CENTRE, Graphics_BOTTOM);
324 Graphics_text (my graphics.get(), 0.5 * my rightMargin, my d_y, formula);
325 Graphics_setTextAlignment (my graphics.get(), Graphics_LEFT, Graphics_BOTTOM);
326 }
327 } else {
328 Graphics_setFont (my ps, font);
329 Graphics_setFontStyle (my ps, 0);
330 Graphics_setFontSize (my ps, size);
331 my d_y -= ( my d_y == PAPER_TOP - TOP_MARGIN ? 0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0 );
332 my d_y -= size * (1.2/72);
333 if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) {
334 Graphics_nextSheetOfPaper (my ps);
335 if (my d_printingPageNumber) my d_printingPageNumber ++;
336 HyperPage_initSheetOfPaper (me);
337 Graphics_setFont (my ps, font);
338 Graphics_setFontSize (my ps, size);
339 my d_y -= size * (1.2/72);
340 }
341 Graphics_setWrapWidth (my ps, 0.0);
342 Graphics_setTextAlignment (my ps, Graphics_CENTRE, Graphics_BOTTOM);
343 Graphics_text (my ps, 3.7, my d_y, formula);
344 Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
345 }
346 my previousBottomSpacing = bottomSpacing;
347 }
348
349 void HyperPage_picture (HyperPage me, double width_inches, double height_inches, void (*draw) (Graphics g)) {
350 constexpr double topSpacing = 0.1, bottomSpacing = 0.1, minFooterDistance = 0.0;
351 const kGraphics_font font = my instancePref_font();
352 const int size = my instancePref_fontSize();
353 width_inches *= ( width_inches < 0.0 ? -1.0 : size / 12.0 );
354 height_inches *= ( height_inches < 0.0 ? -1.0 : size / 12.0 );
355 if (! my printing) {
356 my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0;
357 if (my d_y > PAGE_HEIGHT + height_inches || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) {
358 my d_y -= height_inches;
359 } else {
360 my d_y -= height_inches;
361 Graphics_setFont (my graphics.get(), font);
362 Graphics_setFontStyle (my graphics.get(), 0);
363 Graphics_setFontSize (my graphics.get(), size);
364 my d_x = ( width_inches > my rightMargin ? 0.0 : 0.5 * (my rightMargin - width_inches) );
365 Graphics_setWrapWidth (my graphics.get(), 0.0);
366 Graphics_setViewport (my graphics.get(), my d_x, my d_x + width_inches, my d_y, my d_y + height_inches);
367 draw (my graphics.get());
368 Graphics_setViewport (my graphics.get(), 0.0, 1.0, 0.0, 1.0);
369 Graphics_setWindow (my graphics.get(), 0.0, 1.0, 0.0, 1.0);
370 Graphics_setTextAlignment (my graphics.get(), Graphics_LEFT, Graphics_BOTTOM);
371 }
372 } else {
373 Graphics_setFont (my ps, font);
374 Graphics_setFontStyle (my ps, 0);
375 Graphics_setFontSize (my ps, size);
376 my d_y -= ( my d_y == PAPER_TOP - TOP_MARGIN ? 0.0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * size / 12.0 );
377 my d_y -= height_inches;
378 if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) {
379 Graphics_nextSheetOfPaper (my ps);
380 if (my d_printingPageNumber) my d_printingPageNumber ++;
381 HyperPage_initSheetOfPaper (me);
382 Graphics_setFont (my ps, font);
383 Graphics_setFontSize (my ps, size);
384 my d_y -= height_inches;
385 }
386 my d_x = Melder_clippedLeft (0.0, 3.7 - 0.5 * width_inches);
387 Graphics_setWrapWidth (my ps, 0.0);
388 Graphics_setViewport (my ps, my d_x, my d_x + width_inches, my d_y, my d_y + height_inches);
389 draw (my ps);
390 Graphics_setViewport (my ps, 0.0, 1.0, 0.0, 1.0);
391 Graphics_setWindow (my ps, 0.0, 1.0, 0.0, 1.0);
392 Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
393 }
394 my previousBottomSpacing = bottomSpacing;
395 }
396
397 void HyperPage_script (HyperPage me, double width_inches, double height_inches, conststring32 script,
398 Graphics cacheGraphics, conststring32 cacheInfo)
399 {
400 if (cacheInfo && cacheInfo [0] != U'\0') {
401 const double fontSize = my instancePref_fontSize() * 0.86; // as in CODE
402 Graphics_setColour (my graphics.get(), Melder_MAGENTA);
403 HyperPage_code0 (me, U"\\#{=>}");
404 Graphics_setColour (my graphics.get(), Melder_BLACK);
405 //my d_y -= fontSize * (1.0/72); // some empty space between the code and the output
406 static MelderString buffer;
407 MelderString_empty (& buffer);
408 for (const char32 *p = & cacheInfo [0]; *p != U'\0'; p ++) {
409 if (Melder_isEndOfLine (*p)) {
410 if (
411 str32str (buffer.string, U"**AN ERROR OCCURRED IN THIS CODE CHUNK:**") ||
412 str32str (buffer.string, U"**ERROR** This code chunk was not run,")
413 )
414 Graphics_setColour (my graphics.get(), Melder_RED);
415 if (str32chr (buffer.string, U'\t')) // is there a tab *anywhere* in the line?
416 HyperPage_code (me, Melder_cat (U"\t", buffer.string)); // ... then make sure that the first column is also tabbed
417 else
418 HyperPage_code (me, buffer.string);
419 MelderString_empty (& buffer);
420 } else {
421 MelderString_appendCharacter (& buffer, *p);
422 }
423 }
424 Graphics_setColour (my graphics.get(), Melder_BLACK);
425 }
426 autostring32 text = Melder_dup (script);
427 constexpr double topSpacing = 0.1, bottomSpacing = 0.1, minFooterDistance = 0.0;
428 const kGraphics_font font = my instancePref_font();
429 const double fontSize = my instancePref_fontSize();
430 const double true_width_inches = width_inches * ( width_inches < 0.0 ? -1.0 : fontSize / 12.0 );
431 const double true_height_inches = height_inches * ( height_inches < 0.0 ? -1.0 : fontSize / 12.0 );
432 if (! my printing) {
433 my d_y -= ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * fontSize / 12.0;
434 if (my d_y > PAGE_HEIGHT + true_height_inches || my d_y < PAGE_HEIGHT - SCREEN_HEIGHT) {
435 my d_y -= true_height_inches;
436 } else {
437 my d_y -= true_height_inches;
438 Graphics_setFont (my graphics.get(), font);
439 Graphics_setFontStyle (my graphics.get(), 0);
440 Graphics_setFontSize (my graphics.get(), fontSize);
441 my d_x = ( true_width_inches > my rightMargin ? 0.0 : 0.5 * (my rightMargin - true_width_inches) );
442 Graphics_setWrapWidth (my graphics.get(), 0.0);
443 integer x1DCold, x2DCold, y1DCold, y2DCold;
444 Graphics_inqWsViewport (my graphics.get(), & x1DCold, & x2DCold, & y1DCold, & y2DCold);
445 double x1NDCold, x2NDCold, y1NDCold, y2NDCold;
446 Graphics_inqWsWindow (my graphics.get(), & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold);
447 {
448 if (! my praatApplication)
449 my praatApplication = Melder_calloc_f (structPraatApplication, 1);
450 if (! my praatObjects)
451 my praatObjects = Melder_calloc_f (structPraatObjects, 1);
452 if (! my praatPicture)
453 my praatPicture = Melder_calloc_f (structPraatPicture, 1);
454 theCurrentPraatApplication = my praatApplication;
455 theCurrentPraatApplication -> batch = true; // prevent creation of editor windows
456 theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs
457 theCurrentPraatObjects = my praatObjects;
458 theCurrentPraatPicture = my praatPicture;
459 theCurrentPraatPicture -> graphics = my graphics.get(); // has to draw into HyperPage rather than Picture window
460 theCurrentPraatPicture -> font = font;
461 theCurrentPraatPicture -> fontSize = fontSize;
462 theCurrentPraatPicture -> lineType = Graphics_DRAWN;
463 theCurrentPraatPicture -> colour = Melder_BLACK;
464 theCurrentPraatPicture -> lineWidth = 1.0;
465 theCurrentPraatPicture -> arrowSize = 1.0;
466 theCurrentPraatPicture -> speckleSize = 1.0;
467 theCurrentPraatPicture -> x1NDC = my d_x;
468 theCurrentPraatPicture -> x2NDC = my d_x + true_width_inches;
469 theCurrentPraatPicture -> y1NDC = my d_y;
470 theCurrentPraatPicture -> y2NDC = my d_y + true_height_inches;
471
472 Graphics_setViewport (my graphics.get(), theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
473 Graphics_setWindow (my graphics.get(), 0.0, 1.0, 0.0, 1.0);
474 integer x1DC, y1DC, x2DC, y2DC;
475 Graphics_WCtoDC (my graphics.get(), 0.0, 0.0, & x1DC, & y2DC);
476 Graphics_WCtoDC (my graphics.get(), 1.0, 1.0, & x2DC, & y1DC);
477 Graphics_resetWsViewport (my graphics.get(), x1DC, x2DC, y1DC, y2DC);
478 Graphics_setWsWindow (my graphics.get(), 0, width_inches, 0, height_inches);
479 theCurrentPraatPicture -> x1NDC = 0.0;
480 theCurrentPraatPicture -> x2NDC = width_inches;
481 theCurrentPraatPicture -> y1NDC = 0.0;
482 theCurrentPraatPicture -> y2NDC = height_inches;
483 Graphics_setViewport (my graphics.get(), theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
484
485 {// scope
486 autoMelderProgressOff progress;
487 autoMelderWarningOff nowarn;
488 autoMelderSaveCurrentFolder saveFolder;
489 if (! MelderFolder_isNull (& my rootDirectory))
490 Melder_setCurrentFolder (& my rootDirectory);
491 Melder_assert (cacheGraphics);
492 const bool dollarSignWasCode = my graphics -> dollarSignIsCode;
493 const bool backquoteWasVerbatim = my graphics -> backquoteIsVerbatim;
494 const bool atSignWasLink = my graphics -> atSignIsLink;
495 Graphics_setDollarSignIsCode (my graphics.get(), false);
496 Graphics_setBackquoteIsVerbatim (my graphics.get(), false);
497 Graphics_setAtSignIsLink (my graphics.get(), false);
498 Graphics_play (cacheGraphics, my graphics.get());
499 if (dollarSignWasCode)
500 Graphics_setDollarSignIsCode (my graphics.get(), true);
501 if (backquoteWasVerbatim)
502 Graphics_setBackquoteIsVerbatim (my graphics.get(), true);
503 if (atSignWasLink)
504 Graphics_setAtSignIsLink (my graphics.get(), true);
505 }
506 Graphics_setLineType (my graphics.get(), Graphics_DRAWN);
507 Graphics_setLineWidth (my graphics.get(), 1.0);
508 Graphics_setArrowSize (my graphics.get(), 1.0);
509 Graphics_setSpeckleSize (my graphics.get(), 1.0);
510 Graphics_setColour (my graphics.get(), Melder_BLACK);
511 theCurrentPraatApplication = & theForegroundPraatApplication;
512 theCurrentPraatObjects = & theForegroundPraatObjects;
513 theCurrentPraatPicture = & theForegroundPraatPicture;
514 }
515 Graphics_resetWsViewport (my graphics.get(), x1DCold, x2DCold, y1DCold, y2DCold);
516 Graphics_setWsWindow (my graphics.get(), x1NDCold, x2NDCold, y1NDCold, y2NDCold);
517 Graphics_setViewport (my graphics.get(), 0.0, 1.0, 0.0, 1.0);
518 Graphics_setWindow (my graphics.get(), 0.0, 1.0, 0.0, 1.0);
519 Graphics_setTextAlignment (my graphics.get(), Graphics_LEFT, Graphics_BOTTOM);
520 }
521 } else {
522 Graphics_setFont (my ps, font);
523 Graphics_setFontStyle (my ps, 0);
524 Graphics_setFontSize (my ps, fontSize);
525 my d_y -= ( my d_y == PAPER_TOP - TOP_MARGIN ? 0.0 : ( my previousBottomSpacing > topSpacing ? my previousBottomSpacing : topSpacing ) * fontSize / 12.0 );
526 my d_y -= true_height_inches;
527 if (my d_y < PAPER_BOTTOM + BOTTOM_MARGIN + minFooterDistance) {
528 Graphics_nextSheetOfPaper (my ps);
529 if (my d_printingPageNumber) my d_printingPageNumber ++;
530 HyperPage_initSheetOfPaper (me);
531 Graphics_setFont (my ps, font);
532 Graphics_setFontSize (my ps, fontSize);
533 my d_y -= true_height_inches;
534 }
535 my d_x = Melder_clippedLeft (0.0, 3.7 - 0.5 * true_width_inches);
536 Graphics_setWrapWidth (my ps, 0.0);
537 integer x1DCold, x2DCold, y1DCold, y2DCold;
538 Graphics_inqWsViewport (my ps, & x1DCold, & x2DCold, & y1DCold, & y2DCold);
539 double x1NDCold, x2NDCold, y1NDCold, y2NDCold;
540 Graphics_inqWsWindow (my ps, & x1NDCold, & x2NDCold, & y1NDCold, & y2NDCold);
541 {
542 if (! my praatApplication)
543 my praatApplication = Melder_calloc_f (structPraatApplication, 1);
544 if (! my praatObjects)
545 my praatObjects = Melder_calloc_f (structPraatObjects, 1);
546 if (! my praatPicture)
547 my praatPicture = Melder_calloc_f (structPraatPicture, 1);
548 theCurrentPraatApplication = my praatApplication;
549 theCurrentPraatApplication -> batch = true;
550 theCurrentPraatApplication -> topShell = theForegroundPraatApplication. topShell; // needed for UiForm_create () in dialogs
551 theCurrentPraatObjects = my praatObjects;
552 theCurrentPraatPicture = my praatPicture;
553 theCurrentPraatPicture -> graphics = my ps;
554 theCurrentPraatPicture -> font = font;
555 theCurrentPraatPicture -> fontSize = fontSize;
556 theCurrentPraatPicture -> lineType = Graphics_DRAWN;
557 theCurrentPraatPicture -> colour = Melder_BLACK;
558 theCurrentPraatPicture -> lineWidth = 1.0;
559 theCurrentPraatPicture -> arrowSize = 1.0;
560 theCurrentPraatPicture -> speckleSize = 1.0;
561 theCurrentPraatPicture -> x1NDC = my d_x;
562 theCurrentPraatPicture -> x2NDC = my d_x + true_width_inches;
563 theCurrentPraatPicture -> y1NDC = my d_y;
564 theCurrentPraatPicture -> y2NDC = my d_y + true_height_inches;
565
566 Graphics_setViewport (my ps, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
567 Graphics_setWindow (my ps, 0.0, 1.0, 0.0, 1.0);
568 integer x1DC, y1DC, x2DC, y2DC;
569 Graphics_WCtoDC (my ps, 0.0, 0.0, & x1DC, & y2DC);
570 Graphics_WCtoDC (my ps, 1.0, 1.0, & x2DC, & y1DC);
571 integer shift = (integer) (Graphics_getResolution (my ps) * true_height_inches) + (y1DCold - y2DCold);
572 #if cocoa
573 shift = 0; // this is a FIX
574 #endif
575 Graphics_resetWsViewport (my ps, x1DC, x2DC, y1DC + shift, y2DC + shift);
576 Graphics_setWsWindow (my ps, 0, width_inches, 0, height_inches);
577 theCurrentPraatPicture -> x1NDC = 0.0;
578 theCurrentPraatPicture -> x2NDC = width_inches;
579 theCurrentPraatPicture -> y1NDC = 0.0;
580 theCurrentPraatPicture -> y2NDC = height_inches;
581 Graphics_setViewport (my ps, theCurrentPraatPicture -> x1NDC, theCurrentPraatPicture -> x2NDC, theCurrentPraatPicture -> y1NDC, theCurrentPraatPicture -> y2NDC);
582
583 {// scope
584 autoMelderProgressOff progress;
585 autoMelderWarningOff nowarn;
586 autoMelderSaveCurrentFolder saveFolder;
587 if (! MelderFolder_isNull (& my rootDirectory))
588 Melder_setCurrentFolder (& my rootDirectory);
589 try {
590 //Interpreter_run (interpreter, text.move(), false); // BUG: implement
591 } catch (MelderError) {
592 Melder_clearError ();
593 }
594 }
595 Graphics_setLineType (my ps, Graphics_DRAWN);
596 Graphics_setLineWidth (my ps, 1.0);
597 Graphics_setArrowSize (my ps, 1.0);
598 Graphics_setSpeckleSize (my ps, 1.0);
599 Graphics_setColour (my ps, Melder_BLACK);
600 theCurrentPraatApplication = & theForegroundPraatApplication;
601 theCurrentPraatObjects = & theForegroundPraatObjects;
602 theCurrentPraatPicture = & theForegroundPraatPicture;
603 }
604 Graphics_resetWsViewport (my ps, x1DCold, x2DCold, y1DCold, y2DCold);
605 Graphics_setWsWindow (my ps, x1NDCold, x2NDCold, y1NDCold, y2NDCold);
606 Graphics_setViewport (my ps, 0.0, 1.0, 0.0, 1.0);
607 Graphics_setWindow (my ps, 0.0, 1.0, 0.0, 1.0);
608 Graphics_setTextAlignment (my ps, Graphics_LEFT, Graphics_BOTTOM);
609 }
610 my previousBottomSpacing = bottomSpacing;
611 }
612
613 static void print (void *void_me, Graphics graphics) {
614 iam (HyperPage);
615 my ps = graphics;
616 Graphics_setDollarSignIsCode (graphics, true); // for manuals
617 Graphics_setBackquoteIsVerbatim (graphics, true); // for notebooks
618 Graphics_setAtSignIsLink (graphics, true);
619 my printing = true;
620 HyperPage_initSheetOfPaper (me);
621 my v_draw ();
622 my printing = false;
623 }
624
625 /********** class HyperPage **********/
626
627 void structHyperPage :: v9_destroy () noexcept {
628 if (our praatApplication) {
629 for (integer iobject = ((PraatObjects) our praatObjects) -> n; iobject >= 1; iobject --) {
630 ((PraatObjects) our praatObjects) -> list [iobject]. name. reset();
631 forget (((PraatObjects) our praatObjects) -> list [iobject]. object);
632 }
633 Melder_free (our praatApplication);
634 Melder_free (our praatObjects);
635 Melder_free (our praatPicture);
636 }
637 our HyperPage_Parent :: v9_destroy ();
638 }
639
640 static void gui_drawingarea_cb_expose (HyperPage me, GuiDrawingArea_ExposeEvent /* event */) {
641 trace (U"HyperPage: gui_drawingarea_cb_expose");
642 if (! my graphics)
643 return; // could be the case in the very beginning
644 if (my entryHint && my entryPosition != 0.0) {
645 my entryHint. reset();
646 my top = 5.0 * (PAGE_HEIGHT - my entryPosition);
647 Melder_clipLeft (0.0, & my top);
648 }
649 my d_y = PAGE_HEIGHT + my top / 5.0;
650 my d_x = 0.0;
651 my previousBottomSpacing = 0.0;
652 my links. removeAllItems ();
653 trace (U"going to draw");
654 Graphics_clearWs (my graphics.get());
655 my v_draw ();
656 }
657
658 static void gui_drawingarea_cb_mouse (HyperPage me, GuiDrawingArea_MouseEvent event) {
659 if (! event -> isClick())
660 return;
661 if (! my graphics)
662 return; // could be the case in the very beginning
663 for (integer ilink = 1; ilink <= my links.size; ilink ++) {
664 HyperLink link = my links.at [ilink];
665 if (! link)
666 Melder_crash (U"gui_drawingarea_cb_click: empty link ", ilink, U"/", my links.size, U".");
667 if (event -> y > link -> y2DC && event -> y < link -> y1DC && event -> x > link -> x1DC && event -> x < link -> x2DC) {
668 saveHistory (me, my optionalCurrentPageTitle.get());
669 try {
670 HyperPage_goToPage (me, link -> name.get());
671 } catch (MelderError) {
672 Melder_flushError ();
673 }
674 return;
675 }
676 }
677 }
678
679 extern "C" void GRAPHICS_PostScript_settings (UiForm sendingForm, int narg, Stackel args, conststring32 sendingString, Interpreter interpreter, conststring32 invokingButtonTitle, bool modified, void *buttonClosure);
680
681 static void menu_cb_postScriptSettings (HyperPage me, EDITOR_ARGS) {
682 (void) me;
683 (void) cmd;
684 GRAPHICS_PostScript_settings (_sendingForm_, _narg_, _args_, _sendingString_, optionalInterpreter, nullptr, false, nullptr);
685 }
686
687 #ifdef macintosh
688 static void menu_cb_pageSetup (HyperPage me, EDITOR_ARGS) {
689 (void) me;
690 Printer_pageSetup ();
691 }
692 #endif
693
694 static void menu_cb_print (HyperPage me, EDITOR_ARGS) {
695 EDITOR_FORM (U"Print", nullptr)
696 SENTENCE_FIELD (my insideHeader, U"Left or inside header", U"")
697 SENTENCE_FIELD (my middleHeader, U"Middle header", U"")
698 TEXTFIELD_FIELD (my outsideHeader, U"Right or outside header", U"", 2)
699 SENTENCE_FIELD (my insideFooter, U"Left or inside footer", U"")
700 SENTENCE_FIELD (my middleFooter, U"Middle footer", U"")
701 SENTENCE_FIELD (my outsideFooter, U"Right or outside footer", U"")
702 BOOLEAN_FIELD (my mirror, U"Mirror even/odd headers", true)
703 INTEGER_FIELD (my d_printingPageNumber, U"First page number", U"0 (= no page numbers)")
704 EDITOR_OK
705 my v_defaultHeaders (cmd);
706 if (my d_printingPageNumber != 0)
707 SET_INTEGER (my d_printingPageNumber, my d_printingPageNumber + 1)
708 EDITOR_DO
709 Printer_print (print, me);
710 EDITOR_END
711 }
712
713 static void menu_cb_font (HyperPage me, EDITOR_ARGS) {
714 EDITOR_FORM (U"Font", nullptr)
715 CHOICE (font, U"Font", 1)
716 OPTION (U"Times")
717 OPTION (U"Helvetica")
718 EDITOR_OK
719 SET_OPTION (font, my instancePref_font() == kGraphics_font::TIMES ? 1 :
720 my instancePref_font() == kGraphics_font::HELVETICA ? 2 : my instancePref_font() == kGraphics_font::PALATINO ? 3 : 1);
721 EDITOR_DO
722 my setInstancePref_font ( font == 1 ? kGraphics_font::TIMES : kGraphics_font::HELVETICA );
723 Editor_dataChanged (me, me);
724 if (my graphics)
725 Graphics_updateWs (my graphics.get());
726 EDITOR_END
727 }
728
729 static void updateSizeMenu (HyperPage me) {
730 GuiMenuItem_check (my fontSizeButton_10, my instancePref_fontSize() == 10);
731 GuiMenuItem_check (my fontSizeButton_12, my instancePref_fontSize() == 12);
732 GuiMenuItem_check (my fontSizeButton_14, my instancePref_fontSize() == 14);
733 GuiMenuItem_check (my fontSizeButton_18, my instancePref_fontSize() == 18);
734 GuiMenuItem_check (my fontSizeButton_24, my instancePref_fontSize() == 24);
735 }
736 static void setFontSize (HyperPage me, double fontSize) {
737 my setInstancePref_fontSize (fontSize);
738 Editor_dataChanged (me, me);
739 updateSizeMenu (me);
740 if (my graphics)
741 Graphics_updateWs (my graphics.get());
742 }
743
744 static void menu_cb_10 (HyperPage me, EDITOR_ARGS) { setFontSize (me, 10.0); }
745 static void menu_cb_12 (HyperPage me, EDITOR_ARGS) { setFontSize (me, 12.0); }
746 static void menu_cb_14 (HyperPage me, EDITOR_ARGS) { setFontSize (me, 14.0); }
747 static void menu_cb_18 (HyperPage me, EDITOR_ARGS) { setFontSize (me, 18.0); }
748 static void menu_cb_24 (HyperPage me, EDITOR_ARGS) { setFontSize (me, 24.0); }
749
750 static void menu_cb_fontSize (HyperPage me, EDITOR_ARGS) {
751 EDITOR_FORM (U"Font size", nullptr)
752 POSITIVE (fontSize, U"Font size (points)", my default_fontSize ())
753 EDITOR_OK
754 SET_REAL (fontSize, my instancePref_fontSize())
755 EDITOR_DO
756 setFontSize (me, fontSize);
757 EDITOR_END
758 }
759
760 static void menu_cb_searchForPage (HyperPage me, EDITOR_ARGS) {
761 EDITOR_FORM (U"Search for page", nullptr)
762 TEXTFIELD (page, U"Page", U"a", 2)
763 EDITOR_OK
764 EDITOR_DO
765 HyperPage_goToPage (me, page);
766 EDITOR_END
767 }
768
769 /********************************************************************************
770 *
771 * The vertical scroll bar controls and/or mirrors
772 * the position of the viewable area within the page.
773 * A page can be PAGE_HEIGHT inches high, so 'my top' (and the scroll-bar 'value')
774 * may take on values between 0 and PAGE_HEIGHT * 5 (fifth inches).
775 * Hence, the 'minimum' is 0.
776 * The viewable area shows a certain number of fifth inches;
777 * hence the 'sliderSize' is height / resolution * 5,
778 * and the 'maximum' is PAGE_HEIGHT * 5.
779 * The 'increment' is 1, so the arrows move the page by one fifth of an inch.
780 * The 'pageIncrement' is sliderSize - 1.
781 */
782
783 static void gui_cb_verticalScroll (HyperPage me, GuiScrollBarEvent event) {
784 trace (U"gui_cb_verticalScroll");
785 const double value = GuiScrollBar_getValue (event -> scrollBar);
786 if (value != my top) {
787 trace (U"scroll from ", my top, U" to ", value);
788 my top = value;
789 updateVerticalScrollBar (me);
790 Graphics_updateWs (my graphics.get());
791 }
792 }
793
794 static void createVerticalScrollBar (HyperPage me, GuiForm parent) {
795 const int height = Machine_getTextHeight ();
796 my verticalScrollBar = GuiScrollBar_createShown (parent,
797 - Machine_getScrollBarWidth (), 0,
798 Machine_getMenuBarBottom () + (my d_hasExtraRowOfTools ? 2 * height + 19 : height + 12), - Machine_getScrollBarWidth (),
799 0, PAGE_HEIGHT * 5, 0, 25, 1, 24,
800 gui_cb_verticalScroll, me, 0
801 );
802 }
803
804 static void updateVerticalScrollBar (HyperPage me)
805 /* We cannot call this immediately after creation. */
806 /* This has to be called after changing `my top`. */
807 {
808 trace (U"updateVerticalScrollBar");
809 const int sliderSize = 25;
810 GuiScrollBar_set (my verticalScrollBar, undefined, undefined, my top, sliderSize, 1, sliderSize - 1);
811 my history [my historyPointer]. top = 0/*my top*/;
812 }
813
814 static void menu_cb_pageUp (HyperPage me, EDITOR_ARGS) {
815 if (! my verticalScrollBar)
816 return;
817 const double value = Melder_clippedLeft (0.0, GuiScrollBar_getValue (my verticalScrollBar) - 24.0);
818 if (value != my top) {
819 my top = value;
820 updateVerticalScrollBar (me);
821 Graphics_updateWs (my graphics.get());
822 }
823 }
824
825 static void menu_cb_pageDown (HyperPage me, EDITOR_ARGS) {
826 if (! my verticalScrollBar)
827 return;
828 const double value = Melder_clippedRight (GuiScrollBar_getValue (my verticalScrollBar) + 24.0, (PAGE_HEIGHT * 5.0) - 25.0);
829 if (value != my top) {
830 my top = value;
831 updateVerticalScrollBar (me);
832 Graphics_updateWs (my graphics.get());
833 }
834 }
835
836 /********** **********/
837
838 static void do_back (HyperPage me) {
839 if (my historyPointer <= 0)
840 return;
841 autostring32 pageTitle = Melder_dup_f (my history [-- my historyPointer]. page.get()); // temporary, because pointer will be moved
842 Melder_assert (pageTitle);
843 const double top = my history [my historyPointer]. top;
844 if (my v_goToPage (pageTitle.get())) {
845 my top = top;
846 updateVerticalScrollBar (me);
847 HyperPage_clear (me);
848 }
849 }
850
851 static void menu_cb_back (HyperPage me, EDITOR_ARGS) {
852 do_back (me);
853 }
854
855 static void gui_button_cb_back (HyperPage me, GuiButtonEvent /* event */) {
856 do_back (me);
857 }
858
859 static void do_forth (HyperPage me) {
860 if (my historyPointer >= 19 || ! my history [my historyPointer + 1]. page)
861 return;
862 autostring32 pageTitle = Melder_dup_f (my history [++ my historyPointer]. page.get());
863 Melder_assert (pageTitle);
864 const double top = my history [my historyPointer]. top;
865 if (my v_goToPage (pageTitle.get())) {
866 my top = top;
867 updateVerticalScrollBar (me);
868 HyperPage_clear (me);
869 }
870 }
871
872 static void menu_cb_forth (HyperPage me, EDITOR_ARGS) {
873 do_forth (me);
874 }
875
876 static void gui_button_cb_forth (HyperPage me, GuiButtonEvent /* event */) {
877 do_forth (me);
878 }
879
880 static void menu_cb_previousPage (HyperPage me, EDITOR_ARGS) {
881 HyperPage_goToPage_number (me, my v_getCurrentPageNumber () > 1 ?
882 my v_getCurrentPageNumber () - 1 : my v_getNumberOfPages ());
883 }
884
885 static void gui_button_cb_previousPage (HyperPage me, GuiButtonEvent /* event */) {
886 HyperPage_goToPage_number (me, my v_getCurrentPageNumber () > 1 ?
887 my v_getCurrentPageNumber () - 1 : my v_getNumberOfPages ());
888 }
889
890 static void menu_cb_nextPage (HyperPage me, EDITOR_ARGS) {
891 const integer currentPageNumber = my v_getCurrentPageNumber ();
892 HyperPage_goToPage_number (me, currentPageNumber < my v_getNumberOfPages () ? currentPageNumber + 1 : 1);
893 }
894
895 static void gui_button_cb_nextPage (HyperPage me, GuiButtonEvent /* event */) {
896 const integer currentPageNumber = my v_getCurrentPageNumber ();
897 HyperPage_goToPage_number (me, currentPageNumber < my v_getNumberOfPages () ? currentPageNumber + 1 : 1);
898 }
899
900 void structHyperPage :: v_createMenus () {
901 HyperPage_Parent :: v_createMenus ();
902
903 Editor_addCommand (this, U"File", U"PostScript settings...", GuiMenu_HIDDEN, menu_cb_postScriptSettings);
904 #ifdef macintosh
905 Editor_addCommand (this, U"File", U"Page setup...", GuiMenu_HIDDEN, menu_cb_pageSetup);
906 #endif
907 Editor_addCommand (this, U"File", U"Print page...", GuiMenu_HIDDEN, menu_cb_print);
908 Editor_addCommand (this, U"File", U"-- close --", GuiMenu_HIDDEN, nullptr);
909
910 if (our v_hasHistory ()) {
911 Editor_addMenu (this, U"Go to", 0);
912 #ifdef _WIN32
913 Editor_addCommand (this, U"Go to", U"Back", GuiMenu_COMMAND | GuiMenu_LEFT_ARROW, menu_cb_back); // TODO: this actually captures the Alt key; why?
914 Editor_addCommand (this, U"Go to", U"Forward", GuiMenu_COMMAND | GuiMenu_RIGHT_ARROW, menu_cb_forth);
915 #else
916 Editor_addCommand (this, U"Go to", U"Back", GuiMenu_OPTION | GuiMenu_LEFT_ARROW, menu_cb_back);
917 Editor_addCommand (this, U"Go to", U"Forward", GuiMenu_OPTION | GuiMenu_RIGHT_ARROW, menu_cb_forth);
918 #endif
919 Editor_addCommand (this, U"Go to", U"-- browse --", 0, nullptr);
920 #ifdef _WIN32
921 Editor_addCommand (this, U"Go to", U"Previous page", GuiMenu_COMMAND | GuiMenu_SHIFT | GuiMenu_LEFT_ARROW, menu_cb_previousPage);
922 Editor_addCommand (this, U"Go to", U"Next page", GuiMenu_COMMAND | GuiMenu_SHIFT | GuiMenu_RIGHT_ARROW, menu_cb_nextPage);
923 #else
924 Editor_addCommand (this, U"Go to", U"Previous page", GuiMenu_COMMAND | GuiMenu_LEFT_ARROW, menu_cb_previousPage);
925 Editor_addCommand (this, U"Go to", U"Next page", GuiMenu_COMMAND | GuiMenu_RIGHT_ARROW, menu_cb_nextPage);
926 #endif
927 Editor_addCommand (this, U"Go to", U"-- page --", 0, nullptr);
928 Editor_addCommand (this, U"Go to", U"Page up", GuiMenu_PAGE_UP, menu_cb_pageUp);
929 Editor_addCommand (this, U"Go to", U"Page down", GuiMenu_PAGE_DOWN, menu_cb_pageDown);
930 Editor_addCommand (this, U"Go to", U"-- page --", 0, nullptr);
931 Editor_addCommand (this, U"Go to", U"Search for page...", 0, menu_cb_searchForPage);
932 }
933
934 Editor_addMenu (this, U"Font", 0);
935 Editor_addCommand (this, U"Font", U"Font size...", 0, menu_cb_fontSize);
936 fontSizeButton_10 = Editor_addCommand (this, U"Font", U"10", GuiMenu_CHECKBUTTON, menu_cb_10);
937 fontSizeButton_12 = Editor_addCommand (this, U"Font", U"12", GuiMenu_CHECKBUTTON, menu_cb_12);
938 fontSizeButton_14 = Editor_addCommand (this, U"Font", U"14", GuiMenu_CHECKBUTTON, menu_cb_14);
939 fontSizeButton_18 = Editor_addCommand (this, U"Font", U"18", GuiMenu_CHECKBUTTON, menu_cb_18);
940 fontSizeButton_24 = Editor_addCommand (this, U"Font", U"24", GuiMenu_CHECKBUTTON, menu_cb_24);
941 Editor_addCommand (this, U"Font", U"-- font --", 0, nullptr);
942 Editor_addCommand (this, U"Font", U"Font...", 0, menu_cb_font);
943 }
944
945 /********** **********/
946
947 static void gui_drawingarea_cb_resize (HyperPage me, GuiDrawingArea_ResizeEvent event) {
948 trace (U"HyperPage: gui_drawingarea_cb_resize");
949 if (! my graphics)
950 return;
951 Graphics_setWsViewport (my graphics.get(), 0.0, event -> width, 0.0, event -> height);
952 Graphics_setWsWindow (my graphics.get(), 0.0, my rightMargin = event -> width / resolution,
953 PAGE_HEIGHT - event -> height / resolution, PAGE_HEIGHT);
954 //updateVerticalScrollBar (me);
955 //Graphics_updateWs (my graphics.get());
956 }
957
958 void structHyperPage :: v_createChildren () {
959 const int height = Machine_getTextHeight ();
960 const int y = Machine_getMenuBarBottom () + 4;
961
962 /***** Create navigation buttons. *****/
963
964 if (our v_hasHistory ()) {
965 GuiButton_createShown (our windowForm, 4, 48, y, y + height,
966 U"<", gui_button_cb_back, this, 0);
967 GuiButton_createShown (our windowForm, 54, 98, y, y + height,
968 U">", gui_button_cb_forth, this, 0);
969 }
970 if (our v_isOrdered ()) {
971 GuiButton_createShown (our windowForm, 174, 218, y, y + height,
972 U"< 1", gui_button_cb_previousPage, this, 0);
973 GuiButton_createShown (our windowForm, 224, 268, y, y + height,
974 U"1 >", gui_button_cb_nextPage, this, 0);
975 }
976
977 /***** Create scroll bar. *****/
978
979 createVerticalScrollBar (this, our windowForm);
980
981 /***** Create drawing area. *****/
982
983 drawingArea = GuiDrawingArea_createShown (our windowForm,
984 0, - Machine_getScrollBarWidth (),
985 y + ( our d_hasExtraRowOfTools ? 2 * height + 16 : height + 9 ), - Machine_getScrollBarWidth (),
986 gui_drawingarea_cb_expose, gui_drawingarea_cb_mouse,
987 nullptr, gui_drawingarea_cb_resize, nullptr, this, GuiDrawingArea_BORDER
988 );
989 GuiDrawingArea_setSwipable (drawingArea, nullptr, our verticalScrollBar);
990 }
991
992 void HyperPage_init1 (HyperPage me, conststring32 title, Daata data, bool backquoteIsVerbatim) {
993 resolution = Gui_getResolution (nullptr);
994 const int width = 760; // used to be (int) floor (6 * resolution + 30)
995 Editor_init (me, 0, 0, width, 800, title, data);
996 #if motif
997 Melder_assert (XtWindow (my drawingArea -> d_widget));
998 #endif
999 my graphics = Graphics_create_xmdrawingarea (my drawingArea);
1000 Graphics_setDollarSignIsCode (my graphics.get(), true); // for manuals
1001 if (backquoteIsVerbatim)
1002 Graphics_setBackquoteIsVerbatim (my graphics.get(), true); // for notebooks
1003 Graphics_setAtSignIsLink (my graphics.get(), true);
1004 Graphics_setFont (my graphics.get(), kGraphics_font::TIMES);
1005 if (my instancePref_font() != kGraphics_font::TIMES && my instancePref_font() != kGraphics_font::HELVETICA)
1006 my setInstancePref_font (kGraphics_font::TIMES); // ensure Unicode compatibility
1007 }
1008 void HyperPage_init2 (HyperPage me, conststring32 /* title */, Daata /* data */) {
1009 /*
1010 Relevant parts from the dataChanged message:
1011 */
1012 updateSizeMenu (me);
1013 Graphics_updateWs (my graphics.get());
1014
1015 struct structGuiDrawingArea_ResizeEvent event { my drawingArea, 0, 0 };
1016 event. width = GuiControl_getWidth (my drawingArea);
1017 event. height = GuiControl_getHeight (my drawingArea);
1018 gui_drawingarea_cb_resize (me, & event);
1019
1020 updateVerticalScrollBar (me); // scroll to the top (my top == 0)
1021 }
1022 void HyperPage_init (HyperPage me, conststring32 title, Daata data) {
1023 HyperPage_init1 (me, title, data, false);
1024 HyperPage_init2 (me, title, data);
1025 }
1026
1027 void HyperPage_clear (HyperPage me) {
1028 my links. removeAllItems();
1029 Graphics_updateWs (my graphics.get());
1030 }
1031
1032 void structHyperPage :: v1_dataChanged (Editor /* sender */) {
1033 const bool oldError = Melder_hasError (); // this method can be called during error time
1034 (void) our v_goToPage (our optionalCurrentPageTitle.get());
1035 if (Melder_hasError () && ! oldError)
1036 Melder_flushError ();
1037 updateVerticalScrollBar (this);
1038 HyperPage_clear (this);
1039 }
1040
1041 int HyperPage_goToPage (HyperPage me, conststring32 pageTitle) {
1042 Melder_assert (pageTitle);
1043 switch (my v_goToPage (pageTitle)) {
1044 case -1: return 0;
1045 case 0: HyperPage_clear (me); return 0;
1046 }
1047 saveHistory (me, pageTitle); // last chance: HyperPage_clear will destroy "title" !!!
1048 my optionalCurrentPageTitle = Melder_dup_f (pageTitle);
1049 Melder_assert (my optionalCurrentPageTitle);
1050 my top = 0.0;
1051 updateVerticalScrollBar (me); // scroll to the top (my top == 0)
1052 HyperPage_clear (me);
1053 return 1;
1054 }
1055
1056 void HyperPage_goToPage_number (HyperPage me, integer optionalPageNumber) {
1057 my v_goToPage_number (optionalPageNumber); // catch -> HyperPage_clear (me); ?
1058 Melder_assert (! optionalPageNumber || my optionalCurrentPageTitle); // only page 0 has no title
1059 my top = 0.0;
1060 updateVerticalScrollBar (me); // scroll to the top (my top == 0.0)
1061 HyperPage_clear (me);
1062 }
1063
1064 void HyperPage_setEntryHint (HyperPage me, conststring32 hint) {
1065 my entryHint = Melder_dup_f (hint);
1066 }
1067
1068 /* End of file HyperPage.cpp */