mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:30:47 +00:00
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:
parent
2e2c001c85
commit
365fab266c
4 changed files with 103 additions and 84 deletions
10
ChangeLog
10
ChangeLog
|
@ -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>
|
2009-02-09 20:16-EST Gregory John Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
* Source/NSToolbar.m: (-windowDidUpdate:): Automatically update
|
* Source/NSToolbar.m: (-windowDidUpdate:): Automatically update
|
||||||
|
|
|
@ -26,15 +26,17 @@
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "Foundation/NSBundle.h"
|
#import <Foundation/NSBundle.h>
|
||||||
#import "Foundation/NSDictionary.h"
|
#import <Foundation/NSDictionary.h>
|
||||||
#import "Foundation/NSFileManager.h"
|
#import <Foundation/NSFileManager.h>
|
||||||
#import "Foundation/NSMapTable.h"
|
#import <Foundation/NSInvocvation.h>
|
||||||
#import "Foundation/NSNotification.h"
|
#import <Foundation/NSMapTable.h>
|
||||||
#import "Foundation/NSNull.h"
|
#import <Foundation/NSMethodSignature.h>
|
||||||
#import "Foundation/NSPathUtilities.h"
|
#import <Foundation/NSNotification.h>
|
||||||
#import "Foundation/NSSet.h"
|
#import <Foundation/NSNull.h>
|
||||||
#import "Foundation/NSUserDefaults.h"
|
#import <Foundation/NSPathUtilities.h>
|
||||||
|
#import <Foundation/NSSet.h>
|
||||||
|
#import <Foundation/NSUserDefaults.h>
|
||||||
#import "GNUstepGUI/GSTheme.h"
|
#import "GNUstepGUI/GSTheme.h"
|
||||||
#import "AppKit/NSApplication.h"
|
#import "AppKit/NSApplication.h"
|
||||||
#import "AppKit/NSButton.h"
|
#import "AppKit/NSButton.h"
|
||||||
|
@ -849,3 +851,50 @@ typedef struct {
|
||||||
}
|
}
|
||||||
@end
|
@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
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,10 @@
|
||||||
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
||||||
Boston, MA 02110-1301, USA.
|
Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
#ifndef _INCLUDED_GSTHEMEPRIVATE_H
|
||||||
|
#define _INCLUDED_GSTHEMEPRIVATE_H
|
||||||
|
|
||||||
|
#import <Foundation/NSProxy.h>
|
||||||
#import "AppKit/NSPanel.h"
|
#import "AppKit/NSPanel.h"
|
||||||
#import "GNUstepGUI/GSTheme.h"
|
#import "GNUstepGUI/GSTheme.h"
|
||||||
|
|
||||||
|
@ -149,3 +152,21 @@ typedef enum {
|
||||||
withColor: (NSColor*)backgroundColor;
|
withColor: (NSColor*)backgroundColor;
|
||||||
@end
|
@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
|
||||||
|
|
||||||
|
|
|
@ -34,9 +34,7 @@
|
||||||
#include <Foundation/NSDictionary.h>
|
#include <Foundation/NSDictionary.h>
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
#include <Foundation/NSInvocation.h>
|
|
||||||
#include <Foundation/NSKeyedArchiver.h>
|
#include <Foundation/NSKeyedArchiver.h>
|
||||||
#include <Foundation/NSProxy.h>
|
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSValue.h>
|
#include <Foundation/NSValue.h>
|
||||||
|
|
||||||
|
@ -54,6 +52,7 @@
|
||||||
#include "AppKit/NSWindow.h"
|
#include "AppKit/NSWindow.h"
|
||||||
#include "AppKit/PSOperators.h"
|
#include "AppKit/PSOperators.h"
|
||||||
#include "GNUstepGUI/GSDisplayServer.h"
|
#include "GNUstepGUI/GSDisplayServer.h"
|
||||||
|
#include "GSThemePrivate.h"
|
||||||
|
|
||||||
|
|
||||||
/* Helpers. Would be nicer to use the C99 fmin/fmax functions, but that
|
/* 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;
|
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 */
|
BOOL NSImageForceCaching = NO; /* use on missmatch */
|
||||||
|
|
||||||
@implementation NSBundle (NSImageAdditions)
|
@implementation NSBundle (NSImageAdditions)
|
||||||
|
@ -526,8 +471,8 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
||||||
RELEASE(_reps);
|
RELEASE(_reps);
|
||||||
/* Make sure we don't remove name from the nameDict if we are just a copy
|
/* Make sure we don't remove name from the nameDict if we are just a copy
|
||||||
of the named image, not the original image */
|
of the named image, not the original image */
|
||||||
if (_name && self == [[nameDict objectForKey: _name] _image])
|
if (_name && self == [[nameDict objectForKey: _name] _resource])
|
||||||
[[nameDict objectForKey: _name] _setImage: nil];
|
[[nameDict objectForKey: _name] _setResource: nil];
|
||||||
RELEASE(_name);
|
RELEASE(_name);
|
||||||
TEST_RELEASE(_fileName);
|
TEST_RELEASE(_fileName);
|
||||||
RELEASE(_color);
|
RELEASE(_color);
|
||||||
|
@ -565,34 +510,28 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
|
||||||
|
|
||||||
- (BOOL) setName: (NSString *)aName
|
- (BOOL) setName: (NSString *)aName
|
||||||
{
|
{
|
||||||
GSImageProxy *proxy = nil;
|
GSThemeProxy *proxy = nil;
|
||||||
BOOL retained = NO;
|
|
||||||
|
|
||||||
if (!aName || [[nameDict objectForKey: aName] _image] != nil)
|
if (!aName || [[nameDict objectForKey: aName] _resource] != nil)
|
||||||
return NO;
|
|
||||||
|
|
||||||
if (_name && self == [(proxy = [nameDict objectForKey: _name]) _image])
|
|
||||||
{
|
{
|
||||||
/* We retain self in case removing from the dictionary releases
|
return NO;
|
||||||
us */
|
}
|
||||||
RETAIN (self);
|
if (_name && self == [(proxy = [nameDict objectForKey: _name]) _resource])
|
||||||
retained = YES;
|
{
|
||||||
[proxy _setImage: nil];
|
/* We retain self in case removing from the dictionary releases us */
|
||||||
|
IF_NO_GC([[self retain] autorelease]);
|
||||||
|
[proxy _setResource: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIGN(_name, aName);
|
ASSIGN(_name, aName);
|
||||||
|
|
||||||
if ((proxy = [nameDict objectForKey: _name]) == nil)
|
if ((proxy = [nameDict objectForKey: _name]) == nil)
|
||||||
{
|
{
|
||||||
proxy = [GSImageProxy alloc];
|
proxy = [GSThemeProxy alloc];
|
||||||
[nameDict setObject: proxy forKey: _name];
|
[nameDict setObject: proxy forKey: _name];
|
||||||
[proxy release];
|
[proxy release];
|
||||||
}
|
}
|
||||||
[proxy _setImage: self];
|
[proxy _setResource: self];
|
||||||
if (retained)
|
|
||||||
{
|
|
||||||
RELEASE (self);
|
|
||||||
}
|
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue