Re: Tracking mouse activity in NSToolbar?
Re: Tracking mouse activity in NSToolbar?
- Subject: Re: Tracking mouse activity in NSToolbar?
- From: Jay Koutavas <email@hidden>
- Date: Wed, 7 May 2003 12:44:43 -0400
Thanks j o a r. Your reply sent me hopefully into the right direction/
I created a "myToolbarItemView", based on the example code I found at
http://www.omnigroup.com/mailman/archive/macosx-dev/2001-April/012666.html
and added a "viewDidMoveToWindow:" to set up a tracking rect and
mouseEntered: and mouseExit: to track the mouse rollovers.
Some problems/questions that arise when I tried this code out (see
attached code snippits):
1. when my application comes up, the mouseEntered: and mouseExit:
selectors I provided aren't getting hit (the bounds look good at
addTrackingRect time.)
2. I'm not getting my icon to show. I imagine there's something I
have to add to my drawRect:, eh?
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.)
Thanks,
/Jay
In my setup code, I have this:
NSToolbarItem *item = [[NSToolbarItem alloc]
initWithItemIdentifier:itemIdentifier];
myToolbarItemView *view = [[myToolbarItemView alloc] initWithFrame:
NSMakeRect(0,0,100,32)];
[item setView:view];
[item setLabel:@"Foobar"];
[item setPaletteLabel:[item label]];
[item setImage:[NSImage imageNamed:@"foobar"]];
'myToolbarItemView' is defined as:
@interface myToolbarItemView : NSView {
@private
// we don't have any instance variables yet
}
@end
..and is implemented as:
@implementation myToolbarItemView
- (id)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder: coder];
if (self) {
// we don't have any instance variables yet
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder: coder];
if (self) {
// we don't have any instance variables yet
}
}
- (void)viewDidMoveToWindow {
[self addTrackingRect:[self bounds]
owner:self user
Data:nil assumeInside:NO];
[super viewDidMoveToWindow];
}
- (void)mouseEntered:(NSEvent *)event {
NSLog(@"toolbar item mouse entered\n");
}
- (void)mouseExited:(NSEvent *)event {
NSLog(@"toolbar item mouse exited\n");
}
At 10:01 PM +0200 on 5/6/03, j o a r wrote:
You should be able to achieve this is if you create your own view
type toolbar items that have tracking rects set in the view you
provide when you create them?
j o a r
On Tuesday, May 6, 2003, at 21:37 Europe/Stockholm, Jay Koutavas wrote:
I'd like to get mouse enter/exit notification for items in
NSToolbar. Seeing that NSToolbar and NSToolbarItem are not children
of NSView, I can't simply subclass them to add in a call to
addTrackingRect. And, because of the dynamic nature of how the
toolbar is added to the window at runtime, I can't define a
containing view to do the tracking either. There seems to be no
obvious notification/delegation for mouse movement in NSToolbar or
NSToolbarItem.
How would one go about doing tracking for a toolbar?
--
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Jay Koutavas
mailto:email@hidden
Heynow Software
http://www.heynow.com
Windham, New Hampshire, USA
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
_______________________________________________
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.