mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:37:46 +00:00
LibCore: Add CEvent and make LibGUI/GEvent inherit from it.
This commit is contained in:
parent
696ada2810
commit
b8062f69d8
31 changed files with 98 additions and 159 deletions
|
@ -1,22 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibCore/CEvent.h>
|
||||
#include <SharedGraphics/Point.h>
|
||||
#include <SharedGraphics/Rect.h>
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/Types.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <AK/Function.h>
|
||||
#include <Kernel/KeyCode.h>
|
||||
#include <LibGUI/GWindowType.h>
|
||||
|
||||
class GObject;
|
||||
|
||||
class GEvent {
|
||||
class GEvent : public CEvent{
|
||||
public:
|
||||
enum Type {
|
||||
Invalid = 0,
|
||||
Quit,
|
||||
Show,
|
||||
Show = 1000,
|
||||
Hide,
|
||||
Paint,
|
||||
Resize,
|
||||
|
@ -27,9 +22,6 @@ public:
|
|||
Leave,
|
||||
KeyDown,
|
||||
KeyUp,
|
||||
Timer,
|
||||
DeferredDestroy,
|
||||
DeferredInvoke,
|
||||
WindowEntered,
|
||||
WindowLeft,
|
||||
WindowBecameInactive,
|
||||
|
@ -37,37 +29,17 @@ public:
|
|||
FocusIn,
|
||||
FocusOut,
|
||||
WindowCloseRequest,
|
||||
ChildAdded,
|
||||
ChildRemoved,
|
||||
WM_WindowRemoved,
|
||||
WM_WindowStateChanged,
|
||||
};
|
||||
|
||||
GEvent() { }
|
||||
explicit GEvent(Type type) : m_type(type) { }
|
||||
explicit GEvent(Type type) : CEvent(type) { }
|
||||
virtual ~GEvent() { }
|
||||
|
||||
Type type() const { return m_type; }
|
||||
|
||||
bool is_mouse_event() const { return m_type == MouseMove || m_type == MouseDown || m_type == MouseUp; }
|
||||
bool is_key_event() const { return m_type == KeyUp || m_type == KeyDown; }
|
||||
bool is_paint_event() const { return m_type == Paint; }
|
||||
|
||||
private:
|
||||
Type m_type { Invalid };
|
||||
};
|
||||
|
||||
class GDeferredInvocationEvent : public GEvent {
|
||||
friend class GEventLoop;
|
||||
public:
|
||||
GDeferredInvocationEvent(Function<void(GObject&)> invokee)
|
||||
: GEvent(GEvent::Type::DeferredInvoke)
|
||||
, m_invokee(move(invokee))
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
Function<void(GObject&)> m_invokee;
|
||||
bool is_mouse_event() const { return type() == MouseMove || type() == MouseDown || type() == MouseUp; }
|
||||
bool is_key_event() const { return type() == KeyUp || type() == KeyDown; }
|
||||
bool is_paint_event() const { return type() == Paint; }
|
||||
};
|
||||
|
||||
class GWMEvent : public GEvent {
|
||||
|
@ -121,14 +93,6 @@ private:
|
|||
bool m_minimized;
|
||||
};
|
||||
|
||||
class QuitEvent final : public GEvent {
|
||||
public:
|
||||
QuitEvent()
|
||||
: GEvent(GEvent::Quit)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class GPaintEvent final : public GEvent {
|
||||
public:
|
||||
explicit GPaintEvent(const Rect& rect, const Size& window_size = Size())
|
||||
|
@ -233,26 +197,3 @@ private:
|
|||
GMouseButton m_button { GMouseButton::None };
|
||||
unsigned m_modifiers { 0 };
|
||||
};
|
||||
|
||||
class GTimerEvent final : public GEvent {
|
||||
public:
|
||||
explicit GTimerEvent(int timer_id) : GEvent(GEvent::Timer), m_timer_id(timer_id) { }
|
||||
~GTimerEvent() { }
|
||||
|
||||
int timer_id() const { return m_timer_id; }
|
||||
|
||||
private:
|
||||
int m_timer_id;
|
||||
};
|
||||
|
||||
class GChildEvent final : public GEvent {
|
||||
public:
|
||||
GChildEvent(Type, GObject& child);
|
||||
~GChildEvent();
|
||||
|
||||
GObject* child() { return m_child.ptr(); }
|
||||
const GObject* child() const { return m_child.ptr(); }
|
||||
|
||||
private:
|
||||
WeakPtr<GObject> m_child;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue