The listbox class. More...
#include <listbox.hpp>


Public Member Functions | |
| tlistbox (const bool has_minimum, const bool has_maximum, const tgenerator_::tplacement placement, const bool select) | |
| Constructor. | |
| void | add_row (const string_map &item, const int index=-1) |
| When an item in the list is selected by the user we need to update the state. | |
| void | add_row (const std::map< std::string, string_map > &data, const int index=-1) |
| Adds single row to the grid. | |
| void | remove_row (const unsigned row, unsigned count=1) |
| Removes a row in the listbox. | |
| void | clear () |
| Removes all the rows in the listbox, clearing it. | |
| unsigned | get_item_count () const |
| Returns the number of items in the listbox. | |
| void | set_row_active (const unsigned row, const bool active) |
| Makes a row active or inactive. | |
| void | set_row_shown (const unsigned row, const bool shown) |
| Makes a row visible or invisible. | |
| void | set_row_shown (const std::vector< bool > &shown) |
| Makes a row visible or invisible. | |
| const tgrid * | get_row_grid (const unsigned row) const |
| Returns the grid of the wanted row. | |
| tgrid * | get_row_grid (const unsigned row) |
| The possibly-giving-problems nonconst version of get_row_grid. | |
| bool | select_row (const unsigned row, const bool select=true) |
| Selectes a row. | |
| int | get_selected_row () const |
| Returns the first selected row. | |
| void | list_item_clicked (twidget *caller) |
| Function to call after the user clicked on a row. | |
| void | set_self_active (const bool) |
| Inherited from tcontainer_. | |
| bool | update_content_size () |
| Request to update the size of the content after changing the content. | |
| void | place (const tpoint &origin, const tpoint &size) |
| Inherited from tscrollbar_container. | |
| void | layout_children () |
| Inherited from tscrollbar_container. | |
| void | child_populate_dirty_list (twindow &caller, const std::vector< twidget * > &call_stack) |
| Inherited from tscrollbar_container. | |
| void | set_callback_value_change (void(*callback)(twidget *caller)) |
| void | set_list_builder (tbuilder_grid_ptr list_builder) |
Protected Member Functions | |
| void | handle_key_up_arrow (SDLMod modifier, bool &handled) |
| Inherited from tscrollbar_container. | |
| void | handle_key_down_arrow (SDLMod modifier, bool &handled) |
| Inherited from tscrollbar_container. | |
| void | handle_key_left_arrow (SDLMod modifier, bool &handled) |
| Inherited from tscrollbar_container. | |
| void | handle_key_right_arrow (SDLMod modifier, bool &handled) |
| Inherited from tscrollbar_container. | |
Private Member Functions | |
| void | finalize (tbuilder_grid_const_ptr header, tbuilder_grid_const_ptr footer, const std::vector< string_map > &list_data) |
| Finishes the building initialization of the widget. | |
| void | resize_content (const int width_modification, const int height_modification) |
| Resizes the content. | |
| void | layout_children (const bool force) |
| Layouts the children if needed. | |
| virtual void | set_content_size (const tpoint &origin, const tpoint &size) |
| Inherited from tscrollbar_container. | |
| const std::string & | get_control_type () const |
| Inherited from tcontrol. | |
Private Attributes | |
| tgenerator_ * | generator_ |
| Contains a pointer to the generator. | |
| tbuilder_grid_const_ptr | list_builder_ |
| Contains the builder for the new items. | |
| void(* | callback_value_changed_ )(twidget *) |
| This callback is called when the value in the listbox changes. | |
| bool | need_layout_ |
Friends | |
| struct | implementation::tbuilder_listbox |
| struct | implementation::tbuilder_horizontal_listbox |
| class | tdebug_layout_graph |
The listbox class.
Definition at line 32 of file listbox.hpp.
| gui2::tlistbox::tlistbox | ( | const bool | has_minimum, | |
| const bool | has_maximum, | |||
| const tgenerator_::tplacement | placement, | |||
| const bool | select | |||
| ) |
Constructor.
| has_minimum | Does the listbox need to have one item selected. | |
| has_maximum | Can the listbox only have one item selected. | |
| placement | How are the items placed. | |
| select | Select an item when selected, if false it changes the visible state instead. |
Definition at line 50 of file listbox.cpp.
References gui2::build(), and generator_.

