Categories, Protocols, Delegates and ToolTips
Categories, Protocols, Delegates and ToolTips
- Subject: Categories, Protocols, Delegates and ToolTips
- From: Paul Cezanne <email@hidden>
- Date: Wed, 19 Jun 2002 09:06:46 -0400
Tooltips?
That is where is all started. I need a form of roll over help. Tooltips aren't good enough (user testing has spoken, the objection was primarily how they faded away after a set time). I want to place the mouse over a control and have help text appear in a help text area.
Sounds simple enough, right? I'm new to Cocoa so the first thing I did was subclass NSButton and do the addTrackingRect, setAcceptsMouseMovedEvents and mouseEntered stuff. It all worked fine. Of course my UI has more than NSButtons in it, so I decided to subclass all that I needed and use multiple inheritance to mix-in the behavior that I need. Obviously I found out quickly that that doesnt' work.
So after a ton of reading I think I know I want either a Category or a Protocol but I have some problems and I know I'm close to the right answer but I don't know the Cocoa Way yet.
First problem I see with Categories is that from my reading they are meant to add methods to an existing class. The methods I need, resetCursorRects, mouseEntered and mouseExited, are already existing methods. So I don't need to make a category for them but I do need to make an implementation for them, but where do I put them? Right now they are in a subclass of NSButton which works great for buttons but not at all for other controls. If I make a subclass of NSControl than I can't assign the connections in Interface Builder, a button needs a datatype that is a descendant of NSButton, not NSControl.
Protocols seem to have the same problem in this application. First, I don't need them because the methods are already there (and probably part of some protocol anyway) and secondly, I don't know how to hook them up without subclass every type of control that I use, which I want to avoid.
Delegates seem like they could help a lot, but NSViews don't have delegates, there is nothing in IB to control drag to.
http://cocoa.mamasam.com/COCOADEV/2002/01/1/21131.php was very helpful but none of the alternatives seem to work for me.
And of course the final problem is that even if I could get Categories to work, a category can only have methods, I can't add an new IBOutlet so the control knows where to draw its new help text. With my subclasses NSButton this was really easy.
(Note, the alternative is of course to subclass the existing tool tips drawing code, but I can't seem to find anyway to do that . I can set and remove the text and rects, and there is even a NSToolTipOwner category, but these don't seem to help me and besides, solving the generic case seems more interesting.)
I appreciate any help, thanks.
_______________________________________________
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.