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.

211 lines
6.2KB

  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_DRAWABLETREEVIEWITEM_JUCEHEADER__
  19. #define __JUCER_DRAWABLETREEVIEWITEM_JUCEHEADER__
  20. //==============================================================================
  21. /**
  22. */
  23. class DrawableTreeViewItem : public JucerTreeViewBase,
  24. public ValueTree::Listener,
  25. public ChangeListener
  26. {
  27. public:
  28. DrawableTreeViewItem (DrawableEditor& editor_, const ValueTree& drawableRoot)
  29. : editor (editor_), node (drawableRoot), typeName (drawableRoot.getType().toString())
  30. {
  31. node.getState().addListener (this);
  32. editor.getSelection().addChangeListener (this);
  33. }
  34. ~DrawableTreeViewItem()
  35. {
  36. editor.getSelection().removeChangeListener (this);
  37. node.getState().removeListener (this);
  38. }
  39. //==============================================================================
  40. void valueTreePropertyChanged (ValueTree& tree, const Identifier& property)
  41. {
  42. }
  43. void valueTreeChildrenChanged (ValueTree& tree)
  44. {
  45. if (tree == node.getState())
  46. refreshSubItems();
  47. }
  48. void valueTreeParentChanged (ValueTree& tree)
  49. {
  50. }
  51. //==============================================================================
  52. // TreeViewItem stuff..
  53. bool mightContainSubItems()
  54. {
  55. return node.getState().getType() == DrawableComposite::valueTreeType;
  56. }
  57. const String getUniqueName() const
  58. {
  59. jassert (node.getID().isNotEmpty());
  60. return node.getID();
  61. }
  62. void itemOpennessChanged (bool isNowOpen)
  63. {
  64. if (isNowOpen)
  65. refreshSubItems();
  66. }
  67. void refreshSubItems()
  68. {
  69. if (node.getState().getType() == DrawableComposite::valueTreeType)
  70. {
  71. ScopedPointer <XmlElement> oldOpenness (getOpennessState());
  72. clearSubItems();
  73. DrawableComposite::ValueTreeWrapper composite (node.getState());
  74. for (int i = 0; i < composite.getNumDrawables(); ++i)
  75. {
  76. ValueTree subNode (composite.getDrawableState (i));
  77. DrawableTreeViewItem* const item = new DrawableTreeViewItem (editor, subNode);
  78. addSubItem (item);
  79. }
  80. if (oldOpenness != 0)
  81. restoreOpennessState (*oldOpenness);
  82. editor.getSelection().changed();
  83. }
  84. }
  85. const String getDisplayName() const
  86. {
  87. const String name (getRenamingName());
  88. return typeName + (name.isEmpty() ? String::empty
  89. : (" \"" + name + "\""));
  90. }
  91. const String getRenamingName() const
  92. {
  93. return node.getID();
  94. }
  95. void setName (const String& newName)
  96. {
  97. }
  98. bool isMissing() { return false; }
  99. Image* getIcon() const
  100. {
  101. return LookAndFeel::getDefaultLookAndFeel().getDefaultDocumentFileImage();
  102. }
  103. void itemClicked (const MouseEvent& e)
  104. {
  105. }
  106. void itemDoubleClicked (const MouseEvent& e)
  107. {
  108. }
  109. void itemSelectionChanged (bool isNowSelected)
  110. {
  111. const String objectId (node.getID());
  112. if (isNowSelected)
  113. editor.getSelection().addToSelection (objectId);
  114. else
  115. editor.getSelection().deselect (objectId);
  116. }
  117. void changeListenerCallback (void*)
  118. {
  119. setSelected (editor.getSelection().isSelected (node.getID()), false);
  120. }
  121. const String getTooltip()
  122. {
  123. return String::empty;
  124. }
  125. const String getDragSourceDescription()
  126. {
  127. return drawableItemDragType;
  128. }
  129. //==============================================================================
  130. // Drag-and-drop stuff..
  131. bool isInterestedInFileDrag (const StringArray& files)
  132. {
  133. return false;
  134. }
  135. void filesDropped (const StringArray& files, int insertIndex)
  136. {
  137. }
  138. bool isInterestedInDragSource (const String& sourceDescription, Component* sourceComponent)
  139. {
  140. return false;
  141. }
  142. void itemDropped (const String& sourceDescription, Component* sourceComponent, int insertIndex)
  143. {
  144. }
  145. //==============================================================================
  146. void showRenameBox()
  147. {
  148. }
  149. // Text editor listener for renaming..
  150. void textEditorTextChanged (TextEditor& textEditor) {}
  151. void textEditorReturnKeyPressed (TextEditor& textEditor) { textEditor.exitModalState (1); }
  152. void textEditorEscapeKeyPressed (TextEditor& textEditor) { textEditor.exitModalState (0); }
  153. void textEditorFocusLost (TextEditor& textEditor) { textEditor.exitModalState (0); }
  154. //==============================================================================
  155. DrawableEditor& editor;
  156. Drawable::ValueTreeWrapperBase node;
  157. private:
  158. String typeName;
  159. DrawableEditor* getEditor() const
  160. {
  161. return getOwnerView()->findParentComponentOfClass ((DrawableEditor*) 0);
  162. }
  163. };
  164. #endif // __JUCER_DRAWABLETREEVIEWITEM_JUCEHEADER__