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.

144 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 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. #include "../../jucer_Headers.h"
  19. #include "jucer_ComponentViewer.h"
  20. //==============================================================================
  21. ComponentViewer::ComponentViewer (OpenDocumentManager::Document* document_, Project* project_, ComponentDocument* componentDocument_)
  22. : document (document_), project (project_), componentDocument (componentDocument_)
  23. {
  24. OpenDocumentManager::getInstance()->addListener (this);
  25. documentRoot = componentDocument->getRoot();
  26. documentRoot.addListener (this);
  27. handleAsyncUpdate();
  28. }
  29. ComponentViewer::~ComponentViewer()
  30. {
  31. OpenDocumentManager::getInstance()->removeListener (this);
  32. deleteAllChildren();
  33. }
  34. void ComponentViewer::documentAboutToClose (OpenDocumentManager::Document* closingDoc)
  35. {
  36. if (document == closingDoc)
  37. {
  38. componentDocument = 0;
  39. document = 0;
  40. layoutManager = 0;
  41. documentRoot = ValueTree::invalid;
  42. triggerAsyncUpdate();
  43. handleUpdateNowIfNeeded();
  44. // xxx
  45. }
  46. }
  47. void ComponentViewer::paint (Graphics& g)
  48. {
  49. if (componentDocument == 0)
  50. drawComponentPlaceholder (g, getWidth(), getHeight(), "(Not a valid Jucer component)");
  51. else
  52. g.fillAll (background);
  53. }
  54. void ComponentViewer::handleAsyncUpdate()
  55. {
  56. deleteAllChildren();
  57. layoutManager = 0;
  58. background = Colours::transparentBlack;
  59. if (componentDocument != 0)
  60. {
  61. background = Colour::fromString (componentDocument->getBackgroundColour().toString());
  62. if (layoutManager == 0)
  63. layoutManager = new RelativeRectangleLayoutManager (this);
  64. int i;
  65. for (i = getNumChildComponents(); --i >= 0;)
  66. {
  67. Component* c = getChildComponent (i);
  68. if (! componentDocument->containsComponent (c))
  69. delete c;
  70. }
  71. {
  72. Array <Component*> componentsInOrder;
  73. const int num = componentDocument->getNumComponents();
  74. for (i = 0; i < num; ++i)
  75. {
  76. const ValueTree v (componentDocument->getComponent (i));
  77. Component* c = componentDocument->findComponentForState (this, v);
  78. if (c == 0)
  79. addAndMakeVisible (c = componentDocument->createComponent (i));
  80. else
  81. componentDocument->updateComponent (c);
  82. componentsInOrder.add (c);
  83. layoutManager->setComponentBounds (c, v [ComponentDocument::memberNameProperty],
  84. componentDocument->getCoordsFor (v));
  85. }
  86. // Make sure the z-order is correct..
  87. if (num > 0)
  88. {
  89. componentsInOrder.getLast()->toFront (false);
  90. for (i = num - 1; --i >= 0;)
  91. componentsInOrder.getUnchecked(i)->toBehind (componentsInOrder.getUnchecked (i + 1));
  92. }
  93. }
  94. setSize (componentDocument->getCanvasWidth().getValue(),
  95. componentDocument->getCanvasHeight().getValue());
  96. for (i = 0; i < componentDocument->getMarkerListX().size(); ++i)
  97. {
  98. const ValueTree marker (componentDocument->getMarkerListX().getMarker (i));
  99. layoutManager->setMarker (componentDocument->getMarkerListX().getName (marker),
  100. componentDocument->getMarkerListX().getCoordinate (marker));
  101. }
  102. for (i = 0; i < componentDocument->getMarkerListY().size(); ++i)
  103. {
  104. const ValueTree marker (componentDocument->getMarkerListY().getMarker (i));
  105. layoutManager->setMarker (componentDocument->getMarkerListY().getName (marker),
  106. componentDocument->getMarkerListY().getCoordinate (marker));
  107. }
  108. }
  109. repaint();
  110. }