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.

263 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. // we need this for now
  17. //#define PUGL_GRAB_FOCUS 1
  18. // #include "../Base.hpp"
  19. #include "WindowPrivateData.hpp"
  20. // #include "../../distrho/extra/String.hpp"
  21. START_NAMESPACE_DGL
  22. // -----------------------------------------------------------------------
  23. // Window
  24. Window::Window(Application& app)
  25. : pData(new PrivateData(app, this)) {}
  26. Window::Window(Application& app, Window& parent)
  27. : pData(new PrivateData(app, this, parent)) {}
  28. Window::Window(Application& app, intptr_t parentId, double scaling, bool resizable)
  29. : pData(new PrivateData(app, this, parentId, scaling, resizable)) {}
  30. Window::~Window()
  31. {
  32. delete pData;
  33. }
  34. #if 0
  35. void Window::show()
  36. {
  37. pData->setVisible(true);
  38. }
  39. void Window::hide()
  40. {
  41. pData->setVisible(false);
  42. }
  43. void Window::close()
  44. {
  45. pData->close();
  46. }
  47. void Window::exec(bool lockWait)
  48. {
  49. pData->exec(lockWait);
  50. }
  51. void Window::focus()
  52. {
  53. pData->focus();
  54. }
  55. void Window::repaint() noexcept
  56. {
  57. puglPostRedisplay(pData->fView);
  58. }
  59. bool Window::isEmbed() const noexcept
  60. {
  61. return pData->fUsingEmbed;
  62. }
  63. bool Window::isVisible() const noexcept
  64. {
  65. return pData->fVisible;
  66. }
  67. void Window::setVisible(bool yesNo)
  68. {
  69. pData->setVisible(yesNo);
  70. }
  71. bool Window::isResizable() const noexcept
  72. {
  73. return pData->fResizable;
  74. }
  75. void Window::setResizable(bool yesNo)
  76. {
  77. pData->setResizable(yesNo);
  78. }
  79. void Window::setGeometryConstraints(uint width, uint height, bool aspect)
  80. {
  81. pData->setGeometryConstraints(width, height, aspect);
  82. }
  83. uint Window::getWidth() const noexcept
  84. {
  85. return pData->fWidth;
  86. }
  87. uint Window::getHeight() const noexcept
  88. {
  89. return pData->fHeight;
  90. }
  91. Size<uint> Window::getSize() const noexcept
  92. {
  93. return Size<uint>(pData->fWidth, pData->fHeight);
  94. }
  95. void Window::setSize(uint width, uint height)
  96. {
  97. pData->setSize(width, height);
  98. }
  99. void Window::setSize(Size<uint> size)
  100. {
  101. pData->setSize(size.getWidth(), size.getHeight());
  102. }
  103. const char* Window::getTitle() const noexcept
  104. {
  105. return pData->getTitle();
  106. }
  107. void Window::setTitle(const char* title)
  108. {
  109. pData->setTitle(title);
  110. }
  111. void Window::setTransientWinId(uintptr_t winId)
  112. {
  113. pData->setTransientWinId(winId);
  114. }
  115. double Window::getScaling() const noexcept
  116. {
  117. return pData->getScaling();
  118. }
  119. bool Window::getIgnoringKeyRepeat() const noexcept
  120. {
  121. return pData->getIgnoringKeyRepeat();
  122. }
  123. void Window::setIgnoringKeyRepeat(bool ignore) noexcept
  124. {
  125. pData->setIgnoringKeyRepeat(ignore);
  126. }
  127. #endif
  128. Application& Window::getApp() const noexcept
  129. {
  130. return pData->fApp;
  131. }
  132. uintptr_t Window::getWindowId() const noexcept
  133. {
  134. return puglGetNativeWindow(pData->fView);
  135. }
  136. #if 0
  137. const GraphicsContext& Window::getGraphicsContext() const noexcept
  138. {
  139. GraphicsContext& context = pData->fContext;
  140. #ifdef DGL_CAIRO
  141. context.cairo = (cairo_t*)puglGetContext(pData->fView);
  142. #endif
  143. return context;
  144. }
  145. void Window::_setAutoScaling(double scaling) noexcept
  146. {
  147. pData->setAutoScaling(scaling);
  148. }
  149. void Window::_addWidget(Widget* const widget)
  150. {
  151. pData->addWidget(widget);
  152. }
  153. void Window::_removeWidget(Widget* const widget)
  154. {
  155. pData->removeWidget(widget);
  156. }
  157. void Window::_idle()
  158. {
  159. pData->idle();
  160. }
  161. #endif
  162. // -----------------------------------------------------------------------
  163. void Window::addIdleCallback(IdleCallback* const callback)
  164. {
  165. DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
  166. pData->fApp.pData->idleCallbacks.push_back(callback);
  167. }
  168. void Window::removeIdleCallback(IdleCallback* const callback)
  169. {
  170. DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr,)
  171. pData->fApp.pData->idleCallbacks.remove(callback);
  172. }
  173. // -----------------------------------------------------------------------
  174. void Window::onDisplayBefore()
  175. {
  176. PrivateData::Fallback::onDisplayBefore();
  177. }
  178. void Window::onDisplayAfter()
  179. {
  180. PrivateData::Fallback::onDisplayAfter();
  181. }
  182. void Window::onReshape(const uint width, const uint height)
  183. {
  184. PrivateData::Fallback::onReshape(width, height);
  185. }
  186. void Window::onClose()
  187. {
  188. }
  189. #ifndef DGL_FILE_BROWSER_DISABLED
  190. void Window::fileBrowserSelected(const char*)
  191. {
  192. }
  193. #endif
  194. #if 0
  195. bool Window::handlePluginKeyboard(const bool press, const uint key)
  196. {
  197. return pData->handlePluginKeyboard(press, key);
  198. }
  199. bool Window::handlePluginSpecial(const bool press, const Key key)
  200. {
  201. return pData->handlePluginSpecial(press, key);
  202. }
  203. #endif
  204. // -----------------------------------------------------------------------
  205. END_NAMESPACE_DGL
  206. #undef DBG
  207. #undef DBGF