static void gui_button_cb_insert (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); Strings strings = (Strings) my data; /* * Find the first selected item. */ long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); long position = selected == NULL ? strings -> numberOfStrings + 1 : selected [1]; NUMvector_free (selected, 1); wchar_t *text = GuiText_getString (my text); /* * Change the data. */ Strings_insert (strings, position, text); /* * Change the list. */ GuiList_insertItem (my list, text, position); GuiList_deselectAllItems (my list); GuiList_selectItem (my list, position); /* * Clean up. */ Melder_free (text); my broadcastDataChanged (); }
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_insert (StringsEditor me, GuiButtonEvent /* event */) { Strings strings = (Strings) my data; /* * Find the first selected item. */ long numberOfSelected, *selected = GuiList_getSelectedPositions (my list, & numberOfSelected); long position = selected ? selected [1] : strings -> numberOfStrings + 1; NUMvector_free (selected, 1); char32 *text = GuiText_getString (my text); /* * Change the data. */ Strings_insert (strings, position, text); /* * Change the list. */ GuiList_insertItem (my list, text, position); GuiList_deselectAllItems (my list); GuiList_selectItem (my list, position); /* * Clean up. */ Melder_free (text); Editor_broadcastDataChanged (me); }
void StringsEditor::gui_button_cb_insert (I, GuiButtonEvent event) { (void) event; StringsEditor *stringsEditor = (StringsEditor *)void_me; Strings strings = (structStrings*)stringsEditor->_data; /* * Find the first selected item. */ long numberOfSelected, *selected = GuiList_getSelectedPositions (stringsEditor->_list, & numberOfSelected); long position = selected == NULL ? strings -> numberOfStrings + 1 : selected [1]; NUMlvector_free (selected, 1); wchar_t *text = GuiText_getString (stringsEditor->_text); /* * Change the data. */ Strings_insert (strings, position, text); /* * Change the list. */ GuiList_insertItem (stringsEditor->_list, text, position); GuiList_deselectAllItems (stringsEditor->_list); GuiList_selectItem (stringsEditor->_list, position); /* * Clean up. */ Melder_free (text); stringsEditor->broadcastChange (); }
static void updateList (ArtwordEditor me) { Artword artword = (Artword) my data; ArtwordData a = & artword -> data [my feature]; GuiList_deleteAllItems (my list); for (int i = 1; i <= a -> numberOfTargets; i ++) { GuiList_insertItem (my list, Melder_cat (Melder_single (a -> times [i]), U" ", Melder_single (a -> targets [i])), i); } Graphics_updateWs (my graphics.get()); }
static void updateList (ArtwordEditor me) { Artword artword = (Artword) my data; ArtwordData a = & artword -> data [my feature]; GuiList_deleteAllItems (my list); for (int i = 1; i <= a -> numberOfTargets; i ++) { static MelderString itemText = { 0 }; MelderString_empty (& itemText); MelderString_append (& itemText, Melder_single (a -> times [i]), L" ", Melder_single (a -> targets [i])); GuiList_insertItem (my list, itemText.string, i); } Graphics_updateWs (my graphics); }
static void gui_button_cb_append (StringsEditor me, GuiButtonEvent /* event */) { Strings strings = (Strings) my data; char32 *text = GuiText_getString (my text); /* * Change the data. */ Strings_insert (strings, 0, text); /* * Change the list. */ GuiList_insertItem (my list, text, 0); GuiList_deselectAllItems (my list); GuiList_selectItem (my list, strings -> numberOfStrings); /* * Clean up. */ Melder_free (text); Editor_broadcastDataChanged (me); }
static void gui_button_cb_append (I, GuiButtonEvent event) { (void) event; iam (StringsEditor); Strings strings = (Strings) my data; wchar_t *text = GuiText_getString (my text); /* * Change the data. */ Strings_insert (strings, 0, text); /* * Change the list. */ GuiList_insertItem (my list, text, 0); GuiList_deselectAllItems (my list); GuiList_selectItem (my list, strings -> numberOfStrings); /* * Clean up. */ Melder_free (text); my broadcastDataChanged (); }
void StringsEditor::gui_button_cb_append (I, GuiButtonEvent event) { (void) event; StringsEditor *stringsEditor = (StringsEditor *)void_me; Strings strings = (structStrings*)stringsEditor->_data; wchar_t *text = GuiText_getString (stringsEditor->_text); /* * Change the data. */ Strings_insert (strings, 0, text); /* * Change the list. */ GuiList_insertItem (stringsEditor->_list, text, 0); GuiList_deselectAllItems (stringsEditor->_list); GuiList_selectItem (stringsEditor->_list, strings -> numberOfStrings); /* * Clean up. */ 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); } }
static void updateList (StringsEditor me) { Strings strings = (Strings) my data; GuiList_deleteAllItems (my list); for (long i = 1; i <= strings -> numberOfStrings; i ++) GuiList_insertItem (my list, strings -> strings [i], 0); }
void StringsEditor::updateList () { Strings strings = (structStrings*)_data; GuiList_deleteAllItems (_list); for (long i = 1; i <= strings -> numberOfStrings; i ++) GuiList_insertItem (_list, strings -> strings [i], 0); }