• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImageView and mouse events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImageView and mouse events


  • Subject: Re: NSImageView and mouse events
  • From: Duncan Campbell <email@hidden>
  • Date: Tue, 25 Jan 2005 15:00:20 +1100

Thx for the response Daniel.

When I replace the NSImageView with an NSButton, I can no longer do the [self addSubview:] piece - how do i add my button to my NSView?

Cheers,

=========================================
Duncan Campbell
http://www.duncanandsarah.com/duncan
=========================================

It's raisins that make Post Raisin Bran so raisiny ...

On 25/01/2005, at 2:07 PM, daniel wrote:

Duncan,

The NSImageView is not a button. Therefore it doesn't make sense for it to send its action on mouse click. I believe it sends its action method when editable and the user drops a new image on it. Since its "data" is an image, it makes sense to send its action when the data changes. Similarly, a control like the NSTextView doesn't send its action when the user clicks it, but when the user finishes typing text into it.

If you want to respond to a mouse click, I suggest using the NSButton class, instead. There is probably a reasonable variant of this class that will display your image the way you wish, and also forward action on click.

Daniel

On Jan 24, 2005, at 5:27 PM, Duncan Campbell wrote:

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
=========================================

_______________________________________________
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

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

  • Follow-Ups:
    • Re: NSImageView and mouse events
      • From: Jeremy Dronfield <email@hidden>
References: 
 >NSImageView and mouse events (From: Duncan Campbell <email@hidden>)
 >Re: NSImageView and mouse events (From: daniel <email@hidden>)

  • Prev by Date: Re: Document bundles and rude users
  • Next by Date: Filtering breaks bindings-enabled app
  • Previous by thread: Re: NSImageView and mouse events
  • Next by thread: Re: NSImageView and mouse events
  • Index(es):
    • Date
    • Thread