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.

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