system_context_wx.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. //
  3. // Copyright (c) 2019 Ivan Baidakou (basiliscos) (the dot dmol at gmail dot com)
  4. //
  5. // Distributed under the MIT Software License
  6. //
  7. #include "rotor/arc.hpp"
  8. #include "rotor/wx/supervisor_config_wx.h"
  9. #include "rotor/system_context.h"
  10. #include <wx/app.h>
  11. namespace rotor {
  12. namespace wx {
  13. struct supervisor_wx_t;
  14. /** \brief intrusive pointer for wx supervisor */
  15. using supervisor_ptr_t = intrusive_ptr_t<supervisor_wx_t>;
  16. /** \struct system_context_wx_t
  17. * \brief The wxWidgets system context, which holds a pointer to wxApp and
  18. * root wx-supervisor
  19. *
  20. */
  21. struct system_context_wx_t : public system_context_t {
  22. /** \brief intrusive pointer type for wx system context */
  23. using ptr_t = rotor::intrusive_ptr_t<system_context_wx_t>;
  24. /** \brief construct the context from wx application
  25. *
  26. * If `app` is null, then the wx application is taken via `wxTheApp` macro
  27. *
  28. */
  29. system_context_wx_t(wxAppConsole *app = nullptr);
  30. /** \brief creates root supervior. `args` and config are forwarded for supervisor constructor */
  31. template <typename Supervisor = supervisor_t, typename... Args>
  32. auto create_supervisor(const supervisor_config_wx_t &config, Args &&... args) -> intrusive_ptr_t<Supervisor> {
  33. if (supervisor) {
  34. on_error(make_error_code(error_code_t::supervisor_defined));
  35. return intrusive_ptr_t<Supervisor>{};
  36. } else {
  37. auto typed_sup =
  38. system_context_t::create_supervisor<Supervisor>(nullptr, config, std::forward<Args>(args)...);
  39. supervisor = typed_sup;
  40. return typed_sup;
  41. }
  42. }
  43. /** \brief returns wx application */
  44. inline wxAppConsole *get_app() noexcept { return app; }
  45. protected:
  46. friend struct supervisor_wx_t;
  47. /** \brief root wx supervisor */
  48. supervisor_ptr_t supervisor;
  49. /** \brief non-owning pointer to the wx application */
  50. wxAppConsole *app;
  51. };
  52. /** \brief intrusive pointer type for wx system context */
  53. using system_context_ptr_t = typename system_context_wx_t::ptr_t;
  54. } // namespace wx
  55. } // namespace rotor