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.

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