NSImageView and mouse events
NSImageView and mouse events
- Subject: NSImageView and mouse events
- From: Duncan Campbell <email@hidden>
- Date: Tue, 25 Jan 2005 12:27:45 +1100
Forgive the newbie question - I am about 3 days into Cocoa here :-)
I'm trying to write some code to implement tabs like in safari. I have an NSView that i am placing a "close" graphic on lhs of - that when clicked, should do something (eventually close the tab).
I've figured out how to place the graphic on the NSView, however I am having difficulty registering the "click".
My code is so:
<x-tad-smaller> </x-tad-smaller><x-tad-smaller>//Draw Close Tab icon</x-tad-smaller><x-tad-smaller>
NSImage *closeGraphicImage = [NSImage imageNamed:</x-tad-smaller><x-tad-smaller>@"browserClose4.tiff"</x-tad-smaller><x-tad-smaller>];
NSRect closeGraphicRect = NSMakeRect(</x-tad-smaller><x-tad-smaller>3.0</x-tad-smaller><x-tad-smaller>,[closeGraphicImage size].width,[closeGraphicImage size].height);
NSImageView *closeGraphic = [[NSImageView alloc] initWithFrame:closeGraphicRect];
[closeGraphic setImage:closeGraphicImage];
[closeGraphic setTarget:</x-tad-smaller><x-tad-smaller>self</x-tad-smaller><x-tad-smaller>];
[closeGraphic setAction:</x-tad-smaller><x-tad-smaller>@selector</x-tad-smaller><x-tad-smaller>(closeIconAction:)]; </x-tad-smaller><--- this is the bit of code that isn't working.<x-tad-smaller>
</x-tad-smaller><x-tad-smaller>//add image to View</x-tad-smaller><x-tad-smaller>
[</x-tad-smaller><x-tad-smaller>self</x-tad-smaller><x-tad-smaller> addSubview:closeGraphic];
</x-tad-smaller>
with the "click"
<x-tad-smaller> - (</x-tad-smaller><x-tad-smaller>void</x-tad-smaller><x-tad-smaller>)closeIconAction:(NSEvent *)theEvent
{
NSLog(</x-tad-smaller><x-tad-smaller>@"close button clicked"</x-tad-smaller><x-tad-smaller>);
}
</x-tad-smaller>I'm not sure if i am doing this correctly at all - but i can't seem to find any sample code anywhere on how to do this. Can anyone help?
In case you are wondering why the NSRect - it's 'cause i am going to want to add a tracking rect to make close graphic change on mouse-over.
Cheers in advance for any help,
<x-tad-smaller>
</x-tad-smaller>=========================================
Duncan Campbell
http://www.duncanandsarah.com/duncan
=========================================
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden