Attempt to get gnome and windows themes working again.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@34528 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2012-01-14 17:55:43 +00:00
parent 28460f68e4
commit db92916b2f
3 changed files with 95 additions and 56 deletions

View file

@ -1,3 +1,15 @@
2011-01-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTheme.m:
* Source/NSImage.m:
Attempt to get image support working as documented again ... restore
code in GSTheme to set up new named images on activation and restore
originals on deactivation (rather than doing everything in a
notification handler at the wrong point).
Honor +imageClass as the class to load new images again.
Hopefully this will get the windows and gnome
themes working again (though I dn't use either).
2011-01-14 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSTheme.m: Clean up and simplify theme switching based on
@ -10,7 +22,8 @@
2012-01-11 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSImage.m (+_clearFileTypeCaches): Use DESTROY instead of RELEASE.
* Source/NSImage.m (+_clearFileTypeCaches): Use DESTROY instead
of RELEASE.
Patch by Philippe Roussel <p.o.roussel@free.fr>.
2012-01-10 Eric Wasylishen <ewasylishen@gmail.com>

View file

@ -206,6 +206,10 @@ GSStringFromBorderType(NSBorderType borderType)
}
}
@interface NSImage (Private)
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
@end
@interface GSTheme (Private)
- (void) _revokeOwnerships;
@end
@ -240,8 +244,7 @@ typedef struct {
NSBundle *bundle;
NSColorList *colors;
NSColorList *extraColors[GSThemeSelectedState+1];
NSMutableDictionary *images;
NSMutableDictionary *oldImages;
NSMutableSet *imageNames;
NSMutableDictionary *tiles[GSThemeSelectedState+1];
NSMutableSet *owned;
NSImage *icon;
@ -255,8 +258,7 @@ typedef struct {
#define _bundle _internal->bundle
#define _colors _internal->colors
#define _extraColors _internal->extraColors
#define _images _internal->images
#define _oldImages _internal->oldImages
#define _imageNames _internal->imageNames
#define _tiles _internal->tiles
#define _owned _internal->owned
#define _icon _internal->icon
@ -444,6 +446,9 @@ typedef struct {
NSUserDefaults *defs;
NSMutableArray *searchList;
NSEnumerator *enumerator;
NSArray *imagePaths;
NSString *imagePath;
NSArray *imageTypes;
NSDictionary *infoDict;
NSWindow *window;
GSThemeControlState state;
@ -459,6 +464,30 @@ typedef struct {
_extraColors[state] = nil;
}
/*
* We step through all the bundle image resources and load them in
* to memory, setting their names so that they are visible to
* [NSImage+imageNamed:] and storing them in our local array.
*/
imageTypes = [_imageClass imageFileTypes];
imagePaths = [_bundle pathsForResourcesOfType: nil
inDirectory: @"ThemeImages"];
enumerator = [imagePaths objectEnumerator];
while ((imagePath = [enumerator nextObject]) != nil)
{
NSString *ext = [imagePath pathExtension];
if (ext != nil && [imageTypes containsObject: ext] == YES)
{
NSString *imageName;
imageName = [imagePath lastPathComponent];
imageName = [imageName stringByDeletingPathExtension];
[_imageNames addObject: imageName];
[NSImage _setImagePath: imagePath name: imageName];
}
}
/*
* Use the GSThemeDomain key in the info dictionary of the theme to
* set a defaults domain which will establish user defaults values
@ -678,6 +707,9 @@ typedef struct {
- (void) deactivate
{
NSEnumerator *enumerator;
NSString *imageName;
NSDebugMLLog(@"GSTheme", @"%@ %p", [self name], self);
/* Tell everything that we will become inactive.
@ -700,6 +732,15 @@ typedef struct {
}
}
/* Unload all images created by this theme.
*/
enumerator = [_imageNames objectEnumerator];
while ((imageName = [enumerator nextObject]) != nil)
{
[NSImage _setImagePath: nil name: imageName];
}
[_imageNames removeAllObjects];
[self _revokeOwnerships];
/* Tell everything that we have become inactive.
@ -723,8 +764,7 @@ typedef struct {
}
RELEASE(_bundle);
RELEASE(_colors);
RELEASE(_images);
RELEASE(_oldImages);
RELEASE(_imageNames);
RELEASE(_icon);
[self _revokeOwnerships];
RELEASE(_overrides);
@ -793,8 +833,7 @@ typedef struct {
_reserved = NSZoneCalloc ([self zone], 1, sizeof(internal));
ASSIGN(_bundle, bundle);
_images = [NSMutableDictionary new];
_oldImages = [NSMutableDictionary new];
_imageNames = [NSMutableSet new];
for (state = 0; state <= GSThemeSelectedState; state++)
{
_tiles[state] = [NSMutableDictionary new];

View file

@ -154,7 +154,7 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
@interface NSImage (Private)
+ (void) _clearFileTypeCaches: (NSNotification*)notif;
+ (void) _themeDidActivate: (NSNotification*)notif;
+ (void) _setImagePath: (NSString*)path name: (NSString*)name;
+ (NSString *) _pathForImageNamed: (NSString *)aName;
- (BOOL) _useFromFile: (NSString *)fileName;
- (BOOL) _loadFromData: (NSData *)data;
@ -194,12 +194,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
selector: @selector(_clearFileTypeCaches:)
name: NSImageRepRegistryChangedNotification
object: [NSImageRep class]];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(_themeDidActivate:)
name: GSThemeDidActivateNotification
object: nil];
[imageLock unlock];
}
}
@ -221,13 +215,13 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
if ([path length] != 0)
{
image = [[self allocWithZone: NSDefaultMallocZone()]
initByReferencingFile: path];
image = [[[[GSTheme theme] imageClass] alloc]
initByReferencingFile: path];
if (image != nil)
{
[image setName: aName];
AUTORELEASE(image);
image->_flags.archiveByName = YES;
AUTORELEASE(image);
}
}
}
@ -455,9 +449,6 @@ repd_for_rep(NSArray *_reps, NSImageRep *rep)
/* This methd sets the name of an image, updating the global name dictionary
* to point to the image (or removing an image from the dictionary if the
* new name is nil).
* The images are actually accessed via proxy objects, so that when a
* new system image is set (using [NSImage+_setImage:name:]), the proxy
* for that image just starts using the new version.
*/
- (BOOL) setName: (NSString *)aName
{
@ -1818,22 +1809,41 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
DESTROY(imagePasteboardTypes);
}
+ (void) _themeDidActivate: (NSNotification *)notif
+ (void) _setImagePath: (NSString*)path name: (NSString*)name
{
[imageLock lock];
NSImage *image;
NSImage *o;
NSEnumerator *e = [[nameDict allValues] objectEnumerator];
while ((o = (NSImage*)[e nextObject]) != nil)
[imageLock lock];
image = (NSImage*)[nameDict objectForKey: name];
if (nil == image && nil != path)
{
NSString *newPath = [self _pathForImageNamed: o->_name];
if (newPath != nil &&
![newPath isEqual: o->_fileName])
/* There was no existing image with the given name ...
* create a new one.
*/
image = [[[[GSTheme theme] imageClass] alloc]
initByReferencingFile: path];
if (image != nil)
{
[o _resetAndUseFromFile: newPath];
[image setName: name];
image->_flags.archiveByName = YES;
AUTORELEASE(image);
}
[image setName: name];
}
else
{
if (nil == path)
{
path = [self _pathForImageNamed: name];
}
if (path != nil && ![path isEqual: image->_fileName])
{
/* Reset the existing image to use the contents of
* the specified file.
*/
[image _resetAndUseFromFile: path];
}
}
[imageLock unlock];
}
@ -1845,7 +1855,7 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
NSBundle *main_bundle;
NSArray *array;
if (realName == nil)
if (nil == realName)
{
realName = aName;
}
@ -1892,29 +1902,6 @@ iterate_reps_for_types(NSArray* imageReps, SEL method)
}
}
/* Second search on theme bundle */
if (!path)
{
if (ext)
path = [[[GSTheme theme] bundle] pathForResource: realName
ofType: ext
inDirectory: @"ThemeImages"];
else
{
id o, e;
e = [array objectEnumerator];
while ((o = [e nextObject]))
{
path = [[[GSTheme theme] bundle] pathForResource: realName
ofType: o
inDirectory: @"ThemeImages"];
if (path != nil && [path length] != 0)
break;
}
}
}
/* If not found then search in system */
if (!path)
{