GObject.h 816 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <AK/Vector.h>
  3. #include <AK/Weakable.h>
  4. class GEvent;
  5. class GTimerEvent;
  6. class GObject : public Weakable<GObject> {
  7. public:
  8. GObject(GObject* parent = nullptr);
  9. virtual ~GObject();
  10. virtual const char* class_name() const { return "GObject"; }
  11. virtual void event(GEvent&);
  12. Vector<GObject*>& children() { return m_children; }
  13. GObject* parent() { return m_parent; }
  14. const GObject* parent() const { return m_parent; }
  15. void start_timer(int ms);
  16. void stop_timer();
  17. bool has_timer() const { return m_timer_id; }
  18. void add_child(GObject&);
  19. void remove_child(GObject&);
  20. void delete_later();
  21. private:
  22. virtual void timer_event(GTimerEvent&);
  23. GObject* m_parent { nullptr };
  24. int m_timer_id { 0 };
  25. Vector<GObject*> m_children;
  26. };