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.

205 lines
5.4KB

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