コード例 #1
0
ファイル: text.cpp プロジェクト: shikadilord/wesnoth
void ttext_::set_selection(size_t start, int length)
{
	const size_t text_size = text_.get_length();

	if(start >= text_size) {
		start = text_size;
	}

	if(length == 0) {
		set_cursor(start, false);
		return;
	}

	// The text pos/size type differs in both signedness and size with the
	// selection length. Such is life.
	const int sel_start = std::min<size_t>(start, std::numeric_limits<int>::max());
	const int sel_max_length = std::min<size_t>(text_size - start, std::numeric_limits<int>::max());

	const bool backwards = length < 0;

	if(backwards && -length > sel_start) {
		length = -sel_start;
	} else if(!backwards && length > sel_max_length) {
		length = sel_max_length;
	}

	set_selection_start(start);
	set_selection_length(length);

	update_canvas();
}
コード例 #2
0
void tpassword_box::pre_function() {
	// ttext_box::set_value() will reset the selection,
	// we therefore have to remember it
	size_t selection_start = get_selection_start();
	size_t selection_length = get_selection_length();

	// Tell ttext_box the actual input of this box
	ttext_box::set_value(real_value_);

	// Restore the selection
	set_selection_start(selection_start);
	set_selection_length(selection_length);
}
コード例 #3
0
void tpassword_box::post_function() {
	// See above
	size_t selection_start = get_selection_start();
	size_t selection_length = get_selection_length();

	// Get the input back and make ttext_box forget it
	real_value_ = get_value();
	ttext_box::set_value(std::string(get_text_length(real_value_), '*'));

	// See above
	set_selection_start(selection_start);
	set_selection_length(selection_length);

	// Why do the selection functions not update
	// the canvas?
	update_canvas();
	set_dirty(true);
}