1 /* praatP.h
2  *
3  * Copyright (C) 1992-2007,2009-2021 Paul Boersma
4  *
5  * This code is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or (at
8  * your option) any later version.
9  *
10  * This code is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  * See the GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this work. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "praat.h"
20 
21 void praat_addActionScript (conststring32 className1, integer n1, conststring32 className2, integer n2, conststring32 className3, integer n3,
22 	conststring32 title, conststring32 after, integer depth, conststring32 script);
23 /* No strings may be null; unspecify them by giving an empty string. 'title' and 'script' are deep-copied. */
24 
25 void praat_removeAction_classNames (conststring32 className1, conststring32 className2,
26 	conststring32 className3, conststring32 title);
27 /* No arguments may be null; unspecify them by giving an empty string. */
28 
29 void praat_hideAction (ClassInfo class1, ClassInfo class2, ClassInfo class3, conststring32 title);
30 void praat_hideAction_classNames (conststring32 className1, conststring32 className2,
31 	conststring32 className3, conststring32 title);
32 void praat_showAction (ClassInfo class1, ClassInfo class2, ClassInfo class3, conststring32 title);
33 void praat_showAction_classNames (conststring32 className1, conststring32 className2,
34 	conststring32 className3, conststring32 title);
35 void praat_sortActions ();
36 
37 void praat_addMenuCommandScript (conststring32 window, conststring32 menu, conststring32 title,
38 	conststring32 after, integer depth, conststring32 script);
39 /* All strings are deep-copied and may not be null; unspecify them by giving an empty string. */
40 
41 /*
42 	For the Praat objects window:
43 	'window' is "Objects", 'menu' is "Praat", "New", "Open", "Help", "Preferences", "Goodies", or "Technical".
44 	For the Praat picture window:
45 	'window' is "Picture", 'menu' is "File", "Edit", "Margins", "World", "Select", "Pen", "Font", or "Help".
46 */
47 void praat_hideMenuCommand (conststring32 window, conststring32 menu, conststring32 title);
48 void praat_showMenuCommand (conststring32 window, conststring32 menu, conststring32 title);
49 void praat_saveAddedMenuCommands (MelderString *buffer);
50 void praat_saveToggledMenuCommands (MelderString *buffer);
51 #define praat_addFixedButtonCommand(p,t,c,x,y)  praat_addFixedButtonCommand_ (p, t, c, U"" #c, x, y)
52 void praat_addFixedButtonCommand_ (GuiForm parent, conststring32 title, UiCallback callback, conststring32 nameOfCallback, int x, int y);
53 void praat_sensitivizeFixedButtonCommand (conststring32 title, bool sensitive);
54 void praat_sortMenuCommands ();
55 
56 #define praat_MAXNUM_MENUS 20   /* Maximum number of added New, Open, Save, or Help menus. */
57 #define praat_MAXNUM_FILE_TYPE_RECOGNIZERS 50   /* File types recognizable by 'Read from file...'. */
58 
Thing_define(Praat_Command,Thing)59 Thing_define (Praat_Command, Thing) {
60 	ClassInfo class1, class2, class3, class4;   // selected classes
61 	integer n1, n2, n3, n4;   // number of selected objects of each class; 0 means "any number"
62 	autostring32 title;   // button text = command text
63 	UiCallback callback;   // multi-purpose
64 		/* If both UiCallback::sendingForm and sendingString are null, this routine is an activate callback;
65 			you should directly execute the command, or call UiForm_do(dialog) if you need arguments;
66 			UiForm_do will call this routine again with sendingForm = dialog. */
67 		/* If sendingForm exists, this routine is an ok callback,
68 			and you should execute the command. */
69 		/* If sendingString exists (apparently from a command file),
70 			UiForm_parseString should be called, which will call this routine again with sendingForm. */
71 		/* All of these things are normally taken care of by the macros defined in praat.h. */
72 	conststring32 nameOfCallback;
73 	signed char
74 		visible,   // do the selected classes match class1, class2, class3 and class4?
75 		executable,   // is the command actually executable? I.e. isn't the button greyed out?
76 		depth,   // 0 = command in main menu, 1 = command in submenu, 2 = command in submenu of submenu
77 		hidden,   // this can change when Praat is running, even from the start-up file
78 		toggled,   // did the hiddenness change when Praat was running? The factory value for "hidden" is (hidden != toggled)
79 		phase,
80 		unhidable,
81 		attractive,
82 		noApi,   // do not include in a library API ("View & Edit", help commands...)
83 		forceApi;   // include in a library API even if this button is hidden by default ("Record Sound (fixed time)...")
84 	integer deprecationYear;
85 	GuiThing button;
86 	autostring32 window, menu;
87 	autostring32 script;   // if 'callback' equals DO_RunTheScriptFromAnyAddedMenuCommand
88 	autostring32 after;   // title of previous command, often null; if starting with an asterisk (deprecation), then a reference to the replacement
89 	integer uniqueID;   // for sorting the added commands
90 	integer sortingTail;
91 };
92 
93 #define praat_STARTING_UP  1
94 #define praat_READING_BUTTONS  2
95 #define praat_HANDLING_EVENTS  3
96 
97 integer praat_numberOfSelected (ClassInfo klas);
98 integer praat_idOfSelected (ClassInfo klas, integer inplace);
99 autoVEC praat_idsOfAllSelected (ClassInfo klas);
100 char32 * praat_nameOfSelected (ClassInfo klas, integer inplace);
101 
102 /* Used by praat.cpp; defined in praat_picture.cpp.
103 */
104 void praat_picture_init ();
105 void praat_picture_exit ();
106 
107 void praat_picture_prefs ();
108 void praat_picture_prefsChanged ();
109 /* Praat shell tells Picture window that preferences have been changed
110    (after reading the prefs file).
111    Picture window will update the font menu.
112 */
113 GuiMenu praat_picture_resolveMenu (conststring32 menu);
114 
115 /* The following routines are a bit private (used by praat_script.cpp). */
116 /* If you must call them, follow them by praat_show (). */
117 void praat_deselect (integer i);
118 void praat_deselectAll ();
119 void praat_select (integer i);
120 void praat_selectAll ();
121 
122 void praat_list_background ();
123 void praat_list_foreground ();   // updates the list of objects after backgrounding
124 void praat_background ();
125 void praat_foreground ();
126 Editor praat_findEditorFromString (conststring32 string);
127 Editor praat_findEditorById (integer id);
128 
129 void praat_showLogo ();
130 
131 /* Communication with praat_menuCommands.cpp: */
132 void praat_menuCommands_init ();
133 void praat_menuCommands_exit_optimizeByLeaking ();
134 int praat_doMenuCommand (conststring32 command, conststring32 arguments, Interpreter interpreter);   // 0 = not found
135 int praat_doMenuCommand (conststring32 command, integer narg, Stackel args, Interpreter interpreter);   // 0 = not found
136 integer praat_getNumberOfMenuCommands ();
137 Praat_Command praat_getMenuCommand (integer i);
138 
139 /* Communication with praat_actions.cpp: */
140 void praat_actions_show ();
141 void praat_actions_createWriteMenu (GuiWindow window);
142 void praat_actions_init ();   // creates space for action commands
143 void praat_actions_exit_optimizeByLeaking ();
144 void praat_actions_createDynamicMenu (GuiWindow window);
145 void praat_saveAddedActions (MelderString *buffer);
146 void praat_saveToggledActions (MelderString *buffer);
147 int praat_doAction (conststring32 command, conststring32 arguments, Interpreter interpreter);   // 0 = not found
148 int praat_doAction (conststring32 command, integer narg, Stackel args, Interpreter interpreter);   // 0 = not found
149 integer praat_getNumberOfActions ();   // for ButtonEditor
150 Praat_Command praat_getAction (integer i);   // for ButtonEditor
151 
152 /* Communication with praat_statistics.cpp: */
153 void praat_statistics_prefs ();   // at init time
154 void praat_statistics_prefsChanged ();   // after reading prefs file
155 void praat_statistics_exit ();   // at exit time
156 void praat_reportMemoryUse ();
157 void praat_reportSystemProperties ();
158 void praat_reportGraphicalProperties ();
159 void praat_reportIntegerProperties ();
160 void praat_reportTextProperties ();
161 void praat_reportFontProperties ();
162 
163 /* Communication with praat_objectMenus.cpp: */
164 GuiMenu praat_objects_resolveMenu (conststring32 menu);
165 void praat_addFixedButtons (GuiWindow window);
166 void praat_addMenus (GuiWindow window);
167 void praat_addMenus2 ();
168 
169 /* API creation: */
170 void praat_library_createC (bool isInHeaderFile, bool includeCreateAPI, bool includeReadAPI, bool includeSaveAPI,
171 	bool includeQueryAPI, bool includeModifyAPI, bool includeToAPI,
172 	bool includeRecordAPI, bool includePlayAPI,
173 	bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI,
174 	bool includeDemoAPI);
175 void praat_menuCommands_writeC (bool isInHeaderFile, bool includeCreateAPI, bool includeReadAPI,
176 	bool includeRecordAPI, bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI);
177 void praat_actions_writeC (bool isInHeaderFile, bool includeSaveAPI,
178 	bool includeQueryAPI, bool includeModifyAPI, bool includeToAPI,
179 	bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI);
180 
181 void praat_cleanUpName (char32 *name);
182 void praat_list_renameAndSelect (integer position, conststring32 name);
183 
184 inline struct PraatP {
185 	int argc;
186 	char **argv;
187 	int argumentNumber;
188 	bool userWantsToOpen;
189 	bool dontUsePictureWindow;   // see praat_dontUsePictureWindow ()
190 	bool ignorePreferenceFiles, ignorePlugins;
191 	bool hasCommandLineInput;
192 	autostring32 title;
193 	GuiWindow menuBar;
194 	int phase;
195 	Editor editor;   // scripting environment
196 } praatP;
197 
198 struct autoPraatBackground {
autoPraatBackgroundautoPraatBackground199 	autoPraatBackground () { praat_background (); }
~autoPraatBackgroundautoPraatBackground200 	~autoPraatBackground () { try { praat_foreground (); } catch (...) { Melder_clearError (); } }   // BUG if called during error time
201 };
202 
203 /* End of file praatP.h */
204