mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:30:47 +00:00
Replaced use of mcell_highlighted with _cell.is_highlighted.
Removed this ivar and mcell_has_submenu from the coding methods. Removed method [highlight:withFrame:inView:]. in [drawBorderAndBackgroundWithFrame:inView:] moved duplicated out of if clause. in [calcSize] use cached arrow image for submenu sizing and changed image size code. Change all composite operators from NSCompositeCopy to NSCompositeSourceOver. Use the cached colour if it is computed otherwise ignore it. In [drawWithFrame:inView:] allways call [drawBorderAndBackgroundWithFrame:inView:] and check for border there. Moved lockfocus calls down one level. In [drawInteriorWithFrame:inView:] removed some of the checks already done in [drawWithFrame:inView:]. Replaced all the highlight/state logic with the one used in NSButtonCell. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10828 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
2437b86d25
commit
0d9d85cf4d
1 changed files with 148 additions and 239 deletions
|
@ -64,7 +64,6 @@ static NSImage *arrowImageH = nil;
|
||||||
|
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
mcell_has_submenu = NO;
|
|
||||||
[super init];
|
[super init];
|
||||||
_target = nil;
|
_target = nil;
|
||||||
_highlightsByMask = NSChangeBackgroundCellMask;
|
_highlightsByMask = NSChangeBackgroundCellMask;
|
||||||
|
@ -78,51 +77,33 @@ static NSImage *arrowImageH = nil;
|
||||||
|
|
||||||
- (void) setHighlighted:(BOOL)flag
|
- (void) setHighlighted:(BOOL)flag
|
||||||
{
|
{
|
||||||
mcell_highlighted = flag;
|
_cell.is_highlighted = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) isHighlighted
|
- (BOOL) isHighlighted
|
||||||
{
|
{
|
||||||
return mcell_highlighted;
|
// Same as in super class
|
||||||
}
|
return _cell.is_highlighted;
|
||||||
|
|
||||||
- (void) highlight: (BOOL)flag
|
|
||||||
withFrame: (NSRect)cellFrame
|
|
||||||
inView: (NSView*)controlView
|
|
||||||
{
|
|
||||||
if (mcell_highlighted != flag)
|
|
||||||
{
|
|
||||||
// Save last view drawn to
|
|
||||||
if (_control_view != controlView)
|
|
||||||
_control_view = controlView;
|
|
||||||
|
|
||||||
[controlView lockFocus];
|
|
||||||
|
|
||||||
mcell_highlighted = flag;
|
|
||||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
|
||||||
|
|
||||||
[controlView unlockFocus];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setMenuItem:(NSMenuItem *)item
|
- (void) setMenuItem:(NSMenuItem *)item
|
||||||
{
|
{
|
||||||
ASSIGN(mcell_item, item);
|
ASSIGN(_menuItem, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMenuItem *) menuItem
|
- (NSMenuItem *) menuItem
|
||||||
{
|
{
|
||||||
return mcell_item;
|
return _menuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setMenuView:(NSMenuView *)menuView
|
- (void) setMenuView:(NSMenuView *)menuView
|
||||||
{
|
{
|
||||||
ASSIGN(mcell_menuView, menuView);
|
ASSIGN(_menuView, menuView);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMenuView *) menuView
|
- (NSMenuView *) menuView
|
||||||
{
|
{
|
||||||
return mcell_menuView;
|
return _menuView;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) calcSize
|
- (void) calcSize
|
||||||
|
@ -132,109 +113,114 @@ static NSImage *arrowImageH = nil;
|
||||||
float neededMenuItemHeight = 20;
|
float neededMenuItemHeight = 20;
|
||||||
|
|
||||||
// State Image
|
// State Image
|
||||||
if ([mcell_item changesState])
|
if ([_menuItem changesState])
|
||||||
{
|
{
|
||||||
// NSOnState
|
// NSOnState
|
||||||
componentSize = [[mcell_item onStateImage] size];
|
componentSize = [[_menuItem onStateImage] size];
|
||||||
mcell_stateImageWidth = componentSize.width;
|
_stateImageWidth = componentSize.width;
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
neededMenuItemHeight = componentSize.height;
|
neededMenuItemHeight = componentSize.height;
|
||||||
|
|
||||||
// NSOffState
|
// NSOffState
|
||||||
componentSize = [[mcell_item offStateImage] size];
|
componentSize = [[_menuItem offStateImage] size];
|
||||||
if (componentSize.width > mcell_stateImageWidth)
|
if (componentSize.width > _stateImageWidth)
|
||||||
mcell_stateImageWidth = componentSize.width;
|
_stateImageWidth = componentSize.width;
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
neededMenuItemHeight = componentSize.height;
|
neededMenuItemHeight = componentSize.height;
|
||||||
|
|
||||||
// NSMixedState
|
// NSMixedState
|
||||||
componentSize = [[mcell_item mixedStateImage] size];
|
componentSize = [[_menuItem mixedStateImage] size];
|
||||||
if (componentSize.width > mcell_stateImageWidth)
|
if (componentSize.width > _stateImageWidth)
|
||||||
mcell_stateImageWidth = componentSize.width;
|
_stateImageWidth = componentSize.width;
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
neededMenuItemHeight = componentSize.height;
|
neededMenuItemHeight = componentSize.height;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mcell_stateImageWidth = 0.0;
|
_stateImageWidth = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
if ((anImage = [mcell_item image]) && _cell.image_position == NSNoImage)
|
if ((anImage = [_menuItem image]) && _cell.image_position == NSNoImage)
|
||||||
[self setImagePosition: NSImageLeft];
|
[self setImagePosition: NSImageLeft];
|
||||||
componentSize = NSMakeSize(0,0);
|
|
||||||
if (anImage)
|
if (anImage)
|
||||||
componentSize = [anImage size];
|
{
|
||||||
mcell_imageWidth = componentSize.width;
|
componentSize = [anImage size];
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
_imageWidth = componentSize.width;
|
||||||
neededMenuItemHeight = componentSize.height;
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
|
neededMenuItemHeight = componentSize.height;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_imageWidth = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
// Title and Key Equivalent
|
// Title and Key Equivalent
|
||||||
componentSize = [self _sizeText: [mcell_item title]];
|
componentSize = [self _sizeText: [_menuItem title]];
|
||||||
mcell_titleWidth = componentSize.width;
|
_titleWidth = componentSize.width;
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
neededMenuItemHeight = componentSize.height;
|
neededMenuItemHeight = componentSize.height;
|
||||||
componentSize = [self _sizeText: [mcell_item keyEquivalent]];
|
componentSize = [self _sizeText: [_menuItem keyEquivalent]];
|
||||||
mcell_keyEquivalentWidth = componentSize.width;
|
_keyEquivalentWidth = componentSize.width;
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
neededMenuItemHeight = componentSize.height;
|
neededMenuItemHeight = componentSize.height;
|
||||||
|
|
||||||
// Submenu Arrow
|
// Submenu Arrow
|
||||||
if ([mcell_item hasSubmenu])
|
if ([_menuItem hasSubmenu])
|
||||||
{
|
{
|
||||||
componentSize = [[NSImage imageNamed:@"common_3DArrowRight"] size];
|
componentSize = [arrowImage size];
|
||||||
mcell_keyEquivalentWidth = componentSize.width;
|
_keyEquivalentWidth = componentSize.width;
|
||||||
if (componentSize.height > neededMenuItemHeight)
|
if (componentSize.height > neededMenuItemHeight)
|
||||||
neededMenuItemHeight = componentSize.height;
|
neededMenuItemHeight = componentSize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache definitive height
|
// Cache definitive height
|
||||||
mcell_menuItemHeight = neededMenuItemHeight;
|
_menuItemHeight = neededMenuItemHeight;
|
||||||
|
|
||||||
// At the end we set sizing to NO.
|
// At the end we set sizing to NO.
|
||||||
mcell_needs_sizing = NO;
|
_needs_sizing = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setNeedsSizing:(BOOL)flag
|
- (void) setNeedsSizing:(BOOL)flag
|
||||||
{
|
{
|
||||||
mcell_needs_sizing = flag;
|
_needs_sizing = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL) needsSizing
|
- (BOOL) needsSizing
|
||||||
{
|
{
|
||||||
return mcell_needs_sizing;
|
return _needs_sizing;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) imageWidth
|
- (float) imageWidth
|
||||||
{
|
{
|
||||||
if (mcell_needs_sizing)
|
if (_needs_sizing)
|
||||||
[self calcSize];
|
[self calcSize];
|
||||||
|
|
||||||
return mcell_imageWidth;
|
return _imageWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) titleWidth
|
- (float) titleWidth
|
||||||
{
|
{
|
||||||
if (mcell_needs_sizing)
|
if (_needs_sizing)
|
||||||
[self calcSize];
|
[self calcSize];
|
||||||
|
|
||||||
return mcell_titleWidth;
|
return _titleWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) keyEquivalentWidth
|
- (float) keyEquivalentWidth
|
||||||
{
|
{
|
||||||
if (mcell_needs_sizing)
|
if (_needs_sizing)
|
||||||
[self calcSize];
|
[self calcSize];
|
||||||
|
|
||||||
return mcell_keyEquivalentWidth;
|
return _keyEquivalentWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (float) stateImageWidth
|
- (float) stateImageWidth
|
||||||
{
|
{
|
||||||
if (mcell_needs_sizing)
|
if (_needs_sizing)
|
||||||
[self calcSize];
|
[self calcSize];
|
||||||
|
|
||||||
return mcell_stateImageWidth;
|
return _stateImageWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -245,16 +231,17 @@ static NSImage *arrowImageH = nil;
|
||||||
if (_mcell_belongs_to_popupbutton && _cell.image_position)
|
if (_mcell_belongs_to_popupbutton && _cell.image_position)
|
||||||
{
|
{
|
||||||
/* Special case: draw image on the extreme right [FIXME check the distance]*/
|
/* Special case: draw image on the extreme right [FIXME check the distance]*/
|
||||||
cellFrame.origin.x += cellFrame.size.width - mcell_imageWidth - 4;
|
cellFrame.origin.x += cellFrame.size.width - _imageWidth - 4;
|
||||||
cellFrame.size.width = mcell_imageWidth;
|
cellFrame.size.width = _imageWidth;
|
||||||
return cellFrame;
|
return cellFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the image part of cell frame from NSMenuView
|
// Calculate the image part of cell frame from NSMenuView
|
||||||
cellFrame.origin.x += [mcell_menuView imageAndTitleOffset];
|
cellFrame.origin.x += [_menuView imageAndTitleOffset];
|
||||||
cellFrame.size.width = [mcell_menuView imageAndTitleWidth];
|
cellFrame.size.width = [_menuView imageAndTitleWidth];
|
||||||
if ([mcell_item changesState])
|
if ([_menuItem changesState])
|
||||||
cellFrame.origin.x += [mcell_menuView stateImageWidth]
|
cellFrame.origin.x += [_menuView stateImageWidth]
|
||||||
+ 2 * [mcell_menuView horizontalEdgePadding];
|
+ 2 * [_menuView horizontalEdgePadding];
|
||||||
|
|
||||||
switch (_cell.image_position)
|
switch (_cell.image_position)
|
||||||
{
|
{
|
||||||
|
@ -267,12 +254,12 @@ static NSImage *arrowImageH = nil;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageLeft:
|
case NSImageLeft:
|
||||||
cellFrame.size.width = mcell_imageWidth;
|
cellFrame.size.width = _imageWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageRight:
|
case NSImageRight:
|
||||||
cellFrame.origin.x += mcell_titleWidth + xDist;
|
cellFrame.origin.x += _titleWidth + xDist;
|
||||||
cellFrame.size.width = mcell_imageWidth;
|
cellFrame.size.width = _imageWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageBelow:
|
case NSImageBelow:
|
||||||
|
@ -291,8 +278,8 @@ static NSImage *arrowImageH = nil;
|
||||||
- (NSRect) keyEquivalentRectForBounds:(NSRect)cellFrame
|
- (NSRect) keyEquivalentRectForBounds:(NSRect)cellFrame
|
||||||
{
|
{
|
||||||
// Calculate the image part of cell frame from NSMenuView
|
// Calculate the image part of cell frame from NSMenuView
|
||||||
cellFrame.origin.x += [mcell_menuView keyEquivalentOffset];
|
cellFrame.origin.x += [_menuView keyEquivalentOffset];
|
||||||
cellFrame.size.width = [mcell_menuView keyEquivalentWidth];
|
cellFrame.size.width = [_menuView keyEquivalentWidth];
|
||||||
|
|
||||||
return cellFrame;
|
return cellFrame;
|
||||||
}
|
}
|
||||||
|
@ -300,8 +287,8 @@ static NSImage *arrowImageH = nil;
|
||||||
- (NSRect) stateImageRectForBounds:(NSRect)cellFrame
|
- (NSRect) stateImageRectForBounds:(NSRect)cellFrame
|
||||||
{
|
{
|
||||||
// Calculate the image part of cell frame from NSMenuView
|
// Calculate the image part of cell frame from NSMenuView
|
||||||
cellFrame.origin.x += [mcell_menuView stateImageOffset];
|
cellFrame.origin.x += [_menuView stateImageOffset];
|
||||||
cellFrame.size.width = [mcell_menuView stateImageWidth];
|
cellFrame.size.width = [_menuView stateImageWidth];
|
||||||
|
|
||||||
return cellFrame;
|
return cellFrame;
|
||||||
}
|
}
|
||||||
|
@ -309,11 +296,11 @@ static NSImage *arrowImageH = nil;
|
||||||
- (NSRect) titleRectForBounds:(NSRect)cellFrame
|
- (NSRect) titleRectForBounds:(NSRect)cellFrame
|
||||||
{
|
{
|
||||||
// Calculate the image part of cell frame from NSMenuView
|
// Calculate the image part of cell frame from NSMenuView
|
||||||
cellFrame.origin.x += [mcell_menuView imageAndTitleOffset];
|
cellFrame.origin.x += [_menuView imageAndTitleOffset];
|
||||||
cellFrame.size.width = [mcell_menuView imageAndTitleWidth];
|
cellFrame.size.width = [_menuView imageAndTitleWidth];
|
||||||
if ([mcell_item changesState])
|
if ([_menuItem changesState])
|
||||||
cellFrame.origin.x += [mcell_menuView stateImageWidth]
|
cellFrame.origin.x += [_menuView stateImageWidth]
|
||||||
+ 2 * [mcell_menuView horizontalEdgePadding];
|
+ 2 * [_menuView horizontalEdgePadding];
|
||||||
|
|
||||||
switch (_cell.image_position)
|
switch (_cell.image_position)
|
||||||
{
|
{
|
||||||
|
@ -326,12 +313,12 @@ static NSImage *arrowImageH = nil;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageLeft:
|
case NSImageLeft:
|
||||||
cellFrame.origin.x += mcell_imageWidth + xDist;
|
cellFrame.origin.x += _imageWidth + xDist;
|
||||||
cellFrame.size.width = mcell_titleWidth;
|
cellFrame.size.width = _titleWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageRight:
|
case NSImageRight:
|
||||||
cellFrame.size.width = mcell_titleWidth;
|
cellFrame.size.width = _titleWidth;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSImageBelow:
|
case NSImageBelow:
|
||||||
|
@ -350,32 +337,29 @@ static NSImage *arrowImageH = nil;
|
||||||
//
|
//
|
||||||
// Drawing.
|
// Drawing.
|
||||||
//
|
//
|
||||||
- (void) drawBorderAndBackgroundWithFrame:(NSRect)cellFrame
|
- (void) drawBorderAndBackgroundWithFrame: (NSRect)cellFrame
|
||||||
inView:(NSView *)controlView
|
inView: (NSView *)controlView
|
||||||
{
|
{
|
||||||
|
if (!_cell.is_bordered)
|
||||||
|
return;
|
||||||
|
|
||||||
|
[controlView lockFocus];
|
||||||
|
|
||||||
if (_mcell_belongs_to_popupbutton)
|
if (_mcell_belongs_to_popupbutton)
|
||||||
{
|
{
|
||||||
cellFrame.origin.x--;
|
cellFrame.origin.x--;
|
||||||
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
|
}
|
||||||
{
|
|
||||||
NSDrawGrayBezel(cellFrame, NSZeroRect);
|
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
|
||||||
}
|
{
|
||||||
else
|
NSDrawGrayBezel(cellFrame, NSZeroRect);
|
||||||
{
|
|
||||||
NSDrawButton(cellFrame, NSZeroRect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask))
|
NSDrawButton(cellFrame, NSZeroRect);
|
||||||
{
|
|
||||||
NSDrawGrayBezel(cellFrame, NSZeroRect);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
NSDrawButton(cellFrame, NSZeroRect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[controlView unlockFocus];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawImageWithFrame: (NSRect)cellFrame
|
- (void) drawImageWithFrame: (NSRect)cellFrame
|
||||||
|
@ -383,10 +367,9 @@ static NSImage *arrowImageH = nil;
|
||||||
{
|
{
|
||||||
NSSize size;
|
NSSize size;
|
||||||
NSPoint position;
|
NSPoint position;
|
||||||
NSColor *backgroundColor = _backgroundColor;
|
|
||||||
|
|
||||||
cellFrame = [self imageRectForBounds: cellFrame];
|
cellFrame = [self imageRectForBounds: cellFrame];
|
||||||
size = [mcell_imageToDisplay size];
|
size = [_imageToDisplay size];
|
||||||
position.x = MAX(NSMidX(cellFrame) - (size.width/2.), 0.);
|
position.x = MAX(NSMidX(cellFrame) - (size.width/2.), 0.);
|
||||||
position.y = MAX(NSMidY(cellFrame) - (size.height/2.), 0.);
|
position.y = MAX(NSMidY(cellFrame) - (size.height/2.), 0.);
|
||||||
/*
|
/*
|
||||||
|
@ -396,26 +379,9 @@ static NSImage *arrowImageH = nil;
|
||||||
if ([controlView isFlipped])
|
if ([controlView isFlipped])
|
||||||
position.y += size.height;
|
position.y += size.height;
|
||||||
|
|
||||||
if (backgroundColor == nil)
|
if (nil != _backgroundColor)
|
||||||
{
|
[_imageToDisplay setBackgroundColor: _backgroundColor];
|
||||||
if (_cell.state)
|
[_imageToDisplay compositeToPoint: position operation: NSCompositeSourceOver];
|
||||||
{
|
|
||||||
if (_showAltStateMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
if (mcell_highlighted)
|
|
||||||
{
|
|
||||||
if (_highlightsByMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
if (backgroundColor == nil)
|
|
||||||
backgroundColor = [colorClass controlBackgroundColor];
|
|
||||||
}
|
|
||||||
|
|
||||||
[mcell_imageToDisplay setBackgroundColor: backgroundColor];
|
|
||||||
[mcell_imageToDisplay compositeToPoint: position operation: NSCompositeCopy];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawKeyEquivalentWithFrame:(NSRect)cellFrame
|
- (void) drawKeyEquivalentWithFrame:(NSRect)cellFrame
|
||||||
|
@ -423,14 +389,13 @@ static NSImage *arrowImageH = nil;
|
||||||
{
|
{
|
||||||
cellFrame = [self keyEquivalentRectForBounds: cellFrame];
|
cellFrame = [self keyEquivalentRectForBounds: cellFrame];
|
||||||
|
|
||||||
if ([mcell_item hasSubmenu])
|
if ([_menuItem hasSubmenu])
|
||||||
{
|
{
|
||||||
NSSize size;
|
NSSize size;
|
||||||
NSPoint position;
|
NSPoint position;
|
||||||
NSColor *backgroundColor = _backgroundColor;
|
|
||||||
NSImage *imageToDraw;
|
NSImage *imageToDraw;
|
||||||
|
|
||||||
if (mcell_highlighted)
|
if (_cell.is_highlighted)
|
||||||
imageToDraw = arrowImageH;
|
imageToDraw = arrowImageH;
|
||||||
else
|
else
|
||||||
imageToDraw = arrowImage;
|
imageToDraw = arrowImage;
|
||||||
|
@ -444,28 +409,12 @@ static NSImage *arrowImageH = nil;
|
||||||
if ([controlView isFlipped])
|
if ([controlView isFlipped])
|
||||||
position.y += size.height;
|
position.y += size.height;
|
||||||
|
|
||||||
if (backgroundColor == nil)
|
if (nil != _backgroundColor)
|
||||||
{
|
[imageToDraw setBackgroundColor: _backgroundColor];
|
||||||
if (_cell.state)
|
[imageToDraw compositeToPoint: position operation: NSCompositeSourceOver];
|
||||||
{
|
|
||||||
if (_showAltStateMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
if (mcell_highlighted)
|
|
||||||
{
|
|
||||||
if (_highlightsByMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
if (backgroundColor == nil)
|
|
||||||
backgroundColor = [colorClass controlBackgroundColor];
|
|
||||||
}
|
|
||||||
[imageToDraw setBackgroundColor: backgroundColor];
|
|
||||||
[imageToDraw compositeToPoint: position operation: NSCompositeCopy];
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
[self _drawText: [mcell_item keyEquivalent] inFrame: cellFrame];
|
[self _drawText: [_menuItem keyEquivalent] inFrame: cellFrame];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawSeparatorItemWithFrame:(NSRect)cellFrame
|
- (void) drawSeparatorItemWithFrame:(NSRect)cellFrame
|
||||||
|
@ -481,23 +430,22 @@ static NSImage *arrowImageH = nil;
|
||||||
NSSize size;
|
NSSize size;
|
||||||
NSPoint position;
|
NSPoint position;
|
||||||
NSImage *imageToDisplay;
|
NSImage *imageToDisplay;
|
||||||
NSColor *backgroundColor = _backgroundColor;
|
|
||||||
|
|
||||||
cellFrame = [self stateImageRectForBounds: cellFrame];
|
cellFrame = [self stateImageRectForBounds: cellFrame];
|
||||||
|
|
||||||
switch ([mcell_item state])
|
switch ([_menuItem state])
|
||||||
{
|
{
|
||||||
case NSOnState:
|
case NSOnState:
|
||||||
imageToDisplay = [mcell_item onStateImage];
|
imageToDisplay = [_menuItem onStateImage];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSMixedState:
|
case NSMixedState:
|
||||||
imageToDisplay = [mcell_item mixedStateImage];
|
imageToDisplay = [_menuItem mixedStateImage];
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NSOffState:
|
case NSOffState:
|
||||||
default:
|
default:
|
||||||
imageToDisplay = [mcell_item offStateImage];
|
imageToDisplay = [_menuItem offStateImage];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -511,36 +459,20 @@ static NSImage *arrowImageH = nil;
|
||||||
if ([controlView isFlipped])
|
if ([controlView isFlipped])
|
||||||
position.y += size.height;
|
position.y += size.height;
|
||||||
|
|
||||||
if (backgroundColor == nil)
|
if (nil != _backgroundColor)
|
||||||
{
|
[imageToDisplay setBackgroundColor: _backgroundColor];
|
||||||
if (_cell.state)
|
[imageToDisplay compositeToPoint: position operation: NSCompositeSourceOver];
|
||||||
{
|
|
||||||
if (_showAltStateMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
if (mcell_highlighted)
|
|
||||||
{
|
|
||||||
if (_highlightsByMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
if (backgroundColor == nil)
|
|
||||||
backgroundColor = [colorClass controlBackgroundColor];
|
|
||||||
}
|
|
||||||
[imageToDisplay setBackgroundColor: _backgroundColor];
|
|
||||||
[imageToDisplay compositeToPoint: position operation: NSCompositeCopy];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawTitleWithFrame:(NSRect)cellFrame
|
- (void) drawTitleWithFrame:(NSRect)cellFrame
|
||||||
inView:(NSView *)controlView
|
inView:(NSView *)controlView
|
||||||
{
|
{
|
||||||
if ([mcell_item isEnabled])
|
if ([_menuItem isEnabled])
|
||||||
_cell.is_disabled = NO;
|
_cell.is_disabled = NO;
|
||||||
else
|
else
|
||||||
_cell.is_disabled = YES;
|
_cell.is_disabled = YES;
|
||||||
|
|
||||||
[self _drawText: [mcell_item title]
|
[self _drawText: [_menuItem title]
|
||||||
inFrame: [self titleRectForBounds: cellFrame]];
|
inFrame: [self titleRectForBounds: cellFrame]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -562,59 +494,49 @@ static NSImage *arrowImageH = nil;
|
||||||
if ([[controlView window] gState] == 0)
|
if ([[controlView window] gState] == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[controlView lockFocus];
|
|
||||||
|
|
||||||
// Draw the border if needed
|
// Draw the border if needed
|
||||||
if (_cell.is_bordered)
|
[self drawBorderAndBackgroundWithFrame: cellFrame inView: controlView];
|
||||||
[self drawBorderAndBackgroundWithFrame: cellFrame inView: controlView];
|
|
||||||
|
|
||||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||||
|
|
||||||
[controlView unlockFocus];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
BOOL showAlternate = NO;
|
|
||||||
unsigned mask;
|
unsigned mask;
|
||||||
|
|
||||||
// Transparent buttons never draw
|
// Transparent buttons never draw
|
||||||
if (_buttoncell_is_transparent)
|
if (_buttoncell_is_transparent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Do nothing if the cell frame is empty
|
|
||||||
if (NSIsEmptyRect(cellFrame))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Do nothing if the window is deferred
|
|
||||||
if ([[controlView window] gState] == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
cellFrame = [self drawingRectForBounds: cellFrame];
|
cellFrame = [self drawingRectForBounds: cellFrame];
|
||||||
|
[controlView lockFocus];
|
||||||
|
|
||||||
// Pushed in buttons contents are displaced to the bottom right 1px
|
if (_cell.is_highlighted)
|
||||||
if (_cell.is_bordered && mcell_highlighted
|
{
|
||||||
&& (_highlightsByMask & NSPushInCellMask))
|
mask = _highlightsByMask;
|
||||||
PStranslate(1., [controlView isFlipped] ? 1. : -1.);
|
|
||||||
|
if (_cell.state)
|
||||||
|
mask &= ~_showAltStateMask;
|
||||||
|
}
|
||||||
|
else if (_cell.state)
|
||||||
|
mask = _showAltStateMask;
|
||||||
|
else
|
||||||
|
mask = NSNoCellMask;
|
||||||
|
|
||||||
|
// pushed in buttons contents are displaced to the bottom right 1px
|
||||||
|
if (_cell.is_bordered && (mask & NSPushInCellMask))
|
||||||
|
{
|
||||||
|
cellFrame = NSOffsetRect(cellFrame, 1., [controlView isFlipped] ? 1. : -1.);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Determine the background color and cache it in an ivar so that the
|
* Determine the background color and cache it in an ivar so that the
|
||||||
* low-level drawing methods don't need to do it again.
|
* low-level drawing methods don't need to do it again.
|
||||||
*/
|
*/
|
||||||
if (_cell.state)
|
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
||||||
{
|
{
|
||||||
if (_showAltStateMask
|
_backgroundColor = [colorClass selectedMenuItemColor];
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
_backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcell_highlighted)
|
|
||||||
{
|
|
||||||
if (_highlightsByMask
|
|
||||||
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
_backgroundColor = [colorClass selectedMenuItemColor];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_backgroundColor == nil)
|
if (_backgroundColor == nil)
|
||||||
_backgroundColor = [colorClass controlBackgroundColor];
|
_backgroundColor = [colorClass controlBackgroundColor];
|
||||||
|
|
||||||
|
@ -640,49 +562,43 @@ static NSImage *arrowImageH = nil;
|
||||||
* The results are saved in two ivars for use in other
|
* The results are saved in two ivars for use in other
|
||||||
* drawing methods.
|
* drawing methods.
|
||||||
*/
|
*/
|
||||||
if (mcell_highlighted)
|
|
||||||
mask = _highlightsByMask;
|
|
||||||
else
|
|
||||||
mask = _showAltStateMask;
|
|
||||||
if (mask & NSContentsCellMask)
|
if (mask & NSContentsCellMask)
|
||||||
showAlternate = _cell.state;
|
|
||||||
|
|
||||||
if (mcell_highlighted || showAlternate)
|
|
||||||
{
|
{
|
||||||
mcell_imageToDisplay = _altImage;
|
_imageToDisplay = _altImage;
|
||||||
if (!mcell_imageToDisplay)
|
if (!_imageToDisplay)
|
||||||
mcell_imageToDisplay = [mcell_item image];
|
_imageToDisplay = [_menuItem image];
|
||||||
mcell_titleToDisplay = _altContents;
|
_titleToDisplay = _altContents;
|
||||||
if (mcell_titleToDisplay == nil || [mcell_titleToDisplay isEqual: @""])
|
if (_titleToDisplay == nil || [_titleToDisplay isEqual: @""])
|
||||||
mcell_titleToDisplay = [mcell_item title];
|
_titleToDisplay = [_menuItem title];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mcell_imageToDisplay = [mcell_item image];
|
_imageToDisplay = [_menuItem image];
|
||||||
mcell_titleToDisplay = [mcell_item title];
|
_titleToDisplay = [_menuItem title];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mcell_imageToDisplay)
|
if (_imageToDisplay)
|
||||||
{
|
{
|
||||||
mcell_imageWidth = [mcell_imageToDisplay size].width;
|
_imageWidth = [_imageToDisplay size].width;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw the state image
|
// Draw the state image
|
||||||
if (mcell_stateImageWidth > 0)
|
if (_stateImageWidth > 0)
|
||||||
[self drawStateImageWithFrame: cellFrame inView: controlView];
|
[self drawStateImageWithFrame: cellFrame inView: controlView];
|
||||||
|
|
||||||
// Draw the image
|
// Draw the image
|
||||||
if (mcell_imageWidth > 0)
|
if (_imageWidth > 0)
|
||||||
[self drawImageWithFrame: cellFrame inView: controlView];
|
[self drawImageWithFrame: cellFrame inView: controlView];
|
||||||
|
|
||||||
// Draw the title
|
// Draw the title
|
||||||
if (mcell_titleWidth > 0)
|
if (_titleWidth > 0)
|
||||||
[self drawTitleWithFrame: cellFrame inView: controlView];
|
[self drawTitleWithFrame: cellFrame inView: controlView];
|
||||||
|
|
||||||
// Draw the key equivalent
|
// Draw the key equivalent
|
||||||
if (mcell_keyEquivalentWidth > 0)
|
if (_keyEquivalentWidth > 0)
|
||||||
[self drawKeyEquivalentWithFrame: cellFrame inView: controlView];
|
[self drawKeyEquivalentWithFrame: cellFrame inView: controlView];
|
||||||
|
|
||||||
|
[controlView unlockFocus];
|
||||||
_backgroundColor = nil;
|
_backgroundColor = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,12 +609,9 @@ static NSImage *arrowImageH = nil;
|
||||||
{
|
{
|
||||||
NSMenuItemCell *c = [super copyWithZone: zone];
|
NSMenuItemCell *c = [super copyWithZone: zone];
|
||||||
|
|
||||||
//c->mcell_highlighted = mcell_highlighted;
|
if (_menuItem)
|
||||||
//c->mcell_has_submenu = mcell_has_submenu;
|
c->_menuItem = [_menuItem copyWithZone: zone];
|
||||||
//c->mcell_needs_sizing = mcell_needs_sizing;
|
c->_menuView = RETAIN(_menuView);
|
||||||
if (mcell_item)
|
|
||||||
c->mcell_item = [mcell_item copyWithZone: zone];
|
|
||||||
c->mcell_menuView = RETAIN(mcell_menuView);
|
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -710,22 +623,18 @@ static NSImage *arrowImageH = nil;
|
||||||
{
|
{
|
||||||
[super encodeWithCoder: aCoder];
|
[super encodeWithCoder: aCoder];
|
||||||
|
|
||||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &mcell_highlighted];
|
[aCoder encodeConditionalObject: _menuItem];
|
||||||
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &mcell_has_submenu];
|
[aCoder encodeConditionalObject: _menuView];
|
||||||
[aCoder encodeConditionalObject: mcell_item];
|
|
||||||
[aCoder encodeConditionalObject: mcell_menuView];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||||
{
|
{
|
||||||
[super initWithCoder: aDecoder];
|
[super initWithCoder: aDecoder];
|
||||||
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &mcell_highlighted];
|
_menuItem = [aDecoder decodeObject];
|
||||||
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &mcell_has_submenu];
|
_menuView = [aDecoder decodeObject];
|
||||||
mcell_item = [aDecoder decodeObject];
|
|
||||||
mcell_menuView = [aDecoder decodeObject];
|
|
||||||
|
|
||||||
mcell_needs_sizing = YES;
|
_needs_sizing = YES;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue