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.

153 lines
5.1KB

  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_COMPONENTEDITORTOOLBAR_H_6B5CA931__
  19. #define __JUCER_COMPONENTEDITORTOOLBAR_H_6B5CA931__
  20. #include "../../utility/jucer_ColourEditorComponent.h"
  21. //==============================================================================
  22. class ComponentEditorToolbarFactory : public ToolbarItemFactory
  23. {
  24. public:
  25. ComponentEditorToolbarFactory (ComponentEditor& editor_)
  26. : editor (editor_)
  27. {
  28. }
  29. ~ComponentEditorToolbarFactory()
  30. {
  31. }
  32. //==============================================================================
  33. enum ToolbarItemIds
  34. {
  35. createComponent = 1,
  36. changeBackground,
  37. showInfo,
  38. showTree,
  39. showOrHideMarkers,
  40. toggleSnapping
  41. };
  42. void getAllToolbarItemIds (Array <int>& ids)
  43. {
  44. ids.add (createComponent);
  45. ids.add (changeBackground);
  46. ids.add (showInfo);
  47. ids.add (showTree);
  48. ids.add (showOrHideMarkers);
  49. ids.add (toggleSnapping);
  50. ids.add (separatorBarId);
  51. ids.add (spacerId);
  52. ids.add (flexibleSpacerId);
  53. }
  54. void getDefaultItemSet (Array <int>& ids)
  55. {
  56. ids.add (spacerId);
  57. ids.add (createComponent);
  58. ids.add (changeBackground);
  59. ids.add (flexibleSpacerId);
  60. ids.add (showOrHideMarkers);
  61. ids.add (toggleSnapping);
  62. ids.add (flexibleSpacerId);
  63. ids.add (showTree);
  64. ids.add (showInfo);
  65. ids.add (spacerId);
  66. }
  67. ToolbarItemComponent* createItem (int itemId)
  68. {
  69. String name;
  70. int commandId = 0;
  71. switch (itemId)
  72. {
  73. case createComponent: return new NewComponentToolbarButton (editor, itemId);
  74. case changeBackground: return new BackgroundColourToolbarButton (editor, itemId);
  75. case showInfo: name = "info"; commandId = CommandIDs::showOrHideProperties; break;
  76. case showTree: name = "tree"; commandId = CommandIDs::showOrHideTree; break;
  77. case showOrHideMarkers: name = "markers"; commandId = CommandIDs::showOrHideMarkers; break;
  78. case toggleSnapping: name = "snap"; commandId = CommandIDs::toggleSnapping; break;
  79. default: jassertfalse; return 0;
  80. }
  81. JucerToolbarButton* b = new JucerToolbarButton (itemId, name);
  82. b->setCommandToTrigger (commandManager, commandId, true);
  83. return b;
  84. }
  85. //==============================================================================
  86. class NewComponentToolbarButton : public JucerToolbarButton
  87. {
  88. public:
  89. NewComponentToolbarButton (ComponentEditor& editor_, int itemId_)
  90. : JucerToolbarButton (itemId_, "create..."), editor (editor_)
  91. {
  92. setTriggeredOnMouseDown (true);
  93. }
  94. void clicked()
  95. {
  96. editor.showNewComponentMenu (this);
  97. }
  98. private:
  99. ComponentEditor& editor;
  100. };
  101. //==============================================================================
  102. class BackgroundColourToolbarButton : public JucerToolbarButton
  103. {
  104. public:
  105. BackgroundColourToolbarButton (ComponentEditor& editor_, int itemId_)
  106. : JucerToolbarButton (itemId_, "background"), editor (editor_)
  107. {
  108. setTriggeredOnMouseDown (true);
  109. }
  110. void clicked()
  111. {
  112. editor.getDocument().getUndoManager()->beginNewTransaction();
  113. PopupColourSelector::showAt (this, editor.getDocument().getBackgroundColour(), Colours::white, true);
  114. }
  115. private:
  116. ComponentEditor& editor;
  117. };
  118. private:
  119. ComponentEditor& editor;
  120. ComponentEditorToolbarFactory (const ComponentEditorToolbarFactory&);
  121. ComponentEditorToolbarFactory& operator= (const ComponentEditorToolbarFactory&);
  122. };
  123. #endif // __JUCER_COMPONENTEDITORTOOLBAR_H_6B5CA931__