1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-06 11:07:35 +00:00

LibGUI: Refactor context menus to be event-driven instead of declarative.

The declarative approach had way too many limitations. This patch adds a
context menu event that can be hooked to prepare a custom context menu on
demand just-in-time. :^)
This commit is contained in:
Andreas Kling 2019-04-18 04:12:27 +02:00
parent e74b5bc054
commit a747a10eab
5 changed files with 37 additions and 27 deletions

View file

@ -42,11 +42,6 @@ public:
bool is_enabled() const { return m_enabled; }
void set_enabled(bool);
enum class ContextMenuMode { SwallowMouseEvent, PassthroughMouseEvent };
const GMenu* context_menu() const { return m_context_menu.ptr(); }
void set_context_menu(OwnPtr<GMenu>&&, ContextMenuMode = ContextMenuMode::SwallowMouseEvent);
virtual void event(CEvent&) override;
virtual void paint_event(GPaintEvent&);
virtual void resize_event(GResizeEvent&);
@ -59,6 +54,7 @@ public:
virtual void mouseup_event(GMouseEvent&);
virtual void click_event(GMouseEvent&);
virtual void doubleclick_event(GMouseEvent&);
virtual void context_menu_event(GContextMenuEvent&);
virtual void focusin_event(CEvent&);
virtual void focusout_event(CEvent&);
virtual void enter_event(CEvent&);
@ -206,6 +202,4 @@ private:
bool m_enabled { true };
CElapsedTimer m_click_clock;
OwnPtr<GMenu> m_context_menu;
ContextMenuMode m_context_menu_mode { ContextMenuMode::SwallowMouseEvent };
};