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.

249 lines
8.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. #include "../../jucer_Headers.h"
  19. #include "../../model/Drawable/jucer_DrawableDocument.h"
  20. #include "../jucer_JucerTreeViewBase.h"
  21. #include "../Editor Base/jucer_EditorPanel.h"
  22. #include "../Editor Base/jucer_EditorCanvas.h"
  23. #include "../Editor Base/jucer_EditorDragOperation.h"
  24. #include "jucer_DrawableEditor.h"
  25. #include "jucer_DrawableEditorCanvas.h"
  26. #include "jucer_DrawableEditorTreeView.h"
  27. #include "jucer_DrawableEditorToolbar.h"
  28. //==============================================================================
  29. class DrawableEditor::Panel : public EditorPanelBase
  30. {
  31. public:
  32. Panel (DrawableEditor& editor_)
  33. : toolbarFactory (editor_),
  34. editor (editor_)
  35. {
  36. }
  37. ~Panel()
  38. {
  39. shutdown();
  40. }
  41. void createCanvas()
  42. {
  43. initialise (new DrawableEditorCanvas (editor), toolbarFactory,
  44. new DrawableTreeViewItem (editor, editor.getDocument().getRootDrawableNode().getState()));
  45. }
  46. SelectedItemSet<String>& getSelection()
  47. {
  48. return editor.getSelection();
  49. }
  50. void getSelectedItemProperties (Array<PropertyComponent*>& newComps)
  51. {
  52. //editor.getSelectedItemProperties (newComps);
  53. }
  54. private:
  55. DrawableEditorToolbarFactory toolbarFactory;
  56. DrawableEditor& editor;
  57. };
  58. //==============================================================================
  59. DrawableEditor::DrawableEditor (OpenDocumentManager::Document* document_,
  60. Project* project_,
  61. DrawableDocument* drawableDocument_)
  62. : DocumentEditorComponent (document_),
  63. project (project_),
  64. drawableDocument (drawableDocument_)
  65. {
  66. jassert (drawableDocument_ != 0);
  67. setOpaque (true);
  68. addAndMakeVisible (panel = new Panel (*this));
  69. panel->createCanvas();
  70. }
  71. DrawableEditor::~DrawableEditor()
  72. {
  73. deleteAllChildren();
  74. }
  75. void DrawableEditor::paint (Graphics& g)
  76. {
  77. g.fillAll (Colours::white);
  78. }
  79. void DrawableEditor::resized()
  80. {
  81. panel->setBounds (getLocalBounds());
  82. }
  83. //==============================================================================
  84. void DrawableEditor::deleteSelection()
  85. {
  86. }
  87. void DrawableEditor::selectionToFront()
  88. {
  89. }
  90. void DrawableEditor::selectionToBack()
  91. {
  92. }
  93. void DrawableEditor::showNewShapeMenu (Component* componentToAttachTo)
  94. {
  95. PopupMenu m;
  96. getDocument().addNewItemMenuItems (m);
  97. const int r = m.showAt (componentToAttachTo);
  98. getDocument().performNewItemMenuItem (r);
  99. }
  100. //==============================================================================
  101. void DrawableEditor::getAllCommands (Array <CommandID>& commands)
  102. {
  103. DocumentEditorComponent::getAllCommands (commands);
  104. const CommandID ids[] = { CommandIDs::undo,
  105. CommandIDs::redo,
  106. CommandIDs::toFront,
  107. CommandIDs::toBack,
  108. CommandIDs::showOrHideProperties,
  109. CommandIDs::showOrHideTree,
  110. CommandIDs::showOrHideMarkers,
  111. CommandIDs::toggleSnapping,
  112. StandardApplicationCommandIDs::del };
  113. commands.addArray (ids, numElementsInArray (ids));
  114. }
  115. void DrawableEditor::getCommandInfo (CommandID commandID, ApplicationCommandInfo& result)
  116. {
  117. result.setActive (document != 0);
  118. switch (commandID)
  119. {
  120. case CommandIDs::undo:
  121. result.setInfo ("Undo", "Undoes the last change", CommandCategories::general, 0);
  122. result.defaultKeypresses.add (KeyPress ('z', ModifierKeys::commandModifier, 0));
  123. break;
  124. case CommandIDs::redo:
  125. result.setInfo ("Redo", "Redoes the last change", CommandCategories::general, 0);
  126. result.defaultKeypresses.add (KeyPress ('z', ModifierKeys::shiftModifier | ModifierKeys::commandModifier, 0));
  127. result.defaultKeypresses.add (KeyPress ('y', ModifierKeys::commandModifier, 0));
  128. break;
  129. case CommandIDs::toFront:
  130. result.setInfo ("Bring to Front", "Brings the selected items to the front", CommandCategories::editing, 0);
  131. break;
  132. case CommandIDs::toBack:
  133. result.setInfo ("Send to Back", "Moves the selected items to the back", CommandCategories::editing, 0);
  134. break;
  135. case CommandIDs::showOrHideProperties:
  136. result.setInfo ("Show/Hide Tree", "Shows or hides the component tree view", CommandCategories::editing, 0);
  137. result.setTicked (panel != 0 && panel->arePropertiesVisible());
  138. break;
  139. case CommandIDs::showOrHideTree:
  140. result.setInfo ("Show/Hide Properties", "Shows or hides the component properties panel", CommandCategories::editing, 0);
  141. result.setTicked (panel != 0 && panel->isTreeVisible());
  142. break;
  143. case CommandIDs::showOrHideMarkers:
  144. result.setInfo ("Show/Hide Markers", "Shows or hides the markers", CommandCategories::editing, 0);
  145. result.setTicked (panel != 0 && panel->areMarkersVisible());
  146. break;
  147. case CommandIDs::toggleSnapping:
  148. result.setInfo ("Toggle snapping", "Turns object snapping on or off", CommandCategories::editing, 0);
  149. result.setTicked (panel != 0 && panel->isSnappingEnabled());
  150. break;
  151. case StandardApplicationCommandIDs::del:
  152. result.setInfo ("Delete", String::empty, CommandCategories::general, 0);
  153. result.defaultKeypresses.add (KeyPress (KeyPress::deleteKey, 0, 0));
  154. result.defaultKeypresses.add (KeyPress (KeyPress::backspaceKey, 0, 0));
  155. break;
  156. default:
  157. DocumentEditorComponent::getCommandInfo (commandID, result);
  158. break;
  159. }
  160. }
  161. bool DrawableEditor::perform (const InvocationInfo& info)
  162. {
  163. switch (info.commandID)
  164. {
  165. case CommandIDs::undo:
  166. getDocument().getUndoManager()->beginNewTransaction();
  167. getDocument().getUndoManager()->undo();
  168. return true;
  169. case CommandIDs::redo:
  170. getDocument().getUndoManager()->beginNewTransaction();
  171. getDocument().getUndoManager()->redo();
  172. return true;
  173. case CommandIDs::toFront:
  174. selectionToFront();
  175. return true;
  176. case CommandIDs::toBack:
  177. selectionToBack();
  178. return true;
  179. case CommandIDs::showOrHideProperties:
  180. panel->showOrHideProperties();
  181. return true;
  182. case CommandIDs::showOrHideTree:
  183. panel->showOrHideTree();
  184. return true;
  185. case CommandIDs::showOrHideMarkers:
  186. panel->showOrHideMarkers();
  187. return true;
  188. case CommandIDs::toggleSnapping:
  189. panel->toggleSnapping();
  190. return true;
  191. case StandardApplicationCommandIDs::del:
  192. deleteSelection();
  193. return true;
  194. default:
  195. break;
  196. }
  197. return DocumentEditorComponent::perform (info);
  198. }