From f74202392745923f9ce372a6bdcd0a45db6bcd08 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 4 Mar 2012 16:08:55 +0300 Subject: Fix possible crash in npc menu. --- src/gui/npcdialog.cpp | 2 +- src/gui/widgets/listbox.cpp | 10 ++++++++++ src/gui/widgets/listbox.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index dd9e79b46..12b3e1244 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -355,7 +355,7 @@ void NpcDialog::parseListItems(const std::string &itemString) void NpcDialog::refocus() { if (!mItems.empty()) - mItemList->requestFocus(); + mItemList->refocus(); } void NpcDialog::textRequest(const std::string &defaultText) diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 28fe9daa1..2944c5be6 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -29,6 +29,7 @@ #include "gui/sdlinput.h" #include "gui/theme.h" +#include #include #include #include @@ -149,3 +150,12 @@ void ListBox::mouseDragged(gcn::MouseEvent &event) if (getRowHeight()) setSelected(y / getRowHeight()); } + +void ListBox::refocus() +{ + if (!mFocusHandler) + return; + + if (isFocusable()) + mFocusHandler->requestFocus(this); +} diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index e4b6dd54e..1df07f19d 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -66,6 +66,8 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); + void refocus(); + protected: gcn::Color mHighlightColor; static float mAlpha; -- cgit v1.2.3-70-g09d2