Exemplo n.º 1
0
void OrderedOfString_sequentialNumbers (OrderedOfString me, long n) {
	Collection_removeAllItems (me);
	for (long i = 1; i <= n; i++) {
		char32 s[40];
		Melder_sprint (s,40, i);
		autoSimpleString str = SimpleString_create (s);
		Collection_addItem (me, str.transfer());
	}
}
void OrderedOfString_sequentialNumbers (I, long n) {
	iam (OrderedOfString);
	Collection_removeAllItems (me);
	for (long i = 1; i <= n; i++) {
		wchar_t s[20];
		swprintf (s, 20, L"%ld", i);
		autoSimpleString str = SimpleString_create (s);
		Collection_addItem (me, str.transfer());
	}
}
Exemplo n.º 3
0
autoCategories ResultsMFC_to_Categories_responses (ResultsMFC me) {
	try {
		autoCategories thee = Categories_create ();
		for (long trial = 1; trial <= my numberOfTrials; trial ++) {
			autoSimpleString category = SimpleString_create (my result [trial]. response);
			thy addItem_move (category.move());
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": responses not converted to Categories.");
	}
}
Exemplo n.º 4
0
Categories ResultsMFC_to_Categories_responses (ResultsMFC me) {
	try {
		autoCategories thee = Categories_create ();
		for (long trial = 1; trial <= my numberOfTrials; trial ++) {
			autoSimpleString category = SimpleString_create (my result [trial]. response);
			Collection_addItem (thee.peek(), category.transfer());
		}
		return thee.transfer();
	} catch (MelderError) {
		Melder_throw (me, U": responses not converted to Categories.");
	}
}
Exemplo n.º 5
0
static void insert (CategoriesEditor me, int position) {
	autostring32 text = GuiText_getString (my text);
	if (str32len (text.peek()) != 0) {
		autoSimpleString str = SimpleString_create (text.peek());
		autoCategoriesEditorInsert command = CategoriesEditorInsert_create (me, str.move(), position);
		Command_do (command.peek());
		if (my history) {
			CommandHistory_insertItem_move (my history.peek(), command.move());
		}
		updateWidgets (me);
	}
}
Exemplo n.º 6
0
long OrderedOfString_indexOfItem_c (OrderedOfString me, const char32 *str) {
	long index = 0;
	autoSimpleString s = SimpleString_create (str);

	for (long i = 1; i <= my size; i++) {
		if (Data_equal ( (Daata) my item[i], s.peek())) {
			index = i;
			break;
		}
	}
	return index;
}
Exemplo n.º 7
0
int OrderedOfString_append (OrderedOfString me, char32 *append) {
	try {
		if (append == nullptr) {
			return 1;    // BUG: lege string appenden??
		}
		autoSimpleString item = SimpleString_create (append);
		Collection_addItem (me, item.transfer());
		return 1;
	} catch (MelderError) {
		Melder_throw (me, U": text not appended.");
	}
}
Exemplo n.º 8
0
int OrderedOfString_append (OrderedOfString me, const char32 *append) {
	try {
		if (! append) {
			return 1;    // BUG: lege string appenden??
		}
		autoSimpleString item = SimpleString_create (append);
		my addItem_move (item.move());
		return 1;
	} catch (MelderError) {
		Melder_throw (me, U": text not appended.");
	}
}
Exemplo n.º 9
0
autoCategories TableOfReal_to_CategoriesColumn (TableOfReal me) {
	try {
		autoCategories thee = Categories_create ();

		for (long i = 1; i <= my numberOfColumns; i++) {
			if (my columnLabels[i]) {
				autoSimpleString s = SimpleString_create (my columnLabels[i]);
				Collection_addItem_move (thee.peek(), s.move());
			}
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": columnlabels not converted to Categories.");
	}
}
Exemplo n.º 10
0
static void gui_button_cb_replace (CategoriesEditor me, GuiButtonEvent /* event */) {
	long posCount;
	autoNUMvector<long> posList (GuiList_getSelectedPositions (my list, & posCount), 1);
	if (posCount > 0) {
		autostring32 text = GuiText_getString (my text);
		if (str32len (text.peek()) != 0) {
			autoSimpleString str = SimpleString_create (text.peek());
			autoCategoriesEditorReplace command = CategoriesEditorReplace_create (me, str.move(), posList.peek(), posCount);
			Command_do (command.peek());
			if (my history) {
				CommandHistory_insertItem_move (my history.peek(), command.move());
			}
			updateWidgets (me);
		}
	}
}
Exemplo n.º 11
0
autoCategories Strings_to_Categories (Strings me) {
	try {
		if (my numberOfStrings < 1) {
			Melder_throw (U"Empty strings.");
		}
		autoCategories thee = Thing_new (Categories);
		thy _grow (my numberOfStrings);

		for (long i = 1; i <= my numberOfStrings; i++) {
			autoSimpleString s = SimpleString_create (my strings [i]);
			thy addItem_move (s.move());
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": not converted.");
	}
}
Exemplo n.º 12
0
autoStringsIndex Strings_to_StringsIndex (Strings me) {
	try {
		autoStringsIndex thee = StringsIndex_create (my numberOfStrings);
		autoPermutation sorted = Strings_to_Permutation (me, 1);
		long numberOfClasses = 0;
		char32 *strings = nullptr;
		for (long i = 1; i <= sorted -> numberOfElements; i++) {
			long index = sorted -> p[i];
			char32 *stringsi = my strings[index];
			if (i == 1 || Melder_cmp (strings, stringsi) != 0) {
				numberOfClasses++;
				autoSimpleString him = SimpleString_create (stringsi);
				Collection_addItem_move (thy classes.peek(), him.move());
				strings = stringsi;
			}
			thy classIndex[index] = numberOfClasses;
		}
		return thee;
	} catch (MelderError) {
		Melder_throw (me, U": no StringsIndex created.");
	}
}
Exemplo n.º 13
0
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);
	}
}
Exemplo n.º 14
0
void OrderedOfString_initWithSequentialNumbers (OrderedOfString me, long n) {
	for (long i = 1; i <= n; i ++) {
		my addItem_move (SimpleString_create (Melder_integer (i)));
	}
}