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.

152 lines
6.1KB

  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 __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__
  19. #define __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__
  20. #include "../keyboard/juce_KeyPressMappingSet.h"
  21. #include "../controls/juce_TreeView.h"
  22. #include "../buttons/juce_TextButton.h"
  23. //==============================================================================
  24. /**
  25. A component to allow editing of the keymaps stored by a KeyPressMappingSet
  26. object.
  27. @see KeyPressMappingSet
  28. */
  29. class JUCE_API KeyMappingEditorComponent : public Component,
  30. public TreeViewItem,
  31. public ChangeListener,
  32. private ButtonListener
  33. {
  34. public:
  35. //==============================================================================
  36. /** Creates a KeyMappingEditorComponent.
  37. @param mappingSet this is the set of mappings to display and
  38. edit. Make sure the mappings object is not
  39. deleted before this component!
  40. @param showResetToDefaultButton if true, then at the bottom of the
  41. list, the component will include a 'reset to
  42. defaults' button.
  43. */
  44. KeyMappingEditorComponent (KeyPressMappingSet* const mappingSet,
  45. const bool showResetToDefaultButton);
  46. /** Destructor. */
  47. virtual ~KeyMappingEditorComponent();
  48. //==============================================================================
  49. /** Sets up the colours to use for parts of the component.
  50. @param mainBackground colour to use for most of the background
  51. @param textColour colour to use for the text
  52. */
  53. void setColours (const Colour& mainBackground,
  54. const Colour& textColour);
  55. /** Returns the KeyPressMappingSet that this component is acting upon.
  56. */
  57. KeyPressMappingSet* getMappings() const throw() { return mappings; }
  58. //==============================================================================
  59. /** Can be overridden if some commands need to be excluded from the list.
  60. By default this will use the KeyPressMappingSet's shouldCommandBeVisibleInEditor()
  61. method to decide what to return, but you can override it to handle special cases.
  62. */
  63. virtual bool shouldCommandBeIncluded (const CommandID commandID);
  64. /** Can be overridden to indicate that some commands are shown as read-only.
  65. By default this will use the KeyPressMappingSet's shouldCommandBeReadOnlyInEditor()
  66. method to decide what to return, but you can override it to handle special cases.
  67. */
  68. virtual bool isCommandReadOnly (const CommandID commandID);
  69. /** This can be overridden to let you change the format of the string used
  70. to describe a keypress.
  71. This is handy if you're using non-standard KeyPress objects, e.g. for custom
  72. keys that are triggered by something else externally. If you override the
  73. method, be sure to let the base class's method handle keys you're not
  74. interested in.
  75. */
  76. virtual const String getDescriptionForKeyPress (const KeyPress& key);
  77. //==============================================================================
  78. /** A set of colour IDs to use to change the colour of various aspects of the editor.
  79. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  80. methods.
  81. To change the colours of the menu that pops up
  82. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  83. */
  84. enum ColourIds
  85. {
  86. backgroundColourId = 0x100ad00, /**< The background colour to fill the editor background. */
  87. textColourId = 0x100ad01, /**< The colour for the text. */
  88. };
  89. //==============================================================================
  90. /** @internal */
  91. void parentHierarchyChanged();
  92. /** @internal */
  93. void resized();
  94. /** @internal */
  95. void changeListenerCallback (void*);
  96. /** @internal */
  97. bool mightContainSubItems();
  98. /** @internal */
  99. const String getUniqueName() const;
  100. /** @internal */
  101. void buttonClicked (Button* button);
  102. juce_UseDebuggingNewOperator
  103. private:
  104. //==============================================================================
  105. KeyPressMappingSet* mappings;
  106. TreeView* tree;
  107. friend class KeyMappingTreeViewItem;
  108. friend class KeyCategoryTreeViewItem;
  109. friend class KeyMappingItemComponent;
  110. friend class KeyMappingChangeButton;
  111. TextButton* resetButton;
  112. void assignNewKey (const CommandID commandID, int index);
  113. KeyMappingEditorComponent (const KeyMappingEditorComponent&);
  114. const KeyMappingEditorComponent& operator= (const KeyMappingEditorComponent&);
  115. };
  116. #endif // __JUCE_KEYMAPPINGEDITORCOMPONENT_JUCEHEADER__