123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- #include "UiPause.h"
- #include "praatP.h"
- static autoUiForm thePauseForm;
- static UiField thePauseFormRadio = nullptr;
- static int thePauseForm_clicked = 0;
- static int theCancelContinueButton = 0;
- static int theEventLoopDepth = 0;
- static void thePauseFormOkCallback (UiForm , integer , Stackel ,
- conststring32 , Interpreter ,
- conststring32 , bool , void *closure) {
-
-
- thePauseForm_clicked = UiForm_getClickedContinueButton (thePauseForm.get());
- if (thePauseForm_clicked != theCancelContinueButton)
- UiForm_Interpreter_addVariables (thePauseForm.get(), (Interpreter) closure);
- }
- static void thePauseFormCancelCallback (UiForm , void * ) {
- if (theCancelContinueButton != 0) {
- thePauseForm_clicked = theCancelContinueButton;
- } else {
- thePauseForm_clicked = -1;
- }
- }
- void UiPause_begin (GuiWindow topShell, conststring32 title, Interpreter interpreter) {
- if (theEventLoopDepth > 0)
- Melder_throw (U"Praat cannot have more than one pause form at a time.");
- thePauseForm = UiForm_create (topShell, Melder_cat (U"Pause: ", title),
- thePauseFormOkCallback, interpreter,
- nullptr, nullptr);
- }
- void UiPause_real (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"real\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addReal (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_positive (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"positive\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addPositive (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_integer (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"integer\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addInteger (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_natural (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"natural\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addNatural (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_word (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"word\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addWord (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_sentence (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"sentence\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addSentence (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_text (conststring32 label, conststring32 defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"text\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addText (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_boolean (conststring32 label, bool defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"boolean\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addBoolean (thePauseForm.get(), nullptr, nullptr, label, defaultValue);
- }
- void UiPause_choice (conststring32 label, int defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"choice\" has to be between a \"beginPause\" and an \"endPause\".");
- thePauseFormRadio = UiForm_addRadio (thePauseForm.get(), nullptr, nullptr, nullptr, label, defaultValue, 1);
- }
- void UiPause_optionMenu (conststring32 label, int defaultValue) {
- if (! thePauseForm)
- Melder_throw (U"The function \"optionMenu\" has to be between a \"beginPause\" and an \"endPause\".");
- thePauseFormRadio = UiForm_addOptionMenu (thePauseForm.get(), nullptr, nullptr, nullptr, label, defaultValue, 1);
- }
- void UiPause_option (conststring32 label) {
- if (! thePauseForm)
- Melder_throw (U"The function \"option\" has to be between a \"beginPause\" and an \"endPause\".");
- if (! thePauseFormRadio) {
- thePauseForm. reset();
- Melder_throw (U"Found the function \"option\" without a preceding \"choice\" or \"optionMenu\".");
- }
- UiOptionMenu_addButton (thePauseFormRadio, label);
- }
- void UiPause_comment (conststring32 label) {
- if (! thePauseForm)
- Melder_throw (U"The function \"comment\" has to be between a \"beginPause\" and an \"endPause\".");
- UiForm_addLabel (thePauseForm.get(), nullptr, label);
- }
- int UiPause_end (int numberOfContinueButtons, int defaultContinueButton, int cancelContinueButton,
- conststring32 continueText1, conststring32 continueText2, conststring32 continueText3,
- conststring32 continueText4, conststring32 continueText5, conststring32 continueText6,
- conststring32 continueText7, conststring32 continueText8, conststring32 continueText9,
- conststring32 continueText10, Interpreter interpreter)
- {
- if (! thePauseForm)
- Melder_throw (U"Found the function \"endPause\" without a preceding \"beginPause\".");
- UiForm_setPauseForm (thePauseForm.get(), numberOfContinueButtons, defaultContinueButton, cancelContinueButton,
- continueText1, continueText2, continueText3, continueText4, continueText5,
- continueText6, continueText7, continueText8, continueText9, continueText10,
- thePauseFormCancelCallback);
- theCancelContinueButton = cancelContinueButton;
- UiForm_finish (thePauseForm.get());
- bool wasBackgrounding = Melder_backgrounding;
-
- if (wasBackgrounding) praat_foreground ();
-
- UiForm_destroyWhenUnmanaged (thePauseForm.get());
- UiForm_do (thePauseForm.get(), false);
-
- {
- autoMelderSaveDefaultDir saveDir;
- thePauseForm_clicked = 0;
- Melder_assert (theEventLoopDepth == 0);
- theEventLoopDepth ++;
- try {
- #if gtk
- do {
- gtk_main_iteration ();
- } while (! thePauseForm_clicked);
- #elif cocoa
- do {
- NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-
- NSEvent *nsEvent = [NSApp
- nextEventMatchingMask: NSAnyEventMask
- untilDate: [NSDate distantFuture]
- inMode: NSDefaultRunLoopMode
- dequeue: YES
- ];
- Melder_assert (nsEvent);
- [NSApp sendEvent: nsEvent];
- [NSApp updateWindows];
- [pool release];
- } while (! thePauseForm_clicked);
- #elif motif
- do {
- XEvent event;
- GuiNextEvent (& event);
- XtDispatchEvent (& event);
- } while (! thePauseForm_clicked);
- #endif
- } catch (MelderError) {
- Melder_flushError (U"An error made it to the outer level in a pause window; should not occur! Please write to paul.boersma@uva.nl");
- }
- theEventLoopDepth --;
- }
- if (wasBackgrounding) praat_background ();
-
- thePauseForm. releaseToUser();
- thePauseFormRadio = nullptr;
- if (thePauseForm_clicked == -1) {
- Interpreter_stop (interpreter);
- Melder_throw (U"You interrupted the script.");
-
-
- } else {
-
- }
- return thePauseForm_clicked;
- }
|