Toolbar question


I’m trying to create a unified header for my window (much like XCode’s), in which the toolbar has the same colour as the title bar.

Is there a way to eliminate the black line drawn between the title bar and the toolbar by DocumentWindow::paint()?

  if (resizableBorder == 0 && getBorderSize() == 1)
        g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
        g.drawRect (0, 0, getWidth(), getHeight());

I’d like my window to be resizable, and I don’t seem to have control over the border size of the window. I’m using juce 1.46, and a native title bar…


But that line draws a line around the outside edge of the whole window, not between the title bar and the content?

(Though I do agree that it should be in the look and feel, rather than the paint method…)


Yes, that’s the line that draws itself around the whole juce window.

I agree that it would be great if that drawing could be customized. From what I can tell, the solid black line around the window isn’t part of Apple’s current aesthetic, and it would be nice if we could try to mimic that if we so choose.


OK, two more questions as I dig deeper.

It seems that the MacOS treats the header differently if there’s a toolbar at the top. There’s a fixed gradient that’s drawn on just the title bar if there’s no toolbar, or over the titlebar plus the toolbar if there is one. Is there a way to mimic this in juce? That is, can we get a title bar that has the unified header shading somehow?

The title bar (and thus the unified header) change color if the window is foremost or not. I thought I could force a repaint of the toolbar by forcing a repaint() on a handleFocusGain() or handleFocusLoss(), but I don’t seem to trip those componentPeer routines when I select or deselect my window. What’s the correct way to change appearance when the window is selected?


I think you’re going to have a hard time trying to draw stuff to match apple’s title bar - if you need a really specific look, then it’d be better just to draw the title bar yourself in juce, I reckon.


That’s good advice about the title bar colours. I’ll heed it.

What of the notification on window activation? I’ve overridden handleBroughtToFront(), handleFocusGain() and handleFocusLoss() in my DialogWindow() derived window, but none of these seems to be called when my window is clicked on, or hidden behind another active window from another application. Where does the window get notified if it’s currently frontmost on the user’s screen?


TopLevelWindow::activeWindowStatusChanged ()

I’m not sure what the best way is to notify child components that the window is no longer active. You’ll need to do this to ensure that your toolbar dims alongside your main window.

In my case, so much of my app needs to show a loss of focus that I simply call repaint in my implementation of activeWindowStatusChanged (). Sub components just find the top level window component and check for active in their painter methods.

If you only need to dim your toolbar, there’s almost certainly a cleaner way to pass the notification on.


Thanks for the activeWindowStatusChanged() tip!

My next problem is that I’d like to have buttons that aren’t as tall as the toolbar in my toolbar, like the buttons in Safari, or the “view” buttons in iTunes.

The hight of these buttons is set in ToolbarItemComponent::resized(), and uses the variable contentArea to hold the height of the buttons. I can’t override the resized() routine in my ToolbarItemComponent subclass because contentArea is private.

Is there another way to add buttons that are not full height to the toolbar?