# SharedResourcePointer and TooltipWindow example?

**URL:** <https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879>\
**Category:** General JUCE discussion\
**Created:** [August 3, 2018, 2:10pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879 "2018-08-03T14:10:47Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 2:10pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/1 "2018-08-03T14:10:48Z")

</div>

I’m trying to follow the advice in TooltipWindow to use a SharedResourcePointer, but I can’t figure out exactly _how_ to change my code to work with that. Currently, I have a TooltipWindow\* that I create using “tooltipWindow = new TooltipWindow(this);” in my editor’s constructor. If I define it in my class as “SharedResourcePointer\<TooltipWindow\> tooltipWindow;”, then how do I create it? I get an error on the “new” that I have currently, saying there is no “=” operator for that. I’ve looked for examples, but none of the ones I’ve seen actually show how/where it is created, only a definition in the class. I tried that (not calling new), and my plug-in crashes when it tries to call the window’s setMillisecondsBeforeTipAppears(), because it hasn’t been created. I’m confused!

---

<div class="post-metadata">

**Author:** ![bgporter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bgporter/32/12710_2.png) [@bgporter](https://forum.juce.com/u/bgporter)\
**Post date:** [August 3, 2018, 2:19pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/2 "2018-08-03T14:19:04Z")

</div>

It’s a class template, so you need to declare instances of it as

```auto
   SharedResourcePointer<TooltipWindow> tipWindow;

```

…and all of the allocation details are handled for you. On first execution, that template will create a new instance of the template parameter class; on subsequent instantiations, that already existing instance will be used, and that instance is guaranteed to exist until the last `SharedResourcePointer` object goes out of scope.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 2:23pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/3 "2018-08-03T14:23:27Z")

</div>

That’s what I did. (I edited the post to show the part in angle brackets; requires using backslash to escape that, I guess). But it crashes when it executes the call to set the time before showing. Plus, there is no way to set “this” as the parent component when using that. Just found another post that suggest that the use of SharedResourcePointer is no longer recommended? Instead, I can define it as “TooltipWindow tooltipWindow {this};” Is that the way I should do this (for an audio plug-in)?

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 2:34pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/4 "2018-08-03T14:34:24Z")

</div>

Well, that idea doesn’t fly, because then I get multiple tooltip windows, just as the docs said.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 2:37pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/5 "2018-08-03T14:37:11Z")

</div>

Looks like your advice works after all. I don’t understand why it crashed the first time I tried it. Now it’s no longer crashing, and is behaving properly. Never mind!

---

<div class="post-metadata">

**Author:** ![bgporter](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/bgporter/32/12710_2.png) [@bgporter](https://forum.juce.com/u/bgporter)\
**Post date:** [August 3, 2018, 2:39pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/6 "2018-08-03T14:39:54Z")

</div>

Jeez, didn’t look at the `TooltipWindow` docs. Yeah, not sure, because `SharedResourcePointer` says clearly _“The SharedObjectType template type indicates the class to use for the shared object - the only requirements on this class are that it must have a public default constructor and destructor.”_

I’ve only been working on host apps of late, so I just create a `ScopedPointer<TooltipWindow>` in my main window, which isn’t helpful to you.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 2:49pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/7 "2018-08-03T14:49:11Z")

</div>

Well, I have it working, but now have a requirement that the user be able to turn tooltips on and off! Any idea how I can do that? There is nothing in the Look&Feel or the TooltipWindow that suggests the ability to enable or disable the tooltip. Given that I need to use a SharedResourcePointer in my audio plug-in, how can I turn the tooltips on and off (for this instance of the plug-in)? Is it even possible?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [August 3, 2018, 3:02pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/8 "2018-08-03T15:02:50Z")

</div>

The easiest way is probably just to stop the timer of the TooltipWindow:

```auto
if (enableTooltips)
{
    if (Desktop::getInstance().getMainMouseSource().canHover())
        tipWindow.startTimer (123);
}
else
{
    tipWindow.stopTimer();
    tipWindow.hideTip();
}

```

but maybe not the nicest way to do it…

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 3:04pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/9 "2018-08-03T15:04:35Z")

</div>

I tried using a container object for the SharedResourcePointer, and creating and destroying that (using std::unique\_ptr), but that doesn’t work as expected with multiple plug-in instances. I have to destroy my container object in all instances of the plug-in before the tooltip turns off. I just don’t see any way to accomplish turning on and off tooltips.

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 3:24pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/10 "2018-08-03T15:24:43Z")

</div>

Timer is a private base class of TooltipWindow, so I can’t access startTimer() and stopTimer() from an instance of the TooltipWindow, unfortunately.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [August 3, 2018, 3:27pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/11 "2018-08-03T15:27:00Z")

</div>

Oh, I thought I checked it inherits public, but you are right, it’s private inheritance (like it should).  
I must have been too tired, sorry…

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 3, 2018, 4:20pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/12 "2018-08-03T16:20:30Z")

</div>

Hmm, I suppose I could set the delay to INT\_MAX milliseconds, which works out to over 596 hours! 🙂

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 6, 2018, 8:39pm UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/13 "2018-08-06T20:39:28Z")

</div>

Thought that was working, but on Windows when I disabled the tooltips this way, they appeared immediately! This line of code is why:

&& now \> lastCompChangeTime + (uint32) millisecondsBeforeTipAppears

On my pc, "lastCompChangeTime " is returning (currently) as 4fxxxxxx, which when adding INT\_MAX to it, wraps to less than “now” every time.

I need a reliable way to disable the tooltips. Anyone?

---

<div class="post-metadata">

**Author:** ![HowardAntares](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/howardantares/32/4629_2.png) [@HowardAntares](https://forum.juce.com/u/HowardAntares)\
**Post date:** [August 7, 2018, 1:40am UTC](https://forum.juce.com/t/sharedresourcepointer-and-tooltipwindow-example/28879/14 "2018-08-07T01:40:59Z")

</div>

Ah, now that I have put my TooltipWindow into a container object, and create that container objects using the SharedResourcePointer (instead of creating the TooltipWindow using a SharedResourcePointer directly), I can simply create and delete the TooltipWindow to turn it on or off! That turns it on or off for all current instances of my plug-in, but that’s probably what a user would want, anyway!
