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.

123 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-7 by Raw Material Software ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the
  7. GNU General Public License, as published by the Free Software Foundation;
  8. either version 2 of the License, or (at your option) any later version.
  9. JUCE is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with JUCE; if not, visit www.gnu.org/licenses or write to the
  15. Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  16. Boston, MA 02111-1307 USA
  17. ------------------------------------------------------------------------------
  18. If you'd like to release a closed-source product which uses JUCE, commercial
  19. licenses are also available: visit www.rawmaterialsoftware.com/juce for
  20. more information.
  21. ==============================================================================
  22. */
  23. #ifndef __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  24. #define __JUCE_TOOLTIPWINDOW_JUCEHEADER__
  25. #include "../juce_Component.h"
  26. #include "../../../events/juce_Timer.h"
  27. #include "../mouse/juce_TooltipClient.h"
  28. //==============================================================================
  29. /**
  30. A window that displays a pop-up tooltip when the mouse hovers over another component.
  31. To enable tooltips in your app, just create a single instance of a TooltipWindow
  32. object.
  33. The TooltipWindow object will then stay invisible, waiting until the mouse
  34. hovers for the specified length of time - it will then see if it's currently
  35. over a component which implements the TooltipClient interface, and if so,
  36. it will make itself visible to show the tooltip in the appropriate place.
  37. @see TooltipClient, SettableTooltipClient
  38. */
  39. class JUCE_API TooltipWindow : public Component,
  40. private Timer
  41. {
  42. public:
  43. //==============================================================================
  44. /** Creates a tooltip window.
  45. Make sure your app only creates one instance of this class, otherwise you'll
  46. get multiple overlaid tooltips appearing. The window will initially be invisible
  47. and will make itself visible when it needs to display a tip.
  48. To change the style of tooltips, see the LookAndFeel class for its tooltip
  49. methods.
  50. @param parentComponent if set to 0, the TooltipWindow will appear on the desktop,
  51. otherwise the tooltip will be added to the given parent
  52. component.
  53. @param millisecondsBeforeTipAppears the time for which the mouse has to stay still
  54. before a tooltip will be shown
  55. @see TooltipClient, LookAndFeel::drawTooltip, LookAndFeel::getTooltipSize
  56. */
  57. TooltipWindow (Component* parentComponent = 0,
  58. const int millisecondsBeforeTipAppears = 700);
  59. /** Destructor. */
  60. ~TooltipWindow();
  61. //==============================================================================
  62. /** A set of colour IDs to use to change the colour of various aspects of the tooltip.
  63. These constants can be used either via the Component::setColour(), or LookAndFeel::setColour()
  64. methods.
  65. @see Component::setColour, Component::findColour, LookAndFeel::setColour, LookAndFeel::findColour
  66. */
  67. enum ColourIds
  68. {
  69. backgroundColourId = 0x1001b00, /**< The colour to fill the background with. */
  70. textColourId = 0x1001c00, /**< The colour to use for the text. */
  71. outlineColourId = 0x1001c10 /**< The colour to use to draw an outline around the tooltip. */
  72. };
  73. //==============================================================================
  74. juce_UseDebuggingNewOperator
  75. private:
  76. //==============================================================================
  77. const int millisecondsBeforeTipAppears;
  78. int mouseX, mouseY, mouseClicks;
  79. unsigned int lastCompChangeTime, lastHideTime;
  80. Component* lastComponentUnderMouse;
  81. bool changedCompsSinceShown;
  82. String tipShowing, lastTipUnderMouse;
  83. void paint (Graphics& g);
  84. void mouseEnter (const MouseEvent& e);
  85. void timerCallback();
  86. static const String getTipFor (Component* const c);
  87. void showFor (Component* const c, const String& tip);
  88. void hide();
  89. TooltipWindow (const TooltipWindow&);
  90. const TooltipWindow& operator= (const TooltipWindow&);
  91. };
  92. #endif // __JUCE_TOOLTIPWINDOW_JUCEHEADER__