Re: Subclassing NSToolbar is *almost* really good
Re: Subclassing NSToolbar is *almost* really good
- Subject: Re: Subclassing NSToolbar is *almost* really good
- From: Chris Giordano <email@hidden>
- Date: Mon, 3 May 2004 16:52:11 -0400
John,
On May 3, 2004, at 1:29 PM, John Lombardo wrote:
It would be fully good if it didn't explode whenever I try to run the
customization palette either programatically or by right-clicking on
the toolbar and selecting Customize Toolbar. By "explode" I mean
spewing out half a dozen of the following:
2004-05-04 00:29:40.844 BBToolbarTest[2174] ***
-[NSAttributeDictionary selectedItemIdentifier]: selector not
recognized
No customization palette is produced. Then, when I click some
no-longer-functional toolbar items and then quit the app I get the
following message:
*** malloc[2174]: Deallocation of a pointer not malloced: 0xbfffe420;
This could be a double free(), or free() called with the middle of an
allocated block; Try setting environment variable MallocHelp to see
tools to help debug
I've been going crazy trying to figure out where the first message is
coming from. I've created a little demo Xcode project demonstrating the
subclass in all its glory hoping that someone may care to check it out
and spot a something that I missed.
http://betterbomb.com/BBToolbarTest.zip
Cheers!
john
I think the key problem here is that your
toolbar:itemForIdentifier:willBeInsertedIntoToolbar: method is not
returning a copy of the toolbar item. I'm not exactly sure why you're
ending up with a dictionary in its place unless it's a memory
management issue that is very predictable and always results in a
dictionary being created in its place (since I get the same error
message that you do).
I modified your project with the code below and it came close. There
are a few quirks with the display of a few of the view-based items
(i.e., your segmented control and the search field) in the customize
sheet when I drag things to the toolbar, but I get the customize sheet
and it doesn't crash. My application didn't have any view-based
toolbar items when I first implemented my toolbar code so I haven't
found a solution to the display issue yet (I assume it has something to
do with copying the view out, but Apple's sample code at
<
http://developer.apple.com/documentation/Cocoa/Conceptual/Toolbars/
index.html#//apple_ref/doc/uid/10000109i> doesn't copy the view either,
so I can only assume something else is at play here.)
chris
============ In BBToolbar.m =============
// NSToolbar Delegates
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
NSToolbarItem *newItem = [[[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier] autorelease];
NSToolbarItem *item = [toolbarItemDictionary
objectForKey:itemIdentifier];
[newItem setLabel:[item label]];
[newItem setPaletteLabel:[item paletteLabel]];
if ([item view] != nil)
{
[newItem setView:[item view]];
}
else
{
[newItem setImage:[item image]];
}
[newItem setToolTip:[item toolTip]];
[newItem setTarget:[item target]];
[newItem setAction:[item action]];
[newItem setMenuFormRepresentation:[item menuFormRepresentation]];
// If we have a custom view, we *have* to set the min/max size -
otherwise, it'll default to 0,0 and the custom
// view won't show up at all! This doesn't affect toolbar items
with images, however.
if ([newItem view] != nil)
{
[newItem setMinSize:[[item view] bounds].size];
[newItem setMaxSize:[[item view] bounds].size];
}
return newItem;
}
_______________________________________________
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.