| 1 |
#ifndef _EditorM_h_ |
| 2 |
#define _EditorM_h_ |
| 3 |
/* EditorM.h |
| 4 |
* |
| 5 |
* Copyright (C) 1992-2013,2015-2024,2026 Paul Boersma, 2026 Anastasia Shchupak |
| 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 3 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 |
#ifdef _praatM_h_ |
| 22 |
#error Include either praatM.h or EditorM.h, but not both. |
| 23 |
#endif |
| 24 |
|
| 25 |
#define EDITOR_ARGS \ |
| 26 |
[[maybe_unused]] EditorCommand cmd, \ |
| 27 |
[[maybe_unused]] UiForm _sendingForm_, \ |
| 28 |
[[maybe_unused]] integer _narg_, \ |
| 29 |
[[maybe_unused]] Stackel _args_, \ |
| 30 |
[[maybe_unused]] conststring32 _sendingString_, \ |
| 31 |
[[maybe_unused]] Interpreter optionalInterpreter |
| 32 |
|
| 33 |
#define EDITOR_FORM(title, helpTitle) \ |
| 34 |
if (cmd -> d_uiform) \ |
| 35 |
goto _form_inited_; \ |
| 36 |
cmd -> d_uiform = UiForm_createE (cmd, title, cmd -> itemTitle.get(), helpTitle); |
| 37 |
|
| 38 |
#define EDITOR_OK \ |
| 39 |
UiForm_finish (cmd -> d_uiform.get()); \ |
| 40 |
_form_inited_: \ |
| 41 |
if (! _args_ && ! _sendingForm_ && ! _sendingString_) { |
| 42 |
|
| 43 |
#define EDITOR_DO \ |
| 44 |
UiForm_do (cmd -> d_uiform.get(), false); \ |
| 45 |
} else if (! _sendingForm_) { \ |
| 46 |
UiForm_parseStringE (cmd, _narg_, _args_, _sendingString_, optionalInterpreter); \ |
| 47 |
} else { |
| 48 |
|
| 49 |
#define EDITOR_DO_ALTERNATIVE(alternative) \ |
| 50 |
UiForm_do (cmd -> d_uiform.get(), false); \ |
| 51 |
} else if (! _sendingForm_) { \ |
| 52 |
try { \ |
| 53 |
UiForm_parseStringE (cmd, _narg_, _args_, _sendingString_, optionalInterpreter); \ |
| 54 |
} catch (MelderError) { \ |
| 55 |
if (Melder_hasCrash ()) \ |
| 56 |
throw; \ |
| 57 |
autostring32 _parkedError = Melder_dup_f (Melder_getError ()); \ |
| 58 |
Melder_clearError (); \ |
| 59 |
try { \ |
| 60 |
static autoEditorCommand _alternativeCmd; \ |
| 61 |
if (! _alternativeCmd) \ |
| 62 |
_alternativeCmd = Thing_new (EditorCommand); \ |
| 63 |
_alternativeCmd -> d_editor = cmd -> d_editor; \ |
| 64 |
_alternativeCmd -> sender = cmd -> sender; \ |
| 65 |
_alternativeCmd -> menu = cmd -> menu; \ |
| 66 |
_alternativeCmd -> itemTitle = Melder_dup (cmd -> itemTitle.get()); \ |
| 67 |
_alternativeCmd -> itemWidget = nullptr; \ |
| 68 |
_alternativeCmd -> commandCallback = cmd -> commandCallback; \ |
| 69 |
_alternativeCmd -> script = Melder_dup (cmd -> script.get()); \ |
| 70 |
_alternativeCmd -> d_uiform = autoUiForm (); \ |
| 71 |
alternative (me, _alternativeCmd.get(), _sendingForm_, _narg_, _args_, _sendingString_, optionalInterpreter); \ |
| 72 |
} catch (MelderError) { \ |
| 73 |
Melder_clearError (); \ |
| 74 |
Melder_appendError (_parkedError.get()); \ |
| 75 |
throw; \ |
| 76 |
} \ |
| 77 |
} \ |
| 78 |
} else { |
| 79 |
|
| 80 |
#define EDITOR_END \ |
| 81 |
} |
| 82 |
|
| 83 |
/* |
| 84 |
Functions to define the fields in a form on the basis of the label text |
| 85 |
and factory default value. |
| 86 |
They are to be called between EDITOR_FORM and EDITOR_OK. |
| 87 |
*/ |
| 88 |
|
| 89 |
#define REAL_VARIABLE(realVariable) \ |
| 90 |
static double realVariable; |
| 91 |
|
| 92 |
#define REAL_FIELD(realVariable, labelText, defaultStringValue) \ |
| 93 |
UiForm_addReal (cmd -> d_uiform.get(), & realVariable, nullptr, labelText, defaultStringValue); |
| 94 |
|
| 95 |
#define REAL(realVariable, labelText, defaultStringValue) \ |
| 96 |
REAL_VARIABLE (realVariable) \ |
| 97 |
REAL_FIELD (realVariable, labelText, defaultStringValue) |
| 98 |
|
| 99 |
|
| 100 |
#define REAL_OR_UNDEFINED_VARIABLE(realVariable) \ |
| 101 |
static double realVariable; |
| 102 |
|
| 103 |
#define REAL_OR_UNDEFINED_FIELD(realVariable, labelText, defaultStringValue) \ |
| 104 |
UiForm_addRealOrUndefined (cmd -> d_uiform.get(), & realVariable, nullptr, labelText, defaultStringValue); |
| 105 |
|
| 106 |
#define REAL_OR_UNDEFINED(realVariable, labelText, defaultStringValue) \ |
| 107 |
REAL_OR_UNDEFINED_VARIABLE (realVariable) \ |
| 108 |
REAL_OR_UNDEFINED_FIELD (realVariable, labelText, defaultStringValue) |
| 109 |
|
| 110 |
|
| 111 |
#define POSITIVE_VARIABLE(realVariable) \ |
| 112 |
static double realVariable; |
| 113 |
|
| 114 |
#define POSITIVE_FIELD(realVariable, labelText, defaultStringValue) \ |
| 115 |
UiForm_addPositive (cmd -> d_uiform.get(), & realVariable, nullptr, labelText, defaultStringValue); |
| 116 |
|
| 117 |
#define POSITIVE(realVariable, labelText, defaultStringValue) \ |
| 118 |
POSITIVE_VARIABLE (realVariable) \ |
| 119 |
POSITIVE_FIELD (realVariable, labelText, defaultStringValue) |
| 120 |
|
| 121 |
|
| 122 |
#define NONNEGATIVE_VARIABLE(realVariable) \ |
| 123 |
static double realVariable; |
| 124 |
|
| 125 |
#define NONNEGATIVE_FIELD(realVariable, labelText, defaultStringValue) \ |
| 126 |
UiForm_addNonnegative (cmd -> d_uiform.get(), & realVariable, nullptr, labelText, defaultStringValue); |
| 127 |
|
| 128 |
#define NONNEGATIVE(realVariable, labelText, defaultStringValue) \ |
| 129 |
NONNEGATIVE_VARIABLE (realVariable) \ |
| 130 |
NONNEGATIVE_FIELD (realVariable, labelText, defaultStringValue) |
| 131 |
|
| 132 |
|
| 133 |
#define INTEGER_VARIABLE(integerVariable) \ |
| 134 |
static integer integerVariable; |
| 135 |
|
| 136 |
#define INTEGER_FIELD(integerVariable, labelText, defaultStringValue) \ |
| 137 |
UiForm_addInteger (cmd -> d_uiform.get(), & integerVariable, nullptr, labelText, defaultStringValue); |
| 138 |
|
| 139 |
#define INTEGER(integerVariable, labelText, defaultStringValue) \ |
| 140 |
INTEGER_VARIABLE (integerVariable) \ |
| 141 |
INTEGER_FIELD (integerVariable, labelText, defaultStringValue) |
| 142 |
|
| 143 |
|
| 144 |
#define NATURAL0_VARIABLE(integerVariable) \ |
| 145 |
static integer integerVariable; |
| 146 |
|
| 147 |
#define NATURAL0_FIELD(integerVariable, labelText, defaultStringValue) \ |
| 148 |
UiForm_addNatural0 (cmd -> d_uiform.get(), & integerVariable, nullptr, labelText, defaultStringValue); |
| 149 |
|
| 150 |
#define NATURAL0(integerVariable, labelText, defaultStringValue) \ |
| 151 |
NATURAL0_VARIABLE (integerVariable) \ |
| 152 |
NATURAL0_FIELD (integerVariable, labelText, defaultStringValue) |
| 153 |
|
| 154 |
|
| 155 |
#define NATURAL1_VARIABLE(integerVariable) \ |
| 156 |
static integer integerVariable; |
| 157 |
|
| 158 |
#define NATURAL1_FIELD(integerVariable, labelText, defaultStringValue) \ |
| 159 |
UiForm_addNatural1 (cmd -> d_uiform.get(), & integerVariable, nullptr, labelText, defaultStringValue); |
| 160 |
|
| 161 |
#define NATURAL1(integerVariable, labelText, defaultStringValue) \ |
| 162 |
NATURAL1_VARIABLE (integerVariable) \ |
| 163 |
NATURAL1_FIELD (integerVariable, labelText, defaultStringValue) |
| 164 |
|
| 165 |
|
| 166 |
/* TODO: remove */ |
| 167 |
#define NATURAL_VARIABLE(integerVariable) \ |
| 168 |
static integer integerVariable; |
| 169 |
|
| 170 |
#define NATURAL_FIELD(integerVariable, labelText, defaultStringValue) \ |
| 171 |
UiForm_addNatural1 (cmd -> d_uiform.get(), & integerVariable, nullptr, labelText, defaultStringValue); |
| 172 |
|
| 173 |
#define NATURAL(integerVariable, labelText, defaultStringValue) \ |
| 174 |
NATURAL_VARIABLE (integerVariable) \ |
| 175 |
NATURAL_FIELD (integerVariable, labelText, defaultStringValue) |
| 176 |
|
| 177 |
|
| 178 |
#define WORD_VARIABLE(stringVariable) \ |
| 179 |
static conststring32 stringVariable; |
| 180 |
|
| 181 |
#define WORD_FIELD(stringVariable, labelText, defaultStringValue) \ |
| 182 |
UiForm_addWord (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultStringValue); |
| 183 |
|
| 184 |
#define WORD(stringVariable, labelText, defaultStringValue) \ |
| 185 |
WORD_VARIABLE (stringVariable) \ |
| 186 |
WORD_FIELD (stringVariable, labelText, defaultStringValue) |
| 187 |
|
| 188 |
|
| 189 |
#define SENTENCE_VARIABLE(stringVariable) \ |
| 190 |
static conststring32 stringVariable; |
| 191 |
|
| 192 |
#define SENTENCE_FIELD(stringVariable, labelText, defaultStringValue) \ |
| 193 |
UiForm_addSentence (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultStringValue); |
| 194 |
|
| 195 |
#define SENTENCE(stringVariable, labelText, defaultStringValue) \ |
| 196 |
SENTENCE_VARIABLE (stringVariable) \ |
| 197 |
SENTENCE_FIELD (stringVariable, labelText, defaultStringValue) |
| 198 |
|
| 199 |
|
| 200 |
#define COLOUR_VARIABLE(colourVariable) \ |
| 201 |
static MelderColour colourVariable; |
| 202 |
|
| 203 |
#define COLOUR_FIELD(colourVariable, labelText, defaultStringValue) \ |
| 204 |
UiForm_addColour (cmd -> d_uiform.get(), & colourVariable, nullptr, labelText, defaultStringValue); |
| 205 |
|
| 206 |
#define COLOUR(colourVariable, labelText, defaultStringValue) \ |
| 207 |
COLOUR_VARIABLE (colourVariable) \ |
| 208 |
COLOUR_FIELD (colourVariable, labelText, defaultStringValue) |
| 209 |
|
| 210 |
|
| 211 |
#define CHANNEL_VARIABLE(integerVariable) \ |
| 212 |
static integer integerVariable; |
| 213 |
|
| 214 |
#define CHANNEL_FIELD(integerVariable, labelText, defaultStringValue) \ |
| 215 |
UiForm_addChannel (cmd -> d_uiform.get(), & integerVariable, nullptr, labelText, defaultStringValue); |
| 216 |
|
| 217 |
#define CHANNEL(integerVariable, labelText, defaultStringValue) \ |
| 218 |
CHANNEL_VARIABLE (integerVariable) \ |
| 219 |
CHANNEL_FIELD (integerVariable, labelText, defaultStringValue) |
| 220 |
|
| 221 |
|
| 222 |
#define BOOLEAN_VARIABLE(booleanVariable) \ |
| 223 |
static bool booleanVariable; |
| 224 |
|
| 225 |
#define BOOLEAN_FIELD(booleanVariable, labelText, defaultBooleanValue) \ |
| 226 |
UiForm_addBoolean (cmd -> d_uiform.get(), & booleanVariable, nullptr, labelText, defaultBooleanValue); |
| 227 |
|
| 228 |
#define BOOLEAN(booleanVariable, labelText, defaultBooleanValue) \ |
| 229 |
BOOLEAN_VARIABLE (booleanVariable) \ |
| 230 |
BOOLEAN_FIELD (booleanVariable, labelText, defaultBooleanValue) |
| 231 |
|
| 232 |
|
| 233 |
#define HEADING(labelText) \ |
| 234 |
UiForm_addHeading (cmd -> d_uiform.get(), nullptr, labelText); |
| 235 |
|
| 236 |
|
| 237 |
#define COMMENT(labelText) \ |
| 238 |
UiForm_addComment (cmd -> d_uiform.get(), nullptr, labelText); |
| 239 |
|
| 240 |
|
| 241 |
#define MUTABLE_COMMENT_VARIABLE(stringVariable) \ |
| 242 |
static conststring32 stringVariable; |
| 243 |
|
| 244 |
#define MUTABLE_COMMENT_FIELD(stringVariable, labelText) \ |
| 245 |
UiForm_addComment (cmd -> d_uiform.get(), & stringVariable, labelText); |
| 246 |
|
| 247 |
#define MUTABLE_COMMENT(stringVariable, labelText) \ |
| 248 |
MUTABLE_COMMENT_VARIABLE (stringVariable) \ |
| 249 |
MUTABLE_COMMENT_FIELD (stringVariable, labelText) |
| 250 |
|
| 251 |
|
| 252 |
#define CAPTION(labelText) \ |
| 253 |
UiForm_addCaption (cmd -> d_uiform.get(), nullptr, labelText); |
| 254 |
|
| 255 |
|
| 256 |
#define MUTABLE_CAPTION_VARIABLE(stringVariable) \ |
| 257 |
static conststring32 stringVariable; |
| 258 |
|
| 259 |
#define MUTABLE_CAPTION_FIELD(stringVariable, labelText) \ |
| 260 |
UiForm_addCaption (cmd -> d_uiform.get(), & stringVariable, labelText); |
| 261 |
|
| 262 |
#define MUTABLE_CAPTION(stringVariable, labelText) \ |
| 263 |
MUTABLE_CAPTION_VARIABLE (stringVariable) \ |
| 264 |
MUTABLE_CAPTION_FIELD (stringVariable, labelText) |
| 265 |
|
| 266 |
|
| 267 |
#define TEXTFIELD_VARIABLE(stringVariable) \ |
| 268 |
static conststring32 stringVariable; |
| 269 |
|
| 270 |
#define TEXTFIELD_FIELD(stringVariable, labelText, defaultValue, numberOfLines) \ |
| 271 |
UiForm_addText (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultValue, numberOfLines); |
| 272 |
|
| 273 |
#define TEXTFIELD(stringVariable, labelText, defaultValue, numberOfLines) \ |
| 274 |
TEXTFIELD_VARIABLE (stringVariable) \ |
| 275 |
TEXTFIELD_FIELD (stringVariable, labelText, defaultValue, numberOfLines) |
| 276 |
|
| 277 |
|
| 278 |
#define FORMULA_VARIABLE(stringVariable) \ |
| 279 |
static conststring32 stringVariable; |
| 280 |
|
| 281 |
#define FORMULA_FIELD(stringVariable, labelText, defaultValue) \ |
| 282 |
UiForm_addFormula (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultValue); |
| 283 |
|
| 284 |
#define FORMULA(stringVariable, labelText, defaultValue) \ |
| 285 |
FORMULA_VARIABLE (stringVariable) \ |
| 286 |
FORMULA_FIELD (stringVariable, labelText, defaultValue) |
| 287 |
|
| 288 |
|
| 289 |
#define INFILE_VARIABLE(stringVariable) \ |
| 290 |
static conststring32 stringVariable; |
| 291 |
|
| 292 |
#define INFILE_FIELD(stringVariable, labelText, defaultValue) \ |
| 293 |
UiForm_addInfile (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultValue); |
| 294 |
|
| 295 |
#define INFILE(stringVariable, labelText, defaultValue) \ |
| 296 |
INFILE_VARIABLE (stringVariable) \ |
| 297 |
INFILE_FIELD (stringVariable, labelText, defaultValue) |
| 298 |
|
| 299 |
|
| 300 |
#define OUTFILE_VARIABLE(stringVariable) \ |
| 301 |
static conststring32 stringVariable; |
| 302 |
|
| 303 |
#define OUTFILE_FIELD(stringVariable, labelText, defaultValue) \ |
| 304 |
UiForm_addOutfile (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultValue); |
| 305 |
|
| 306 |
#define OUTFILE(stringVariable, labelText, defaultValue) \ |
| 307 |
OUTFILE_VARIABLE (stringVariable) \ |
| 308 |
OUTFILE_FIELD (stringVariable, labelText, defaultValue) |
| 309 |
|
| 310 |
|
| 311 |
#define FOLDER_VARIABLE(stringVariable) \ |
| 312 |
static conststring32 stringVariable; |
| 313 |
|
| 314 |
#define FOLDER_FIELD(stringVariable, labelText, defaultValue) \ |
| 315 |
UiForm_addFolder (cmd -> d_uiform.get(), & stringVariable, nullptr, labelText, defaultValue); |
| 316 |
|
| 317 |
#define FOLDER(stringVariable, labelText, defaultValue) \ |
| 318 |
FOLDER_VARIABLE (stringVariable) \ |
| 319 |
FOLDER_FIELD (stringVariable, labelText, defaultValue) |
| 320 |
|
| 321 |
|
| 322 |
#define REALVECTOR_VARIABLE(realVectorVariable) \ |
| 323 |
static constVEC realVectorVariable; |
| 324 |
|
| 325 |
#define REALVECTOR_FIELD(realVectorVariable, labelText, defaultFormat, defaultStringValue) \ |
| 326 |
UiForm_addRealVector (cmd -> d_uiform.get(), & realVectorVariable, nullptr, labelText, kUi_realVectorFormat::defaultFormat, defaultStringValue); |
| 327 |
|
| 328 |
#define REALVECTOR(realVectorVariable, labelText, defaultFormat, defaultStringValue) \ |
| 329 |
REALVECTOR_VARIABLE (realVectorVariable) \ |
| 330 |
REALVECTOR_FIELD (realVectorVariable, labelText, defaultFormat, defaultStringValue) |
| 331 |
|
| 332 |
|
| 333 |
#define NATURAL0VECTOR_VARIABLE(integerVectorVariable) \ |
| 334 |
static constINTVEC integerVectorVariable; |
| 335 |
|
| 336 |
#define NATURAL0VECTOR_FIELD(integerVectorVariable, labelText, defaultFormat, defaultStringValue) \ |
| 337 |
UiForm_addNatural0Vector (cmd -> d_uiform.get(), & integerVectorVariable, nullptr, labelText, kUi_integerVectorFormat::defaultFormat, defaultStringValue); |
| 338 |
|
| 339 |
#define NATURAL0VECTOR(integerVectorVariable, labelText, defaultFormat, defaultStringValue) \ |
| 340 |
NATURAL0VECTOR_VARIABLE (integerVectorVariable) \ |
| 341 |
NATURAL0VECTOR_FIELD (integerVectorVariable, labelText, defaultFormat, defaultStringValue) |
| 342 |
|
| 343 |
|
| 344 |
#define NATURAL1VECTOR_VARIABLE(integerVectorVariable) \ |
| 345 |
static constINTVEC integerVectorVariable; |
| 346 |
|
| 347 |
#define NATURAL1VECTOR_FIELD(integerVectorVariable, labelText, defaultFormat, defaultStringValue) \ |
| 348 |
UiForm_addNatural1Vector (cmd -> d_uiform.get(), & integerVectorVariable, nullptr, labelText, kUi_integerVectorFormat::defaultFormat, defaultStringValue); |
| 349 |
|
| 350 |
#define NATURAL1VECTOR(integerVectorVariable, labelText, defaultFormat, defaultStringValue) \ |
| 351 |
NATURAL1VECTOR_VARIABLE (integerVectorVariable) \ |
| 352 |
NATURAL1VECTOR_FIELD (integerVectorVariable, labelText, defaultFormat, defaultStringValue) |
| 353 |
|
| 354 |
|
| 355 |
#define CHOICE_VARIABLE(optionVariable) \ |
| 356 |
static int optionVariable; |
| 357 |
|
| 358 |
#define CHOICE_FIELD(optionVariable, labelText, defaultValue) \ |
| 359 |
UiForm_addChoice (cmd -> d_uiform.get(), & optionVariable, nullptr, nullptr, labelText, defaultValue, 1); |
| 360 |
|
| 361 |
#define CHOICE(optionVariable, labelText, defaultValue) \ |
| 362 |
CHOICE_VARIABLE (optionVariable) \ |
| 363 |
CHOICE_FIELD (optionVariable, labelText, defaultValue) |
| 364 |
|
| 365 |
|
| 366 |
#define CHOICESTR(stringVariable, labelText, defaultValue) \ |
| 367 |
static conststring32 stringVariable; \ |
| 368 |
UiForm_addChoice (cmd -> d_uiform.get(), nullptr, & stringVariable, nullptr, labelText, defaultValue, 1); |
| 369 |
|
| 370 |
|
| 371 |
#define OPTIONMENU_VARIABLE(optionVariable) \ |
| 372 |
static int optionVariable; |
| 373 |
|
| 374 |
#define OPTIONMENU_FIELD(optionVariable, labelText, defaultValue) \ |
| 375 |
UiForm_addOptionMenu (cmd -> d_uiform.get(), & optionVariable, nullptr, nullptr, labelText, defaultValue, 1); |
| 376 |
|
| 377 |
#define OPTIONMENU(optionVariable, labelText, defaultValue) \ |
| 378 |
OPTIONMENU_VARIABLE (optionVariable) \ |
| 379 |
OPTIONMENU_FIELD(optionVariable, labelText, defaultValue) |
| 380 |
|
| 381 |
|
| 382 |
#define OPTIONMENUSTR(stringVariable, labelText, defaultValue) \ |
| 383 |
static conststring32 stringVariable; \ |
| 384 |
UiForm_addOptionMenu (cmd -> d_uiform.get(), nullptr, & stringVariable, nullptr, labelText, defaultValue, 1); |
| 385 |
|
| 386 |
|
| 387 |
#define OPTION(labelText) \ |
| 388 |
UiForm_addOption (cmd -> d_uiform.get(), labelText); |
| 389 |
|
| 390 |
|
| 391 |
#define CHOICE_ENUM_VARIABLE(EnumeratedType, enumeratedVariable) \ |
| 392 |
static enum EnumeratedType enumeratedVariable; \ |
| 393 |
|
| 394 |
#define CHOICE_ENUM_FIELD(EnumeratedType, enumeratedVariable, labelText, defaultValue) \ |
| 395 |
{/* type checks */ \ |
| 396 |
[[maybe_unused]] enum EnumeratedType _compilerTypeCheckDummy = defaultValue; \ |
| 397 |
_compilerTypeCheckDummy = enumeratedVariable; \ |
| 398 |
} \ |
| 399 |
UiForm_addChoiceEnum (cmd -> d_uiform.get(), (int *) & enumeratedVariable, nullptr, nullptr, labelText, \ |
| 400 |
(int) defaultValue - (int) EnumeratedType::MIN + 1, (int) EnumeratedType::MIN, \ |
| 401 |
(enum_generic_getValue) EnumeratedType##_getValue \ |
| 402 |
); \ |
| 403 |
for (int _ienum = (int) EnumeratedType::MIN; _ienum <= (int) EnumeratedType::MAX; _ienum ++) \ |
| 404 |
UiForm_addOption (cmd -> d_uiform.get(), EnumeratedType##_getText ((enum EnumeratedType) _ienum)); \ |
| 405 |
|
| 406 |
#define CHOICE_ENUM(EnumeratedType, enumeratedVariable, labelText, defaultValue) \ |
| 407 |
CHOICE_ENUM_VARIABLE (EnumeratedType, enumeratedVariable) \ |
| 408 |
CHOICE_ENUM_FIELD (EnumeratedType, enumeratedVariable, labelText, defaultValue) |
| 409 |
|
| 410 |
|
| 411 |
#define OPTIONMENU_ENUM_VARIABLE(EnumeratedType, enumeratedVariable) \ |
| 412 |
static enum EnumeratedType enumeratedVariable; \ |
| 413 |
|
| 414 |
#define OPTIONMENU_ENUM_FIELD(EnumeratedType, enumeratedVariable, labelText, defaultValue) \ |
| 415 |
{/* type checks */ \ |
| 416 |
[[maybe_unused]] enum EnumeratedType _compilerTypeCheckDummy = defaultValue; \ |
| 417 |
_compilerTypeCheckDummy = enumeratedVariable; \ |
| 418 |
} \ |
| 419 |
UiForm_addOptionMenuEnum (cmd -> d_uiform.get(), (int *) & enumeratedVariable, nullptr, nullptr, labelText, \ |
| 420 |
(int) defaultValue - (int) EnumeratedType::MIN + 1, (int) EnumeratedType::MIN, \ |
| 421 |
(enum_generic_getValue) EnumeratedType##_getValue \ |
| 422 |
); \ |
| 423 |
for (int _ienum = (int) EnumeratedType::MIN; _ienum <= (int) EnumeratedType::MAX; _ienum ++) \ |
| 424 |
UiForm_addOption (cmd -> d_uiform.get(), EnumeratedType##_getText ((enum EnumeratedType) _ienum)); \ |
| 425 |
|
| 426 |
#define OPTIONMENU_ENUM(EnumeratedType, enumeratedVariable, labelText, defaultValue) \ |
| 427 |
OPTIONMENU_ENUM_VARIABLE (EnumeratedType, enumeratedVariable) \ |
| 428 |
OPTIONMENU_ENUM_FIELD (EnumeratedType, enumeratedVariable, labelText, defaultValue) |
| 429 |
|
| 430 |
|
| 431 |
/* |
| 432 |
LIST will throw if the supplied string is not in the list. |
| 433 |
*/ |
| 434 |
#define LIST(integerVariable, labelText, strings, defaultOptionNumber) \ |
| 435 |
static integer integerVariable; \ |
| 436 |
UiForm_addList (cmd -> d_uiform.get(), & integerVariable, nullptr, U"" #integerVariable, \ |
| 437 |
labelText, strings, defaultOptionNumber); |
| 438 |
|
| 439 |
/* |
| 440 |
LISTSTR will throw if the supplied string is not in the list. |
| 441 |
*/ |
| 442 |
#define LISTSTR(stringVariable, labelText, strings, defaultOptionNumber) \ |
| 443 |
static conststring32 stringVariable; \ |
| 444 |
UiForm_addList (cmd -> d_uiform.get(), nullptr, & stringVariable, U"" #stringVariable, \ |
| 445 |
labelText, strings, defaultOptionNumber); |
| 446 |
|
| 447 |
/* |
| 448 |
If the supplied string is not in the list, LISTNUMSTR will return 0 as well as the supplied string, for later handling. |
| 449 |
*/ |
| 450 |
#define LISTNUMSTR(integerVariable, stringVariable, labelText, strings, defaultOptionNumber) \ |
| 451 |
static integer integerVariable; \ |
| 452 |
static conststring32 stringVariable; \ |
| 453 |
UiForm_addList (cmd -> d_uiform.get(), & integerVariable, & stringVariable, U"" #stringVariable, \ |
| 454 |
labelText, strings, defaultOptionNumber); |
| 455 |
|
| 456 |
/* |
| 457 |
Seven optional functions to change the content of a field on the basis of the current |
| 458 |
editor setting rather than on the basis of the factory default. |
| 459 |
They are to be called between EDITOR_OK and EDITOR_DO. |
| 460 |
*/ |
| 461 |
|
| 462 |
#define SET_REAL(realVariable, realValue) \ |
| 463 |
UiForm_setReal (cmd -> d_uiform.get(), & realVariable, realValue); |
| 464 |
|
| 465 |
#define SET_INTEGER(integerVariable, integerValue) \ |
| 466 |
UiForm_setInteger (cmd -> d_uiform.get(), & integerVariable, integerValue); |
| 467 |
|
| 468 |
#define SET_INTEGER_AS_STRING(integerVariable, stringValue) \ |
| 469 |
UiForm_setIntegerAsString (cmd -> d_uiform.get(), & integerVariable, stringValue); |
| 470 |
|
| 471 |
#define SET_BOOLEAN(booleanVariable, booleanValue) \ |
| 472 |
UiForm_setBoolean (cmd -> d_uiform.get(), & booleanVariable, booleanValue); |
| 473 |
|
| 474 |
#define SET_OPTION(optionVariable, optionValue) \ |
| 475 |
UiForm_setOption (cmd -> d_uiform.get(), & optionVariable, optionValue); |
| 476 |
|
| 477 |
#define SET_STRING(stringVariable, stringValue) \ |
| 478 |
UiForm_setString (cmd -> d_uiform.get(), & stringVariable, stringValue); |
| 479 |
|
| 480 |
#define SET_ENUM(enumeratedVariable, EnumeratedType, enumeratedValue) \ |
| 481 |
enumeratedVariable = enumeratedValue /* type check */; \ |
| 482 |
UiForm_setOption (cmd -> d_uiform.get(), (int *) & enumeratedVariable, (int) enumeratedValue - (int) EnumeratedType::MIN + 1); |
| 483 |
|
| 484 |
#define SET_LIST(integerVariable, stringVariable, strings, defaultValue) \ |
| 485 |
UiForm_setList (cmd -> d_uiform.get(), & integerVariable, & stringVariable, strings, defaultValue); |
| 486 |
|
| 487 |
#define DIALOG cmd -> d_uiform |
| 488 |
|
| 489 |
#define EDITOR_FORM_SAVE(title, helpTitle) \ |
| 490 |
if (! cmd -> d_uiform) { \ |
| 491 |
cmd -> d_uiform = UiOutfile_createE (cmd, title, cmd -> itemTitle.get(), helpTitle); \ |
| 492 |
} if (! _args_ && ! _sendingForm_ && ! _sendingString_) { char32 defaultName [300]; defaultName [0] = U'\0'; |
| 493 |
#define EDITOR_DO_SAVE \ |
| 494 |
UiOutfile_do (cmd -> d_uiform.get(), defaultName); } else { MelderFile file; structMelderFile _file2 { }; \ |
| 495 |
if (_args_) { \ |
| 496 |
Melder_require (_narg_ == 1, \ |
| 497 |
U"Command requires exactly 1 argument, the name of the file to write, instead of the given ", _narg_, U" arguments."); \ |
| 498 |
Melder_require (_args_ [1]. which == Stackel_STRING, \ |
| 499 |
U"The file name argument should be a string, not ", _args_ [1]. whichText(), U"."); \ |
| 500 |
Melder_relativePathToFile (_args_ [1]. getString(), & _file2); \ |
| 501 |
file = & _file2; \ |
| 502 |
} else if (_sendingString_) { \ |
| 503 |
Melder_relativePathToFile (_sendingString_, & _file2); \ |
| 504 |
file = & _file2; \ |
| 505 |
} else { \ |
| 506 |
file = UiFile_getFile (cmd -> d_uiform.get()); \ |
| 507 |
} |
| 508 |
|
| 509 |
#define EDITOR_FORM_READ(title, helpTitle) \ |
| 510 |
if (! cmd -> d_uiform) { \ |
| 511 |
cmd -> d_uiform = UiInfile_createE (cmd, title, cmd -> itemTitle.get(), helpTitle); \ |
| 512 |
} if (! _args_ && ! _sendingForm_ && ! _sendingString_) { |
| 513 |
#define EDITOR_DO_READ \ |
| 514 |
UiInfile_do (cmd -> d_uiform.get()); } else { MelderFile file; structMelderFile _file2 { }; \ |
| 515 |
if (_args_) { \ |
| 516 |
Melder_require (_narg_ == 1, \ |
| 517 |
U"Command requires exactly 1 argument, the name of the file to read, instead of the given ", _narg_, U" arguments."); \ |
| 518 |
Melder_require (_args_ [1]. which == Stackel_STRING, \ |
| 519 |
U"The file name argument should be a string, not ", _args_ [1]. whichText(), U"."); \ |
| 520 |
Melder_relativePathToFile (_args_ [1]. getString(), & _file2); \ |
| 521 |
file = & _file2; \ |
| 522 |
} else if (_sendingString_) { \ |
| 523 |
Melder_relativePathToFile (_sendingString_, & _file2); \ |
| 524 |
file = & _file2; \ |
| 525 |
} else { \ |
| 526 |
file = UiFile_getFile (cmd -> d_uiform.get()); \ |
| 527 |
} |
| 528 |
|
| 529 |
#define VOID_EDITOR |
| 530 |
#define VOID_EDITOR_END |
| 531 |
|
| 532 |
#define DATA_BEGIN__ \ |
| 533 |
Melder_assert (my data()); |
| 534 |
|
| 535 |
#define PLAY_DATA \ |
| 536 |
DATA_BEGIN__ |
| 537 |
#define PLAY_DATA_END |
| 538 |
|
| 539 |
#define INFO_EDITOR |
| 540 |
#define INFO_EDITOR_END \ |
| 541 |
if (optionalInterpreter) \ |
| 542 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::STRING_; |
| 543 |
|
| 544 |
#define INFO_DATA \ |
| 545 |
DATA_BEGIN__ |
| 546 |
#define INFO_DATA_END \ |
| 547 |
if (optionalInterpreter) \ |
| 548 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::STRING_; |
| 549 |
|
| 550 |
#define FOR_REAL__(...) \ |
| 551 |
if (optionalInterpreter) \ |
| 552 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::REAL_; \ |
| 553 |
Melder_information (result, __VA_ARGS__); |
| 554 |
|
| 555 |
#define FOR_INTEGER__(...) \ |
| 556 |
if (optionalInterpreter) \ |
| 557 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::INTEGER_; \ |
| 558 |
Melder_information (double (result), __VA_ARGS__); |
| 559 |
|
| 560 |
#define FOR_BOOLEAN__(...) \ |
| 561 |
if (optionalInterpreter) \ |
| 562 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::BOOLEAN_; \ |
| 563 |
Melder_information (double (result), __VA_ARGS__); |
| 564 |
|
| 565 |
#define FOR_COMPLEX__(...) \ |
| 566 |
if (optionalInterpreter) \ |
| 567 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::STRING_; /* TODO: make true complex types in script */ \ |
| 568 |
Melder_information (result, __VA_ARGS__); |
| 569 |
|
| 570 |
#define FOR_STRING__ \ |
| 571 |
if (optionalInterpreter) \ |
| 572 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::STRING_; \ |
| 573 |
Melder_information (result); |
| 574 |
|
| 575 |
#define QUERY_EDITOR_FOR_REAL |
| 576 |
#define QUERY_EDITOR_FOR_REAL_END(...) \ |
| 577 |
FOR_REAL__ (__VA_ARGS__) |
| 578 |
|
| 579 |
#define QUERY_EDITOR_FOR_INTEGER |
| 580 |
#define QUERY_EDITOR_FOR_INTEGER_END(...) \ |
| 581 |
FOR_INTEGER__ (__VA_ARGS__) |
| 582 |
|
| 583 |
#define QUERY_EDITOR_FOR_BOOLEAN |
| 584 |
#define QUERY_EDITOR_FOR_BOOLEAN_END(...) \ |
| 585 |
FOR_BOOLEAN__ (__VA_ARGS__) |
| 586 |
|
| 587 |
#define QUERY_EDITOR_FOR_STRING |
| 588 |
#define QUERY_EDITOR_FOR_STRING_END \ |
| 589 |
FOR_STRING__ |
| 590 |
|
| 591 |
#define QUERY_DATA_FOR_REAL \ |
| 592 |
DATA_BEGIN__ |
| 593 |
#define QUERY_DATA_FOR_REAL_END(...) \ |
| 594 |
FOR_REAL__ (__VA_ARGS__) |
| 595 |
|
| 596 |
#define QUERY_DATA_FOR_INTEGER \ |
| 597 |
DATA_BEGIN__ |
| 598 |
#define QUERY_DATA_FOR_INTEGER_END(...) \ |
| 599 |
FOR_INTEGER__ (__VA_ARGS__) |
| 600 |
|
| 601 |
#define QUERY_DATA_FOR_BOOLEAN \ |
| 602 |
DATA_BEGIN__ |
| 603 |
#define QUERY_DATA_FOR_BOOLEAN_END(...) \ |
| 604 |
FOR_BOOLEAN__ (__VA_ARGS__) |
| 605 |
|
| 606 |
#define QUERY_DATA_FOR_STRING \ |
| 607 |
DATA_BEGIN__ |
| 608 |
#define QUERY_DATA_FOR_STRING_END \ |
| 609 |
FOR_STRING__ |
| 610 |
|
| 611 |
#define MODIFY_DATA(undoTitle) \ |
| 612 |
Editor_save (my boss(), undoTitle); |
| 613 |
#define MODIFY_DATA_END \ |
| 614 |
Editor_broadcastDataChanged (my boss()); |
| 615 |
|
| 616 |
#define CONVERT_DATA_TO_ONE \ |
| 617 |
DATA_BEGIN__ |
| 618 |
#define CONVERT_DATA_TO_ONE_END(...) \ |
| 619 |
if (optionalInterpreter) \ |
| 620 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::OBJECT_; \ |
| 621 |
Thing_setName (result.get(), __VA_ARGS__); \ |
| 622 |
Editor_broadcastPublication (my boss(), result.move()); |
| 623 |
|
| 624 |
#define CREATE_ONE |
| 625 |
#define CREATE_ONE_END(...) \ |
| 626 |
if (optionalInterpreter) \ |
| 627 |
optionalInterpreter -> returnType = kInterpreter_ReturnType::OBJECT_; \ |
| 628 |
Thing_setName (result.get(), __VA_ARGS__); \ |
| 629 |
Editor_broadcastPublication (my boss(), result.move()); |
| 630 |
|
| 631 |
#define HELP(title) \ |
| 632 |
Melder_help (title); |
| 633 |
|
| 634 |
/* End of file EditorM.h */ |
| 635 |
#endif |