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.

206 lines
7.2KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2022 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 ignore resize requests and feed them into the host instead. used for VST3 */
  47. const bool usesSizeRequest;
  48. /** Scale factor to report to widgets on request, purely informational. */
  49. double scaleFactor;
  50. /** Automatic scaling to apply on widgets, implemented internally. */
  51. bool autoScaling;
  52. double autoScaleFactor;
  53. /** Pugl geometry constraints access. */
  54. uint minWidth, minHeight;
  55. bool keepAspectRatio;
  56. /** Whether to ignore idle callback requests, useful for temporary windows. */
  57. bool ignoreIdleCallbacks;
  58. /** Whether we are waiting to receive clipboard data, ignoring some events in the process. */
  59. bool waitingForClipboardData;
  60. bool waitingForClipboardEvents;
  61. /** The type id returned by the last onClipboardDataOffer call. */
  62. uint32_t clipboardTypeId;
  63. /** Render to a picture file when non-null, automatically free+unset after saving. */
  64. char* filenameToRenderInto;
  65. #ifndef DGL_FILE_BROWSER_DISABLED
  66. /** Handle for file browser dialog operations. */
  67. DGL_NAMESPACE::FileBrowserHandle fileBrowserHandle;
  68. #endif
  69. /** Modal window setup. */
  70. struct Modal {
  71. PrivateData* parent; // parent of this window (so we can become modal)
  72. PrivateData* child; // child window to give focus to when modal mode is enabled
  73. bool enabled; // wherever modal mode is enabled (only possible if parent != null)
  74. /** Constructor for a non-modal window. */
  75. Modal() noexcept
  76. : parent(nullptr),
  77. child(nullptr),
  78. enabled(false) {}
  79. /** Constructor for a modal window (with a parent). */
  80. Modal(PrivateData* const p) noexcept
  81. : parent(p),
  82. child(nullptr),
  83. enabled(false) {}
  84. /** Destructor. */
  85. ~Modal() noexcept
  86. {
  87. DISTRHO_SAFE_ASSERT(! enabled);
  88. }
  89. DISTRHO_DECLARE_NON_COPYABLE(Modal)
  90. DISTRHO_PREVENT_HEAP_ALLOCATION
  91. } modal;
  92. /** Constructor for a regular, standalone window. */
  93. explicit PrivateData(Application& app, Window* self);
  94. /** Constructor for a modal window. */
  95. explicit PrivateData(Application& app, Window* self, PrivateData* ppData);
  96. /** Constructor for an embed Window, with a few extra hints from the host side. */
  97. explicit PrivateData(Application& app, Window* self, uintptr_t parentWindowHandle, double scaling, bool resizable);
  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,
  100. uint width, uint height, double scaling, bool resizable, bool isVST3);
  101. /** Destructor. */
  102. ~PrivateData() override;
  103. /** Helper initialization function called at the end of all this class constructors. */
  104. void initPre(uint width, uint height, bool resizable);
  105. /** Helper initialization function called on the Window constructor after we are done. */
  106. bool initPost();
  107. /** Hide window and notify application of a window close event.
  108. * Does nothing if window is embed (that is, not standalone).
  109. * The application event-loop will stop when all windows have been closed.
  110. *
  111. * @note It is possible to hide the window while not stopping the event-loop.
  112. * A closed window is always hidden, but the reverse is not always true.
  113. */
  114. void close();
  115. void show();
  116. void hide();
  117. void focus();
  118. void setResizable(bool resizable);
  119. const GraphicsContext& getGraphicsContext() const noexcept;
  120. // idle callback stuff
  121. void idleCallback() override;
  122. bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs);
  123. bool removeIdleCallback(IdleCallback* callback);
  124. #ifndef DGL_FILE_BROWSER_DISABLED
  125. // file handling
  126. bool openFileBrowser(const DGL_NAMESPACE::FileBrowserOptions& options);
  127. #endif
  128. static void renderToPicture(const char* filename, const GraphicsContext& context, uint width, uint height);
  129. // modal handling
  130. void startModal();
  131. void stopModal();
  132. void runAsModal(bool blockWait);
  133. // pugl events
  134. void onPuglConfigure(double width, double height);
  135. void onPuglExpose();
  136. void onPuglClose();
  137. void onPuglFocus(bool focus, CrossingMode mode);
  138. void onPuglKey(const Widget::KeyboardEvent& ev);
  139. void onPuglText(const Widget::CharacterInputEvent& ev);
  140. void onPuglMouse(const Widget::MouseEvent& ev);
  141. void onPuglMotion(const Widget::MotionEvent& ev);
  142. void onPuglScroll(const Widget::ScrollEvent& ev);
  143. // clipboard related handling
  144. const void* getClipboard(size_t& dataSize);
  145. uint32_t onClipboardDataOffer();
  146. void onClipboardData(uint32_t typeId);
  147. // Pugl event handling entry point
  148. static PuglStatus puglEventCallback(PuglView* view, const PuglEvent* event);
  149. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData)
  150. };
  151. // -----------------------------------------------------------------------
  152. END_NAMESPACE_DGL
  153. #endif // DGL_WINDOW_PRIVATE_DATA_HPP_INCLUDED