Gui.h 34 KB

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