From 5d125e40d9b85d2c066c5f17bfccd48e52d6f40c Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Oct 2018 01:26:20 +0200 Subject: [PATCH] Deliver mouse events to the appropriate Window. --- Widgets/Window.cpp | 12 ++++++++++++ Widgets/Window.h | 4 +++- Widgets/WindowManager.cpp | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Widgets/Window.cpp b/Widgets/Window.cpp index aba80e3715..81fc780db7 100644 --- a/Widgets/Window.cpp +++ b/Widgets/Window.cpp @@ -1,5 +1,6 @@ #include "Window.h" #include "WindowManager.h" +#include "Event.h" Window::Window(Object* parent) : Object(parent) @@ -37,3 +38,14 @@ void Window::setRect(const Rect& rect) m_rect = rect; WindowManager::the().notifyRectChanged(*this, oldRect, m_rect); } + +void Window::event(Event& event) +{ + if (event.isMouseEvent()) { + auto& me = static_cast(event); + printf("Window{%p}: %s %d,%d\n", this, me.name(), me.x(), me.y()); + return Object::event(event); + } + + return Object::event(event); +} diff --git a/Widgets/Window.h b/Widgets/Window.h index 1d33d55505..1ce434c08c 100644 --- a/Widgets/Window.h +++ b/Widgets/Window.h @@ -6,7 +6,7 @@ class Widget; -class Window : public Object { +class Window final : public Object { public: explicit Window(Object* parent = nullptr); virtual ~Window() override; @@ -27,6 +27,8 @@ public: void setMainWidget(Widget*); + virtual void event(Event&) override; + private: String m_title; Rect m_rect; diff --git a/Widgets/WindowManager.cpp b/Widgets/WindowManager.cpp index 7bf9a196ec..84808a2d79 100644 --- a/Widgets/WindowManager.cpp +++ b/Widgets/WindowManager.cpp @@ -116,6 +116,7 @@ void WindowManager::processMouseEvent(MouseEvent& event) if (window->rect().contains(event.position())) { // FIXME: Re-use the existing event instead of crafting a new one? auto localEvent = make(event.type(), event.x() - window->rect().x(), event.y() - window->rect().y(), event.button()); + window->event(*localEvent); return; } }