• 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
[SOLVED] Re: NSBrowser/NSMatrix as drag-and-drop source
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SOLVED] Re: NSBrowser/NSMatrix as drag-and-drop source


  • Subject: [SOLVED] Re: NSBrowser/NSMatrix as drag-and-drop source
  • From: Kevin Dorne <email@hidden>
  • Date: Fri, 27 May 2005 04:28:44 -0700

On Thu, May 26, 2005 at 02:47:32PM -0700, I wrote:
> Hi all,
>
> I'm trying to use an NSBrowser as a drag and drop source, but I'm running into some difficulties.
>
> Following an example posted December 2003, I've added mouseDown and mouseDragged methods to MyMatrix.  The issue is that if I have the mouseDown method as below, I can't select multiple cells, but dragging works.  If I just have the mouseDragged method, I can select multiple cells, but dragging doesn't work.

I've managed something that works.  It seems needlessly complicated, but the behaviour is what I'd expect from a typical browser.

Code is included below for future reference.

(mouseDragged: remains the same)

#define NO_SELECTION -1
#define NO_MODIFIERS(x) (! (x & NSCommandKeyMask || x & NSShiftKeyMask))

- (void)mouseDown:(NSEvent *)event
{
  int row, col;
  int startPos;
  int flags;
  BOOL rowIsSelected;

  if ([self getRow: &row column: &col
          forPoint:[self convertPoint:[event locationInWindow]
                             fromView: nil]]) {
    startPos = row;

    if ([self selectedRow] < 0)
      anchor = NO_SELECTION;

    flags = [event modifierFlags];

    if (NO_SELECTION == anchor ||
        flags & NSCommandKeyMask)
      anchor = row;

    if (flags & NSShiftKeyMask)
      startPos = anchor;

    rowIsSelected = ([[self selectedCells] containsObject:[self cellAtRow:row column:0]]);

    if (rowIsSelected)
    {
      // Do nothing if no modifiers
      if (NO_MODIFIERS(flags))
        return;
      // Otherwise, deselect the current cell
      [self setSelectionFrom:row to:row anchor:row highlight:NO];
      [self deselectSelectedCell];
    }
    // If no modifiers are pressed and the cell isn't selected,
    // deselect all of the cells
    else
    {
      if (NO_MODIFIERS(flags))
      {
        [self deselectAllCells];
        anchor = row;
      }
      // Finally, add the row to the selection
      [self setSelectionFrom:startPos to:row anchor:anchor highlight:YES];
    }
    // And update the browser
    [self sendAction];
    anchor = row;
  }
}
 _______________________________________________
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

References: 
 >NSBrowser/NSMatrix as drag-and-drop source (From: Kevin Dorne <email@hidden>)

  • Prev by Date: Re: NSNumber is completely broken
  • Next by Date: Re: Cocoa bindings one- or bi-directional
  • Previous by thread: Re: NSBrowser/NSMatrix as drag-and-drop source
  • Next by thread: NSTextView insertText & undo
  • Index(es):
    • Date
    • Thread