Re: Tracking mouse activity in NSToolbar?
Re: Tracking mouse activity in NSToolbar?
- Subject: Re: Tracking mouse activity in NSToolbar?
- From: j o a r <email@hidden>
- Date: Wed, 7 May 2003 22:30:55 +0200
On Wednesday, May 7, 2003, at 18:44 Europe/Stockholm, Jay Koutavas
wrote:
1. when my application comes up, the mouseEntered: and mouseExit:
selectors I provided aren't getting hit (the bounds look good at
addTrackingRect time.)
Have you used tracking rects previously? If not you should probably
read this:
<file:///Developer/Documentation/Cocoa/TasksAndConcepts/
ProgrammingTopics/BasicEventHandling/Tasks/HandlingMouseTracking.html#/
/apple_ref/doc/uid/20000907>
I would particularly like to highlight:
"Tracking rectangles, though created and used by NSViews, are actually
maintained by NSWindows. Because of this, a tracking rectangle is a
static entity; it doesn't move or change its size when the NSView does.
If you use tracking rectangles, you should be sure to remove and
reestablish them any time you change the frame rectangle of the NSView
that contains them. If you're using a custom subclass of NSView, you
can override the frame- and bounds-setting methods to do this. You can
also register an observer for the NSViewFrameDidChangeNotification, and
have it reestablish the tracking rectangles on receiving the
notification."
It's probably a good idea for you to try using tracking rects in a
non-toolbar item view - to get the hang of things before introducing
them in the toolbar.
That said, there is one thing that could prevent this from working at
all. As the snippet above states, events in tracking rects are
maintained by the window, and it's quite possible that the window
restricts these events to the bounds of it's content view - and the
toolbar isn't part of the content view. If tracking rects doesn't work
for you, this might be the reason.
A similar case: command key events are not delivered to controls in
toolbar items for example.
2. I'm not getting my icon to show. I imagine there's something I have
to add to my drawRect:, eh?
Read the docs for NSToolbarItem - a toolbar item is either a
image-type-toolbar-item or a view-type-toolbar-item. When you assign a
view it turns into the latter, and the image you provided will be
ignored. Ergo, if you want the image to be displayed, you either need
to draw it yourself in the drawRect: method of your view subclass - or
better: inherit from NSImageView and let it do this for you.
3. Is it safe to assume the rectangle is 0,0,100,32? (I swiped the
NSMakeRect(0,0,100,32) call directly from the code example.)
Perhaps. I think that the toolbar item will be as large as the view you
provide, but also that it would respect the autoresize mask you provide
- ie. to be able to provide a view that has a flexible width.
j o a r
_______________________________________________
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.