Audio plugin host https://kx.studio/carla
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.

JucePluginWindow.hpp 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * Juce Plugin Window Helper
  3. * Copyright (C) 2013-2019 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef JUCE_PLUGIN_WINDOW_HPP_INCLUDED
  18. #define JUCE_PLUGIN_WINDOW_HPP_INCLUDED
  19. #include "CarlaJuceUtils.hpp"
  20. #include "AppConfig.h"
  21. #include "juce_gui_basics/juce_gui_basics.h"
  22. #if defined(CARLA_OS_LINUX) && defined(HAVE_X11)
  23. # include <X11/Xlib.h>
  24. #elif defined(CARLA_OS_MAC)
  25. # define Component CocoaComponent
  26. # define MemoryBlock CocoaMemoryBlock
  27. # define Point CocoaPoint
  28. # import <Cocoa/Cocoa.h>
  29. # undef Component
  30. # undef MemoryBlock
  31. # undef Point
  32. #endif
  33. // -----------------------------------------------------------------------
  34. namespace juce {
  35. class JucePluginWindow : public DialogWindow
  36. {
  37. public:
  38. JucePluginWindow(const uintptr_t parentId)
  39. : DialogWindow("JucePluginWindow", Colour(50, 50, 200), true, false),
  40. fClosed(false),
  41. fTransientId(parentId)
  42. {
  43. setVisible(false);
  44. //setAlwaysOnTop(true);
  45. setOpaque(true);
  46. setResizable(false, false);
  47. setUsingNativeTitleBar(true);
  48. }
  49. void show(Component* const comp)
  50. {
  51. fClosed = false;
  52. centreWithSize(comp->getWidth(), comp->getHeight());
  53. setContentNonOwned(comp, true);
  54. if (! isOnDesktop())
  55. addToDesktop();
  56. setVisible(true);
  57. setTransient();
  58. }
  59. void hide()
  60. {
  61. setVisible(false);
  62. if (isOnDesktop())
  63. removeFromDesktop();
  64. clearContentComponent();
  65. }
  66. bool wasClosedByUser() const noexcept
  67. {
  68. return fClosed;
  69. }
  70. protected:
  71. void closeButtonPressed() override
  72. {
  73. fClosed = true;
  74. }
  75. bool escapeKeyPressed() override
  76. {
  77. fClosed = true;
  78. return true;
  79. }
  80. private:
  81. volatile bool fClosed;
  82. const uintptr_t fTransientId;
  83. void setTransient()
  84. {
  85. if (fTransientId == 0)
  86. return;
  87. #if defined(CARLA_OS_LINUX) && defined(HAVE_X11)
  88. Display* const display = XWindowSystem::getInstance()->getDisplay();
  89. CARLA_SAFE_ASSERT_RETURN(display != nullptr,);
  90. ::Window window = (::Window)getWindowHandle();
  91. CARLA_SAFE_ASSERT_RETURN(window != 0,);
  92. XSetTransientForHint(display, window, static_cast<::Window>(fTransientId));
  93. #endif
  94. #ifdef CARLA_OS_MAC
  95. NSView* const view = (NSView*)getWindowHandle();
  96. CARLA_SAFE_ASSERT_RETURN(view != nullptr,);
  97. NSWindow* const window = [view window];
  98. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  99. NSWindow* const parentWindow = [NSApp windowWithWindowNumber:fTransientId];
  100. CARLA_SAFE_ASSERT_RETURN(parentWindow != nullptr,);
  101. [parentWindow addChildWindow:window
  102. ordered:NSWindowAbove];
  103. #endif
  104. #ifdef CARLA_OS_WIN
  105. const HWND window = (HWND)getWindowHandle();
  106. CARLA_SAFE_ASSERT_RETURN(window != nullptr,);
  107. SetWindowLongPtr(window, GWLP_HWNDPARENT, static_cast<LONG_PTR>(fTransientId));
  108. #endif
  109. }
  110. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(JucePluginWindow)
  111. };
  112. } // namespace juce
  113. using juce::JucePluginWindow;
  114. // -----------------------------------------------------------------------
  115. #endif // JUCE_PLUGIN_WINDOW_HPP_INCLUDED