mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-04-22 12:55:44 +00:00
* EOInterface/EOAssociation.h/m: New files.
* EOInterface/EOInterface.h: Add EOAssocitaion. * EOInterface/GNUmakefile: Ditto. * EOInterface/EODisplayGroup.h: Add missing forward * declaration. * EOInterface/EODisplayGroup.m: ([-insertObjectAtIndex]): avoid warning. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@20226 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b683e9125a
commit
14be1f330b
7 changed files with 496 additions and 0 deletions
|
@ -1,3 +1,12 @@
|
|||
2004-10-15 David Ayers <d.ayers@inode.at>
|
||||
|
||||
* EOInterface/EOAssociation.h/m: New files.
|
||||
* EOInterface/EOInterface.h: Add EOAssocitaion.
|
||||
* EOInterface/GNUmakefile: Ditto.
|
||||
* EOInterface/EODisplayGroup.h: Add missing forward declaration.
|
||||
* EOInterface/EODisplayGroup.m: ([-insertObjectAtIndex]):
|
||||
avoid warning.
|
||||
|
||||
2004-10-14 David Ayers <d.ayers@inode.at>
|
||||
|
||||
* EOInterface: New directory.
|
||||
|
|
120
EOInterface/EOAssociation.h
Normal file
120
EOInterface/EOAssociation.h
Normal file
|
@ -0,0 +1,120 @@
|
|||
/** -*-ObjC-*-
|
||||
EOAssociation.h
|
||||
|
||||
Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: David Ayers <d.ayers@inode.at>
|
||||
|
||||
This file is part of the GNUstep Database Library
|
||||
|
||||
The GNUstep Database Library is free software; you can redistribute it
|
||||
and/or modify it under the terms of the GNU Lesser General Public License
|
||||
as published by the Free Software Foundation; either version 2,
|
||||
or (at your option) any later version.
|
||||
|
||||
The GNUstep Database 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNUstep Database Library; see the file COPYING. If not,
|
||||
write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __EOInterface_EOAssociation_h__
|
||||
#define __EOInterface_EOAssociation_h__
|
||||
|
||||
#ifdef GNUSTEP
|
||||
#include <Foundation/NSObject.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#else
|
||||
#include <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
#include <EOControl/EOObserver.h>
|
||||
|
||||
@class NSString;
|
||||
@class NSArray;
|
||||
|
||||
@class EODisplayGroup;
|
||||
|
||||
@interface EOAssociation : EODelayedObserver <NSCoding>
|
||||
{
|
||||
id _object;
|
||||
|
||||
unsigned int _refs:8;
|
||||
unsigned int _isConnected:1;
|
||||
unsigned int _extras:7;
|
||||
unsigned int subclassFlags:16;
|
||||
|
||||
@private
|
||||
NSMapTable *_displayGroupMap;
|
||||
NSMapTable *_displayGroupKeyMap;
|
||||
}
|
||||
|
||||
/* Defining capabilities of concete class. */
|
||||
+ (NSArray *)aspects;
|
||||
+ (NSArray *)aspectSignatures;
|
||||
|
||||
+ (NSArray *)objectKeysTaken;
|
||||
+ (BOOL)isUsableWithObject: (id)object;
|
||||
|
||||
+ (NSArray *)associationClassesSuperseded;
|
||||
|
||||
+ (NSString *)displayName;
|
||||
|
||||
+ (NSString *)primaryAspect;
|
||||
|
||||
+ (NSArray *)associationClassesForObject: (id)object;
|
||||
|
||||
/* Creation and configuration. */
|
||||
- (id)initWithObject: (id)object;
|
||||
- (void)bindAspect: (NSString *)aspectName
|
||||
displayGroup: (EODisplayGroup *)displayGroup
|
||||
key: (NSString *)key;
|
||||
- (void)establishConnection;
|
||||
- (void)breakConnection;
|
||||
|
||||
- (void)copyMatchingBindingsFromAssociation: (EOAssociation *)association;
|
||||
|
||||
/* Defining capabilities of concrete instance. */
|
||||
- (BOOL)canBindAspect: (NSString *)aspectName
|
||||
displayGroup: (EODisplayGroup *)displayGroup
|
||||
key: (NSString *)key;
|
||||
|
||||
/* Display object access. */
|
||||
- (id)object;
|
||||
|
||||
/* Bindings access. */
|
||||
- (EODisplayGroup *)displayGroupForAspect: (NSString *)aspectName;
|
||||
- (NSString *)displayGroupKeyForAspect: (NSString *)aspectName;
|
||||
|
||||
/* Display object value manipulation. */
|
||||
- (void)subjectChanged;
|
||||
- (BOOL)endEditing;
|
||||
|
||||
/* Enterprise object value manipulation. */
|
||||
- (id)valueForAspect: (NSString *)aspectName;
|
||||
- (BOOL)setValue: (id)value forAspect: (NSString *)aspectName;
|
||||
|
||||
- (id)valueForAspect: (NSString *)aspectName
|
||||
atIndex: (unsigned int)index;
|
||||
- (BOOL)setValue: (id)value
|
||||
forAspect: (NSString *)aspectName
|
||||
atIndex: (unsigned int)index;
|
||||
|
||||
/* Handling of validation errors. */
|
||||
- (BOOL)shouldEndEditingForAspect: (NSString *)aspectName
|
||||
invalidInput: (NSString *)input
|
||||
errorDescription: (NSString *)description;
|
||||
- (BOOL)shouldEndEditingForAspect: (NSString *)aspectName
|
||||
invalidInput: (NSString *)input
|
||||
errorDescription: (NSString *)description
|
||||
index: (unsigned int)index;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
362
EOInterface/EOAssociation.m
Normal file
362
EOInterface/EOAssociation.m
Normal file
|
@ -0,0 +1,362 @@
|
|||
/**
|
||||
EOAssociation.m
|
||||
|
||||
Copyright (C) 2004 Free Software Foundation, Inc.
|
||||
|
||||
Author: David Ayers <d.ayers@inode.at>
|
||||
|
||||
This file is part of the GNUstep Database Library
|
||||
|
||||
The GNUstep Database Library is free software; you can redistribute it
|
||||
and/or modify it under the terms of the GNU Lesser General Public License
|
||||
as published by the Free Software Foundation; either version 2,
|
||||
or (at your option) any later version.
|
||||
|
||||
The GNUstep Database 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
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with the GNUstep Database Library; see the file COPYING. If not,
|
||||
write to the Free Software Foundation, Inc.,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifdef GNUSTEP
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSBundle.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSMapTable.h>
|
||||
#else
|
||||
#include <Foundation/Foundation.h>
|
||||
#endif
|
||||
|
||||
#include <GNUstepBase/GSObjCRuntime.h>
|
||||
|
||||
#include "EODisplayGroup.h"
|
||||
|
||||
#include "EOAssociation.h"
|
||||
|
||||
/*++ TEMPORARY LOCAL DEFINITION ++*/
|
||||
static inline NSArray *
|
||||
GSObjCAllSubclassesOfClass(Class baseClass)
|
||||
{
|
||||
if (!baseClass)
|
||||
return nil;
|
||||
|
||||
{
|
||||
Class aClass;
|
||||
NSMutableArray *result = [NSMutableArray array];
|
||||
#ifdef GNU_RUNTIME
|
||||
for (aClass = baseClass->subclass_list;
|
||||
aClass;
|
||||
aClass=aClass->sibling_class)
|
||||
{
|
||||
[result addObject:aClass];
|
||||
[result addObjectsFromArray: GSObjCAllSubclassesOfClass(aClass)];
|
||||
}
|
||||
#endif
|
||||
return AUTORELEASE([result copy]);
|
||||
}
|
||||
}
|
||||
/*++ TEMPORARY LOCAL DEFINITION ++*/
|
||||
|
||||
@implementation EOAssociation
|
||||
static NSArray *_emptyArray = nil;
|
||||
static NSMutableArray *_associationClasses = nil;
|
||||
+ (void)bundleLoaded: (NSNotification *)notification
|
||||
{
|
||||
DESTROY(_associationClasses);
|
||||
}
|
||||
|
||||
+ (void)initialize
|
||||
{
|
||||
if (_emptyArray == nil)
|
||||
{
|
||||
NSNotificationCenter *nc;
|
||||
_emptyArray = [NSArray new];
|
||||
nc = [NSNotificationCenter defaultCenter];
|
||||
[nc addObserver: self
|
||||
selector: @selector(bundleLoaded:)
|
||||
name: NSBundleDidLoadNotification
|
||||
object: nil];
|
||||
}
|
||||
}
|
||||
|
||||
+ (NSArray *)aspects
|
||||
{
|
||||
return _emptyArray;
|
||||
}
|
||||
|
||||
+ (NSArray *)aspectSignatures
|
||||
{
|
||||
unsigned int count = [[self aspects] count];
|
||||
unsigned int i;
|
||||
NSMutableArray *sigs = [NSMutableArray arrayWithCapacity: count];
|
||||
|
||||
for (i = count; i < count; i++)
|
||||
{
|
||||
[sigs addObject: @"A1M"];
|
||||
}
|
||||
|
||||
return AUTORELEASE([sigs copy]);
|
||||
}
|
||||
|
||||
+ (NSArray *)objectKeysTaken
|
||||
{
|
||||
return _emptyArray;
|
||||
}
|
||||
|
||||
+ (BOOL)isUsableWithObject: (id)object
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
+ (NSArray *)associationClassesSuperseded
|
||||
{
|
||||
return _emptyArray;
|
||||
}
|
||||
|
||||
+ (NSString *)displayName
|
||||
{
|
||||
return NSStringFromClass(self);
|
||||
}
|
||||
|
||||
+ (NSString *)primaryAspect
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSArray *)associationClassesForObject: (id)object
|
||||
{
|
||||
unsigned int i, count;
|
||||
NSMutableArray *arr;
|
||||
Class cls;
|
||||
|
||||
if (_associationClasses == nil)
|
||||
{
|
||||
_associationClasses
|
||||
= RETAIN(GSObjCAllSubclassesOfClass([EOAssociation class]));
|
||||
}
|
||||
|
||||
[_associationClasses count];
|
||||
arr = [NSMutableArray arrayWithCapacity: count];
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
cls = [_associationClasses objectAtIndex: i];
|
||||
if ([cls isUsableWithObject: cls])
|
||||
{
|
||||
[arr addObject: cls];
|
||||
}
|
||||
}
|
||||
return AUTORELEASE([arr copy]);
|
||||
}
|
||||
|
||||
|
||||
- (id)initWithObject: (id)object
|
||||
{
|
||||
if ((self = [super init]))
|
||||
{
|
||||
unsigned int count = [[[self class] aspects] count];
|
||||
NSZone *zone = [self zone];
|
||||
_object = object;
|
||||
_displayGroupMap
|
||||
= NSCreateMapTableWithZone(NSObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks,
|
||||
count, zone);
|
||||
_displayGroupKeyMap
|
||||
= NSCreateMapTableWithZone(NSObjectMapKeyCallBacks,
|
||||
NSNonRetainedObjectMapValueCallBacks,
|
||||
count, zone);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
return [self initWithObject: nil];
|
||||
}
|
||||
|
||||
- (id)initWithCoder: (NSCoder *)coder
|
||||
{
|
||||
return [self init];
|
||||
}
|
||||
|
||||
- (void) encodeWithCoder: (NSCoder*)coder
|
||||
{
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
NSFreeMapTable (_displayGroupMap);
|
||||
NSFreeMapTable (_displayGroupKeyMap);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)bindAspect: (NSString *)aspectName
|
||||
displayGroup: (EODisplayGroup *)displayGroup
|
||||
key: (NSString *)key
|
||||
{
|
||||
NSMapInsert(_displayGroupMap, aspectName, displayGroup);
|
||||
NSMapInsert(_displayGroupKeyMap, aspectName, key);
|
||||
}
|
||||
- (void)establishConnection
|
||||
{
|
||||
if (_isConnected == NO)
|
||||
{
|
||||
NSMapEnumerator displayGroupEnum;
|
||||
EODisplayGroup *displayGroup;
|
||||
Class EOObserverCenterClass = [EOObserverCenter class];
|
||||
|
||||
displayGroupEnum = NSEnumerateMapTable(_displayGroupMap);
|
||||
while (NSNextMapEnumeratorPair(&displayGroupEnum,
|
||||
0, (void*)&displayGroup))
|
||||
{
|
||||
[EOObserverCenterClass addObserver: self forObject: displayGroup];
|
||||
}
|
||||
NSEndMapTableEnumeration (&displayGroupEnum);
|
||||
_isConnected = YES;
|
||||
|
||||
//TODO: cause _object to retain us
|
||||
}
|
||||
}
|
||||
- (void)breakConnection
|
||||
{
|
||||
if (_isConnected)
|
||||
{
|
||||
NSMapEnumerator displayGroupEnum;
|
||||
EODisplayGroup *displayGroup;
|
||||
Class EOObserverCenterClass = [EOObserverCenter class];
|
||||
|
||||
displayGroupEnum = NSEnumerateMapTable(_displayGroupMap);
|
||||
while (NSNextMapEnumeratorPair(&displayGroupEnum,
|
||||
0, (void *)&displayGroup))
|
||||
{
|
||||
[EOObserverCenterClass removeObserver: self forObject: displayGroup];
|
||||
}
|
||||
NSEndMapTableEnumeration (&displayGroupEnum);
|
||||
_isConnected = YES;
|
||||
|
||||
//TODO: cause _object to release us
|
||||
}
|
||||
}
|
||||
|
||||
- (void)copyMatchingBindingsFromAssociation: (EOAssociation *)association
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)canBindAspect: (NSString *)aspectName
|
||||
displayGroup: (EODisplayGroup *)displayGroup
|
||||
key: (NSString *)key
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)object
|
||||
{
|
||||
return _object;
|
||||
}
|
||||
|
||||
- (EODisplayGroup *)displayGroupForAspect: (NSString *)aspectName
|
||||
{
|
||||
return NSMapGet(_displayGroupMap, aspectName);
|
||||
}
|
||||
- (NSString *)displayGroupKeyForAspect: (NSString *)aspectName;
|
||||
{
|
||||
return NSMapGet(_displayGroupKeyMap, aspectName);
|
||||
}
|
||||
|
||||
- (void)subjectChanged
|
||||
{
|
||||
}
|
||||
|
||||
- (BOOL)endEditing
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)valueForAspect: (NSString *)aspectName
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
- (BOOL)setValue: (id)value forAspect: (NSString *)aspectName
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (id)valueForAspect: (NSString *)aspectName
|
||||
atIndex: (unsigned int)index
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
- (BOOL)setValue: (id)value
|
||||
forAspect: (NSString *)aspectName
|
||||
atIndex: (unsigned int)index
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)shouldEndEditingForAspect: (NSString *)aspectName
|
||||
invalidInput: (NSString *)input
|
||||
errorDescription: (NSString *)description
|
||||
{
|
||||
EODisplayGroup *displayGroup;
|
||||
BOOL reply = YES;
|
||||
|
||||
displayGroup = [self displayGroupForAspect: aspectName];
|
||||
if (displayGroup)
|
||||
{
|
||||
NSString *displayGroupString
|
||||
= [self displayGroupKeyForAspect: aspectName];
|
||||
id selectedObject = [displayGroup selectedObject];
|
||||
reply = [displayGroup association: self
|
||||
failedToValidateValue: input
|
||||
forKey: displayGroupString
|
||||
object: selectedObject
|
||||
errorDescription: description];
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
- (BOOL)shouldEndEditingForAspect: (NSString *)aspectName
|
||||
invalidInput: (NSString *)input
|
||||
errorDescription: (NSString *)description
|
||||
index: (unsigned int)index
|
||||
{
|
||||
EODisplayGroup *displayGroup;
|
||||
BOOL reply = YES;
|
||||
|
||||
displayGroup = [self displayGroupForAspect: aspectName];
|
||||
if (displayGroup)
|
||||
{
|
||||
NSString *displayGroupString
|
||||
= [self displayGroupKeyForAspect: aspectName];
|
||||
NSArray *displayedObjects = [displayGroup displayedObjects];
|
||||
id object = [displayedObjects objectAtIndex: index];
|
||||
reply = [displayGroup association: self
|
||||
failedToValidateValue: input
|
||||
forKey: displayGroupString
|
||||
object: object
|
||||
errorDescription: description];
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
- (NSString *)debugDescription
|
||||
{
|
||||
NSLog(@"self:%p", self);
|
||||
/*
|
||||
NSLog(@"_end1:%p", &_end1);
|
||||
NSLog(@"_end2:%p", &_end2);
|
||||
*/
|
||||
NSLog(@"dGM :%p", &_displayGroupMap);
|
||||
NSLog(@"dGKM:%p", &_displayGroupKeyMap);
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
|
@ -39,6 +39,7 @@
|
|||
@class NSMutableDictionary;
|
||||
@class NSNotification;
|
||||
|
||||
@class EOEditingContext;
|
||||
@class EODataSource;
|
||||
@class EOQualifier;
|
||||
|
||||
|
|
|
@ -341,6 +341,7 @@ static BOOL _globalDefaultForValidatesChangesImmediately= NO;
|
|||
|
||||
- (id)insertObjectAtIndex: (unsigned)index
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
- (void)insertObject: (id)object atIndex: (unsigned)index
|
||||
{
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#ifndef __EOInterface_h__
|
||||
#define __EOInterface_h__
|
||||
|
||||
#include <EOInterface/EOAssociation.h>
|
||||
#include <EOInterface/EODisplayGroup.h>
|
||||
|
||||
#endif /* __EOInterface_h__ */
|
||||
|
|
|
@ -34,12 +34,14 @@ EOInterface_C_FILES =
|
|||
|
||||
# The Objective-C source files to be compiled
|
||||
EOInterface_OBJC_FILES = \
|
||||
EOAssociation.m \
|
||||
EODisplayGroup.m \
|
||||
|
||||
|
||||
EOInterface_HEADER_FILES_DIR = .
|
||||
|
||||
EOInterface_HEADER_FILES = \
|
||||
EOAssociation.h \
|
||||
EODisplayGroup.h \
|
||||
EOInterface.h
|
||||
|
||||
|
|
Loading…
Reference in a new issue