1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00

GWidget: Add some new child z-ordering facilities.

- child_at(Point)
- move_to_front()
- move_to_back()
- is_frontmost()
- is_backmost()

This patch also makes it possible to receive the mouse event that triggers
a context menu before the context menu is shown. I'm not sure this is the
best design for context menus but it works for now.
This commit is contained in:
Andreas Kling 2019-04-16 03:47:55 +02:00
parent d31b47b371
commit 04500c1ae2
3 changed files with 69 additions and 7 deletions

View file

@ -42,8 +42,10 @@ 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>&&);
void set_context_menu(OwnPtr<GMenu>&&, ContextMenuMode = ContextMenuMode::SwallowMouseEvent);
virtual void event(CEvent&) override;
virtual void paint_event(GPaintEvent&);
@ -95,6 +97,8 @@ public:
};
HitTestResult hit_test(int x, int y);
GWidget* child_at(const Point&);
virtual const char* class_name() const override { return "GWidget"; }
void set_relative_rect(const Rect&);
@ -165,6 +169,12 @@ public:
bool is_greedy_for_hits() const { return m_greedy_for_hits; }
void set_greedy_for_hits(bool b) { m_greedy_for_hits = b; }
void move_to_front();
void move_to_back();
bool is_frontmost() const;
bool is_backmost() const;
private:
virtual bool is_widget() const final { return true; }
@ -196,4 +206,5 @@ private:
CElapsedTimer m_click_clock;
OwnPtr<GMenu> m_context_menu;
ContextMenuMode m_context_menu_mode { ContextMenuMode::SwallowMouseEvent };
};