Add drawing methods for theming NSBrowserCell.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38690 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2015-06-26 05:27:12 +00:00
parent 4213323979
commit 971a573445
5 changed files with 198 additions and 89 deletions

View file

@ -1,3 +1,11 @@
2015-06-26 01:22-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Headers/Additions/GNUstepGUI/GSTheme.h: Add declarations for
drawing methods for theming.
* Source/GSThemeDrawing.m: Add drawing methods for theming
* Source/NSBrowserCell.m: Use drawing methods
* Source/NSCell.m: Add private method for _inEditing
2015-06-25 20:11-EDT Gregory John Casamento <greg.casamento@gmail.com>
* Headers/Additions/GNUstepGUI/GSTheme.h: Add declarations for method

View file

@ -235,8 +235,8 @@
#if OS_API_VERSION(GS_API_NONE,GS_API_NONE)
@class NSArray;
@class NSBundle;
@class NSBrowserCell;
@class NSDictionary;
@class NSButton;
@class NSColor;
@class NSColorList;
@ -1479,6 +1479,46 @@ withRepeatedImage: (NSImage*)image
*/
- (void) didSetDefaultButtonCell: (NSButtonCell *)aCell;
@end
@interface GSTheme (NSBrowserCell)
/**
* Draw editor in cell
*/
- (void) drawEditorForCell: (NSCell *)cell
withFrame: (NSRect)cellFrame
inView: (NSView *)view;
/**
* Draw attributed text in cell
*/
- (void) drawInCell: (NSCell *)cell
attributedText: (NSAttributedString *)stringValue
inFrame: (NSRect)cellFrame;
/**
* Draw the interior of the browser cell
*/
- (void) drawBrowserInteriorWithFrame: (NSRect)cellFrame
withCell: (NSBrowserCell *)cell
inView: (NSView *)controlView
withImage: (NSImage *)theImage
alternateImage: (NSImage *)alternateImage
isHighlighted: (BOOL)isHighlighted
state: (int)state
isLeaf: (BOOL)isLeaf;
/**
* This method returns the branch image
*/
- (NSImage *) branchImage;
/**
* This method returns the highlighted version of
* the branch image
*/
- (NSImage *) highlightedBranchImage;
@end
#endif /* OS_API_VERSION */
#endif /* _GNUstep_H_GSTheme */

View file

@ -35,6 +35,7 @@
#import "AppKit/NSBezierPath.h"
#import "AppKit/NSButtonCell.h"
#import "AppKit/NSBrowser.h"
#import "AppKit/NSBrowserCell.h"
#import "AppKit/NSCell.h"
#import "AppKit/NSColor.h"
#import "AppKit/NSColorList.h"
@ -75,6 +76,11 @@
@interface NSCell (Private)
- (void) _setInEditing: (BOOL)flag;
- (BOOL) _inEditing;
- (void) _drawEditorWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView;
- (void) _drawAttributedText: (NSAttributedString*)aString
inFrame: (NSRect)aRect;
@end
@implementation GSTheme (Drawing)
@ -3351,4 +3357,131 @@ typedef enum {
}
}
- (void) drawEditorForCell: (NSCell *)cell
withFrame: (NSRect)cellFrame
inView: (NSView *)view
{
[cell _drawEditorWithFrame: cellFrame
inView: view];
}
- (void) drawInCell: (NSCell *)cell
attributedText: (NSAttributedString *)stringValue
inFrame: (NSRect)cellFrame
{
[cell _drawAttributedText: stringValue
inFrame: cellFrame];
}
// NSBrowserCell
- (void) drawBrowserInteriorWithFrame: (NSRect)cellFrame
withCell: (NSBrowserCell *)cell
inView: (NSView *)controlView
withImage: (NSImage *)theImage
alternateImage: (NSImage *)alternateImage
isHighlighted: (BOOL)isHighlighted
state: (int)state
isLeaf: (BOOL)isLeaf
{
NSRect title_rect = cellFrame;
NSImage *branch_image = nil;
NSImage *cell_image = theImage;
if (isHighlighted || state)
{
if (!isLeaf)
branch_image = [self highlightedBranchImage];
if (nil != alternateImage)
[cell setImage: alternateImage];
// If we are highlighted, fill the background
[[cell highlightColorInView: controlView] setFill];
NSRectFill(cellFrame);
}
else
{
if (!isLeaf)
branch_image = [self branchImage];
// (Don't fill the background)
}
// Draw the branch image if there is one
if (branch_image)
{
NSRect imgRect;
imgRect.size = [branch_image size];
imgRect.origin.x = MAX(NSMaxX(title_rect) - imgRect.size.width - 4.0, 0.);
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.), 0.);
if (controlView != nil)
{
imgRect = [controlView centerScanRect: imgRect];
}
[branch_image drawInRect: imgRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
title_rect.size.width -= imgRect.size.width + 8;
}
// Skip 2 points from the left border
title_rect.origin.x += 2;
title_rect.size.width -= 2;
// Draw the cell image if there is one
if (cell_image)
{
NSRect imgRect;
imgRect.size = [cell_image size];
imgRect.origin.x = NSMinX(title_rect);
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.);
if (controlView != nil)
{
imgRect = [controlView centerScanRect: imgRect];
}
[cell_image drawInRect: imgRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
title_rect.origin.x += imgRect.size.width + 4;
title_rect.size.width -= imgRect.size.width + 4;
}
// Draw the body of the cell
if ([cell _inEditing])
{
[self drawEditorForCell: cell
withFrame: cellFrame
inView: controlView];
}
else
{
[self drawInCell: cell
attributedText: [cell attributedStringValue]
inFrame: title_rect];
}
}
- (NSImage *) branchImage
{
return [NSImage imageNamed: @"common_3DArrowRight"];
}
- (NSImage *) highlightedBranchImage
{
return [NSImage imageNamed: @"common_3DArrowRightH"];
}
@end

