Author: mordante
Date: Sun May 18 19:28:31 2008
New Revision: 26706
URL: http://svn.gna.org/viewcvs/wesnoth?rev=26706&view=rev
Log:
Added the list() function to get the spacer area for the list.
Some cleanups in the unit.
Modified:
trunk/src/gui/widgets/listbox.cpp
trunk/src/gui/widgets/listbox.hpp
Modified: trunk/src/gui/widgets/listbox.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.cpp?rev=26706&r1=26705&r2=26706&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.cpp (original)
+++ trunk/src/gui/widgets/listbox.cpp Sun May 18 19:28:31 2008
@@ -175,8 +175,8 @@
}
}
} else {
- tspacer* spacer =
dynamic_cast<tspacer*>(tcontainer_::find_widget("_list", false));
- assert(spacer);
+ // Validate the existance.
+ tspacer* spacer = tlistbox::list();
}
scrollbar()->set_callback_positioner_move(callback_scrollbar);
@@ -238,33 +238,6 @@
// Set the scrollbar itself
scrollbar()->set_active(!(scrollbar()->at_begin() &&
scrollbar()->at_end()));
-}
-
-/**
- * Helper function to avoid a const problem.
- *
- * get_best_size is const but we use a spacer so we can use the generic
routine.
- * So we drop the const and set the size of the spacer, a bit and a cleaner
- * solution might be needed. We could make set_best_size() const but
- * get_widget_by_id is also not available in a const version.
- *
- * @param size The new size for the spacer.
- * @param const_grid The grid containing a spacer with id "_list".
- */
-static void set_spacer_size(const tpoint& size, const tgrid& const_grid)
-{
- tgrid& grid = const_cast<tgrid&>(const_grid);
-
- tspacer* spacer = dynamic_cast<tspacer*>(grid.find_widget("_list",
false));
- assert(spacer);
- spacer->set_best_size(size);
-}
-
-static tpoint get_spacer_size(const tgrid& grid)
-{
- const tspacer* spacer = dynamic_cast<const
tspacer*>(grid.find_widget("_list", false));
- assert(spacer);
- return spacer->get_best_size();
}
tpoint tlistbox::get_best_size() const
@@ -288,7 +261,12 @@
height += best_size.y;
}
}
- set_spacer_size(tpoint(width, height), grid());
+
+ // Kind of a hack, we edit the spacer in a const function.
+ // Of course we could cache the list and make it mutable instead.
+ // But since the spacer is a kind of cache the const_cast doesn't
+ // look too ugly.
+ const_cast<tspacer*>(list())->set_best_size(tpoint(width, height));
// Now the container will return the wanted result.
return tcontainer_::get_best_size();
@@ -336,7 +314,7 @@
const tpoint best_size = get_best_size();
if(best_size.y > rect.h) {
- best_spacer_size_ = get_spacer_size(grid());
+ best_spacer_size_ = list()->get_best_size();
best_spacer_size_.y -= (best_size.y - rect.h);
if(assume_fixed_row_size_) {
const unsigned row_height =
rows_[0].grid()->get_best_size().y;
@@ -356,8 +334,7 @@
best_spacer_size_ = tpoint(0, 0);
// Now set the items in the spacer.
- tspacer* spacer =
dynamic_cast<tspacer*>(tcontainer_::find_widget("_list", false));
- assert(spacer);
+ tspacer* spacer = list();
list_rect_ = spacer->get_rect();
foreach(trow& row, rows_) {
@@ -373,7 +350,7 @@
// FIXME we assume fixed row height atm.
if(rows_.size() > 0) {
- const unsigned rows = get_spacer_size(grid()).y /
rows_[0].get_height();
+ const unsigned rows = list()->get_best_size().y /
rows_[0].get_height();
scrollbar()->set_visible_items(rows);
} else {
scrollbar()->set_visible_items(1);
@@ -469,6 +446,22 @@
return result;
}
+tspacer* tlistbox::list()
+{
+ tspacer* list =
+ dynamic_cast<tspacer*>(tcontainer_::find_widget("_list",
false));
+ assert(list);
+ return list;
+}
+
+const tspacer* tlistbox::list() const
+{
+ const tspacer* list =
+ dynamic_cast<const tspacer*>(tcontainer_::find_widget("_list",
false));
+ assert(list);
+ return list;
+}
+
bool tlistbox::select_row(const unsigned row, const bool select)
{
if(!select && must_select_ && selection_count_ < 2) {
Modified: trunk/src/gui/widgets/listbox.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.hpp?rev=26706&r1=26705&r2=26706&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.hpp (original)
+++ trunk/src/gui/widgets/listbox.hpp Sun May 18 19:28:31 2008
@@ -22,6 +22,7 @@
namespace gui2 {
class tscrollbar_;
+class tspacer;
//! @todo list
//! header row + footer row same width as client data
@@ -157,6 +158,12 @@
/** Returns the scrollbar widget */
const tscrollbar_* scrollbar() const;
+ /** Returns the spacer widget which is used to reserve space of the
real list. */
+ tspacer* list();
+
+ /** Returns the spacer widget which is used to reserve space of the
real list. */
+ const tspacer* list() const;
+
bool assume_fixed_row_size_;
//! Inherited from tcontrol.
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits