summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GDialog.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-07-04 16:16:50 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-07-04 16:16:50 +0200
commit04b9dc2d30cfc9b383029f6a4b02e2725108b0ae (patch)
treee117a998173b767f9fd009d49c4f8573d8b85432 /Libraries/LibGUI/GDialog.cpp
parent63814ffebf16291419745cd8ba29a4d2fd888563 (diff)
downloadserenity-04b9dc2d30cfc9b383029f6a4b02e2725108b0ae.zip
Libraries: Create top level directory for libraries.
Things were getting a little crowded in the project root, so this patch moves the Lib*/ directories into Libraries/.
Diffstat (limited to 'Libraries/LibGUI/GDialog.cpp')
-rw-r--r--Libraries/LibGUI/GDialog.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/Libraries/LibGUI/GDialog.cpp b/Libraries/LibGUI/GDialog.cpp
new file mode 100644
index 0000000000..4de55f8c95
--- /dev/null
+++ b/Libraries/LibGUI/GDialog.cpp
@@ -0,0 +1,42 @@
+#include <LibGUI/GDesktop.h>
+#include <LibGUI/GDialog.h>
+#include <LibGUI/GEventLoop.h>
+
+GDialog::GDialog(CObject* parent)
+ : GWindow(parent)
+{
+ set_modal(true);
+ set_should_exit_event_loop_on_close(true);
+}
+
+GDialog::~GDialog()
+{
+}
+
+int GDialog::exec()
+{
+ ASSERT(!m_event_loop);
+ m_event_loop = make<GEventLoop>();
+ auto new_rect = rect();
+ if (parent() && parent()->is_window()) {
+ auto& parent_window = *static_cast<GWindow*>(parent());
+ new_rect.center_within(parent_window.rect());
+ } else {
+ new_rect.center_within(GDesktop::the().rect());
+ }
+ set_rect(new_rect);
+ show();
+ auto result = m_event_loop->exec();
+ m_event_loop = nullptr;
+ dbgprintf("%s: event loop returned with result %d\n", class_name(), result);
+ return result;
+}
+
+void GDialog::done(int result)
+{
+ if (!m_event_loop)
+ return;
+ m_result = result;
+ dbgprintf("%s: quit event loop with result %d\n", class_name(), result);
+ m_event_loop->quit(result);
+}