# RAII of default look and feel

**URL:** <https://forum.juce.com/t/raii-of-default-look-and-feel/9267>\
**Category:** General JUCE discussion\
**Created:** [September 19, 2012, 7:59pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267 "2012-09-19T19:59:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 7:59pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/1 "2012-09-19T19:59:30Z")

</div>

Hi Jules,  
Is there a reason, for us users, to be forced to delete our own default LookAndFeel which is set using the LookAndFeel::setDefaultLookAndFeel(…) ?  
If we don’t provide any L&F, Juce creates a default one, called “LookAndFeel” and this is autodeleted with the help of a ScopedPointer.

Granted that it’s easy to use a ScopedPointer in the App class, but I’m having difficulties seeing how to do this in a plug-in, if you understand what I mean.

Grateful for your insight.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 19, 2012, 8:07pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/2 "2012-09-19T20:07:38Z")

</div>

There’s no reason to use a ScopedPointer, I just generally embed the lookandfeel object in the app class - have a look at how the introjucer does it. Clean, simple, no deletions or pointers required.

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 8:25pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/3 "2012-09-19T20:25:29Z")

</div>

> [@jules](#):
>
> I just generally embed the lookandfeel object in the app class…

Yes, very clean.

But…

How would one use a defalt LnF in a plug-in, having no such thing as an App class.  
You can’t place it in the AudioProcessor class.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 19, 2012, 8:42pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/4 "2012-09-19T20:42:47Z")

</div>

Put it in the editor class?

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 8:46pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/5 "2012-09-19T20:46:34Z")

</div>

> [@jules](#):
>
> Put it in the editor class?

No!! Because if you instantiate 2 plug-ins from the same binary and open their 2 editors, “1” and “2” you will first refer to the LnF of instance 1, then 2. Then if you close editor 2, editor 1 will go nuts!

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 19, 2012, 8:56pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/6 "2012-09-19T20:56:20Z")

</div>

Yeah, obviously if you set it as the global l+f it won’t work, but if you just make it the lookandfeel for that editor component, it’ll be fine.

If you really need to share a l+f (or any kind of data) between instances, then you’d want to have a shared, reference-counted class to hold it.

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 8:57pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/7 "2012-09-19T20:57:43Z")

</div>

Perhaps you thought I meant that you put one LookAndFeel to the editor window itself, not as a system default. I believe all children would inherit this? In that case you’d be safe, but there are other things that may pop up that are outside the control of the editor, such as AlertWindows.

Granted that a plug-in should never ever do anything modal, but could it not happen?

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 8:58pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/8 "2012-09-19T20:58:14Z")

</div>

I wrote my post after you posted yours. Doh…

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 9:00pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/9 "2012-09-19T21:00:55Z")

</div>

> [@](#):
>
> then you’d want to have a shared, reference-counted class to hold it.

Which brings me back to the original question. The juce class LookAndFeel is managed through a ScopedPointer.  
I wish I wish I could squeeze my own LnF in there. No?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [September 19, 2012, 9:06pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/10 "2012-09-19T21:06:26Z")

</div>

If it deleted the object you give it, then it’d be impossible to use non-heap-based objects (like in the introjucer).

---

<div class="post-metadata">

**Author:** ![Mike](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/mike/32/629_2.png) [@Mike](https://forum.juce.com/u/Mike)\
**Post date:** [September 19, 2012, 9:14pm UTC](https://forum.juce.com/t/raii-of-default-look-and-feel/9267/11 "2012-09-19T21:14:06Z")

</div>

> [@jules](#):
>
> If it deleted the object you give it, then it’d be impossible to use non-heap-based objects (like in the introjucer).

Of course, but in many places you use the term “Owned” and “NonOwned” such as in ViewPorts etc…

Currently, I do have a reference counted mechanism that takes care of everything. I don’t like it though; I rather put the LnF directly on the editor class because that makes the most sense. I’ll look into all the places I use AlertWindows. The ones I have are only for critical error messages, and will probably not be in there in the end user version.
