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.

236 lines
6.4KB

  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_HPP_INCLUDED
  17. #define DGL_WINDOW_HPP_INCLUDED
  18. #include "Geometry.hpp"
  19. START_NAMESPACE_DGL
  20. class Application;
  21. // -----------------------------------------------------------------------
  22. /**
  23. DGL Window class.
  24. This is the where all OS-related events initially happen, before being propagated to any widgets.
  25. A Window MUST have an Application instance tied to it.
  26. It is not possible to swap Application instances from within the lifetime of a Window.
  27. But it is possible to completely change the Widgets that a Window contains during its lifetime.
  28. Typically the event handling functions as following:
  29. Application -> Window -> Top-Level-Widget -> SubWidgets
  30. ...
  31. Please note that, unlike many other graphical toolkits out there,
  32. DGL makes a clear distinction between a Window and a Widget.
  33. You cannot directly draw in a Window, you need to create a Widget for that.
  34. ...
  35. */
  36. class Window
  37. {
  38. public:
  39. /**
  40. Constructor for a regular, standalone window.
  41. */
  42. explicit Window(Application& app);
  43. /**
  44. Constructor for an embed Window, typically used in modules or plugins that run inside another host.
  45. */
  46. explicit Window(Application& app, uintptr_t parentWindowHandle, double scaling, bool resizable);
  47. /**
  48. Destructor.
  49. */
  50. virtual ~Window();
  51. void close();
  52. /**
  53. Get the "native" window handle.
  54. Returned value depends on the platform:
  55. - HaikuOS: This is a pointer to a `BView`.
  56. - MacOS: This is a pointer to an `NSView*`.
  57. - Windows: This is a `HWND`.
  58. - Everything else: This is an [X11] `Window`.
  59. */
  60. uintptr_t getNativeWindowHandle() const noexcept;
  61. private:
  62. struct PrivateData;
  63. PrivateData* const pData;
  64. friend class Application;
  65. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window);
  66. };
  67. // -----------------------------------------------------------------------
  68. END_NAMESPACE_DGL
  69. /* TODO
  70. * add focusEvent with CrossingMode arg
  71. * add eventcrossing/enter-leave event
  72. */
  73. // class StandaloneWindow;
  74. // class Widget;
  75. // #ifdef DISTRHO_DEFINES_H_INCLUDED
  76. // START_NAMESPACE_DISTRHO
  77. // class UI;
  78. // class UIExporter;
  79. // END_NAMESPACE_DISTRHO
  80. // #endif
  81. #if 0
  82. #ifndef DGL_FILE_BROWSER_DISABLED
  83. /**
  84. File browser options.
  85. */
  86. struct FileBrowserOptions {
  87. const char* startDir;
  88. const char* title;
  89. uint width;
  90. uint height;
  91. /**
  92. File browser buttons.
  93. 0 means hidden.
  94. 1 means visible and unchecked.
  95. 2 means visible and checked.
  96. */
  97. struct Buttons {
  98. uint listAllFiles;
  99. uint showHidden;
  100. uint showPlaces;
  101. /** Constuctor for default values */
  102. Buttons()
  103. : listAllFiles(2),
  104. showHidden(1),
  105. showPlaces(1) {}
  106. } buttons;
  107. /** Constuctor for default values */
  108. FileBrowserOptions()
  109. : startDir(nullptr),
  110. title(nullptr),
  111. width(0),
  112. height(0),
  113. buttons() {}
  114. };
  115. #endif // DGL_FILE_BROWSER_DISABLED
  116. static Window& withTransientParentWindow(Window& transientParentWindow);
  117. void show();
  118. void hide();
  119. void exec(bool lockWait = false);
  120. void focus();
  121. void repaint() noexcept;
  122. void repaint(const Rectangle<uint>& rect) noexcept;
  123. #ifndef DGL_FILE_BROWSER_DISABLED
  124. bool openFileBrowser(const FileBrowserOptions& options);
  125. #endif
  126. bool isEmbed() const noexcept;
  127. bool isVisible() const noexcept;
  128. void setVisible(bool visible);
  129. bool isResizable() const noexcept;
  130. void setResizable(bool resizable);
  131. bool getIgnoringKeyRepeat() const noexcept;
  132. void setIgnoringKeyRepeat(bool ignore) noexcept;
  133. uint getWidth() const noexcept;
  134. uint getHeight() const noexcept;
  135. Size<uint> getSize() const noexcept;
  136. void setSize(uint width, uint height);
  137. void setSize(Size<uint> size);
  138. const char* getTitle() const noexcept;
  139. void setTitle(const char* title);
  140. void setGeometryConstraints(uint width, uint height, bool aspect);
  141. void setTransientWinId(uintptr_t winId);
  142. double getScaling() const noexcept;
  143. #if 0
  144. // should this be removed?
  145. Application& getApp() const noexcept;
  146. #endif
  147. const GraphicsContext& getGraphicsContext() const noexcept;
  148. void addIdleCallback(IdleCallback* const callback);
  149. void removeIdleCallback(IdleCallback* const callback);
  150. protected:
  151. virtual void onDisplayBefore();
  152. virtual void onDisplayAfter();
  153. virtual void onReshape(uint width, uint height);
  154. virtual void onClose();
  155. #ifndef DGL_FILE_BROWSER_DISABLED
  156. virtual void fileBrowserSelected(const char* filename);
  157. #endif
  158. // internal
  159. void _setAutoScaling(double scaling) noexcept;
  160. virtual void _addWidget(Widget* const widget);
  161. virtual void _removeWidget(Widget* const widget);
  162. void _idle();
  163. bool handlePluginKeyboard(const bool press, const uint key);
  164. bool handlePluginSpecial(const bool press, const Key key);
  165. // friend class Widget;
  166. // friend class StandaloneWindow;
  167. // #ifdef DISTRHO_DEFINES_H_INCLUDED
  168. // friend class DISTRHO_NAMESPACE::UI;
  169. // friend class DISTRHO_NAMESPACE::UIExporter;
  170. // #endif
  171. // Prevent copies
  172. // #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  173. // Window& operator=(Window&) = delete;
  174. // Window& operator=(const Window&) = delete;
  175. // #else
  176. // Window& operator=(Window&);
  177. // Window& operator=(const Window&);
  178. // #endif
  179. #endif
  180. // -----------------------------------------------------------------------
  181. #endif // DGL_WINDOW_HPP_INCLUDED