• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problem with custom control in NSToolbar
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with custom control in NSToolbar


  • Subject: Re: Problem with custom control in NSToolbar
  • From: Chris Giordano <email@hidden>
  • Date: Tue, 8 Jun 2004 10:55:04 -0400

Laurent,

On Jun 8, 2004, at 10:20 AM, Laurent Daudelin wrote:

On 08/06/04 10:09, "Chris Giordano" <email@hidden> wrote:

Laurent,

I haven't seen a response from one of the more knowledgeable members of
the list yet, so...

On Jun 7, 2004, at 4:54 PM, Laurent Daudelin wrote:


[snip]

How are you returning the toolbar item in
toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:? There was
some discussion a month or so back (see the thread "Subclassing
NSToolbar is *almost* really good") in which the same kind of issue was
happening. The fix there was to be sure to return a copy (i.e.,
[toolbarItem copy]) of the toolbar item in this method. Even creating
a new toolbar item and setting the view to be identical to the source
doesn't entirely work -- it has similar odd results (in the test code
I'm looking at, it usually disappears from the toolbar when the
customization palette is displayed). My guess is that creating a copy
of the view would work, but I'm not really in a position to test that
out right now.


Hi Chris!

I thought about that. Initially, I was always returning the same instance,
but now, I'm creating a new one every time I'm asked for it, using a
dictionary to hold the attributes. I did put a few NSLog() here and there
and I know that 3 different instances are created when I run the
customization palette, and the drawCellInFrame: is also called for each on
these instances. The only thing I haven't duplicated in my encodeWithCoder:
and initWithCoder: (which is used by the toolbar apparently), are the images
used to draw the icons, but I thought that a single image was shared anyway
no matter how often it would be requested.

I'll check it out this thread, although it didn't show up in the various
searches I did in the archive before posting.

Thanks for the reply!


Laurent,

Are you creating copies of your view in the toolbar items, or just setting the view to that of the original item?

For view-based toolbar items, one thing that I can say from (my very meager) experience (again, in the test cases for the discussion from a month ago) is that manually making a copy and returning it doesn't yield the same results as returning [toolbarItem copy]. The latter works, whereas the former will only display the view in one place. Archiving and unarchiving the view to get a copy of it gives the correct results, so my guess is that [toolbarItem copy] makes a copy of the view by archiving/unarchiving it which is why that works. (In the example I'm working with, I have verified that the view of a -copy'd toolbar item's view and the original view are different, and the view doesn't respond to copyWithZone:, so it can't be copying via that route.)

So, am I correct that you're currently manually creating a copy of the toolbar item and then setting the view on the copy to that of the original? What happens if you do something like the following instead?

// item is the original NSToolbarItem, newItem is the new NSToolbarItem to be returned
NSView * v = [item view];
NSData * d = [NSArchiver archivedDataWithRootObject:v];
v = [NSUnarchiver unarchiveObjectWithData:d];
[newItem setView:v];


chris
_______________________________________________
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.


  • Follow-Ups:
    • Re: Problem with custom control in NSToolbar
      • From: Laurent Daudelin <email@hidden>
References: 
 >Re: Problem with custom control in NSToolbar (From: Laurent Daudelin <email@hidden>)

  • Prev by Date: Re: Problem with custom control in NSToolbar
  • Next by Date: Re: Modification date is changing and I don't know why
  • Previous by thread: Re: Problem with custom control in NSToolbar
  • Next by thread: Re: Problem with custom control in NSToolbar
  • Index(es):
    • Date
    • Thread