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.

195 lines
5.2KB

  1. /*
  2. * DISTRHO Plugin Framework (DPF)
  3. * Copyright (C) 2012-2020 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. #ifdef DISTRHO_DEFINES_H_INCLUDED
  20. START_NAMESPACE_DISTRHO
  21. class UI;
  22. class UIExporter;
  23. END_NAMESPACE_DISTRHO
  24. #endif
  25. START_NAMESPACE_DGL
  26. // -----------------------------------------------------------------------
  27. class Application;
  28. class Widget;
  29. class StandaloneWindow;
  30. /* TODO
  31. * add focusEvent with CrossingMode arg
  32. * add eventcrossing/enter-leave event
  33. */
  34. class Window
  35. {
  36. public:
  37. #ifndef DGL_FILE_BROWSER_DISABLED
  38. /**
  39. File browser options.
  40. */
  41. struct FileBrowserOptions {
  42. const char* startDir;
  43. const char* title;
  44. uint width;
  45. uint height;
  46. /**
  47. File browser buttons.
  48. 0 means hidden.
  49. 1 means visible and unchecked.
  50. 2 means visible and checked.
  51. */
  52. struct Buttons {
  53. uint listAllFiles;
  54. uint showHidden;
  55. uint showPlaces;
  56. /** Constuctor for default values */
  57. Buttons()
  58. : listAllFiles(2),
  59. showHidden(1),
  60. showPlaces(1) {}
  61. } buttons;
  62. /** Constuctor for default values */
  63. FileBrowserOptions()
  64. : startDir(nullptr),
  65. title(nullptr),
  66. width(0),
  67. height(0),
  68. buttons() {}
  69. };
  70. #endif // DGL_FILE_BROWSER_DISABLED
  71. explicit Window(Application& app);
  72. explicit Window(Window& transientParentWindow);
  73. explicit Window(Application& app, uintptr_t parentWindowHandle, double scaling, bool resizable);
  74. virtual ~Window();
  75. void show();
  76. void hide();
  77. void close();
  78. void exec(bool lockWait = false);
  79. void focus();
  80. void repaint() noexcept;
  81. void repaint(const Rectangle<uint>& rect) noexcept;
  82. #ifndef DGL_FILE_BROWSER_DISABLED
  83. bool openFileBrowser(const FileBrowserOptions& options);
  84. #endif
  85. bool isEmbed() const noexcept;
  86. bool isVisible() const noexcept;
  87. void setVisible(bool visible);
  88. bool isResizable() const noexcept;
  89. void setResizable(bool resizable);
  90. bool getIgnoringKeyRepeat() const noexcept;
  91. void setIgnoringKeyRepeat(bool ignore) noexcept;
  92. uint getWidth() const noexcept;
  93. uint getHeight() const noexcept;
  94. Size<uint> getSize() const noexcept;
  95. void setSize(uint width, uint height);
  96. void setSize(Size<uint> size);
  97. const char* getTitle() const noexcept;
  98. void setTitle(const char* title);
  99. void setGeometryConstraints(uint width, uint height, bool aspect);
  100. void setTransientWinId(uintptr_t winId);
  101. double getScaling() const noexcept;
  102. #if 0
  103. // should this be removed?
  104. Application& getApp() const noexcept;
  105. #endif
  106. /**
  107. Get the "native" window handle.
  108. Returned value depends on the platform:
  109. - HaikuOS: This is a pointer to a `BView`.
  110. - MacOS: This is a pointer to an `NSView*`.
  111. - Windows: This is a `HWND`.
  112. - Everything else: This is an [X11] `Window`.
  113. */
  114. uintptr_t getNativeWindowHandle() const noexcept;
  115. const GraphicsContext& getGraphicsContext() const noexcept;
  116. void addIdleCallback(IdleCallback* const callback);
  117. void removeIdleCallback(IdleCallback* const callback);
  118. protected:
  119. virtual void onDisplayBefore();
  120. virtual void onDisplayAfter();
  121. virtual void onReshape(uint width, uint height);
  122. virtual void onClose();
  123. #ifndef DGL_FILE_BROWSER_DISABLED
  124. virtual void fileBrowserSelected(const char* filename);
  125. #endif
  126. // internal
  127. void _setAutoScaling(double scaling) noexcept;
  128. private:
  129. struct PrivateData;
  130. PrivateData* const pData;
  131. friend class Application;
  132. friend class Widget;
  133. friend class StandaloneWindow;
  134. #ifdef DISTRHO_DEFINES_H_INCLUDED
  135. friend class DISTRHO_NAMESPACE::UI;
  136. friend class DISTRHO_NAMESPACE::UIExporter;
  137. #endif
  138. virtual void _addWidget(Widget* const widget);
  139. virtual void _removeWidget(Widget* const widget);
  140. void _idle();
  141. bool handlePluginKeyboard(const bool press, const uint key);
  142. bool handlePluginSpecial(const bool press, const Key key);
  143. // Prevent copies
  144. #ifdef DISTRHO_PROPER_CPP11_SUPPORT
  145. Window& operator=(Window&) = delete;
  146. Window& operator=(const Window&) = delete;
  147. #else
  148. Window& operator=(Window&);
  149. Window& operator=(const Window&);
  150. #endif
  151. DISTRHO_LEAK_DETECTOR(Window);
  152. };
  153. // -----------------------------------------------------------------------
  154. END_NAMESPACE_DGL
  155. #endif // DGL_WINDOW_HPP_INCLUDED