Updates for dnd support

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4327 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-06-01 17:05:57 +00:00
parent 934e125679
commit 5a808ad389
7 changed files with 201 additions and 51 deletions

View file

@ -1,3 +1,14 @@
Tue Jun 1 18:20:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Headers/AppKit/NSResponder.h: New flag for dnd.
* Headers/AppKit/GSDragManager.h: new file.
* Source/GSDragManager.m: new file.
* Source/NSView.m: Implemented drag registration/unregistration and
prepared for garbage collection.
* Source/NSWindow.m: Implemented drag registration/unregistration and
prepared for garbage collection.
* Source/GNUmakefile: Updated for above changes
Fri May 28 15:15:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Fri May 28 15:15:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSPanel.m: ([-canBecomeKeyWindow]) return NO only if the * Source/NSPanel.m: ([-canBecomeKeyWindow]) return NO only if the

View file

@ -0,0 +1,37 @@
/*
GSDragManager.h
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: June 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _GNUstep_H_GSDragManager
#define _GNUstep_H_GSDragManager
#include <Foundation/Foundation.h>
NSArray *GSGetDragTypes(id obj);
void GSRegisterDragTypes(id obj, NSArray *types);
void GSUnregisterDragTypes(id obj);
#endif

View file

@ -52,9 +52,10 @@
* be sure to change the flag accordingly. * be sure to change the flag accordingly.
*/ */
unsigned flipped_view:1; unsigned flipped_view:1;
unsigned has_subviews:1; unsigned has_subviews:1; /* This view has subviews */
unsigned has_currects:1; unsigned has_currects:1; /* This view has cursor rects */
unsigned has_trkrects:1; unsigned has_trkrects:1; /* This view has tracking rects */
unsigned has_draginfo:1; /* View/window has drag types */
} _rFlags; } _rFlags;
} }

View file

@ -108,6 +108,7 @@ NSView.m \
NSWindow.m \ NSWindow.m \
NSWorkspace.m \ NSWorkspace.m \
GSTrackingRect.m \ GSTrackingRect.m \
GSDragManager.m \
GSServicesManager.m \ GSServicesManager.m \
tiff.m \ tiff.m \
externs.m externs.m
@ -210,6 +211,7 @@ AppKit/GSMethodTable.h \
AppKit/DPSOperators.h \ AppKit/DPSOperators.h \
AppKit/PSOperators.h \ AppKit/PSOperators.h \
AppKit/GSPasteboardServer.h \ AppKit/GSPasteboardServer.h \
AppKit/GSDragManager.h \
AppKit/GSServicesManager.h AppKit/GSServicesManager.h
-include GNUmakefile.preamble -include GNUmakefile.preamble

75
Source/GSDragManager.m Normal file
View file

@ -0,0 +1,75 @@
/*
GSDragManager.m
Copyright (C) 1999 Free Software Foundation, Inc.
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Date: June 1999
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gnustep/gui/config.h>
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
/*
* Stuff to maintain a map table so we know what windows and views are
* registered for drag and drop.
* FIXME - may need locks for thread safety?
*/
static NSMapTable *typesMap = 0;
static inline void
GSSetupDragTypes()
{
if (typesMap == 0)
{
typesMap = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks,
NSObjectMapValueCallBacks, 0);
}
}
NSArray*
GSGetDragTypes(id obj)
{
GSSetupDragTypes();
return NSMapGet(typesMap, (void*)(gsaddr)obj);
}
void
GSRegisterDragTypes(id obj, NSArray *types)
{
NSArray *m = [types mutableCopy];
NSArray *t = [m copy];
RELEASE(m);
GSSetupDragTypes();
NSMapInsert(typesMap, (void*)(gsaddr)obj, (void*)(gsaddr)t);
RELEASE(t);
}
void
GSUnregisterDragTypes(id obj)
{
GSSetupDragTypes();
NSMapRemove(typesMap, (void*)(gsaddr)obj);
}

View file

