void multimenu_button::signal_handler_left_button_click(const event::ui_event event, bool& handled)
{
	assert(get_window());
	DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";

	sound::play_UI_sound(settings::sound_button_click);

	// If a button has a retval do the default handling.
	dialogs::drop_down_menu droplist(this->get_rectangle(), this->values_, -1, this->get_use_markup(), true,
		std::bind(&multimenu_button::toggle_state_changed, this));

	droplist_ = &droplist;
	droplist.show();
	droplist_ = nullptr;

	if(retval_ != 0) {
		if(window* window = get_window()) {
			window->set_retval(retval_);
			return;
		}
	}

	/* In order to allow toggle button states to be specified by verious dialogs in the values config, we write the state
	 * bools to the values_ config here, but only if a checkbox= key was already provided. The value of the checkbox= key
	 * is handled by the drop_down_menu widget.
	 *
	 * Passing the dynamic_bitset directly to the drop_down_menu ctor would mean bool values would need to be passed to this
	 * class independently of the values config by dialogs that use this widget. However, the bool states are also saved
	 * in a dynamic_bitset class member which can be fetched for other uses if necessary.
	 */
	update_config_from_toggle_states();

	handled = true;
}
void menu_button::signal_handler_left_button_click(const event::ui_event event, bool& handled)
{
	assert(get_window());
	DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";

	sound::play_UI_sound(settings::sound_button_click);

	// If a button has a retval do the default handling.
	dialogs::drop_down_menu droplist(this->get_rectangle(), this->values_, this->selected_, this->get_use_markup(), this->keep_open_,
		nullptr);

	if(droplist.show()) {
		const int selected = droplist.selected_item();

		// Safety check. If the user clicks a selection in the dropdown and moves their mouse away too
		// quickly, selected_ could be set to -1. This returns in that case, preventing crashes.
		if(selected < 0) {
			return;
		}

		set_selected(selected, true);

		if(retval_ != 0) {
			if(window* window = get_window()) {
				window->set_retval(retval_);
				return;
			}
		}
	}

	handled = true;
}
Exemple #3
0
void tcombobox::signal_handler_left_button_click(const event::tevent event,
											   bool& handled)
{
	assert(get_window());
	DBG_GUI_E << LOG_HEADER << ' ' << event << ".\n";

	sound::play_UI_sound(settings::sound_button_click);

	// If a button has a retval do the default handling.
	tdrop_down_list droplist(this->get_rectangle(), this->values_, this->selected_, this->get_use_markup());

	if(droplist.show(get_window()->video())) {
		selected_ = droplist.selected_item();
		this->set_label(values_[selected_]);
		if(selected_callback_) {
			selected_callback_(*this);
		}
		if(retval_ != 0) {
			twindow* window = get_window();
			if(window) {
				window->set_retval(retval_);
				return;
			}
		}
	}

	handled = true;
}