static void gui_button_cb_addTarget (ArtwordEditor me, GuiButtonEvent /* event */) { Artword artword = (Artword) my data; char32 *timeText = GuiText_getString (my time); double tim = Melder_atof (timeText); char32 *valueText = GuiText_getString (my value); double value = Melder_atof (valueText); ArtwordData a = & artword -> data [my feature]; int i = 1, oldCount = a -> numberOfTargets; Melder_free (timeText); Melder_free (valueText); Artword_setTarget (artword, my feature, tim, value); /* Optimization instead of "updateList (me)". */ if (tim < 0) tim = 0; if (tim > artword -> totalTime) tim = artword -> totalTime; while (tim != a -> times [i]) { i ++; Melder_assert (i <= a -> numberOfTargets); // can fail if tim is in an extended precision register } const char32 *itemText = Melder_cat (Melder_single (tim), U" ", Melder_single (value)); if (a -> numberOfTargets == oldCount) { GuiList_replaceItem (my list, itemText, i); } else { GuiList_insertItem (my list, itemText, i); } Graphics_updateWs (my graphics.get()); Editor_broadcastDataChanged (me); }
static void gui_button_cb_replace (StringsEditor me, GuiButtonEvent /* event */) { Strings strings = (Strings) my data; long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); char32 *text = GuiText_getString (my text); for (long iselected = 1; iselected <= numberOfSelected; iselected ++) { Strings_replace (strings, selected [iselected], text); GuiList_replaceItem (my list, text, selected [iselected]); } Melder_free (text); Editor_broadcastDataChanged (me); }
static void gui_button_cb_replace (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); Strings strings = (Strings) my data; long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); wchar_t *text = GuiText_getString (my text); for (long iselected = 1; iselected <= numberOfSelected; iselected ++) { Strings_replace (strings, selected [iselected], text); GuiList_replaceItem (my list, text, selected [iselected]); } Melder_free (text); my broadcastDataChanged (); }
void StringsEditor::gui_button_cb_replace (I, GuiButtonEvent event) { (void) event; StringsEditor *stringsEditor = (StringsEditor *)void_me; Strings strings = (structStrings*)stringsEditor->_data; long numberOfSelected, *selected = GuiList_getSelectedPositions (stringsEditor->_list, & numberOfSelected); wchar_t *text = GuiText_getString (stringsEditor->_text); for (long iselected = 1; iselected <= numberOfSelected; iselected ++) { Strings_replace (strings, selected [iselected], text); GuiList_replaceItem (stringsEditor->_list, text, selected [iselected]); } Melder_free (text); stringsEditor->broadcastChange (); }
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); } }