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 Frith-MacDonald 1999-06-01 17:05:57 +00:00
parent a069600acc
commit dcd2e40b41
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>
* 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.
*/
unsigned flipped_view:1;
unsigned has_subviews:1;
unsigned has_currects:1;
unsigned has_trkrects:1;
unsigned has_subviews:1; /* This view has subviews */
unsigned has_currects:1; /* This view has cursor rects */
unsigned has_trkrects:1; /* This view has tracking rects */
unsigned has_draginfo:1; /* View/window has drag types */
} _rFlags;
}

View file

@ -108,6 +108,7 @@ NSView.m \
NSWindow.m \
NSWorkspace.m \
GSTrackingRect.m \
GSDragManager.m \
GSServicesManager.m \
tiff.m \
externs.m
@ -210,6 +211,7 @@ AppKit/GSMethodTable.h \
AppKit/DPSOperators.h \
AppKit/PSOperators.h \
AppKit/GSPasteboardServer.h \
AppKit/GSDragManager.h \
AppKit/GSServicesManager.h
-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/NSWindow.h>
#include <AppKit/GSDragManager.h>
#include <AppKit/GSTrackingRect.h>
#include <AppKit/NSAffineTransform.h>
@ -147,13 +148,14 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
- (void) dealloc
{
[matrixToWindow release];
[matrixFromWindow release];
[frameMatrix release];
[boundsMatrix release];
[sub_views release];
[tracking_rects release];
[cursor_rects release];
RELEASE(matrixToWindow);
RELEASE(matrixFromWindow);
RELEASE(frameMatrix);
RELEASE(boundsMatrix);
TEST_RELEASE(sub_views);
TEST_RELEASE(tracking_rects);
TEST_RELEASE(cursor_rects);
[self unregisterDraggedTypes];
[super dealloc];
}
@ -166,7 +168,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
return;
}
[aView retain];
RETAIN(aView);
[aView removeFromSuperview];
[aView viewWillMoveToWindow: window];
[aView viewWillMoveToSuperview: self];
@ -175,7 +177,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1;
[aView resetCursorRects];
[aView setNeedsDisplay: YES];
[aView release];
RELEASE(aView);
}
- (void) addSubview: (NSView*)aView
@ -202,7 +204,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
else
index = [sub_views count];
}
[aView retain];
RETAIN(aView);
[aView removeFromSuperview];
[aView viewWillMoveToWindow: window];
[aView viewWillMoveToSuperview: self];
@ -214,7 +216,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1;
[aView resetCursorRects];
[aView setNeedsDisplay: YES];
[aView release];
RELEASE(aView);
}
- (NSView*) ancestorSharedWithView: (NSView*)aView
@ -280,13 +282,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if ([window firstResponder] == self)
[window makeFirstResponder: window];
[self retain];
RETAIN(self);
[super_view->sub_views removeObjectIdenticalTo: self];
if ([super_view->sub_views count] == 0)
super_view->_rFlags.has_subviews = 0;
super_view = nil;
[self viewWillMoveToWindow: nil];
[self release];
RELEASE(self);
}
- (void) removeFromSuperview
@ -307,13 +309,13 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
if ([window firstResponder] == self)
[window makeFirstResponder: window];
[super_view setNeedsDisplayInRect: frame];
[self retain];
RETAIN(self);
[super_view->sub_views removeObjectIdenticalTo: self];
if ([super_view->sub_views count] == 0)
super_view->_rFlags.has_subviews = 0;
super_view = nil;
[self viewWillMoveToWindow: nil];
[self release];
RELEASE(self);
}
- (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.
* So a replacement with no oldView is an addition.
*/
[newView retain];
RETAIN(newView);
[newView removeFromSuperview];
[newView viewWillMoveToWindow: window];
[newView viewWillMoveToSuperview: self];
@ -342,7 +344,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1;
[newView resetCursorRects];
[newView setNeedsDisplay: YES];
[newView release];
RELEASE(newView);
}
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
* place.
*/
[newView retain];
RETAIN(newView);
[newView removeFromSuperview];
index = [sub_views indexOfObjectIdenticalTo: oldView];
[oldView removeFromSuperview];
@ -376,7 +378,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
_rFlags.has_subviews = 1;
[newView resetCursorRects];
[newView setNeedsDisplay: YES];
[newView release];
RELEASE(newView);
}
}
}
@ -1452,7 +1454,7 @@ static SEL invalidateSel = @selector(_invalidateCoordinates);
userData: NULL
inside: YES];
[cursor_rects addObject: m];
[m release];
RELEASE(m);
_rFlags.has_currects = 1;
}
@ -1687,11 +1689,12 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
}
++t;
m = [[[GSTrackingRect alloc] initWithRect: aRect
m = [[GSTrackingRect alloc] initWithRect: aRect
tag: t
owner: anObject
userData: data
inside: flag] autorelease];
inside: flag];
AUTORELEASE(m);
[tracking_rects addObject: m];
_rFlags.has_trkrects = 1;
return t;
@ -1718,10 +1721,19 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
{}
- (void) registerForDraggedTypes: (NSArray*)newTypes
{}
{
GSRegisterDragTypes(self, newTypes);
_rFlags.has_draginfo = 1;
}
- (void) unregisterDraggedTypes
{}
{
if (_rFlags.has_draginfo)
{
GSUnregisterDragTypes(self);
_rFlags.has_draginfo = 0;
}
}
//
// 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
* 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

