1 #ifndef _Gui_h_
2 #define _Gui_h_
3 /* Gui.h
4 *
5 * Copyright (C) 1993-2021 Paul Boersma, 2013 Tom Naughton
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 /*
22 Determine the widget set, honouring the compiler switch NO_GUI
23 and/or the compiler switch NO_GRAPHICS, which entails NO_GUI.
24 */
25 #if defined (NO_GRAPHICS) && ! defined (NO_GUI)
26 #define NO_GUI
27 #endif
28 #if defined (NO_GUI)
29 #define gtk 0
30 #define motif 0
31 #define cocoa 0
32 #elif defined (UNIX)
33 #define gtk 1
34 #define motif 0
35 #define cocoa 0
36 #elif defined (_WIN32)
37 #define gtk 0
38 #define motif 1
39 #define cocoa 0
40 #elif defined (macintosh)
41 #define gtk 0
42 #define motif 0
43 #define cocoa 1
44 #else
45 /*
46 Unknown platforms have no GUI.
47 */
48 #define gtk 0
49 #define motif 0
50 #define cocoa 0
51 #endif
52
53 constexpr bool theCommandKeyIsToTheLeftOfTheOptionKey =
54 #if defined (macintosh)
55 false;
56 #else
57 true;
58 #endif
59
60 #include "Collection.h"
61
62 #if defined (UNIX)
63 #if gtk
64 #include <gtk/gtk.h>
65 #include <gdk/gdk.h>
66 #endif
67 #if ! defined (NO_GRAPHICS)
68 #include <cairo/cairo.h>
69 #include <pango/pango.h>
70 #include <pango/pangocairo.h>
71 #endif
72 #elif defined (macintosh)
73 #include "macport_on.h"
74 #include <Cocoa/Cocoa.h>
75 #include "macport_off.h"
76 #elif defined (_WIN32)
77 #include "winport_on.h"
78 #include <windows.h>
79 #include <windowsx.h>
80 #include "winport_off.h"
81 #endif
82
83 #include "machine.h"
84
85 #define Gui_LEFT_DIALOG_SPACING 20
86 #define Gui_RIGHT_DIALOG_SPACING 20
87 #if defined (chrome)
88 #define Gui_TOP_DIALOG_SPACING 34
89 #else
90 #define Gui_TOP_DIALOG_SPACING 14
91 #endif
92 #define Gui_BOTTOM_DIALOG_SPACING 20
93 #define Gui_HORIZONTAL_DIALOG_SPACING 12
94 #define Gui_VERTICAL_DIALOG_SPACING_SAME 12
95 #define Gui_VERTICAL_DIALOG_SPACING_DIFFERENT 20
96 #define Gui_TEXTFIELD_HEIGHT Machine_getTextHeight ()
97 #define Gui_LABEL_HEIGHT 16
98 #define Gui_RADIOBUTTON_HEIGHT 18
99 #define Gui_RADIOBUTTON_SPACING 8
100 #define Gui_CHECKBUTTON_HEIGHT 20
101 #define Gui_LABEL_SPACING 8
102 #define Gui_OPTIONMENU_HEIGHT 20
103 #define Gui_PUSHBUTTON_HEIGHT Machine_getButtonHeight ()
104 #define Gui_OK_BUTTON_WIDTH 69
105 #define Gui_CANCEL_BUTTON_WIDTH 69
106 #define Gui_APPLY_BUTTON_WIDTH 69
107
108 #define Gui_HOMOGENEOUS 1
109
110 #if gtk
111 typedef void *GuiObject;
112 #elif cocoa
113 Thing_declare (GuiThing);
114 @protocol GuiCocoaAny
115 - (GuiThing) getUserData;
116 - (void) setUserData: (GuiThing) userData;
117 @end
118 typedef NSObject <GuiCocoaAny> *GuiObject;
119 @interface GuiCocoaApplication : NSApplication @end
120 @interface GuiCocoaButton : NSButton <GuiCocoaAny> @end
121 @interface GuiCocoaCheckButton : NSButton <GuiCocoaAny> @end
122 @interface GuiCocoaDrawingArea : NSView <GuiCocoaAny> @end
123 @interface GuiCocoaLabel : NSTextField <GuiCocoaAny> @end
124 @interface GuiCocoaList : NSView <GuiCocoaAny, NSTableViewDataSource, NSTableViewDelegate>
125 @property (nonatomic, retain) NSMutableArray *contents;
126 @property (nonatomic, retain) NSTableView *tableView;
127 @end
128 @interface GuiCocoaMenu : NSMenu <GuiCocoaAny> @end
129 @interface GuiCocoaMenuButton : NSPopUpButton <GuiCocoaAny> @end
130 @interface GuiCocoaMenuItem : NSMenuItem <GuiCocoaAny> @end
131 @interface GuiCocoaOptionMenu : NSPopUpButton <GuiCocoaAny> @end
132 @interface GuiCocoaProgressBar : NSProgressIndicator <GuiCocoaAny> @end
133 @interface GuiCocoaRadioButton : NSButton <GuiCocoaAny> @end
134 @interface GuiCocoaScale : NSProgressIndicator <GuiCocoaAny> @end
135 @interface GuiCocoaScrollBar : NSScroller <GuiCocoaAny>
136 - (void) scrollBy: (double) step;
137 - (void) magnifyBy: (double) step;
138 @end
139 @interface GuiCocoaScrolledWindow : NSScrollView <GuiCocoaAny> @end
140 @interface GuiCocoaShell : NSWindow <GuiCocoaAny> @end
141 @interface GuiCocoaTextField : NSTextField <GuiCocoaAny> @end
142 @interface GuiCocoaTextView : NSTextView <GuiCocoaAny, NSTextViewDelegate> @end
143 #elif motif
144 typedef class structGuiObject *GuiObject; // opaque
145
146 /*
147 * Definitions of X11 types.
148 */
149 typedef MSG XEvent;
150 typedef unsigned char Boolean;
151 typedef integer Cardinal;
152 typedef unsigned int Dimension;
153 typedef int Position;
154 typedef void *Window;
155 typedef char *String;
156 typedef struct Display Display;
157 /*typedef integer Time;*/
158 typedef integer Atom;
159 typedef struct { int /* elsewhere: char* */ name; integer value; } Arg, *ArgList;
160
161 /*
162 * Declarations of X11 functions.
163 */
164 void XMapRaised (int displayDummy, Window window);
165 #define DefaultScreenOfDisplay(d) 0
166 int WidthOfScreen (int screen);
167 int HeightOfScreen (int screen);
168
169 /*
170 * Definitions of Xt types.
171 */
172 typedef void *XtPointer;
173 typedef GuiObject *GuiObjectList;
174 typedef integer XtWorkProcId, XtIntervalId;
175 typedef void (*XtCallbackProc) (GuiObject w, XtPointer client_data, XtPointer call_data);
176 typedef bool (*XtWorkProc) (void *client_data);
177 typedef void (*XtTimerCallbackProc) (XtPointer, XtIntervalId *);
178 typedef uinteger WidgetClass;
179 #define False 0
180 #define True 1
181
182 /*
183 * Declarations of Xt functions.
184 */
185 void XtAddCallback (GuiObject w, int kind, XtCallbackProc proc, XtPointer closure);
186 XtIntervalId GuiAddTimeOut (uinteger interval,
187 XtTimerCallbackProc timerProc, XtPointer closure);
188 XtWorkProcId GuiAddWorkProc (XtWorkProc workProc, XtPointer closure);
189 void GuiMainLoop ();
190 void GuiNextEvent (XEvent *event);
191 #define XtCalloc Melder_calloc
192 #define XtClass(w) (w) -> widgetClass
193 void XtDestroyWidget (GuiObject w);
194 void XtDispatchEvent (XEvent *event);
195 #define XtDisplay(w) 0
196 Boolean XtIsManaged (GuiObject w);
197 Boolean XtIsShell (GuiObject w);
198 void XtManageChild (GuiObject w);
199 void XtManageChildren (GuiObjectList children, Cardinal num_children);
200 void XtMapWidget (GuiObject w);
201 void XtNextEvent (XEvent *event);
202 void XtRemoveTimeOut (XtIntervalId id);
203 void XtRemoveWorkProc (XtWorkProcId id);
204 void XtSetKeyboardFocus (GuiObject tree, GuiObject descendant);
205 void XtSetSensitive (GuiObject w, Boolean value);
206 void XtUnmanageChild (GuiObject self);
207 void XtUnmanageChildren (GuiObjectList children, Cardinal num_children);
208 void GuiAppInitialize (const char *name, unsigned int argc, char **argv);
209 void GuiApp_setApplicationShell (GuiObject shell);
210 GuiObject XtVaCreateWidget (const char *name, int widgetClass, GuiObject parent, ...);
211 GuiObject XtVaCreateManagedWidget (const char *name, int widgetClass, GuiObject parent, ...);
212 void XtVaGetValues (GuiObject w, ...);
213 void XtVaSetValues (GuiObject w, ...);
214 Window XtWindow (GuiObject w);
215 integer Gui_getNumberOfMotifWidgets ();
216
217 /*
218 * Xm widget classes.
219 */
220 #define xmBulletinBoardWidgetClass 0x0000'0001
221 #define xmDrawingAreaWidgetClass 0x0000'0002
222 #define xmFormWidgetClass 0x0000'0004
223 #define xmFrameWidgetClass 0x0000'0008
224 #define xmLabelWidgetClass 0x0000'0010
225 #define xmListWidgetClass 0x0000'0020
226 #define xmMenuBarWidgetClass 0x0000'0040
227 #define xmPulldownMenuWidgetClass 0x0000'0100
228 #define xmPushButtonWidgetClass 0x0000'0200
229 #define xmRowColumnWidgetClass 0x0000'0400
230 #define xmScaleWidgetClass 0x0000'0800
231 #define xmScrollBarWidgetClass 0x0000'1000
232 #define xmScrolledWindowWidgetClass 0x0000'2000
233 #define xmSeparatorWidgetClass 0x0000'4000
234 #define xmShellWidgetClass 0x0000'8000
235 #define xmTextWidgetClass 0x0001'0000
236 #define xmToggleButtonWidgetClass 0x0002'0000
237 #define xmCascadeButtonWidgetClass 0x0004'0000
238 #define xmPushButtonGadgetClass xmPushButtonWidgetClass
239 #define xmCascadeButtonGadgetClass xmCascadeButtonWidgetClass
240 #define xmSeparatorGadgetClass xmSeparatorWidgetClass
241 #define xmToggleButtonGadgetClass xmToggleButtonWidgetClass
242
243 /*
244 * Xm resource names.
245 */
246 enum {
247 XmNnull,
248 #define motif_RESOURCE(xxx) xxx,
249 #include "motifEmulator_resources.h"
250 #undef motif_RESOURCE
251 XmNend
252 };
253
254 /*
255 * Xm enumerated types.
256 * All start at 1, because we have to reserve zero for the dynamic default value.
257 * This is important for the resources set during creation.
258 */
259 enum /* dialog styles */ { XmDIALOG_MODELESS = 1, XmDIALOG_FULL_APPLICATION_MODAL };
260 enum /* orientation */ { XmVERTICAL = 1, XmHORIZONTAL };
261 enum /* attachment */ { XmATTACH_NONE = 1, XmATTACH_FORM, XmATTACH_POSITION };
262 enum /* rowColumn types */ { XmWORK_AREA = 1, XmMENU_BAR };
263 enum /* delete responses */ { XmDESTROY = 1, XmUNMAP, XmDO_NOTHING };
264 enum /* indicator types */ { XmONE_OF_MANY = 1, XmN_OF_MANY };
265
266 /*
267 * Declarations of Xm functions.
268 */
269 void XmAddWMProtocolCallback (GuiObject shell, Atom protocol, XtCallbackProc callback, char *closure);
270 GuiObject XmCreateBulletinBoard (GuiObject, const char *, ArgList, int);
271 GuiObject XmCreateBulletinBoardDialog (GuiObject, const char *, ArgList, int);
272 GuiObject XmCreateCascadeButton (GuiObject, const char *, ArgList, int);
273 GuiObject XmCreateCascadeButtonGadget (GuiObject, const char *, ArgList, int);
274 GuiObject XmCreateDialogShell (GuiObject, const char *, ArgList, int);
275 GuiObject XmCreateForm (GuiObject, const char *, ArgList, int);
276 GuiObject XmCreateFormDialog (GuiObject, const char *, ArgList, int);
277 GuiObject XmCreateMenuBar (GuiObject, const char *, ArgList, int);
278 GuiObject XmCreatePulldownMenu (GuiObject, const char *, ArgList, int);
279 GuiObject XmCreateRadioBox (GuiObject, const char *, ArgList, int);
280 GuiObject XmCreateRowColumn (GuiObject, const char *, ArgList, int);
281 GuiObject XmCreateScale (GuiObject, const char *, ArgList, int);
282 GuiObject XmCreateScrolledWindow (GuiObject, const char *, ArgList, int);
283 GuiObject XmCreateScrollBar (GuiObject, const char *, ArgList, int);
284 GuiObject XmCreateSeparator (GuiObject, const char *, ArgList, int);
285 GuiObject XmCreateSeparatorGadget (GuiObject, const char *, ArgList, int);
286 GuiObject XmCreateShell (GuiObject, const char *, ArgList, int);
287 GuiObject XmCreateToggleButton (GuiObject, const char *, ArgList, int);
288 GuiObject XmCreateToggleButtonGadget (GuiObject, const char *, ArgList, int);
289 void XmScaleGetValue (GuiObject widget, int *value_return);
290 void XmScaleSetValue (GuiObject widget, int value);
291 void XmScrollBarGetValues (GuiObject me, int *value, int *sliderSize, int *increment, int *pageIncrement);
292 void XmScrollBarSetValues (GuiObject me, int value, int sliderSize, int increment, int pageIncrement, Boolean notify);
293 Boolean XmToggleButtonGadgetGetState (GuiObject widget);
294 #define XmToggleButtonGetState XmToggleButtonGadgetGetState
295 void XmToggleButtonGadgetSetState (GuiObject widget, Boolean value, Boolean notify);
296 #define XmToggleButtonSetState XmToggleButtonGadgetSetState
297
298 void motif_win_setUserMessageCallback (int (*userMessageCallback) (void));
299 #else
300 typedef void *GuiObject;
301 #endif
302
303 int Gui_getResolution (GuiObject widget);
304 void Gui_getWindowPositioningBounds (double *x, double *y, double *width, double *height);
305
306 Thing_declare (GuiDrawingArea);
307 Thing_declare (GuiForm);
308 Thing_declare (GuiMenu);
309 Thing_declare (GuiScrolledWindow);
310 Thing_declare (GuiShell);
311 Thing_declare (GuiWindow);
312
Thing_define(GuiThing,Thing)313 Thing_define (GuiThing, Thing) {
314 GuiShell d_shell;
315 GuiThing d_parent;
316 GuiObject d_widget;
317
318 void v_destroy () noexcept
319 override;
320
321 virtual void v_show ();
322 virtual void v_hide ();
323 virtual void v_setSensitive (bool sensitive);
324 };
325
326 void GuiThing_show (GuiThing me);
327 void GuiThing_hide (GuiThing me);
328 void GuiThing_setSensitive (GuiThing me, bool sensitive);
329
Thing_define(GuiControl,GuiThing)330 Thing_define (GuiControl, GuiThing) {
331 int d_left, d_right, d_top, d_bottom;
332 bool d_blockValueChangedCallbacks;
333
334 virtual void v_positionInForm (GuiObject widget, int left, int right, int top, int bottom, GuiForm parent);
335 virtual void v_positionInScrolledWindow (GuiObject widget, int width, int height, GuiScrolledWindow parent);
336 };
337
338 int GuiControl_getX (GuiControl me);
339 int GuiControl_getY (GuiControl me);
340 int GuiControl_getWidth (GuiControl me);
341 int GuiControl_getHeight (GuiControl me);
342 void GuiControl_move (GuiControl me, int x, int y);
343 void GuiControl_setSize (GuiControl me, int width, int height);
344
Thing_define(GuiForm,GuiControl)345 Thing_define (GuiForm, GuiControl) {
346 };
347
348 using GuiShell_GoAwayCallback = MelderCallback <void, structThing /* boss */>;
349
Thing_define(GuiShell,GuiForm)350 Thing_define (GuiShell, GuiForm) {
351 int d_width, d_height;
352 #if gtk
353 GtkWindow *d_gtkWindow;
354 #if defined (chrome)
355 GtkWidget *chrome_surrogateShellTitleLabelWidget;
356 #endif
357 #elif cocoa
358 GuiCocoaShell *d_cocoaShell;
359 #elif motif
360 GuiObject d_xmShell;
361 #endif
362 GuiShell_GoAwayCallback d_goAwayCallback;
363 Thing d_goAwayBoss;
364 GuiDrawingArea drawingArea;
365
366 void v_destroy () noexcept
367 override;
368 };
369
370 int GuiShell_getShellWidth (GuiShell me); // needed because GuiControl_getWidth yields the width of the inner form
371 int GuiShell_getShellHeight (GuiShell me);
372 void GuiShell_setTitle (GuiShell me, conststring32 title /* cattable */);
373 void GuiShell_drain (GuiShell me); // force display of update regions (forces the handling of an expose event)
374
375 /********** GuiButton **********/
376
377 Thing_declare (GuiButton);
378
379 typedef struct structGuiButtonEvent {
380 GuiButton button;
381 bool shiftKeyPressed, commandKeyPressed, optionKeyPressed;
382 } *GuiButtonEvent;
383
384 using GuiButton_ActivateCallback = MelderCallback <void, structThing /* boss */, GuiButtonEvent>;
385
Thing_define(GuiButton,GuiControl)386 Thing_define (GuiButton, GuiControl) {
387 GuiButton_ActivateCallback d_activateCallback;
388 Thing d_activateBoss;
389 GuiMenu d_menu; // for cascade buttons
390 };
391
392 /* GuiButton creation flags: */
393 #define GuiButton_DEFAULT 1
394 #define GuiButton_CANCEL 2
395 #define GuiButton_INSENSITIVE 4
396 #define GuiButton_ATTRACTIVE 8
397 GuiButton GuiButton_create (GuiForm parent,
398 int left, int right, int top, int bottom,
399 conststring32 text,
400 GuiButton_ActivateCallback activateCallback, Thing boss,
401 uint32 flags
402 );
403 GuiButton GuiButton_createShown (GuiForm parent,
404 int left, int right, int top, int bottom,
405 conststring32 text,
406 GuiButton_ActivateCallback activateCallback, Thing boss,
407 uint32 flags
408 );
409
410 void GuiButton_setText (GuiButton me, conststring32 text /* cattable */);
411
412 /********** GuiCheckButton **********/
413
414 Thing_declare (GuiCheckButton);
415
416 typedef struct structGuiCheckButtonEvent {
417 GuiCheckButton toggle;
418 } *GuiCheckButtonEvent;
419
420 using GuiCheckButton_ValueChangedCallback = MelderCallback <void, structThing /* boss */, GuiCheckButtonEvent>;
421
Thing_define(GuiCheckButton,GuiControl)422 Thing_define (GuiCheckButton, GuiControl) {
423 GuiCheckButton_ValueChangedCallback d_valueChangedCallback;
424 Thing d_valueChangedBoss;
425 };
426
427 /* GuiCheckButton creation flags: */
428 #define GuiCheckButton_SET 1
429 #define GuiCheckButton_INSENSITIVE 2
430 GuiCheckButton GuiCheckButton_create (GuiForm parent,
431 int left, int right, int top, int bottom,
432 conststring32 text,
433 GuiCheckButton_ValueChangedCallback valueChangedCallback, Thing boss,
434 uint32 flags
435 );
436 GuiCheckButton GuiCheckButton_createShown (GuiForm parent,
437 int left, int right, int top, int bottom,
438 conststring32 text,
439 GuiCheckButton_ValueChangedCallback valueChangedCallback, Thing boss,
440 uint32 flags
441 );
442
443 bool GuiCheckButton_getValue (GuiCheckButton me);
444 void GuiCheckButton_setValue (GuiCheckButton me, bool value);
445
446 /********** GuiDialog **********/
447
448 using GuiDialog_DefaultCallback = MelderCallback <void, structThing /* boss */>;
449
Thing_define(GuiDialog,GuiShell)450 Thing_define (GuiDialog, GuiShell) {
451 GuiDialog_DefaultCallback d_defaultCallback;
452 Thing d_defaultBoss;
453 };
454
455 /* GuiDialog creation flags: */
456 #define GuiDialog_MODAL 1
457 GuiDialog GuiDialog_create (GuiWindow parent,
458 int x, int y, int width, int height,
459 conststring32 title,
460 GuiShell_GoAwayCallback goAwayCallback, Thing goAwayBoss,
461 uint32 flags
462 );
463
464 void GuiDialog_setDefaultCallback (GuiDialog me, GuiDialog_DefaultCallback callback, Thing boss);
465
466 /********** GuiDrawingArea **********/
467
468 Thing_declare (GuiDrawingArea);
469 Thing_declare (GuiScrollBar);
470
471 typedef struct structGuiDrawingArea_ExposeEvent {
472 GuiDrawingArea widget;
473 int x, y, width, height;
474 } *GuiDrawingArea_ExposeEvent;
475
476 typedef struct structGuiDrawingArea_MouseEvent {
477 GuiDrawingArea widget;
478 int x, y;
479 enum class Phase { CLICK, DRAG, DROP } phase;
isClickstructGuiDrawingArea_MouseEvent480 bool isClick() const { return our phase == Phase::CLICK; }
isDragstructGuiDrawingArea_MouseEvent481 bool isDrag() const { return our phase == Phase::DRAG; }
isDropstructGuiDrawingArea_MouseEvent482 bool isDrop() const { return our phase == Phase::DROP; }
483 bool shiftKeyPressed, commandKeyPressed, optionKeyPressed;
isLeftBottomFunctionKeyPressedstructGuiDrawingArea_MouseEvent484 bool isLeftBottomFunctionKeyPressed () const {
485 return theCommandKeyIsToTheLeftOfTheOptionKey ? our commandKeyPressed : our optionKeyPressed;
486 }
isRightBottomFunctionKeyPressedstructGuiDrawingArea_MouseEvent487 bool isRightBottomFunctionKeyPressed () const {
488 return theCommandKeyIsToTheLeftOfTheOptionKey ? our optionKeyPressed : our commandKeyPressed;
489 }
490 } *GuiDrawingArea_MouseEvent;
491
492 typedef struct structGuiDrawingArea_KeyEvent {
493 GuiDrawingArea widget;
494 char32 key;
495 bool shiftKeyPressed, commandKeyPressed, optionKeyPressed;
496 } *GuiDrawingArea_KeyEvent;
497
498 typedef struct structGuiDrawingArea_ResizeEvent {
499 GuiDrawingArea widget;
500 int width, height;
501 } *GuiDrawingArea_ResizeEvent;
502
503 using GuiDrawingArea_ExposeCallback = MelderCallback <void, structThing /* boss */, GuiDrawingArea_ExposeEvent>;
504 using GuiDrawingArea_MouseCallback = MelderCallback <void, structThing /* boss */, GuiDrawingArea_MouseEvent >;
505 using GuiDrawingArea_KeyCallback = MelderCallback <void, structThing /* boss */, GuiDrawingArea_KeyEvent >;
506 using GuiDrawingArea_ResizeCallback = MelderCallback <void, structThing /* boss */, GuiDrawingArea_ResizeEvent>;
507
Thing_define(GuiDrawingArea,GuiControl)508 Thing_define (GuiDrawingArea, GuiControl) {
509 GuiScrollBar d_horizontalScrollBar, d_verticalScrollBar; // for swiping
510 GuiDrawingArea_ExposeCallback d_exposeCallback;
511 Thing d_exposeBoss;
512 GuiDrawingArea_MouseCallback mouseCallback;
513 Thing mouseBoss;
514 GuiDrawingArea_KeyCallback d_keyCallback;
515 Thing d_keyBoss;
516 GuiDrawingArea_ResizeCallback d_resizeCallback;
517 Thing d_resizeBoss;
518 integer numberOfGraphicses;
519 constexpr static integer MAXIMUM_NUMBER_OF_GRAPHICSES = 10;
520 Graphics graphicses [1+MAXIMUM_NUMBER_OF_GRAPHICSES];
521
522 void v_destroy () noexcept
523 override;
524 };
525
526 /* GuiDrawingArea creation flags: */
527 #define GuiDrawingArea_BORDER 1
528 GuiDrawingArea GuiDrawingArea_create (GuiForm parent, int left, int right, int top, int bottom,
529 GuiDrawingArea_ExposeCallback exposeCallback,
530 GuiDrawingArea_MouseCallback mouseCallback,
531 GuiDrawingArea_KeyCallback keyCallback,
532 GuiDrawingArea_ResizeCallback resizeCallback, Thing boss,
533 uint32 flags);
534 GuiDrawingArea GuiDrawingArea_createShown (GuiForm parent, int left, int right, int top, int bottom,
535 GuiDrawingArea_ExposeCallback exposeCallback,
536 GuiDrawingArea_MouseCallback mouseCallback,
537 GuiDrawingArea_KeyCallback keyCallback,
538 GuiDrawingArea_ResizeCallback resizeCallback, Thing boss,
539 uint32 flags);
540 GuiDrawingArea GuiDrawingArea_create (GuiScrolledWindow parent, int width, int height,
541 GuiDrawingArea_ExposeCallback exposeCallback,
542 GuiDrawingArea_MouseCallback mouseCallback,
543 GuiDrawingArea_KeyCallback keyCallback,
544 GuiDrawingArea_ResizeCallback resizeCallback, Thing boss,
545 uint32 flags);
546 GuiDrawingArea GuiDrawingArea_createShown (GuiScrolledWindow parent, int width, int height,
547 GuiDrawingArea_ExposeCallback exposeCallback,
548 GuiDrawingArea_MouseCallback mouseCallback,
549 GuiDrawingArea_KeyCallback keyCallback,
550 GuiDrawingArea_ResizeCallback resizeCallback, Thing boss,
551 uint32 flags);
552
553 void GuiDrawingArea_setSwipable (GuiDrawingArea me, GuiScrollBar horizontalScrollBar, GuiScrollBar verticalScrollBar);
554 void GuiDrawingArea_setExposeCallback (GuiDrawingArea me, GuiDrawingArea_ExposeCallback callback, Thing boss);
555 void GuiDrawingArea_setMouseCallback (GuiDrawingArea me, GuiDrawingArea_MouseCallback callback, Thing boss);
556 void GuiDrawingArea_setResizeCallback (GuiDrawingArea me, GuiDrawingArea_ResizeCallback callback, Thing boss);
557
558 /********** GuiFileSelect **********/
559
560 autoStringSet GuiFileSelect_getInfileNames (GuiWindow parent, conststring32 title, bool allowMultipleFiles);
561 autostring32 GuiFileSelect_getOutfileName (GuiWindow parent, conststring32 title, conststring32 defaultName);
562 autostring32 GuiFileSelect_getFolderName (GuiWindow parent, conststring32 title);
563
564 /********** GuiForm **********/
565
566 GuiForm GuiForm_createInScrolledWindow (GuiScrolledWindow parent);
567
568 /********** GuiLabel **********/
569
570 //Thing_declare (GuiLabel);
571
Thing_define(GuiLabel,GuiControl)572 Thing_define (GuiLabel, GuiControl) {
573 };
574
575 /* GuiLabel creation flags: */
576 #define GuiLabel_CENTRE 1
577 #define GuiLabel_RIGHT 2
578 GuiLabel GuiLabel_create (GuiForm parent, int left, int right, int top, int bottom,
579 conststring32 text, uint32 flags);
580 GuiLabel GuiLabel_createShown (GuiForm parent, int left, int right, int top, int bottom,
581 conststring32 text, uint32 flags);
582
583 void GuiLabel_setText (GuiLabel me, conststring32 text /* cattable */);
584
585 /********** GuiList **********/
586
587 Thing_declare (GuiList);
588 Thing_declare (GuiScrolledWindow);
589
590 typedef struct structGuiList_SelectionChangedEvent {
591 GuiList list;
592 } *GuiList_SelectionChangedEvent;
593 using GuiList_SelectionChangedCallback = MelderCallback <void, structThing /* boss */, GuiList_SelectionChangedEvent>;
594
595 typedef struct structGuiList_DoubleClickEvent {
596 GuiList list;
597 } *GuiList_DoubleClickEvent;
598 using GuiList_DoubleClickCallback = MelderCallback <void, structThing /* boss */, GuiList_DoubleClickEvent>;
599
600 typedef struct structGuiList_ScrollEvent {
601 GuiList list;
602 } *GuiList_ScrollEvent;
603 using GuiList_ScrollCallback = MelderCallback <void, structThing /* boss */, GuiList_ScrollEvent>;
604
Thing_define(GuiList,GuiControl)605 Thing_define (GuiList, GuiControl) {
606 bool d_allowMultipleSelection;
607 GuiList_SelectionChangedCallback d_selectionChangedCallback;
608 Thing d_selectionChangedBoss;
609 GuiList_DoubleClickCallback d_doubleClickCallback;
610 Thing d_doubleClickBoss;
611 GuiList_ScrollCallback d_scrollCallback;
612 Thing d_scrollBoss;
613 #if gtk
614 GtkListStore *d_liststore;
615 #endif
616 };
617
618 GuiList GuiList_create (GuiForm parent, int left, int right, int top, int bottom, bool allowMultipleSelection, conststring32 header);
619 GuiList GuiList_createShown (GuiForm parent, int left, int right, int top, int bottom, bool allowMultipleSelection, conststring32 header);
620
621 void GuiList_deleteAllItems (GuiList me);
622 void GuiList_deleteItem (GuiList me, integer position);
623 void GuiList_deselectAllItems (GuiList me);
624 void GuiList_deselectItem (GuiList me, integer position);
625 integer GuiList_getBottomPosition (GuiList me);
626 integer GuiList_getNumberOfItems (GuiList me);
627 autoINTVEC GuiList_getSelectedPositions (GuiList me);
628 integer GuiList_getTopPosition (GuiList me);
629
630 /**
631 Inserts a new item into a GuiList at a given position.
632 @param me
633 The GuiList into which the new item is inserted.
634 @param itemText
635 The text of the new item. Cattable.
636 @param position
637 The position of the new item in the list after insertion.
638 A value of 1 therefore puts the new item at the top of the list.
639 A value of 0 is special: the item is put at the bottom of the list.
640 */
641 void GuiList_insertItem (GuiList me, conststring32 itemText /* cattable */, integer position);
642
643 void GuiList_replaceItem (GuiList me, conststring32 itemText /* cattable */, integer position);
644 void GuiList_setTopPosition (GuiList me, integer topPosition);
645 void GuiList_selectItem (GuiList me, integer position);
646 void GuiList_setSelectionChangedCallback (GuiList me, GuiList_SelectionChangedCallback callback, Thing boss);
647 void GuiList_setDoubleClickCallback (GuiList me, GuiList_DoubleClickCallback callback, Thing boss);
648 void GuiList_setScrollCallback (GuiList me, GuiList_ScrollCallback callback, Thing boss);
649
650 /********** GuiMenu **********/
651
652 Thing_declare (GuiMenuItem);
653
Thing_define(GuiMenu,GuiThing)654 Thing_define (GuiMenu, GuiThing) {
655 autoGuiMenuItem d_menuItem;
656 autoGuiButton d_cascadeButton;
657 #if gtk
658 GtkMenuItem *d_gtkMenuTitle;
659 #elif cocoa
660 GuiCocoaMenu *d_cocoaMenu;
661 GuiCocoaMenuItem *d_cocoaMenuItem;
662 GuiCocoaMenuButton *d_cocoaMenuButton;
663 #elif motif
664 GuiObject d_xmMenuTitle; // in case the menu is in a menu bar
665 GuiObject d_xmMenuBar; // in case the menu is in a form
666 #endif
667
668 void v_destroy () noexcept
669 override;
670 void v_show ()
671 override;
672 void v_hide ()
673 override;
674 void v_setSensitive (bool sensitive)
675 override;
676 };
677
678 GuiMenu GuiMenu_createInWindow (GuiWindow window, conststring32 title, uint32 flags);
679 GuiMenu GuiMenu_createInMenu (GuiMenu supermenu, conststring32 title, uint32 flags);
680 GuiMenu GuiMenu_createInForm (GuiForm form, int left, int right, int top, int bottom, conststring32 title, uint32 flags);
681
682 void GuiMenu_empty (GuiMenu me);
683
684 /********** GuiMenuItem **********/
685
686 Thing_declare (GuiMenuItem);
687
688 typedef struct structGuiMenuItemEvent {
689 GuiMenuItem menuItem;
690 bool shiftKeyPressed, commandKeyPressed, optionKeyPressed;
691 } *GuiMenuItemEvent;
692
693 using GuiMenuItemCallback = MelderCallback <void, structThing /* boss */, GuiMenuItemEvent>;
694
695 #if cocoa
696 extern GuiMenuItemCallback theGuiEscapeMenuItemCallback;
697 extern Thing theGuiEscapeMenuItemBoss;
698 #endif
699
Thing_define(GuiMenuItem,GuiThing)700 Thing_define (GuiMenuItem, GuiThing) {
701 GuiMenu d_menu;
702 GuiMenuItemCallback d_callback;
703 Thing d_boss;
704 #if gtk
705 bool d_callbackBlocked;
706 #endif
707 };
708
709 /* Button layout and state: */
710 #define GuiMenu_INSENSITIVE (1 << 8)
711 #define GuiMenu_CHECKBUTTON (1 << 9)
712 #define GuiMenu_TOGGLE_ON (1 << 10)
713 #define GuiMenu_ATTRACTIVE (1 << 11)
714 #define GuiMenu_RADIO_FIRST (1 << 12)
715 #define GuiMenu_RADIO_NEXT (1 << 13)
716 #define GuiMenu_BUTTON_STATE_MASK (GuiMenu_INSENSITIVE|GuiMenu_CHECKBUTTON|GuiMenu_TOGGLE_ON|GuiMenu_ATTRACTIVE|GuiMenu_RADIO_FIRST|GuiMenu_RADIO_NEXT)
717
718 /* Accelerators: */
719 #define GuiMenu_OPTION (1 << 24)
720 #define GuiMenu_SHIFT (1 << 25)
721 #define GuiMenu_COMMAND (1 << 26)
722 #define GuiMenu_LEFT_ARROW 1
723 #define GuiMenu_RIGHT_ARROW 2
724 #define GuiMenu_UP_ARROW 3
725 #define GuiMenu_DOWN_ARROW 4
726 #define GuiMenu_PAUSE 5
727 #define GuiMenu_DELETE 6
728 #define GuiMenu_INSERT 7
729 #define GuiMenu_BACKSPACE 8
730 #define GuiMenu_TAB 9
731 #define GuiMenu_LINEFEED 10
732 #define GuiMenu_HOME 11
733 #define GuiMenu_END 12
734 #define GuiMenu_ENTER 13
735 #define GuiMenu_PAGE_UP 14
736 #define GuiMenu_PAGE_DOWN 15
737 #define GuiMenu_ESCAPE 16
738 #define GuiMenu_F1 17
739 #define GuiMenu_F2 18
740 #define GuiMenu_F3 19
741 #define GuiMenu_F4 20
742 #define GuiMenu_F5 21
743 #define GuiMenu_F6 22
744 #define GuiMenu_F7 23
745 #define GuiMenu_F8 24
746 #define GuiMenu_F9 25
747 #define GuiMenu_F10 26
748 #define GuiMenu_F11 27
749 #define GuiMenu_F12 28
750 // or any ASCII character (preferably a letter or digit) between 32 and 126
751
752 GuiMenuItem GuiMenu_addItem (GuiMenu menu, conststring32 title, uint32 flags,
753 GuiMenuItemCallback callback, Thing boss);
754 /* Flags is a combination of the above defines (both layout and accelerators). */
755 GuiMenuItem GuiMenu_addSeparator (GuiMenu menu);
756
757 void GuiMenuItem_check (GuiMenuItem me, bool check);
758
759 /********** GuiOptionMenu **********/
760
Thing_define(GuiOptionMenu,GuiControl)761 Thing_define (GuiOptionMenu, GuiControl) {
762 int d_value;
763 OrderedOf<structGuiMenuItem> d_options;
764 #if gtk
765 //GtkComboBox *d_gtkCascadeButton;
766 #elif cocoa
767 #elif motif
768 GuiObject d_xmMenuBar, d_xmCascadeButton;
769 #endif
770
771 void v_show ()
772 override;
773 };
774
775 void GuiOptionMenu_init (GuiOptionMenu me, GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
776 GuiOptionMenu GuiOptionMenu_create (GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
777 GuiOptionMenu GuiOptionMenu_createShown (GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
778
779 void GuiOptionMenu_addOption (GuiOptionMenu me, conststring32 text);
780 int GuiOptionMenu_getValue (GuiOptionMenu me);
781 void GuiOptionMenu_setValue (GuiOptionMenu me, int value);
782
783 /********** GuiProgressBar **********/
784
785 Thing_declare (GuiProgressBar);
786
Thing_define(GuiProgressBar,GuiControl)787 Thing_define (GuiProgressBar, GuiControl) {
788 #if cocoa
789 GuiCocoaProgressBar *d_cocoaProgressBar;
790 #endif
791 };
792
793 GuiProgressBar GuiProgressBar_create (GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
794 GuiProgressBar GuiProgressBar_createShown (GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
795
796 void GuiProgressBar_setValue (GuiProgressBar me, double value); // between 0.0 and 1.0
797
798 /********** GuiRadioButton **********/
799
800 Thing_declare (GuiRadioButton);
801
802 typedef struct structGuiRadioButtonEvent {
803 GuiRadioButton toggle;
804 int position;
805 } *GuiRadioButtonEvent;
806
807 using GuiRadioButtonCallback = MelderCallback <void, structThing /* boss */, GuiRadioButtonEvent>;
808
Thing_define(GuiRadioButton,GuiControl)809 Thing_define (GuiRadioButton, GuiControl) {
810 GuiRadioButton d_previous, d_next; // there's a linked list of grouped radio buttons
811 GuiRadioButtonCallback d_valueChangedCallback;
812 Thing d_valueChangedBoss;
813 #if cocoa
814 GuiCocoaRadioButton *d_cocoaRadioButton;
815 #endif
816 };
817
818 /* GuiRadioButton creation flags: */
819 #define GuiRadioButton_SET 1
820 #define GuiRadioButton_INSENSITIVE 2
821 GuiRadioButton GuiRadioButton_create (GuiForm parent, int left, int right, int top, int bottom,
822 conststring32 buttonText, GuiRadioButtonCallback valueChangedCallback, Thing valueChangedBoss, uint32 flags);
823 GuiRadioButton GuiRadioButton_createShown (GuiForm parent, int left, int right, int top, int bottom,
824 conststring32 buttonText, GuiRadioButtonCallback valueChangedCallback, Thing valueChangedBoss, uint32 flags);
825
826 void GuiRadioGroup_begin ();
827 void GuiRadioGroup_end ();
828
829 bool GuiRadioButton_getValue (GuiRadioButton me);
830 void GuiRadioButton_set (GuiRadioButton me);
831
832 /********** GuiScale **********/
833
834 Thing_declare (GuiScale);
835
Thing_define(GuiScale,GuiControl)836 Thing_define (GuiScale, GuiControl) { public:
837 #if cocoa
838 GuiCocoaScale *d_cocoaScale;
839 #endif
840 };
841
842 GuiScale GuiScale_create (GuiForm parent, int left, int right, int top, int bottom,
843 int minimum, int maximum, int value, uint32 flags);
844 GuiScale GuiScale_createShown (GuiForm parent, int left, int right, int top, int bottom,
845 int minimum, int maximum, int value, uint32 flags);
846
847 int GuiScale_getValue (GuiScale me);
848 void GuiScale_setValue (GuiScale me, int value);
849
850 /********** GuiScrollBar **********/
851
852 Thing_declare (GuiScrollBar);
853
854 typedef struct structGuiScrollBarEvent {
855 GuiScrollBar scrollBar;
856 } *GuiScrollBarEvent;
857
858 using GuiScrollBarCallback = MelderCallback <void, structThing /* boss */, GuiScrollBarEvent>;
859
Thing_define(GuiScrollBar,GuiControl)860 Thing_define (GuiScrollBar, GuiControl) {
861 GuiScrollBarCallback d_valueChangedCallback;
862 Thing d_valueChangedBoss;
863 };
864
865 /* GuiScrollBar creation flags: */
866 #define GuiScrollBar_HORIZONTAL 1
867 GuiScrollBar GuiScrollBar_create (GuiForm parent, int left, int right, int top, int bottom,
868 double minimum, double maximum, double value, double sliderSize, double increment, double pageIncrement,
869 GuiScrollBarCallback valueChangedCallback, Thing valueChangedBoss, uint32 flags);
870 GuiScrollBar GuiScrollBar_createShown (GuiForm parent, int left, int right, int top, int bottom,
871 double minimum, double maximum, double value, double sliderSize, double increment, double pageIncrement,
872 GuiScrollBarCallback valueChangedCallback, Thing valueChangedBoss, uint32 flags);
873
874 double GuiScrollBar_getValue (GuiScrollBar me);
875 double GuiScrollBar_getSliderSize (GuiScrollBar me);
876 void GuiScrollBar_set (GuiScrollBar me, double minimum, double maximum, double value,
877 double sliderSize, double increment, double pageIncrement);
878
879 /********** GuiScrolledWindow **********/
880
881 Thing_declare (GuiScrolledWindow);
882
Thing_define(GuiScrolledWindow,GuiControl)883 Thing_define (GuiScrolledWindow, GuiControl) { public:
884 };
885
886 GuiScrolledWindow GuiScrolledWindow_create (GuiForm parent, int left, int right, int top, int bottom,
887 int horizontalScrollbarPersistence, int verticalScrollbarPersistence, uint32 flags);
888 GuiScrolledWindow GuiScrolledWindow_createShown (GuiForm parent, int left, int right, int top, int bottom,
889 int horizontalScrollbarPersistence, int verticalScrollbarPersistence, uint32 flags);
890
891 /********** GuiText **********/
892
893 Thing_declare (GuiText);
894
895 typedef struct structGuiTextEvent {
896 GuiText text;
897 } *GuiTextEvent;
898
899 using GuiText_ChangedCallback = MelderCallback <void, structThing /* boss */, GuiTextEvent>;
900
901 #if gtk
902 typedef gchar * history_data;
903 #else
904 typedef char * history_data;
905 #endif
906
907 typedef struct _history_entry_s history_entry;
908 struct _history_entry_s {
909 history_entry *prev, *next;
910 integer first, last;
911 history_data text;
912 bool type_del : 1;
913 };
914
Thing_define(GuiText,GuiControl)915 Thing_define (GuiText, GuiControl) {
916 GuiText_ChangedCallback d_changedCallback;
917 Thing d_changedBoss;
918 #if cocoa
919 GuiCocoaScrolledWindow *d_cocoaScrollView;
920 GuiCocoaTextView *d_cocoaTextView;
921 double d_macFontSize;
922 #elif defined (macintosh)
923 TXNObject d_macMlteObject;
924 TXNFrameID d_macMlteFrameId;
925 #else
926 history_entry *d_prev, *d_next;
927 GuiMenuItem d_undo_item, d_redo_item;
928 bool d_history_change : 1;
929 #endif
930 #if motif
931 bool d_editable;
932 #endif
933 };
934
935 /* GuiText creation flags: */
936 #define GuiText_SCROLLED 1
937 #define GuiText_CHARWRAP 2
938 #define GuiText_INKWRAP 4
939 #define GuiText_ANYWRAP (GuiText_CHARWRAP | GuiText_INKWRAP)
940 #define GuiText_NONEDITABLE 8
941 GuiText GuiText_create (GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
942 GuiText GuiText_createShown (GuiForm parent, int left, int right, int top, int bottom, uint32 flags);
943
944 void GuiText_copy (GuiText me);
945 void GuiText_cut (GuiText me);
946 autostring32 GuiText_getSelection (GuiText me);
947 autostring32 GuiText_getString (GuiText me);
948 autostring32 GuiText_getStringAndSelectionPosition (GuiText me, integer *first, integer *last);
949 void GuiText_paste (GuiText me);
950 void GuiText_redo (GuiText me);
951 void GuiText_remove (GuiText me);
952 void GuiText_replace (GuiText me, integer from_pos, integer to_pos, conststring32 value);
953 void GuiText_scrollToSelection (GuiText me);
954 void GuiText_setChangedCallback (GuiText me, GuiText_ChangedCallback changedCallback, Thing changedBoss);
955 void GuiText_setFontSize (GuiText me, double size);
956 void GuiText_setRedoItem (GuiText me, GuiMenuItem item);
957 void GuiText_setSelection (GuiText me, integer first, integer last);
958 void GuiText_setString (GuiText me, conststring32 text, bool undoable = true);
959 void GuiText_setUndoItem (GuiText me, GuiMenuItem item);
960 void GuiText_undo (GuiText me);
961
962 /********** GuiWindow **********/
963
Thing_define(GuiWindow,GuiShell)964 Thing_define (GuiWindow, GuiShell) {
965 #if gtk
966 GtkMenuBar *d_gtkMenuBar;
967 #elif cocoa
968 int d_menuBarWidth;
969 GuiMenuItemCallback d_tabCallback;
970 Thing d_tabBoss;
971 GuiMenuItemCallback d_shiftTabCallback;
972 Thing d_shiftTabBoss;
973 GuiMenuItemCallback d_enterCallback;
974 Thing d_enterBoss;
975 GuiMenuItemCallback d_optionBackspaceCallback;
976 Thing d_optionBackspaceBoss;
977 GuiMenuItemCallback d_escapeCallback;
978 Thing d_escapeBoss;
979 #elif motif
980 GuiObject d_xmMenuBar;
981 #endif
982 };
983
984 /* GuiWindow creation flags: */
985 #define GuiWindow_FULLSCREEN 1
986 GuiWindow GuiWindow_create (int x, int y, int width, int height, int minimumWidth, int minimumHeight,
987 conststring32 title /* cattable */, GuiShell_GoAwayCallback goAwayCallback, Thing goAwayBoss, uint32 flags);
988 // returns a Form widget that has a new Shell parent.
989
990 void GuiWindow_addMenuBar (GuiWindow me);
991 bool GuiWindow_setDirty (GuiWindow me, bool dirty);
992 /*
993 Purpose: on OSX you get a little dot in the red close button,
994 and the window proxy icon dims.
995 Return value:
996 `true` if the system supports this feature, `false` if not;
997 the point of this is that you can use a different user feedback strategy, like appending
998 the text "(modified)" to the window title, if this feature is not supported.
999 */
1000 void GuiWindow_setFile (GuiWindow me, MelderFile file);
1001 /*
1002 Purpose: set the window title, and (on MacOS X) the window proxy icon and the window path menu.
1003 */
1004
1005 void GuiObject_destroy (GuiObject me);
1006
1007 /********** EVENTS **********/
1008
1009 #if defined (macintosh) || defined (_WIN32)
1010 void Gui_setOpenDocumentCallback (void (*openDocumentCallback) (MelderFile file), void (*finishedOpeningDocumentsCallback) ());
1011 #endif
1012
1013 #if defined (macintosh)
1014 void Gui_setQuitApplicationCallback (int (*quitApplicationCallback) (void));
1015 #endif
1016
1017 extern uinteger theGuiTopLowAccelerators [8];
1018
1019 /*
1020 'parent' is the top-level widget returned by GuiAppInitialize.
1021 */
1022 void Gui_injectMessageProcs (GuiWindow parent);
1023
1024 /* End of file Gui.h */
1025 #endif
1026