 |
 |
Putting NSView subclass into NSMatrix or similar(cocoa)
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
OK, basically, I've got a subclass of NSView that I'd like to have a number of copies of arranged in a structure like an NSMatrix. Unfortunately, NSMatrix can only contain NSCells, not views.
Anyway, my question is if there's a better way to do this than writing my own class similar to NSMatrix that does what I want. for example, maybe I could:
1. put the drawing code into an NSCell instead of an NSView?(subclasses)
2. subclass NSMatrix to allow NSViews
3. make it an NSControl subclass (instead of NSView) and find some way to make a cell to go along with the control.
Thanks!
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status:
Offline
|
|
If what you're making is like a simple control, it'd probably be best to follow the NSCell + NSControl approach, especially if you will later want the same sort of flexibility you have with AppKit controls. It can be a little confusing at first compared to the simplicity of just subclassing NSView and -drawRect:, but you'll appreciate the power once yopu get used to it. And to that end, Apple has some good sample code: look for "ClockControl" on the developer site. It not only shows how to make a cell+control pair work well, but also other good things for writing custom controls, like accessibility support, drawing keyboard focus rings, etc.
I've written "view matrix" type classes a couple of times (the Downloads panel in OmniWeb has one). It's kinda cumbersome, but not too complicated -- really all you have to do is subclass the subview-management methods (adding and removing, maybe resizing) so that they adjust the subviews' frames to fit the layout you want. But it's still a lot of work, so it's probably best to avoid it unless your situation doesn't allow other options... say, if you're dealing with other people's controls that don't have cell equivalents (like NSProgressIndicator). There's some Apple sample code that might help you a bit with the view-frame arithmetic: I don't recall the name, but its primary purpose is showing how to make a Finder-style Info window with disclosure triangles for expanding/collapsing sections.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
basically, my (currently view) class needs to:
1. draw an image, and some text that gives a bit of info
2. Be dragged to a different source
3. if easy enough, it'd be nice if it could be highlighted when clicked on, but it really doesn't matter much to me.
then, I want to take a number of those (at the moment it's four, but they're user-addable, so there could be lots) and stack them, and put them in an NSScrollView so that they can be found easily.
Which solution would you recommend?
I was looking over the documentation for NSCell today, and it looked atractive as far as having an image and text laid out for me. unless there's a good reason to do things the other way, I'm thinking that's the way to go.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|