summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-02-01 00:55:40 +0200
committerAndrei Karas <akaras@inbox.ru>2011-02-01 00:55:40 +0200
commitba1c188f7a1850761eb7d63fbaaeece6dfb2a256 (patch)
tree3a17e441504ebc5ad27d3851d9784acf966dd935
parenta37fd9c2a8340f3b861f9d9d74d0e940b1df102c (diff)
downloadmv-ba1c188f7a1850761eb7d63fbaaeece6dfb2a256.tar.gz
mv-ba1c188f7a1850761eb7d63fbaaeece6dfb2a256.tar.bz2
mv-ba1c188f7a1850761eb7d63fbaaeece6dfb2a256.tar.xz
mv-ba1c188f7a1850761eb7d63fbaaeece6dfb2a256.zip
Possible guichan mouseevent bug fix.
-rw-r--r--src/gui/gui.cpp108
-rw-r--r--src/gui/gui.h4
2 files changed, 112 insertions, 0 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 054e17584..984b9ea1a 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -308,3 +308,111 @@ void Gui::updateFonts()
static_cast<TrueTypeFont*>(boldFont)->loadFont(fontFile, fontSize);
}
+
+void Gui::distributeMouseEvent(gcn::Widget* source, int type, int button,
+ int x, int y, bool force,
+ bool toSourceOnly)
+{
+ if (!source || !mFocusHandler)
+ return;
+
+ gcn::Widget* parent = source;
+ gcn::Widget* widget = source;
+
+ if (!force && mFocusHandler->getModalFocused() != NULL
+ && !widget->isModalFocused())
+ {
+ return;
+ }
+
+ if (!force && mFocusHandler->getModalMouseInputFocused() != NULL
+ && !widget->isModalMouseInputFocused())
+ {
+ return;
+ }
+
+ while (parent != NULL)
+ {
+ // If the widget has been removed due to input
+ // cancel the distribution.
+ if (!gcn::Widget::widgetExists(widget))
+ break;
+
+ parent = (gcn::Widget*)widget->getParent();
+
+ if (widget->isEnabled() || force)
+ {
+ int widgetX, widgetY;
+ widget->getAbsolutePosition(widgetX, widgetY);
+
+ gcn::MouseEvent mouseEvent(source, mShiftPressed, mControlPressed,
+ mAltPressed, mMetaPressed, type, button,
+ x - widgetX, y - widgetY, mClickCount);
+
+ std::list<gcn::MouseListener*> mouseListeners
+ = widget->_getMouseListeners();
+
+ // Send the event to all mouse listeners of the widget.
+ for (std::list<gcn::MouseListener*>::iterator
+ it = mouseListeners.begin();
+ it != mouseListeners.end(); ++ it)
+ {
+ switch (mouseEvent.getType())
+ {
+ case gcn::MouseEvent::ENTERED:
+ (*it)->mouseEntered(mouseEvent);
+ break;
+ case gcn::MouseEvent::EXITED:
+ (*it)->mouseExited(mouseEvent);
+ break;
+ case gcn::MouseEvent::MOVED:
+ (*it)->mouseMoved(mouseEvent);
+ break;
+ case gcn::MouseEvent::PRESSED:
+ (*it)->mousePressed(mouseEvent);
+ break;
+ case gcn::MouseEvent::RELEASED:
+ (*it)->mouseReleased(mouseEvent);
+ break;
+ case gcn::MouseEvent::WHEEL_MOVED_UP:
+ (*it)->mouseWheelMovedUp(mouseEvent);
+ break;
+ case gcn::MouseEvent::WHEEL_MOVED_DOWN:
+ (*it)->mouseWheelMovedDown(mouseEvent);
+ break;
+ case gcn::MouseEvent::DRAGGED:
+ (*it)->mouseDragged(mouseEvent);
+ break;
+ case gcn::MouseEvent::CLICKED:
+ (*it)->mouseClicked(mouseEvent);
+ break;
+ default:
+ throw GCN_EXCEPTION("Unknown mouse event type.");
+ }
+ }
+
+ if (toSourceOnly)
+ break;
+ }
+
+ gcn::Widget* swap = widget;
+ widget = parent;
+ parent = (gcn::Widget*)swap->getParent();
+
+ // If a non modal focused widget has been reach
+ // and we have modal focus cancel the distribution.
+ if (mFocusHandler->getModalFocused() != NULL
+ && !widget->isModalFocused())
+ {
+ break;
+ }
+
+ // If a non modal mouse input focused widget has been reach
+ // and we have modal mouse input focus cancel the distribution.
+ if (mFocusHandler->getModalMouseInputFocused() != NULL
+ && !widget->isModalMouseInputFocused())
+ {
+ break;
+ }
+ }
+}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index b4ddfc299..5daa90232 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -125,6 +125,10 @@ class Gui : public gcn::Gui
protected:
void handleMouseMoved(const gcn::MouseInput &mouseInput);
+ void distributeMouseEvent(gcn::Widget* source, int type, int button,
+ int x, int y, bool force = false,
+ bool toSourceOnly = false);
+
private:
GuiConfigListener *mConfigListener;
gcn::Font *mGuiFont; /**< The global GUI font */