On 26 Nov 2009, at 18:22, Sandro Noël wrote:

> I'm trying to educate myself on how to create my custom controls/Views.
> Everywhere i look no one uses the same methods to override drawing and 
> behaviour.
> and most of the example do not start from the same place, 

:-)  There are, as you have noticed, several approaches that work, depending on 
what you're doing and what you hope to achieve.

> Some start from NSControl with a combination of NSCell and NSActionCell

Yep.

> Others Start from NSView, and some start from Apple's controls and override 
> the drawing.

Yep.

> What i am trying to achieve is 
> 1: to be able to change the look of the controls that already exist if i need 
> to.

In which case you'll have to look how the control in question is implemented.  
If it's an NSControl subclass, you probably need to subclass the corresponding 
NSCell subclass in order to customise it.

> 2: if I have the need for a control that does not exist, i want to be able to 
> create it myself.
>       including having to respond to user input and mouse clicks and send 
> those back to the caller ( thru delegates or actions )

If it "smells like" an NSControl (e.g. a button or something), then using a 
custom cell is probably the best way to go.  Especially if there's already a 
matching subclass of NSControl (e.g. NSButton), in which case you can subclass 
NSButton and NSButtonCell and get most of the existing button functionality for 
free.

If it doesn't look like that, for instance it's some new control that the 
system doesn't have, or it's the main document view of your app or something, 
then NSView is probably a better bet.

NSControl and NSCell have the advantage that they do various things for you, 
*and* you can create an NSMatrix of your new cell class, or stick it into an 
NSTableView.

If you're using a custom NSView, it's harder to put it into a table view, and 
you have to handle everything directly yourself, but, on the other hand, you 
only have to write one class and it's perhaps slightly more apparent how to 
handle e.g. mouse events than it is with NSCell (I know that's something I 
struggled with at first).

I'll also add a warning.  While you can create custom controls, it's important 
to consider carefully whether they're necessary.  Making controls that look or 
work in a manner that doesn't match those in the HIG is probably a mistake, 
unless you have a good justification for it (and "looks/works like Windows", 
although a common justification, is wrong).

If you want more specific advice, you'll have to be more specific about what 
you want to achieve.

Kind regards,

Alastair.

--
http://alastairs-place.net

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to