View file

@ -40,6 +40,7 @@
#import "AppKit/NSEvent.h"
#import "AppKit/NSWindow.h"
#import "GSGuiPrivate.h"
#import "GNUstepGUI/GSTheme.h"
/*
* Class variables
@ -90,7 +91,7 @@ static NSFont *_leafFont;
*/
+ (NSImage*) branchImage
{
return _branch_image;
return [[GSTheme theme] branchImage];
}
/**<p>Returns the default hightlited branch image</p>
@ -98,7 +99,7 @@ static NSFont *_leafFont;
*/
+ (NSImage*) highlightedBranchImage
{
return _highlight_image;
return [[GSTheme theme] highlightedBranchImage];
}
/*
@ -330,92 +331,14 @@ static NSFont *_leafFont;
*/
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
{
NSRect title_rect = cellFrame;
NSImage *branch_image = nil;
NSImage *cell_image = [self image];
if (_cell.is_highlighted || _cell.state)
{
if (!_browsercell_is_leaf)
branch_image = [object_getClass(self) highlightedBranchImage];
if (nil != [self alternateImage])
cell_image = [self alternateImage];
// If we are highlighted, fill the background
[[self highlightColorInView: controlView] setFill];
NSRectFill(cellFrame);
}
else
{
if (!_browsercell_is_leaf)
branch_image = [object_getClass(self) branchImage];
// (Don't fill the background)
}
// Draw the branch image if there is one
if (branch_image)
{
NSRect imgRect;
imgRect.size = [branch_image size];
imgRect.origin.x = MAX(NSMaxX(title_rect) - imgRect.size.width - 4.0, 0.);
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.), 0.);
if (controlView != nil)
{
imgRect = [controlView centerScanRect: imgRect];
}
[branch_image drawInRect: imgRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
title_rect.size.width -= imgRect.size.width + 8;
}
// Skip 2 points from the left border
title_rect.origin.x += 2;
title_rect.size.width -= 2;
// Draw the cell image if there is one
if (cell_image)
{
NSRect imgRect;
imgRect.size = [cell_image size];
imgRect.origin.x = NSMinX(title_rect);
imgRect.origin.y = MAX(NSMidY(title_rect) - (imgRect.size.height/2.),0.);
if (controlView != nil)
{
imgRect = [controlView centerScanRect: imgRect];
}
[cell_image drawInRect: imgRect
fromRect: NSZeroRect
operation: NSCompositeSourceOver
fraction: 1.0
respectFlipped: YES
hints: nil];
title_rect.origin.x += imgRect.size.width + 4;
title_rect.size.width -= imgRect.size.width + 4;
}
// Draw the body of the cell
if (_cell.in_editing)
{
[self _drawEditorWithFrame: cellFrame inView: controlView];
}
else
{
[self _drawAttributedText: [self attributedStringValue]
inFrame: title_rect];
}
[[GSTheme theme] drawBrowserInteriorWithFrame: cellFrame
withCell: self
inView: controlView
withImage: [self image]
alternateImage: [self alternateImage]
isHighlighted: [self isHighlighted]
state: [self state]
isLeaf: [self isLeaf]];
}
/*

View file

@ -3030,6 +3030,11 @@ static NSColor *dtxtCol;
_cell.in_editing = flag;
}
- (BOOL) _inEditing
{
return _cell.in_editing;
}
- (void) _updateFieldEditor: (NSText*)textObject
{
if (_formatter != nil)