Extract a few more drawing and colour methods to GSTheme.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@28937 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2009-11-02 11:48:22 +00:00
parent b5fc9e025d
commit eecdf96f4b
6 changed files with 161 additions and 106 deletions

View file

@ -1,3 +1,12 @@
2009-11-02 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSTheme.m: Remove some compiler warnings.
* Source/NSMenuItemCell.m,
* Source/GSToolbarView.m,
* Source/GSThemeDrawing.m,
* Headers/Additions/GNUstepGUI/GSTheme.h: New theme methods for
toolbar and menu item drawing.
2009-11-01 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSImage.m: Switch to the new shared composite and

View file

@ -585,11 +585,14 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
- (float) defaultScrollerWidth;
/**
* Method for toolbar theming.
* Method fors toolbar theming.
*/
- (NSColor *) toolbarBackgroundColor;
- (NSColor *) toolbarBorderColor;
- (void) drawToolbarRect: (NSRect)aRect
frame: (NSRect)viewFrame
borderMask: (unsigned int)borderMask;
- (BOOL) toolbarIsOpaque;
// Methods to deal with steppers..
/**
@ -623,6 +626,15 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification;
withFrame: (NSRect) aRect
position: (NSPoint) position;
// menu item cell drawing methods
- (NSColor *) backgroundColorForMenuItemCell: (NSMenuItemCell *)cell
state: (GSThemeControlState)state;
- (void) drawBorderAndBackgroundForMenuItemCell: (NSMenuItemCell *)cell
withFrame: (NSRect)cellFrame
inView: (NSView *)controlView
state: (GSThemeControlState)state
isHorizontal: (BOOL)isHorizontal;
- (float) titlebarHeight;
- (float) resizebarHeight;

View file

@ -243,7 +243,7 @@ typedef struct {
bundle = [themes objectForKey: theme];
if (bundle == nil)
{
NSString *path;
NSString *path = nil;
NSFileManager *mgr = [NSFileManager defaultManager];
BOOL isDir;
@ -543,6 +543,7 @@ typedef struct {
*/
switch (elementState)
{
default:
case GSThemeNormalState:
listName = @"ThemeExtra";
break;
@ -841,6 +842,7 @@ typedef struct {
switch (elementState)
{
default:
case GSThemeNormalState:
fullName = aName;
break;

View file

@ -402,16 +402,44 @@
return 18.0;
}
- (NSColor *) toolbarBackgroundColor
{
NSColor *color;
color = [self colorNamed: @"toolbarBackgroundColor"
state: GSThemeNormalState
cache: YES];
if (color == nil)
{
color = [NSColor clearColor];
}
return color;
}
- (NSColor *) toolbarBorderColor
{
NSColor *color;
color = [self colorNamed: @"toolbarBorderColor"
state: GSThemeNormalState
cache: YES];
if (color == nil)
{
color = [NSColor grayColor];
}
return color;
}
- (void) drawToolbarRect: (NSRect)aRect
frame: (NSRect)viewFrame
borderMask: (unsigned int)borderMask
{
// We draw the background
[[NSColor toolbarBackgroundColor] set];
[[self toolbarBackgroundColor] set];
[NSBezierPath fillRect: aRect];
// We draw the border
[[NSColor toolbarBorderColor] set];
[[self toolbarBorderColor] set];
if (borderMask & GSToolbarViewBottomBorder)
{
[NSBezierPath strokeLineFromPoint: NSMakePoint(0, 0.5)
@ -437,6 +465,18 @@
}
}
- (BOOL) toolbarIsOpaque
{
if ([[self toolbarBackgroundColor] alphaComponent] < 1.0)
{
return NO;
}
else
{
return YES;
}
}
- (NSRect) drawStepperLightButton: (NSRect) border :(NSRect) clip
{
/*
@ -566,6 +606,56 @@
}
}
// menu item cell drawing methods
- (NSColor *) backgroundColorForMenuItemCell: (NSMenuItemCell *)cell
state: (GSThemeControlState)state
{
if ((state == GSThemeHighlightedState) || (state == GSThemeSelectedState))
{
return [NSColor selectedMenuItemColor];
}
else
{
return [NSColor controlBackgroundColor];
}
}
- (void) drawBorderAndBackgroundForMenuItemCell: (NSMenuItemCell *)cell
withFrame: (NSRect)cellFrame
inView: (NSView *)controlView
state: (GSThemeControlState)state
isHorizontal: (BOOL)isHorizontal
{
NSColor *backgroundColor = [self backgroundColorForMenuItemCell: cell
state: state];
if (isHorizontal)
{
cellFrame = [cell drawingRectForBounds: cellFrame];
[backgroundColor set];
NSRectFill(cellFrame);
return;
}
// Set cell's background color
[backgroundColor set];
NSRectFill(cellFrame);
if (![cell isBordered])
return;
if (state == GSThemeSelectedState)
{
[self drawGrayBezel: cellFrame withClip: NSZeroRect];
}
else
{
[self drawButton: cellFrame withClip: NSZeroRect];
}
}
// Window decoration drawing methods
/* These include the black border. */
#define TITLE_HEIGHT 23.0
#define RESIZE_HEIGHT 9.0

View file

@ -38,7 +38,6 @@
#include "AppKit/NSButton.h"
#include "AppKit/NSClipView.h"
#include "AppKit/NSColor.h"
#include "AppKit/NSColorList.h"
#include "AppKit/NSDragging.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSImage.h"
@ -64,73 +63,6 @@ static const int ClippedItemsViewWidth = 28;
// Internal
static const int current_version = 1;
static NSColorList *SystemExtensionsColors;
// Toolbar color extensions
static void initSystemExtensionsColors(void)
{
NSColor *toolbarBackgroundColor;
NSColor *toolbarBorderColor;
NSDictionary *colors;
/* Set up a dictionary containing the names of all the system extensions
colours as keys and with colours as values. */
toolbarBorderColor = [NSColor colorWithCalibratedRed: 0.5
green: 0.5
blue: 0.5
alpha: 1.0];
// Window background color by tranparency
toolbarBackgroundColor = [NSColor clearColor];
colors = [[NSDictionary alloc] initWithObjectsAndKeys:
toolbarBackgroundColor, @"toolbarBackgroundColor",
toolbarBorderColor, @"toolbarBorderColor", nil];
SystemExtensionsColors = [NSColorList colorListNamed: @"System extensions"];
if (SystemExtensionsColors == nil)
{
SystemExtensionsColors = [[NSColorList alloc] initWithName: @"System extensions"];
}
{
NSEnumerator *e;
NSString *colorKey;
NSColor *color;
BOOL changed = NO;
// Set up default system extensions colors
e = [colors keyEnumerator];
while ((colorKey = (NSString *)[e nextObject]))
{
if ([SystemExtensionsColors colorWithKey: colorKey])
continue;
color = [colors objectForKey: colorKey];
[SystemExtensionsColors setColor: color forKey: colorKey];
changed = YES;
}
if (changed)
[SystemExtensionsColors writeToFile: nil];
}
}
@implementation NSColor (GSToolbarViewAdditions)
+ (NSColor *) toolbarBackgroundColor
{
return [SystemExtensionsColors colorWithKey: @"toolbarBackgroundColor"];
}
+ (NSColor *) toolbarBorderColor
{
return [SystemExtensionsColors colorWithKey: @"toolbarBorderColor"];
}
@end
/*
* Toolbar related code
@ -269,7 +201,8 @@ static void initSystemExtensionsColors(void)
+ (void) initialize
{
if (self == [GSToolbarView class])
initSystemExtensionsColors();
{
}
}
- (id) initWithFrame: (NSRect)frame
@ -438,14 +371,7 @@ static void initSystemExtensionsColors(void)
- (BOOL) isOpaque
{
if ([[NSColor toolbarBackgroundColor] alphaComponent] < 1.0)
{
return NO;
}
else
{
return YES;
}
return [[GSTheme theme] toolbarIsOpaque];
}
- (void) windowDidResize: (NSNotification *)notification

View file

@ -108,8 +108,8 @@ static NSImage *arrowImage = nil; /* Cache arrow image. */
- (NSColor *) backgroundColor
{
NSColor *backgroundColor = nil;
unsigned mask;
GSThemeControlState menuState = GSThemeNormalState;
if (_cell.is_highlighted)
{
@ -126,14 +126,16 @@ static NSImage *arrowImage = nil; /* Cache arrow image. */
// Determine the background color
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
{
backgroundColor = [NSColor selectedMenuItemColor];
menuState = GSThemeHighlightedState;
}
// TODO: Should we also check the ivar _backgroundColor?
if (backgroundColor == nil)
backgroundColor = [NSColor controlBackgroundColor];
return backgroundColor;
if (mask & NSPushInCellMask)
{
menuState = GSThemeSelectedState;
}
return [[GSTheme theme] backgroundColorForMenuItemCell: self
state: menuState];
}
- (void) setMenuItem: (NSMenuItem *)item
@ -608,29 +610,43 @@ static NSImage *arrowImage = nil; /* Cache arrow image. */
- (void) drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView
{
if ([_menuView isHorizontal] == YES)
unsigned mask;
GSThemeControlState menuState = GSThemeNormalState;
// set the mask
if (_cell.is_highlighted)
{
cellFrame = [self drawingRectForBounds: cellFrame];
[[self backgroundColor] set];
NSRectFill(cellFrame);
return;
}
// Set cell's background color
[[self backgroundColor] set];
NSRectFill(cellFrame);
if (!_cell.is_bordered)
return;
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
{
[[GSTheme theme] drawGrayBezel: cellFrame withClip: NSZeroRect];
mask = _highlightsByMask;
if (_cell.state)
{
mask &= ~_showAltStateMask;
}
}
else if (_cell.state)
mask = _showAltStateMask;
else
mask = NSNoCellMask;
/* Determine the background color.
We draw when there is a border or when highlightsByMask
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
as required by our nextstep-like look and feel. */
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
{
[[GSTheme theme] drawButton: cellFrame withClip: NSZeroRect];
menuState = GSThemeHighlightedState;
}
/* Pushed in buttons contents are displaced to the bottom right 1px. */
if (mask & NSPushInCellMask)
{
menuState = GSThemeSelectedState;
}
[[GSTheme theme] drawBorderAndBackgroundForMenuItemCell: self
withFrame: cellFrame
inView: controlView
state: menuState
isHorizontal: [_menuView isHorizontal]];
}
- (void) drawImageWithFrame: (NSRect)cellFrame