Re: NSCell subclassing to contain other NSCells
Re: NSCell subclassing to contain other NSCells
- Subject: Re: NSCell subclassing to contain other NSCells
- From: email@hidden
- Date: Fri, 2 Dec 2005 11:52:48 -0800
email@hidden wrote:
I'm looking for an attack strategy on subclassing an NSCell.
Here's a simplified scenario of what I want to do. This scenario is
only for the sake of discussion.
I have a list of books I allow people to borrow all the time. I
want to list my books as NSCells within an NSMatrix. Within each
cell I want to have a large thumbnail of the book cover, the title
and author of the book and 2 controls under the title and author
information. These controls are...
1. Button to allow me to set whether book is being borrowed or not
2. Text field to allow me to type the name of the person that has
the book.
What I think I should do is create a subclass of NSCell (say
BookCell) and use member variables for other NSCells (NSImageCell,
NSTextCell, NSButtonCell, NSTextFieldCell) within it and control
them all independently. But, I can't figure out how to have my
NSCell treat these other cells similar to an NSView containing
subviews. I was hoping for something similar to NSView's addSubview
method to allow me to have subcells, but no such thing exists that
I could find.
Any assistance would be appreciated.
You'll need to have some type of layout calculation and a list of cells.
You subclass NSCell then add the instance variables (an Array for the
subcells).
You then decide the layout of these items and also layout relative to
each-other (it gets tricky and potentially messy here).
Then in your master cell, you calculate layout and draw and call the
other cells to draw as well.
Remember, NSCell does not retain its NSSize, its only notified at
runtime, though this could be
added by a subclass or layout engine (something I'm investigating...)
If you wanna pipe events to each cell, then in the NSEvent response
methods (like beginTracking:InView:)
you see if that mouse down hits any subcells, and then forward the
NSEvent to that particular cell by calling its same method...
Its a bit of work, and I would suggest making a lightweight reusable
behavior, it may take more time in the
beginning, but over time you'll save it (I should know, its not fun
doing this over and over)
Good luck.
_______________________________________________
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