• 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: mouseDown/Up on window's titlebar?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: mouseDown/Up on window's titlebar?


  • Subject: Re: mouseDown/Up on window's titlebar?
  • From: Ken Tabb <email@hidden>
  • Date: Tue, 1 Feb 2005 10:54:23 +0000

Hi Murat, thanks for the reply,

On 31 Jan 2005, at 7:02 pm, m wrote:

On Jan 31, 2005, at 12:03 PM, Ken Tabb wrote:

I need to detect mouseDown / mouseUp / mouseDragged events on a window's titlebar - I'm implementing sticky windows (snappable palettes). These events are sent correctly when the mouse is in the content view, but not in the window's titlebar... mouseDragged is sent but not mouseDown / mouseUp.

I could set my window subclass as it's own delegate so that it receives the -windowWillMove and -windowDidMove notifications, which roughly speaking mimic mouseDown / mouseUp in terms of indicating the mouse state, however there are some circumstances when they don't work reliably enough for my needs.

Why is it not adequate to simply know when the window moved? Why do you need to know when the mouse is pressed and released?

I need mouseDown / mouseUp info to get around another 'feature' in Cocoa, which is that when a Cocoa window is being dragged, you can't rely on it's -frame being correct... it reports the frame at the start of the drag, not during the drag. So the common way to do window drag overriding (eg. for snappable palettes) is the following:


[1] on mouseDown, record the cursor's position relative to the window's frame's origin. This tells you the offset of the window origin vs. the cursor location

[2] on mouseDragged, set the window's origin according to the cursor's current position, and adjust by the deltaX / deltaY as per [1], so that the window is offset correctly from the cursor position

... you can use mouseDown and mouseUp to optimise the algorithm, so that for instance the mouseDown records the relative cursor / window origin position at the start of each drag. Also on mouseDown you might want to record the positions of the other windows (if you're implementing window to window snapping, as opposed to just window to screen snapping), rather than calculate those positions per each stage of the drag (bearing in mind the windows you're not dragging shouldn't have moved during your drag, so it's needless computation each time).

If you just need to know whether the mouse is up or down when you recieve your windowDidMove notification, you can use NSApplication's currentEvent method to grab the event being processed and check the events modifier flags for mouse state.

Cracking idea, thanks!

Ken

- - - - - - - - - -
Dr. Ken Tabb
Mac & UNIX Developer - Health & Human Sciences
Machine Vision & Neural Network researcher - School of Computer Science
University of Hertfordshire, UK
http://www.health.herts.ac.uk/ken/

Certified non-Microsoft Solution Provider

_______________________________________________
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


  • Prev by Date: Re: mouseDown/Up on window's titlebar?
  • Next by Date: Re: Finding Subnet
  • Previous by thread: Re: mouseDown/Up on window's titlebar?
  • Next by thread: Re: mouseDown/Up on window's titlebar?
  • Index(es):
    • Date
    • Thread