Author: mordante
Date: Mon Jun 23 20:23:30 2008
New Revision: 27447
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27447&view=rev
Log:
Added proof-of-conecpt hack to let the listbox do something when the arrow keys
are used and it has the keyboard focus.
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=27447&r1=27446&r2=27447&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.cpp (original)
+++ trunk/src/gui/widgets/listbox.cpp Mon Jun 23 20:23:30 2008
@@ -16,11 +16,13 @@
#include "foreach.hpp"
#include "gui/widgets/button.hpp"
+#include "gui/widgets/event_handler.hpp"
#include "gui/widgets/helper.hpp"
#include "gui/widgets/scrollbar.hpp"
#include "gui/widgets/spacer.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/toggle_panel.hpp"
+#include "gui/widgets/window.hpp"
#include "log.hpp"
#define DBG_G LOG_STREAM_INDENT(debug, gui)
@@ -89,8 +91,61 @@
{
}
+void tlistbox::mouse_left_button_down(tevent_handler& event)
+{
+ /**
+ * @todo We never get called since the mouse events are captured by our
+ * children.
+ */
+ DBG_G_E << "Listbox: left mouse button down.\n";
+
+ event.keyboard_capture(this);
+}
+
+void tlistbox::key_press(tevent_handler& /*event*/, bool& handled,
+ SDLKey key, SDLMod /*modifier*/, Uint16 /*unicode*/)
+{
+ DBG_G_E << "Listbox: key press.\n";
+
+ /**
+ * @todo Proof of concept only handles up and down and not too elegant.
+ * Ignores the modifiers and also whether or not rows are active. When
+ * moving out of visible range we don't scroll down and possibly more
minor
+ * glitches exist in this hack.
+ */
+ switch(key) {
+
+ case SDLK_UP : {
+
+ int i = get_selected_row() - 1;
+ if(i >= 0) {
+ select_row(i);
+ handled = true;
+ }
+ break;
+ }
+
+ case SDLK_DOWN : {
+
+ int i = get_selected_row() + 1;
+ if(i < rows_.size()) {
+ select_row(i);
+ handled = true;
+ }
+ break;
+ }
+
+ default :
+ /* DO NOTHING */
+ break;
+ }
+}
+
void tlistbox::list_item_selected(twidget* caller)
{
+ /** @todo Hack to capture the keyboard focus. */
+ get_window()->keyboard_capture(this);
+
for(unsigned i = 0; i < scrollbar()->get_visible_items(); ++i) {
const unsigned row = i + scrollbar()->get_item_position();
@@ -115,6 +170,9 @@
void tlistbox::scrollbar_click(twidget* caller)
{
+ /** @todo Hack to capture the keyboard focus. */
+ get_window()->keyboard_capture(this);
+
if(caller->id() == "_begin") {
scrollbar()->scroll(tscrollbar_::BEGIN);
} else if(caller->id() == "_line_up") {
Modified: trunk/src/gui/widgets/listbox.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gui/widgets/listbox.hpp?rev=27447&r1=27446&r2=27447&view=diff
==============================================================================
--- trunk/src/gui/widgets/listbox.hpp (original)
+++ trunk/src/gui/widgets/listbox.hpp Mon Jun 23 20:23:30 2008
@@ -41,6 +41,13 @@
void set_active(const bool active) { set_state(active ? ENABLED :
DISABLED); };
bool get_active() const { return state_ != DISABLED; }
unsigned get_state() const { return state_; }
+
+ /** Inherited from tevent_executor. */
+ void mouse_left_button_down(tevent_handler& event);
+
+ /** Inherited from tevent_executor. */
+ void key_press(tevent_handler& event, bool& handled,
+ SDLKey key, SDLMod modifier, Uint16 unicode);
/** Inherited from twidget. */
bool has_vertical_scrollbar() const { return true; }
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits