juce_CaretComponent.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2013 - Raw Material Software 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. #ifndef JUCE_CARETCOMPONENT_H_INCLUDED
  18. #define JUCE_CARETCOMPONENT_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. */
  22. class JUCE_API CaretComponent : public Component,
  23. private Timer
  24. {
  25. public:
  26. //==============================================================================
  27. /** Creates the caret component.
  28. The keyFocusOwner is an optional component which the caret will check, making
  29. itself visible only when the keyFocusOwner has keyboard focus.
  30. */
  31. CaretComponent (Component* keyFocusOwner);
  32. /** Destructor. */
  33. ~CaretComponent();
  34. //==============================================================================
  35. /** Sets the caret's position to place it next to the given character.
  36. The area is the rectangle containing the entire character that the caret is
  37. positioned on, so by default a vertical-line caret may choose to just show itself
  38. at the left of this area. You can override this method to customise its size.
  39. This method will also force the caret to reset its timer and become visible (if
  40. appropriate), so that as it moves, you can see where it is.
  41. */
  42. virtual void setCaretPosition (const Rectangle<int>& characterArea);
  43. /** A set of colour IDs to use to change the colour of various aspects of the caret.
  44. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  45. methods.
  46. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  47. */
  48. enum ColourIds
  49. {
  50. caretColourId = 0x1000204, /**< The colour with which to draw the caret. */
  51. };
  52. //==============================================================================
  53. /** @internal */
  54. void paint (Graphics&) override;
  55. private:
  56. Component* owner;
  57. bool shouldBeShown() const;
  58. void timerCallback() override;
  59. JUCE_DECLARE_NON_COPYABLE (CaretComponent)
  60. };
  61. #endif // JUCE_CARETCOMPONENT_H_INCLUDED