The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

83 lines
3.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #include <Cocoa/Cocoa.h>
  24. #include "../../../../../juce.h"
  25. //==============================================================================
  26. void* attachSubWindow (void* hostWindowRef, Component* comp)
  27. {
  28. const ScopedAutoReleasePool pool;
  29. NSWindow* hostWindow = [[NSWindow alloc] initWithWindowRef: hostWindowRef];
  30. [hostWindow retain];
  31. NSView* content = [hostWindow contentView];
  32. NSRect f = [content frame];
  33. f.size.width = comp->getWidth();
  34. f.size.height = comp->getHeight();
  35. [content setFrame: f];
  36. NSPoint windowPos = [hostWindow convertBaseToScreen: f.origin];
  37. windowPos.y = [[NSScreen mainScreen] frame].size.height - (windowPos.y + f.size.height);
  38. comp->setTopLeftPosition ((int) windowPos.x, (int) windowPos.y);
  39. #if ! JucePlugin_EditorRequiresKeyboardFocus
  40. comp->addToDesktop (ComponentPeer::windowIsTemporary | ComponentPeer::windowIgnoresKeyPresses);
  41. #else
  42. comp->addToDesktop (ComponentPeer::windowIsTemporary);
  43. #endif
  44. comp->setVisible (true);
  45. NSView* pluginView = (NSView*) comp->getWindowHandle();
  46. NSWindow* pluginWindow = [pluginView window];
  47. [hostWindow addChildWindow: pluginWindow
  48. ordered: NSWindowAbove];
  49. [hostWindow orderFront: nil];
  50. return hostWindow;
  51. }
  52. void removeSubWindow (void* nsWindow, Component* comp)
  53. {
  54. const ScopedAutoReleasePool pool;
  55. NSView* pluginView = (NSView*) comp->getWindowHandle();
  56. NSWindow* hostWindow = (NSWindow*) nsWindow;
  57. NSWindow* pluginWindow = [pluginView window];
  58. [hostWindow removeChildWindow: pluginWindow];
  59. comp->removeFromDesktop();
  60. [hostWindow release];
  61. }