mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:37:35 +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
|
@ -97,7 +97,7 @@ void MemoryStatsWidget::refresh()
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryStatsWidget::timer_event(GTimerEvent&)
|
void MemoryStatsWidget::timer_event(CTimerEvent&)
|
||||||
{
|
{
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ public:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void timer_event(GTimerEvent&) override;
|
virtual void timer_event(CTimerEvent&) override;
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
|
|
||||||
GLabel* m_user_physical_pages_label { nullptr };
|
GLabel* m_user_physical_pages_label { nullptr };
|
||||||
|
|
|
@ -16,7 +16,7 @@ ProcessTableView::~ProcessTableView()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessTableView::timer_event(GTimerEvent&)
|
void ProcessTableView::timer_event(CTimerEvent&)
|
||||||
{
|
{
|
||||||
model()->update();
|
model()->update();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,6 @@ protected:
|
||||||
virtual void model_notification(const GModelNotification&) override;
|
virtual void model_notification(const GModelNotification&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void timer_event(GTimerEvent&) override;
|
virtual void timer_event(CTimerEvent&) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -726,7 +726,7 @@ bool Terminal::Line::has_only_one_background_color() const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Terminal::event(GEvent& event)
|
void Terminal::event(CEvent& event)
|
||||||
{
|
{
|
||||||
if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) {
|
if (event.type() == GEvent::WindowBecameActive || event.type() == GEvent::WindowBecameInactive) {
|
||||||
m_in_active_window = event.type() == GEvent::WindowBecameActive;
|
m_in_active_window = event.type() == GEvent::WindowBecameActive;
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void apply_size_increments_to_window(GWindow&);
|
void apply_size_increments_to_window(GWindow&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void event(GEvent&) override;
|
virtual void event(CEvent&) override;
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void resize_event(GResizeEvent&) override;
|
virtual void resize_event(GResizeEvent&) override;
|
||||||
virtual void keydown_event(GKeyEvent&) override;
|
virtual void keydown_event(GKeyEvent&) override;
|
||||||
|
|
12
LibCore/CEvent.cpp
Normal file
12
LibCore/CEvent.cpp
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#include <LibCore/CEvent.h>
|
||||||
|
#include <LibGUI/GObject.h>
|
||||||
|
|
||||||
|
CChildEvent::CChildEvent(Type type, GObject& child)
|
||||||
|
: CEvent(type)
|
||||||
|
, m_child(child.make_weak_ptr())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
CChildEvent::~CChildEvent()
|
||||||
|
{
|
||||||
|
}
|
|
@ -1,7 +1,6 @@
|
||||||
OBJS = \
|
OBJS = \
|
||||||
CElapsedTimer.o
|
CElapsedTimer.o \
|
||||||
|
CEvent.o
|
||||||
LIBS =
|
|
||||||
|
|
||||||
LIBRARY = libcore.a
|
LIBRARY = libcore.a
|
||||||
STANDARD_FLAGS = -std=c++17 -Wno-sized-deallocation
|
STANDARD_FLAGS = -std=c++17 -Wno-sized-deallocation
|
||||||
|
|
|
@ -97,13 +97,13 @@ void GButton::mouseup_event(GMouseEvent& event)
|
||||||
GWidget::mouseup_event(event);
|
GWidget::mouseup_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GButton::enter_event(GEvent&)
|
void GButton::enter_event(CEvent&)
|
||||||
{
|
{
|
||||||
m_hovered = true;
|
m_hovered = true;
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GButton::leave_event(GEvent&)
|
void GButton::leave_event(CEvent&)
|
||||||
{
|
{
|
||||||
m_hovered = false;
|
m_hovered = false;
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -42,8 +42,8 @@ private:
|
||||||
virtual void mousedown_event(GMouseEvent&) override;
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
virtual void mouseup_event(GMouseEvent&) override;
|
virtual void mouseup_event(GMouseEvent&) override;
|
||||||
virtual void mousemove_event(GMouseEvent&) override;
|
virtual void mousemove_event(GMouseEvent&) override;
|
||||||
virtual void enter_event(GEvent&) override;
|
virtual void enter_event(CEvent&) override;
|
||||||
virtual void leave_event(GEvent&) override;
|
virtual void leave_event(CEvent&) override;
|
||||||
|
|
||||||
String m_caption;
|
String m_caption;
|
||||||
RetainPtr<GraphicsBitmap> m_icon;
|
RetainPtr<GraphicsBitmap> m_icon;
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
#include <LibGUI/GEvent.h>
|
|
||||||
#include <LibGUI/GObject.h>
|
|
||||||
|
|
||||||
GChildEvent::GChildEvent(Type type, GObject& child)
|
|
||||||
: GEvent(type)
|
|
||||||
, m_child(child.make_weak_ptr())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
GChildEvent::~GChildEvent()
|
|
||||||
{
|
|
||||||
}
|
|
|
@ -1,22 +1,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibCore/CEvent.h>
|
||||||
#include <SharedGraphics/Point.h>
|
#include <SharedGraphics/Point.h>
|
||||||
#include <SharedGraphics/Rect.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 <Kernel/KeyCode.h>
|
||||||
#include <LibGUI/GWindowType.h>
|
#include <LibGUI/GWindowType.h>
|
||||||
|
|
||||||
class GObject;
|
class GObject;
|
||||||
|
|
||||||
class GEvent {
|
class GEvent : public CEvent{
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
Invalid = 0,
|
Show = 1000,
|
||||||
Quit,
|
|
||||||
Show,
|
|
||||||
Hide,
|
Hide,
|
||||||
Paint,
|
Paint,
|
||||||
Resize,
|
Resize,
|
||||||
|
@ -27,9 +22,6 @@ public:
|
||||||
Leave,
|
Leave,
|
||||||
KeyDown,
|
KeyDown,
|
||||||
KeyUp,
|
KeyUp,
|
||||||
Timer,
|
|
||||||
DeferredDestroy,
|
|
||||||
DeferredInvoke,
|
|
||||||
WindowEntered,
|
WindowEntered,
|
||||||
WindowLeft,
|
WindowLeft,
|
||||||
WindowBecameInactive,
|
WindowBecameInactive,
|
||||||
|
@ -37,37 +29,17 @@ public:
|
||||||
FocusIn,
|
FocusIn,
|
||||||
FocusOut,
|
FocusOut,
|
||||||
WindowCloseRequest,
|
WindowCloseRequest,
|
||||||
ChildAdded,
|
|
||||||
ChildRemoved,
|
|
||||||
WM_WindowRemoved,
|
WM_WindowRemoved,
|
||||||
WM_WindowStateChanged,
|
WM_WindowStateChanged,
|
||||||
};
|
};
|
||||||
|
|
||||||
GEvent() { }
|
GEvent() { }
|
||||||
explicit GEvent(Type type) : m_type(type) { }
|
explicit GEvent(Type type) : CEvent(type) { }
|
||||||
virtual ~GEvent() { }
|
virtual ~GEvent() { }
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
bool is_mouse_event() const { return type() == MouseMove || type() == MouseDown || type() == MouseUp; }
|
||||||
|
bool is_key_event() const { return type() == KeyUp || type() == KeyDown; }
|
||||||
bool is_mouse_event() const { return m_type == MouseMove || m_type == MouseDown || m_type == MouseUp; }
|
bool is_paint_event() const { return type() == Paint; }
|
||||||
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;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class GWMEvent : public GEvent {
|
class GWMEvent : public GEvent {
|
||||||
|
@ -121,14 +93,6 @@ private:
|
||||||
bool m_minimized;
|
bool m_minimized;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QuitEvent final : public GEvent {
|
|
||||||
public:
|
|
||||||
QuitEvent()
|
|
||||||
: GEvent(GEvent::Quit)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class GPaintEvent final : public GEvent {
|
class GPaintEvent final : public GEvent {
|
||||||
public:
|
public:
|
||||||
explicit GPaintEvent(const Rect& rect, const Size& window_size = Size())
|
explicit GPaintEvent(const Rect& rect, const Size& window_size = Size())
|
||||||
|
@ -233,26 +197,3 @@ private:
|
||||||
GMouseButton m_button { GMouseButton::None };
|
GMouseButton m_button { GMouseButton::None };
|
||||||
unsigned m_modifiers { 0 };
|
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;
|
|
||||||
};
|
|
||||||
|
|
|
@ -153,15 +153,15 @@ int GEventLoop::exec()
|
||||||
#endif
|
#endif
|
||||||
if (!receiver) {
|
if (!receiver) {
|
||||||
switch (event.type()) {
|
switch (event.type()) {
|
||||||
case GEvent::Quit:
|
case CEvent::Quit:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
return 0;
|
return 0;
|
||||||
default:
|
default:
|
||||||
dbgprintf("Event type %u with no receiver :(\n", event.type());
|
dbgprintf("Event type %u with no receiver :(\n", event.type());
|
||||||
}
|
}
|
||||||
} else if (event.type() == GEvent::Type::DeferredInvoke) {
|
} else if (event.type() == CEvent::Type::DeferredInvoke) {
|
||||||
printf("DeferredInvoke: receiver=%s{%p}\n", receiver->class_name(), receiver);
|
printf("DeferredInvoke: receiver=%s{%p}\n", receiver->class_name(), receiver);
|
||||||
static_cast<GDeferredInvocationEvent&>(event).m_invokee(*receiver);
|
static_cast<CDeferredInvocationEvent&>(event).m_invokee(*receiver);
|
||||||
} else {
|
} else {
|
||||||
receiver->event(event);
|
receiver->event(event);
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ int GEventLoop::exec()
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GEventLoop::post_event(GObject& receiver, OwnPtr<GEvent>&& event)
|
void GEventLoop::post_event(GObject& receiver, OwnPtr<CEvent>&& event)
|
||||||
{
|
{
|
||||||
#ifdef GEVENTLOOP_DEBUG
|
#ifdef GEVENTLOOP_DEBUG
|
||||||
dbgprintf("GEventLoop::post_event: {%u} << receiver=%p, event=%p\n", m_queued_events.size(), &receiver, event.ptr());
|
dbgprintf("GEventLoop::post_event: {%u} << receiver=%p, event=%p\n", m_queued_events.size(), &receiver, event.ptr());
|
||||||
|
@ -322,9 +322,9 @@ void GEventLoop::wait_for_event()
|
||||||
if (!timer.has_expired())
|
if (!timer.has_expired())
|
||||||
continue;
|
continue;
|
||||||
#ifdef GEVENTLOOP_DEBUG
|
#ifdef GEVENTLOOP_DEBUG
|
||||||
dbgprintf("GEventLoop: Timer %d has expired, sending GTimerEvent to %p\n", timer.timer_id, timer.owner);
|
dbgprintf("GEventLoop: Timer %d has expired, sending CTimerEvent to %p\n", timer.timer_id, timer.owner);
|
||||||
#endif
|
#endif
|
||||||
post_event(*timer.owner, make<GTimerEvent>(timer.timer_id));
|
post_event(*timer.owner, make<CTimerEvent>(timer.timer_id));
|
||||||
if (timer.should_reload) {
|
if (timer.should_reload) {
|
||||||
timer.reload();
|
timer.reload();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -20,7 +20,7 @@ public:
|
||||||
|
|
||||||
int exec();
|
int exec();
|
||||||
|
|
||||||
void post_event(GObject& receiver, OwnPtr<GEvent>&&);
|
void post_event(GObject& receiver, OwnPtr<CEvent>&&);
|
||||||
|
|
||||||
static GEventLoop& main();
|
static GEventLoop& main();
|
||||||
static GEventLoop& current();
|
static GEventLoop& current();
|
||||||
|
@ -66,7 +66,7 @@ private:
|
||||||
|
|
||||||
struct QueuedEvent {
|
struct QueuedEvent {
|
||||||
WeakPtr<GObject> receiver;
|
WeakPtr<GObject> receiver;
|
||||||
OwnPtr<GEvent> event;
|
OwnPtr<CEvent> event;
|
||||||
};
|
};
|
||||||
Vector<QueuedEvent> m_queued_events;
|
Vector<QueuedEvent> m_queued_events;
|
||||||
|
|
||||||
|
|
|
@ -21,17 +21,17 @@ GObject::~GObject()
|
||||||
delete child;
|
delete child;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GObject::event(GEvent& event)
|
void GObject::event(CEvent& event)
|
||||||
{
|
{
|
||||||
switch (event.type()) {
|
switch (event.type()) {
|
||||||
case GEvent::Timer:
|
case GEvent::Timer:
|
||||||
return timer_event(static_cast<GTimerEvent&>(event));
|
return timer_event(static_cast<CTimerEvent&>(event));
|
||||||
case GEvent::DeferredDestroy:
|
case GEvent::DeferredDestroy:
|
||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
case GEvent::ChildAdded:
|
case GEvent::ChildAdded:
|
||||||
case GEvent::ChildRemoved:
|
case GEvent::ChildRemoved:
|
||||||
return child_event(static_cast<GChildEvent&>(event));
|
return child_event(static_cast<CChildEvent&>(event));
|
||||||
case GEvent::Invalid:
|
case GEvent::Invalid:
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
break;
|
break;
|
||||||
|
@ -43,7 +43,7 @@ void GObject::event(GEvent& event)
|
||||||
void GObject::add_child(GObject& object)
|
void GObject::add_child(GObject& object)
|
||||||
{
|
{
|
||||||
m_children.append(&object);
|
m_children.append(&object);
|
||||||
GEventLoop::current().post_event(*this, make<GChildEvent>(GEvent::ChildAdded, object));
|
GEventLoop::current().post_event(*this, make<CChildEvent>(GEvent::ChildAdded, object));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GObject::remove_child(GObject& object)
|
void GObject::remove_child(GObject& object)
|
||||||
|
@ -51,17 +51,17 @@ void GObject::remove_child(GObject& object)
|
||||||
for (ssize_t i = 0; i < m_children.size(); ++i) {
|
for (ssize_t i = 0; i < m_children.size(); ++i) {
|
||||||
if (m_children[i] == &object) {
|
if (m_children[i] == &object) {
|
||||||
m_children.remove(i);
|
m_children.remove(i);
|
||||||
GEventLoop::current().post_event(*this, make<GChildEvent>(GEvent::ChildRemoved, object));
|
GEventLoop::current().post_event(*this, make<CChildEvent>(GEvent::ChildRemoved, object));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GObject::timer_event(GTimerEvent&)
|
void GObject::timer_event(CTimerEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GObject::child_event(GChildEvent&)
|
void GObject::child_event(CChildEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +86,7 @@ void GObject::stop_timer()
|
||||||
|
|
||||||
void GObject::delete_later()
|
void GObject::delete_later()
|
||||||
{
|
{
|
||||||
GEventLoop::current().post_event(*this, make<GEvent>(GEvent::DeferredDestroy));
|
GEventLoop::current().post_event(*this, make<CEvent>(CEvent::DeferredDestroy));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GObject::dump_tree(int indent)
|
void GObject::dump_tree(int indent)
|
||||||
|
@ -103,5 +103,5 @@ void GObject::dump_tree(int indent)
|
||||||
|
|
||||||
void GObject::deferred_invoke(Function<void(GObject&)> invokee)
|
void GObject::deferred_invoke(Function<void(GObject&)> invokee)
|
||||||
{
|
{
|
||||||
GEventLoop::current().post_event(*this, make<GDeferredInvocationEvent>(move(invokee)));
|
GEventLoop::current().post_event(*this, make<CDeferredInvocationEvent>(move(invokee)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#include <AK/Weakable.h>
|
#include <AK/Weakable.h>
|
||||||
|
|
||||||
class GEvent;
|
class CEvent;
|
||||||
class GChildEvent;
|
class CChildEvent;
|
||||||
class GTimerEvent;
|
class CTimerEvent;
|
||||||
|
|
||||||
class GObject : public Weakable<GObject> {
|
class GObject : public Weakable<GObject> {
|
||||||
public:
|
public:
|
||||||
|
@ -15,7 +15,7 @@ public:
|
||||||
|
|
||||||
virtual const char* class_name() const { return "GObject"; }
|
virtual const char* class_name() const { return "GObject"; }
|
||||||
|
|
||||||
virtual void event(GEvent&);
|
virtual void event(CEvent&);
|
||||||
|
|
||||||
Vector<GObject*>& children() { return m_children; }
|
Vector<GObject*>& children() { return m_children; }
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ public:
|
||||||
virtual bool is_window() const { return false; }
|
virtual bool is_window() const { return false; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void timer_event(GTimerEvent&);
|
virtual void timer_event(CTimerEvent&);
|
||||||
virtual void child_event(GChildEvent&);
|
virtual void child_event(CChildEvent&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GObject* m_parent { nullptr };
|
GObject* m_parent { nullptr };
|
||||||
|
|
|
@ -293,7 +293,7 @@ void GScrollBar::mousemove_event(GMouseEvent& event)
|
||||||
set_value(new_value);
|
set_value(new_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GScrollBar::leave_event(GEvent&)
|
void GScrollBar::leave_event(CEvent&)
|
||||||
{
|
{
|
||||||
if (m_hovered_component != Component::Invalid) {
|
if (m_hovered_component != Component::Invalid) {
|
||||||
m_hovered_component = Component::Invalid;
|
m_hovered_component = Component::Invalid;
|
||||||
|
|
|
@ -39,7 +39,7 @@ private:
|
||||||
virtual void mousedown_event(GMouseEvent&) override;
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
virtual void mouseup_event(GMouseEvent&) override;
|
virtual void mouseup_event(GMouseEvent&) override;
|
||||||
virtual void mousemove_event(GMouseEvent&) override;
|
virtual void mousemove_event(GMouseEvent&) override;
|
||||||
virtual void leave_event(GEvent&) override;
|
virtual void leave_event(CEvent&) override;
|
||||||
|
|
||||||
int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); }
|
int button_size() const { return orientation() == Orientation::Vertical ? width() : height(); }
|
||||||
Rect up_button_rect() const;
|
Rect up_button_rect() const;
|
||||||
|
|
|
@ -16,14 +16,14 @@ GSplitter::~GSplitter()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSplitter::enter_event(GEvent&)
|
void GSplitter::enter_event(CEvent&)
|
||||||
{
|
{
|
||||||
set_background_color(Color::from_rgb(0xd6d2ce));
|
set_background_color(Color::from_rgb(0xd6d2ce));
|
||||||
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? GStandardCursor::ResizeHorizontal : GStandardCursor::ResizeVertical);
|
window()->set_override_cursor(m_orientation == Orientation::Horizontal ? GStandardCursor::ResizeHorizontal : GStandardCursor::ResizeVertical);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GSplitter::leave_event(GEvent&)
|
void GSplitter::leave_event(CEvent&)
|
||||||
{
|
{
|
||||||
set_background_color(Color::LightGray);
|
set_background_color(Color::LightGray);
|
||||||
if (!m_resizing)
|
if (!m_resizing)
|
||||||
|
|
|
@ -11,8 +11,8 @@ protected:
|
||||||
virtual void mousedown_event(GMouseEvent&) override;
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
virtual void mousemove_event(GMouseEvent&) override;
|
virtual void mousemove_event(GMouseEvent&) override;
|
||||||
virtual void mouseup_event(GMouseEvent&) override;
|
virtual void mouseup_event(GMouseEvent&) override;
|
||||||
virtual void enter_event(GEvent&) override;
|
virtual void enter_event(CEvent&) override;
|
||||||
virtual void leave_event(GEvent&) override;
|
virtual void leave_event(CEvent&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Orientation m_orientation;
|
Orientation m_orientation;
|
||||||
|
|
|
@ -31,7 +31,7 @@ void GStackWidget::resize_event(GResizeEvent& event)
|
||||||
m_active_widget->set_relative_rect({ { }, event.size() });
|
m_active_widget->set_relative_rect({ { }, event.size() });
|
||||||
}
|
}
|
||||||
|
|
||||||
void GStackWidget::child_event(GChildEvent& event)
|
void GStackWidget::child_event(CChildEvent& event)
|
||||||
{
|
{
|
||||||
if (!event.child() || !event.child()->is_widget())
|
if (!event.child() || !event.child()->is_widget())
|
||||||
return GWidget::child_event(event);
|
return GWidget::child_event(event);
|
||||||
|
|
|
@ -13,7 +13,7 @@ public:
|
||||||
virtual const char* class_name() const override { return "GStackWidget"; }
|
virtual const char* class_name() const override { return "GStackWidget"; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void child_event(GChildEvent&) override;
|
virtual void child_event(CChildEvent&) override;
|
||||||
virtual void resize_event(GResizeEvent&) override;
|
virtual void resize_event(GResizeEvent&) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -564,18 +564,18 @@ void GTextEditor::set_cursor(const GTextPosition& position)
|
||||||
on_cursor_change();
|
on_cursor_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::focusin_event(GEvent&)
|
void GTextEditor::focusin_event(CEvent&)
|
||||||
{
|
{
|
||||||
update_cursor();
|
update_cursor();
|
||||||
start_timer(500);
|
start_timer(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::focusout_event(GEvent&)
|
void GTextEditor::focusout_event(CEvent&)
|
||||||
{
|
{
|
||||||
stop_timer();
|
stop_timer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::timer_event(GTimerEvent&)
|
void GTextEditor::timer_event(CTimerEvent&)
|
||||||
{
|
{
|
||||||
m_cursor_state = !m_cursor_state;
|
m_cursor_state = !m_cursor_state;
|
||||||
if (is_focused())
|
if (is_focused())
|
||||||
|
@ -805,13 +805,13 @@ void GTextEditor::paste()
|
||||||
insert_at_cursor_or_replace_selection(paste_text);
|
insert_at_cursor_or_replace_selection(paste_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::enter_event(GEvent&)
|
void GTextEditor::enter_event(CEvent&)
|
||||||
{
|
{
|
||||||
ASSERT(window());
|
ASSERT(window());
|
||||||
window()->set_override_cursor(GStandardCursor::IBeam);
|
window()->set_override_cursor(GStandardCursor::IBeam);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTextEditor::leave_event(GEvent&)
|
void GTextEditor::leave_event(CEvent&)
|
||||||
{
|
{
|
||||||
ASSERT(window());
|
ASSERT(window());
|
||||||
window()->set_override_cursor(GStandardCursor::None);
|
window()->set_override_cursor(GStandardCursor::None);
|
||||||
|
|
|
@ -108,12 +108,12 @@ private:
|
||||||
virtual void mouseup_event(GMouseEvent&) override;
|
virtual void mouseup_event(GMouseEvent&) override;
|
||||||
virtual void mousemove_event(GMouseEvent&) override;
|
virtual void mousemove_event(GMouseEvent&) override;
|
||||||
virtual void keydown_event(GKeyEvent&) override;
|
virtual void keydown_event(GKeyEvent&) override;
|
||||||
virtual void focusin_event(GEvent&) override;
|
virtual void focusin_event(CEvent&) override;
|
||||||
virtual void focusout_event(GEvent&) override;
|
virtual void focusout_event(CEvent&) override;
|
||||||
virtual void timer_event(GTimerEvent&) override;
|
virtual void timer_event(CTimerEvent&) override;
|
||||||
virtual bool accepts_focus() const override { return true; }
|
virtual bool accepts_focus() const override { return true; }
|
||||||
virtual void enter_event(GEvent&) override;
|
virtual void enter_event(CEvent&) override;
|
||||||
virtual void leave_event(GEvent&) override;
|
virtual void leave_event(CEvent&) override;
|
||||||
|
|
||||||
void paint_ruler(Painter&);
|
void paint_ruler(Painter&);
|
||||||
void update_content_size();
|
void update_content_size();
|
||||||
|
|
|
@ -30,7 +30,7 @@ void GTimer::stop()
|
||||||
m_active = false;
|
m_active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GTimer::timer_event(GTimerEvent&)
|
void GTimer::timer_event(CTimerEvent&)
|
||||||
{
|
{
|
||||||
if (m_single_shot)
|
if (m_single_shot)
|
||||||
stop();
|
stop();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public:
|
||||||
virtual const char* class_name() const override { return "GTimer"; }
|
virtual const char* class_name() const override { return "GTimer"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void timer_event(GTimerEvent&) override;
|
virtual void timer_event(CTimerEvent&) override;
|
||||||
|
|
||||||
bool m_active { false };
|
bool m_active { false };
|
||||||
bool m_single_shot { false };
|
bool m_single_shot { false };
|
||||||
|
|
|
@ -22,7 +22,7 @@ GWidget::~GWidget()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::child_event(GChildEvent& event)
|
void GWidget::child_event(CChildEvent& event)
|
||||||
{
|
{
|
||||||
if (event.type() == GEvent::ChildAdded) {
|
if (event.type() == GEvent::ChildAdded) {
|
||||||
if (event.child() && event.child()->is_widget() && layout())
|
if (event.child() && event.child()->is_widget() && layout())
|
||||||
|
@ -54,7 +54,7 @@ void GWidget::set_relative_rect(const Rect& rect)
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::event(GEvent& event)
|
void GWidget::event(CEvent& event)
|
||||||
{
|
{
|
||||||
switch (event.type()) {
|
switch (event.type()) {
|
||||||
case GEvent::Paint:
|
case GEvent::Paint:
|
||||||
|
@ -178,14 +178,14 @@ void GWidget::handle_mousedown_event(GMouseEvent& event)
|
||||||
mousedown_event(event);
|
mousedown_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::handle_enter_event(GEvent& event)
|
void GWidget::handle_enter_event(CEvent& event)
|
||||||
{
|
{
|
||||||
if (has_tooltip())
|
if (has_tooltip())
|
||||||
GApplication::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
|
GApplication::the().show_tooltip(m_tooltip, screen_relative_rect().center().translated(0, height() / 2));
|
||||||
enter_event(event);
|
enter_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::handle_leave_event(GEvent& event)
|
void GWidget::handle_leave_event(CEvent& event)
|
||||||
{
|
{
|
||||||
GApplication::the().hide_tooltip();
|
GApplication::the().hide_tooltip();
|
||||||
leave_event(event);
|
leave_event(event);
|
||||||
|
@ -235,19 +235,19 @@ void GWidget::mousemove_event(GMouseEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::focusin_event(GEvent&)
|
void GWidget::focusin_event(CEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::focusout_event(GEvent&)
|
void GWidget::focusout_event(CEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::enter_event(GEvent&)
|
void GWidget::enter_event(CEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWidget::leave_event(GEvent&)
|
void GWidget::leave_event(CEvent&)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public:
|
||||||
String tooltip() const { return m_tooltip; }
|
String tooltip() const { return m_tooltip; }
|
||||||
void set_tooltip(const String& tooltip) { m_tooltip = tooltip; }
|
void set_tooltip(const String& tooltip) { m_tooltip = tooltip; }
|
||||||
|
|
||||||
virtual void event(GEvent&) override;
|
virtual void event(CEvent&) override;
|
||||||
virtual void paint_event(GPaintEvent&);
|
virtual void paint_event(GPaintEvent&);
|
||||||
virtual void resize_event(GResizeEvent&);
|
virtual void resize_event(GResizeEvent&);
|
||||||
virtual void show_event(GShowEvent&);
|
virtual void show_event(GShowEvent&);
|
||||||
|
@ -50,11 +50,11 @@ public:
|
||||||
virtual void mouseup_event(GMouseEvent&);
|
virtual void mouseup_event(GMouseEvent&);
|
||||||
virtual void click_event(GMouseEvent&);
|
virtual void click_event(GMouseEvent&);
|
||||||
virtual void doubleclick_event(GMouseEvent&);
|
virtual void doubleclick_event(GMouseEvent&);
|
||||||
virtual void focusin_event(GEvent&);
|
virtual void focusin_event(CEvent&);
|
||||||
virtual void focusout_event(GEvent&);
|
virtual void focusout_event(CEvent&);
|
||||||
virtual void enter_event(GEvent&);
|
virtual void enter_event(CEvent&);
|
||||||
virtual void leave_event(GEvent&);
|
virtual void leave_event(CEvent&);
|
||||||
virtual void child_event(GChildEvent&) override;
|
virtual void child_event(CChildEvent&) override;
|
||||||
|
|
||||||
Rect relative_rect() const { return m_relative_rect; }
|
Rect relative_rect() const { return m_relative_rect; }
|
||||||
Point relative_position() const { return m_relative_rect.location(); }
|
Point relative_position() const { return m_relative_rect.location(); }
|
||||||
|
@ -154,8 +154,8 @@ private:
|
||||||
void handle_resize_event(GResizeEvent&);
|
void handle_resize_event(GResizeEvent&);
|
||||||
void handle_mousedown_event(GMouseEvent&);
|
void handle_mousedown_event(GMouseEvent&);
|
||||||
void handle_mouseup_event(GMouseEvent&);
|
void handle_mouseup_event(GMouseEvent&);
|
||||||
void handle_enter_event(GEvent&);
|
void handle_enter_event(CEvent&);
|
||||||
void handle_leave_event(GEvent&);
|
void handle_leave_event(CEvent&);
|
||||||
void do_layout();
|
void do_layout();
|
||||||
|
|
||||||
GWindow* m_window { nullptr };
|
GWindow* m_window { nullptr };
|
||||||
|
|
|
@ -168,21 +168,21 @@ void GWindow::set_override_cursor(GStandardCursor cursor)
|
||||||
GEventLoop::current().post_message_to_server(request);
|
GEventLoop::current().post_message_to_server(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GWindow::event(GEvent& event)
|
void GWindow::event(CEvent& event)
|
||||||
{
|
{
|
||||||
if (event.is_mouse_event()) {
|
if (event.type() == GEvent::MouseUp || event.type() == GEvent::MouseDown || event.type() == GEvent::MouseMove) {
|
||||||
auto& mouse_event = static_cast<GMouseEvent&>(event);
|
auto& mouse_event = static_cast<GMouseEvent&>(event);
|
||||||
if (m_global_cursor_tracking_widget) {
|
if (m_global_cursor_tracking_widget) {
|
||||||
auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect();
|
auto window_relative_rect = m_global_cursor_tracking_widget->window_relative_rect();
|
||||||
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
|
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
|
||||||
auto local_event = make<GMouseEvent>(event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
||||||
m_global_cursor_tracking_widget->event(*local_event);
|
m_global_cursor_tracking_widget->event(*local_event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (m_automatic_cursor_tracking_widget) {
|
if (m_automatic_cursor_tracking_widget) {
|
||||||
auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect();
|
auto window_relative_rect = m_automatic_cursor_tracking_widget->window_relative_rect();
|
||||||
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
|
Point local_point { mouse_event.x() - window_relative_rect.x(), mouse_event.y() - window_relative_rect.y() };
|
||||||
auto local_event = make<GMouseEvent>(event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), local_point, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
||||||
m_automatic_cursor_tracking_widget->event(*local_event);
|
m_automatic_cursor_tracking_widget->event(*local_event);
|
||||||
if (mouse_event.buttons() == 0)
|
if (mouse_event.buttons() == 0)
|
||||||
m_automatic_cursor_tracking_widget = nullptr;
|
m_automatic_cursor_tracking_widget = nullptr;
|
||||||
|
@ -192,7 +192,7 @@ void GWindow::event(GEvent& event)
|
||||||
return;
|
return;
|
||||||
if (m_main_widget) {
|
if (m_main_widget) {
|
||||||
auto result = m_main_widget->hit_test(mouse_event.x(), mouse_event.y());
|
auto result = m_main_widget->hit_test(mouse_event.x(), mouse_event.y());
|
||||||
auto local_event = make<GMouseEvent>(event.type(), Point { result.localX, result.localY }, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
auto local_event = make<GMouseEvent>((GEvent::Type)event.type(), Point { result.localX, result.localY }, mouse_event.buttons(), mouse_event.button(), mouse_event.modifiers());
|
||||||
ASSERT(result.widget);
|
ASSERT(result.widget);
|
||||||
set_hovered_widget(result.widget);
|
set_hovered_widget(result.widget);
|
||||||
if (mouse_event.buttons() != 0 && !m_automatic_cursor_tracking_widget)
|
if (mouse_event.buttons() != 0 && !m_automatic_cursor_tracking_widget)
|
||||||
|
@ -203,7 +203,7 @@ void GWindow::event(GEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.is_paint_event()) {
|
if (event.type() == GEvent::Paint) {
|
||||||
if (!m_window_id)
|
if (!m_window_id)
|
||||||
return;
|
return;
|
||||||
m_pending_paint_event_rects.clear();
|
m_pending_paint_event_rects.clear();
|
||||||
|
@ -240,7 +240,7 @@ void GWindow::event(GEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.is_key_event()) {
|
if (event.type() == GEvent::KeyUp || event.type() == GEvent::KeyDown) {
|
||||||
if (m_focused_widget)
|
if (m_focused_widget)
|
||||||
return m_focused_widget->event(event);
|
return m_focused_widget->event(event);
|
||||||
if (m_main_widget)
|
if (m_main_widget)
|
||||||
|
|
|
@ -56,7 +56,7 @@ public:
|
||||||
void move_to(int x, int y) { move_to({ x, y }); }
|
void move_to(int x, int y) { move_to({ x, y }); }
|
||||||
void move_to(const Point& point) { set_rect({ point, size() }); }
|
void move_to(const Point& point) { set_rect({ point, size() }); }
|
||||||
|
|
||||||
virtual void event(GEvent&) override;
|
virtual void event(CEvent&) override;
|
||||||
|
|
||||||
bool is_visible() const;
|
bool is_visible() const;
|
||||||
bool is_active() const { return m_is_active; }
|
bool is_active() const { return m_is_active; }
|
||||||
|
|
|
@ -40,7 +40,6 @@ LIBGUI_OBJS = \
|
||||||
GClipboard.o \
|
GClipboard.o \
|
||||||
GSortingProxyModel.o \
|
GSortingProxyModel.o \
|
||||||
GStackWidget.o \
|
GStackWidget.o \
|
||||||
GEvent.o \
|
|
||||||
GScrollableWidget.o \
|
GScrollableWidget.o \
|
||||||
GSocket.o \
|
GSocket.o \
|
||||||
GTCPSocket.o \
|
GTCPSocket.o \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue