Re: Resizing NSToolbarItems?
Re: Resizing NSToolbarItems?
- Subject: Re: Resizing NSToolbarItems?
- From: j o a r <email@hidden>
- Date: Sat, 13 Apr 2002 12:42:02 +0200
On Saturday, April 13, 2002, at 03:15 , Michael Thole wrote:
Is it necessary to sublass NSToolBarItem in order to implement
intelligent resizing of the view?
No.
All I want to do is this:
I have a toolbar with several items, the most important of which is an
NSComboBox. I want the combo box to take up the extra space in the
toolbar
as the window the toolbar is in resizes. I've tried using
NSToolbarItem's
setMinSize/setMaxSize and the NSView resizes like I want inside of IB.
Ideas?
What I would do is this:
* Create a nib in IB with only a custom view containing the combo box
and set up all connections you need. Don't set any struts / springs with
hints to how it should be resized (IIRC).
* Then, in the code, something like this ("programmed" in Mail, syntax
needs to be checked):
- (void) awakeFromNib
{
// Your other stuff
if (![NSBundle loadNibNamed:@"MyComboBoxNib"]) {
NSLog(@"Failed to load nib");
} else {
// If it's not retained, ugly things can happen if the user
remove it from the toolbar
[myComboBox retain];
[myComboBox removeFromSuperviewWithoutNeedingDisplay];
}
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *newItem = nil;
if ([itemIdentifier isEqualToString:@"ComboBoxItem"]) {
NSRect comboFrame = [myComboBox frame];
newItem = [[NSToolbarItem alloc] initWithItemIdentifier:
itemIdentifier];
[newItem setView: myComboBox];
[newItem setMinSize: comboFrame.size];
[newItem setMaxSize:NSMakeSize(1000.0,comboFrame.size.height)];
[newItem autorelease];
}
return newItem;
}
- (void) dealloc
{
[myComboBox release];
[super dealloc];
}
If this doesn't work, let me know.
Regards,
j o a r
_______________________________________________
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.