* GormViewEditor.m

* GormInternalViewEditor.m
* GormViewWithContentViewEditor.m
  Multiple selection through mouse dragging is back.
  When attempting to start a connection, make sure the current
  widget is selected.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@15296 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Pierre-Yves Rivaille 2002-12-14 14:31:43 +00:00
parent 10ba0cd4ce
commit 8da3ca9c07
4 changed files with 287 additions and 42 deletions

View file

@ -1,3 +1,13 @@
2002-12-14 Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
* GormViewEditor.m
* GormInternalViewEditor.m
* GormViewWithContentViewEditor.m
Multiple selection through mouse dragging is back.
When attempting to start a connection, make sure the current
widget is selected.
2002-12-06 Gregory John Casamento <greg_casamento@yahoo.com>
* GormDocument.m: Added code to scroll to the class name

View file

@ -31,6 +31,18 @@
@class GormEditorToParent;
@class GSWindowView;
static NSImage *verticalImage;
static NSImage *horizontalImage;
#ifndef max
#define max(a,b) ((a) >= (b) ? (a):(b))
#endif
#ifndef min
#define min(a,b) ((a) <= (b) ? (a):(b))
#endif
@implementation NSView (GormObjectAdditions)
- (NSString*) editorClassName
{
@ -57,6 +69,13 @@
@implementation GormInternalViewEditor
+ (void)initialize
{
horizontalImage = nil;
verticalImage = nil;
}
- (void) dealloc
{
RELEASE(selection);
@ -234,6 +253,34 @@
[self registerForDraggedTypes: [NSArray arrayWithObjects:
IBViewPboardType, GormLinkPboardType, IBFormatterPboardType, nil]];
if (horizontalImage == nil)
{
NSCachedImageRep *rep;
horizontalImage = [[NSImage allocWithZone:(NSZone *)[(NSObject *)self zone]]
initWithSize: NSMakeSize(3000, 2)];
rep = [[NSCachedImageRep allocWithZone:
(NSZone *)[(NSObject *)self zone]]
initWithSize:NSMakeSize(3000, 2)
depth:[NSWindow defaultDepthLimit]
separate:YES
alpha:YES];
[horizontalImage addRepresentation: rep];
RELEASE(rep);
verticalImage = [[NSImage allocWithZone:(NSZone *)[(NSObject *)self zone]]
initWithSize: NSMakeSize(2, 3000)];
rep = [[NSCachedImageRep allocWithZone:
(NSZone *)[(NSObject *)self zone]]
initWithSize:NSMakeSize(2, 3000)
depth:[NSWindow defaultDepthLimit]
separate:YES
alpha:YES];
[verticalImage addRepresentation: rep];
RELEASE(rep);
}
return self;
}
@ -449,28 +496,14 @@
if ([result isKindOfClass: [GormViewEditor class]])
{
/*
if (result != self)
{
[self selectObjects: [NSMutableArray arrayWithObject: result]];
}
else
{
[self selectObjects: [NSMutableArray array]];
}
[[self window] disableFlushWindow];
[self display];
[[self window] enableFlushWindow];
[[self window] flushWindow];
NSLog(@"clicked on %@", result);
*/
}
else
{
// NSLog(@"md %@ result = nil", self);
result = nil;
}
// this is the direct subeditor the mouse was clicked on
// (or self)
editorView = (GormViewEditor *)result;
}
@ -478,7 +511,7 @@
&& [editorView isKindOfClass: [GormViewWithSubviewsEditor class]]
&& ([(id)editorView canBeOpened] == YES)
&& (editorView != self))
// Let's open a subeditor
{
[(GormViewWithSubviewsEditor *) editorView setOpened: YES];
[self silentlyResetSelection];
@ -496,13 +529,172 @@
else // editorView == self
{
// NSLog(@"editorView == self");
[self selectObjects: [NSMutableArray array]];
NSEvent *e;
unsigned eventMask;
NSDate *future = [NSDate distantFuture];
BOOL first = YES;
NSRect oldRect = NSZeroRect;
NSPoint p, oldp;
NSRect r;
float x, y, w, h;
oldp = [self convertPoint: [theEvent locationInWindow] fromView: nil];
eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
if (!([theEvent modifierFlags] & NSShiftKeyMask))
[self selectObjects: [NSMutableArray array]];
[[self window] disableFlushWindow];
[self setNeedsDisplay: YES];
[self displayIfNeeded];
[[self window] enableFlushWindow];
[[self window] flushWindowIfNeeded];
e = [NSApp nextEventMatchingMask: eventMask
untilDate: future
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
[self lockFocus];
while ([e type] != NSLeftMouseUp)
{
p = [self convertPoint: [e locationInWindow] fromView: nil];
x = (p.x >= oldp.x) ? oldp.x : p.x;
y = (p.y >= oldp.y) ? oldp.y : p.y;
w = max(p.x, oldp.x) - min(p.x, oldp.x);
w = (w == 0) ? 1 : w;
h = max(p.y, oldp.y) - min(p.y, oldp.y);
h = (h == 0) ? 1 : h;
r = NSMakeRect(x, y, w, h);
if (NSEqualRects(oldRect, NSZeroRect) == NO)
{
[verticalImage
compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect))
fromRect: NSMakeRect(0.0, 0.0, 1.0, oldRect.size.height)
operation: NSCompositeCopy];
[verticalImage
compositeToPoint: NSMakePoint(NSMaxX(oldRect)-1, NSMinY(oldRect))
fromRect: NSMakeRect(1.0, 0.0, 1.0, oldRect.size.height)
operation: NSCompositeCopy];
[horizontalImage
compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMinY(oldRect))
fromRect: NSMakeRect(0.0, 0.0, oldRect.size.width, 1.0)
operation: NSCompositeCopy];
[horizontalImage
compositeToPoint: NSMakePoint(NSMinX(oldRect), NSMaxY(oldRect)-1)
fromRect: NSMakeRect(0.0, 1.0, oldRect.size.width, 1.0)
operation: NSCompositeCopy];
}
{
NSRect wr;
NSCachedImageRep *tableRep =
[[verticalImage representations]objectAtIndex:0];
wr = [self convertRect: r
toView: nil];
[verticalImage lockFocus];
NSCopyBits([[self window] gState],
NSMakeRect(NSMinX(wr), NSMinY(wr),
1.0, r.size.height),
NSMakePoint(0.0, 0.0));
NSCopyBits([[self window] gState],
NSMakeRect(NSMaxX(wr)-1, NSMinY(wr),
1.0, r.size.height),
NSMakePoint(1.0, 0.0));
[verticalImage unlockFocus];
[horizontalImage lockFocus];
NSCopyBits([[self window] gState],
NSMakeRect(NSMinX(wr), NSMinY(wr),
r.size.width, 1.0),
NSMakePoint(0.0, 0.0));
NSCopyBits([[self window] gState],
NSMakeRect(NSMinX(wr), NSMaxY(wr)-1,
r.size.width, 1.0),
NSMakePoint(0.0, 1.0));
[horizontalImage unlockFocus];
}
[[NSColor darkGrayColor] set];
NSFrameRect(r);
oldRect = r;
// [[self window] displayIfNeeded];
[[self window] enableFlushWindow];
[[self window] flushWindow];
[[self window] disableFlushWindow];
e = [NSApp nextEventMatchingMask: eventMask
untilDate: future
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
}
if (NSEqualRects(r, NSZeroRect) == NO)
{
[verticalImage
compositeToPoint: NSMakePoint(NSMinX(r), NSMinY(r))
fromRect: NSMakeRect(0.0, 0.0, 1.0, r.size.height)
operation: NSCompositeCopy];
[verticalImage
compositeToPoint: NSMakePoint(NSMaxX(r)-1, NSMinY(r))
fromRect: NSMakeRect(1.0, 0.0, 1.0, r.size.height)
operation: NSCompositeCopy];
[horizontalImage
compositeToPoint: NSMakePoint(NSMinX(r), NSMinY(r))
fromRect: NSMakeRect(0.0, 0.0, r.size.width, 1.0)
operation: NSCompositeCopy];
[horizontalImage
compositeToPoint: NSMakePoint(NSMinX(r), NSMaxY(r)-1)
fromRect: NSMakeRect(0.0, 1.0, r.size.width, 1.0)
operation: NSCompositeCopy];
}
{
NSMutableArray *array;
NSEnumerator *enumerator;
NSView *subview;
if ([theEvent modifierFlags] & NSShiftKeyMask)
array = [NSMutableArray arrayWithArray: selection];
else
array = [NSMutableArray arrayWithCapacity: 8];
enumerator = [[_editedObject subviews] objectEnumerator];
while ((subview = [enumerator nextObject]) != nil)
{
if ((NSIntersectsRect(r, [subview frame]) == YES)
&& [subview isKindOfClass: [GormViewEditor class]])
{
[array addObject: subview];
}
}
if ([array count] > 0)
{
[self selectObjects: array];
}
[self displayIfNeeded];
[self unlockFocus];
[[self window] enableFlushWindow];
[[self window] flushWindow];
}
}
}
/*
// are we on a selected view ?
{

View file

@ -1333,6 +1333,21 @@ static BOOL currently_displaying = NO;
if ([theEvent modifierFlags] & NSControlKeyMask)
// start a action/outlet connection
{
// first we need to select ourself
// to do so we need to find our first ancestor that can handle a selection
NSView *view = [self superview];
while ((view != nil)
&& ([view respondsToSelector: @selector(selectObjects:)] == NO))
{
view = [view superview];
}
if (view != nil)
[(id)view selectObjects: [NSArray arrayWithObject: self]];
// now we can start the connection process
[self startConnectingObject: _editedObject
withEvent: theEvent];
}

View file

@ -384,7 +384,9 @@
NSRect oldMovingFrame;
NSRect suggestedFrame;
GormPlacementInfo *gpi;
BOOL shouldUpdateSelection = YES;
BOOL mouseDidMove = NO;
// NSLog(@"hMOV %@", self);
eventMask = NSLeftMouseUpMask | NSLeftMouseDraggedMask
@ -415,10 +417,20 @@
newSelection = [selection arrayByAddingObject: view];
[self selectObjects: newSelection];
}
shouldUpdateSelection = NO;
}
else
{
[self selectObjects: [NSArray arrayWithObject: view]];
if ([selection containsObject: view])
{
if ([selection count] == 1)
shouldUpdateSelection = NO;
}
else
{
shouldUpdateSelection = NO;
[self selectObjects: [NSArray arrayWithObject: view]];
}
}
superview = [view superview];
@ -467,15 +479,14 @@
suggestedFrame = oldMovingFrame;
}
/* Set the arrows cursor in case it might be something else */
// Set the arrows cursor in case it might be something else
[[NSCursor arrowCursor] push];
/*
* Track mouse movements until left mouse up.
* While we keep track of all mouse movements, we only act on a
* movement when a periodic event arives (every 20th of a second)
* in order to avoid excessive amounts of drawing.
*/
// Track mouse movements until left mouse up.
// While we keep track of all mouse movements, we only act on a
// movement when a periodic event arives (every 20th of a second)
// in order to avoid excessive amounts of drawing.
[NSEvent startPeriodicEventsAfterDelay: 0.1 withPeriod: 0.05];
e = [NSApp nextEventMatchingMask: eventMask
untilDate: future
@ -483,15 +494,32 @@
dequeue: YES];
eType = [e type];
{
while ((eType != NSLeftMouseUp) && !mouseDidMove)
{
if (eType != NSPeriodic)
{
point = [superview convertPoint: [e locationInWindow]
fromView: nil];
if (NSEqualPoints(mouseDownPoint, point) == NO)
mouseDidMove = YES;
}
e = [NSApp nextEventMatchingMask: eventMask
untilDate: future
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
eType = [e type];
}
}
while (eType != NSLeftMouseUp)
{
if (eType != NSPeriodic)
{
point = [superview convertPoint: [e locationInWindow]
fromView: nil];
/*
point = _constrainPointToBounds(point, [superview bounds]);
*/
}
else if (NSEqualPoints(point, lastPoint) == NO)
{
@ -516,9 +544,7 @@
if (dragStarted == NO)
{
/*
* Remove selection knobs before moving selection.
*/
// Remove selection knobs before moving selection.
dragStarted = YES;
_displaySelection = NO;
[self setNeedsDisplay: YES];
@ -588,11 +614,17 @@
if ([selection count] == 1)
[[selection objectAtIndex: 0] setFrame: suggestedFrame];
if (mouseDidMove == NO && shouldUpdateSelection == YES)
{
[self selectObjects: [NSArray arrayWithObject: view]];
}
[self setNeedsDisplay: YES];
[NSEvent stopPeriodicEvents];
[NSCursor pop];
/* Typically after a view has been dragged in a window, NSWindow
sends a spurious moustEntered event. Sending the mouseUp
sends a spurious mouseEntered event. Sending the mouseUp
event back to the NSWindow resets the NSWindow's idea of the
last mouse point so it doesn't think that the mouse has
entered the view (since it was always there, it's just that
@ -602,17 +634,13 @@
if (NSEqualPoints(point, mouseDownPoint) == NO)
{
/*
* A subview was moved or resized, so we must mark the
* doucment as edited.
*/
// A subview was moved or resized, so we must mark the doucment as edited.
[document touch];
}
[superview unlockFocus];
/*
* Restore state to what it was on entry.
*/
// Restore window state to what it was when entering the method.
[[self window] setAcceptsMouseMovedEvents: acceptsMouseMoved];
}