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.

131 lines
5.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #pragma once
  18. //==============================================================================
  19. /**
  20. A component to allow editing of the keymaps stored by a KeyPressMappingSet
  21. object.
  22. @see KeyPressMappingSet
  23. */
  24. class JUCE_API KeyMappingEditorComponent : public Component
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates a KeyMappingEditorComponent.
  29. @param mappingSet this is the set of mappings to display and edit. Make sure the
  30. mappings object is not deleted before this component!
  31. @param showResetToDefaultButton if true, then at the bottom of the list, the
  32. component will include a 'reset to defaults' button.
  33. */
  34. KeyMappingEditorComponent (KeyPressMappingSet& mappingSet,
  35. bool showResetToDefaultButton);
  36. /** Destructor. */
  37. ~KeyMappingEditorComponent();
  38. //==============================================================================
  39. /** Sets up the colours to use for parts of the component.
  40. @param mainBackground colour to use for most of the background
  41. @param textColour colour to use for the text
  42. */
  43. void setColours (Colour mainBackground,
  44. Colour textColour);
  45. /** Returns the KeyPressMappingSet that this component is acting upon. */
  46. KeyPressMappingSet& getMappings() const noexcept { return mappings; }
  47. /** Returns the ApplicationCommandManager that this component is connected to. */
  48. ApplicationCommandManager& getCommandManager() const noexcept { return mappings.getCommandManager(); }
  49. //==============================================================================
  50. /** Can be overridden if some commands need to be excluded from the list.
  51. By default this will use the KeyPressMappingSet's shouldCommandBeVisibleInEditor()
  52. method to decide what to return, but you can override it to handle special cases.
  53. */
  54. virtual bool shouldCommandBeIncluded (CommandID commandID);
  55. /** Can be overridden to indicate that some commands are shown as read-only.
  56. By default this will use the KeyPressMappingSet's shouldCommandBeReadOnlyInEditor()
  57. method to decide what to return, but you can override it to handle special cases.
  58. */
  59. virtual bool isCommandReadOnly (CommandID commandID);
  60. /** This can be overridden to let you change the format of the string used
  61. to describe a keypress.
  62. This is handy if you're using non-standard KeyPress objects, e.g. for custom
  63. keys that are triggered by something else externally. If you override the
  64. method, be sure to let the base class's method handle keys you're not
  65. interested in.
  66. */
  67. virtual String getDescriptionForKeyPress (const KeyPress& key);
  68. //==============================================================================
  69. /** A set of colour IDs to use to change the colour of various aspects of the editor.
  70. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  71. methods.
  72. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  73. */
  74. enum ColourIds
  75. {
  76. backgroundColourId = 0x100ad00, /**< The background colour to fill the editor background. */
  77. textColourId = 0x100ad01, /**< The colour for the text. */
  78. };
  79. //==============================================================================
  80. /** @internal */
  81. void parentHierarchyChanged() override;
  82. /** @internal */
  83. void resized() override;
  84. private:
  85. //==============================================================================
  86. KeyPressMappingSet& mappings;
  87. TreeView tree;
  88. TextButton resetButton;
  89. class TopLevelItem;
  90. class ChangeKeyButton;
  91. class MappingItem;
  92. class CategoryItem;
  93. class ItemComponent;
  94. friend class TopLevelItem;
  95. friend struct ContainerDeletePolicy<ChangeKeyButton>;
  96. friend struct ContainerDeletePolicy<TopLevelItem>;
  97. ScopedPointer<TopLevelItem> treeItem;
  98. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (KeyMappingEditorComponent)
  99. };