@ -47,6 +47,7 @@
#include <AppKit/NSView.h> #include <AppKit/NSView.h>
#include <AppKit/NSWindow.h> #include <AppKit/NSWindow.h>
#include <AppKit/GSDragManager.h>
#include <AppKit/GSTrackingRect.h> #include <AppKit/GSTrackingRect.h>
#include <AppKit/NSAffineTransform.h> #include <AppKit/NSAffineTransform.h>
@ -147,13 +148,14 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) dealloc - (void) dealloc
{ {
[matrixToWindow release]; RELEASE(matrixToWindow);
[matrixFromWindow release]; RELEASE(matrixFromWindow);
[frameMatrix release]; RELEASE(frameMatrix);
[boundsMatrix release]; RELEASE(boundsMatrix);
[sub_views release]; TEST_RELEASE(sub_views);
[tracking_rects release]; TEST_RELEASE(tracking_rects);
[cursor_rects release]; TEST_RELEASE(cursor_rects);
[self unregisterDraggedTypes];
[super dealloc]; [super dealloc];
} }
@ -166,7 +168,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
return; return;
} }
[aView retain]; RETAIN(aView);
[aView removeFromSuperview]; [aView removeFromSuperview];
[aView viewWillMoveToWindow: window]; [aView viewWillMoveToWindow: window];
[aView viewWillMoveToSuperview: self]; [aView viewWillMoveToSuperview: self];
@ -175,7 +177,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1; _rFlags.has_subviews = 1;
[aView resetCursorRects]; [aView resetCursorRects];
[aView setNeedsDisplay: YES]; [aView setNeedsDisplay: YES];
[aView release]; RELEASE(aView);
} }
- (void) addSubview: (NSView*)aView - (void) addSubview: (NSView*)aView
@ -202,7 +204,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
else else
index = [sub_views count]; index = [sub_views count];
} }
[aView retain]; RETAIN(aView);
[aView removeFromSuperview]; [aView removeFromSuperview];
[aView viewWillMoveToWindow: window]; [aView viewWillMoveToWindow: window];
[aView viewWillMoveToSuperview: self]; [aView viewWillMoveToSuperview: self];
@ -214,7 +216,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1; _rFlags.has_subviews = 1;
[aView resetCursorRects]; [aView resetCursorRects];
[aView setNeedsDisplay: YES]; [aView setNeedsDisplay: YES];
[aView release]; RELEASE(aView);
} }
- (NSView*) ancestorSharedWithView: (NSView*)aView - (NSView*) ancestorSharedWithView: (NSView*)aView
@ -280,13 +282,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if ([window firstResponder] == self) if ([window firstResponder] == self)
[window makeFirstResponder: window]; [window makeFirstResponder: window];
[self retain]; RETAIN(self);
[super_view->sub_views removeObjectIdenticalTo: self]; [super_view->sub_views removeObjectIdenticalTo: self];
if ([super_view->sub_views count] == 0) if ([super_view->sub_views count] == 0)
super_view->_rFlags.has_subviews = 0; super_view->_rFlags.has_subviews = 0;
super_view = nil; super_view = nil;
[self viewWillMoveToWindow: nil]; [self viewWillMoveToWindow: nil];
[self release]; RELEASE(self);
} }
- (void) removeFromSuperview - (void) removeFromSuperview
@ -307,13 +309,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if ([window firstResponder] == self) if ([window firstResponder] == self)
[window makeFirstResponder: window]; [window makeFirstResponder: window];
[super_view setNeedsDisplayInRect: frame]; [super_view setNeedsDisplayInRect: frame];
[self retain]; RETAIN(self);
[super_view->sub_views removeObjectIdenticalTo: self]; [super_view->sub_views removeObjectIdenticalTo: self];
if ([super_view->sub_views count] == 0) if ([super_view->sub_views count] == 0)
super_view->_rFlags.has_subviews = 0; super_view->_rFlags.has_subviews = 0;
super_view = nil; super_view = nil;
[self viewWillMoveToWindow: nil]; [self viewWillMoveToWindow: nil];
[self release]; RELEASE(self);
} }
- (void) replaceSubview: (NSView*)oldView with: (NSView*)newView - (void) replaceSubview: (NSView*)oldView with: (NSView*)newView
@ -333,7 +335,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
* of the receiver then we do nothing - but here we add newView anyway. * of the receiver then we do nothing - but here we add newView anyway.
* So a replacement with no oldView is an addition. * So a replacement with no oldView is an addition.
*/ */
[newView retain]; RETAIN(newView);
[newView removeFromSuperview]; [newView removeFromSuperview];
[newView viewWillMoveToWindow: window]; [newView viewWillMoveToWindow: window];
[newView viewWillMoveToSuperview: self]; [newView viewWillMoveToSuperview: self];
@ -342,7 +344,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1; _rFlags.has_subviews = 1;
[newView resetCursorRects]; [newView resetCursorRects];
[newView setNeedsDisplay: YES]; [newView setNeedsDisplay: YES];
[newView release]; RELEASE(newView);
} }
else if ([sub_views indexOfObjectIdenticalTo: oldView] != NSNotFound) else if ([sub_views indexOfObjectIdenticalTo: oldView] != NSNotFound)
{ {
@ -365,7 +367,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
* newView), remove the oldView, and insert the newView in it's * newView), remove the oldView, and insert the newView in it's
* place. * place.
*/ */
[newView retain]; RETAIN(newView);
[newView removeFromSuperview]; [newView removeFromSuperview];
index = [sub_views indexOfObjectIdenticalTo: oldView]; index = [sub_views indexOfObjectIdenticalTo: oldView];
[oldView removeFromSuperview]; [oldView removeFromSuperview];
@ -376,7 +378,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1; _rFlags.has_subviews = 1;
[newView resetCursorRects]; [newView resetCursorRects];
[newView setNeedsDisplay: YES]; [newView setNeedsDisplay: YES];
[newView release]; RELEASE(newView);
} }
} }
} }
@ -1452,7 +1454,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
userData: NULL userData: NULL
inside: YES]; inside: YES];
[cursor_rects addObject: m]; [cursor_rects addObject: m];
[m release]; RELEASE(m);
_rFlags.has_currects = 1; _rFlags.has_currects = 1;
} }
@ -1687,11 +1689,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
} }
++t; ++t;
m = [[[GSTrackingRect alloc] initWithRect: aRect m = [[GSTrackingRect alloc] initWithRect: aRect
tag: t tag: t
owner: anObject owner: anObject
userData: data userData: data
inside: flag] autorelease]; inside: flag];
AUTORELEASE(m);
[tracking_rects addObject: m]; [tracking_rects addObject: m];
_rFlags.has_trkrects = 1; _rFlags.has_trkrects = 1;
return t; return t;
@ -1718,10 +1721,19 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
{} {}
- (void) registerForDraggedTypes: (NSArray*)newTypes - (void) registerForDraggedTypes: (NSArray*)newTypes
{} {
GSRegisterDragTypes(self, newTypes);
_rFlags.has_draginfo = 1;
}
- (void) unregisterDraggedTypes - (void) unregisterDraggedTypes
{} {
if (_rFlags.has_draginfo)
{
GSUnregisterDragTypes(self);
_rFlags.has_draginfo = 0;
}
}
// //
// Printing // Printing
@ -1944,7 +1956,7 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
* a mutable array does a shallow copy - which is what we want to give * a mutable array does a shallow copy - which is what we want to give
* away - we don't want people to mess with our actual subviews array. * away - we don't want people to mess with our actual subviews array.
*/ */
return [[sub_views mutableCopyWithZone: NSDefaultMallocZone()] autorelease]; return AUTORELEASE([sub_views mutableCopyWithZone: NSDefaultMallocZone()]);
} }
- (NSView*) superview - (NSView*) superview

