2019-01-20 03:49:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-04-07 12:36:10 +00:00
|
|
|
#include <AK/Function.h>
|
2019-01-20 03:49:48 +00:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <AK/Weakable.h>
|
|
|
|
|
2019-04-10 14:56:55 +00:00
|
|
|
class CEvent;
|
|
|
|
class CChildEvent;
|
|
|
|
class CTimerEvent;
|
2019-01-20 03:49:48 +00:00
|
|
|
|
|
|
|
class GObject : public Weakable<GObject> {
|
|
|
|
public:
|
|
|
|
GObject(GObject* parent = nullptr);
|
|
|
|
virtual ~GObject();
|
|
|
|
|
|
|
|
virtual const char* class_name() const { return "GObject"; }
|
|
|
|
|
2019-04-10 14:56:55 +00:00
|
|
|
virtual void event(CEvent&);
|
2019-01-20 03:49:48 +00:00
|
|
|
|
|
|
|
Vector<GObject*>& children() { return m_children; }
|
|
|
|
|
|
|
|
GObject* parent() { return m_parent; }
|
|
|
|
const GObject* parent() const { return m_parent; }
|
|
|
|
|
2019-01-31 16:31:23 +00:00
|
|
|
void start_timer(int ms);
|
|
|
|
void stop_timer();
|
|
|
|
bool has_timer() const { return m_timer_id; }
|
2019-01-20 03:49:48 +00:00
|
|
|
|
2019-01-31 16:31:23 +00:00
|
|
|
void add_child(GObject&);
|
|
|
|
void remove_child(GObject&);
|
2019-01-20 03:49:48 +00:00
|
|
|
|
2019-01-30 19:03:52 +00:00
|
|
|
void delete_later();
|
2019-01-20 03:49:48 +00:00
|
|
|
|
2019-03-18 23:01:02 +00:00
|
|
|
void dump_tree(int indent = 0);
|
|
|
|
|
2019-04-07 12:36:10 +00:00
|
|
|
void deferred_invoke(Function<void(GObject&)>);
|
|
|
|
|
2019-03-15 15:12:06 +00:00
|
|
|
virtual bool is_widget() const { return false; }
|
2019-03-19 01:20:00 +00:00
|
|
|
virtual bool is_window() const { return false; }
|
2019-03-15 15:12:06 +00:00
|
|
|
|
|
|
|
protected:
|
2019-04-10 14:56:55 +00:00
|
|
|
virtual void timer_event(CTimerEvent&);
|
|
|
|
virtual void child_event(CChildEvent&);
|
2019-01-20 03:49:48 +00:00
|
|
|
|
2019-03-15 15:12:06 +00:00
|
|
|
private:
|
2019-01-20 03:49:48 +00:00
|
|
|
GObject* m_parent { nullptr };
|
2019-01-31 16:31:23 +00:00
|
|
|
int m_timer_id { 0 };
|
2019-01-20 03:49:48 +00:00
|
|
|
Vector<GObject*> m_children;
|
|
|
|
};
|