| void gui2::tlistbox::add_row | ( | const string_map & | item, | |
| const int | index = -1 | |||
| ) |
When an item in the list is selected by the user we need to update the state.
We installed a callback handler which calls us.
| item | The data send to the set_members of the widgets. | |
| index | The item before which to add the new item, 0 == begin, -1 == end. |
Definition at line 62 of file listbox.cpp.
References gui2::tgenerator_::create_item(), generator_, and list_builder_.
Referenced by gui2::tmp_change_control::model::add_nick(), gui2::tgamestate_inspector::model::add_row_to_stuff_list(), gui2::tgamestate_inspector::model::add_row_to_stuff_types_list(), gui2::tmp_change_control::model::add_side(), gui2::tdata_manage::filter_text_changed(), gui2::tmp_create_game::post_show(), gui2::twml_message_::pre_show(), gui2::tsimple_item_selector::pre_show(), gui2::tlanguage_selection::pre_show(), gui2::teditor_set_starting_position::pre_show(), gui2::tcampaign_difficulty::pre_show(), gui2::taddon_uninstall_list::pre_show(), gui2::tlobby_main::search_create_window(), gui2::tlobby_main::update_gamelist(), and gui2::tlobby_main::update_gamelist_diff().


| void gui2::tlistbox::add_row | ( | const std::map< std::string, string_map > & | data, | |
| const int | index = -1 | |||
| ) |
Adds single row to the grid.
This function expect a row to have multiple widgets (either multiple columns or one column with multiple widgets).
| data | The data to send to the set_members of the widgets. If the member id is not an empty string it is only send to the widget that has the wanted id (if any). If the member id is an empty string, it is send to all members. Having both empty and non-empty id's gives undefined behaviour. | |
| index | The item before which to add the new item, 0 == begin, -1 == end. |
Definition at line 69 of file listbox.cpp.
References gui2::tgenerator_::create_item(), generator_, and list_builder_.

