mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Fix typo in method to set parent window of a child, optimise color handling in themes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27742 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
52de0f2703
commit
774a9ec1d4
8 changed files with 137 additions and 94 deletions
10
ChangeLog
10
ChangeLog
|
@ -1,3 +1,13 @@
|
|||
2009-01-31 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSDisplayServer.m: Fix typo
|
||||
* Headers/Additions/GNUstepGUI/GSDisplayServer.h: ditto
|
||||
* Source/NSWindow.m: ditto
|
||||
* Source/GSTheme.m: Make color handling more efficient
|
||||
* Headers/Additions/GNUstepGUI/GSTheme.h: ditto
|
||||
* Source/GSThemeDrawing.m: ditto
|
||||
* Source/NSScrollView.m: ditto
|
||||
|
||||
2009-01-31 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/GSToolTips.m: Fix retain/release problem.
|
||||
|
|
|
@ -162,8 +162,8 @@ APPKIT_EXPORT NSString * GSScreenNumber;
|
|||
- (void) imagecursor: (NSPoint)hotp : (int)w : (int)h : (int)colors
|
||||
: (const unsigned char *) image : (void**)cid;
|
||||
- (void) setcursorcolor: (NSColor *)fg : (NSColor *)bg : (void*)cid;
|
||||
- (void) setPartentWindow: (int)partentWin
|
||||
forChildWindow: (int)childWin;
|
||||
- (void) setParentWindow: (int)parentWin
|
||||
forChildWindow: (int)childWin;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -187,11 +187,13 @@ typedef enum {
|
|||
* This enumeration provides constants for informing drawing methods
|
||||
* what state a control is in (and consequently how the display element
|
||||
* being drawn should be presented).
|
||||
* NB. GSThemeNormalState must be 0 and GSThemeSelectedState must be the
|
||||
* last state, in order to allow code to iterate through all the states.
|
||||
*/
|
||||
typedef enum {
|
||||
GSThemeNormalState, /** A control in its normal state */
|
||||
GSThemeNormalState = 0, /** A control in its normal state */
|
||||
GSThemeHighlightedState, /** A control which is highlighted */
|
||||
GSThemeSelectedState, /** A control which is selected */
|
||||
GSThemeSelectedState /** A control which is selected */
|
||||
} GSThemeControlState;
|
||||
|
||||
/** Notification sent when a theme has just become active.<br />
|
||||
|
@ -316,6 +318,18 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
|
|||
*/
|
||||
- (NSBundle*) bundle;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* for the particular combination of item name and state, the method
|
||||
* returns nil.<br />
|
||||
* The useCache argument controls whether the information is retrieved
|
||||
* from cache or regenerated from information in the theme bundle.
|
||||
*/
|
||||
- (NSColor*) colorNamed: (NSString*)aName
|
||||
state: (GSThemeControlState)elementState
|
||||
cache: (BOOL)useCache;
|
||||
|
||||
/**
|
||||
* Returns the system color list defined by the receiver.<br />
|
||||
* The default implementation returns the color list provided in the
|
||||
|
@ -337,15 +351,6 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
|
|||
*/
|
||||
- (void) deactivate;
|
||||
|
||||
/**
|
||||
* Returns the extra color list defined by the receiver.<br />
|
||||
* This is a set of named colors to be used for particular parts of the
|
||||
* gui which have been named by the -setName:forElement:temporary:
|
||||
* method. The presence of a color in this list may override the default
|
||||
* system color for a control.
|
||||
*/
|
||||
- (NSColorList*) extraColors;
|
||||
|
||||
/**
|
||||
* Returns the theme's icon.
|
||||
*/
|
||||
|
|
|
@ -896,8 +896,8 @@ GSCurrentServer(void)
|
|||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
||||
- (void) setPartentWindow: (int)partentWin
|
||||
forChildWindow: (int)childWin
|
||||
- (void) setParentWindow: (int)partentWin
|
||||
forChildWindow: (int)childWin
|
||||
{
|
||||
[self subclassResponsibility: _cmd];
|
||||
}
|
||||
|
|
146
Source/GSTheme.m
146
Source/GSTheme.m
|
@ -92,11 +92,9 @@ static NSMapTable *names = 0;
|
|||
typedef struct {
|
||||
NSBundle *bundle;
|
||||
NSColorList *colors;
|
||||
NSColorList *extraColors;
|
||||
NSColorList *extraColors[GSThemeSelectedState+1];
|
||||
NSMutableDictionary *images;
|
||||
NSMutableDictionary *normalTiles;
|
||||
NSMutableDictionary *highlightedTiles;
|
||||
NSMutableDictionary *selectedTiles;
|
||||
NSMutableDictionary *tiles[GSThemeSelectedState+1];
|
||||
NSMutableSet *owned;
|
||||
NSImage *icon;
|
||||
NSString *name;
|
||||
|
@ -107,9 +105,7 @@ typedef struct {
|
|||
#define _colors _internal->colors
|
||||
#define _extraColors _internal->extraColors
|
||||
#define _images _internal->images
|
||||
#define _normalTiles _internal->normalTiles
|
||||
#define _highlightedTiles _internal->highlightedTiles
|
||||
#define _selectedTiles _internal->selectedTiles
|
||||
#define _tiles _internal->tiles
|
||||
#define _owned _internal->owned
|
||||
#define _icon _internal->icon
|
||||
#define _name _internal->name
|
||||
|
@ -283,13 +279,17 @@ typedef struct {
|
|||
NSArray *imageTypes;
|
||||
NSDictionary *infoDict;
|
||||
NSWindow *window;
|
||||
|
||||
GSThemeControlState state;
|
||||
|
||||
/* Get rid of any cached colors list so that we regenerate it when needed
|
||||
*/
|
||||
[_colors release];
|
||||
_colors = nil;
|
||||
[_extraColors release];
|
||||
_extraColors = nil;
|
||||
for (state = 0; state <= GSThemeSelectedState; state++)
|
||||
{
|
||||
[_extraColors[state] release];
|
||||
_extraColors[state] = nil;
|
||||
}
|
||||
|
||||
/*
|
||||
* We step through all the bundle image resources and load them in
|
||||
|
@ -434,6 +434,72 @@ typedef struct {
|
|||
return _bundle;
|
||||
}
|
||||
|
||||
- (NSColor*) colorNamed: (NSString*)aName
|
||||
state: (GSThemeControlState)elementState
|
||||
cache: (BOOL)useCache
|
||||
{
|
||||
NSColor *c = nil;
|
||||
|
||||
NSAssert(elementState <= GSThemeSelectedState, NSInvalidArgumentException);
|
||||
|
||||
if (aName != nil)
|
||||
{
|
||||
if (useCache == NO)
|
||||
{
|
||||
[_extraColors[elementState] release];
|
||||
_extraColors[elementState] = nil;
|
||||
}
|
||||
if (_extraColors[elementState] == nil)
|
||||
{
|
||||
NSString *colorsPath;
|
||||
NSString *listName;
|
||||
NSString *resourceName;
|
||||
|
||||
/* Attempt to load color list ... if the list is not found
|
||||
* or the load fails, set a null marker.
|
||||
*/
|
||||
switch (elementState)
|
||||
{
|
||||
case GSThemeNormalState:
|
||||
listName = @"ThemeExtra";
|
||||
break;
|
||||
case GSThemeHighlightedState:
|
||||
listName = @"ThemeExtraHighlighted";
|
||||
break;
|
||||
case GSThemeSelectedState:
|
||||
listName = @"ThemeExtraSelected";
|
||||
break;
|
||||
}
|
||||
resourceName = [listName stringByAppendingString: @"Colors"];
|
||||
colorsPath = [_bundle pathForResource: resourceName
|
||||
ofType: @"clr"];
|
||||
if (colorsPath != nil)
|
||||
{
|
||||
_extraColors[elementState]
|
||||
= [[NSColorList alloc] initWithName: listName
|
||||
fromFile: colorsPath];
|
||||
/* If the list is actually empty, we get rid of it to avoid
|
||||
* unnecessary lookups.
|
||||
*/
|
||||
if ([[_extraColors[elementState] allKeys] count] == 0)
|
||||
{
|
||||
[_extraColors[elementState] release];
|
||||
_extraColors[elementState] = nil;
|
||||
}
|
||||
}
|
||||
if (_extraColors[elementState] == nil)
|
||||
{
|
||||
_extraColors[elementState] = [null retain];
|
||||
}
|
||||
}
|
||||
if (_extraColors[elementState] != (id)null)
|
||||
{
|
||||
c = [_extraColors[elementState] colorWithKey: aName];
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
- (NSColorList*) colors
|
||||
{
|
||||
if (_colors == nil)
|
||||
|
@ -497,13 +563,16 @@ typedef struct {
|
|||
{
|
||||
if (_reserved != 0)
|
||||
{
|
||||
GSThemeControlState state;
|
||||
|
||||
for (state = 0; state <= GSThemeSelectedState; state++)
|
||||
{
|
||||
RELEASE(_extraColors[state]);
|
||||
RELEASE(_tiles[state]);
|
||||
}
|
||||
RELEASE(_bundle);
|
||||
RELEASE(_colors);
|
||||
RELEASE(_extraColors);
|
||||
RELEASE(_images);
|
||||
RELEASE(_normalTiles);
|
||||
RELEASE(_highlightedTiles);
|
||||
RELEASE(_selectedTiles);
|
||||
RELEASE(_icon);
|
||||
[self _revokeOwnerships];
|
||||
RELEASE(_owned);
|
||||
|
@ -512,31 +581,6 @@ typedef struct {
|
|||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSColorList*) extraColors
|
||||
{
|
||||
if (_extraColors == nil)
|
||||
{
|
||||
NSString *colorsPath;
|
||||
|
||||
colorsPath = [_bundle pathForResource: @"ThemeExtraColors"
|
||||
ofType: @"clr"];
|
||||
if (colorsPath == nil)
|
||||
{
|
||||
_extraColors = [null retain];
|
||||
}
|
||||
else
|
||||
{
|
||||
_extraColors = [[NSColorList alloc] initWithName: @"ThemeExtra"
|
||||
fromFile: colorsPath];
|
||||
}
|
||||
}
|
||||
if ((id)_extraColors == (id)null)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
return _extraColors;
|
||||
}
|
||||
|
||||
- (NSImage*) icon
|
||||
{
|
||||
if (_icon == nil)
|
||||
|
@ -565,13 +609,16 @@ typedef struct {
|
|||
|
||||
- (id) initWithBundle: (NSBundle*)bundle
|
||||
{
|
||||
GSThemeControlState state;
|
||||
|
||||
_reserved = NSZoneCalloc ([self zone], 1, sizeof(internal));
|
||||
|
||||
ASSIGN(_bundle, bundle);
|
||||
_images = [NSMutableDictionary new];
|
||||
_normalTiles = [NSMutableDictionary new];
|
||||
_highlightedTiles = [NSMutableDictionary new];
|
||||
_selectedTiles = [NSMutableDictionary new];
|
||||
for (state = 0; state <= GSThemeSelectedState; state++)
|
||||
{
|
||||
_tiles[state] = [NSMutableDictionary new];
|
||||
}
|
||||
_owned = [NSMutableSet new];
|
||||
|
||||
ASSIGN(_name,
|
||||
|
@ -654,23 +701,12 @@ typedef struct {
|
|||
GSDrawTiles *tiles;
|
||||
NSMutableDictionary *cache;
|
||||
|
||||
NSAssert(elementState <= GSThemeSelectedState, NSInvalidArgumentException);
|
||||
if (aName == nil)
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
switch (elementState)
|
||||
{
|
||||
case GSThemeNormalState:
|
||||
cache = _normalTiles;
|
||||
break;
|
||||
case GSThemeHighlightedState:
|
||||
cache = _highlightedTiles;
|
||||
break;
|
||||
case GSThemeSelectedState:
|
||||
cache = _selectedTiles;
|
||||
break;
|
||||
}
|
||||
|
||||
cache = _tiles[elementState];
|
||||
tiles = (useCache == YES) ? [cache objectForKey: aName] : nil;
|
||||
if (tiles == nil)
|
||||
{
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
{
|
||||
GSDrawTiles *tiles = nil;
|
||||
NSColor *color = nil;
|
||||
NSColorList *extra = [self extraColors];
|
||||
NSString *name = [self nameForElement: cell];
|
||||
|
||||
if (name == nil)
|
||||
|
@ -50,28 +49,18 @@
|
|||
name = @"NSButton";
|
||||
}
|
||||
|
||||
if (state == GSThemeNormalState)
|
||||
color = [self colorNamed: name state: state cache: YES];
|
||||
if (color == nil)
|
||||
{
|
||||
color = [extra colorWithKey: name];
|
||||
if (color == nil)
|
||||
if (state == GSThemeNormalState)
|
||||
{
|
||||
color = [NSColor controlBackgroundColor];
|
||||
}
|
||||
}
|
||||
else if (state == GSThemeHighlightedState)
|
||||
{
|
||||
color = [extra colorWithKey:
|
||||
[name stringByAppendingString: @"Highlighted"]];
|
||||
if (color == nil)
|
||||
else if (state == GSThemeHighlightedState)
|
||||
{
|
||||
color = [NSColor selectedControlColor];
|
||||
}
|
||||
}
|
||||
else if (state == GSThemeSelectedState)
|
||||
{
|
||||
color = [extra colorWithKey:
|
||||
[name stringByAppendingString: @"Selected"]];
|
||||
if (color == nil)
|
||||
else if (state == GSThemeSelectedState)
|
||||
{
|
||||
color = [NSColor selectedControlColor];
|
||||
}
|
||||
|
@ -371,7 +360,6 @@
|
|||
- (NSCell*) cellForScrollerKnobSlot: (BOOL)horizontal
|
||||
{
|
||||
NSButtonCell *cell;
|
||||
NSColorList *extra = [self extraColors];
|
||||
NSColor *color;
|
||||
|
||||
cell = [NSButtonCell new];
|
||||
|
@ -380,12 +368,16 @@
|
|||
|
||||
if (horizontal)
|
||||
{
|
||||
color = [extra colorWithKey: GSScrollerHorizontalSlot];
|
||||
color = [self colorNamed: GSScrollerHorizontalSlot
|
||||
state: GSThemeNormalState
|
||||
cache: YES];
|
||||
[self setName: GSScrollerHorizontalSlot forElement: cell temporary: YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
color = [extra colorWithKey: GSScrollerVerticalSlot];
|
||||
color = [self colorNamed: GSScrollerVerticalSlot
|
||||
state: GSThemeNormalState
|
||||
cache: YES];
|
||||
[self setName: GSScrollerVerticalSlot forElement: cell temporary: YES];
|
||||
}
|
||||
if (color == nil)
|
||||
|
|
|
@ -1126,7 +1126,7 @@ static float scrollerWidth;
|
|||
{
|
||||
name = @"NSScrollView";
|
||||
}
|
||||
color = [[theme extraColors] colorWithKey: name];
|
||||
color = [theme colorNamed: name state: GSThemeNormalState cache: YES];
|
||||
if (color == nil)
|
||||
{
|
||||
color = [NSColor controlDarkShadowColor];
|
||||
|
|
|
@ -857,8 +857,8 @@ many times.
|
|||
: [_screen screenNumber]];
|
||||
[srv setwindowlevel: [self level] : _windowNum];
|
||||
if (_parent != nil)
|
||||
[srv setPartentWindow: [_parent windowNumber]
|
||||
forChildWindow: _windowNum];
|
||||
[srv setParentWindow: [_parent windowNumber]
|
||||
forChildWindow: _windowNum];
|
||||
|
||||
// Set up context
|
||||
[self _startBackendWindow];
|
||||
|
@ -4748,8 +4748,8 @@ current key view.<br />
|
|||
|
||||
if (_windowNum)
|
||||
{
|
||||
[GSServerForWindow(self) setPartentWindow: [_parent windowNumber]
|
||||
forChildWindow: _windowNum];
|
||||
[GSServerForWindow(self) setParentWindow: [_parent windowNumber]
|
||||
forChildWindow: _windowNum];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue