mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 00:51:02 +00:00
Better helper methods for cell string drawing. Implement MacOSX 10.4
methods on NSForm and NSFormCell. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25421 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
1a13f90156
commit
d33b2e8dd0
8 changed files with 320 additions and 220 deletions
173
Source/NSCell.m
173
Source/NSCell.m
|
@ -1943,57 +1943,32 @@ static NSColor *shadowCol;
|
|||
switch (_cell.type)
|
||||
{
|
||||
case NSTextCellType:
|
||||
{
|
||||
if (!_cell.is_disabled)
|
||||
{
|
||||
[self _drawAttributedText: [self attributedStringValue]
|
||||
inFrame: cellFrame];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSAttributedString *attrStr = [self attributedStringValue];
|
||||
NSDictionary *attribs;
|
||||
NSMutableDictionary *newAttribs;
|
||||
|
||||
attribs = [attrStr attributesAtIndex: 0
|
||||
effectiveRange: NULL];
|
||||
newAttribs = [NSMutableDictionary
|
||||
dictionaryWithDictionary: attribs];
|
||||
[newAttribs setObject: [NSColor disabledControlTextColor]
|
||||
forKey: NSForegroundColorAttributeName];
|
||||
|
||||
attrStr = [[NSAttributedString alloc]
|
||||
initWithString: [attrStr string]
|
||||
attributes: newAttribs];
|
||||
[self _drawAttributedText: attrStr
|
||||
inFrame: cellFrame];
|
||||
RELEASE(attrStr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
[self _drawAttributedText: [self _drawAttributedString]
|
||||
inFrame: cellFrame];
|
||||
break;
|
||||
|
||||
case NSImageCellType:
|
||||
if (_cell_image)
|
||||
{
|
||||
NSSize size;
|
||||
NSPoint position;
|
||||
|
||||
size = [_cell_image size];
|
||||
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
|
||||
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
|
||||
/*
|
||||
* Images are always drawn with their bottom-left corner
|
||||
* at the origin so we must adjust the position to take
|
||||
* account of a flipped view.
|
||||
*/
|
||||
if ([controlView isFlipped])
|
||||
position.y += size.height;
|
||||
[_cell_image compositeToPoint: position operation: NSCompositeSourceOver];
|
||||
}
|
||||
break;
|
||||
if (_cell_image)
|
||||
{
|
||||
NSSize size;
|
||||
NSPoint position;
|
||||
|
||||
size = [_cell_image size];
|
||||
position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.);
|
||||
position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.);
|
||||
/*
|
||||
* Images are always drawn with their bottom-left corner
|
||||
* at the origin so we must adjust the position to take
|
||||
* account of a flipped view.
|
||||
*/
|
||||
if ([controlView isFlipped])
|
||||
position.y += size.height;
|
||||
[_cell_image compositeToPoint: position operation: NSCompositeSourceOver];
|
||||
}
|
||||
break;
|
||||
|
||||
case NSNullCellType:
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
// NB: We don't do any highlighting to make it easier for subclasses
|
||||
|
@ -2001,44 +1976,6 @@ static NSColor *shadowCol;
|
|||
// prettyfying
|
||||
}
|
||||
|
||||
// Private helper method overridden in subclasses
|
||||
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
{
|
||||
if (_cell.is_bordered)
|
||||
{
|
||||
[shadowCol set];
|
||||
NSFrameRect(cellFrame);
|
||||
}
|
||||
else if (_cell.is_bezeled)
|
||||
{
|
||||
[[GSTheme theme] drawWhiteBezel: cellFrame withClip: NSZeroRect];
|
||||
}
|
||||
}
|
||||
|
||||
// Private helper method
|
||||
- (void) _drawFocusRingWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
{
|
||||
if (_cell.shows_first_responder
|
||||
&& [[controlView window] firstResponder] == controlView)
|
||||
{
|
||||
switch (_cell.focus_ring_type)
|
||||
{
|
||||
case NSFocusRingTypeDefault:
|
||||
[[GSTheme theme] drawFocusFrame: [self drawingRectForBounds:
|
||||
cellFrame]
|
||||
view: controlView];
|
||||
break;
|
||||
case NSFocusRingTypeExterior:
|
||||
[[GSTheme theme] drawFocusFrame: cellFrame
|
||||
view: controlView];
|
||||
break;
|
||||
case NSFocusRingTypeNone:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**<p>Draws the cell in <var>controlView</var></p>
|
||||
*/
|
||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
|
@ -2802,6 +2739,33 @@ static NSColor *shadowCol;
|
|||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Private internal method, returns an attributed string to display.
|
||||
*/
|
||||
- (NSAttributedString*) _drawAttributedString
|
||||
{
|
||||
if (!_cell.is_disabled)
|
||||
{
|
||||
return [self attributedStringValue];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSAttributedString *attrStr = [self attributedStringValue];
|
||||
NSDictionary *attribs;
|
||||
NSMutableDictionary *newAttribs;
|
||||
|
||||
attribs = [attrStr attributesAtIndex: 0
|
||||
effectiveRange: NULL];
|
||||
newAttribs = [NSMutableDictionary dictionaryWithDictionary: attribs];
|
||||
[newAttribs setObject: [NSColor disabledControlTextColor]
|
||||
forKey: NSForegroundColorAttributeName];
|
||||
|
||||
return AUTORELEASE([[NSAttributedString alloc]
|
||||
initWithString: [attrStr string]
|
||||
attributes: newAttribs]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Private internal method to display an attributed string.
|
||||
*/
|
||||
|
@ -2849,6 +2813,45 @@ static NSColor *shadowCol;
|
|||
RELEASE (attributes);
|
||||
}
|
||||
|
||||
// Private helper method overridden in subclasses
|
||||
- (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
|
||||
inView: (NSView*)controlView
|
||||
{
|
||||
if (_cell.is_bordered)
|
||||
{
|
||||
[shadowCol set];
|
||||
NSFrameRect(cellFrame);
|
||||
}
|
||||
else if (_cell.is_bezeled)
|
||||
{
|
||||
[[GSTheme theme] drawWhiteBezel: cellFrame withClip: NSZeroRect];
|
||||
}
|
||||
}
|
||||
|
||||
// Private helper method
|
||||
- (void) _drawFocusRingWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||
{
|
||||
if (_cell.shows_first_responder
|
||||
&& [[controlView window] firstResponder] == controlView)
|
||||
{
|
||||
switch (_cell.focus_ring_type)
|
||||
{
|
||||
case NSFocusRingTypeDefault:
|
||||
[[GSTheme theme] drawFocusFrame: [self drawingRectForBounds:
|
||||
cellFrame]
|
||||
view: controlView];
|
||||
break;
|
||||
case NSFocusRingTypeExterior:
|
||||
[[GSTheme theme] drawFocusFrame: cellFrame
|
||||
view: controlView];
|
||||
break;
|
||||
case NSFocusRingTypeNone:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) _sendsActionOn:(int)eventTypeMask
|
||||
{
|
||||
return (_action_mask & eventTypeMask);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue