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.

154 lines
4.6KB

  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_JucerTreeViewBase.h"
  19. //==============================================================================
  20. JucerTreeViewBase::JucerTreeViewBase()
  21. : numLeftHandComps (0)
  22. {
  23. setLinesDrawnForSubItems (false);
  24. }
  25. JucerTreeViewBase::~JucerTreeViewBase()
  26. {
  27. }
  28. const Font JucerTreeViewBase::getFont() const
  29. {
  30. return Font (getItemHeight() * 0.6f);
  31. }
  32. int JucerTreeViewBase::getTextX() const
  33. {
  34. return (numLeftHandComps + 1) * getItemHeight() + 8;
  35. }
  36. void JucerTreeViewBase::paintItem (Graphics& g, int width, int height)
  37. {
  38. if (isSelected())
  39. g.fillAll (Colour (0x401111ee));
  40. const int x = getTextX();
  41. g.setColour (Colours::black);
  42. getIcon()->drawWithin (g, Rectangle<float> (0.0f, 2.0f, height + 6.0f, height - 4.0f),
  43. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, 1.0f);
  44. g.setFont (getFont());
  45. g.setColour (isMissing() ? Colours::red : Colours::black);
  46. g.drawFittedText (getDisplayName(), x, 0, width - x, height, Justification::centredLeft, 1, 0.8f);
  47. }
  48. void JucerTreeViewBase::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  49. {
  50. Path p;
  51. if (isOpen())
  52. p.addTriangle (width * 0.2f, height * 0.25f, width * 0.8f, height * 0.25f, width * 0.5f, height * 0.75f);
  53. else
  54. p.addTriangle (width * 0.25f, height * 0.25f, width * 0.8f, height * 0.5f, width * 0.25f, height * 0.75f);
  55. g.setColour (Colours::lightgrey);
  56. g.fillPath (p);
  57. }
  58. //==============================================================================
  59. class TreeLeftHandButtonHolderComponent : public Component
  60. {
  61. public:
  62. TreeLeftHandButtonHolderComponent (const Array<Component*>& comps)
  63. {
  64. components.addArray (comps);
  65. setInterceptsMouseClicks (false, true);
  66. for (int i = 0; i < comps.size(); ++i)
  67. addAndMakeVisible (comps.getUnchecked(i));
  68. }
  69. void resized()
  70. {
  71. const int edge = 1;
  72. const int itemSize = getHeight() - edge * 2;
  73. for (int i = 0; i < components.size(); ++i)
  74. components.getUnchecked(i)->setBounds (5 + (i + 1) * getHeight(), edge, itemSize, itemSize);
  75. }
  76. private:
  77. OwnedArray<Component> components;
  78. };
  79. Component* JucerTreeViewBase::createItemComponent()
  80. {
  81. Array<Component*> components;
  82. createLeftEdgeComponents (components);
  83. numLeftHandComps = components.size();
  84. return numLeftHandComps == 0 ? 0 : new TreeLeftHandButtonHolderComponent (components);
  85. }
  86. //==============================================================================
  87. void JucerTreeViewBase::showRenameBox()
  88. {
  89. TextEditor ed (String::empty);
  90. ed.setMultiLine (false, false);
  91. ed.setPopupMenuEnabled (false);
  92. ed.setSelectAllWhenFocused (true);
  93. ed.setFont (getFont());
  94. ed.addListener (this);
  95. ed.setText (getRenamingName());
  96. Rectangle<int> r (getItemPosition (true));
  97. r.setLeft (r.getX() + getTextX());
  98. r.setHeight (getItemHeight());
  99. ed.setBounds (r);
  100. getOwnerView()->addAndMakeVisible (&ed);
  101. if (ed.runModalLoop() != 0)
  102. setName (ed.getText());
  103. }
  104. void JucerTreeViewBase::itemClicked (const MouseEvent& e)
  105. {
  106. if (e.mods.isPopupMenu())
  107. {
  108. if (getOwnerView()->getNumSelectedItems() > 1)
  109. showMultiSelectionPopupMenu();
  110. else
  111. showPopupMenu();
  112. }
  113. }
  114. void JucerTreeViewBase::showPopupMenu()
  115. {
  116. }
  117. void JucerTreeViewBase::showMultiSelectionPopupMenu()
  118. {
  119. }