void tdata_manage::pre_show(CVideo& /*video*/, twindow& window) { assert(txtFilter_); ttext_box* filter = find_widget<ttext_box>(&window, "txtFilter", false, true); window.keyboard_capture(filter); filter->set_text_changed_callback( boost::bind(&tdata_manage::filter_text_changed, this, _1, _2)); tlistbox& list = find_widget<tlistbox>(&window, "persist_list", false); window.keyboard_capture(&list); #ifdef GUI2_EXPERIMENTAL_LISTBOX connect_signal_notify_modified(list, boost::bind(&tdata_manage::list_item_clicked, this, boost::ref(window))); #else list.set_callback_value_change( dialog_callback<tdata_manage, &tdata_manage::list_item_clicked>); #endif { cursor::setter cur(cursor::WAIT); games_ = savegame::get_saves_list(); } fill_game_list(window, games_); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "clear", false), boost::bind(&tdata_manage::delete_button_callback, this, boost::ref(window))); }
/** * @todo This function enables the wml markup for all items, but the interface * is a bit hacky. Especially the fiddling in the internals of the listbox is * ugly. There needs to be a clean interface to set whether a widget has a * markup and what kind of markup. These fixes will be post 1.6. */ void twml_message_::pre_show(twindow& window) { set_restore(true); window.canvas(1).set_variable("portrait_image", variant(portrait_)); window.canvas(1).set_variable("portrait_mirror", variant(mirror_)); // Set the markup tlabel& title = find_widget<tlabel>(&window, "title", false); title.set_label(title_); title.set_use_markup(true); title.set_can_wrap(true); tcontrol& message = find_widget<tcontrol>(&window, "message", false); message.set_label(message_); message.set_use_markup(true); // The message label might not always be a scroll_label but the capturing // shouldn't hurt. window.keyboard_capture(&message); // Find the input box related fields. tlabel& caption = find_widget<tlabel>(&window, "input_caption", false); ttext_box& input = find_widget<ttext_box>(&window, "input", true); if(has_input_) { caption.set_label(input_caption_); caption.set_use_markup(true); input.set_value(*input_text_); input.set_maximum_length(input_maximum_length_); window.keyboard_capture(&input); window.set_click_dismiss(false); window.set_escape_disabled(true); } else { caption.set_visible(twidget::tvisible::invisible); input.set_visible(twidget::tvisible::invisible); } // Find the option list related fields. tlistbox& options = find_widget<tlistbox>(&window, "input_list", true); if(!option_list_.empty()) { std::map<std::string, string_map> data; BOOST_FOREACH(const twml_message_option& item, option_list_) { // Add the data. data["icon"]["label"] = item.image(); data["label"]["label"] = item.label(); data["label"]["use_markup"] = "true"; data["description"]["label"] = item.description(); data["description"]["use_markup"] = "true"; options.add_row(data); }
void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window) { window.set_canvas_variable("border", variant("default-border")); tlistbox& list = find_widget<tlistbox>(&window, "language_list", false); window.keyboard_capture(&list); const std::vector<language_def>& languages = get_languages(); const language_def& current_language = get_language(); std::stringstream strstr; int number = hero::number_normal_min; BOOST_FOREACH (const language_def& lang, languages) { string_map list_item; std::map<std::string, string_map> list_item_item; strstr.str(""); strstr << "hero-64/" << number << ".png"; list_item["label"] = strstr.str(); list_item_item.insert(std::make_pair("icon", list_item)); list_item["label"] = lang.language; list_item_item.insert(std::make_pair("name", list_item)); list.add_row(list_item_item); if (lang == current_language) { list.select_row(list.get_item_count() - 1); } number ++; }
void tmessage::pre_show(CVideo& /*video*/, twindow& window) { // ***** Validate the required buttons ***** ***** ***** ***** tmessage_implementation:: init_button(window, buttons_[left_1], "left_side"); tmessage_implementation:: init_button(window, buttons_[cancel], "cancel"); tmessage_implementation:: init_button(window, buttons_[ok] ,"ok"); tmessage_implementation:: init_button(window, buttons_[right_1], "right_side"); // ***** ***** ***** ***** Set up the widgets ***** ***** ***** ***** if(!title_.empty()) { find_widget<tlabel>(&window, "title", false).set_label(title_); } if(!image_.empty()) { find_widget<timage>(&window, "image", false).set_label(image_); } tcontrol& label = find_widget<tcontrol>(&window, "label", false); label.set_label(message_); // The label might not always be a scroll_label but the capturing // shouldn't hurt. window.keyboard_capture(&label); // Override the user value, to make sure it's set properly. window.set_click_dismiss(auto_close_); }
void tcampaign_difficulty::pre_show(CVideo& /*video*/, twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "listbox", false); window.keyboard_capture(&list); std::map<std::string, string_map> data; BOOST_FOREACH(const config &d, difficulties_.child_range("difficulty")) { data["icon"]["label"] = d["image"]; data["label"]["label"] = d["label"]; data["label"]["use_markup"] = "true"; data["description"]["label"] = d["old_markup"].to_bool() || d["description"].empty() ? d["description"] : std::string("(") + d["description"] + std::string(")"); data["description"]["use_markup"] = "true"; list.add_row(data); const int this_row = list.get_item_count() - 1; if(d["default"].to_bool(false)) { list.select_row(this_row); } tgrid* grid = list.get_row_grid(this_row); assert(grid); twidget *widget = grid->find("victory", false); if (widget && !preferences::is_campaign_completed(campaign_id_, d["define"])) { widget->set_visible(twidget::tvisible::hidden); } } }
void ttheme_list::pre_show(twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "themes", false); window.keyboard_capture(&list); for(const auto & t : themes_) { std::map<std::string, string_map> data; string_map column; std::string theme_name = t.name; if(theme_name.empty()) { theme_name = t.id; } column["label"] = theme_name; data.emplace("name", column); column["label"] = t.description; data.emplace("description", column); list.add_row(data); } if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) { list.select_row(index_); } index_ = -1; }
void tcombo_box::pre_show(CVideo& /*video*/, twindow& window) { window.set_canvas_variable("border", variant("default-border")); tlabel* title = find_widget<tlabel>(&window, "title", false, true); if (type_ == EXTRACT) { title->set_label(_("Extract hero")); } else { title->set_visible(twidget::INVISIBLE); find_widget<twidget>(&window, "ok", false, true)->set_visible(twidget::INVISIBLE); find_widget<twidget>(&window, "cancel", false, true)->set_visible(twidget::INVISIBLE); } tlistbox& list = find_widget<tlistbox>(&window, "listbox", false); window.keyboard_capture(&list); std::map<std::string, string_map> data; int item_index = 0; for (std::vector<tval_str>::const_iterator it = items_.begin(); it != items_.end(); ++ it) { const tval_str& item = *it; data["label"]["label"] = item.str; list.add_row(data); item_index ++; } list.set_callback_value_change(dialog_callback3<tcombo_box, tlistbox, &tcombo_box::item_selected>); if (index_ != -1) { list.select_row(index_); } }
void teditor_set_starting_position::pre_show(CVideo& /*video*/, twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "listbox", false); window.keyboard_capture(&list); std::map<std::string, string_map> data; string_map column; column["label"] = _("player^None"); data.insert(std::make_pair("player", column)); list.add_row(data); for(unsigned i = 0; i < starting_positions_.size(); ++i) { const map_location& player_pos = starting_positions_[i]; data.clear(); utils::string_map symbols; symbols["player_number"] = str_cast(i + 1); column["label"] = utils::interpolate_variables_into_string(_("Player $player_number"), &symbols); data.insert(std::make_pair("player", column)); if(player_pos.valid()) { column["label"] = (formatter() << "(" << player_pos.x + 1 << ", " << player_pos.y + 1 << ")").str(); data.insert(std::make_pair("location", column)); } list.add_row(data); } list.select_row(selection_); }
void taddon_connect::pre_show(CVideo& /*video*/, twindow& window) { ttext_box* host_widget = dynamic_cast<ttext_box*>(window.find_widget("host_name", false)); VALIDATE(host_widget, missing_widget("host_name")); host_widget->set_value(host_name_); window.keyboard_capture(host_widget); }
void tgame_save::pre_show(CVideo& /*video*/, twindow& window) { assert(txtFilename_); find_widget<tlabel>(&window, "lblTitle", false).set_label(title_); txtFilename_->set_widget_value(window, filename_); window.keyboard_capture(txtFilename_->widget(window)); }
void tmp_cmd_wrapper::pre_show(CVideo& /*video*/, twindow& window) { ttext_box* message = dynamic_cast<ttext_box*>(window.find("message", false)); if(message) { /** * @todo For some reason the text wrapping fails on Windows and Mac, * this causes an exception to be thrown, which brings the user back * to the main menu. So avoid that problem by imposing a maximum * length (the number of letters W that fit). */ #if defined(_WIN32) || defined(__APPLE__) message->set_maximum_length(18); #endif window.keyboard_capture(message); } message = dynamic_cast<ttext_box*>(window.find("reason", false)); if(message) message->set_active(preferences::is_authenticated()); message = dynamic_cast<ttext_box*>(window.find("time", false)); if(message) message->set_active(preferences::is_authenticated()); tlabel* label = dynamic_cast<tlabel*>(window.find("user_label", false)); if(label) label->set_label(user_); tbutton* b = dynamic_cast<tbutton*>(window.find("add_friend", false)); if(b) b->set_retval(1); b = dynamic_cast<tbutton*>(window.find("add_ignore", false)); if(b) b->set_retval(2); b = dynamic_cast<tbutton*>(window.find("remove", false)); if(b) b->set_retval(3); b = dynamic_cast<tbutton*>(window.find("status", false)); if(b) { b->set_retval(4); b->set_active(preferences::is_authenticated()); } b = dynamic_cast<tbutton*>(window.find("kick", false)); if(b) { b->set_retval(5); b->set_active(preferences::is_authenticated()); } b = dynamic_cast<tbutton*>(window.find("ban", false)); if(b) { b->set_retval(6); b->set_active(preferences::is_authenticated()); } }
void tunit_recruit::pre_show(twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "recruit_list", false); #ifdef GUI2_EXPERIMENTAL_LISTBOX connect_signal_notify_modified(*list, std::bind(&tunit_recruit::list_item_clicked, *this, std::ref(window))); #else list.set_callback_value_change( dialog_callback<tunit_recruit, &tunit_recruit::list_item_clicked>); #endif window.keyboard_capture(&list); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "show_help", false), std::bind(&tunit_recruit::show_help, this, std::ref(window))); for(const auto& recruit : recruit_list_) { std::map<std::string, string_map> row_data; string_map column; std::string image_string = recruit->image() + "~RC(" + recruit->flag_rgb() + ">" + team::get_side_color_index(team_.side()) + ")"; int wb_gold = 0; if(resources::controller) { if(const std::shared_ptr<wb::manager>& whiteb = resources::controller->get_whiteboard()) { wb::future_map future; // So gold takes into account planned spending wb_gold = whiteb->get_spent_gold_for(team_.side()); } } const bool can_afford = recruit->cost() <= team_.gold() - wb_gold; const std::string cost_string = std::to_string(recruit->cost()); column["use_markup"] = "true"; column["label"] = image_string; row_data.emplace("unit_image", column); column["label"] = can_afford_unit(recruit->type_name(), can_afford); row_data.emplace("unit_type", column); column["label"] = can_afford_unit(cost_string, can_afford); row_data.emplace("unit_cost", column); list.add_row(row_data); } list_item_clicked(window); }
void tgame_load::pre_show(CVideo& /*video*/, twindow& window) { assert(txtFilter_); find_widget<tminimap>(&window, "minimap", false).set_config(&cache_config_); ttext_box* filter = find_widget<ttext_box>( &window, "txtFilter", false, true); window.keyboard_capture(filter); filter->set_text_changed_callback(boost::bind( &tgame_load::filter_text_changed, this, _1, _2)); tlistbox* list = find_widget<tlistbox>( &window, "savegame_list", false, true); window.keyboard_capture(list); #ifdef GUI2_EXPERIMENTAL_LISTBOX connect_signal_notify_modified(*list, boost::bind( &tgame_load::list_item_clicked , *this , boost::ref(window))); #else list->set_callback_value_change( dialog_callback<tgame_load, &tgame_load::list_item_clicked>); #endif { cursor::setter cur(cursor::WAIT); games_ = savegame::get_saves_list(); } fill_game_list(window, games_); connect_signal_mouse_left_click( find_widget<tbutton>(&window, "delete", false) , boost::bind( &tgame_load::delete_button_callback , this , boost::ref(window))); display_savegame(window); }
void tcore_selection::pre_show(twindow& window) { /***** Setup core list. *****/ tlistbox& list = find_widget<tlistbox>(&window, "core_list", false); #ifdef GUI2_EXPERIMENTAL_LISTBOX connect_signal_notify_modified( list, std::bind(&tcore_selection::core_selected, this, std::ref(window))); #else list.set_callback_value_change( dialog_callback<tcore_selection, &tcore_selection::core_selected>); #endif window.keyboard_capture(&list); /***** Setup core details. *****/ tmulti_page& multi_page = find_widget<tmulti_page>(&window, "core_details", false); for(const auto & core : cores_) { /*** Add list item ***/ string_map list_item; std::map<std::string, string_map> list_item_item; list_item["label"] = core["image"]; list_item_item.insert(std::make_pair("image", list_item)); list_item["label"] = core["name"]; list_item_item.insert(std::make_pair("name", list_item)); list.add_row(list_item_item); tgrid* grid = list.get_row_grid(list.get_item_count() - 1); assert(grid); /*** Add detail item ***/ string_map detail_item; std::map<std::string, string_map> detail_page; detail_item["label"] = core["description"]; detail_item["use_markup"] = "true"; detail_page.insert(std::make_pair("description", detail_item)); multi_page.add_page(detail_page); } list.select_row(choice_, true); core_selected(window); }
void tmp_method_selection::pre_show(CVideo& /*video*/, twindow& window) { user_name_ = preferences::login(); ttext_box* user_widget = find_widget<ttext_box>( &window, "user_name", false, true); user_widget->set_value(user_name_); user_widget->set_maximum_length(mp::max_login_size); window.keyboard_capture(user_widget); tlistbox* list = find_widget<tlistbox>(&window, "method_list", false, true); window.add_to_keyboard_chain(list); }
void tdialog::init_fields(twindow& window) { for(auto field : fields_) { field->attach_to_window(window); field->widget_init(window); } if(!focus_.empty()) { if(twidget* widget = window.find(focus_, false)) { window.keyboard_capture(widget); } } }
void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "language_list", false); window.keyboard_capture(&list); const std::vector<language_def>& languages = get_languages(); const language_def& current_language = get_language(); FOREACH(const AUTO& lang, languages) { string_map item; item.insert(std::make_pair("label", lang.language)); list.add_row(item); if(lang == current_language) { list.select_row(list.get_item_count() - 1); } }
void tmessage2::pre_show(CVideo& /*video*/, twindow& window) { // ***** ***** ***** ***** Set up the widgets ***** ***** ***** ***** tcontrol& label = find_widget<tcontrol>(&window, "label", false); label.set_label(message_); // The label might not always be a scroll_label but the capturing // shouldn't hurt. window.keyboard_capture(&label); tcontrol& ok = find_widget<tcontrol>(&window, "ok", false); ok.set_label(ok_caption_); tcontrol& cancel = find_widget<tcontrol>(&window, "cancel", false); cancel.set_label(cancel_caption_); }
void tcore_selection::pre_show(CVideo& /*video*/, twindow& window) { if(new_widgets && false) { /***** Setup core tree. *****/ ttree_view& tree = find_widget<ttree_view>(&window, "core_tree", false); tree.set_selection_change_callback( boost::bind(&tcore_selection::core_selected, this, boost::ref(window))); window.keyboard_capture(&tree); string_map tree_group_field; std::map<std::string, string_map> tree_group_item; tree_group_item["tree_view_node_label"] = tree_group_field; /***** Setup core details. *****/ tmulti_page& multi_page = find_widget<tmulti_page>(&window, "core_details", false); // unsigned id = 0; FOREACH(const AUTO & core, cores_) { /*** Add tree item ***/ tree_group_field["label"] = core["icon"]; tree_group_item["icon"] = tree_group_field; tree_group_field["label"] = core["name"]; tree_group_item["name"] = tree_group_field; /*** Add detail item ***/ string_map detail_item; std::map<std::string, string_map> detail_page; detail_item["label"] = core["description"]; detail_item["use_markup"] = "true"; detail_page.insert(std::make_pair("description", detail_item)); detail_item["label"] = core["image"]; detail_page.insert(std::make_pair("image", detail_item)); multi_page.add_page(detail_page); }
void tmessage::pre_show(CVideo& /*video*/, twindow& window) { if(!title_.empty()) { tlabel* title = dynamic_cast<tlabel*>(window.find_widget("title", false)); VALIDATE(title, missing_widget("title")); title->set_label(title_); } if(!image_.empty()) { timage* image = dynamic_cast<timage*>(window.find_widget("image", false)); VALIDATE(image, missing_widget("image")); image->set_label(image_); } tcontrol* label = dynamic_cast<tcontrol*>(window.find_widget("label", false)); VALIDATE(label, missing_widget("label")); label->set_label(message_); // The label might not always be a scroll_label but the capturing // shouldn't hurt. window.keyboard_capture(label); if(auto_close_) { /* * Hide the buttton and do the layout, if window.does_easy_close() is * false the scroll_label has a scrollbar so we need to show the * button. When the button is hidden the text for the label is bigger * and thus not need a scrollbar. Also when the button is visible * easy_close will always return false. */ tbutton* button = dynamic_cast<tbutton*>(window.find_widget("ok", false)); VALIDATE(button, missing_widget("ok")); button->set_visible(twidget::INVISIBLE); window.layout(); if(! window.does_easy_close()) { button->set_visible(twidget::VISIBLE); } } }
void taddon_uninstall_list::pre_show(CVideo& /*video*/, twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "addons_list", false); window.keyboard_capture(&list); this->names_.clear(); this->selections_.clear(); foreach(const std::string& id, this->ids_) { this->names_.push_back(make_addon_title(id)); this->selections_[id] = false; std::map<std::string, string_map> data; string_map column; column["label"] = this->names_.back(); data.insert(std::make_pair("name", column)); list.add_row(data); } }
void bind(twindow& window) { LOG_CHAT_LOG << "Entering tchat_log::view::bind" << std::endl; model_.msg_label = &find_widget<tcontrol>(&window, "msg", false); model_.page_number = &find_widget<tslider>(&window, "page_number", false); connect_signal_notify_modified( *model_.page_number, std::bind(&view::handle_page_number_changed, this, std::ref(window))); model_.previous_page = &find_widget<tbutton>(&window, "previous_page", false); model_.previous_page->connect_click_handler( std::bind(&view::previous_page, this, std::ref(window))); model_.next_page = &find_widget<tbutton>(&window, "next_page", false); model_.next_page->connect_click_handler( std::bind(&view::next_page, this, std::ref(window))); model_.filter = &find_widget<ttext_box>(&window, "filter", false); model_.filter->set_text_changed_callback( std::bind(&view::filter, this, std::ref(window))); window.keyboard_capture(model_.filter); model_.copy_button = &find_widget<tbutton>(&window, "copy", false); connect_signal_mouse_left_click( *model_.copy_button, std::bind(&view::handle_copy_button_clicked, this, std::ref(window))); if (!desktop::clipboard::available()) { model_.copy_button->set_active(false); model_.copy_button->set_tooltip(_("Clipboard support not found, contact your packager")); } model_.page_label = &find_widget<tcontrol>(&window, "page_label", false); LOG_CHAT_LOG << "Exiting tchat_log::view::bind" << std::endl; }
void teditor_generate_map::pre_show(twindow& window) { assert(!map_generators_.empty()); register_text("seed_textbox", false, random_seed_, false); tlistbox& list = find_widget<tlistbox>(&window, "generators_list", false); window.keyboard_capture(&list); std::map<std::string, string_map> lrow; for(const auto & gen : map_generators_) { assert(gen); lrow["generator_name"]["label"] = gen->config_name(); // lrow["generator_id"]["label"] = gen->name(); list.add_row(lrow); if(gen == last_map_generator_) { list.select_row(list.get_item_count() - 1); } } if (last_map_generator_ != nullptr) { // We need to call this manually because it won't be called by // list.select_row() even if we set the callback before // calling it this->do_generator_selected(window); } list.set_callback_item_change( std::bind(&teditor_generate_map::do_generator_selected, this, std::ref(window))); tbutton& settings_button = find_widget<tbutton>(&window, "settings", false); connect_signal_mouse_left_click( settings_button, std::bind(&teditor_generate_map::do_settings, this, std::ref(window))); }
void teditor_generate_map::pre_show(CVideo& /*video*/, twindow& window) { assert(!map_generators_.empty()); register_text("seed_textbox", false, random_seed_, false); tlistbox& list = find_widget<tlistbox>(&window, "generators_list", false); window.keyboard_capture(&list); std::map<std::string, string_map> lrow; FOREACH(const AUTO & gen, map_generators_) { assert(gen); lrow["generator_name"]["label"] = gen->config_name(); // lrow["generator_id"]["label"] = gen->name(); list.add_row(lrow); if(gen == last_map_generator_) { list.select_row(list.get_item_count() - 1); } }
void tsimple_item_selector::pre_show(CVideo& /*video*/, twindow& window) { tlabel& ltitle = find_widget<tlabel>(&window, "title", false); tcontrol& lmessage = find_widget<tcontrol>(&window, "message", false); tlistbox& list = find_widget<tlistbox>(&window, "listbox", false); window.keyboard_capture(&list); ltitle.set_label(title_); ltitle.set_use_markup(markup_title_); lmessage.set_label(msg_); lmessage.set_use_markup(markup_msg_); foreach(const tsimple_item_selector::item_type& it, items_) { std::map<std::string, string_map> data; string_map column; column["label"] = it; data.insert(std::make_pair("item", column)); list.add_row(data); }
void ttheme_list::pre_show(CVideo& /*video*/, twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "themes", false); window.keyboard_capture(&list); FOREACH(const AUTO & t, themes_) { std::map<std::string, string_map> data; string_map column; std::string theme_name = t.name; if(theme_name.empty()) { theme_name = t.id; } column["label"] = theme_name; data.insert(std::make_pair("name", column)); column["label"] = t.description; data.insert(std::make_pair("description", column)); list.add_row(data); }
static void set_weapon_info(twindow& window , const std::vector<battle_context>& weapons , const int best_weapon) { tlistbox& weapon_list = find_widget<tlistbox>(&window, "weapon_list", false); window.keyboard_capture(&weapon_list); const config empty; const attack_type no_weapon(empty); FOREACH(const AUTO& weapon, weapons) { const battle_context_unit_stats& attacker = weapon.get_attacker_stats(); const battle_context_unit_stats& defender = weapon.get_defender_stats(); const attack_type& attacker_weapon = *attacker.weapon; const attack_type& defender_weapon = defender.weapon ? *defender.weapon : no_weapon; std::map<std::string, string_map> data; string_map item; item["label"] = attacker_weapon.name(); data.insert(std::make_pair("attacker_weapon", item)); item["label"] = defender_weapon.name(); data.insert(std::make_pair("defender_weapon", item)); weapon_list.add_row(data); } assert(best_weapon < static_cast<int>(weapon_list.get_item_count())); weapon_list.select_row(best_weapon); }
void taddon_uninstall_list::pre_show(CVideo& /*video*/, twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "addons_list", false); window.keyboard_capture(&list); this->selections_.clear(); FOREACH(const AUTO & entry, titles_map_) { const std::string& id = entry.first; const std::string& title = entry.second; this->ids_.push_back(id); this->selections_[id] = false; std::map<std::string, string_map> data; string_map column; column["label"] = title; data.insert(std::make_pair("name", column)); list.add_row(data); } }
void tsimple_item_selector::pre_show(twindow& window) { tlistbox& list = find_widget<tlistbox>(&window, "listbox", false); window.keyboard_capture(&list); for(const auto & it : items_) { std::map<std::string, string_map> data; string_map column; column["label"] = it; data.insert(std::make_pair("item", column)); list.add_row(data); } if(index_ != -1 && static_cast<unsigned>(index_) < list.get_item_count()) { list.select_row(index_); } index_ = -1; tbutton& button_ok = find_widget<tbutton>(&window, "ok", false); tbutton& button_cancel = find_widget<tbutton>(&window, "cancel", false); if(!ok_label_.empty()) { button_ok.set_label(ok_label_); } if(!cancel_label_.empty()) { button_cancel.set_label(cancel_label_); } if(single_button_) { button_cancel.set_visible(gui2::twidget::tvisible::invisible); } }
/** * @todo This function enables the wml markup for all items, but the interface * is a bit hacky. Especially the fiddling in the internals of the listbox is * ugly. There needs to be a clean interface to set whether a widget has a * markup and what kind of markup. These fixes will be post 1.6. */ void twml_message_::pre_show(CVideo& /*video*/, twindow& window) { window.canvas(1).set_variable("portrait_image", variant(portrait_)); window.canvas(1).set_variable("portrait_mirror", variant(mirror_)); // Set the markup tlabel& title = find_widget<tlabel>(&window, "title", false); title.set_label(title_); title.set_use_markup(true); title.set_can_wrap(true); tcontrol& message = find_widget<tcontrol>(&window, "message", false); message.set_label(message_); message.set_use_markup(true); // The message label might not always be a scroll_label but the capturing // shouldn't hurt. window.keyboard_capture(&message); // Find the input box related fields. tlabel& caption = find_widget<tlabel>(&window, "input_caption", false); ttext_box& input = find_widget<ttext_box>(&window, "input", true); if(has_input_) { caption.set_label(input_caption_); caption.set_use_markup(true); input.set_value(*input_text_); input.set_maximum_length(input_maximum_length_); window.keyboard_capture(&input); window.set_click_dismiss(false); window.set_escape_disabled(true); } else { caption.set_visible(twidget::tvisible::invisible); input.set_visible(twidget::tvisible::invisible); } // Find the option list related fields. tlistbox& options = find_widget<tlistbox>(&window, "input_list", true); if(!option_list_.empty()) { std::map<std::string, string_map> data; for(size_t i = 0; i < option_list_.size(); ++i) { /** * @todo This syntax looks like a bad hack, it would be nice to write * a new syntax which doesn't use those hacks (also avoids the problem * with special meanings for certain characters. */ tlegacy_menu_item item(option_list_[i]); if(item.is_default()) { // Number of items hasn't been increased yet so i is ok. *chosen_option_ = i; } // Add the data. data["icon"]["label"] = item.icon(); data["label"]["label"] = item.label(); data["label"]["use_markup"] = "true"; data["description"]["label"] = item.description(); data["description"]["use_markup"] = "true"; options.add_row(data); } // Avoid negative and 0 since item 0 is already selected. if(*chosen_option_ > 0 && static_cast<size_t>(*chosen_option_) < option_list_.size()) { options.select_row(*chosen_option_); } if(!has_input_) { window.keyboard_capture(&options); window.set_click_dismiss(false); window.set_escape_disabled(true); } else { window.add_to_keyboard_chain(&options); // click_dismiss has been disabled due to the input. } } else { options.set_visible(twidget::tvisible::invisible); } window.set_click_dismiss(!has_input_ && option_list_.empty()); }