DISTRHO Plugin Framework
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
7.0KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any purpose with
  6. * or without fee is hereby granted, provided that the above copyright notice and this
  7. * permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
  10. * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
  11. * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  12. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
  13. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #ifndef DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED
  17. #define DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED
  18. #include "../Window.hpp"
  19. #include "../Widget.hpp"
  20. #include "ApplicationPrivateData.hpp"
  21. #include "pugl.hpp"
  22. #include <list>
  23. START_NAMESPACE_DGL
  24. class TopLevelWidget;
  25. // -----------------------------------------------------------------------
  26. struct Window::PrivateData : IdleCallback {
  27. /** Reference to the DGL Application class this (private data) window associates with. */
  28. Application& app;
  29. /** Direct access to the DGL Application private data where we registers ourselves in. */
  30. Application::PrivateData* const appData;
  31. /** Pointer to the the DGL Window class that this private data belongs to. */
  32. Window* const self;
  33. /** Pugl view instance. */
  34. PuglView* view;
  35. /** Pugl view instance of the transient parent window. */
  36. PuglView* const transientParentView;
  37. /** Reserved space for graphics context. */
  38. mutable uint8_t graphicsContext[sizeof(void*)];
  39. /** The top-level widgets associated with this Window. */
  40. std::list<TopLevelWidget*> topLevelWidgets;
  41. /** Whether this Window is closed (not visible or counted in the Application it is tied to).
  42. Defaults to true unless embed (embed windows are never closed). */
  43. bool isClosed;
  44. /** Whether this Window is currently visible/mapped. Defaults to false. */
  45. bool isVisible;
  46. /** Whether this Window is embed into another (usually not DGL-controlled) Window. */
  47. const bool isEmbed;
  48. /** Whether to ignore resize requests and feed them into the host instead. used for VST3 */
  49. const bool usesSizeRequest;
  50. /** Scale factor to report to widgets on request, purely informational. */
  51. double scaleFactor;
  52. /** Automatic scaling to apply on widgets, implemented internally. */
  53. bool autoScaling;
  54. double autoScaleFactor;
  55. /** Pugl geometry constraints access. */
  56. uint minWidth, minHeight;
  57. bool keepAspectRatio;
  58. /** Whether to ignore idle callback requests, useful for temporary windows. */
  59. bool ignoreIdleCallbacks;
  60. /** Whether to ignore pugl events (except create and destroy), used for puglGetClipboard. */
  61. bool ignoreEvents;
  62. /** Render to a picture file when non-null, automatically free+unset after saving. */
  63. char* filenameToRenderInto;
  64. #ifndef DGL_FILE_BROWSER_DISABLED
  65. /** Handle for file browser dialog operations. */
  66. FileBrowserHandle fileBrowserHandle;
  67. #endif
  68. /** Modal window setup. */
  69. struct Modal {
  70. PrivateData* parent; // parent of this window (so we can become modal)
  71. PrivateData* child; // child window to give focus to when modal mode is enabled
  72. bool enabled; // wherever modal mode is enabled (only possible if parent != null)
  73. /** Constructor for a non-modal window. */
  74. Modal() noexcept
  75. : parent(nullptr),
  76. child(nullptr),
  77. enabled(false) {}
  78. /** Constructor for a modal window (with a parent). */
  79. Modal(PrivateData* const p) noexcept
  80. : parent(p),
  81. child(nullptr),
  82. enabled(false) {}
  83. /** Destructor. */
  84. ~Modal() noexcept
  85. {
  86. DISTRHO_SAFE_ASSERT(! enabled);
  87. }
  88. DISTRHO_DECLARE_NON_COPYABLE(Modal)
  89. DISTRHO_PREVENT_HEAP_ALLOCATION
  90. } modal;
  91. /** Constructor for a regular, standalone window. */
  92. explicit PrivateData(Application& app, Window* self);
  93. /** Constructor for a modal window. */
  94. explicit PrivateData(Application& app, Window* self, PrivateData* ppData);
  95. /** Constructor for an embed Window, with a few extra hints from the host side. */
  96. explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle, double scaling, bool resizable);
  97. /** Constructor for an embed Window, with a few extra hints from the host side. */
  98. explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle,
  99. uint width, uint height, double scaling, bool resizable, bool isVST3);
  100. /** Destructor. */
  101. ~PrivateData() override;
  102. /** Helper initialization function called at the end of all this class constructors. */
  103. void initPre(uint width, uint height, bool resizable);
  104. /** Helper initialization function called on the Window constructor after we are done. */
  105. bool initPost();
  106. /** Hide window and notify application of a window close event.
  107. * Does nothing if window is embed (that is, not standalone).
  108. * The application event-loop will stop when all windows have been closed.
  109. *
  110. * @note It is possible to hide the window while not stopping the event-loop.
  111. * A closed window is always hidden, but the reverse is not always true.
  112. */
  113. void close();
  114. void show();
  115. void hide();
  116. void focus();
  117. void setResizable(bool resizable);
  118. const GraphicsContext& getGraphicsContext() const noexcept;
  119. // idle callback stuff
  120. void idleCallback() override;
  121. bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs);
  122. bool removeIdleCallback(IdleCallback* callback);
  123. #ifndef DGL_FILE_BROWSER_DISABLED
  124. // file handling
  125. bool openFileBrowser(const FileBrowserOptions& options);
  126. #endif
  127. static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height);
  128. // modal handling
  129. void startModal();
  130. void stopModal();
  131. void runAsModal(bool blockWait);
  132. // pugl events
  133. void onPuglConfigure(double width, double height);
  134. void onPuglExpose();
  135. void onPuglClose();
  136. void onPuglFocus(bool focus, CrossingMode mode);
  137. void onPuglKey(const Widget::KeyboardEvent& ev);
  138. void onPuglText(const Widget::CharacterInputEvent& ev);
  139. void onPuglMouse(const Widget::MouseEvent& ev);
  140. void onPuglMotion(const Widget::MotionEvent& ev);
  141. void onPuglScroll(const Widget::ScrollEvent& ev);
  142. // Pugl event handling entry point
  143. static PuglStatus puglEventCallback(PuglView* view, const PuglEvent* event);
  144. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
  145. };
  146. // -----------------------------------------------------------------------
  147. END_NAMESPACE_DGL
  148. #endif // DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED