CocoaDev

Edit AllPages

Cocoa provides only almost static tooltips. When you want to implement something like Keynote tooltips in a canvas while editing, in mouseDown events, you are out of luck. To remedy that, I created a small class to do it. It tries to imitate as much as possible the Keynote look and feels. – General/EricForget

See also General/LittleYellowBox.


I don’t have Keynote. How are Keynote tooltips different from the standard ones?


Normal tooltips are for views, but mostly for controls. When the user move the cursor over it, wait a few seconds the tooltip appears for 10 seconds and then disappear. Keynote tooltips looks the same but are there for displaying the position of the moving object, the dimension of the resizing object or the angle for the rotation. Those tooltips appear only during mouseDown:/mouseDragged events. – General/EricForget

—-General/ToolTipTextField Interface

@interface General/ToolTipTextField : General/NSTextField @end

—-General/ToolTipTextField Implementation

@implementation General/ToolTipTextField

@end

—-General/ToolTip Interface

@interface General/ToolTip : General/NSObject { General/NSWindow *window; General/NSTextField *textField; General/NSDictionary *textAttributes; }

@end

—-General/ToolTip Implementation

static General/ToolTip *sharedToolTip = nil;

@interface General/ToolTip (Private)

@end

—-General/ToolTip Usage Sample

– General/EricForget



How ‘bout something like this?…

#import <General/AppKit/General/AppKit.h>

@interface General/TooltipWindow : General/NSWindow { General/NSTimer *closeTimer; id tooltipObject; }

// returns the approximate window size needed to display the tooltip string.

// setting and getting the default duration..

// setting and getting the default bgColor

@end

#import “General/TooltipWindow.h”

float defaultDuration; BOOL doneInitialSetup; General/NSDictionary *textAttributes; General/NSColor *backgroundColor;

@implementation General/TooltipWindow

return tipSize;

}

@end

I stuck a demo project that uses that there General/TooltipWindow class here: http://homepage.mac.com/ryanstevens/.Public/General/TooltipWindowDemo.zip

Maybe someone will find it useful. :)


What are the differences between your implementation and the one from Cocoa, outside that you have to do everything by hand? What is the intent of your implementation, which doesn’t seems to serves the same needs as the one I provided? –General/EricForget


I think my implementation serves the same needs, just in a different way.

I really just wanted more control over the window itself, that and attributed tooltips.


I tried out Ryan’s version and it works beautifully. Thanks! –Daniel


It’s been ages since I’ve looked back at this…wow. I guess the demo link was broken (or was never right in the first place) - that should be fixed now.

Just glad I could contribute back. –General/RyanStevens


Thanks for showing me how to create handy little windows; I’ve wondered how to do this for quite some time, and I’m sure the knowledge will be dangerous in my hands :)

I used Eric’s implementation because it was less reading for me to understand. I like the way that Eric uses class methods to communicate with his singleton, instead of the way Apple does it with stuff like their -sharedDocumentController. Alot of brain-power and screen real estate is wasted when Apple makes us do:

General/[[NSGobbleDeeGookManager sharedGobbleDeeGookManager] canYouPleaseDoSomething] ;

You can also attach these tool tips to dragged rows of General/NSTableView or General/NSOutlineView. To do that, referring to Eric’s “Tool Tip Usage Sample” above, move his code

*from Eric’s mouseDown: to your draggingEntered: *from Eric’s mouseDragged: to your draggingUpdated: *from Eric’s mouseUp: to your draggingExited:, draggingEnded: and acceptDrop:::

The last one goes to three places because there are several ways that a dragging session can end.

– Jerry Krinock 2007 Oct 08