static void gui_drawingarea_cb_click (ArtwordEditor me, GuiDrawingArea_ClickEvent event) { if (! my graphics) return; Artword artword = (Artword) my data; Graphics_setWindow (my graphics.get(), 0, artword -> totalTime, -1.0, 1.0); Graphics_setInner (my graphics.get()); double xWC, yWC; Graphics_DCtoWC (my graphics.get(), event -> x, event -> y, & xWC, & yWC); Graphics_unsetInner (my graphics.get()); GuiText_setString (my time, Melder_fixed (xWC, 6)); GuiText_setString (my value, Melder_fixed (yWC, 6)); }
static void gui_list_cb_doubleClick (GuiObject widget, void *void_me, long item) { (void) widget; iam (StringsEditor); Strings strings = (Strings) my data; if (item <= strings -> numberOfStrings) GuiText_setString (my text, strings -> strings [item]); }
void StringsEditor::gui_list_cb_doubleClick (GuiObject widget, void *void_me, long item) { (void) widget; StringsEditor *stringsEditor = (StringsEditor *)void_me; Strings strings = (structStrings*)stringsEditor->_data; if (item <= strings -> numberOfStrings) GuiText_setString (stringsEditor->_text, strings -> strings [item]); }
static void menu_cb_expandIncludeFiles (ScriptEditor me, EDITOR_ARGS_DIRECT) { structMelderFile file = { 0 }; autostring32 text = GuiText_getString (my textWidget); if (my name [0]) { Melder_pathToFile (my name, & file); MelderFile_setDefaultDir (& file); } Melder_includeIncludeFiles (& text); GuiText_setString (my textWidget, text.peek()); }
static void gui_list_cb_doubleClick (CategoriesEditor me, GuiList_DoubleClickEvent event) { Melder_assert (event -> list == my list); // `my position` should just have been updated by the selectionChanged callback. long posCount; autoNUMvector<long> posList (GuiList_getSelectedPositions (my list, & posCount), 1); if (posCount == 1 // often or even usually true when double-clicking? && posList [1] == my position) // should be true, but we don't crash if it's false { const char32 *catg = OrderedOfString_itemAtIndex_c ((OrderedOfString) my data, my position); if (catg) { // should be non-null, but we don't crash if not GuiText_setString (my text, catg); } } }
// origin is at top left. void structCategoriesEditor :: v_createChildren () { constexpr int menuBarOffset { 40 }; constexpr int button_width { 130 }, button_height { menuBarOffset }, list_width { 260 }, list_height { 420 }; constexpr int delta_x { 15 }, delta_y { menuBarOffset / 2 }, text_button_height { button_height / 2 }; int left, right, top, bottom, buttons_left, buttons_top, list_bottom; left = 5; right = left + button_width; top = 3 + menuBarOffset; bottom = top + text_button_height; GuiLabel_createShown (d_windowForm, left, right, top, bottom, U"Positions:", 0); left = right + delta_x ; right = left + button_width; GuiLabel_createShown (d_windowForm, left, right, top, bottom, U"Values:", 0); left = 0; right = left + list_width; buttons_top = (top = bottom + delta_y); list_bottom = bottom = top + list_height; list = GuiList_create (d_windowForm, left, right, top, bottom, true, 0); GuiList_setSelectionChangedCallback (list, gui_list_cb_selectionChanged, this); GuiList_setDoubleClickCallback (list, gui_list_cb_doubleClick, this); GuiList_setScrollCallback (list, gui_list_cb_scroll, this); GuiThing_show (list); buttons_left = left = right + 2 * delta_x; right = left + button_width; bottom = top + button_height; GuiLabel_createShown (d_windowForm, left, right, top, bottom, U"Value:", 0); left = right + delta_x; right = left + button_width; text = GuiText_createShown (d_windowForm, left, right, top, bottom, 0); GuiText_setString (text, CategoriesEditor_EMPTYLABEL); left = buttons_left; right = left + button_width; top = bottom + delta_y; bottom = top + button_height; insert = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Insert", gui_button_cb_insert, this, GuiButton_DEFAULT); left = right + delta_x; right = left + button_width; replace = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Replace", gui_button_cb_replace, this, 0); left = buttons_left; right = left + int (1.5 * button_width); top = bottom + delta_y; bottom = top + button_height; insertAtEnd = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Insert at end", gui_button_cb_insertAtEnd, this, 0); top = bottom + delta_y; bottom = top + button_height; undo = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Undo", gui_button_cb_undo, this, 0); top = bottom + delta_y; bottom = top + button_height; redo = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Redo", gui_button_cb_redo, this, 0); top = bottom + delta_y; bottom = top + button_height; remove = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Remove", gui_button_cb_remove, this, 0); top = bottom + delta_y; bottom = top + button_height; moveUp = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Move selection up", gui_button_cb_moveUp, this, 0); top = bottom + delta_y; bottom = top + button_height; moveDown = GuiButton_createShown (d_windowForm, left, right, top, bottom, U"Move selection down", gui_button_cb_moveDown, this, 0); top = list_bottom + delta_y; bottom = top + button_height; left = 5; right = left + 200; outOfView = GuiLabel_createShown (d_windowForm, left, right, top, bottom, U"", 0); }
static void openDocument (TextEditor me, MelderFile file) { if (theOpenTextEditors) { for (long ieditor = 1; ieditor <= theOpenTextEditors -> size; ieditor ++) { TextEditor editor = (TextEditor) theOpenTextEditors -> item [ieditor]; if (editor != me && MelderFile_equal (file, & editor -> file)) { Editor_raise (editor); Melder_appendError (U"Text file ", file, U" is already open."); forget (me); // don't forget me before Melder_appendError, because "file" is owned by one of my dialogs Melder_flushError (); return; } } } autostring32 text = MelderFile_readText (file); GuiText_setString (my textWidget, text.peek()); /* * GuiText_setString has invoked the changeCallback, * which has set `my dirty` to `true`. Fix this. */ my dirty = false; MelderFile_copy (file, & my file); Thing_setName (me, Melder_fileToPath (file)); }
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); } }
void Manual_search (Manual me, const char32 *query) { GuiText_setString (my searchText, query); search (me, query); }
static void newDocument (TextEditor me) { GuiText_setString (my textWidget, U""); // implicitly sets my dirty to `true` my dirty = false; if (my v_fileBased ()) Thing_setName (me, U""); }