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.

312 lines
8.2KB

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