• 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: Drag and Drop Oddities
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drag and Drop Oddities


  • Subject: Re: Drag and Drop Oddities
  • From: Jason Harris <email@hidden>
  • Date: Wed, 12 Jun 2002 12:26:47 -0700

Sorry, I wasn't clear. Attached is a (slightly lobotomized) example showing
periodic events used to begin a drag after the user has clicked and held the
mouse without moving it. If dragging begins because of an NSPeriodic event,
locationInWindow is undefined.


- (void)mouseDown:(NSEvent *)theEvent {
NSEvent *newEvent;

[NSEvent startPeriodicEventsAfterDelay: 0.5 withPeriod: 0];
newEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask |
NSLeftMouseDraggedMask | NSPeriodicMask];
switch ([newEvent type]) {
case NSLeftMouseUp:
break;
case NSLeftMouseDragged:
case NSPeriodic:
[self __doDrag: theEvent];
break;
default:
break;
}
[NSEvent stopPeriodicEvents];
}


Jason


John Anderson Tried to Tell Me:

> So if I'm using the following code to detect a click or a drag, I'm
> only using periodic events, right?:
>
> - (void)mouseDown:(NSEvent *)theEvent
> {
> NSPoint localPoint = [self convertPoint:[theEvent locationInWindow]
> fromView:nil];
>
> [[[self window] windowController] deselectAll];
>
> if ([self mouse:localPoint inRect:[self clickableRect]]) {
> isSelected = YES;
> [self display];
> }
> else
> isSelected = NO;
> }
>
> - (void)mouseDragged:(NSEvent *)theEvent
> {
> NSSize dragOffset;
> NSPoint imageLoc;
> NSPasteboard *pboard;
> NSImage *dragImage = [[NSImage alloc] initWithData:[self
> dataWithPDFInsideRect:[self clickableRect]]];
> NSPoint localPoint = [self convertPoint:[theEvent locationInWindow]
> fromView:nil];
> NSData *ownerData;
>
> [[[self window] windowController] deselectAll];
>
> if ([self mouse:localPoint inRect:[self clickableRect]]) {
> imageLoc = [self clickableRect].origin;
> imageLoc.y += 8;
> dragOffset = NSMakeSize(localPoint.x, localPoint.y);
>
> pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
> [pboard declareTypes:[NSArray
> arrayWithObject:@"PresenceContainer"] owner:self];
> ownerData = [NSArchiver archivedDataWithRootObject:self];
> [pboard setData:ownerData forType:@"PresenceContainer"];
> [self dragImage:dragImage at:imageLoc offset:dragOffset
> event:theEvent pasteboard:pboard source:self slideBack:YES];
> }
> }
>
> What's causing the slowness here? Should I create the NSImage and
> NSData when I get the mouseDown event instead, and hold onto it until I
> get a drag? Perhaps that would speed things up... any other
> suggestions? I don't really want to send dragImage: when I get
> onMouseDown because I support selection of these objects as well, and
> the slightest mouse movement causes a snap-back effect, which is
> disturbing... so i want a delay, just not one this big.
>
> John Anderson
> everchanging
>
> On Wednesday, June 12, 2002, at 12:26 AM, Jason Harris wrote:
>
>> I've seen this before. It occurs when overriding mouseDown to receive
>> an
>> event and then starting periodic events to determine whether to begin
>> a drag
>> even if the user hasn't moved the mouse. You send locationInWindow to
>> the
>> periodic event and this is what you see, because locationInWindow is
>> only
>> defined for mouse events.
>>
>> Jason
>>
>>
>> Hsu Tried to Tell Me:
>>
>>> I've not seen this in XShelf (which is based directly on code from
>>> Apple
>>> source archives and Hillegass' book)... drag/drop seems to work fine
>>> (and it's thus far all Cocoa, no Carbon)
>>>
>>> Karl
>>>
>>> On Tuesday, June 11, 2002, at 11:39 AM, John Anderson wrote:
>>>
>>>> I've seen the exact same problem. Hate to post a "me too" here but I
>>>> thought you'd like to know that someone feels your pain :-)
>>>>
>>>> John
>>>>
>>>>
>>>> On Monday, June 10, 2002, at 09:02 PM, Lucas Haley wrote:
>>>>
>>>>> Heya all --
>>>>>
>>>>> I've just delved into drag and drop, and things are going well.
>>>>> However, whenever I begin my drag, the app stalls a little, and the
>>>>> image quickly jumps once from the top left of the monitor to the
>>>>> mouse
>>>>> position. Has anyone else encountered this? I am using code almost
>>>>> exclusively lifted from Hillegass and the Apple source code
>>>>> archives.
>>>>>
>>>>> Also: is it not possible in IB to make a matrix out of a custom
>>>>> view?
>>>>>
>>>>> Thanks for any help!
>>>>>
>>>>> -Lucas
>>>>> _______________________________________________
>>>>> cocoa-dev mailing list | email@hidden
>>>>> Help/Unsubscribe/Archives:
>>>>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>>>>> Do not post admin requests to the list. They will be ignored.
>>>> _______________________________________________
>>>> cocoa-dev mailing list | email@hidden
>>>> Help/Unsubscribe/Archives:
>>>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>>>> Do not post admin requests to the list. They will be ignored.
>>>>
>>>>
>>> --
>>>
>>> Attention pregnant women: Anybody who talks to their own stomach is
>>> crazy.
>>>
>>> Homepage:
>>> http://homepage.mac.com/khsu/index.html
>>> _______________________________________________
>>> cocoa-dev mailing list | email@hidden
>>> Help/Unsubscribe/Archives:
>>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>>> Do not post admin requests to the list. They will be ignored.
>> _______________________________________________
>> cocoa-dev mailing list | email@hidden
>> Help/Unsubscribe/Archives:
>> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>> Do not post admin requests to the list. They will be ignored.
> _______________________________________________
> cocoa-dev mailing list | email@hidden
> Help/Unsubscribe/Archives:
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
> Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Drag and Drop Oddities (From: John Anderson <email@hidden>)

  • Prev by Date: Re: -[NSResponder flagsChanged:] not called?
  • Next by Date: How do I rotate text ?
  • Previous by thread: Re: Drag and Drop Oddities
  • Next by thread: Re: NSSlider's mouseDown implementation
  • Index(es):
    • Date
    • Thread