NSView / Drag and Drop: Any API or constants to detect the start of a drag?

  • I must be missing something obvious but I don't find in the Cocoa
    documentation or headers something that exists in the Carbon/Mac OS
    Classic API IIRC.

    Detecting the start of a drag operation requires to detect the
    following chain of events:

    1) mouse left button down

    2) mouse moved more than a specific limit

    In Carbon/Mac ToolBox, there was an API you could use to know that a
    mouse movement was the start of a drag.

    In Cocoa, I don't see such an API. I searched the ADC and Dveloper
    tools sample code (CocoaDragAndDrop is not a good sample code),
    searched the mailing list archive through cocoabuilder.com, quickly
    searched cocoadev.com, had a look at the NSTableView source code in
    GNUStep with no success.

    Would there an API or constant I'm missing?
  • See -mouseDragged: in NSResponder.

    Cheers,
    Chuck

    --- Stéphane Sudre <ssudre2...> wrote:

    > I must be missing something obvious but I don't find
    > in the Cocoa
    > documentation or headers something that exists in
    > the Carbon/Mac OS
    > Classic API IIRC.
    >
    > Detecting the start of a drag operation requires to
    > detect the
    > following chain of events:
    >
    > 1) mouse left button down
    >
    > 2) mouse moved more than a specific limit
    >
    > In Carbon/Mac ToolBox, there was an API you could
    > use to know that a
    > mouse movement was the start of a drag.
    >
    > In Cocoa, I don't see such an API. I searched the
    > ADC and Dveloper
    > tools sample code (CocoaDragAndDrop is not a good
    > sample code),
    > searched the mailing list archive through
    > cocoabuilder.com, quickly
    > searched cocoadev.com, had a look at the NSTableView
    > source code in
    > GNUStep with no success.
    >
    > Would there an API or constant I'm missing?
    >

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • Unfortunately, I had a look at this method during my search.

    There's no "magnetism" with this call : you get the message as soon as
    the mouse moved from 1 pixel.

    This is not the way it works in text fields, table view, etc.

    On samedi, novembre 10, 2007, at 01:51  AM, Charles Steinman wrote:

    > See -mouseDragged: in NSResponder.
    >
    > Cheers,
    > Chuck
    >
    > --- Stéphane Sudre <ssudre2...> wrote:
    >
    >> I must be missing something obvious but I don't find
    >> in the Cocoa
    >> documentation or headers something that exists in
    >> the Carbon/Mac OS
    >> Classic API IIRC.
    >>
    >> [...]
  • On Nov 10, 2007, at 2:48 AM, Stéphane Sudre wrote:

    > Unfortunately, I had a look at this method during my search.
    >
    > There's no "magnetism" with this call : you get the message as soon
    > as the mouse moved from 1 pixel.

    Stephane,

    What we typically do in a Cocoa app for the behavior you describe is
    to save the location of the mouseDown event, and compare it to the
    location of a mouseDragged event.  If the distance is greater than
    whatever threshold you want, then you go ahead and send a -
    dragFile:... or -dragImage:... type of message.

    In some cases, drag and drop is chosen by a modifier key, and in those
    situations, you probably want to go ahead and initiate the dragging
    session without caring how far the cursor has moved.

    -jcr
  • Correct  me if I'm wrong, but I don't believe text fields start a
    drag depending on the distance moved by the mouse. Instead, as I far
    as I'm aware it's time based. i.e. to drag you have to click and hold
    for a fraction of time before moving the mouse.

    This would have been fairly easy to achieve using an iVar in -
    mouseDown and -mouseDragged.

    Mike.

    On 10 Nov 2007, at 10:48, Stéphane Sudre wrote:

    > Unfortunately, I had a look at this method during my search.
    >
    > There's no "magnetism" with this call : you get the message as soon
    > as the mouse moved from 1 pixel.
    >
    > This is not the way it works in text fields, table view, etc.
    >
    > On samedi, novembre 10, 2007, at 01:51  AM, Charles Steinman wrote:
    >
    >> See -mouseDragged: in NSResponder.
    >>
    >> Cheers,
    >> Chuck
    >>
    >> --- Stéphane Sudre <ssudre2...> wrote:
    >>
    >>> I must be missing something obvious but I don't find
    >>> in the Cocoa
    >>> documentation or headers something that exists in
    >>> the Carbon/Mac OS
    >>> Classic API IIRC.
    >>>
    >>> [...]

  • On samedi, novembre 10, 2007, at 02:02  PM, John C. Randolph wrote:

    > On Nov 10, 2007, at 2:48 AM, Stéphane Sudre wrote:
    >
    >> Unfortunately, I had a look at this method during my search.
    >>
    >> There's no "magnetism" with this call : you get the message as soon
    >> as the mouse moved from 1 pixel.
    >
    > Stephane,
    >
    > What we typically do in a Cocoa app for the behavior you describe is
    > to save the location of the mouseDown event, and compare it to the
    > location of a mouseDragged event.  If the distance is greater than
    > whatever threshold you want, then you go ahead and send a
    > -dragFile:... or -dragImage:... type of message.
    >
    > In some cases, drag and drop is chosen by a modifier key, and in those
    > situations, you probably want to go ahead and initiate the dragging
    > session without caring how far the cursor has moved.

    That's somehow what I fear from a user experience point of view.

    Since there does not seem to be a method or constant to define the
    threshold, we end up with having different thresholds; not only within
    Cocoa apps but also between Cocoa and Carbon apps.

    I guess the idea is to file an enhancement request so that we can
    eventually get a constant in 2010.
  • On Nov 10, 2007, at 5:07 AM, Mike Abdullah wrote:

    > Correct  me if I'm wrong, but I don't believe text fields start a
    > drag depending on the distance moved by the mouse. Instead, as I far
    > as I'm aware it's time based. i.e. to drag you have to click and
    > hold for a fraction of time before moving the mouse.

    That's correct.  Also, in Mail, if you drag horizontally you start a
    drag session, and if you drag vertically you select more than one
    message.

    > This would have been fairly easy to achieve using an iVar in -
    > mouseDown and -mouseDragged.

    Yep.

    -jcr
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today