Friday, December 18, 2009

TimeLine view - making the header active

In the TimeLine view the header is not a passive information-only structure it is active.
  • The text is editable.
  • The "Lock" icon works as a checkbox.
  • The "Draw Mode" icon is a popup menu with four states.
This is what one of the popup menus looks in the windows version if Cello.


The way that I plan to accomplish these active areas are by using subclasses of NSCell and friends. There is, for example, a NSPopupButtonCell that handles a popup menu button.

NSCell and it's derivatives are classes that encompass everything that is needed to draw a particular object, say a popup menu, and handle it's behavior. It is everything except the view in which it is drawn. As with all things in Cocoa they are there for the taking - you can use them as is or subclass them as you please. The way you use them is really easy - if you want them to draw then you:
  • Set it up
  • Ask it to draw in a given rectangle in a given view
If you want to handle a mouse down then you:
  • Set it up
  • Ask it to handle the mouse down
All the Cocoa controls (for example NSButton) use a NSCell subclass to do the drawing etc. If you want to see how they work - check out the Cocoatron project. You can download the source and see just how simple the cocoatron NSButton is.

I have started by crudely hacking in the NSPopupButtonCell
into the TimeLine view and getting it to draw and to handle the mousedown - the menu is just a dummy. My plan is to refine this (stepwise refinement) until I get what I want.

No comments: