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.

164 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. #ifndef __JUCER_EDITORPANEL_H_8E192A99__
  19. #define __JUCER_EDITORPANEL_H_8E192A99__
  20. //==============================================================================
  21. class EditorPanelBase : public Component
  22. {
  23. public:
  24. EditorPanelBase()
  25. : infoPanel (0), tree (0)
  26. {
  27. addAndMakeVisible (toolbar = new Toolbar());
  28. toolbar->setStyle (Toolbar::textOnly);
  29. addAndMakeVisible (viewport = new Viewport());
  30. addChildComponent (tree = new TreeView());
  31. tree->setRootItemVisible (true);
  32. tree->setMultiSelectEnabled (true);
  33. tree->setDefaultOpenness (true);
  34. tree->setColour (TreeView::backgroundColourId, Colours::white);
  35. tree->setIndentSize (15);
  36. }
  37. ~EditorPanelBase()
  38. {
  39. jassert (infoPanel == 0); // remember to call shutdown()
  40. deleteAllChildren();
  41. }
  42. void initialise (Component* canvas, ToolbarItemFactory& toolbarFactory, TreeViewItem* treeRootItem)
  43. {
  44. toolbar->addDefaultItems (toolbarFactory);
  45. viewport->setViewedComponent (canvas);
  46. addAndMakeVisible (infoPanel = new InfoPanel (this));
  47. tree->setRootItem (treeRootItem);
  48. resized();
  49. }
  50. void shutdown()
  51. {
  52. tree->deleteRootItem();
  53. deleteAndZero (infoPanel);
  54. }
  55. void showOrHideProperties()
  56. {
  57. infoPanel->setVisible (! infoPanel->isVisible());
  58. resized();
  59. }
  60. void showOrHideTree()
  61. {
  62. tree->setVisible (! tree->isVisible());
  63. resized();
  64. }
  65. virtual SelectedItemSet<String>& getSelection() = 0;
  66. virtual void getSelectedItemProperties (Array<PropertyComponent*>& newComps) = 0;
  67. void resized()
  68. {
  69. const int toolbarHeight = 22;
  70. toolbar->setBounds (0, 0, getWidth(), toolbarHeight);
  71. int infoPanelWidth = 200;
  72. if (infoPanel != 0 && infoPanel->isVisible())
  73. infoPanel->setBounds (getWidth() - infoPanelWidth, toolbar->getBottom(), infoPanelWidth, getHeight() - toolbar->getBottom());
  74. else
  75. infoPanelWidth = 0;
  76. if (tree->isVisible())
  77. {
  78. tree->setBounds (0, toolbar->getBottom(), infoPanelWidth, getHeight() - toolbar->getBottom());
  79. viewport->setBounds (infoPanelWidth, toolbar->getBottom(), getWidth() - infoPanelWidth * 2, getHeight() - toolbar->getBottom());
  80. }
  81. else
  82. {
  83. viewport->setBounds (0, toolbar->getBottom(), getWidth() - infoPanelWidth, getHeight() - toolbar->getBottom());
  84. }
  85. }
  86. private:
  87. //==============================================================================
  88. class InfoPanel : public Component,
  89. public ChangeListener
  90. {
  91. public:
  92. InfoPanel (EditorPanelBase* owner_)
  93. : owner (owner_)
  94. {
  95. setOpaque (true);
  96. addAndMakeVisible (props = new PropertyPanel());
  97. owner->getSelection().addChangeListener (this);
  98. }
  99. ~InfoPanel()
  100. {
  101. owner->getSelection().removeChangeListener (this);
  102. props->clear();
  103. deleteAllChildren();
  104. }
  105. void changeListenerCallback (void*)
  106. {
  107. Array <PropertyComponent*> newComps;
  108. owner->getSelectedItemProperties (newComps);
  109. props->clear();
  110. props->addProperties (newComps);
  111. }
  112. void paint (Graphics& g)
  113. {
  114. g.fillAll (Colour::greyLevel (0.92f));
  115. }
  116. void resized()
  117. {
  118. props->setSize (getWidth(), getHeight());
  119. }
  120. private:
  121. EditorPanelBase* owner;
  122. PropertyPanel* props;
  123. };
  124. Toolbar* toolbar;
  125. Viewport* viewport;
  126. InfoPanel* infoPanel;
  127. TreeView* tree;
  128. };
  129. #endif // __JUCER_EDITORPANEL_H_8E192A99__