static void print (void *void_me, Graphics graphics) { iam (Manual); ManPages manPages = (ManPages) my data; long numberOfPages = manPages -> pages.size, savePage = my path; my ps = graphics; Graphics_setDollarSignIsCode (my ps, true); Graphics_setAtSignIsLink (my ps, true); my printing = true; HyperPage_initSheetOfPaper ((HyperPage) me); for (long ipage = 1; ipage <= numberOfPages; ipage ++) { ManPage page = manPages -> pages.at [ipage]; if (my printPagesStartingWith == nullptr || Melder_stringMatchesCriterion (page -> title, kMelder_string_STARTS_WITH, my printPagesStartingWith)) { ManPage_Paragraph par; my path = ipage; my paragraphs = page -> paragraphs; my numberOfParagraphs = 0; par = my paragraphs; while ((par ++) -> type) my numberOfParagraphs ++; Melder_free (my currentPageTitle); my currentPageTitle = Melder_dup_f (page -> title); my v_goToPage_i (ipage); my v_draw (); my v_goToPage_i (savePage); } } my printing = false; my printPagesStartingWith = nullptr; }
void Thing_setName (Thing me, const char32 *name /* cattable */) { /* * First check without change. */ autostring32 newName = Melder_dup_f (name); // BUG: that's no checking /* * Then change without error. */ Melder_free (my name); my name = newName.transfer(); my v_nameChanged (); }
autoStrings FileInMemorySet_to_Strings_id (FileInMemorySet me) { try { autoStrings thee = Thing_new (Strings); thy strings = NUMvector <char32 *> (1, my size); thy numberOfStrings = 0; for (long ifile = 1; ifile <= my size; ifile ++) { FileInMemory fim = my at [ifile]; thy strings [ifile] = Melder_dup_f (fim -> d_id); thy numberOfStrings ++; } return thee; } catch (MelderError) { Melder_throw (U"No Strings created from FilesinMemory."); } }
static void update (CategoriesEditor me, long from, long to, const long *select, long nSelect) { long size = ((Categories) my data) -> size; if (size == 0) { autoSimpleString str = SimpleString_create (CategoriesEditor_EMPTYLABEL); Collection_addItem_move ((Categories) my data, str.move()); update (me, 0, 0, nullptr, 0); return; } if (from == 0 && from == to) { from = 1; to = size; } if (from < 1 || from > size) { from = size; } if (to < 1 || to > size) { to = size; } if (from > to) { long ti = from; from = to; to = ti; } // Begin optimization: add the items from a table instead of separately. try { autostring32vector table (from, to); long itemCount = GuiList_getNumberOfItems (my list); for (long i = from; i <= to; i++) { char wcindex[20]; snprintf (wcindex,20, "%5ld ", i); table[i] = Melder_dup_f (Melder_cat (Melder_peek8to32 (wcindex), OrderedOfString_itemAtIndex_c ((OrderedOfString) my data, i))); } if (itemCount > size) { // some items have been removed from Categories? for (long j = itemCount; j > size; j --) { GuiList_deleteItem (my list, j); } itemCount = size; } if (to > itemCount) { for (long j = 1; j <= to - itemCount; j ++) { GuiList_insertItem (my list, table [itemCount + j], 0); } } if (from <= itemCount) { long n = (to < itemCount ? to : itemCount); for (long j = from; j <= n; j++) { GuiList_replaceItem (my list, table[j], j); } } } catch (MelderError) { throw; } // End of optimization // HIGHLIGHT GuiList_deselectAllItems (my list); if (size == 1) { /* the only item is always selected */ const char32 *catg = OrderedOfString_itemAtIndex_c ((OrderedOfString) my data, 1); GuiList_selectItem (my list, 1); updateWidgets (me); // instead of "notify". BUG? GuiText_setString (my text, catg); } else if (nSelect > 0) { // Select but postpone highlighting for (long i = 1; i <= nSelect; i++) { GuiList_selectItem (my list, select[i] > size ? size : select[i]); } } // VIEWPORT { long top = GuiList_getTopPosition (my list), bottom = GuiList_getBottomPosition (my list); long visible = bottom - top + 1; if (nSelect == 0) { top = my position - visible / 2; } else if (select[nSelect] < top) { // selection above visible area top = select[1]; } else if (select[1] > bottom) { // selection below visible area top = select[nSelect] - visible + 1; } else { long deltaTopPos = -1, nUpdate = to - from + 1; if ( (from == select[1] && to == select[nSelect]) || // Replace (nUpdate > 2 && nSelect == 1) /* Inserts */) { deltaTopPos = 0; } else if (nUpdate == nSelect + 1 && select[1] == from + 1) { // down deltaTopPos = 1; } top += deltaTopPos; } if (top + visible > size) { top = size - visible + 1; } if (top < 1) { top = 1; } GuiList_setTopPosition (my list, top); } }
char32 *Melder_firstToken (const char32 *string) { Melder_free (theMelderToken); theMelderToken = Melder_dup_f (string); return Melder_tok (theMelderToken, U" \t\n\r"); }
static void gui_drawingarea_cb_expose (I, GuiDrawingAreaExposeEvent event) { iam (RunnerMFC); Melder_assert (event -> widget == my d_drawingArea); if (my graphics == NULL) return; // Could be the case in the very beginning. ExperimentMFC experiment = (ExperimentMFC) my data; long iresponse; if (my data == NULL) return; Graphics_setGrey (my graphics, 0.8); Graphics_fillRectangle (my graphics, 0, 1, 0, 1); Graphics_setGrey (my graphics, 0.0); if (experiment -> trial == 0) { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> startText); } else if (experiment -> pausing) { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> pauseText); if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } else if (experiment -> trial <= experiment -> numberOfTrials) { const char32 *visibleText = experiment -> stimulus [experiment -> stimuli [experiment -> trial]]. visibleText; autostring32 visibleText_dup = Melder_dup_f (visibleText ? visibleText : U""); char32 *visibleText_p = visibleText_dup.peek(); Graphics_setFont (my graphics, kGraphics_font_TIMES); Graphics_setFontSize (my graphics, 10); Graphics_setColour (my graphics, Graphics_BLACK); Graphics_setTextAlignment (my graphics, Graphics_LEFT, Graphics_TOP); Graphics_text (my graphics, 0, 1, experiment -> trial, U" / ", experiment -> numberOfTrials); Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_TOP); Graphics_setFontSize (my graphics, 24); /* * The run text. */ if (visibleText_p [0] != U'\0') { char32 *visibleText_q = str32chr (visibleText_p, U'|'); if (visibleText_q) *visibleText_q = '\0'; Graphics_text (my graphics, 0.5, 1.0, visibleText_p [0] != '\0' ? visibleText_p : experiment -> runText); if (visibleText_q) visibleText_p = visibleText_q + 1; else visibleText_p += str32len (visibleText_p); } else { Graphics_text (my graphics, 0.5, 1.0, experiment -> runText); } Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); for (iresponse = 1; iresponse <= experiment -> numberOfDifferentResponses; iresponse ++) { ResponseMFC response = & experiment -> response [iresponse]; char32 *textToDraw = response -> label; // can be overridden if (visibleText_p [0] != U'\0') { char32 *visibleText_q = str32chr (visibleText_p, U'|'); if (visibleText_q) *visibleText_q = U'\0'; textToDraw = visibleText_p; // override if (visibleText_q) visibleText_p = visibleText_q + 1; else visibleText_p += str32len (visibleText_p); } if (str32nequ (textToDraw, U"\\FI", 3)) { structMelderFile file = { 0 }; MelderDir_relativePathToFile (& experiment -> rootDirectory, textToDraw + 3, & file); Graphics_imageFromFile (my graphics, Melder_fileToPath (& file), response -> left, response -> right, response -> bottom, response -> top); } else { Graphics_setColour (my graphics, response -> name [0] == U'\0' ? Graphics_SILVER : experiment -> responses [experiment -> trial] == iresponse ? Graphics_RED : experiment -> ok_right > experiment -> ok_left || experiment -> responses [experiment -> trial] == 0 ? Graphics_YELLOW : Graphics_SILVER); Graphics_setLineWidth (my graphics, 3.0); Graphics_fillRectangle (my graphics, response -> left, response -> right, response -> bottom, response -> top); Graphics_setColour (my graphics, Graphics_MAROON); Graphics_rectangle (my graphics, response -> left, response -> right, response -> bottom, response -> top); Graphics_setFontSize (my graphics, response -> fontSize ? response -> fontSize : 24); Graphics_text (my graphics, 0.5 * (response -> left + response -> right), 0.5 * (response -> bottom + response -> top), textToDraw); } Graphics_setFontSize (my graphics, 24); } for (iresponse = 1; iresponse <= experiment -> numberOfGoodnessCategories; iresponse ++) { GoodnessMFC goodness = & experiment -> goodness [iresponse]; Graphics_setColour (my graphics, experiment -> responses [experiment -> trial] == 0 ? Graphics_SILVER : experiment -> goodnesses [experiment -> trial] == iresponse ? Graphics_RED : Graphics_YELLOW); Graphics_setLineWidth (my graphics, 3.0); Graphics_fillRectangle (my graphics, goodness -> left, goodness -> right, goodness -> bottom, goodness -> top); Graphics_setColour (my graphics, Graphics_MAROON); Graphics_rectangle (my graphics, goodness -> left, goodness -> right, goodness -> bottom, goodness -> top); Graphics_text (my graphics, 0.5 * (goodness -> left + goodness -> right), 0.5 * (goodness -> bottom + goodness -> top), goodness -> label); } if (experiment -> replay_right > experiment -> replay_left && my numberOfReplays < experiment -> maximumNumberOfReplays) { drawControlButton (me, experiment -> replay_left, experiment -> replay_right, experiment -> replay_bottom, experiment -> replay_top, experiment -> replay_label); } if (experiment -> ok_right > experiment -> ok_left && experiment -> responses [experiment -> trial] != 0 && (experiment -> numberOfGoodnessCategories == 0 || experiment -> goodnesses [experiment -> trial] != 0)) { drawControlButton (me, experiment -> ok_left, experiment -> ok_right, experiment -> ok_bottom, experiment -> ok_top, experiment -> ok_label); } if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } else { Graphics_setTextAlignment (my graphics, Graphics_CENTRE, Graphics_HALF); Graphics_setFontSize (my graphics, 24); Graphics_text (my graphics, 0.5, 0.5, experiment -> endText); if (experiment -> oops_right > experiment -> oops_left && experiment -> trial > 1) { drawControlButton (me, experiment -> oops_left, experiment -> oops_right, experiment -> oops_bottom, experiment -> oops_top, experiment -> oops_label); } } }
GuiText_setSelection (my textWidget, left, left + str32len (theReplaceString)); GuiText_scrollToSelection (my textWidget); #ifdef _WIN32 GuiThing_show (my d_windowForm); #endif } static void menu_cb_find (TextEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"Find", 0) LABEL (U"", U"Find:") TEXTFIELD (U"findString", U"") EDITOR_OK if (theFindString) SET_STRING (U"findString", theFindString); EDITOR_DO Melder_free (theFindString); theFindString = Melder_dup_f (GET_STRING (U"findString")); do_find (me); EDITOR_END } static void menu_cb_findAgain (TextEditor me, EDITOR_ARGS_DIRECT) { do_find (me); } static void menu_cb_replace (TextEditor me, EDITOR_ARGS_FORM) { EDITOR_FORM (U"Find", 0) LABEL (U"", U"This is a \"slow\" find-and-replace method;") LABEL (U"", U"if the selected text is identical to the Find string,") LABEL (U"", U"the selected text will be replaced by the Replace string;") LABEL (U"", U"otherwise, the next occurrence of the Find string will be selected.") LABEL (U"", U"So you typically need two clicks on Apply to get a text replaced.")
void praat_addAction4 (ClassInfo class1, int n1, ClassInfo class2, int n2, ClassInfo class3, int n3, ClassInfo class4, int n4, const char32 *title, const char32 *after, unsigned long flags, UiCallback callback) { try { int depth = flags, key = 0; bool unhidable = false, hidden = false, attractive = false; unsigned long motifFlags = 0; if (flags > 7) { depth = ((flags & praat_DEPTH_7) >> 16); unhidable = (flags & praat_UNHIDABLE) != 0; hidden = (flags & praat_HIDDEN) != 0 && ! unhidable; key = flags & 0x000000FF; motifFlags = key ? flags & (0x002000FF | GuiMenu_BUTTON_STATE_MASK) : flags & GuiMenu_BUTTON_STATE_MASK; attractive = (motifFlags & praat_ATTRACTIVE) != 0; } fixSelectionSpecification (& class1, & n1, & class2, & n2, & class3, & n3); if (callback && ! title) Melder_throw (U"An action command with callback has no title. Classes: ", class1 ? class1 -> className : U"", U" ", class2 ? class2 -> className : U"", U" ", class3 ? class3 -> className : U"", U" ", class4 ? class4 -> className : U"", U"."); if (! class1) Melder_throw (U"The action command \"", title, U"\" has no first class."); /* * Determine the position of the new command. */ long position; if (after) { // search for existing command with same selection long found = lookUpMatchingAction (class1, class2, class3, class4, after); if (found == 0) Melder_throw (U"The action command \"", title, U"\" cannot be put after \"", after, U"\",\n" U"because the latter command does not exist."); position = found + 1; // after 'after' } else { position = theActions -> size + 1; // at end } /* * Make new command. */ autoPraat_Command action = Thing_new (Praat_Command); action -> class1 = class1; action -> n1 = n1; action -> class2 = class2; action -> n2 = n2; action -> class3 = class3; action -> n3 = n3; action -> class4 = class4; action -> n4 = n4; action -> title = Melder_dup_f (title); action -> depth = depth; action -> callback = callback; // null for a separator action -> button = nullptr; action -> script = nullptr; action -> hidden = hidden; action -> unhidable = unhidable; action -> attractive = attractive; /* * Insert new command. */ Ordered_addItemAtPosition_move (theActions, action.move(), position); } catch (MelderError) {