From 39fbad9a4214b25c005bb1c5dc3481e1993f1dde Mon Sep 17 00:00:00 2001
From: rfm
While many themes can be created without subclassing GSTheme,
there are some cases where writing code is necessary (most
- notably when interfacing to a native themeing engine for some
+ notably when interfacing to a native theming engine for some
platform in order to make a GNUstep app have a native look). 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, however, the method is not
- * really intended to be overridden, and subcasses should generally
+ * really intended to be overridden, and subclasses should generally
* handle activation work in response to the GSThemeWillActivatenotification
* posted by this method.
* Finally, this method marks all windows in the application as needing
* update ... so they will draw themselves with the new theme information.
* NB. If a GSTheme subclass is integrating to an external native themeing
+ * NB. If a GSTheme subclass is integrating to an external native theming
* mechanism in order to make GNUstep apps look like native apps, then the
* external theme may change dynamically and the GSTheme subclass may need
* to change the GNUstep application to reflect this change. When this
@@ -547,7 +547,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
* sends a GSThemeDidDeactivateNotification to allow other parts of the
* GUI library to update themselves.
* NB. If a GSTheme subclass is integrating to an external native themeing
+ * NB. If a GSTheme subclass is integrating to an external native theming
* mechanism in order to make GNUstep apps look like native apps, then the
* external theme may change dynamically and the GSTheme subclass may need
* to change the GNUstep application to reflect this change. When this
@@ -602,14 +602,14 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
* The code managing this object (if any) must be prepared to have the
- * content view of the window reparented into another window for display
+ * content view of the window re-parented into another window for display
* on screen.
* The returned color is used by
* -drawBackgroundForMenuView:withFrame:dirtyRect:horizontal: Can be overriden in subclasses to return a custom color. Can be overridden in subclasses to return a custom color. Can be overriden in subclasses to return a custom color. Can be overridden in subclasses to return a custom color. The returned color is used by
* -drawBackgroundForMenuView:withFrame:dirtyRect:horizontal: Can be overriden in subclasses to return a custom color. Can be overridden in subclasses to return a custom color. The returned edge color is used by
* -drawBackgroundForMenuView:withFrame:dirtyRect:horizontal: Can be overriden in subclasses to return a custom color per edge. Can be overridden in subclasses to return a custom color per edge. The returned value used by
* -drawBorderAndBackgroundForMenuItemCell:withFrame:inView:state:isHorizontal: Can be overriden in subclasses. Can be overridden in subclasses. Draws the menu item title. Can be overriden to customize the text font, size and position. Can be overridden to customize the text font, size and position. The title color is mapped to the theme state as described below: The returned color is used by
* -drawSeparatorItemForMenuItemCell:withFrame:inView:isHorizontal: Can be overriden in subclasses to return a custom color. Can be overridden in subclasses to return a custom color. The returned color is used by
* -drawSeparatorItemForMenuItemCell:withFrame:inView:isHorizontal: Can be overriden in subclasses to return a custom value. Can be overridden in subclasses to return a custom value. You can provide an image tile named GSMenuSeparatorItem to
* draw the separator.
- * Can be overriden in subclasses to customize the drawing.
In these cases the subclass should follow certain rules in order
to operate cleanly and efficiently:
@@ -160,17 +160,17 @@
with versions stored in the theme bundle.
If a subclass wishes to dynamically provide these resources rather
than supplying them as static information in the bundle, it may
- update the in-memory information after the normal opertation has
+ update the in-memory information after the normal operation has
taken place. This should be done by the theme registering itsself
as an observer of GSThemeWillActivateNotification and adding the
- resources just before the theme bocomes active.
+ resources just before the theme becomes active.
Cleanup may be done in response to a GSThemeWillDeactivateNotification
(called before the default cleanup) or a
GSThemeDidDeactivateNotification (called after the default cleanup).
* Supplying a nil value for aString simply removes any name setting for
@@ -673,13 +673,13 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
* and the authors of the theme.
*
* Passing nil for aName removes all named tiles.
* Passing a negative value for elementState applies to all caches.
@@ -699,7 +699,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
* The elementState argument specifies the state for which tiles are
* requested.
* See the -colorNamed:state: method for determining colors to be
- * used for drawing specific gui elements.
+ * used for drawing specific GUI elements.
*/
- (GSDrawTiles*) tilesNamed: (NSString*)aName
state: (GSThemeControlState)elementState;
@@ -715,7 +715,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
* Theme drawing methods.
* Methods which return information/resources are generally expected
* (ie unless explicitly documented otherwise) to be returning something
- * which persists until the mewthod is called again or until the current
+ * which persists until the method is called again or until the current
* theme is deactivated (whichever comes first).
* This means that drawing code should not need to
* retain/release any returned object (the theme is responsible for
@@ -822,7 +822,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
- (float) defaultScrollerWidth;
/**
- * Method fors toolbar theming.
+ * Method for toolbar theming.
*/
- (NSColor *) toolbarBackgroundColor;
- (NSColor *) toolbarBorderColor;
@@ -886,7 +886,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
*
+ *
* You can use [[cell menuItem] title]
to get the title.
See also -menuSeparatorColor and -menuSeparatorInset
*/ @@ -1140,7 +1140,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; inRect: (NSRect)border withClip: (NSRect)clip; -/** Draw a grey bezel border */ +/** Draw a gray bezel border */ - (NSRect) drawGrayBezel: (NSRect)border withClip: (NSRect)clip; /** Draw a groove border */ @@ -1155,7 +1155,7 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; @end /** - * Low level drawiong methods ... themes may use these for drawing, + * Low level drawing methods ... themes may use these for drawing, * but should not normally override them. */ @interface GSTheme (LowLevelDrawing) diff --git a/Source/GSTheme.m b/Source/GSTheme.m index 5189d2158..a709f0180 100644 --- a/Source/GSTheme.m +++ b/Source/GSTheme.m @@ -231,7 +231,6 @@ GSStringFromBorderType(NSBorderType borderType) @implementation GSTheme static GSTheme *defaultTheme = nil; -static NSString *currentThemeName = nil; static GSTheme *theTheme = nil; static NSMutableDictionary *themes = nil; static NSNull *null = nil; @@ -273,10 +272,17 @@ typedef struct { defs = [NSUserDefaults standardUserDefaults]; name = [defs stringForKey: @"GSTheme"]; - if (name != currentThemeName && [name isEqual: currentThemeName] == NO) + if (0 == [name length]) + { + name = @"GNUstep"; + } + else if ([[name pathExtension] isEqual: @"theme"]) + { + name = [name stringByDeletingPathExtension]; + } + if (NO == [[name lastPathComponent] isEqual: [theTheme name]]) { [self setTheme: [self loadThemeNamed: name]]; - ASSIGN(currentThemeName, name); // Don't try to load again. } } @@ -288,13 +294,12 @@ typedef struct { null = RETAIN([NSNull null]); defaultTheme = [[self alloc] initWithBundle: nil]; ASSIGN(theTheme, defaultTheme); - ASSIGN(currentThemeName, [defaultTheme name]); names = NSCreateMapTable(NSNonOwnedPointerMapKeyCallBacks, NSIntMapValueCallBacks, 0); + /* Establish the theme specified by the user defaults (if any); + */ + [self defaultsDidChange: nil]; } - /* Establish the theme specified by the user defaults (if any); - */ - [self defaultsDidChange: nil]; } + (GSTheme*) loadThemeNamed: (NSString*)aName @@ -304,7 +309,11 @@ typedef struct { GSTheme *instance; NSString *theme; - if ([aName length] == 0) + if ([[aName pathExtension] isEqual: @"theme"]) + { + aName = [aName stringByDeletingPathExtension]; + } + if ([aName length] == 0 || [[aName lastPathComponent] isEqual: @"GNUstep"]) { return defaultTheme; } @@ -316,21 +325,17 @@ typedef struct { else { aName = [aName lastPathComponent]; + } - /* Ensure that the theme name has the 'theme' extension. - */ - if ([[aName pathExtension] isEqualToString: @"theme"] == YES) - { - theme = aName; - } - else - { - theme = [aName stringByAppendingPathExtension: @"theme"]; - } - if ([theme isEqualToString: @"GNUstep.theme"] == YES) - { - return defaultTheme; - } + /* Ensure that the theme name has the 'theme' extension. + */ + if ([[aName pathExtension] isEqualToString: @"theme"] == YES) + { + theme = aName; + } + else + { + theme = [aName stringByAppendingPathExtension: @"theme"]; } bundle = [themes objectForKey: theme]; @@ -415,10 +420,8 @@ typedef struct { removeObserver: self]; [theTheme deactivate]; - DESTROY(currentThemeName); ASSIGN (theTheme, theme); [theTheme activate]; - ASSIGN(currentThemeName, [theTheme name]); /* * Listen to notifications...