setUsingNativeTitleBar

I just tried adding this to my app. Looks like it only works correctly if the window has been added to the desktop, unless I’m just missing something.

On Windows, if you call setUsingNativeTitleBar(true) on a DocumentWindow that hasn’t been added to the desktop yet, you get a window with both a native title bar and a JUCE title bar underneath that.

I guess I can live with it, but it seems like it should work either way.

Matt

oh bugger. I only tested it with the demo app. Will investigate, but for now I think just make it visible first.

No worries - I’m just letting you know.

Matt

Just looking into this, and I can’t get it to go wrong… what’s the order you were doing things in?

Here’s what happens normally. For my window’s constructor, I do this:

ConsoleWindow::ConsoleWindow(ehw *dev) : DocumentWindow(T("Console"), Colours::white, minimiseButton | closeButton, false)

and inside the constructor :

[code]CwContent *comp;

setOpaque(true);
setSize(w,h);

comp = new CwContent(_layout,dev,_session);
comp->setSize(w,h);
setContentComponent(comp,false,true);
[/code]
Once I’ve built the window, my application does this:

[code]window->addToDesktop( ComponentPeer::windowAppearsOnTaskbar |
ComponentPeer::windowHasTitleBar |
ComponentPeer::windowHasCloseButton |
ComponentPeer::windowHasMinimiseButton |
ComponentPeer::windowHasDropShadow);

window->setTopLeftPosition(xoffset,yoffset);
window->setVisible(true);
window->toFront(true);
[/code]

One thing that changed with 1.29 was that I have to call setSize twice - once for the window and then again for the content component. The content component has a fixed size, so I was expecting that I could just set the size of the content component and then set the resizeToFit parameter to true. It looks like the DocumentWindow isn’t resized properly on the call to setContentComponent unless the window has a non-zero size first; it ends up not being tall enough.

For the native stuff, I get different results depending on when I do things.

If I call setUsingNativeTitleBar(true) just before the addToDesktop call, I get the double title bar - the native one on top and the JUCE one right below it. My content component is right under the JUCE title bar.

If I call setUsingNativeTitleBar(true) right after the addToDesktop call, I get a window that’s too tall - my content component is right up under the native title bar and there’s a blue bar at the bottom of the window about the size of the JUCE title bar.

Matt

Ah - it’s because you’re explicitly adding it to the desktop with your own window flags, without telling the window that you’ve done so.

The TopLevelWindow prefers to manage its own addToDesktop() call, so that it knows when it’s being used with a titlebar and can make sure the flags match its own idea of what buttons are visible, resize itself, etc. Why not get rid of your call to addToDesktop, and just pass ‘true’ to the DocumentWindow constructor?

In fact, I should probably sort out the problem so it works in all cases, by making the TopLevelWindow class intercept your addToDesktop call and do the proper thing, but you’re doing more work than is strictly necessary here.

Alrighty then.

Perhaps you could add a note to that effect in the documentation.

Thanks for taking the time to look at it!

Matt

yep, I’ll add some notes about it.

Great; thanks!