1 |
From f74202392745923f9ce372a6bdcd0a45db6bcd08 Mon Sep 17 00:00:00 2001 |
2 |
From: Andrei Karas <akaras@inbox.ru> |
3 |
Date: Sun, 4 Mar 2012 16:08:55 +0300 |
4 |
Subject: [PATCH] Fix possible crash in npc menu. |
5 |
|
6 |
--- |
7 |
src/gui/npcdialog.cpp | 2 +- |
8 |
src/gui/widgets/listbox.cpp | 10 ++++++++++ |
9 |
src/gui/widgets/listbox.h | 2 ++ |
10 |
3 files changed, 13 insertions(+), 1 deletions(-) |
11 |
|
12 |
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp |
13 |
index dd9e79b..12b3e12 100644 |
14 |
--- a/src/gui/npcdialog.cpp |
15 |
+++ b/src/gui/npcdialog.cpp |
16 |
@@ -355,7 +355,7 @@ void NpcDialog::parseListItems(const std::string &itemString) |
17 |
void NpcDialog::refocus() |
18 |
{ |
19 |
if (!mItems.empty()) |
20 |
- mItemList->requestFocus(); |
21 |
+ mItemList->refocus(); |
22 |
} |
23 |
|
24 |
void NpcDialog::textRequest(const std::string &defaultText) |
25 |
diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp |
26 |
index 28fe9da..2944c5b 100644 |
27 |
--- a/src/gui/widgets/listbox.cpp |
28 |
+++ b/src/gui/widgets/listbox.cpp |
29 |
@@ -29,6 +29,7 @@ |
30 |
#include "gui/sdlinput.h" |
31 |
#include "gui/theme.h" |
32 |
|
33 |
+#include <guichan/focushandler.hpp> |
34 |
#include <guichan/font.hpp> |
35 |
#include <guichan/graphics.hpp> |
36 |
#include <guichan/key.hpp> |
37 |
@@ -149,3 +150,12 @@ void ListBox::mouseDragged(gcn::MouseEvent &event) |
38 |
if (getRowHeight()) |
39 |
setSelected(y / getRowHeight()); |
40 |
} |
41 |
+ |
42 |
+void ListBox::refocus() |
43 |
+{ |
44 |
+ if (!mFocusHandler) |
45 |
+ return; |
46 |
+ |
47 |
+ if (isFocusable()) |
48 |
+ mFocusHandler->requestFocus(this); |
49 |
+} |
50 |
diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h |
51 |
index e4b6dd5..1df07f1 100644 |
52 |
--- a/src/gui/widgets/listbox.h |
53 |
+++ b/src/gui/widgets/listbox.h |
54 |
@@ -66,6 +66,8 @@ class ListBox : public gcn::ListBox |
55 |
|
56 |
void mouseDragged(gcn::MouseEvent &event); |
57 |
|
58 |
+ void refocus(); |
59 |
+ |
60 |
protected: |
61 |
gcn::Color mHighlightColor; |
62 |
static float mAlpha; |
63 |
-- |
64 |
1.7.6 |
65 |
|