GDialog.cpp 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include <LibGUI/GDesktop.h>
  2. #include <LibGUI/GDialog.h>
  3. GDialog::GDialog(CObject* parent)
  4. : GWindow(parent)
  5. {
  6. set_modal(true);
  7. }
  8. GDialog::~GDialog()
  9. {
  10. }
  11. int GDialog::exec()
  12. {
  13. ASSERT(!m_event_loop);
  14. m_event_loop = make<CEventLoop>();
  15. auto new_rect = rect();
  16. if (parent() && parent()->is_window()) {
  17. auto& parent_window = *static_cast<GWindow*>(parent());
  18. new_rect.center_within(parent_window.rect());
  19. } else {
  20. new_rect.center_within(GDesktop::the().rect());
  21. }
  22. set_rect(new_rect);
  23. show();
  24. auto result = m_event_loop->exec();
  25. m_event_loop = nullptr;
  26. dbgprintf("%s: event loop returned with result %d\n", class_name(), result);
  27. remove_from_parent();
  28. return result;
  29. }
  30. void GDialog::done(int result)
  31. {
  32. if (!m_event_loop)
  33. return;
  34. m_result = result;
  35. dbgprintf("%s: quit event loop with result %d\n", class_name(), result);
  36. m_event_loop->quit(result);
  37. }
  38. void GDialog::close()
  39. {
  40. GWindow::close();
  41. m_event_loop->quit(ExecCancel);
  42. }