Re: Restrain size of NSWindow to NSToolbar only
Re: Restrain size of NSWindow to NSToolbar only
- Subject: Re: Restrain size of NSWindow to NSToolbar only
- From: Rolf <email@hidden>
- Date: Tue, 01 Jul 2003 01:48:24 +0200
Hi
Thanks for your help :-)
/Rolf
30.06.2003 22:23:42, skrev Matt Gemmell <email@hidden>:
>
On 30/6/03 at 8:48 pm, Rolf said:
>
>
> My app has an NSWindow that contains only a NSToolbar. The NSWindow
>
> is supposed to have a fixed height that is equal to the NSToolbar +
>
> Window Title bar height, and a variable width from X upto the width
>
> of the toolbar. How do I do that ? I guess the correct way of
>
> limiting NSWindow size is to use the setMinSize: and setMaxSize:
>
> methods, but I haven't been able to find a way of determining the
>
> NSToolbar size and the Window Titale bar height.
>
>
To find the window titlebar height, assuming your window is "win":
>
>
[win frame].size.height - [[win contentView] frame].size.height
>
>
>
To find the height of the toolbar attached to a given window, use this
>
function from Apple:
>
>
/* --- begin code --- */
>
float ToolbarHeightForWindow(NSWindow *window)
>
{
>
NSToolbar *toolbar;
>
float toolbarHeight = 0.0;
>
NSRect windowFrame;
>
>
toolbar = [window toolbar];
>
>
if (toolbar && [toolbar isVisible])
>
{
>
windowFrame = [NSWindow contentRectForFrameRect:[window frame]
>
styleMask:[window
>
styleMask]];
>
toolbarHeight = NSHeight(windowFrame)
>
- NSHeight([[window contentView] frame]);
>
}
>
>
return toolbarHeight;
>
}
>
/* --- end code --- */
>
>
>
No idea how you'd find the width of a toolbar. It varies depending on
>
number of items, display mode, size mode (which depends on the version
>
of OS X), and the labels of items (if displayed).
>
>
You could probably write a (nightmarish) routine to calculate the size,
>
but you'd be hard-coding all kinds of values, including the font used to
>
draw the toolbar labels, spacing between items, edge spacing, and so on.
>
I'd just allow your window to resize horizontally as far as it likes
>
(set the maximum width to FLT_MAX).
>
>
If you're desperate, I suppose you could keep the window off-screen, and
>
repeatedly increase its size until the toolbar's -visibleItems match its
>
-items. Then use [NSWindow -setMaxSize:] to not allow it to get any
>
wider. That's quite an ugly way to do it, though. Maybe I've missed
>
something (it's happened before).
>
>
Cheers,
>
-Matt
>
>
--
>
Matt Gemmell
>
Scotland Software
>
http://www.scotlandsoftware.com/
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.