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.

120 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 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_TOOLTIPWINDOW_JUCEHEADER__
  19. #define __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  20. #include "../components/juce_Component.h"
  21. #include "../mouse/juce_TooltipClient.h"
  22. //==============================================================================
  23. /**
  24. A window that displays a pop-up tooltip when the mouse hovers over another component.
  25. To enable tooltips in your app, just create a single instance of a TooltipWindow
  26. object.
  27. The TooltipWindow object will then stay invisible, waiting until the mouse
  28. hovers for the specified length of time - it will then see if it's currently
  29. over a component which implements the TooltipClient interface, and if so,
  30. it will make itself visible to show the tooltip in the appropriate place.
  31. @see TooltipClient, SettableTooltipClient
  32. */
  33. class JUCE_API TooltipWindow : public Component,
  34. private Timer
  35. {
  36. public:
  37. //==============================================================================
  38. /** Creates a tooltip window.
  39. Make sure your app only creates one instance of this class, otherwise you'll
  40. get multiple overlaid tooltips appearing. The window will initially be invisible
  41. and will make itself visible when it needs to display a tip.
  42. To change the style of tooltips, see the LookAndFeel class for its tooltip
  43. methods.
  44. @param parentComponent if set to 0, the TooltipWindow will appear on the desktop,
  45. otherwise the tooltip will be added to the given parent
  46. component.
  47. @param millisecondsBeforeTipAppears the time for which the mouse has to stay still
  48. before a tooltip will be shown
  49. @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize
  50. */
  51. explicit TooltipWindow (Component* parentComponent = nullptr,
  52. int millisecondsBeforeTipAppears = 700);
  53. /** Destructor. */
  54. ~TooltipWindow();
  55. //==============================================================================
  56. /** Changes the time before the tip appears.
  57. This lets you change the value that was set in the constructor.
  58. */
  59. void setMillisecondsBeforeTipAppears (int newTimeMs = 700) noexcept;
  60. //==============================================================================
  61. /** A set of colour IDs to use to change the colour of various aspects of the tooltip.
  62. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  63. methods.
  64. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  65. */
  66. enum ColourIds
  67. {
  68. backgroundColourId = 0x1001b00, /**< The colour to fill the background with. */
  69. textColourId = 0x1001c00, /**< The colour to use for the text. */
  70. outlineColourId = 0x1001c10 /**< The colour to use to draw an outline around the tooltip. */
  71. };
  72. private:
  73. //==============================================================================
  74. int millisecondsBeforeTipAppears;
  75. Point<int> lastMousePos;
  76. int mouseClicks;
  77. unsigned int lastCompChangeTime, lastHideTime;
  78. Component* lastComponentUnderMouse;
  79. bool changedCompsSinceShown;
  80. String tipShowing, lastTipUnderMouse;
  81. void paint (Graphics& g);
  82. void mouseEnter (const MouseEvent& e);
  83. void timerCallback();
  84. static String getTipFor (Component* c);
  85. void showFor (const String& tip);
  86. void hide();
  87. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TooltipWindow);
  88. };
  89. #endif // __JUCE_TOOLTIPWINDOW_JUCEHEADER__