View file

@ -168,18 +168,18 @@ static Class responderClass;
{ {
if (content_view) if (content_view)
{ {
[[content_view superview] release]; // Release the window view RELEASE([content_view superview]); /* Release the window view */
[content_view release]; // Release the content view RELEASE(content_view);
} }
if (_fieldEditor) TEST_RELEASE(_fieldEditor);
[_fieldEditor release]; TEST_RELEASE(background_color);
[background_color release]; TEST_RELEASE(represented_filename);
[represented_filename release]; TEST_RELEASE(miniaturized_title);
[miniaturized_title release]; TEST_RELEASE(miniaturized_image);
[miniaturized_image release]; TEST_RELEASE(window_title);
[window_title release]; TEST_RELEASE(rectsBeingDrawn);
[rectsBeingDrawn release]; [self unregisterDraggedTypes];
[super dealloc]; [super dealloc];
} }
@ -233,12 +233,12 @@ static Class responderClass;
cframe.origin = NSZeroPoint; // Create the content view cframe.origin = NSZeroPoint; // Create the content view
cframe.size = frame.size; cframe.size = frame.size;
[self setContentView: [[[NSView alloc] initWithFrame: cframe] autorelease]]; [self setContentView: AUTORELEASE([[NSView alloc] initWithFrame: cframe])];
/* rectBeingDrawn is variable used to optimize flushing the backing store. /* rectBeingDrawn is variable used to optimize flushing the backing store.
It is set by NSGraphicContext during a lockFocus to tell NSWindow what It is set by NSGraphicContext during a lockFocus to tell NSWindow what
part a view is drawing in, so NSWindow only has to flush that portion */ part a view is drawing in, so NSWindow only has to flush that portion */
rectsBeingDrawn = [[NSMutableArray arrayWithCapacity: 10] retain]; rectsBeingDrawn = RETAIN([NSMutableArray arrayWithCapacity: 10]);
NSDebugLog(@"NSWindow end of init\n"); NSDebugLog(@"NSWindow end of init\n");
return self; return self;
@ -258,7 +258,7 @@ static Class responderClass;
// contentview can't be nil // contentview can't be nil
if (!aView) if (!aView)
aView = [[[NSView alloc] initWithFrame: frame] autorelease]; aView = AUTORELEASE([[NSView alloc] initWithFrame: frame]);
// If window view has not been created, create it // If window view has not been created, create it
if ((!content_view) || ([content_view superview] == nil)) if ((!content_view) || ([content_view superview] == nil))
@ -416,15 +416,20 @@ static Class responderClass;
} }
- (NSText *) fieldEditor: (BOOL)createFlag forObject: (id)anObject - (NSText *) fieldEditor: (BOOL)createFlag forObject: (id)anObject
{ // ask delegate if it can {
if ([delegate respondsToSelector: // provide a field editor /* ask delegate if it can provide a field editor */
if ([delegate respondsToSelector:
@selector(windowWillReturnFieldEditor:toObject:)]) @selector(windowWillReturnFieldEditor:toObject:)])
return [delegate windowWillReturnFieldEditor: self toObject: anObject]; return [delegate windowWillReturnFieldEditor: self toObject: anObject];
if(!_fieldEditor && createFlag) // each window has a global /*
{ // text field editor, if it * Each window has a global text field editor, if it doesn't exist create it
_fieldEditor = [[NSText new] retain]; // doesn't exist create it * if create flag is set
[_fieldEditor setFieldEditor: YES]; // if create flag is set */
if (!_fieldEditor && createFlag)
{
_fieldEditor = [NSText new];
[_fieldEditor setFieldEditor: YES];
} }
return _fieldEditor; return _fieldEditor;
@ -899,14 +904,14 @@ static Class responderClass;
* removal takes place when we post the notification. * removal takes place when we post the notification.
*/ */
if (is_released_when_closed) if (is_released_when_closed)
[self retain]; RETAIN(self);
[nc postNotificationName: NSWindowWillCloseNotification object: self]; [nc postNotificationName: NSWindowWillCloseNotification object: self];
[theApp removeWindowsItem: self]; [theApp removeWindowsItem: self];
[self orderOut: self]; [self orderOut: self];
if (is_released_when_closed) if (is_released_when_closed)
[self release]; RELEASE(self);
} }
- (void) deminiaturize: sender - (void) deminiaturize: sender
@ -1435,12 +1440,19 @@ static Class responderClass;
{ {
} }
- (void) registerForDraggedTypes: (NSArray *)newTypes - (void) registerForDraggedTypes: (NSArray*)newTypes
{ {
GSRegisterDragTypes(self, newTypes);
_rFlags.has_draginfo = 1;
} }
- (void) unregisterDraggedTypes - (void) unregisterDraggedTypes
{ {
if (_rFlags.has_draginfo)
{
GSUnregisterDragTypes(self);
_rFlags.has_draginfo = 0;
}
} }
// //
@ -1801,7 +1813,7 @@ static Class responderClass;
delegate = nil; delegate = nil;
window_num = 0; window_num = 0;
gstate = 0; gstate = 0;
background_color = [[NSColor controlColor] retain]; background_color = RETAIN([NSColor controlColor]);
represented_filename = @"Window"; represented_filename = @"Window";
miniaturized_title = @"Window"; miniaturized_title = @"Window";
miniaturized_image = nil; miniaturized_image = nil;