Improve theme activation ... redisplay all windows

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/themes@23639 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-09-27 16:59:59 +00:00
parent 062fc1b21a
commit 7dae6bd29e
2 changed files with 42 additions and 15 deletions

View file

@ -228,14 +228,18 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification;
* <p>This method is called automatically when the receiver is made into * <p>This method is called automatically when the receiver is made into
* the currently active theme by the +setTheme: method. Subclasses may * the currently active theme by the +setTheme: method. Subclasses may
* override it to perform startup operations, but should call the super * override it to perform startup operations, but should call the super
* class implementation before doing their own thing. * class implementation after doing their own thing.
* </p> * </p>
* <p>The base implementation handles setup and caching of certain image * <p>The base implementation handles setup and caching of the system color
* information and then sends a GSThemeDidActivateNotification to allow * list and certain image information.<br />
* other parts of the GUI library to update themselves from the new theme.<br /> * It then sends a GSThemeDidActivateNotification to allow other
* parts of the GUI library to update themselves from the new theme.<br />
* If the theme sets an alternative system color list, the notification * If the theme sets an alternative system color list, the notification
* userInfo dictionary will contain that list keyed on <em>Colors</em>. * userInfo dictionary will contain that list keyed on <em>Colors</em>.
* </p> * </p>
* <p>Finally, this method marks all windows in the application as needing
* update ... so they will draw themselves with the new theme information.
* </p>
*/ */
- (void) activate; - (void) activate;

View file

@ -33,11 +33,13 @@
#include "Foundation/NSPathUtilities.h" #include "Foundation/NSPathUtilities.h"
#include "Foundation/NSUserDefaults.h" #include "Foundation/NSUserDefaults.h"
#include "GNUstepGUI/GSTheme.h" #include "GNUstepGUI/GSTheme.h"
#include "AppKit/NSApplication.h"
#include "AppKit/NSColor.h" #include "AppKit/NSColor.h"
#include "AppKit/NSColorList.h" #include "AppKit/NSColorList.h"
#include "AppKit/NSGraphics.h" #include "AppKit/NSGraphics.h"
#include "AppKit/NSImage.h" #include "AppKit/NSImage.h"
#include "AppKit/NSView.h" #include "AppKit/NSView.h"
#include "AppKit/NSWindow.h"
#include "AppKit/NSBezierPath.h" #include "AppKit/NSBezierPath.h"
#include "AppKit/PSOperators.h" #include "AppKit/PSOperators.h"
@ -271,12 +273,15 @@ static NSNull *null = nil;
- (void) activate - (void) activate
{ {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; NSMutableDictionary *userInfo;
NSArray *imagePaths; NSArray *imagePaths;
NSEnumerator *enumerator; NSEnumerator *enumerator;
NSString *imagePath; NSString *imagePath;
NSArray *imageTypes;
NSString *colorsPath; NSString *colorsPath;
NSWindow *window;
userInfo = [NSMutableDictionary dictionary];
colorsPath = [_bundle pathForResource: @"ThemeColors" ofType: @"clr"]; colorsPath = [_bundle pathForResource: @"ThemeColors" ofType: @"clr"];
if (colorsPath != nil) if (colorsPath != nil)
{ {
@ -296,30 +301,48 @@ static NSNull *null = nil;
* to memory, setting their names so that they are visible to * to memory, setting their names so that they are visible to
* [NSImage+imageNamed:] and storing them in our local array. * [NSImage+imageNamed:] and storing them in our local array.
*/ */
imageTypes = [NSImage imageFileTypes];
imagePaths = [_bundle pathsForResourcesOfType: nil imagePaths = [_bundle pathsForResourcesOfType: nil
inDirectory: @"ThemeImages"]; inDirectory: @"ThemeImages"];
enumerator = [imagePaths objectEnumerator]; enumerator = [imagePaths objectEnumerator];
while ((imagePath = [enumerator nextObject]) != nil) while ((imagePath = [enumerator nextObject]) != nil)
{ {
NSImage *image; NSString *ext = [imagePath pathExtension];
image = [[NSImage alloc] initWithContentsOfFile: imagePath]; if (ext != nil && [imageTypes containsObject: ext] == YES)
if (image != nil) {
{ NSImage *image;
NSString *imageName;
imageName = [imagePath lastPathComponent]; image = [[NSImage alloc] initWithContentsOfFile: imagePath];
imageName = [imageName stringByDeletingPathExtension]; if (image != nil)
[_images addObject: image]; {
[image setName: imageName]; NSString *imageName;
RELEASE(image);
imageName = [imagePath lastPathComponent];
imageName = [imageName stringByDeletingPathExtension];
[_images addObject: image];
[image setName: imageName];
RELEASE(image);
}
} }
} }
/*
* Tell all other classes that new theme information is present.
*/
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
postNotificationName: GSThemeDidActivateNotification postNotificationName: GSThemeDidActivateNotification
object: self object: self
userInfo: userInfo]; userInfo: userInfo];
/*
* Mark all windows as needing redisplaying to thos the new theme.
*/
enumerator = [[NSApp windows] objectEnumerator];
while ((window = [enumerator nextObject]) != nil)
{
[[[window contentView] superview] setNeedsDisplay: YES];
}
} }
- (NSBundle*) bundle - (NSBundle*) bundle