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.

150 lines
4.3KB

  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. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  24. // compiled on its own).
  25. #ifdef JUCE_INCLUDED_FILE
  26. //==============================================================================
  27. class NSViewComponentInternal : public ComponentMovementWatcher
  28. {
  29. Component* const owner;
  30. NSViewComponentPeer* currentPeer;
  31. bool wasShowing;
  32. public:
  33. NSView* view;
  34. //==============================================================================
  35. NSViewComponentInternal (NSView* view_, Component* const owner_)
  36. : ComponentMovementWatcher (owner_),
  37. owner (owner_),
  38. currentPeer (0),
  39. wasShowing (false),
  40. view (view_)
  41. {
  42. [view retain];
  43. if (owner_->isShowing())
  44. componentPeerChanged();
  45. }
  46. ~NSViewComponentInternal()
  47. {
  48. [view removeFromSuperview];
  49. [view release];
  50. }
  51. //==============================================================================
  52. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  53. {
  54. Component* const topComp = owner->getTopLevelComponent();
  55. if (topComp->getPeer() != 0)
  56. {
  57. int x = 0, y = 0;
  58. owner->relativePositionToOtherComponent (topComp, x, y);
  59. NSRect r;
  60. r.origin.x = (float) x;
  61. r.origin.y = (float) y;
  62. r.size.width = (float) owner->getWidth();
  63. r.size.height = (float) owner->getHeight();
  64. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  65. [view setFrame: r];
  66. }
  67. }
  68. void componentPeerChanged()
  69. {
  70. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  71. if (currentPeer != peer)
  72. {
  73. [view removeFromSuperview];
  74. currentPeer = peer;
  75. if (peer != 0)
  76. {
  77. [peer->view addSubview: view];
  78. componentMovedOrResized (false, false);
  79. }
  80. }
  81. [view setHidden: ! owner->isShowing()];
  82. }
  83. void componentVisibilityChanged (Component&)
  84. {
  85. componentPeerChanged();
  86. }
  87. juce_UseDebuggingNewOperator
  88. private:
  89. NSViewComponentInternal (const NSViewComponentInternal&);
  90. const NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  91. };
  92. //==============================================================================
  93. NSViewComponent::NSViewComponent()
  94. : info (0)
  95. {
  96. }
  97. NSViewComponent::~NSViewComponent()
  98. {
  99. delete info;
  100. }
  101. void NSViewComponent::setView (void* view)
  102. {
  103. if (view != getView())
  104. {
  105. deleteAndZero (info);
  106. if (view != 0)
  107. info = new NSViewComponentInternal ((NSView*) view, this);
  108. }
  109. }
  110. void* NSViewComponent::getView() const
  111. {
  112. return info == 0 ? 0 : info->view;
  113. }
  114. void NSViewComponent::paint (Graphics& g)
  115. {
  116. }
  117. #endif