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.

307 lines
7.9KB

  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,
  47. uintptr_t parentWindowHandle,
  48. uint width,
  49. uint height,
  50. double scaling,
  51. bool resizable);
  52. /**
  53. Destructor.
  54. */
  55. virtual ~Window();
  56. /**
  57. Whether this Window is embed into another (usually not DGL-controlled) Window.
  58. */
  59. bool isEmbed() const noexcept;
  60. /**
  61. Check if this window is visible / mapped.
  62. Invisible windows do not receive events except resize.
  63. @see setVisible(bool)
  64. */
  65. bool isVisible() const noexcept;
  66. /**
  67. Set windows visible (or not) according to @a visible.
  68. Only valid for standalones, embed windows are always visible.
  69. @see isVisible(), hide(), show()
  70. */
  71. void setVisible(bool visible);
  72. /**
  73. Show window.
  74. This is the same as calling setVisible(true).
  75. @see isVisible(), setVisible(bool)
  76. */
  77. void show();
  78. /**
  79. Hide window.
  80. This is the same as calling setVisible(false).
  81. @see isVisible(), setVisible(bool)
  82. */
  83. void hide();
  84. /**
  85. Hide window and notify application of a window close event.
  86. The application event-loop will stop when all windows have been closed.
  87. For standalone windows only, has no effect if window is embed.
  88. @see isEmbed()
  89. @note It is possible to hide the window while not stopping the event-loop.
  90. A closed window is always hidden, but the reverse is not always true.
  91. */
  92. void close();
  93. /**
  94. Get width.
  95. */
  96. uint getWidth() const noexcept;
  97. /**
  98. Get height.
  99. */
  100. uint getHeight() const noexcept;
  101. /**
  102. Get size.
  103. */
  104. Size<uint> getSize() const noexcept;
  105. /**
  106. Set width.
  107. */
  108. void setWidth(uint width);
  109. /**
  110. Set height.
  111. */
  112. void setHeight(uint height);
  113. /**
  114. Set size using @a width and @a height values.
  115. */
  116. void setSize(uint width, uint height);
  117. /**
  118. Set size.
  119. */
  120. void setSize(const Size<uint>& size);
  121. const char* getTitle() const noexcept;
  122. void setTitle(const char* title);
  123. /**
  124. Get the "native" window handle.
  125. Returned value depends on the platform:
  126. - HaikuOS: This is a pointer to a `BView`.
  127. - MacOS: This is a pointer to an `NSView*`.
  128. - Windows: This is a `HWND`.
  129. - Everything else: This is an [X11] `Window`.
  130. */
  131. uintptr_t getNativeWindowHandle() const noexcept;
  132. protected:
  133. virtual void onDisplayBefore();
  134. virtual void onDisplayAfter();
  135. virtual void onReshape(uint width, uint height);
  136. private:
  137. struct PrivateData;
  138. PrivateData* const pData;
  139. friend class Application;
  140. DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Window);
  141. };
  142. // -----------------------------------------------------------------------
  143. END_NAMESPACE_DGL
  144. /* TODO
  145. * add focusEvent with CrossingMode arg
  146. * add eventcrossing/enter-leave event
  147. */
  148. // class StandaloneWindow;
  149. // class Widget;
  150. // #ifdef DISTRHO_DEFINES_H_INCLUDED
  151. // START_NAMESPACE_DISTRHO
  152. // class UI;
  153. // class UIExporter;
  154. // END_NAMESPACE_DISTRHO
  155. // #endif
  156. #if 0
  157. #ifndef DGL_FILE_BROWSER_DISABLED
  158. /**
  159. File browser options.
  160. */
  161. struct FileBrowserOptions {
  162. const char* startDir;
  163. const char* title;
  164. uint width;
  165. uint height;
  166. /**
  167. File browser buttons.
  168. 0 means hidden.
  169. 1 means visible and unchecked.
  170. 2 means visible and checked.
  171. */
  172. struct Buttons {
  173. uint listAllFiles;
  174. uint showHidden;
  175. uint showPlaces;
  176. /** Constuctor for default values */
  177. Buttons()
  178. : listAllFiles(2),
  179. showHidden(1),
  180. showPlaces(1) {}
  181. } buttons;
  182. /** Constuctor for default values */
  183. FileBrowserOptions()
  184. : startDir(nullptr),
  185. title(nullptr),
  186. width(0),
  187. height(0),
  188. buttons() {}
  189. };
  190. #endif // DGL_FILE_BROWSER_DISABLED
  191. static Window& withTransientParentWindow(Window& transientParentWindow);
  192. void exec(bool lockWait = false);
  193. void focus();
  194. void repaint() noexcept;
  195. void repaint(const Rectangle<uint>& rect) noexcept;
  196. #ifndef DGL_FILE_BROWSER_DISABLED
  197. bool openFileBrowser(const FileBrowserOptions& options);
  198. #endif
  199. bool isResizable() const noexcept;
  200. void setResizable(bool resizable);
  201. bool getIgnoringKeyRepeat() const noexcept;
  202. void setIgnoringKeyRepeat(bool ignore) noexcept;
  203. void setGeometryConstraints(uint width, uint height, bool aspect);
  204. void setTransientWinId(uintptr_t winId);
  205. double getScaling() const noexcept;
  206. #if 0
  207. // should this be removed?
  208. Application& getApp() const noexcept;
  209. #endif
  210. const GraphicsContext& getGraphicsContext() const noexcept;
  211. void addIdleCallback(IdleCallback* const callback);
  212. void removeIdleCallback(IdleCallback* const callback);
  213. protected:
  214. virtual void onClose();
  215. #ifndef DGL_FILE_BROWSER_DISABLED
  216. virtual void fileBrowserSelected(const char* filename);
  217. #endif
  218. // internal
  219. void _setAutoScaling(double scaling) noexcept;
  220. virtual void _addWidget(Widget* const widget);
  221. virtual void _removeWidget(Widget* const widget);
  222. void _idle();
  223. bool handlePluginKeyboard(const bool press, const uint key);
  224. bool handlePluginSpecial(const bool press, const Key key);
  225. // friend class Widget;
  226. // friend class StandaloneWindow;
  227. // #ifdef DISTRHO_DEFINES_H_INCLUDED
  228. // friend class DISTRHO_NAMESPACE::UI;
  229. // friend class DISTRHO_NAMESPACE::UIExporter;
  230. // #endif
  231. // Prevent copies
  232. // #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  233. // Window& operator=(Window&) = delete;
  234. // Window& operator=(const Window&) = delete;
  235. // #else
  236. // Window& operator=(Window&);
  237. // Window& operator=(const Window&);
  238. // #endif
  239. #endif
  240. // -----------------------------------------------------------------------
  241. #endif // DGL_WINDOW_HPP_INCLUDED