Collection of DPF-based plugins for packaging
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.

222 lines
7.7KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2026 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. /** Reserved space for graphics context. */
  36. mutable uint8_t graphicsContext[sizeof(int) * 9];
  37. void createContextIfNeeded();
  38. void destroyContext();
  39. void startContext();
  40. void endContext();
  41. /** The top-level widgets associated with this Window. */
  42. std::list<TopLevelWidget*> topLevelWidgets;
  43. /** Whether this Window is closed (not visible or counted in the Application it is tied to).
  44. Defaults to true unless embed (embed windows are never closed). */
  45. bool isClosed;
  46. /** Whether this Window is currently visible/mapped. Defaults to false. */
  47. bool isVisible;
  48. /** Whether this Window is embed into another (usually not DGL-controlled) Window. */
  49. const bool isEmbed;
  50. /** Whether to schedule repaints on the next idle call, used for AU */
  51. const bool usesScheduledRepaints;
  52. /** Whether to ignore resize requests and feed them into the host instead, used for CLAP and VST3 */
  53. const bool usesSizeRequest;
  54. /** Scale factor to report to widgets on request, purely informational. */
  55. double scaleFactor;
  56. /** Automatic scaling to apply on widgets, implemented internally. */
  57. bool autoScaling;
  58. double autoScaleFactor;
  59. uint baseWidth, baseHeight;
  60. /** Whether to ignore idle callback requests, useful for temporary windows. */
  61. bool ignoreIdleCallbacks;
  62. /** Whether we are waiting to receive clipboard data, ignoring some events in the process. */
  63. bool waitingForClipboardData;
  64. bool waitingForClipboardEvents;
  65. /** The type id returned by the last onClipboardDataOffer call. */
  66. uint32_t clipboardTypeId;
  67. /** Render to a picture file when non-null, automatically free+unset after saving. */
  68. char* filenameToRenderInto;
  69. #ifdef DGL_USE_FILE_BROWSER
  70. /** Handle for file browser dialog operations. */
  71. DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle;
  72. #endif
  73. #ifdef DGL_USE_WEB_VIEW
  74. /** Handle for web view operations. */
  75. DGL_NAMESPACE::WebViewHandle webViewHandle;
  76. DGL_NAMESPACE::Point<int> webViewOffset;
  77. #endif
  78. /** Modal window setup. */
  79. struct Modal {
  80. PrivateData* parent; // parent of this window (so we can become modal)
  81. PrivateData* child; // child window to give focus to when modal mode is enabled
  82. bool enabled; // wherever modal mode is enabled (only possible if parent != null)
  83. /** Constructor for a non-modal window. */
  84. Modal() noexcept
  85. : parent(nullptr),
  86. child(nullptr),
  87. enabled(false) {}
  88. /** Constructor for a modal window (with a parent). */
  89. Modal(PrivateData* const p) noexcept
  90. : parent(p),
  91. child(nullptr),
  92. enabled(false) {}
  93. /** Destructor. */
  94. ~Modal() noexcept
  95. {
  96. DISTRHO_SAFE_ASSERT(! enabled);
  97. }
  98. DISTRHO_DECLARE_NON_COPYABLE(Modal)
  99. DISTRHO_PREVENT_HEAP_ALLOCATION
  100. } modal;
  101. /** Constructor for a regular, standalone window. */
  102. explicit PrivateData(Application& app, Window* self);
  103. /** Constructor for a modal window. */
  104. explicit PrivateData(Application& app, Window* self, PrivateData* ppData);
  105. /** Constructor for an embed Window, with a few extra hints from the host side. */
  106. explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle, double scaling, bool resizable);
  107. /** Constructor for an embed Window, with a few extra hints from the host side. */
  108. explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle,
  109. uint width, uint height, double scaling, bool resizable,
  110. bool usesScheduledRepaints, bool usesSizeRequest);
  111. /** Destructor. */
  112. ~PrivateData() override;
  113. /** Helper initialization function called at the end of all this class constructors. */
  114. void initPre(uint width, uint height, bool resizable);
  115. /** Helper initialization function called on the Window constructor after we are done. */
  116. bool initPost();
  117. /** Hide window and notify application of a window close event.
  118. * Does nothing if window is embed (that is, not standalone).
  119. * The application event-loop will stop when all windows have been closed.
  120. *
  121. * @note It is possible to hide the window while not stopping the event-loop.
  122. * A closed window is always hidden, but the reverse is not always true.
  123. */
  124. void close();
  125. void show();
  126. void hide();
  127. void focus();
  128. void setResizable(bool resizable);
  129. const GraphicsContext& getGraphicsContext() const noexcept;
  130. // idle callback stuff
  131. void idleCallback() override;
  132. bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs);
  133. bool removeIdleCallback(IdleCallback* callback);
  134. #ifdef DGL_USE_FILE_BROWSER
  135. // file browser dialog
  136. bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options);
  137. #endif
  138. #ifdef DGL_USE_WEB_VIEW
  139. // web view
  140. bool createWebView(const char* url, const DGL_NAMESPACE::WebViewOptions& options);
  141. #endif
  142. static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height);
  143. // modal handling
  144. void startModal();
  145. void stopModal();
  146. void runAsModal(bool blockWait);
  147. // pugl events
  148. void onPuglConfigure(uint width, uint height);
  149. void onPuglExpose();
  150. void onPuglClose();
  151. void onPuglFocus(bool focus, CrossingMode mode);
  152. void onPuglKey(const Widget::KeyboardEvent& ev);
  153. void onPuglText(const Widget::CharacterInputEvent& ev);
  154. void onPuglMouse(const Widget::MouseEvent& ev);
  155. void onPuglMotion(const Widget::MotionEvent& ev);
  156. void onPuglScroll(const Widget::ScrollEvent& ev);
  157. // clipboard related handling
  158. const void* getClipboard(size_t& dataSize);
  159. uint32_t onClipboardDataOffer();
  160. void onClipboardData(uint32_t typeId);
  161. // Pugl event handling entry point
  162. static PuglStatus puglEventCallback(PuglView* view, const PuglEvent* event);
  163. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
  164. };
  165. // -----------------------------------------------------------------------
  166. END_NAMESPACE_DGL
  167. #endif // DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED