Editor.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #ifndef _Editor_h_
  2. #define _Editor_h_
  3. /* Editor.h
  4. *
  5. * Copyright (C) 1992-2018 Paul Boersma
  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. #include "Collection.h"
  21. #include "Gui.h"
  22. #include "Ui.h"
  23. #include "Graphics.h"
  24. #include "prefs.h"
  25. #include "Editor_enums.h"
  26. Thing_declare (Editor);
  27. Thing_define (EditorMenu, Thing) {
  28. Editor d_editor;
  29. autostring32 menuTitle;
  30. GuiMenu menuWidget;
  31. OrderedOf<structEditorCommand> commands;
  32. };
  33. typedef MelderCallback <void, structEditor, EditorCommand, UiForm, integer /*narg*/, Stackel /*args*/, conststring32, Interpreter> EditorCommandCallback;
  34. Thing_define (EditorCommand, Thing) {
  35. Editor d_editor;
  36. EditorMenu menu;
  37. autostring32 itemTitle;
  38. GuiMenuItem itemWidget;
  39. EditorCommandCallback commandCallback;
  40. autostring32 script;
  41. autoUiForm d_uiform;
  42. };
  43. typedef MelderCallback <void, structEditor> Editor_DataChangedCallback;
  44. typedef MelderCallback <void, structEditor> Editor_DestructionCallback;
  45. typedef MelderCallback <void, structEditor, autoDaata /* publication */> Editor_PublicationCallback;
  46. Thing_define (Editor, Thing) {
  47. GuiWindow windowForm;
  48. GuiMenuItem undoButton, searchButton;
  49. OrderedOf<structEditorMenu> menus;
  50. Daata data; // the data that can be displayed and edited
  51. autoDaata previousData; // the data that can be displayed and edited
  52. bool ownData;
  53. char32 undoText [100];
  54. Graphics pictureGraphics;
  55. Editor_DataChangedCallback d_dataChangedCallback;
  56. Editor_DestructionCallback d_destructionCallback;
  57. Editor_PublicationCallback d_publicationCallback;
  58. const char *callbackSocket;
  59. void v_destroy () noexcept
  60. override;
  61. void v_info ()
  62. override;
  63. void v_nameChanged ()
  64. override; // sets the window and icon titles to reflect the new name
  65. virtual void v_goAway () { forget_nozero (this); }
  66. virtual bool v_hasMenuBar () { return true; }
  67. virtual bool v_canFullScreen () { return false; }
  68. virtual bool v_editable () { return true ; }
  69. virtual bool v_scriptable () { return true; }
  70. virtual void v_createMenuItems_file (EditorMenu menu);
  71. virtual void v_createMenuItems_edit (EditorMenu menu);
  72. virtual bool v_hasQueryMenu () { return true; }
  73. virtual void v_createMenuItems_query (EditorMenu menu);
  74. virtual void v_createMenuItems_query_info (EditorMenu menu);
  75. virtual void v_createMenus ();
  76. virtual void v_createHelpMenuItems (EditorMenu menu) { (void) menu; }
  77. virtual void v_createChildren () { }
  78. virtual void v_dataChanged () { }
  79. virtual void v_saveData ();
  80. virtual void v_restoreData ();
  81. virtual void v_form_pictureWindow (EditorCommand cmd);
  82. virtual void v_ok_pictureWindow (EditorCommand cmd);
  83. virtual void v_do_pictureWindow (EditorCommand cmd);
  84. virtual void v_form_pictureMargins (EditorCommand cmd);
  85. virtual void v_ok_pictureMargins (EditorCommand cmd);
  86. virtual void v_do_pictureMargins (EditorCommand cmd);
  87. #include "Editor_prefs.h"
  88. };
  89. GuiMenuItem EditorMenu_addCommand (EditorMenu me, conststring32 itemTitle /* cattable */, uint32 flags, EditorCommandCallback commandCallback);
  90. GuiMenuItem EditorCommand_getItemWidget (EditorCommand me);
  91. EditorMenu Editor_addMenu (Editor me, conststring32 menuTitle, uint32 flags);
  92. GuiObject EditorMenu_getMenuWidget (EditorMenu me);
  93. #define Editor_HIDDEN (1 << 14)
  94. GuiMenuItem Editor_addCommand (Editor me, conststring32 menuTitle, conststring32 itemTitle, uint32 flags, EditorCommandCallback commandCallback);
  95. GuiMenuItem Editor_addCommandScript (Editor me, conststring32 menuTitle, conststring32 itemTitle, uint32 flags,
  96. conststring32 script);
  97. void Editor_setMenuSensitive (Editor me, conststring32 menu, bool sensitive);
  98. inline static void Editor_raise (Editor me)
  99. /*
  100. * Message: "move your window to the front", i.e.
  101. * if you are invisible, then make your window visible at the front;
  102. * if you are iconized, then deiconize yourself at the front;
  103. * if you are already visible, just move your window to the front."
  104. */
  105. {
  106. GuiThing_show (my windowForm);
  107. }
  108. inline static void Editor_dataChanged (Editor me)
  109. /*
  110. * Message: "your data has changed by an action from *outside* yourself,
  111. * so you may e.g. like to redraw yourself."
  112. */
  113. {
  114. my v_dataChanged ();
  115. }
  116. inline static void Editor_setDataChangedCallback (Editor me, Editor_DataChangedCallback dataChangedCallback)
  117. /*
  118. * Message from boss: "notify me by calling this dataChangedCallback every time your data is changed from *inside* yourself."
  119. *
  120. * In Praat, the dataChangedCallback is useful if there is more than one editor
  121. * with the same data; in this case, the owner of all those editors will
  122. * (in the dataChangedCallback it installed) notify the change to the other editors
  123. * by sending them a dataChanged () message.
  124. */
  125. {
  126. my d_dataChangedCallback = dataChangedCallback;
  127. }
  128. inline static void Editor_broadcastDataChanged (Editor me)
  129. /*
  130. * Message to boss: "my data has changed by an action from inside myself."
  131. *
  132. * The editor has to call this after every menu command, click or key press that causes a change in the data.
  133. */
  134. {
  135. if (my d_dataChangedCallback)
  136. my d_dataChangedCallback (me);
  137. }
  138. inline static void Editor_setDestructionCallback (Editor me, Editor_DestructionCallback destructionCallback)
  139. /*
  140. * Message from observer: "notify me by calling this destructionCallback every time you destroy yourself."
  141. *
  142. * In Praat, "destroying yourself" typically happens when the user closes the editor window
  143. * or when an object that is being viewed in an editor window is "Remove"d.
  144. * Typically, the observer will (in the destructionCallback it installed) remove all dangling references to this editor.
  145. */
  146. {
  147. my d_destructionCallback = destructionCallback;
  148. }
  149. inline static void Editor_broadcastDestruction (Editor me)
  150. /*
  151. * Message to boss: "I am destroying all my members and will free myself shortly."
  152. *
  153. * The editor calls this once, namely in Editor::v_destroy().
  154. */
  155. {
  156. if (my d_destructionCallback)
  157. my d_destructionCallback (me);
  158. }
  159. inline static void Editor_setPublicationCallback (Editor me, Editor_PublicationCallback publicationCallback)
  160. /*
  161. * Message from boss: "notify me by calling this publicationCallback every time you have a piece of data to publish."
  162. *
  163. * In Praat, editors typically "publish" a piece of data when the user chooses
  164. * things like "Extract selected sound", "Extract visible pitch curve", or "View spectral slice".
  165. * Typically, the boss will (in the publicationCallback it installed) install the published data in Praat's object list,
  166. * but the editor doesn't have to know that.
  167. */
  168. {
  169. my d_publicationCallback = publicationCallback;
  170. }
  171. inline static void Editor_broadcastPublication (Editor me, autoDaata publication)
  172. /*
  173. * Message to boss: "I have a piece of data for you to publish."
  174. *
  175. * The editor has to call this every time the user wants to "publish" ("Extract") some data from the editor.
  176. *
  177. * Constraint: "publication" has to be new data, either "extracted" or "copied" from data in the editor.
  178. * The boss becomes the owner of this published data,
  179. * so the call to broadcastPublication() has to transfer ownership of "publication".
  180. */
  181. {
  182. if (my d_publicationCallback)
  183. my d_publicationCallback (me, publication.move());
  184. }
  185. /***** For inheritors. *****/
  186. void Editor_init (Editor me, int x, int y , int width, int height,
  187. conststring32 title, Daata data);
  188. /*
  189. This creates my shell and my windowForm,
  190. calls the v_createMenus and v_createChildren methods,
  191. and manages my shell and my windowForm.
  192. 'width' and 'height' determine the dimensions of the editor:
  193. if 'width' < 0, the width of the screen is added to it;
  194. if 'height' < 0, the height of the screeen is added to it;
  195. if 'width' is 0, the width is based on the children;
  196. if 'height' is 0, the height is base on the children.
  197. 'x' and 'y' determine the position of the editor:
  198. if 'x' > 0, 'x' is the distance to the left edge of the screen;
  199. if 'x' < 0, |'x'| is the distance to the right edge of the screen;
  200. if 'x' is 0, the editor is horizontally centred on the screen;
  201. if 'y' > 0, 'y' is the distance to the top of the screen;
  202. if 'y' < 0, |'y'| is the distance to the bottom of the screen;
  203. if 'y' is 0, the editor is vertically centred on the screen;
  204. This routine does not transfer ownership of 'data' to the Editor,
  205. and the Editor will not destroy 'data' when the Editor itself is destroyed.
  206. */
  207. void Editor_save (Editor me, conststring32 text); // for Undo
  208. autoUiForm UiForm_createE (EditorCommand cmd, conststring32 title, conststring32 invokingButtonTitle, conststring32 helpTitle);
  209. void UiForm_parseStringE (EditorCommand cmd, integer narg, Stackel args, conststring32 arguments, Interpreter interpreter);
  210. autoUiForm UiOutfile_createE (EditorCommand cmd, conststring32 title, conststring32 invokingButtonTitle, conststring32 helpTitle);
  211. autoUiForm UiInfile_createE (EditorCommand cmd, conststring32 title, conststring32 invokingButtonTitle, conststring32 helpTitle);
  212. EditorCommand Editor_getMenuCommand (Editor me, conststring32 menuTitle, conststring32 itemTitle);
  213. void Editor_doMenuCommand (Editor me, conststring32 command, integer narg, Stackel args, conststring32 arguments, Interpreter interpreter);
  214. /*
  215. * The following two procedures are in praat_picture.cpp.
  216. * They allow editors to draw into the Picture window.
  217. */
  218. Graphics praat_picture_editor_open (bool eraseFirst);
  219. void praat_picture_editor_close ();
  220. void Editor_openPraatPicture (Editor me);
  221. void Editor_closePraatPicture (Editor me);
  222. #endif
  223. /* End of file Editor.h */