Reorganize location of theme proxy code. Add some more comments too.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27831 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2009-02-10 14:32:08 +00:00
parent 9ef46af7f5
commit 570b8a4963
4 changed files with 103 additions and 84 deletions

View file

@ -1,3 +1,13 @@
2009-02-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSThemePrivate.h:
* Source/GSTheme.m:
* Source/NSImage.m:
Move/rename new proxy code to GSTheme.m and declare it in
GSThemePrivate.h so that all code in the GUI can use it
(we will need to allow other resources to automatically update
to the current theme, not just images).
2009-02-09 20:16-EST Gregory John Casamento <greg_casamento@yahoo.com>
* Source/NSToolbar.m: (-windowDidUpdate:): Automatically update

View file

@ -26,15 +26,17 @@
Boston, MA 02110-1301, USA.
*/
#import "Foundation/NSBundle.h"
#import "Foundation/NSDictionary.h"
#import "Foundation/NSFileManager.h"
#import "Foundation/NSMapTable.h"
#import "Foundation/NSNotification.h"
#import "Foundation/NSNull.h"
#import "Foundation/NSPathUtilities.h"
#import "Foundation/NSSet.h"
#import "Foundation/NSUserDefaults.h"
#import <Foundation/NSBundle.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSInvocvation.h>
#import <Foundation/NSMapTable.h>
#import <Foundation/NSMethodSignature.h>
#import <Foundation/NSNotification.h>
#import <Foundation/NSNull.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSSet.h>
#import <Foundation/NSUserDefaults.h>
#import "GNUstepGUI/GSTheme.h"
#import "AppKit/NSApplication.h"
#import "AppKit/NSButton.h"
@ -849,3 +851,50 @@ typedef struct {
}
@end
@implementation GSThemeProxy
- (id) _resource
{
return _resource;
}
- (void) _setResource: (id)resource
{
ASSIGN(_resource, resource);
}
- (void) dealloc
{
DESTROY(_resource);
[super dealloc];
}
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
[anInvocation invokeWithTarget: _resource];
}
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
{
if (_resource != nil)
{
return [_resource methodSignatureForSelector: aSelector];
}
else
{
/*
* Evil hack to prevent recursion - if we are asking a remote
* object for a method signature, we can't ask it for the
* signature of methodSignatureForSelector:, so we hack in
* the signature required manually :-(
*/
if (sel_eq(aSelector, _cmd))
{
static NSMethodSignature *sig = nil;
if (sig == nil)
{
sig = RETAIN([NSMethodSignature signatureWithObjCTypes: "@@::"]);
}
return sig;
}
return nil;
}
}
@end

View file

@ -25,7 +25,10 @@
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _INCLUDED_GSTHEMEPRIVATE_H
#define _INCLUDED_GSTHEMEPRIVATE_H
#import <Foundation/NSProxy.h>
#import "AppKit/NSPanel.h"
#import "GNUstepGUI/GSTheme.h"
@ -149,3 +152,21 @@ typedef enum {
withColor: (NSColor*)backgroundColor;
@end
/* The GSThemeProxy class provides a simple proxy object for intermal use
* by the GUI library when dealing with references to resources which may
* be changed by activating a new theme, but which will be set in other
* GUI objects. Having objects store a proxy to the orignal resource
* rather than storing the original resource itsself means that, when the
* new theme is activated the new resource can be used for drawing rather
* than the old version.
*/
@interface GSThemeProxy : NSProxy
{
id _resource;
}
- (id) _resource;
- (void) _setResource: (id)resource;
@end
#endif

View file

@ -34,9 +34,7 @@
#include <Foundation/NSDictionary.h>
#include <Foundation/NSException.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSInvocation.h>
#include <Foundation/NSKeyedArchiver.h>
#include <Foundation/NSProxy.h>
#include <Foundation/NSString.h>
#include <Foundation/NSValue.h>
@ -54,6 +52,7 @@
#include "AppKit/NSWindow.h"
#include "AppKit/PSOperators.h"
#include "GNUstepGUI/GSDisplayServer.h"
#include "GSThemePrivate.h"
/* Helpers. Would be nicer to use the C99 fmin/fmax functions, but that
@ -73,60 +72,6 @@ static double gs_max(double x, double y)
return x;
}
@interface GSImageProxy : NSProxy
{
NSImage *_image;
}
- (NSImage*) _image;
- (void) _setImage: (NSImage*)image;
@end
@implementation GSImageProxy
- (NSImage*) _image
{
return _image;
}
- (void) _setImage: (NSImage*)image
{
ASSIGN(_image, image);
}
- (void) dealloc
{
DESTROY(_image);
[super dealloc];
}
- (void) forwardInvocation: (NSInvocation*)anInvocation
{
[anInvocation invokeWithTarget: _image];
}
- (NSMethodSignature*) methodSignatureForSelector: (SEL)aSelector
{
if (_image != nil)
{
return [_image methodSignatureForSelector: aSelector];
}
else
{
/*
* Evil hack to prevent recursion - if we are asking a remote
* object for a method signature, we can't ask it for the
* signature of methodSignatureForSelector:, so we hack in
* the signature required manually :-(
*/
if (sel_eq(aSelector, _cmd))
{
static NSMethodSignature *sig = nil;
if (sig == nil)
{
sig = RETAIN([NSMethodSignature signatureWithObjCTypes: "@@::"]);
}
return sig;
}
return nil;
}
}
@end
BOOL NSImageForceCaching = NO; /* use on missmatch */
@implementation NSBundle (NSImageAdditions)
@ -526,8 +471,8 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
RELEASE(_reps);
/* Make sure we don't remove name from the nameDict if we are just a copy
of the named image, not the original image */
if (_name && self == [[nameDict objectForKey: _name] _image])
[[nameDict objectForKey: _name] _setImage: nil];
if (_name && self == [[nameDict objectForKey: _name] _resource])
[[nameDict objectForKey: _name] _setResource: nil];
RELEASE(_name);
TEST_RELEASE(_fileName);
RELEASE(_color);
@ -565,34 +510,28 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
- (BOOL) setName: (NSString *)aName
{
GSImageProxy *proxy = nil;
BOOL retained = NO;
GSThemeProxy *proxy = nil;
if (!aName || [[nameDict objectForKey: aName] _image] != nil)
return NO;
if (_name && self == [(proxy = [nameDict objectForKey: _name]) _image])
if (!aName || [[nameDict objectForKey: aName] _resource] != nil)
{
/* We retain self in case removing from the dictionary releases
us */
RETAIN (self);
retained = YES;
[proxy _setImage: nil];
return NO;
}
if (_name && self == [(proxy = [nameDict objectForKey: _name]) _resource])
{
/* We retain self in case removing from the dictionary releases us */
IF_NO_GC([[self retain] autorelease]);
[proxy _setResource: nil];
}
ASSIGN(_name, aName);
if ((proxy = [nameDict objectForKey: _name]) == nil)
{
proxy = [GSImageProxy alloc];
proxy = [GSThemeProxy alloc];
[nameDict setObject: proxy forKey: _name];
[proxy release];
}
[proxy _setImage: self];
if (retained)
{
RELEASE (self);
}
[proxy _setResource: self];
return YES;
}