View file

@ -168,18 +168,18 @@ static Class responderClass;
{
if (content_view)
{
[[content_view superview] release]; // Release the window view
[content_view release]; // Release the content view
RELEASE([content_view superview]); /* Release the window view */
RELEASE(content_view);
}
if (_fieldEditor)
[_fieldEditor release];
[background_color release];
[represented_filename release];
[miniaturized_title release];
[miniaturized_image release];
[window_title release];
[rectsBeingDrawn release];
TEST_RELEASE(_fieldEditor);
TEST_RELEASE(background_color);
TEST_RELEASE(represented_filename);
TEST_RELEASE(miniaturized_title);
TEST_RELEASE(miniaturized_image);
TEST_RELEASE(window_title);
TEST_RELEASE(rectsBeingDrawn);
[self unregisterDraggedTypes];
[super dealloc];
}
@ -233,12 +233,12 @@ static Class responderClass;
cframe.origin = NSZeroPoint; // Create the content view
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.
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 */
rectsBeingDrawn = [[NSMutableArray arrayWithCapacity: 10] retain];
rectsBeingDrawn = RETAIN([NSMutableArray arrayWithCapacity: 10]);
NSDebugLog(@"NSWindow end of init\n");
return self;
@ -258,7 +258,7 @@ static Class responderClass;
// contentview can't be nil
if (!aView)
aView = [[[NSView alloc] initWithFrame: frame] autorelease];
aView = AUTORELEASE([[NSView alloc] initWithFrame: frame]);
// If window view has not been created, create it
if ((!content_view) || ([content_view superview] == nil))
@ -416,15 +416,20 @@ static Class responderClass;
}
- (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:)])
return [delegate windowWillReturnFieldEditor: self toObject: anObject];
if(!_fieldEditor && createFlag) // each window has a global
{ // text field editor, if it
_fieldEditor = [[NSText new] retain]; // doesn't exist create it
[_fieldEditor setFieldEditor: YES]; // if create flag is set
/*
* Each window has a global text field editor, if it doesn't exist create it
* if create flag is set
*/
if (!_fieldEditor && createFlag)
{
_fieldEditor = [NSText new];
[_fieldEditor setFieldEditor: YES];
}
return _fieldEditor;
@ -899,14 +904,14 @@ static Class responderClass;
* removal takes place when we post the notification.
*/
if (is_released_when_closed)
[self retain];
RETAIN(self);
[nc postNotificationName: NSWindowWillCloseNotification object: self];
[theApp removeWindowsItem: self];
[self orderOut: self];
if (is_released_when_closed)
[self release];
RELEASE(self);
}
- (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
{
if (_rFlags.has_draginfo)
{
GSUnregisterDragTypes(self);
_rFlags.has_draginfo = 0;
}
}
//
@ -1801,7 +1813,7 @@ static Class responderClass;
delegate = nil;
window_num = 0;
gstate = 0;
background_color = [[NSColor controlColor] retain];
background_color = RETAIN([NSColor controlColor]);
represented_filename = @"Window";
miniaturized_title = @"Window";
miniaturized_image = nil;