CocoaDev

Edit AllPages

I needed a matrix of image views that would let the user change the order of the image in it using drag and drop. Thus I wrote the following class. When the user drags an image a little insertion bar is draw to give them an indication of where the insertion will occur.

– SaileshAgrawal


DragMatrix.h

/**********************

#import <AppKit/AppKit.h>

@interface DragMatrix : NSMatrix { NSEvent * downEvent; NSRect oldDrawRect, newDrawRect; BOOL shouldDraw;

int srcRow, srcCol, dstRow, dstCol; }

// Private


DragMatrix.m

#import “DragMatrix.h”

float INS_WIDTH = 2; float CIRCLE_SIZE = 6; NSString *pasteBoardTypeCover = @”Cover”;

/**********************

@implementation DragMatrix

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

/**********************

@end


Thank you for this class. You have made my week. tips hat


Amen to that! This is almost exactly what I was looking for, and certainly more than I had hoped for in an example. Thanks! – Seth. 2005-03-28


2005-02-18 Changed dstCol = column++; to dstCol = column + 1; in the above. Someone forgot how post-increment works :)