mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 11:30:48 +00:00
Add MaxOS 10.4 methods and required ivars to NSButtonCell, implemented
then and use this methods. Also adjusted subclasses tothis changes. Split off theming code for buttons into two methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24400 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
3aa639828d
commit
e344345023
8 changed files with 340 additions and 181 deletions
27
ChangeLog
27
ChangeLog
|
@ -1,3 +1,30 @@
|
||||||
|
2007-01-23 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Headers/Additions/GNUstepGUI/GSTheme.h,
|
||||||
|
* Source/GSTheme.m (-buttonBorderForStyle:state:): New method to
|
||||||
|
determine the button border size.
|
||||||
|
* Headers/Additions/GNUstepGUI/GSTheme.h (-drawButton:...state:),
|
||||||
|
* Source/GSTheme.m (-drawButton:view:style:state:): Don't return a result.
|
||||||
|
* Source/NSCell.m (-drawInteriorWithFrame:inView:,
|
||||||
|
-drawWithFrame:inView:): Bring drawing of focus ring inline
|
||||||
|
with the one in NSButtonCell.
|
||||||
|
* Headers/AppKit/NSButtonCell.h: Add MacOS 10.4 methods and
|
||||||
|
additional ivars and changed enumerator values.
|
||||||
|
* Source/NSButtonCell.m: Implemented new methods.
|
||||||
|
* Source/NSButtonCell.m (-setButtonType:): Use new enumerator values.
|
||||||
|
* Source/NSButtonCell.m (-_init): Use method call to set button type.
|
||||||
|
* Source/NSButtonCell.m (-drawInteriorWithFrame:inView:,
|
||||||
|
-drawWithFrame:inView:): Use new methods for the drawing.
|
||||||
|
* Source/NSButtonCell.m (-cellSize, -drawingRectForBounds:): Use
|
||||||
|
new theme method to determine border size.
|
||||||
|
* Source/NSButtonCell.m (-encodeWithCoder:, -initWithCoder:):
|
||||||
|
Encode/decode new and previously missing ivars.
|
||||||
|
* Source/NSMenuItemCell.m (-drawingRectForBounds:): Moved old super
|
||||||
|
class code to here.
|
||||||
|
* Source/NSToolbarItem.m (GSToolbarButtonCell
|
||||||
|
-drawImage:withFrame:inView:): Renamed method to match with
|
||||||
|
superclass change and simplified implementation.
|
||||||
|
|
||||||
2007-01-23 Matt Rice <ratmice@gmail.com>
|
2007-01-23 Matt Rice <ratmice@gmail.com>
|
||||||
|
|
||||||
* Source/NSWindow.m (-_lossOfKeyOrMainWindow): Use GSOrderedWindows.
|
* Source/NSWindow.m (-_lossOfKeyOrMainWindow): Use GSOrderedWindows.
|
||||||
|
|
|
@ -378,16 +378,22 @@ APPKIT_EXPORT NSString *GSThemeDidDeactivateNotification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a button frame and background (not its content) for the specified
|
* Draws a button frame and background (not its content) for the specified
|
||||||
* cell and view.<br />
|
* cell and view.
|
||||||
* Returns the rectangle into which the cell contents should be drawn.
|
|
||||||
*/
|
*/
|
||||||
- (NSRect) drawButton: (NSRect)frame
|
- (void) drawButton: (NSRect)frame
|
||||||
in: (NSButtonCell*)cell
|
in: (NSButtonCell*)cell
|
||||||
view: (NSView*)view
|
view: (NSView*)view
|
||||||
style: (int)style
|
style: (int)style
|
||||||
state: (GSThemeControlState)state;
|
state: (GSThemeControlState)state;
|
||||||
|
|
||||||
/** Draws the indicator (normally a dotted rectangle) to show that
|
/**
|
||||||
|
* Amount by which the button is inset by the border.
|
||||||
|
*/
|
||||||
|
- (NSSize) buttonBorderForStyle: (int)style
|
||||||
|
state: (GSThemeControlState)state;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the indicator (normally a dotted rectangle) to show that
|
||||||
* the view currently has keyboard focus.
|
* the view currently has keyboard focus.
|
||||||
*/
|
*/
|
||||||
- (void) drawFocusFrame: (NSRect)frame view: (NSView*)view;
|
- (void) drawFocusFrame: (NSRect)frame view: (NSView*)view;
|
||||||
|
|
|
@ -38,33 +38,40 @@
|
||||||
@class NSSound;
|
@class NSSound;
|
||||||
|
|
||||||
typedef enum _NSButtonType {
|
typedef enum _NSButtonType {
|
||||||
NSMomentaryPushButton,
|
NSMomentaryLightButton,
|
||||||
NSPushOnPushOffButton,
|
NSPushOnPushOffButton,
|
||||||
NSToggleButton,
|
NSToggleButton,
|
||||||
NSSwitchButton,
|
NSSwitchButton,
|
||||||
NSRadioButton,
|
NSRadioButton,
|
||||||
NSMomentaryChangeButton,
|
NSMomentaryChangeButton,
|
||||||
NSOnOffButton,
|
NSOnOffButton,
|
||||||
// These come from MacOSX
|
NSMomentaryPushInButton,
|
||||||
NSMomentaryLight,
|
// These are old names
|
||||||
NSMomentaryLightButton = NSMomentaryLight,
|
NSMomentaryLight = NSMomentaryPushInButton,
|
||||||
NSMomentaryPushInButton = NSMomentaryPushButton
|
NSMomentaryPushButton = NSMomentaryLightButton
|
||||||
} NSButtonType;
|
} NSButtonType;
|
||||||
|
|
||||||
typedef enum _NSBezelStyle {
|
typedef enum _NSBezelStyle {
|
||||||
NSRoundedBezelStyle,
|
NSRoundedBezelStyle = 1,
|
||||||
NSRegularSquareBezelStyle,
|
NSRegularSquareBezelStyle,
|
||||||
NSThickSquareBezelStyle,
|
NSThickSquareBezelStyle,
|
||||||
NSThickerSquareBezelStyle,
|
NSThickerSquareBezelStyle,
|
||||||
|
NSDisclosureBezelStyle,
|
||||||
|
NSShadowlessSquareBezelStyle,
|
||||||
|
NSCircularBezelStyle,
|
||||||
|
NSTexturedSquareBezelStyle,
|
||||||
|
NSHelpButtonBezelStyle,
|
||||||
|
NSSmallSquareBezelStyle,
|
||||||
|
NSTexturedRoundBezelStyle,
|
||||||
|
NSRoundRectBezelStyle,
|
||||||
|
NSRecessedBezelStyle,
|
||||||
|
NSRoundedDisclosureBezelStyle,
|
||||||
// The next five no longer show up in the MacOSX documentation
|
// The next five no longer show up in the MacOSX documentation
|
||||||
NSNeXTBezelStyle,
|
NSNeXTBezelStyle,
|
||||||
NSPushButtonBezelStyle,
|
NSPushButtonBezelStyle,
|
||||||
NSSmallIconButtonBezelStyle,
|
NSSmallIconButtonBezelStyle,
|
||||||
NSMediumIconButtonBezelStyle,
|
NSMediumIconButtonBezelStyle,
|
||||||
NSLargeIconButtonBezelStyle,
|
NSLargeIconButtonBezelStyle
|
||||||
// But those two do
|
|
||||||
NSShadowlessSquareBezelStyle,
|
|
||||||
NSCircularBezelStyle
|
|
||||||
} NSBezelStyle;
|
} NSBezelStyle;
|
||||||
|
|
||||||
typedef enum _NSGradientType {
|
typedef enum _NSGradientType {
|
||||||
|
@ -91,11 +98,12 @@ typedef enum _NSGradientType {
|
||||||
float _repeatInterval;
|
float _repeatInterval;
|
||||||
NSBezelStyle _bezel_style;
|
NSBezelStyle _bezel_style;
|
||||||
NSGradientType _gradient_type;
|
NSGradientType _gradient_type;
|
||||||
BOOL _shows_border_only_while_mouse_inside;
|
NSColor *_backgroundColor;
|
||||||
BOOL _mouse_inside;
|
|
||||||
// Think of the following as a BOOL ivars
|
// Think of the following as a BOOL ivars
|
||||||
#define _buttoncell_is_transparent _cell.subclass_bool_one
|
#define _buttoncell_is_transparent _cell.subclass_bool_one
|
||||||
#define _image_dims_when_disabled _cell.subclass_bool_two
|
#define _image_dims_when_disabled _cell.subclass_bool_two
|
||||||
|
#define _shows_border_only_while_mouse_inside _cell.subclass_bool_three
|
||||||
|
#define _mouse_inside _cell.subclass_bool_four
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -161,6 +169,17 @@ typedef enum _NSGradientType {
|
||||||
- (BOOL)imageDimsWhenDisabled;
|
- (BOOL)imageDimsWhenDisabled;
|
||||||
- (void)setImageDimsWhenDisabled:(BOOL)flag;
|
- (void)setImageDimsWhenDisabled:(BOOL)flag;
|
||||||
#endif
|
#endif
|
||||||
|
#if OS_API_VERSION(MAC_OS_X_VERSION_10_4, GS_API_LATEST)
|
||||||
|
- (NSColor *)backgroundColor;
|
||||||
|
- (void)setBackgroundColor:(NSColor *)color;
|
||||||
|
- (void)drawBezelWithFrame:(NSRect)frame inView:(NSView *)control;
|
||||||
|
- (void)drawImage:(NSImage*)imageToDisplay
|
||||||
|
withFrame:(NSRect)frame
|
||||||
|
inView:(NSView *)control;
|
||||||
|
- (void)drawTitle:(NSAttributedString*)titleToDisplay
|
||||||
|
withFrame:(NSRect)frame
|
||||||
|
inView:(NSView *)control;
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Modifying Graphic Attributes
|
// Modifying Graphic Attributes
|
||||||
|
|
|
@ -691,15 +691,14 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
@implementation GSTheme (Drawing)
|
@implementation GSTheme (Drawing)
|
||||||
|
|
||||||
- (NSRect) drawButton: (NSRect)frame
|
- (void) drawButton: (NSRect)frame
|
||||||
in: (NSButtonCell*)cell
|
in: (NSButtonCell*)cell
|
||||||
view: (NSView*)view
|
view: (NSView*)view
|
||||||
style: (int)style
|
style: (int)style
|
||||||
state: (GSThemeControlState)state
|
state: (GSThemeControlState)state
|
||||||
{
|
{
|
||||||
GSDrawTiles *tiles = nil;
|
GSDrawTiles *tiles = nil;
|
||||||
NSColor *color = nil;
|
NSColor *color = nil;
|
||||||
NSRect interiorFrame;
|
|
||||||
|
|
||||||
if (state == GSThemeNormalState)
|
if (state == GSThemeNormalState)
|
||||||
{
|
{
|
||||||
|
@ -719,7 +718,6 @@ static NSNull *null = nil;
|
||||||
|
|
||||||
if (tiles == nil)
|
if (tiles == nil)
|
||||||
{
|
{
|
||||||
interiorFrame = [cell drawingRectForBounds: frame];
|
|
||||||
[color set];
|
[color set];
|
||||||
NSRectFill(frame);
|
NSRectFill(frame);
|
||||||
|
|
||||||
|
@ -730,21 +728,50 @@ static NSNull *null = nil;
|
||||||
else if (state == GSThemeSelectedState)
|
else if (state == GSThemeSelectedState)
|
||||||
{
|
{
|
||||||
[self drawGrayBezel: frame withClip: NSZeroRect];
|
[self drawGrayBezel: frame withClip: NSZeroRect];
|
||||||
interiorFrame
|
|
||||||
= NSOffsetRect(interiorFrame, 1.0, [view isFlipped] ? 1.0 : -1.0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Use tiles to draw button border with central part filled with color
|
/* Use tiles to draw button border with central part filled with color
|
||||||
*/
|
*/
|
||||||
interiorFrame = [self fillRect: frame
|
[self fillRect: frame
|
||||||
withTiles: tiles
|
withTiles: tiles
|
||||||
background: color
|
background: color
|
||||||
fillStyle: GSThemeFillStyleNone];
|
fillStyle: GSThemeFillStyleNone];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSSize) buttonBorderForStyle: (int)style
|
||||||
|
state: (GSThemeControlState)state
|
||||||
|
{
|
||||||
|
GSDrawTiles *tiles = nil;
|
||||||
|
NSRect interiorFrame;
|
||||||
|
|
||||||
|
if (state == GSThemeNormalState)
|
||||||
|
{
|
||||||
|
tiles = [self tilesNamed: @"NSButtonNormal" cache: YES];
|
||||||
|
}
|
||||||
|
else if (state == GSThemeHighlightedState)
|
||||||
|
{
|
||||||
|
tiles = [self tilesNamed: @"NSButtonHighlighted" cache: YES];
|
||||||
|
}
|
||||||
|
else if (state == GSThemeSelectedState)
|
||||||
|
{
|
||||||
|
tiles = [self tilesNamed: @"NSButtonPushed" cache: YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
return interiorFrame;
|
if (tiles == nil)
|
||||||
|
{
|
||||||
|
// FIXME: Should take style into account
|
||||||
|
return NSMakeSize(3, 3);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSSize cls = tiles->rects[TileCL].size;
|
||||||
|
NSSize bms = tiles->rects[TileBM].size;
|
||||||
|
|
||||||
|
return NSMakeSize(cls.width, bms.height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view
|
- (void) drawFocusFrame: (NSRect) frame view: (NSView*) view
|
||||||
|
|
|
@ -103,12 +103,6 @@ typedef struct _GSButtonCellFlags
|
||||||
#endif
|
#endif
|
||||||
} GSButtonCellFlags;
|
} GSButtonCellFlags;
|
||||||
|
|
||||||
@interface NSButtonCell (Private)
|
|
||||||
// Overriden private internal method
|
|
||||||
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect
|
|
||||||
isFlipped: (BOOL)flipped;
|
|
||||||
@end
|
|
||||||
|
|
||||||
/**<p> TODO Description</p>
|
/**<p> TODO Description</p>
|
||||||
*/
|
*/
|
||||||
@implementation NSButtonCell
|
@implementation NSButtonCell
|
||||||
|
@ -119,7 +113,7 @@ typedef struct _GSButtonCellFlags
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSButtonCell class])
|
if (self == [NSButtonCell class])
|
||||||
[self setVersion: 1];
|
[self setVersion: 2];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -130,19 +124,16 @@ typedef struct _GSButtonCellFlags
|
||||||
// Implicitly performed by allocation:
|
// Implicitly performed by allocation:
|
||||||
//
|
//
|
||||||
//_buttoncell_is_transparent = NO;
|
//_buttoncell_is_transparent = NO;
|
||||||
//_altContents = nil;
|
|
||||||
|
|
||||||
[self setAlignment: NSCenterTextAlignment];
|
[self setAlignment: NSCenterTextAlignment];
|
||||||
_cell.is_bordered = YES;
|
_cell.is_bordered = YES;
|
||||||
_showAltStateMask = NSNoCellMask; // configure as a NSMomentaryPushButton
|
[self setButtonType: NSMomentaryPushInButton];
|
||||||
_highlightsByMask = NSPushInCellMask | NSChangeGrayCellMask;
|
|
||||||
_delayInterval = 0.4;
|
_delayInterval = 0.4;
|
||||||
_repeatInterval = 0.075;
|
_repeatInterval = 0.075;
|
||||||
_keyEquivalentModifierMask = NSCommandKeyMask;
|
_keyEquivalentModifierMask = NSCommandKeyMask;
|
||||||
_keyEquivalent = @"";
|
_keyEquivalent = @"";
|
||||||
_altContents = @"";
|
_altContents = @"";
|
||||||
_gradient_type = NSGradientNone;
|
_gradient_type = NSGradientNone;
|
||||||
_image_dims_when_disabled = NO;
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -175,6 +166,7 @@ typedef struct _GSButtonCellFlags
|
||||||
RELEASE(_keyEquivalent);
|
RELEASE(_keyEquivalent);
|
||||||
RELEASE(_keyEquivalentFont);
|
RELEASE(_keyEquivalentFont);
|
||||||
RELEASE(_sound);
|
RELEASE(_sound);
|
||||||
|
RELEASE(_backgroundColor);
|
||||||
|
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -387,7 +379,7 @@ typedef struct _GSButtonCellFlags
|
||||||
- (void)setTitleWithMnemonic:(NSString *)aString
|
- (void)setTitleWithMnemonic:(NSString *)aString
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
[super setTitleWithMnemonic: aString];
|
[super setTitleWithMnemonic: aString];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString *)alternateMnemonic
|
- (NSString *)alternateMnemonic
|
||||||
|
@ -704,7 +696,7 @@ typedef struct _GSButtonCellFlags
|
||||||
[self setShowsStateBy: NSNoCellMask];
|
[self setShowsStateBy: NSNoCellMask];
|
||||||
[self setImageDimsWhenDisabled: YES];
|
[self setImageDimsWhenDisabled: YES];
|
||||||
break;
|
break;
|
||||||
case NSMomentaryPushButton:
|
case NSMomentaryPushInButton:
|
||||||
[self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask];
|
[self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask];
|
||||||
[self setShowsStateBy: NSNoCellMask];
|
[self setShowsStateBy: NSNoCellMask];
|
||||||
[self setImageDimsWhenDisabled: YES];
|
[self setImageDimsWhenDisabled: YES];
|
||||||
|
@ -834,23 +826,21 @@ typedef struct _GSButtonCellFlags
|
||||||
return [NSColor controlTextColor];
|
return [NSColor controlTextColor];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
- (NSColor *) backgroundColor
|
||||||
|
{
|
||||||
|
return _backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setBackgroundColor: (NSColor *)color
|
||||||
|
{
|
||||||
|
ASSIGN(_backgroundColor, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawBezelWithFrame: (NSRect)cellFrame inView: (NSView *)controlView
|
||||||
{
|
{
|
||||||
unsigned mask;
|
unsigned mask;
|
||||||
GSThemeControlState buttonState = GSThemeNormalState;
|
GSThemeControlState buttonState = GSThemeNormalState;
|
||||||
|
|
||||||
// Save last view drawn to
|
|
||||||
if (_control_view != controlView)
|
|
||||||
_control_view = controlView;
|
|
||||||
|
|
||||||
// transparent buttons never draw
|
|
||||||
if (_buttoncell_is_transparent)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// do nothing if cell's frame rect is zero
|
|
||||||
if (NSIsEmptyRect(cellFrame))
|
|
||||||
return;
|
|
||||||
|
|
||||||
// set the mask
|
// set the mask
|
||||||
if (_cell.is_highlighted)
|
if (_cell.is_highlighted)
|
||||||
{
|
{
|
||||||
|
@ -865,35 +855,91 @@ typedef struct _GSButtonCellFlags
|
||||||
else
|
else
|
||||||
mask = NSNoCellMask;
|
mask = NSNoCellMask;
|
||||||
|
|
||||||
/* Draw the cell's background color.
|
/* Determine the background color.
|
||||||
We draw when there is a border or when highlightsByMask
|
We draw when there is a border or when highlightsByMask
|
||||||
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
|
is NSChangeBackgroundCellMask or NSChangeGrayCellMask,
|
||||||
as required by our nextstep-like look and feel. */
|
as required by our nextstep-like look and feel. */
|
||||||
if (_cell.is_bordered
|
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
||||||
|| (_highlightsByMask & NSChangeBackgroundCellMask)
|
|
||||||
|| (_highlightsByMask & NSChangeGrayCellMask))
|
|
||||||
{
|
{
|
||||||
/* Determine the background color. */
|
buttonState = GSThemeHighlightedState;
|
||||||
if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask))
|
|
||||||
{
|
|
||||||
buttonState = GSThemeHighlightedState;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||||
if (_cell.is_bordered && (mask & NSPushInCellMask))
|
if (mask & NSPushInCellMask)
|
||||||
{
|
{
|
||||||
buttonState = GSThemeSelectedState;
|
buttonState = GSThemeSelectedState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[GSTheme theme] drawButton: cellFrame
|
||||||
|
in: self
|
||||||
|
view: controlView
|
||||||
|
style: _bezel_style
|
||||||
|
state: buttonState];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawImage: (NSImage*)anImage
|
||||||
|
withFrame: (NSRect)aRect
|
||||||
|
inView: (NSView*)controlView
|
||||||
|
{
|
||||||
|
// Draw image
|
||||||
|
if (anImage != nil)
|
||||||
|
{
|
||||||
|
NSSize size;
|
||||||
|
NSPoint position;
|
||||||
|
|
||||||
|
size = [anImage size];
|
||||||
|
position.x = MAX(NSMidX(aRect) - (size.width / 2.), 0.);
|
||||||
|
position.y = MAX(NSMidY(aRect) - (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_cell.is_disabled && _image_dims_when_disabled)
|
||||||
|
{
|
||||||
|
[anImage dissolveToPoint: position fraction: 0.5];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[anImage compositeToPoint: position
|
||||||
|
operation: NSCompositeSourceOver];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) drawTitle: (NSAttributedString*)titleToDisplay
|
||||||
|
withFrame: (NSRect)frame
|
||||||
|
inView: (NSView*)control
|
||||||
|
{
|
||||||
|
[self _drawAttributedText: titleToDisplay
|
||||||
|
inFrame: frame];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
||||||
|
{
|
||||||
|
// Save last view drawn to
|
||||||
|
if (_control_view != controlView)
|
||||||
|
_control_view = controlView;
|
||||||
|
|
||||||
|
// transparent buttons never draw
|
||||||
|
if (_buttoncell_is_transparent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// do nothing if cell's frame rect is zero
|
||||||
|
if (NSIsEmptyRect(cellFrame))
|
||||||
|
return;
|
||||||
|
|
||||||
// draw the border if needed
|
// draw the border if needed
|
||||||
if ((_cell.is_bordered)
|
if ((_cell.is_bordered)
|
||||||
&& (!_shows_border_only_while_mouse_inside || _mouse_inside))
|
&& (!_shows_border_only_while_mouse_inside || _mouse_inside))
|
||||||
{
|
{
|
||||||
cellFrame = [[GSTheme theme]
|
[self drawBezelWithFrame: cellFrame inView: controlView];
|
||||||
drawButton: cellFrame in: self view: controlView
|
|
||||||
style: _bezel_style
|
|
||||||
state: buttonState];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||||
|
@ -902,7 +948,9 @@ typedef struct _GSButtonCellFlags
|
||||||
if (_cell.shows_first_responder
|
if (_cell.shows_first_responder
|
||||||
&& [[controlView window] firstResponder] == controlView)
|
&& [[controlView window] firstResponder] == controlView)
|
||||||
{
|
{
|
||||||
[[GSTheme theme] drawFocusFrame: cellFrame view: controlView];
|
// FIXME: Should depend on _cell.focus_ring_type
|
||||||
|
[[GSTheme theme] drawFocusFrame: [self drawingRectForBounds: cellFrame]
|
||||||
|
view: controlView];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1231,21 +1279,22 @@ typedef struct _GSButtonCellFlags
|
||||||
// Draw gradient
|
// Draw gradient
|
||||||
if (!_cell.is_highlighted && _gradient_type != NSGradientNone)
|
if (!_cell.is_highlighted && _gradient_type != NSGradientNone)
|
||||||
{
|
{
|
||||||
|
// FIXME: I think this method is wrong.
|
||||||
[self drawGradientWithFrame: cellFrame inView: controlView];
|
[self drawGradientWithFrame: cellFrame inView: controlView];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw image
|
// Draw image
|
||||||
if (imageToDisplay != nil)
|
if (imageToDisplay != nil)
|
||||||
{
|
{
|
||||||
[self _drawImage: imageToDisplay
|
[self drawImage: imageToDisplay
|
||||||
inFrame: imageRect
|
withFrame: imageRect
|
||||||
isFlipped: flippedView];
|
inView: controlView];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw title
|
// Draw title
|
||||||
if (titleToDisplay != nil)
|
if (titleToDisplay != nil)
|
||||||
{
|
{
|
||||||
[self _drawAttributedText: titleToDisplay inFrame: titleRect];
|
[self drawTitle: titleToDisplay withFrame: titleRect inView: controlView];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1334,40 +1383,83 @@ typedef struct _GSButtonCellFlags
|
||||||
|
|
||||||
// Get border size
|
// Get border size
|
||||||
if (_cell.is_bordered)
|
if (_cell.is_bordered)
|
||||||
// Buttons only have three paths for border (NeXT looks)
|
{
|
||||||
borderSize = NSMakeSize (3.0, 3.0);
|
GSThemeControlState buttonState = GSThemeNormalState;
|
||||||
|
|
||||||
|
/* 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))
|
||||||
|
{
|
||||||
|
buttonState = GSThemeHighlightedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||||
|
if (mask & NSPushInCellMask)
|
||||||
|
{
|
||||||
|
buttonState = GSThemeSelectedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
borderSize = [[GSTheme theme] buttonBorderForStyle: _bezel_style
|
||||||
|
state: buttonState];
|
||||||
|
}
|
||||||
else
|
else
|
||||||
borderSize = NSZeroSize;
|
borderSize = NSZeroSize;
|
||||||
|
|
||||||
if ((_cell.is_bordered && (_cell.image_position != NSImageOnly))
|
|
||||||
|| _cell.is_bezeled)
|
|
||||||
{
|
|
||||||
borderSize.width += 6;
|
|
||||||
borderSize.height += 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add border size
|
// Add border size
|
||||||
s.width += borderSize.width;
|
s.width += 2 * borderSize.width;
|
||||||
s.height += borderSize.height;
|
s.height += 2 * borderSize.height;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSRect) drawingRectForBounds: (NSRect)theRect
|
- (NSRect) drawingRectForBounds: (NSRect)theRect
|
||||||
{
|
{
|
||||||
// FIXME
|
|
||||||
if (_cell.is_bordered)
|
if (_cell.is_bordered)
|
||||||
{
|
{
|
||||||
/*
|
NSSize borderSize;
|
||||||
* Special case: Buttons have only three different paths for border.
|
unsigned mask;
|
||||||
* One white path at the top left corner, one black path at the
|
GSThemeControlState buttonState = GSThemeNormalState;
|
||||||
* bottom right and another in dark gray at the inner bottom right.
|
NSRect interiorFrame;
|
||||||
*/
|
|
||||||
float yDelta = [_control_view isFlipped] ? 1. : 2.;
|
if (_cell.is_highlighted)
|
||||||
return NSMakeRect (theRect.origin.x + 1.,
|
{
|
||||||
theRect.origin.y + yDelta,
|
mask = _highlightsByMask;
|
||||||
theRect.size.width - 3.,
|
|
||||||
theRect.size.height - 3.);
|
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))
|
||||||
|
{
|
||||||
|
buttonState = GSThemeHighlightedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mask & NSPushInCellMask)
|
||||||
|
{
|
||||||
|
buttonState = GSThemeSelectedState;
|
||||||
|
}
|
||||||
|
|
||||||
|
borderSize = [[GSTheme theme] buttonBorderForStyle: _bezel_style
|
||||||
|
state: buttonState];
|
||||||
|
interiorFrame = NSInsetRect(theRect, borderSize.width, borderSize.height);
|
||||||
|
|
||||||
|
/* Pushed in buttons contents are displaced to the bottom right 1px. */
|
||||||
|
if (mask & NSPushInCellMask)
|
||||||
|
{
|
||||||
|
interiorFrame
|
||||||
|
= NSOffsetRect(interiorFrame, 1.0, [_control_view isFlipped] ? 1.0 : -1.0);
|
||||||
|
}
|
||||||
|
return interiorFrame;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1431,11 +1523,12 @@ typedef struct _GSButtonCellFlags
|
||||||
{
|
{
|
||||||
NSButtonCell *c = [super copyWithZone: zone];
|
NSButtonCell *c = [super copyWithZone: zone];
|
||||||
|
|
||||||
/* Hmmm. */
|
|
||||||
c->_altContents = [_altContents copyWithZone: zone];
|
c->_altContents = [_altContents copyWithZone: zone];
|
||||||
TEST_RETAIN (_altImage);
|
TEST_RETAIN(_altImage);
|
||||||
TEST_RETAIN (_keyEquivalent);
|
TEST_RETAIN(_keyEquivalent);
|
||||||
TEST_RETAIN (_keyEquivalentFont);
|
TEST_RETAIN(_keyEquivalentFont);
|
||||||
|
TEST_RETAIN(_sound);
|
||||||
|
TEST_RETAIN(_backgroundColor);
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
@ -1534,7 +1627,6 @@ typedef struct _GSButtonCellFlags
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// FIXME: Add new ivars
|
|
||||||
[aCoder encodeObject: _keyEquivalent];
|
[aCoder encodeObject: _keyEquivalent];
|
||||||
[aCoder encodeObject: _keyEquivalentFont];
|
[aCoder encodeObject: _keyEquivalentFont];
|
||||||
[aCoder encodeObject: _altContents];
|
[aCoder encodeObject: _altContents];
|
||||||
|
@ -1548,7 +1640,23 @@ typedef struct _GSButtonCellFlags
|
||||||
at: &_highlightsByMask];
|
at: &_highlightsByMask];
|
||||||
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
||||||
at: &_showAltStateMask];
|
at: &_showAltStateMask];
|
||||||
|
|
||||||
|
[aCoder encodeObject: _sound];
|
||||||
|
[aCoder encodeObject: _backgroundColor];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(float)
|
||||||
|
at: &_delayInterval];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(float)
|
||||||
|
at: &_repeatInterval];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
||||||
|
at: &_bezel_style];
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(unsigned int)
|
||||||
|
at: &_gradient_type];
|
||||||
|
tmp = _image_dims_when_disabled;
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(BOOL)
|
||||||
|
at: &tmp];
|
||||||
|
tmp = _shows_border_only_while_mouse_inside;
|
||||||
|
[aCoder encodeValueOfObjCType: @encode(BOOL)
|
||||||
|
at: &tmp];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1608,7 +1716,7 @@ typedef struct _GSButtonCellFlags
|
||||||
[self setShowsBorderOnlyWhileMouseInside: (bFlags2 & 0x8)];
|
[self setShowsBorderOnlyWhileMouseInside: (bFlags2 & 0x8)];
|
||||||
|
|
||||||
// FIXME
|
// FIXME
|
||||||
switch (bFlags2 & 0x7)
|
switch (bFlags2 & 0x27)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
[self setBezelStyle: NSRoundedBezelStyle];
|
[self setBezelStyle: NSRoundedBezelStyle];
|
||||||
|
@ -1623,7 +1731,7 @@ typedef struct _GSButtonCellFlags
|
||||||
[self setBezelStyle: NSThickerSquareBezelStyle];
|
[self setBezelStyle: NSThickerSquareBezelStyle];
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
//[self setBezelStyle: NSDisclosureBezelStyle];
|
[self setBezelStyle: NSDisclosureBezelStyle];
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
[self setBezelStyle: NSShadowlessSquareBezelStyle];
|
[self setBezelStyle: NSShadowlessSquareBezelStyle];
|
||||||
|
@ -1631,14 +1739,12 @@ typedef struct _GSButtonCellFlags
|
||||||
case 7:
|
case 7:
|
||||||
[self setBezelStyle: NSCircularBezelStyle];
|
[self setBezelStyle: NSCircularBezelStyle];
|
||||||
break;
|
break;
|
||||||
/*
|
|
||||||
case 32:
|
case 32:
|
||||||
[self setBezelStyle: NSTexturedSquareBezelStyle];
|
[self setBezelStyle: NSTexturedSquareBezelStyle];
|
||||||
break;
|
break;
|
||||||
case 33:
|
case 33:
|
||||||
[self setBezelStyle: NSHelpButtonBezelStyle];
|
[self setBezelStyle: NSHelpButtonBezelStyle];
|
||||||
break;
|
break;
|
||||||
*/
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1689,7 +1795,6 @@ typedef struct _GSButtonCellFlags
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// FIXME: Add new ivars
|
|
||||||
BOOL tmp;
|
BOOL tmp;
|
||||||
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(id) at: &_keyEquivalent];
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_keyEquivalent];
|
||||||
|
@ -1704,45 +1809,24 @@ typedef struct _GSButtonCellFlags
|
||||||
at: &_highlightsByMask];
|
at: &_highlightsByMask];
|
||||||
[aDecoder decodeValueOfObjCType: @encode(unsigned int)
|
[aDecoder decodeValueOfObjCType: @encode(unsigned int)
|
||||||
at: &_showAltStateMask];
|
at: &_showAltStateMask];
|
||||||
|
|
||||||
|
if ([aDecoder versionForClassName: @"NSButtonCell"] >= 2)
|
||||||
|
{
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_sound];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_backgroundColor];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_delayInterval];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(float) at: &_repeatInterval];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(unsigned int)
|
||||||
|
at: &_bezel_style];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(unsigned int)
|
||||||
|
at: &_gradient_type];
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp];
|
||||||
|
_image_dims_when_disabled = tmp;
|
||||||
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &tmp];
|
||||||
|
_shows_border_only_while_mouse_inside = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation NSButtonCell (Private)
|
|
||||||
|
|
||||||
// Overriden private internal method
|
|
||||||
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect
|
|
||||||
isFlipped: (BOOL)flipped
|
|
||||||
{
|
|
||||||
// To keep partially in sync with the NSCell overriden method
|
|
||||||
|
|
||||||
NSSize size;
|
|
||||||
NSPoint position;
|
|
||||||
|
|
||||||
size = [anImage size];
|
|
||||||
position.x = MAX(NSMidX(aRect) - (size.width / 2.), 0.);
|
|
||||||
position.y = MAX(NSMidY(aRect) - (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 (flipped)
|
|
||||||
{
|
|
||||||
position.y += size.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_cell.is_disabled && _image_dims_when_disabled)
|
|
||||||
{
|
|
||||||
[anImage dissolveToPoint: position fraction: 0.5];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[anImage compositeToPoint: position
|
|
||||||
operation: NSCompositeSourceOver];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1989,12 +1989,6 @@ static NSColor *shadowCol;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_cell.shows_first_responder)
|
|
||||||
{
|
|
||||||
// FIXME: Should depend on _cell.focus_ring_type
|
|
||||||
NSDottedFrameRect(cellFrame);
|
|
||||||
}
|
|
||||||
|
|
||||||
// NB: We don't do any highlighting to make it easier for subclasses
|
// NB: We don't do any highlighting to make it easier for subclasses
|
||||||
// to reuse this code while doing their own custom highlighting and
|
// to reuse this code while doing their own custom highlighting and
|
||||||
// prettyfying
|
// prettyfying
|
||||||
|
@ -2020,6 +2014,15 @@ static NSColor *shadowCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
||||||
|
|
||||||
|
// Draw first responder
|
||||||
|
if (_cell.shows_first_responder
|
||||||
|
&& [[controlView window] firstResponder] == controlView)
|
||||||
|
{
|
||||||
|
// FIXME: Should depend on _cell.focus_ring_type
|
||||||
|
[[GSTheme theme] drawFocusFrame: [self drawingRectForBounds: cellFrame]
|
||||||
|
view: controlView];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**<p>Sets whether the NSCell is highlighted.</p>
|
/**<p>Sets whether the NSCell is highlighted.</p>
|
||||||
|
|
|
@ -797,7 +797,23 @@ static NSImage *arrowImage = nil; /* Cache arrow image. */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return [super drawingRectForBounds: theRect];
|
if (_cell.is_bordered)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Special case: Buttons have only three different paths for border.
|
||||||
|
* One white path at the top left corner, one black path at the
|
||||||
|
* bottom right and another in dark gray at the inner bottom right.
|
||||||
|
*/
|
||||||
|
float yDelta = [_control_view isFlipped] ? 1. : 2.;
|
||||||
|
return NSMakeRect (theRect.origin.x + 1.,
|
||||||
|
theRect.origin.y + yDelta,
|
||||||
|
theRect.size.width - 3.,
|
||||||
|
theRect.size.height - 3.);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return theRect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -454,33 +454,10 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overriden NSButtonCell method
|
// Overriden NSButtonCell method
|
||||||
- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect isFlipped: (BOOL)flipped
|
- (void) drawImage: (NSImage *)anImage withFrame: (NSRect)aRect inView: (NSView*)controlView
|
||||||
{
|
{
|
||||||
NSSize size;
|
|
||||||
NSPoint position;
|
|
||||||
|
|
||||||
// We ignore aRect value
|
// We ignore aRect value
|
||||||
|
[super drawImage: anImage withFrame: imageRect inView: controlView];
|
||||||
size = [anImage size];
|
|
||||||
position.x = MAX(NSMidX(imageRect) - (size.width / 2.), 0.);
|
|
||||||
position.y = MAX(NSMidY(imageRect) - (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 (flipped)
|
|
||||||
{
|
|
||||||
position.y += size.height;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_cell.is_disabled && _image_dims_when_disabled)
|
|
||||||
{
|
|
||||||
[anImage dissolveToPoint: position fraction: 0.5];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[anImage compositeToPoint: position
|
|
||||||
operation: NSCompositeSourceOver];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue