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.

190 lines
5.1KB

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