From ba1c188f7a1850761eb7d63fbaaeece6dfb2a256 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 1 Feb 2011 00:55:40 +0200 Subject: Possible guichan mouseevent bug fix. --- src/gui/gui.cpp | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/gui.h | 4 +++ 2 files changed, 112 insertions(+) (limited to 'src') 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(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 mouseListeners + = widget->_getMouseListeners(); + + // Send the event to all mouse listeners of the widget. + for (std::list::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 */ -- cgit v1.2.3-60-g2f50