• 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
The mouse is where?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The mouse is where?


  • Subject: The mouse is where?
  • From: email@hidden
  • Date: Fri, 25 Jan 2008 14:51:09 -0800

Sorry for a longish post, but I'm bundling 3 related questions together.

Here's my scenario:

I'm working on an application that involves what you might think of as "rollover highlighting" in a custom NSView subclass. The application has nothing to do with web browsing, but (like a web browser) when the mouse moves over certain objects, it wants to change the color of those objects and change the cursor.

Here's my problem:

*Correctly* knowing where the mouse is at any time is ... sometimes unknowable.

I thought I could use an approach based on NSTrackingArea, and the various mouseXxx: messages.

This turned out to be a little trickier than I had anticipated, but I seem to have most of the bases covered now, and am left with 3 specific problems/defects:

(A) Testing seems to indicate that *if the mouse button is pressed* and I drag out of the view, I get a mouseExited: message when the mouse actually goes outside the view (between two mouseDragged: events), but if in the same drag I come back into the view, I do not get a mouseEntered: event until the mouse button is released.

Clearly, this means that I can't rely on mouseEntered:/mouseExited: to know whether the mouse is inside the view. If I have to write code to determine the inside/outside status manually for some cases, then why would I not just use that code all the time and forget about tracking areas that are convenient only some of the time?

I can easily do that, but I wonder: Surely it's wrong that one of the two messages works synchronously, and the other asynchronously, when dragging?

(B) When I turn on mouseEntered:/mouseExited: tracking for my view's NSTrackingArea, the mouse might obviously be inside the view or outside the view. Surely there should be a more-or-less immediate message (either mouseEntered: or mouseExited:) to tell me where the frameworks thinks the mouse is?

If there's not, then I must calculate the current inside/outside state of the mouse location as part of installing the tracking area, so that I don't start off with a wrong assumption. That would be fine, except that (as in part A) I wonder why I'm bothering with tracking areas at all, AND that I'm not quite sure what test to use to match the tracking area's test (NSView mouse:inRect:? NSPointInRect?), AND -- the $64 question -- where the mouse actually is. Which bring us to:

(C) How do I know where the mouse is, in the absence of (prior to receiving) a mouse-related event?

-- There is not, afaik, any Cocoa frameworks function or method that gets the mouse location other than from a NSEvent. (It may exist and I just haven't found it.)

-- Getting the current mouse location using Carbon (if there is a function for that) isn't the answer, because that's going to tell me where the mouse is *right now in real time*, while the information I need is where the mouse is *synchronized with the event stream*. (If I'm about to receive a flood of mouseMoved: or mouseDragged: messages, I want to know where the mouse is before them, not after. Unreceived messages represent the future, I'm still in the present.)

Anyone have any thoughts on this?
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: The mouse is where?
      • From: Jayson Adams <email@hidden>
  • Prev by Date: Getting the content-type in a HTTP response
  • Next by Date: Re: Regular expressions in Cocoa?
  • Previous by thread: Re: Getting the content-type in a HTTP response
  • Next by thread: Re: The mouse is where?
  • Index(es):
    • Date
    • Thread