Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Friends

gui2::tlistbox Class Reference

The listbox class. More...

#include <listbox.hpp>

Inheritance diagram for gui2::tlistbox:
Inheritance graph
[legend]
Collaboration diagram for gui2::tlistbox:
Collaboration graph
[legend]

List of all members.

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 tgridget_row_grid (const unsigned row) const
 Returns the grid of the wanted row.
tgridget_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

Detailed Description

The listbox class.

Definition at line 32 of file listbox.hpp.


Constructor & Destructor Documentation

gui2::tlistbox::tlistbox ( const bool  has_minimum,
const bool  has_maximum,
const tgenerator_::tplacement  placement,
const bool  select 
)

Constructor.

Parameters:
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_.

Here is the call graph for this function:


Member Function Documentation

void gui2::tlistbox::add_row ( const string_map item,
const int  index = -1 
)
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).

Parameters:
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_.

Here is the call graph for this function:

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().

Here is the call graph for this function:

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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Todo:
A listbox must have the following config parameters in the instanciation:
  • fixed row height?
  • fixed column width? and if so the following ways to set them
  • fixed depending on header ids
  • fixed depending on footer ids
  • fixed depending on first row ids
  • fixed depending on list (the user has to enter a list of ids)

For now it's always fixed width depending on the first row.

Parameters:
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_.

Here is the call graph for this function:

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
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).

Parameters:
row The row to get the grid from, the caller has to make sure the row is a valid row.
Returns:
The grid of the wanted 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().

Here is the call graph for this function:

Here is the caller graph for this function:

tgrid * gui2::tlistbox::get_row_grid ( const unsigned  row  ) 

The possibly-giving-problems nonconst version of get_row_grid.

Parameters:
row The row to get the grid from, the caller has to make sure the row is a valid row.
Returns:
The grid of the wanted row.

Definition at line 194 of file listbox.cpp.

References generator_, and gui2::tgenerator_::item().

Here is the call graph for this function:

int gui2::tlistbox::get_selected_row (  )  const
void gui2::tlistbox::handle_key_down_arrow ( SDLMod  modifier,
bool &  handled 
) [protected, virtual]
void gui2::tlistbox::handle_key_left_arrow ( SDLMod  modifier,
bool &  handled 
) [protected, virtual]
void gui2::tlistbox::handle_key_right_arrow ( SDLMod  modifier,
bool &  handled 
) [protected, virtual]
void gui2::tlistbox::handle_key_up_arrow ( SDLMod  modifier,
bool &  handled 
) [protected, virtual]
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]
void gui2::tlistbox::list_item_clicked ( twidget caller  ) 

Function to call after the user clicked on a row.

Todo:
Hack to capture the keyboard focus.

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().

Here is the call graph for this function:

void gui2::tlistbox::place ( const tpoint origin,
const tpoint size 
) [virtual]

Inherited from tscrollbar_container.

Todo:
Work-around to set the selected item visible again.

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().

Here is the call graph for this function:

void gui2::tlistbox::remove_row ( const unsigned  row,
unsigned  count = 1 
)

Removes a row in the listbox.

Parameters:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
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().

Here is the call graph for this function:

Here is the caller graph for this function:

bool gui2::tlistbox::select_row ( const unsigned  row,
const bool  select = true 
)
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().

Here is the caller graph for this function:

void gui2::tlistbox::set_content_size ( const tpoint origin,
const tpoint size 
) [private, virtual]

Inherited from tscrollbar_container.

Todo:
This function needs more testing.

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.

Here is the call graph for this function:

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.

Parameters:
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().

Here is the call graph for this function:

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.

Parameters:
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().

Here is the call graph for this function:

void gui2::tlistbox::set_row_shown ( const unsigned  row,
const bool  shown 
)
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().

Note:
Calling this function on a widget with size == (0, 0) results false but doesn't call invalidate_layout, the engine expects to be in build up phase with the layout already invalidated.
Returns:
True if the resizing succeeded, false otherwise.

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().

Here is the call graph for this function:


Friends And Related Function Documentation

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.


Member Data Documentation

This callback is called when the value in the listbox changes.

Todo:
the implementation of the callback hasn't been tested a lot and there might be too many calls. That might happen if an arrow up didn't change the selected item.

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().

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().

Definition at line 283 of file listbox.hpp.

Referenced by layout_children(), and resize_content().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Thu May 24 2012 01:23:02 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs