mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 14:50:38 +00:00
Update front-end support for registering dnd types.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4407 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
d0b2bf42c6
commit
a967db2efb
8 changed files with 240 additions and 126 deletions
|
@ -155,6 +155,7 @@ struct NSWindow_struct
|
|||
DESTROY(context_data);
|
||||
DESTROY(context_info);
|
||||
DESTROY(event_queue);
|
||||
NSFreeMapTable(drag_types);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
@ -182,6 +183,8 @@ struct NSWindow_struct
|
|||
initWithCapacity: 1];
|
||||
event_queue = [[NSMutableArray allocWithZone: [self zone]]
|
||||
initWithCapacity: 32];
|
||||
drag_types = NSCreateMapTable(NSIntMapKeyCallBacks,
|
||||
NSObjectMapValueCallBacks, 0);
|
||||
|
||||
/*
|
||||
* The classMethodTable dictionary and the list of all contexts must both
|
||||
|
@ -263,6 +266,90 @@ struct NSWindow_struct
|
|||
[focus_stack removeLastObject];
|
||||
}
|
||||
|
||||
/*
|
||||
* Drag and drop support
|
||||
*/
|
||||
|
||||
/*
|
||||
* Add (increment count by 1) each drag type to those registered
|
||||
* for the window. If this results in a change to the types registered
|
||||
* in the counted set, return YES, otherwise return NO.
|
||||
* Subclasses should override this method, call 'super' and take
|
||||
* appropriate action if the method returns 'YES'.
|
||||
*/
|
||||
- (BOOL) _addDragTypes: (NSArray*)types toWindow: (int)winNum
|
||||
{
|
||||
NSCountedSet *old = (NSCountedSet*)NSMapGet(drag_types, winNum);
|
||||
unsigned originalCount;
|
||||
unsigned i = [types count];
|
||||
|
||||
/*
|
||||
* Make sure the set exists.
|
||||
*/
|
||||
if (old == nil)
|
||||
{
|
||||
old = [NSCountedSet new];
|
||||
NSMapInsert(drag_types, (void*)winNum, (void*)(gsaddr)old);
|
||||
RELEASE(old);
|
||||
}
|
||||
originalCount = [old count];
|
||||
|
||||
while (i-- > 0)
|
||||
{
|
||||
id o = [types objectAtIndex: i];
|
||||
|
||||
[old removeObject: o];
|
||||
}
|
||||
if ([old count] == originalCount)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove (decrement count by 1) each drag type from those registered
|
||||
* for the window. If this results in a change to the types registered
|
||||
* in the counted set, return YES, otherwise return NO.
|
||||
* If given 'nil' as the array of types, remove ALL.
|
||||
* Subclasses should override this method, call 'super' and take
|
||||
* appropriate action if the method returns 'YES'.
|
||||
*/
|
||||
- (BOOL) _removeDragTypes: (NSArray*)types fromWindow: (int)winNum
|
||||
{
|
||||
NSCountedSet *old = (NSCountedSet*)NSMapGet(drag_types, winNum);
|
||||
|
||||
if (types == nil)
|
||||
{
|
||||
if (old == nil)
|
||||
return NO;
|
||||
NSMapRemove(drag_types, (void*)winNum);
|
||||
return YES;
|
||||
}
|
||||
else if (old == nil)
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned originalCount = [old count];
|
||||
unsigned i = [types count];
|
||||
|
||||
while (i-- > 0)
|
||||
{
|
||||
id o = [types objectAtIndex: i];
|
||||
|
||||
[old removeObject: o];
|
||||
}
|
||||
if ([old count] == originalCount)
|
||||
return NO;
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSCountedSet*) _dragTypesForWindow: (int)winNum
|
||||
{
|
||||
return (NSCountedSet*)NSMapGet(drag_types, winNum);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSGraphicsContext (Private)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue