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
* the currently active theme by the +setTheme: method. Subclasses may
* 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>The base implementation handles setup and caching of certain image
* information and then sends a GSThemeDidActivateNotification to allow
* other parts of the GUI library to update themselves from the new theme.<br />
* <p>The base implementation handles setup and caching of the system color
* list and certain image information.<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
* userInfo dictionary will contain that list keyed on <em>Colors</em>.
* </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;

View file

@ -33,11 +33,13 @@
#include "Foundation/NSPathUtilities.h"
#include "Foundation/NSUserDefaults.h"
#include "GNUstepGUI/GSTheme.h"
#include "AppKit/NSApplication.h"
#include "AppKit/NSColor.h"
#include "AppKit/NSColorList.h"
#include "AppKit/NSGraphics.h"
#include "AppKit/NSImage.h"
#include "AppKit/NSView.h"
#include "AppKit/NSWindow.h"
#include "AppKit/NSBezierPath.h"
#include "AppKit/PSOperators.h"
@ -271,12 +273,15 @@ static NSNull *null = nil;
- (void) activate
{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
NSMutableDictionary *userInfo;
NSArray *imagePaths;
NSEnumerator *enumerator;
NSString *imagePath;
NSArray *imageTypes;
NSString *colorsPath;
NSWindow *window;
userInfo = [NSMutableDictionary dictionary];
colorsPath = [_bundle pathForResource: @"ThemeColors" ofType: @"clr"];
if (colorsPath != nil)
{
@ -296,30 +301,48 @@ static NSNull *null = nil;
* to memory, setting their names so that they are visible to
* [NSImage+imageNamed:] and storing them in our local array.
*/
imageTypes = [NSImage imageFileTypes];
imagePaths = [_bundle pathsForResourcesOfType: nil
inDirectory: @"ThemeImages"];
enumerator = [imagePaths objectEnumerator];
while ((imagePath = [enumerator nextObject]) != nil)
{
NSImage *image;
NSString *ext = [imagePath pathExtension];
image = [[NSImage alloc] initWithContentsOfFile: imagePath];
if (image != nil)
{
NSString *imageName;
if (ext != nil && [imageTypes containsObject: ext] == YES)
{
NSImage *image;
imageName = [imagePath lastPathComponent];
imageName = [imageName stringByDeletingPathExtension];
[_images addObject: image];
[image setName: imageName];
RELEASE(image);
image = [[NSImage alloc] initWithContentsOfFile: imagePath];
if (image != nil)
{
NSString *imageName;
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]
postNotificationName: GSThemeDidActivateNotification
object: self
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