Re: How do I make a flexible NSToolbarItem?
Re: How do I make a flexible NSToolbarItem?
- Subject: Re: How do I make a flexible NSToolbarItem?
- From: PGM <email@hidden>
- Date: Thu, 7 Sep 2006 21:35:03 -0400
To show the problem, I made a new project with a custom controller,
with only two outlets: the main window and a custom view of 52x32
pixels, that contains a NSSearchField; both the view and the
searchfield are set to be horizontally stretchable. The only task of
the custom controller is to create a toolbar for the window with only
the searchFieldView and a NSToolbarFlexibleSpaceItemIdentifier. The
controller contains the following code:
Controller.h:
#import <Cocoa/Cocoa.h>
@interface Controller : NSObject
{
IBOutlet id theWindow;
IBOutlet NSView *searchBoxView;
}
//Required NSToolbar delegate methods
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:
(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag;
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar;
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar;
@end
Controller.m:
#import "Controller.h"
@implementation Controller
-(void)awakeFromNib
{
NSToolbar *toolbar=[[[NSToolbar alloc]
initWithIdentifier:@"myToolbar"] autorelease];
[toolbar setDelegate:self];
[toolbar setAllowsUserCustomization:YES];
[toolbar setAutosavesConfiguration: YES];
[toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
[theWindow setToolbar:toolbar];
}
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:
(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *newItem = [[[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier] autorelease];
[newItem setLabel:@"Find"];
[newItem setPaletteLabel:@"Find"];
[newItem setView:searchBoxView];
NSSize minSize = [searchBoxView bounds].size;
NSSize maxSize = [searchBoxView bounds].size;
maxSize.width = 2000; //this is the maxSize returned by
NSToolbarFlexibleSpaceItem
[newItem setMinSize:minSize];
if(flag){ //here I try to make it big if inserted into toolbar...
[newItem setMaxSize:maxSize];
}
else{ //...and small if inserted into customisation palette
[newItem setMaxSize:minSize];
}
return newItem;
}
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:@"Find",
NSToolbarFlexibleSpaceItemIdentifier, nil];
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar*)toolbar
{
return [NSArray arrayWithObjects:@"Find",
NSToolbarFlexibleSpaceItemIdentifier, nil];
}
@end
On 7-Sep-06, at 14:46 PM, I. Savant wrote:
Please post the relevant code so people can review and comment.
--
I.S.
On Sep 7, 2006, at 10:49 AM, PGM wrote:
Hi everybody
My app has a toolbar in which I would like to have a view with a
searchbox that stretches automatically, like the one SearchBoxes
in most Apple apps. The documentation says about sizing
NSToolbarItem:
"If a view item’s view does something intelligent when it is
stretched, then you will set its maxSize greater than its minSize
in height, width, or both. Horizontally-stretchable view items,
including the Flexible Space standard item, compete equally for
available horizontal space."
The question now rises: how do I make my view do "something
intelligent"?
In Interface Builder, I have set my view to be flexible. And I
have implemented NSToolbar's toolbarWillAddItem: to set the
maxSize.width of my view to 2000 and the minSize.width to 51.
However, my searchbox and an adjacent NSToolbarFlexibleSpaceItem
do NOT compete equally for space; my searchbox is huge and the
flexibleSpace is tiny. Furthermore, when I customise my toolbar,
the customisation sheet shows the searchBox is the same huge size
as it is in the toolbar and not in the small size that you see for
the searchbox when you customise a toolbar in an Apple app. Has
anybody succeeded in getting this to work as it should?
Serachboxes are becoming increasingly popular, so I would guess
that people have struggled with this before.
Thanks in advance, Patrick
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden