From e9014759834861c7e8618df3c77a3fd3e5728573 Mon Sep 17 00:00:00 2001 From: rfm Date: Thu, 19 Nov 2009 20:37:43 +0000 Subject: [PATCH] api cleanup git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29039 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++ Headers/Additions/GNUstepGUI/GSTheme.h | 35 +++++---- Source/GSTheme.m | 102 +++++++++++++++++++++---- Source/GSThemeDrawing.m | 18 ++--- Source/NSMenuItemCell.m | 2 +- Source/NSScrollView.m | 2 +- 6 files changed, 129 insertions(+), 39 deletions(-) diff --git a/ChangeLog b/ChangeLog index 64c2d8c51..2a2157869 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2009-11-19 Richard Frith-Macdonald + + * Source/GSTheme.m: + * Source/NSMenuItemCell.m: + * Source/GSThemeDrawing.m: + * Source/NSScrollView.m: + * Headers/Additions/GNUstepGUI/GSTheme.h: + Separate cache control from normal fetching of tiles and colors. + 2009-11-19 Richard Frith-Macdonald * Headers/Additions/GNUstepGUI/GSTheme.h: diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index 185d636c0..24efd7251 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -458,6 +458,14 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; */ - (Class) colorClass; +/** Removes the name from the color cache forcing it to be re-created next + * time the named color is required.
+ * Passing nil for aName removes all named colors.
+ * Passing a negative value for elementState applies to all caches. + */ +- (void) colorFlush: (NSString*)aName + state: (GSThemeControlState)elementState; + /** * This returns the color for drawing the item whose name is aName in * the specified state. If aName is nil or if there is no color defined @@ -465,14 +473,10 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; * returns nil.
* The standard names used for the parts of various controls are declared * in GSTheme.h
- * See also the -tilesNamed:state:cache: method.
- * The useCache argument controls whether the information is retrieved - * from cache or regenerated from information in the theme bundle, and - * should normally be YES. + * See also the -tilesNamed:state: method. */ - (NSColor*) colorNamed: (NSString*)aName - state: (GSThemeControlState)elementState - cache: (BOOL)useCache; + state: (GSThemeControlState)elementState; /** * Returns the system color list defined by the receiver.
@@ -611,6 +615,14 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; */ - (NSWindow*) themeInspector; +/** Removes the name tile images from cahce, forcing re-creation next + * time the named tiles are required.
+ * Passing nil for aName removes all named tiles.
+ * Passing a negative value for elementState applies to all caches. + */ +- (void) tilesFlush: (NSString*)aName + state: (GSThemeControlState)elementState; + /** * Returns the tile image information for a particular image name, * or nil if there is no such information or the name is nil.
@@ -621,16 +633,13 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; * returned by this method can be passed to the * -fillRect:withTiles:background:fillStyle: method.
* The elementState argument specifies the state for which tiles are - * requested.
- * The useCache argument controls whether the information is retrieved - * from cache or regenerated from information in the theme bundle, and - * should normally be YES.
- * See the -colorNamed:state:cache: method for determining colors to be + * requested. + * See the -colorNamed:state: method for determining colors to be * used for drawing specific gui elements. */ - (GSDrawTiles*) tilesNamed: (NSString*)aName - state: (GSThemeControlState)elementState - cache: (BOOL)useCache; + state: (GSThemeControlState)elementState; + /** * Return the theme's version string. */ diff --git a/Source/GSTheme.m b/Source/GSTheme.m index 9b8745a5d..10e4a6678 100644 --- a/Source/GSTheme.m +++ b/Source/GSTheme.m @@ -37,6 +37,7 @@ #import #import #import +#import "GNUstepBase/GSObjCRuntime.h" #import "GNUstepGUI/GSTheme.h" #import "AppKit/NSApplication.h" #import "AppKit/NSButton.h" @@ -421,11 +422,6 @@ typedef struct { } } - /* - * We could cache tile info here, but it's probably better for the - * tilesNamed:state:cache: method to do it lazily. - */ - /* * Use the GSThemeDomain key in the info dictionary of the theme to * set a defaults domain which will establish user defaults values @@ -517,21 +513,44 @@ typedef struct { return [NSColorList class]; } +- (void) colorFlush: (NSString*)aName + state: (GSThemeControlState)elementState +{ + int pos; + int end; + + NSAssert(elementState <= GSThemeSelectedState, NSInvalidArgumentException); + if (elementState < 0) + { + pos = 0; + end = GSThemeSelectedState; + } + else + { + pos = elementState; + end = elementState; + } + while (pos <= end) + { + if (_extraColors[pos] != nil) + { + [_extraColors[pos] release]; + _extraColors[pos] = nil; + } + pos++; + } +} + - (NSColor*) colorNamed: (NSString*)aName state: (GSThemeControlState)elementState - cache: (BOOL)useCache { NSColor *c = nil; NSAssert(elementState <= GSThemeSelectedState, NSInvalidArgumentException); + NSAssert(elementState >= 0, NSInvalidArgumentException); if (aName != nil) { - if (useCache == NO) - { - [_extraColors[elementState] release]; - _extraColors[elementState] = nil; - } if (_extraColors[elementState] == nil) { NSString *colorsPath; @@ -754,6 +773,29 @@ typedef struct { return [_bundle infoDictionary]; } +- (void) mapMethod: (SEL)src toMethod: (SEL)dst ofClass: (Class)c +{ + GSMethod method; + BOOL instance = YES; + + method = GSGetMethod([self class], src, instance, NO); + if (method == 0) + { + instance = NO; + method = GSGetMethod([self class], src, instance, NO); + } + if (method != 0) + { + GSMethodList list; + + list = GSAllocMethodList(1); + GSAppendMethodToList(list, + dst, method->method_types, method->method_imp, YES); + GSAddMethodList(c, list, instance); + GSFlushMethodCacheForClass(c); + } +} + - (NSString*) name { if (self == defaultTheme) @@ -820,20 +862,53 @@ typedef struct { return [GSThemeInspector sharedThemeInspector]; } +- (void) tilesFlush: (NSString*)aName + state: (GSThemeControlState)elementState +{ + int pos; + int end; + + NSAssert(elementState <= GSThemeSelectedState, NSInvalidArgumentException); + if (elementState < 0) + { + pos = 0; + end = GSThemeSelectedState; + } + else + { + pos = elementState; + end = elementState; + } + while (pos <= end) + { + NSMutableDictionary *cache; + + cache = _tiles[pos++]; + if (aName == nil) + { + return [cache removeAllObjects]; + } + else + { + [cache removeObjectForKey: aName]; + } + } +} + - (GSDrawTiles*) tilesNamed: (NSString*)aName state: (GSThemeControlState)elementState - cache: (BOOL)useCache { GSDrawTiles *tiles; NSMutableDictionary *cache; NSAssert(elementState <= GSThemeSelectedState, NSInvalidArgumentException); + NSAssert(elementState >= 0, NSInvalidArgumentException); if (aName == nil) { return nil; } cache = _tiles[elementState]; - tiles = (useCache == YES) ? [cache objectForKey: aName] : nil; + tiles = [cache objectForKey: aName]; if (tiles == nil) { NSDictionary *info; @@ -959,6 +1034,7 @@ typedef struct { { return [[self infoDictionary] objectForKey: @"GSThemeVersion"]; } + @end @implementation GSTheme (Private) diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 48bd8fe8d..873a2659a 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -64,7 +64,7 @@ name = @"NSButton"; } - color = [self colorNamed: name state: state cache: YES]; + color = [self colorNamed: name state: state]; if (color == nil) { if (state == GSThemeNormalState) @@ -81,7 +81,7 @@ } } - tiles = [self tilesNamed: name state: state cache: YES]; + tiles = [self tilesNamed: name state: state]; if (tiles == nil) { switch (style) @@ -159,7 +159,7 @@ name = @"NSButton"; } - tiles = [self tilesNamed: name state: state cache: YES]; + tiles = [self tilesNamed: name state: state]; if (tiles == nil) { switch (style) @@ -385,15 +385,13 @@ if (horizontal) { color = [self colorNamed: GSScrollerHorizontalSlot - state: GSThemeNormalState - cache: YES]; + state: GSThemeNormalState]; [self setName: GSScrollerHorizontalSlot forElement: cell temporary: YES]; } else { color = [self colorNamed: GSScrollerVerticalSlot - state: GSThemeNormalState - cache: YES]; + state: GSThemeNormalState]; [self setName: GSScrollerVerticalSlot forElement: cell temporary: YES]; } if (color == nil) @@ -415,8 +413,7 @@ NSColor *color; color = [self colorNamed: @"toolbarBackgroundColor" - state: GSThemeNormalState - cache: YES]; + state: GSThemeNormalState]; if (color == nil) { color = [NSColor clearColor]; @@ -429,8 +426,7 @@ NSColor *color; color = [self colorNamed: @"toolbarBorderColor" - state: GSThemeNormalState - cache: YES]; + state: GSThemeNormalState]; if (color == nil) { color = [NSColor grayColor]; diff --git a/Source/NSMenuItemCell.m b/Source/NSMenuItemCell.m index 423f01b4e..53f3c3ea6 100644 --- a/Source/NSMenuItemCell.m +++ b/Source/NSMenuItemCell.m @@ -131,7 +131,7 @@ state = GSThemeSelectedState; } - color = [[GSTheme theme] colorNamed: @"NSMenuItem" state: state cache: YES]; + color = [[GSTheme theme] colorNamed: @"NSMenuItem" state: state]; if (color == nil) { if ((state == GSThemeHighlightedState) || (state == GSThemeSelectedState)) diff --git a/Source/NSScrollView.m b/Source/NSScrollView.m index 3816752af..6f3cdfd4d 100644 --- a/Source/NSScrollView.m +++ b/Source/NSScrollView.m @@ -1154,7 +1154,7 @@ static float scrollerWidth; { name = @"NSScrollView"; } - color = [theme colorNamed: name state: GSThemeNormalState cache: YES]; + color = [theme colorNamed: name state: GSThemeNormalState]; if (color == nil) { color = [NSColor controlDarkShadowColor];