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.

247 lines
7.2KB

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