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.

156 lines
4.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  19. // compiled on its own).
  20. #ifdef JUCE_INCLUDED_FILE
  21. //==============================================================================
  22. class NSViewComponentInternal : public ComponentMovementWatcher
  23. {
  24. Component* const owner;
  25. NSViewComponentPeer* currentPeer;
  26. bool wasShowing;
  27. public:
  28. NSView* const view;
  29. //==============================================================================
  30. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  31. : ComponentMovementWatcher (owner_),
  32. owner (owner_),
  33. currentPeer (0),
  34. wasShowing (false),
  35. view (view_)
  36. {
  37. [view_ retain];
  38. if (owner_->isShowing())
  39. componentPeerChanged();
  40. }
  41. ~NSViewComponentInternal()
  42. {
  43. [view removeFromSuperview];
  44. [view release];
  45. }
  46. //==============================================================================
  47. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  48. {
  49. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  50. // The ComponentMovementWatcher version of this method avoids calling
  51. // us when the top-level comp is resized, but for an NSView we need to know this
  52. // because with inverted co-ords, we need to update the position even if the
  53. // top-left pos hasn't changed
  54. if (comp.isOnDesktop() && wasResized)
  55. componentMovedOrResized (wasMoved, wasResized);
  56. }
  57. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  58. {
  59. Component* const topComp = owner->getTopLevelComponent();
  60. if (topComp->getPeer() != 0)
  61. {
  62. int x = 0, y = 0;
  63. owner->relativePositionToOtherComponent (topComp, x, y);
  64. NSRect r;
  65. r.origin.x = (float) x;
  66. r.origin.y = (float) y;
  67. r.size.width = (float) owner->getWidth();
  68. r.size.height = (float) owner->getHeight();
  69. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  70. [view setFrame: r];
  71. }
  72. }
  73. void componentPeerChanged()
  74. {
  75. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  76. if (currentPeer != peer)
  77. {
  78. [view removeFromSuperview];
  79. currentPeer = peer;
  80. if (peer != 0)
  81. {
  82. [peer->view addSubview: view];
  83. componentMovedOrResized (false, false);
  84. }
  85. }
  86. [view setHidden: ! owner->isShowing()];
  87. }
  88. void componentVisibilityChanged (Component&)
  89. {
  90. componentPeerChanged();
  91. }
  92. juce_UseDebuggingNewOperator
  93. private:
  94. NSViewComponentInternal (const NSViewComponentInternal&);
  95. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  96. };
  97. //==============================================================================
  98. NSViewComponent::NSViewComponent()
  99. : info (0)
  100. {
  101. }
  102. NSViewComponent::~NSViewComponent()
  103. {
  104. delete info;
  105. }
  106. void NSViewComponent::setView (void* view)
  107. {
  108. if (view != getView())
  109. {
  110. deleteAndZero (info);
  111. if (view != 0)
  112. info = new NSViewComponentInternal ((NSView*) view, this);
  113. }
  114. }
  115. void* NSViewComponent::getView() const
  116. {
  117. return info == 0 ? 0 : info->view;
  118. }
  119. void NSViewComponent::paint (Graphics& g)
  120. {
  121. }
  122. #endif