summaryrefslogtreecommitdiff
path: root/LibGUI/GObject.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-03-19 00:01:02 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-03-19 00:01:02 +0100
commit57ff293a51d97742d50987950c86dfcde55e6ad1 (patch)
tree44cb31375a62808be2b743758bc6c42c574b4afa /LibGUI/GObject.cpp
parent55aa8190773721f1dc0a3f49bedea6ed8524b318 (diff)
downloadserenity-57ff293a51d97742d50987950c86dfcde55e6ad1.zip
LibGUI: Implement nested event loops to support dialog boxes.
This patch adds a simple GMessageBox that can run in a nested event loop. Here's how you use it: GMessageBox box("Message text here", "Message window title"); int result = box.exec(); The next step is to make the WindowServer respect the modality flag of these windows and prevent interaction with other windows in the same process until the modal window has been closed.
Diffstat (limited to 'LibGUI/GObject.cpp')
-rw-r--r--LibGUI/GObject.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/LibGUI/GObject.cpp b/LibGUI/GObject.cpp
index 1d2c59b427..4dbbe4bc0b 100644
--- a/LibGUI/GObject.cpp
+++ b/LibGUI/GObject.cpp
@@ -2,6 +2,7 @@
#include "GEvent.h"
#include "GEventLoop.h"
#include <AK/Assertions.h>
+#include <stdio.h>
GObject::GObject(GObject* parent)
: m_parent(parent)
@@ -42,7 +43,7 @@ void GObject::event(GEvent& event)
void GObject::add_child(GObject& object)
{
m_children.append(&object);
- GEventLoop::main().post_event(*this, make<GChildEvent>(GEvent::ChildAdded, object));
+ GEventLoop::current().post_event(*this, make<GChildEvent>(GEvent::ChildAdded, object));
}
void GObject::remove_child(GObject& object)
@@ -50,7 +51,7 @@ void GObject::remove_child(GObject& object)
for (ssize_t i = 0; i < m_children.size(); ++i) {
if (m_children[i] == &object) {
m_children.remove(i);
- GEventLoop::main().post_event(*this, make<GChildEvent>(GEvent::ChildRemoved, object));
+ GEventLoop::current().post_event(*this, make<GChildEvent>(GEvent::ChildRemoved, object));
return;
}
}
@@ -71,20 +72,32 @@ void GObject::start_timer(int ms)
ASSERT_NOT_REACHED();
}
- m_timer_id = GEventLoop::main().register_timer(*this, ms, true);
+ m_timer_id = GEventLoop::register_timer(*this, ms, true);
}
void GObject::stop_timer()
{
if (!m_timer_id)
return;
- bool success = GEventLoop::main().unregister_timer(m_timer_id);
+ bool success = GEventLoop::unregister_timer(m_timer_id);
ASSERT(success);
m_timer_id = 0;
}
void GObject::delete_later()
{
- GEventLoop::main().post_event(*this, make<GEvent>(GEvent::DeferredDestroy));
+ GEventLoop::current().post_event(*this, make<GEvent>(GEvent::DeferredDestroy));
}
+void GObject::dump_tree(int indent)
+{
+ for (int i = 0; i < indent; ++i) {
+ printf(" ");
+ }
+ printf("%s{%p}\n", class_name(), this);
+
+ for (auto* child : children()) {
+ child->dump_tree(indent + 2);
+ }
+
+}