| void gui2::tlistbox::child_populate_dirty_list | ( | twindow & | caller, | |
| const std::vector< twidget * > & | call_stack | |||
| ) | [virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 317 of file listbox.cpp.
References generator_, and gui2::twidget::populate_dirty_list().

| void gui2::tlistbox::clear | ( | ) |
Removes all the rows in the listbox, clearing it.
Definition at line 103 of file listbox.cpp.
References remove_row().
Referenced by gui2::tmp_change_control::model::clear_nicks(), gui2::tmp_change_control::model::clear_sides(), gui2::tgamestate_inspector::model::clear_stuff_list(), gui2::tgamestate_inspector::model::clear_stuff_types_list(), gui2::tlobby_main::update_gamelist(), and gui2::tlobby_main::update_playerlist().


| void gui2::tlistbox::finalize | ( | tbuilder_grid_const_ptr | header, | |
| tbuilder_grid_const_ptr | footer, | |||
| const std::vector< string_map > & | list_data | |||
| ) | [private] |
Finishes the building initialization of the widget.
For now it's always fixed width depending on the first row.
| header | Builder for the header. | |
| footer | Builder for the footer. | |
| list_data | The initial data to fill the listbox with. |
Definition at line 469 of file listbox.cpp.
References gui2::tscrollbar_container::content_grid(), gui2::tgenerator_::create_items(), gui2::tscrollbar_container::finalize_setup(), generator_, gui2::tcontainer_::grid(), and list_builder_.

| const std::string & gui2::tlistbox::get_control_type | ( | ) | const [private, virtual] |
Inherited from tcontrol.
Reimplemented from gui2::tscrollbar_container.
Definition at line 520 of file listbox.cpp.
References type.
| unsigned gui2::tlistbox::get_item_count | ( | ) | const |
Returns the number of items in the listbox.
Definition at line 110 of file listbox.cpp.
References generator_, and gui2::tgenerator_::get_item_count().
Referenced by gui2::taddon_uninstall_list::post_show(), gui2::tsimple_item_selector::pre_show(), gui2::tlanguage_selection::pre_show(), gui2::tcampaign_difficulty::pre_show(), remove_row(), set_row_shown(), gui2::tlobby_main::update_gamelist(), gui2::tlobby_main::update_gamelist_diff(), and gui2::tlobby_main::update_gamelist_filter().


| const tgrid * gui2::tlistbox::get_row_grid | ( | const unsigned | row | ) | const |
Returns the grid of the wanted row.
There's only a const version since allowing callers to modify the grid behind our backs might give problems. We return a pointer instead of a reference since dynamic casting of pointers is easier (no try catch needed).
| row | The row to get the grid from, the caller has to make sure the row is a valid row. |
Definition at line 187 of file listbox.cpp.
References generator_, and gui2::tgenerator_::item().
Referenced by gui2::tlobby_main::active_window_changed(), gui2::tlobby_main::increment_waiting_messages(), gui2::tlobby_main::increment_waiting_whsipers(), gui2::taddon_uninstall_list::post_show(), gui2::tlobby_main::update_gamelist(), and gui2::tlobby_main::update_gamelist_diff().


| tgrid * gui2::tlistbox::get_row_grid | ( | const unsigned | row | ) |
The possibly-giving-problems nonconst version of get_row_grid.
| row | The row to get the grid from, the caller has to make sure the row is a valid row. |
Definition at line 194 of file listbox.cpp.
References generator_, and gui2::tgenerator_::item().

| int gui2::tlistbox::get_selected_row | ( | ) | const |
Returns the first selected row.
| -1 | No row selected. |
Definition at line 209 of file listbox.cpp.
References generator_, and gui2::tgenerator_::get_selected_item().
Referenced by gui2::tmp_change_control::controller::change_control(), gui2::tmp_change_control::controller::get_side_controller(), gui2::tgamestate_inspector::controller::get_sm_controller(), gui2::tmp_change_control::controller::handle_nicks_list_item_clicked(), gui2::side_controller::handle_nicks_list_selection(), gui2::tmp_change_control::controller::handle_sides_list_item_clicked(), gui2::team_mode_controller::handle_stuff_list_selection(), gui2::unit_mode_controller::handle_stuff_list_selection(), gui2::variable_mode_controller::handle_stuff_list_selection(), gui2::tlobby_main::join_global_button_callback(), gui2::tlobby_main::observe_global_button_callback(), gui2::tsimple_item_selector::post_show(), gui2::teditor_set_starting_position::post_show(), gui2::tcampaign_difficulty::post_show(), gui2::tlobby_main::room_switch_callback(), set_row_shown(), gui2::tlobby_main::update_gamelist(), gui2::tlobby_main::update_gamelist_diff(), and gui2::tlobby_main::update_selected_game().


| void gui2::tlistbox::handle_key_down_arrow | ( | SDLMod | modifier, | |
| bool & | handled | |||
| ) | [protected, virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 355 of file listbox.cpp.
References callback_value_changed_, gui2::tscrollbar_container::content_visible_area(), generator_, gui2::twidget::get_rect(), gui2::tgenerator_::get_selected_item(), gui2::tgenerator_::handle_key_down_arrow(), handle_key_up_arrow(), gui2::tgenerator_::item(), and gui2::tscrollbar_container::show_content_rect().

| void gui2::tlistbox::handle_key_left_arrow | ( | SDLMod | modifier, | |
| bool & | handled | |||
| ) | [protected, virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 382 of file listbox.cpp.
References callback_value_changed_, gui2::tscrollbar_container::content_visible_area(), generator_, gui2::twidget::get_rect(), gui2::tgenerator_::get_selected_item(), gui2::tgenerator_::handle_key_left_arrow(), gui2::tgenerator_::item(), and gui2::tscrollbar_container::show_content_rect().
Referenced by handle_key_right_arrow().


| void gui2::tlistbox::handle_key_right_arrow | ( | SDLMod | modifier, | |
| bool & | handled | |||
| ) | [protected, virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 409 of file listbox.cpp.
References callback_value_changed_, gui2::tscrollbar_container::content_visible_area(), generator_, gui2::twidget::get_rect(), gui2::tgenerator_::get_selected_item(), handle_key_left_arrow(), gui2::tgenerator_::handle_key_right_arrow(), gui2::tgenerator_::item(), and gui2::tscrollbar_container::show_content_rect().

| void gui2::tlistbox::handle_key_up_arrow | ( | SDLMod | modifier, | |
| bool & | handled | |||
| ) | [protected, virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 328 of file listbox.cpp.
References callback_value_changed_, gui2::tscrollbar_container::content_visible_area(), generator_, gui2::twidget::get_rect(), gui2::tgenerator_::get_selected_item(), gui2::tgenerator_::handle_key_up_arrow(), gui2::tgenerator_::item(), and gui2::tscrollbar_container::show_content_rect().
Referenced by handle_key_down_arrow().


| void gui2::tlistbox::layout_children | ( | ) | [virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 312 of file listbox.cpp.
| void gui2::tlistbox::layout_children | ( | const bool | force | ) | [private] |
Layouts the children if needed.
Definition at line 504 of file listbox.cpp.
References gui2::tscrollbar_container::content_grid(), gui2::tscrollbar_container::content_visible_area_, gui2::twidget::get_origin(), gui2::twidget::get_size(), need_layout_, gui2::tgrid::place(), gui2::twidget::set_dirty(), and gui2::tgrid::set_visible_area().

| void gui2::tlistbox::list_item_clicked | ( | twidget * | caller | ) |
Function to call after the user clicked on a row.
Definition at line 216 of file listbox.cpp.
References callback_value_changed_, generator_, gui2::tgenerator_::get_item_count(), gui2::twidget::get_window(), gui2::tgrid::has_widget(), gui2::tgenerator_::item(), gui2::twindow::keyboard_capture(), and gui2::tgenerator_::toggle_item().

Inherited from tscrollbar_container.
At the moment the listboxes and dialogs in general are resized a lot as work-around for sizing. So this function makes the selected item in view again. It doesn't work great in all cases but the proper fix is to avoid resizing dialogs a lot. Need more work later on.
Reimplemented from gui2::tscrollbar_container.
Definition at line 256 of file listbox.cpp.
References gui2::tscrollbar_container::content_visible_area(), generator_, gui2::twidget::get_rect(), gui2::tgenerator_::get_selected_item(), gui2::tgenerator_::item(), and gui2::tscrollbar_container::show_content_rect().

| void gui2::tlistbox::remove_row | ( | const unsigned | row, | |
| unsigned | count = 1 | |||
| ) |
Removes a row in the listbox.
| row | The row to remove, when not in range the function is ignored. | |
| count | The number of rows to remove, 0 means all rows (starting from row). |
Definition at line 78 of file listbox.cpp.
References gui2::tgenerator_::delete_item(), generator_, gui2::twidget::get_height(), get_item_count(), gui2::twidget::get_visible(), gui2::tgenerator_::item(), and resize_content().
Referenced by clear(), gui2::tlobby_main::close_window(), and gui2::tlobby_main::update_gamelist_diff().


| void gui2::tlistbox::resize_content | ( | const int | width_modification, | |
| const int | height_modification | |||
| ) | [private] |
Resizes the content.
The resize either happens due to resizing the content or invalidate the layout of the window.
| width_modification | The wanted modification to the width: * negative values reduce width. * zero leave width as is. * positive values increase width. | |
| height_modification | The wanted modification to the height: * negative values reduce height. * zero leave height as is. * positive values increase height. |
Definition at line 281 of file listbox.cpp.
References gui2::tscrollbar_container::content_grid(), gui2::tscrollbar_container::content_resize_request(), DBG_GUI_L, gui2::twidget::get_size(), LOG_HEADER, need_layout_, gui2::twidget::set_dirty(), gui2::twidget::set_size(), gui2::tpoint::x, and gui2::tpoint::y.
Referenced by remove_row().


| bool gui2::tlistbox::select_row | ( | const unsigned | row, | |
| const bool | select = true | |||
| ) |
Selectes a row.
| row | The row to select. | |
| select | Select or deselect the row. |
Definition at line 200 of file listbox.cpp.
References generator_, and gui2::tgenerator_::select_item().
Referenced by gui2::tlobby_main::close_window(), gui2::twml_message_::pre_show(), gui2::tsimple_item_selector::pre_show(), gui2::tlanguage_selection::pre_show(), gui2::teditor_set_starting_position::pre_show(), gui2::tcampaign_difficulty::pre_show(), gui2::side_controller::show_nicks_list(), gui2::tlobby_main::switch_to_window(), gui2::tlobby_main::update_gamelist(), and gui2::tlobby_main::update_gamelist_diff().


| void gui2::tlistbox::set_callback_value_change | ( | void(*)(twidget *caller) | callback | ) | [inline] |
Definition at line 212 of file listbox.hpp.
References callback_value_changed_.
Referenced by gui2::tmp_change_control::view::bind(), gui2::tgamestate_inspector::view::bind(), and gui2::tlobby_main::pre_show().

| void gui2::tlistbox::set_content_size | ( | const tpoint & | origin, | |
| const tpoint & | size | |||
| ) | [private, virtual] |
Inherited from tscrollbar_container.
Reimplemented from gui2::tscrollbar_container.
Definition at line 493 of file listbox.cpp.
References gui2::tscrollbar_container::content_grid(), gui2::twidget::get_best_size(), gui2::tgrid::place(), gui2::tpoint::x, and gui2::tpoint::y.

| void gui2::tlistbox::set_list_builder | ( | tbuilder_grid_ptr | list_builder | ) | [inline] |
Definition at line 215 of file listbox.hpp.
References list_builder_.
| void gui2::tlistbox::set_row_active | ( | const unsigned | row, | |
| const bool | active | |||
| ) |
Makes a row active or inactive.
NOTE this doesn't change the select status of the row.
| row | The row to (de)activate. | |
| active | true activate, false deactivate. |
Definition at line 116 of file listbox.cpp.
References generator_, gui2::tgenerator_::item(), and gui2::tgrid::set_active().

| void gui2::tlistbox::set_row_shown | ( | const std::vector< bool > & | shown | ) |
Makes a row visible or invisible.
Use this version if you want to show hide multiple items since it's optimized for that purpose, for one it calls the selection changed callback only once instead of several times.
| shown | A vector with the show hide status for every row. The number of items in the vector must be equal to the number of items in the listbox. |
Definition at line 153 of file listbox.cpp.
References gui2::tgenerator_::calculate_best_size(), callback_value_changed_, gui2::tscrollbar_container::content_grid_, gui2::tscrollbar_container::content_resize_request(), gui2::tscrollbar_container::content_visible_area(), generator_, get_item_count(), gui2::twidget::get_origin(), get_selected_row(), gui2::twidget::get_window(), gui2::tgenerator_::place(), gui2::twidget::set_dirty(), gui2::tgenerator_::set_item_shown(), and gui2::tgrid::set_visible_area().

| void gui2::tlistbox::set_row_shown | ( | const unsigned | row, | |
| const bool | shown | |||
| ) |
Makes a row visible or invisible.
| row | The row to show or hide. | |
| shown | true visible, false invisible. |
Definition at line 122 of file listbox.cpp.
References gui2::tgenerator_::calculate_best_size(), callback_value_changed_, gui2::tscrollbar_container::content_grid_, gui2::tscrollbar_container::content_resize_request(), gui2::tscrollbar_container::content_visible_area(), generator_, gui2::twidget::get_origin(), get_selected_row(), gui2::twidget::get_window(), gui2::twindow::invalidate_layout(), gui2::tgenerator_::place(), gui2::twidget::set_dirty(), gui2::tgenerator_::set_item_shown(), and gui2::tgrid::set_visible_area().
Referenced by gui2::tlobby_main::update_gamelist(), gui2::tlobby_main::update_gamelist_diff(), and gui2::tlobby_main::update_gamelist_filter().


| void gui2::tlistbox::set_self_active | ( | const | bool | ) | [inline, virtual] |
Inherited from tcontainer_.
Implements gui2::tcontainer_.
Definition at line 178 of file listbox.hpp.
| bool gui2::tlistbox::update_content_size | ( | ) |
Request to update the size of the content after changing the content.
When a resize is required the container first can try to handle it itself. If it can't honour the request the function will call twindow::invalidate_layout().
Definition at line 237 of file listbox.cpp.
References gui2::tscrollbar_container::content_grid_, gui2::tscrollbar_container::content_resize_request(), gui2::tscrollbar_container::content_visible_area(), gui2::twidget::get_size(), gui2::twidget::get_visible(), gui2::twidget::INVISIBLE, gui2::twidget::set_dirty(), and gui2::tgrid::set_visible_area().

friend struct implementation::tbuilder_horizontal_listbox [friend] |
Definition at line 36 of file listbox.hpp.
friend struct implementation::tbuilder_listbox [friend] |
Definition at line 35 of file listbox.hpp.
friend class tdebug_layout_graph [friend] |
Reimplemented from gui2::tscrollbar_container.
Definition at line 37 of file listbox.hpp.
void(* gui2::tlistbox::callback_value_changed_)(twidget *) [private] |
This callback is called when the value in the listbox changes.
Definition at line 281 of file listbox.hpp.
Referenced by handle_key_down_arrow(), handle_key_left_arrow(), handle_key_right_arrow(), handle_key_up_arrow(), list_item_clicked(), set_callback_value_change(), and set_row_shown().
tgenerator_* gui2::tlistbox::generator_ [private] |
Contains a pointer to the generator.
The pointer is not owned by this class, it's stored in the content_grid_ of the tscrollbar_container super class and freed when it's grid is freed.
Definition at line 269 of file listbox.hpp.
Referenced by add_row(), child_populate_dirty_list(), finalize(), get_item_count(), get_row_grid(), get_selected_row(), handle_key_down_arrow(), handle_key_left_arrow(), handle_key_right_arrow(), handle_key_up_arrow(), list_item_clicked(), place(), remove_row(), select_row(), set_row_active(), set_row_shown(), and tlistbox().
Contains the builder for the new items.
Definition at line 272 of file listbox.hpp.
Referenced by add_row(), finalize(), and set_list_builder().
bool gui2::tlistbox::need_layout_ [private] |
Definition at line 283 of file listbox.hpp.
Referenced by layout_children(), and resize_content().
| Generated by doxygen 1.7.1 on Thu May 24 2012 01:23:02 for The Battle for Wesnoth | Gna! | Forum | Wiki | CIA | devdocs |