Author: mordante
Date: Fri Jul 25 21:10:49 2008
New Revision: 28197
URL: http://svn.gna.org/viewcvs/wesnoth?rev=28197&view=rev
Log:
Add a callback when the selection in a listbox changes.
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=28197&r1=28196&r2=28197&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.cpp (original)
+++ trunk/src/gui/widgets/listbox.cpp Fri Jul 25 21:10:49 2008
@@ -87,6 +87,7 @@
list_rect_(),
list_background_(),
best_spacer_size_(0, 0),
+ callback_value_change_(NULL),
rows_()
{
}
@@ -173,7 +174,11 @@
assert(rows_[row].grid());
if(rows_[row].grid()->has_widget(caller)) {
- if(!select_row(row, !rows_[row].get_selected())) {
+ if(select_row(row, !rows_[row].get_selected())) {
+ if(callback_value_change_) {
+ callback_value_change_(this);
+ }
+ } else {
// if not allowed to deselect reselect.
tselectable_* selectable =
dynamic_cast<tselectable_*>(caller);
assert(selectable);
Modified: trunk/src/gui/widgets/listbox.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.hpp?rev=28197&r1=28196&r2=28197&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.hpp (original)
+++ trunk/src/gui/widgets/listbox.hpp Fri Jul 25 21:10:49 2008
@@ -57,13 +57,19 @@
*/
void list_item_selected(twidget* caller);
+ /***** ***** ***** setters / getters for members ***** ****** *****/
+
+ void set_callback_value_change(void (*callback) (twidget* caller))
+ { callback_value_change_ = callback; }
+
private:
/**
* Helper for list_item_selected().
*
* Tries to sets the selected state for the row, but only if it
contains the
- * wanted widget.
+ * wanted widget. NOTE this function assumes the event was triggered by
the
+ * user and calls the callback handler.
*
* @param row The row to test.
* @param caller The widget to look for.
@@ -289,6 +295,13 @@
/** The best size for the spacer, if not set it's calculated. */
tpoint best_spacer_size_;
+ /**
+ * This callback is used when the selection is chnaged due to a user
event.
+ * The name is not fully appropriate for the event but it's choosen to
be
+ * generic.
+ */
+ void (*callback_value_change_) (twidget* caller);
+
class trow {
public:
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits