mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 00:31:03 +00:00
Adding implementation for NSSelection and skeletal implementation for NSOutlineView. GJC
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11248 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2bc4e57f82
commit
dab1ab0c88
7 changed files with 493 additions and 11 deletions
|
@ -1,10 +1,14 @@
|
|||
/*
|
||||
NSSelection.m
|
||||
|
||||
Description...
|
||||
Description: NSSelection is used by NSDataLink to refer to a
|
||||
selection within a document.
|
||||
|
||||
Copyright (C) 1996 Free Software Foundation, Inc.
|
||||
|
||||
Author: Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
Date: 2001
|
||||
|
||||
Author: Scott Christley <scottc@net-community.com>
|
||||
Date: 1996
|
||||
|
||||
|
@ -27,10 +31,64 @@
|
|||
*/
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <Foundation/NSCoder.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <AppKit/NSSelection.h>
|
||||
#include <AppKit/NSPasteboard.h>
|
||||
|
||||
//
|
||||
// Global instances of these selections
|
||||
//
|
||||
static NSSelection *_sharedAllSelection = nil;
|
||||
static NSSelection *_sharedCurrentSelection = nil;
|
||||
static NSSelection *_sharedEmptySelection = nil;
|
||||
|
||||
// Private methods and variables for NSSelection
|
||||
typedef enum
|
||||
{
|
||||
GSCustomSelection,
|
||||
GSAllSelection,
|
||||
GSCurrentSelection,
|
||||
GSEmptySelection
|
||||
} GSSelectionType;
|
||||
|
||||
@interface NSSelection (PrivateMethods)
|
||||
- (void)_setIsWellKnownSelection: (BOOL)wellknown;
|
||||
- (GSSelectionType)_selectionType;
|
||||
- (void)_setSelectionType: (GSSelectionType)type;
|
||||
+ (NSSelection *)_wellKnownSelection: (char *)description;
|
||||
@end
|
||||
|
||||
@implementation NSSelection (PrivateMethods)
|
||||
- (void)_setIsWellKnownSelection: (BOOL)wellknown
|
||||
{
|
||||
_isWellKnownSelection = wellknown;
|
||||
}
|
||||
|
||||
- (void)_setSelectionType: (GSSelectionType)type
|
||||
{
|
||||
_selectionType = type;
|
||||
}
|
||||
|
||||
- (GSSelectionType)_selectionType
|
||||
{
|
||||
return _selectionType;
|
||||
}
|
||||
|
||||
+ (NSSelection *)_wellKnownSelection: (char *)description
|
||||
{
|
||||
NSData *selectionData = [NSData dataWithBytes: description
|
||||
length: strlen(description)];
|
||||
NSSelection *selection =
|
||||
[NSSelection selectionWithDescriptionData: selectionData];
|
||||
|
||||
[selection _setIsWellKnownSelection: YES];
|
||||
|
||||
return selection;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation NSSelection
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
|
@ -46,19 +104,41 @@
|
|||
//
|
||||
// Returning Special Selection Shared Instances
|
||||
//
|
||||
//
|
||||
// NOTE: The description returned for each of these is similar to the one
|
||||
// returned under OPENSTEP.
|
||||
//
|
||||
+ (NSSelection *)allSelection
|
||||
{
|
||||
return nil;
|
||||
if(!_sharedAllSelection)
|
||||
{
|
||||
_sharedAllSelection =
|
||||
[NSSelection _wellKnownSelection: "GNUstep All selection marker"];
|
||||
[_sharedEmptySelection _setSelectionType: GSAllSelection];
|
||||
}
|
||||
return _sharedAllSelection;
|
||||
}
|
||||
|
||||
+ (NSSelection *)currentSelection
|
||||
{
|
||||
return nil;
|
||||
if(!_sharedCurrentSelection)
|
||||
{
|
||||
_sharedCurrentSelection =
|
||||
[NSSelection _wellKnownSelection: "GNUstep Current selection marker"];
|
||||
[_sharedCurrentSelection _setSelectionType: GSCurrentSelection];
|
||||
}
|
||||
return _sharedCurrentSelection;
|
||||
}
|
||||
|
||||
+ (NSSelection *)emptySelection
|
||||
{
|
||||
return nil;
|
||||
if(!_sharedEmptySelection)
|
||||
{
|
||||
_sharedEmptySelection =
|
||||
[NSSelection _wellKnownSelection: "GNUstep Empty selection marker"];
|
||||
[_sharedEmptySelection _setSelectionType: GSEmptySelection];
|
||||
}
|
||||
return _sharedEmptySelection;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -66,7 +146,9 @@
|
|||
//
|
||||
+ (NSSelection *)selectionWithDescriptionData:(NSData *)data
|
||||
{
|
||||
return nil;
|
||||
NSSelection *selection =
|
||||
AUTORELEASE([[NSSelection alloc] initWithDescriptionData: data]);
|
||||
return selection;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -78,12 +160,21 @@
|
|||
//
|
||||
- (id)initWithDescriptionData:(NSData *)newData
|
||||
{
|
||||
return nil;
|
||||
[super init];
|
||||
ASSIGN(_descriptionData, newData);
|
||||
_isWellKnownSelection = NO;
|
||||
_selectionType = GSCustomSelection;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithPasteboard:(NSPasteboard *)pasteboard
|
||||
{
|
||||
return nil;
|
||||
[super init];
|
||||
ASSIGN(_descriptionData, [pasteboard dataForType: NSGeneralPboardType]);
|
||||
_isWellKnownSelection = NO;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -91,29 +182,72 @@
|
|||
//
|
||||
- (NSData *)descriptionData
|
||||
{
|
||||
return nil;
|
||||
return _descriptionData;
|
||||
}
|
||||
|
||||
- (BOOL)isWellKnownSelection
|
||||
{
|
||||
return NO;
|
||||
return _isWellKnownSelection;
|
||||
}
|
||||
|
||||
//
|
||||
// Writing a Selection to the Pasteboard
|
||||
//
|
||||
- (void)writeToPasteboard:(NSPasteboard *)pasteboard
|
||||
{}
|
||||
{
|
||||
[pasteboard setData: _descriptionData
|
||||
forType: NSGeneralPboardType];
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
[aCoder encodeValueOfObjCType: @encode(BOOL)
|
||||
at: &_isWellKnownSelection];
|
||||
[aCoder encodeValueOfObjCType: @encode(int)
|
||||
at: &_selectionType];
|
||||
[aCoder encodeValueOfObjCType: @encode(id)
|
||||
at: _descriptionData];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
[super init];
|
||||
[aDecoder decodeValueOfObjCType: @encode(BOOL)
|
||||
at: &_isWellKnownSelection];
|
||||
[aDecoder decodeValueOfObjCType: @encode(int)
|
||||
at: &_selectionType];
|
||||
|
||||
// if it's a well known selection then determine which one it is.
|
||||
if(_isWellKnownSelection)
|
||||
{
|
||||
switch(_selectionType)
|
||||
{
|
||||
case GSAllSelection:
|
||||
RELEASE(self);
|
||||
self = RETAIN([NSSelection allSelection]);
|
||||
break;
|
||||
case GSCurrentSelection:
|
||||
RELEASE(self);
|
||||
self = RETAIN([NSSelection currentSelection]);
|
||||
break;
|
||||
case GSEmptySelection:
|
||||
RELEASE(self);
|
||||
self = RETAIN([NSSelection emptySelection]);
|
||||
break;
|
||||
default:
|
||||
// Shouldn't get here.
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
[aDecoder decodeValueOfObjCType: @encode(id)
|
||||
at: _descriptionData];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue