1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/* UiPause.cpp
*
* Copyright (C) 2009-2011 Paul Boersma
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* pb 2009/01/20 created
* pb 2010/07/13 GTK
* pb 2010/07/26 removed UiFile_hide
* pb 2011/02/01 cancelContinueButton
* pb 2011/05/15 C++
* pb 2011/07/12 C++
*/
#include "UiPause.h"
#include "praatP.h"
static UiForm thePauseForm = NULL;
static Any thePauseFormRadio = NULL;
static int thePauseForm_clicked = 0;
static int theCancelContinueButton = 0;
static int theEventLoopDepth = 0;
static void thePauseFormOkCallback (UiForm sendingForm, const wchar *sendingString, Interpreter interpreter, const wchar *invokingButtonTitle, bool modified, void *closure) {
(void) sendingForm;
(void) sendingString;
(void) interpreter;
(void) invokingButtonTitle;
(void) modified;
/* BUG: should also restore praatP. editor. */
/*
* Get the data from the pause form.
*/
thePauseForm_clicked = UiForm_getClickedContinueButton (thePauseForm);
if (thePauseForm_clicked != theCancelContinueButton)
UiForm_Interpreter_addVariables (thePauseForm, (Interpreter) closure); // 'closure', not 'interpreter' or 'theInterpreter'!
}
static void thePauseFormCancelCallback (Any dia, void *closure) {
(void) dia;
(void) closure;
if (theCancelContinueButton != 0) {
thePauseForm_clicked = theCancelContinueButton;
} else {
thePauseForm_clicked = -1; // STOP button
}
}
void UiPause_begin (GuiObject topShell, const wchar *title, Interpreter interpreter) {
if (theEventLoopDepth > 0)
Melder_throw ("Praat cannot have more than one pause form at a time.");
forget (thePauseForm); // in case an earlier build-up of another pause window was interrupted
thePauseForm = UiForm_create (topShell, Melder_wcscat (L"Pause: ", title),
thePauseFormOkCallback, interpreter, // pass interpreter as closure!
NULL, NULL);
}
void UiPause_real (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"real\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addReal (thePauseForm, label, defaultValue);
}
void UiPause_positive (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"positive\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addPositive (thePauseForm, label, defaultValue);
}
void UiPause_integer (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"integer\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addInteger (thePauseForm, label, defaultValue);
}
void UiPause_natural (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"natural\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addNatural (thePauseForm, label, defaultValue);
}
void UiPause_word (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"word\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addWord (thePauseForm, label, defaultValue);
}
void UiPause_sentence (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"sentence\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addSentence (thePauseForm, label, defaultValue);
}
void UiPause_text (const wchar *label, const wchar *defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"text\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addText (thePauseForm, label, defaultValue);
}
void UiPause_boolean (const wchar *label, int defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"boolean\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addBoolean (thePauseForm, label, defaultValue);
}
void UiPause_choice (const wchar *label, int defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"choice\" has to be between a \"beginPause\" and an \"endPause\".");
thePauseFormRadio = UiForm_addRadio (thePauseForm, label, defaultValue);
}
void UiPause_optionMenu (const wchar *label, int defaultValue) {
if (thePauseForm == NULL)
Melder_throw ("The function \"optionMenu\" has to be between a \"beginPause\" and an \"endPause\".");
thePauseFormRadio = UiForm_addOptionMenu (thePauseForm, label, defaultValue);
}
void UiPause_option (const wchar *label) {
if (thePauseForm == NULL)
Melder_throw ("The function \"option\" has to be between a \"beginPause\" and an \"endPause\".");
if (thePauseFormRadio == NULL) {
forget (thePauseForm);
Melder_throw ("Found the function \"option\" without a preceding \"choice\" or \"optionMenu\".");
}
UiOptionMenu_addButton (thePauseFormRadio, label);
}
void UiPause_comment (const wchar *label) {
if (thePauseForm == NULL)
Melder_throw ("The function \"comment\" has to be between a \"beginPause\" and an \"endPause\".");
UiForm_addLabel (thePauseForm, L"", label);
}
int UiPause_end (int numberOfContinueButtons, int defaultContinueButton, int cancelContinueButton,
const wchar *continueText1, const wchar *continueText2, const wchar *continueText3,
const wchar *continueText4, const wchar *continueText5, const wchar *continueText6,
const wchar *continueText7, const wchar *continueText8, const wchar *continueText9,
const wchar *continueText10, Interpreter interpreter)
{
if (thePauseForm == NULL)
Melder_throw ("Found the function \"endPause\" without a preceding \"beginPause\".");
UiForm_setPauseForm (thePauseForm, numberOfContinueButtons, defaultContinueButton, cancelContinueButton,
continueText1, continueText2, continueText3, continueText4, continueText5,
continueText6, continueText7, continueText8, continueText9, continueText10,
thePauseFormCancelCallback);
theCancelContinueButton = cancelContinueButton;
UiForm_finish (thePauseForm); therror
bool wasBackgrounding = Melder_backgrounding;
//if (theCurrentPraatApplication -> batch) goto end;
if (wasBackgrounding) praat_foreground ();
/*
* Put the pause form on the screen.
*/
UiForm_destroyWhenUnmanaged (thePauseForm);
UiForm_do (thePauseForm, false);
/*
* Wait for the user to click Stop or Continue.
*/
#ifndef CONSOLE_APPLICATION
{ // scope
autoMelderSaveDefaultDir saveDir;
thePauseForm_clicked = 0;
Melder_assert (theEventLoopDepth == 0);
theEventLoopDepth ++;
try {
#if gtk
do {
gtk_main_iteration ();
} while (! thePauseForm_clicked);
#else
do {
XEvent event;
GuiNextEvent (& event);
XtDispatchEvent (& event);
} while (! thePauseForm_clicked);
#endif
} catch (MelderError) {
Melder_flushError ("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 ();
/* BUG: should also restore praatP. editor. */
thePauseForm = NULL; // undangle
thePauseFormRadio = NULL; // undangle
if (thePauseForm_clicked == -1) {
Interpreter_stop (interpreter);
Melder_throw ("You interrupted the script.");
//Melder_flushError (NULL);
//Melder_clearError ();
} else {
//Melder_casual ("Clicked %d", thePauseForm_clicked);
}
#endif
return thePauseForm_clicked;
}
/* End of file UiPause.cpp */
|