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.

210 lines
7.4KB

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