Index: Source/GSTheme.m =================================================================== --- Source/GSTheme.m (revision 25093) +++ Source/GSTheme.m (working copy) @@ -43,6 +43,7 @@ #include "AppKit/NSImageView.h" #include "AppKit/NSMatrix.h" #include "AppKit/NSMenu.h" +#include "AppKit/NSMenuView.h" #include "AppKit/NSPanel.h" #include "AppKit/NSScrollView.h" #include "AppKit/NSTextContainer.h" @@ -613,7 +614,7 @@ * VerticalDivision Where to divide the image into rows. */ info = [self infoDictionary]; - info = [[info objectForKey: @"GSThemeTiles"] objectForKey: aName]; + info = [(NSDictionary*)[info objectForKey: @"GSThemeTiles"] objectForKey: aName]; if ([info isKindOfClass: [NSDictionary class]] == YES) { float x; @@ -691,8 +692,13 @@ } @end - +// This is the default scrollbar width +static const float defaultScrollerWidth = 18; + +// This is the default scrollbar color. +static NSColor *scrollBarColor = nil; + @implementation GSTheme (Drawing) - (void) drawButton: (NSRect)frame @@ -786,6 +792,16 @@ } } +- (NSRect) buttonContentRect:(NSRect)frame + forStyle:(int)style + state:(GSThemeControlState)state +{ + NSSize borderSize; + + borderSize = [self buttonBorderForStyle:style state:state]; + return NSInsetRect(frame, borderSize.width, borderSize.height); +} + - (NSSize) buttonBorderForStyle: (int)style state: (GSThemeControlState)state { @@ -858,10 +874,129 @@ NSRectFill (frame); } +- (void) drawMenuViewBackground:(NSRect) frame view:(NSMenuView*)view +{ + NSRectEdge sides[2]; + float grays[] = {NSDarkGray, NSDarkGray}; + + if ([view isHorizontal] == YES) + { + sides[0] = NSMinYEdge; + sides[1] = NSMinYEdge; + NSDrawTiledRects(frame, frame, sides, grays, 2); + } + else + { + sides[0] = NSMinXEdge; + sides[1] = NSMaxYEdge; + // Draw the dark gray upper left lines. + NSDrawTiledRects(frame, frame, sides, grays, 2); + } +} + +- (void) drawMenuItemBorderAndBackground:(NSRect)frame + in:(NSMenuItemCell*)cell + view:(NSView*) view + state:(GSThemeControlState)state +{ + + if ([[cell menuView] isHorizontal] == YES) + { + frame = [cell drawingRectForBounds: frame]; + [[cell backgroundColor] set]; + NSRectFill(frame); + return; + } + + // Set cell's background color + [[cell backgroundColor] set]; + NSRectFill(frame); + + if (![cell isBordered]) + return; + + if (state==GSThemeHighlightedState && ([cell cellAttribute:NSPushInCell] & NSPushInCellMask)) + { + [[GSTheme theme] drawGrayBezel: frame withClip: NSZeroRect]; + } + else + { + [[GSTheme theme] drawButton: frame withClip: NSZeroRect]; + } + +} + +- (float) defaultScrollerWidth +{ + return defaultScrollerWidth; +} + +- (NSButtonCell*) cellForScrollerArrow:(NSScrollerArrow)arrow horizontal:(BOOL)horizontal +{ + NSButtonCell* cell; + + cell = [NSButtonCell new]; + if (horizontal) + { + if (arrow==NSScrollerDecrementArrow) + { + [cell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; + [cell setImage: [NSImage imageNamed: @"common_ArrowLeft"]]; + [cell setAlternateImage: [NSImage imageNamed: @"common_ArrowLeftH"]]; + [cell setImagePosition: NSImageOnly]; + } + else + { + [cell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; + [cell setImage: [NSImage imageNamed: @"common_ArrowRight"]]; + [cell setAlternateImage: [NSImage imageNamed: @"common_ArrowRightH"]]; + [cell setImagePosition: NSImageOnly]; + } + } + else + { + if (arrow==NSScrollerDecrementArrow) + { + [cell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; + [cell setImage: [NSImage imageNamed: @"common_ArrowUp"]]; + [cell setAlternateImage: [NSImage imageNamed: @"common_ArrowUpH"]]; + [cell setImagePosition: NSImageOnly]; + } + else + { + [cell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; + [cell setImage: [NSImage imageNamed: @"common_ArrowDown"]]; + [cell setAlternateImage: [NSImage imageNamed: @"common_ArrowDownH"]]; + [cell setImagePosition: NSImageOnly]; + } + } + return AUTORELEASE(cell); +} + +- (NSCell*) cellForScrollerKnob:(BOOL)horizontal +{ + NSButtonCell* knobCell; + knobCell = [NSButtonCell new]; + [knobCell setButtonType: NSMomentaryChangeButton]; + [knobCell setImage: [NSImage imageNamed: @"common_Dimple"]]; + [knobCell setImagePosition: NSImageOnly]; + return knobCell; +} + +- (NSCell*) cellForScrollerKnobSlot:(BOOL)horizontal +{ + NSButtonCell *cell; + if (scrollBarColor==nil) + scrollBarColor = [NSColor scrollBarColor]; + + cell = [NSButtonCell new]; + [cell setBordered:NO]; + [cell setBackgroundColor:scrollBarColor]; + return AUTORELEASE(cell); +} + @end - - @implementation GSTheme (MidLevelDrawing) - (NSRect) drawButton: (NSRect)border withClip: (NSRect)clip Index: Source/NSButtonCell.m =================================================================== --- Source/NSButtonCell.m (revision 25093) +++ Source/NSButtonCell.m (working copy) @@ -190,7 +190,7 @@ } /**

Returns the NSButtonCell's title.

-

See Also: -setTitle: [NSCell-stringValue]

+

See Also: -setTitle: [NSCell-stringValue]

*/ - (NSString*) title { @@ -198,7 +198,7 @@ } /**

Returns the NSButtonCell's alternate title ( used when highlighted ). -

See Also: -setAlternateTitle:

+

See Also: -setAlternateTitle:

*/ - (NSString*) alternateTitle { @@ -210,39 +210,39 @@ int value = 0; switch (aParameter) - { + { case NSPushInCell: if (_highlightsByMask & NSPushInCellMask) - value = 1; + value = 1; break; case NSChangeGrayCell: if (_showAltStateMask & NSChangeGrayCellMask) - value = 1; + value = 1; break; case NSCellLightsByGray: if (_highlightsByMask & NSChangeGrayCellMask) - value = 1; + value = 1; break; case NSChangeBackgroundCell: if (_showAltStateMask & NSChangeBackgroundCellMask) - value = 1; + value = 1; break; case NSCellLightsByBackground: if (_highlightsByMask & NSChangeBackgroundCellMask) - value = 1; + value = 1; break; case NSCellChangesContents: if (_showAltStateMask & NSContentsCellMask) - value = 1; + value = 1; break; case NSCellLightsByContents: if (_highlightsByMask & NSContentsCellMask) - value = 1; + value = 1; break; default: value = [super cellAttribute: aParameter]; break; - } + } return value; } @@ -250,58 +250,58 @@ - (void) setCellAttribute: (NSCellAttribute)aParameter to: (int)value { switch (aParameter) - { + { case NSPushInCell: if (value) - _highlightsByMask |= NSPushInCellMask; + _highlightsByMask |= NSPushInCellMask; else - _highlightsByMask &= ~NSPushInCellMask; + _highlightsByMask &= ~NSPushInCellMask; break; case NSChangeGrayCell: if (value) - _showAltStateMask |= NSChangeGrayCellMask; + _showAltStateMask |= NSChangeGrayCellMask; else - _showAltStateMask &= ~NSChangeGrayCellMask; + _showAltStateMask &= ~NSChangeGrayCellMask; break; case NSChangeBackgroundCell: if (value) - _showAltStateMask |= NSChangeBackgroundCellMask; + _showAltStateMask |= NSChangeBackgroundCellMask; else - _showAltStateMask &= ~NSChangeBackgroundCellMask; + _showAltStateMask &= ~NSChangeBackgroundCellMask; break; case NSCellChangesContents: if (value) - _showAltStateMask |= NSContentsCellMask; + _showAltStateMask |= NSContentsCellMask; else - _showAltStateMask &= ~NSContentsCellMask; + _showAltStateMask &= ~NSContentsCellMask; break; case NSCellLightsByGray: if (value) - _highlightsByMask |= NSChangeGrayCellMask; + _highlightsByMask |= NSChangeGrayCellMask; else - _highlightsByMask &= ~NSChangeGrayCellMask; + _highlightsByMask &= ~NSChangeGrayCellMask; break; case NSCellLightsByBackground: if (value) - _highlightsByMask |= NSChangeBackgroundCellMask; + _highlightsByMask |= NSChangeBackgroundCellMask; else - _highlightsByMask &= ~NSChangeBackgroundCellMask; + _highlightsByMask &= ~NSChangeBackgroundCellMask; break; case NSCellLightsByContents: if (value) - _highlightsByMask |= NSContentsCellMask; + _highlightsByMask |= NSContentsCellMask; else - _highlightsByMask &= ~NSContentsCellMask; + _highlightsByMask &= ~NSContentsCellMask; break; default: [super setCellAttribute: aParameter to: value]; - } + } } /**

Sets the NSButtonCell's font to fontObject. - The key equivalent font size is changed to match the fontObject - if needed.

See Also: [NSCell-font] -keyEquivalentFont - -setKeyEquivalentFont: -setKeyEquivalentFont:size:

+ The key equivalent font size is changed to match the fontObject + if needed.

See Also: [NSCell-font] -keyEquivalentFont + -setKeyEquivalentFont: -setKeyEquivalentFont:size:

*/ - (void) setFont: (NSFont*)fontObject { @@ -311,14 +311,14 @@ if ((_keyEquivalentFont != nil) && (fontObject != nil) && ((size = [fontObject pointSize]) != [_keyEquivalentFont pointSize])) - { - [self setKeyEquivalentFont: [_keyEquivalentFont fontName] - size: size]; - } + { + [self setKeyEquivalentFont: [_keyEquivalentFont fontName] + size: size]; + } } /**

Sets the NSButtonCell's title to aString.

-

See Also: -title [NSCell-setStringValue:]

+

See Also: -title [NSCell-setStringValue:]

*/ - (void) setTitle: (NSString*)aString { @@ -326,20 +326,20 @@ } /**

Sets the NSButtonCell's alternate title ( used when highlighted ) - to aString and update the cell if it contains - a NSControl view.

See Also: -alternateTitle

+ to aString and update the cell if it contains + a NSControl view.

See Also: -alternateTitle

*/ - (void) setAlternateTitle: (NSString*)aString { ASSIGNCOPY(_altContents, aString); if (_control_view) + { + if ([_control_view isKindOfClass: [NSControl class]]) { - if ([_control_view isKindOfClass: [NSControl class]]) - { - [(NSControl*)_control_view updateCell: self]; - } + [(NSControl*)_control_view updateCell: self]; } + } } - (NSAttributedString *)attributedAlternateTitle @@ -350,7 +350,7 @@ dict = [self _nonAutoreleasedTypingAttributes]; attrStr = [[NSAttributedString alloc] initWithString: _altContents - attributes: dict]; + attributes: dict]; RELEASE(dict); return AUTORELEASE(attrStr); @@ -360,9 +360,9 @@ { // TODO NSString *alternateTitle; - + alternateTitle = AUTORELEASE ([[aString string] copy]); - + [self setAlternateTitle: alternateTitle]; } @@ -404,13 +404,13 @@ unsigned int location = [aString rangeOfString: @"&"].location; [self setAlternateTitle: [aString stringByReplacingString: @"&" - withString: @""]]; + withString: @""]]; // TODO: We should underline this character [self setAlternateMnemonicLocation: location]; } /**

Returns the NSButtonCell's alternate image.

-

See Also: -setAlternateImage:

+

See Also: -setAlternateImage:

*/ - (NSImage*) alternateImage { @@ -418,8 +418,8 @@ } /**

Returns the NSButtonCell's image position. See NSCellImagePosition for more information. -

See Also: -setImagePosition:

+ id="NSCellImagePosition">NSCellImagePosition for more information. +

See Also: -setImagePosition:

*/ - (NSCellImagePosition) imagePosition { @@ -429,21 +429,21 @@ - (void) setImage: (NSImage *)anImage { if (anImage) - { - NSAssert ([anImage isKindOfClass: [NSImage class]], - NSInvalidArgumentException); - } - + { + NSAssert ([anImage isKindOfClass: [NSImage class]], + NSInvalidArgumentException); + } + if (_cell.image_position == NSNoImage) - { - [self setImagePosition: NSImageOnly]; - } - + { + [self setImagePosition: NSImageOnly]; + } + ASSIGN (_cell_image, anImage); } /**

Sets the NSButtonCell's alternate image to anImage.

-

See Also: -alternateImage

+

See Also: -alternateImage

*/ - (void) setAlternateImage: (NSImage*)anImage { @@ -451,55 +451,55 @@ } /**

Sets the image position. The GNUstep implementation depends only on - the image position. If the image position is set to NSNoImage then the type is set to - NSTextCellType, to - NSImageCellType otherwise -

See Also: -imagePosition

-*/ + the image position. If the image position is set to NSNoImage then the type is set to + NSTextCellType, to + NSImageCellType otherwise +

See Also: -imagePosition

+ */ - (void) setImagePosition: (NSCellImagePosition)aPosition { _cell.image_position = aPosition; - + // In the GNUstep NSButtonCell implementation, the cell type depends only on // the image position. - + if (_cell.image_position == NSNoImage) + { + /* NOTE: If we always call -setType: on superclass, the cell _content will + be reset each time. When we alter a button displaying both an image and + a title, by just calling -setImagePosition: with 'NSNoImage' value, + the current title is reset to NSCell default one. That's why we have to + set cell type ourself when a custom title (or attributed title) is + already in use. + Take note that [self title] is able to return the attributed title in + NSString form. + We precisely match Mac OS X behavior currently. That means... When you + switch from 'NSNoImage' option to another one, the title will be the + one in use before you switched to 'NSNoImage'. The reverse with the + image isn't true, when you switch to 'NSNoImage' option, the current + image is lost (image value being reset to nil). + */ + if ([self title] == nil || [[self title] isEqualToString: @""]) { - /* NOTE: If we always call -setType: on superclass, the cell _content will - be reset each time. When we alter a button displaying both an image and - a title, by just calling -setImagePosition: with 'NSNoImage' value, - the current title is reset to NSCell default one. That's why we have to - set cell type ourself when a custom title (or attributed title) is - already in use. - Take note that [self title] is able to return the attributed title in - NSString form. - We precisely match Mac OS X behavior currently. That means... When you - switch from 'NSNoImage' option to another one, the title will be the - one in use before you switched to 'NSNoImage'. The reverse with the - image isn't true, when you switch to 'NSNoImage' option, the current - image is lost (image value being reset to nil). - */ - if ([self title] == nil || [[self title] isEqualToString: @""]) - { - [super setType: NSTextCellType]; - } - else - { - _cell.type = NSTextCellType; - } + [super setType: NSTextCellType]; } + else + { + _cell.type = NSTextCellType; + } + } else - { - [super setType: NSImageCellType]; - } + { + [super setType: NSImageCellType]; + } } /**

Gets the NSButtonCell's delay and the interval - parameters used when NSButton sends continouly action messages. - By default delay is 0.4 and interval is 0.075.

-

See Also: -setPeriodicDelay:interval: - [NSCell-trackMouse:inRect:ofView:untilMouseUp:]

+ parameters used when NSButton sends continouly action messages. + By default delay is 0.4 and interval is 0.075.

+

See Also: -setPeriodicDelay:interval: + [NSCell-trackMouse:inRect:ofView:untilMouseUp:]

*/ - (void) getPeriodicDelay: (float*)delay interval: (float*)interval { @@ -508,10 +508,10 @@ } /**

Sets the NSButtonCell's delay and interval - parameters used when NSButton sends continouly action messages. - By default delay is 0.4 and interval is 0.075.

-

See Also: -getPeriodicDelay:interval: - [NSCell-trackMouse:inRect:ofView:untilMouseUp:]

+ parameters used when NSButton sends continouly action messages. + By default delay is 0.4 and interval is 0.075.

+

See Also: -getPeriodicDelay:interval: + [NSCell-trackMouse:inRect:ofView:untilMouseUp:]

*/ - (void) setPeriodicDelay: (float)delay interval: (float)interval { @@ -520,11 +520,11 @@ } /**

Returns the NSButtonCell's key equivalent. The key equivalent and its - modifier mask are used to simulate the click of the button in - [NSButton-performKeyEquivalent:]. Returns an empty string if no key - equivalent is defined. By default NSButtonCell hasn't key equivalent.

-

See Also: -setKeyEquivalent: [NSButton-performKeyEquivalent:] - -keyEquivalentModifierMask [NSButtonCell-keyEquivalent]

+ modifier mask are used to simulate the click of the button in + [NSButton-performKeyEquivalent:]. Returns an empty string if no key + equivalent is defined. By default NSButtonCell hasn't key equivalent.

+

See Also: -setKeyEquivalent: [NSButton-performKeyEquivalent:] + -keyEquivalentModifierMask [NSButtonCell-keyEquivalent]

*/ - (NSString*) keyEquivalent { @@ -540,10 +540,10 @@ } /**

Returns the modifier mask of the NSButtonCell's key equivalent. - The key equivalent and its modifier mask are used to simulate the click - of the button in [NSButton-performKeyEquivalent:]. The default mask is - NSCommandKeyMask.

See Also: -setKeyEquivalentModifierMask: - -keyEquivalent [NSButton-performKeyEquivalent:]

+ The key equivalent and its modifier mask are used to simulate the click + of the button in [NSButton-performKeyEquivalent:]. The default mask is + NSCommandKeyMask.

See Also: -setKeyEquivalentModifierMask: + -keyEquivalent [NSButton-performKeyEquivalent:]

*/ - (unsigned int) keyEquivalentModifierMask { @@ -551,23 +551,23 @@ } /**

Sets the NSButtonCell's key equivalent to key. The key - equivalent and its modifier mask are used to simulate the click - of the button in [NSButton-performKeyEquivalent:]. By default NSButton - hasn't key equivalent.

See Also: -keyEquivalent - -setKeyEquivalentModifierMask: [NSButton-performKeyEquivalent:]

-*/ + equivalent and its modifier mask are used to simulate the click + of the button in [NSButton-performKeyEquivalent:]. By default NSButton + hasn't key equivalent.

See Also: -keyEquivalent + -setKeyEquivalentModifierMask: [NSButton-performKeyEquivalent:]

+ */ - (void) setKeyEquivalent: (NSString*)key { ASSIGNCOPY(_keyEquivalent, key); } /**

Sets the modifier mask of the NSButtonCell's key equivalent to - mask. The key equivalent and its modifier mask are used to - simulate the click of the button in [NSButton-performKeyEquivalent:]. - By default the mask is NSCommandKeyMask.

-

See Also: -keyEquivalentModifierMask - -setKeyEquivalent: [NSButton-performKeyEquivalent:]

-*/ + mask. The key equivalent and its modifier mask are used to + simulate the click of the button in [NSButton-performKeyEquivalent:]. + By default the mask is NSCommandKeyMask.

+

See Also: -keyEquivalentModifierMask + -setKeyEquivalent: [NSButton-performKeyEquivalent:]

+ */ - (void) setKeyEquivalentModifierMask: (unsigned int)mask { _keyEquivalentModifierMask = mask; @@ -582,8 +582,8 @@ } /**

Sets the NSFont with size fontSize of the key equivalent - to fontName.

-

See Also: -keyEquivalentFont -setKeyEquivalentFont: -setFont:

+ to fontName.

+

See Also: -keyEquivalentFont -setKeyEquivalentFont: -setFont:

*/ - (void) setKeyEquivalentFont: (NSString*)fontName size: (float)fontSize { @@ -591,7 +591,7 @@ } /**

Returns whether the button cell is transparent.

-

See Also: -setTransparent:

+

See Also: -setTransparent:

*/ - (BOOL) isTransparent { @@ -599,7 +599,7 @@ } /**

Sets whether the button cell is transparent.

-

See Also: -isTransparent

+

See Also: -isTransparent

*/ - (void) setTransparent: (BOOL)flag { @@ -607,7 +607,7 @@ } /**

Returns whether the NSButtonCell is opaque. Returns YES if the button - cell is not transparent and if the cell is bordered. NO otherwise

+ cell is not transparent and if the cell is bordered. NO otherwise

*/ - (BOOL) isOpaque { @@ -632,9 +632,9 @@ - (void) setShowsBorderOnlyWhileMouseInside: (BOOL)show { if (_shows_border_only_while_mouse_inside == show) - { - return; - } + { + return; + } _shows_border_only_while_mouse_inside = show; // FIXME Switch mouse tracking on @@ -661,9 +661,9 @@ } /**

Returns a mask describing how the button cell is highlighted :

-

NSNoCellMask, NSContentsCellMask,NSPushInCellMask,NSChangeGrayCellMask, - NSChangeBackgroundCellMask

-

See Also : -setHighlightsBy:

+

NSNoCellMask, NSContentsCellMask,NSPushInCellMask,NSChangeGrayCellMask, + NSChangeBackgroundCellMask

+

See Also : -setHighlightsBy:

*/ - (int) highlightsBy { @@ -671,9 +671,9 @@ } /**

Sets a mask describing how the button cell is highlighted :

-

NSNoCellMask, NSContentsCellMask,NSPushInCellMask,NSChangeGrayCellMask, - NSChangeBackgroundCellMask

-

See Also : -highlightsBy

+

NSNoCellMask, NSContentsCellMask,NSPushInCellMask,NSChangeGrayCellMask, + NSChangeBackgroundCellMask

+

See Also : -highlightsBy

*/ - (void) setHighlightsBy: (int)mask { @@ -690,60 +690,60 @@ // Don't store the button type anywhere switch (buttonType) - { - case NSMomentaryLightButton: - [self setHighlightsBy: NSChangeBackgroundCellMask]; - [self setShowsStateBy: NSNoCellMask]; - [self setImageDimsWhenDisabled: YES]; - break; - case NSMomentaryPushInButton: - [self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask]; - [self setShowsStateBy: NSNoCellMask]; - [self setImageDimsWhenDisabled: YES]; - break; - case NSMomentaryChangeButton: - [self setHighlightsBy: NSContentsCellMask]; - [self setShowsStateBy: NSNoCellMask]; - [self setImageDimsWhenDisabled: YES]; - break; - case NSPushOnPushOffButton: - [self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask]; - [self setShowsStateBy: NSChangeBackgroundCellMask]; - [self setImageDimsWhenDisabled: YES]; - break; - case NSOnOffButton: - [self setHighlightsBy: NSChangeBackgroundCellMask]; - [self setShowsStateBy: NSChangeBackgroundCellMask]; - [self setImageDimsWhenDisabled: YES]; - break; - case NSToggleButton: - [self setHighlightsBy: NSPushInCellMask | NSContentsCellMask]; - [self setShowsStateBy: NSContentsCellMask]; - [self setImageDimsWhenDisabled: YES]; - break; - case NSSwitchButton: - [self setHighlightsBy: NSContentsCellMask]; - [self setShowsStateBy: NSContentsCellMask]; - [self setImage: [NSImage imageNamed: @"NSSwitch"]]; - [self setAlternateImage: [NSImage imageNamed: @"NSHighlightedSwitch"]]; - [self setImagePosition: NSImageLeft]; - [self setAlignment: NSLeftTextAlignment]; - [self setBordered: NO]; - [self setBezeled: NO]; - [self setImageDimsWhenDisabled: NO]; - break; - case NSRadioButton: - [self setHighlightsBy: NSContentsCellMask]; - [self setShowsStateBy: NSContentsCellMask]; - [self setImage: [NSImage imageNamed: @"NSRadioButton"]]; - [self setAlternateImage: [NSImage imageNamed: @"NSHighlightedRadioButton"]]; - [self setImagePosition: NSImageLeft]; - [self setAlignment: NSLeftTextAlignment]; - [self setBordered: NO]; - [self setBezeled: NO]; - [self setImageDimsWhenDisabled: NO]; - break; - } + { + case NSMomentaryLightButton: + [self setHighlightsBy: NSChangeBackgroundCellMask]; + [self setShowsStateBy: NSNoCellMask]; + [self setImageDimsWhenDisabled: YES]; + break; + case NSMomentaryPushInButton: + [self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask]; + [self setShowsStateBy: NSNoCellMask]; + [self setImageDimsWhenDisabled: YES]; + break; + case NSMomentaryChangeButton: + [self setHighlightsBy: NSContentsCellMask]; + [self setShowsStateBy: NSNoCellMask]; + [self setImageDimsWhenDisabled: YES]; + break; + case NSPushOnPushOffButton: + [self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask]; + [self setShowsStateBy: NSChangeBackgroundCellMask]; + [self setImageDimsWhenDisabled: YES]; + break; + case NSOnOffButton: + [self setHighlightsBy: NSChangeBackgroundCellMask]; + [self setShowsStateBy: NSChangeBackgroundCellMask]; + [self setImageDimsWhenDisabled: YES]; + break; + case NSToggleButton: + [self setHighlightsBy: NSPushInCellMask | NSContentsCellMask]; + [self setShowsStateBy: NSContentsCellMask]; + [self setImageDimsWhenDisabled: YES]; + break; + case NSSwitchButton: + [self setHighlightsBy: NSContentsCellMask]; + [self setShowsStateBy: NSContentsCellMask]; + [self setImage: [NSImage imageNamed: @"NSSwitch"]]; + [self setAlternateImage: [NSImage imageNamed: @"NSHighlightedSwitch"]]; + [self setImagePosition: NSImageLeft]; + [self setAlignment: NSLeftTextAlignment]; + [self setBordered: NO]; + [self setBezeled: NO]; + [self setImageDimsWhenDisabled: NO]; + break; + case NSRadioButton: + [self setHighlightsBy: NSContentsCellMask]; + [self setShowsStateBy: NSContentsCellMask]; + [self setImage: [NSImage imageNamed: @"NSRadioButton"]]; + [self setAlternateImage: [NSImage imageNamed: @"NSHighlightedRadioButton"]]; + [self setImagePosition: NSImageLeft]; + [self setAlignment: NSLeftTextAlignment]; + [self setBordered: NO]; + [self setBezeled: NO]; + [self setImageDimsWhenDisabled: NO]; + break; + } } - (int) showsStateBy @@ -784,33 +784,33 @@ - (void) setObjectValue: (id)object { if (object == nil) - { - [self setState: NSOffState]; - } + { + [self setState: NSOffState]; + } else if ([object respondsToSelector: @selector(intValue)]) - { - [self setState: [object intValue]]; - } + { + [self setState: [object intValue]]; + } else - { - [self setState: NSOnState]; - } + { + [self setState: NSOnState]; + } } - (id) objectValue { if (_cell.state == NSOffState) - { - return [NSNumber numberWithBool: NO]; - } + { + return [NSNumber numberWithBool: NO]; + } else if (_cell.state == NSOnState) - { - return [NSNumber numberWithBool: YES]; - } + { + return [NSNumber numberWithBool: YES]; + } else // NSMixedState - { - return [NSNumber numberWithInt: -1]; - } + { + return [NSNumber numberWithInt: -1]; + } } /* @@ -843,13 +843,13 @@ // set the mask if (_cell.is_highlighted) + { + mask = _highlightsByMask; + if (_cell.state) { - mask = _highlightsByMask; - if (_cell.state) - { - mask &= ~_showAltStateMask; - } + mask &= ~_showAltStateMask; } + } else if (_cell.state) mask = _showAltStateMask; else @@ -860,74 +860,74 @@ is NSChangeBackgroundCellMask or NSChangeGrayCellMask, as required by our nextstep-like look and feel. */ if (mask & (NSChangeGrayCellMask | NSChangeBackgroundCellMask)) - { - buttonState = GSThemeHighlightedState; - } + { + buttonState = GSThemeHighlightedState; + } /* Pushed in buttons contents are displaced to the bottom right 1px. */ if (mask & NSPushInCellMask) - { - buttonState = GSThemeSelectedState; - } + { + buttonState = GSThemeSelectedState; + } [[GSTheme theme] drawButton: cellFrame - in: self - view: controlView - style: _bezel_style - state: buttonState]; + in: self + view: controlView + style: _bezel_style + state: buttonState]; } - (void) drawImage: (NSImage*)anImage - withFrame: (NSRect)aRect - inView: (NSView*)controlView +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]) { - 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]; - } + 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 +withFrame: (NSRect)frame +inView: (NSView*)control { [self _drawAttributedText: titleToDisplay - inFrame: frame]; + inFrame: frame]; } // Private helper method overridden in subclasses - (void) _drawBorderAndBackgroundWithFrame: (NSRect)cellFrame inView: (NSView*)controlView { if ((_cell.is_bordered) - && (!_shows_border_only_while_mouse_inside || _mouse_inside)) - { - [self drawBezelWithFrame: cellFrame inView: controlView]; - } + && (!_shows_border_only_while_mouse_inside || _mouse_inside)) + { + [self drawBezelWithFrame: cellFrame inView: controlView]; + } } - (void) drawGradientWithFrame: (NSRect)cellFrame inView: (NSView *)controlView @@ -947,86 +947,86 @@ darkGray = [NSColor colorWithDeviceRed:0.32 green:0.32 blue:0.32 alpha:1.0]; switch (_gradient_type) - { - case NSGradientNone: - return; - break; + { + case NSGradientNone: + return; + break; - case NSGradientConcaveWeak: - [gray getHue: &h saturation: &s brightness: &v alpha: &a]; - start_white = [lightGray brightnessComponent]; - end_white = [gray brightnessComponent]; - break; - - case NSGradientConvexWeak: - [darkGray getHue: &h saturation: &s brightness: &v alpha: &a]; - start_white = [gray brightnessComponent]; - end_white = [lightGray brightnessComponent]; - break; - - case NSGradientConcaveStrong: - [lightGray getHue: &h saturation: &s brightness: &v alpha: &a]; - start_white = [lightGray brightnessComponent]; - end_white = [darkGray brightnessComponent]; - break; - - case NSGradientConvexStrong: - [darkGray getHue: &h saturation: &s brightness: &v alpha: &a]; - start_white = [darkGray brightnessComponent]; - end_white = [lightGray brightnessComponent]; - break; + case NSGradientConcaveWeak: + [gray getHue: &h saturation: &s brightness: &v alpha: &a]; + start_white = [lightGray brightnessComponent]; + end_white = [gray brightnessComponent]; + break; - default: - break; - } + case NSGradientConvexWeak: + [darkGray getHue: &h saturation: &s brightness: &v alpha: &a]; + start_white = [gray brightnessComponent]; + end_white = [lightGray brightnessComponent]; + break; + case NSGradientConcaveStrong: + [lightGray getHue: &h saturation: &s brightness: &v alpha: &a]; + start_white = [lightGray brightnessComponent]; + end_white = [darkGray brightnessComponent]; + break; + + case NSGradientConvexStrong: + [darkGray getHue: &h saturation: &s brightness: &v alpha: &a]; + start_white = [darkGray brightnessComponent]; + end_white = [lightGray brightnessComponent]; + break; + + default: + break; + } + white = start_white; white_step = fabs(start_white - end_white) / (cellFrame.size.width + cellFrame.size.height); // Start from top left p1 = NSMakePoint(cellFrame.origin.x, - cellFrame.size.height + cellFrame.origin.y); + cellFrame.size.height + cellFrame.origin.y); p2 = NSMakePoint(cellFrame.origin.x, - cellFrame.size.height + cellFrame.origin.y); + cellFrame.size.height + cellFrame.origin.y); // Move by Y while (p1.y > cellFrame.origin.y) - { - [[NSColor - colorWithDeviceHue: h saturation: s brightness: white alpha: 1.0] set]; - [NSBezierPath strokeLineFromPoint: p1 toPoint: p2]; - - if (start_white > end_white) - white -= white_step; - else - white += white_step; + { + [[NSColor + colorWithDeviceHue: h saturation: s brightness: white alpha: 1.0] set]; + [NSBezierPath strokeLineFromPoint: p1 toPoint: p2]; - p1.y -= 1.0; - if (p2.x < (cellFrame.size.width + cellFrame.origin.x)) - p2.x += 1.0; - else - p2.y -= 1.0; - } - + if (start_white > end_white) + white -= white_step; + else + white += white_step; + + p1.y -= 1.0; + if (p2.x < (cellFrame.size.width + cellFrame.origin.x)) + p2.x += 1.0; + else + p2.y -= 1.0; + } + // Move by X while (p1.x < (cellFrame.size.width + cellFrame.origin.x)) - { - [[NSColor - colorWithDeviceHue: h saturation: s brightness: white alpha: 1.0] set]; - [NSBezierPath strokeLineFromPoint: p1 toPoint: p2]; - - if (start_white > end_white) - white -= white_step; - else - white += white_step; + { + [[NSColor + colorWithDeviceHue: h saturation: s brightness: white alpha: 1.0] set]; + [NSBezierPath strokeLineFromPoint: p1 toPoint: p2]; - p1.x += 1.0; - if (p2.x >= (cellFrame.size.width + cellFrame.origin.x)) - p2.y -= 1.0; - else - p2.x += 1.0; - } + if (start_white > end_white) + white -= white_step; + else + white += white_step; + + p1.x += 1.0; + if (p2.x >= (cellFrame.size.width + cellFrame.origin.x)) + p2.y -= 1.0; + else + p2.x += 1.0; + } } - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView @@ -1050,12 +1050,12 @@ cellFrame = [self drawingRectForBounds: cellFrame]; if (_cell.is_highlighted) - { - mask = _highlightsByMask; + { + mask = _highlightsByMask; - if (_cell.state) - mask &= ~_showAltStateMask; - } + if (_cell.state) + mask &= ~_showAltStateMask; + } else if (_cell.state) mask = _showAltStateMask; else @@ -1069,209 +1069,209 @@ * content is changed to the face of reversed state). */ if (mask & NSContentsCellMask) + { + imageToDisplay = _altImage; + if (!imageToDisplay) { - imageToDisplay = _altImage; - if (!imageToDisplay) - { - imageToDisplay = _cell_image; - } - titleToDisplay = [self attributedAlternateTitle]; - if (titleToDisplay == nil || [titleToDisplay length] == 0) - { - titleToDisplay = [self attributedTitle]; - } + imageToDisplay = _cell_image; } - else + titleToDisplay = [self attributedAlternateTitle]; + if (titleToDisplay == nil || [titleToDisplay length] == 0) { - imageToDisplay = _cell_image; titleToDisplay = [self attributedTitle]; } + } + else + { + imageToDisplay = _cell_image; + titleToDisplay = [self attributedTitle]; + } if (imageToDisplay && ipos != NSNoImage) - { - imageSize = [imageToDisplay size]; - } + { + imageSize = [imageToDisplay size]; + } if (titleToDisplay && ipos != NSImageOnly) - { - titleSize = [titleToDisplay size]; - } + { + titleSize = [titleToDisplay size]; + } if (flippedView == YES) + { + if (ipos == NSImageAbove) { - if (ipos == NSImageAbove) - { - ipos = NSImageBelow; - } - else if (ipos == NSImageBelow) - { - ipos = NSImageAbove; - } + ipos = NSImageBelow; } - + else if (ipos == NSImageBelow) + { + ipos = NSImageAbove; + } + } + /* - The size calculations here should be changed very carefully, and _must_ be - kept in sync with -cellSize. Changing the calculations to require more - space isn't OK; this breaks interfaces designed using the old sizes by - clipping away parts of the title. + The size calculations here should be changed very carefully, and _must_ be + kept in sync with -cellSize. Changing the calculations to require more + space isn't OK; this breaks interfaces designed using the old sizes by + clipping away parts of the title. - The current size calculations ensure that for bordered or bezeled cells, - there's always at least a three point margin between the size returned by - -cellSize and the minimum size required not to clip text. (In other words, - the text can become three points wider (due to eg. font mismatches) before - you lose the last character.) - */ + The current size calculations ensure that for bordered or bezeled cells, + there's always at least a three point margin between the size returned by + -cellSize and the minimum size required not to clip text. (In other words, + the text can become three points wider (due to eg. font mismatches) before + you lose the last character.) + */ switch (ipos) - { - default: - case NSNoImage: - imageToDisplay = nil; - titleRect = cellFrame; - imageRect = NSZeroRect; - if (titleSize.width + 6 <= titleRect.size.width) - { - titleRect.origin.x += 3; - titleRect.size.width -= 6; - } - break; + { + default: + case NSNoImage: + imageToDisplay = nil; + titleRect = cellFrame; + imageRect = NSZeroRect; + if (titleSize.width + 6 <= titleRect.size.width) + { + titleRect.origin.x += 3; + titleRect.size.width -= 6; + } + break; - case NSImageOnly: - titleToDisplay = nil; - imageRect = cellFrame; - titleRect = NSZeroRect; - break; + case NSImageOnly: + titleToDisplay = nil; + imageRect = cellFrame; + titleRect = NSZeroRect; + break; - case NSImageLeft: - imageRect.origin = cellFrame.origin; - imageRect.size.width = imageSize.width; - imageRect.size.height = cellFrame.size.height; - if (_cell.is_bordered || _cell.is_bezeled) - { - imageRect.origin.x += 3; - } - titleRect = imageRect; - titleRect.origin.x += imageSize.width + GSCellTextImageXDist; - titleRect.size.width = NSMaxX(cellFrame) - titleRect.origin.x; - if (titleSize.width + 3 <= titleRect.size.width) - { - titleRect.size.width -= 3; - } - break; + case NSImageLeft: + imageRect.origin = cellFrame.origin; + imageRect.size.width = imageSize.width; + imageRect.size.height = cellFrame.size.height; + if (_cell.is_bordered || _cell.is_bezeled) + { + imageRect.origin.x += 3; + } + titleRect = imageRect; + titleRect.origin.x += imageSize.width + GSCellTextImageXDist; + titleRect.size.width = NSMaxX(cellFrame) - titleRect.origin.x; + if (titleSize.width + 3 <= titleRect.size.width) + { + titleRect.size.width -= 3; + } + break; - case NSImageRight: - imageRect.origin.x = NSMaxX(cellFrame) - imageSize.width; - imageRect.origin.y = cellFrame.origin.y; - imageRect.size.width = imageSize.width; - imageRect.size.height = cellFrame.size.height; - if (_cell.is_bordered || _cell.is_bezeled) - { - imageRect.origin.x -= 3; - } - titleRect.origin = cellFrame.origin; - titleRect.size.width = imageRect.origin.x - titleRect.origin.x - - GSCellTextImageXDist; - titleRect.size.height = cellFrame.size.height; - if (titleSize.width + 3 <= titleRect.size.width) - { - titleRect.origin.x += 3; - titleRect.size.width -= 3; - } - break; + case NSImageRight: + imageRect.origin.x = NSMaxX(cellFrame) - imageSize.width; + imageRect.origin.y = cellFrame.origin.y; + imageRect.size.width = imageSize.width; + imageRect.size.height = cellFrame.size.height; + if (_cell.is_bordered || _cell.is_bezeled) + { + imageRect.origin.x -= 3; + } + titleRect.origin = cellFrame.origin; + titleRect.size.width = imageRect.origin.x - titleRect.origin.x + - GSCellTextImageXDist; + titleRect.size.height = cellFrame.size.height; + if (titleSize.width + 3 <= titleRect.size.width) + { + titleRect.origin.x += 3; + titleRect.size.width -= 3; + } + break; - case NSImageAbove: - /* - * In this case, imageRect is all the space we can allocate - * above the text. - * The drawing code below will then center the image in imageRect. - */ - titleRect.origin = cellFrame.origin; - titleRect.size.width = cellFrame.size.width; - titleRect.size.height = titleSize.height; - if (_cell.is_bordered || _cell.is_bezeled) - { - titleRect.origin.y += 3; - } + case NSImageAbove: + /* + * In this case, imageRect is all the space we can allocate + * above the text. + * The drawing code below will then center the image in imageRect. + */ + titleRect.origin = cellFrame.origin; + titleRect.size.width = cellFrame.size.width; + titleRect.size.height = titleSize.height; + if (_cell.is_bordered || _cell.is_bezeled) + { + titleRect.origin.y += 3; + } - imageRect.origin.x = cellFrame.origin.x; - imageRect.origin.y = NSMaxY(titleRect) + GSCellTextImageYDist; - imageRect.size.width = cellFrame.size.width; - imageRect.size.height = NSMaxY(cellFrame) - imageRect.origin.y; + imageRect.origin.x = cellFrame.origin.x; + imageRect.origin.y = NSMaxY(titleRect) + GSCellTextImageYDist; + imageRect.size.width = cellFrame.size.width; + imageRect.size.height = NSMaxY(cellFrame) - imageRect.origin.y; - if (_cell.is_bordered || _cell.is_bezeled) - { - imageRect.size.height -= 3; - } - if (titleSize.width + 6 <= titleRect.size.width) - { - titleRect.origin.x += 3; - titleRect.size.width -= 6; - } - break; + if (_cell.is_bordered || _cell.is_bezeled) + { + imageRect.size.height -= 3; + } + if (titleSize.width + 6 <= titleRect.size.width) + { + titleRect.origin.x += 3; + titleRect.size.width -= 6; + } + break; - case NSImageBelow: - /* - * In this case, imageRect is all the space we can allocate - * below the text. - * The drawing code below will then center the image in imageRect. - */ - titleRect.origin.x = cellFrame.origin.x; - titleRect.origin.y = NSMaxY(cellFrame) - titleSize.height; - titleRect.size.width = cellFrame.size.width; - titleRect.size.height = titleSize.height; - if (_cell.is_bordered || _cell.is_bezeled) - { - titleRect.origin.y -= 3; - } + case NSImageBelow: + /* + * In this case, imageRect is all the space we can allocate + * below the text. + * The drawing code below will then center the image in imageRect. + */ + titleRect.origin.x = cellFrame.origin.x; + titleRect.origin.y = NSMaxY(cellFrame) - titleSize.height; + titleRect.size.width = cellFrame.size.width; + titleRect.size.height = titleSize.height; + if (_cell.is_bordered || _cell.is_bezeled) + { + titleRect.origin.y -= 3; + } - imageRect.origin.x = cellFrame.origin.x; - imageRect.origin.y = cellFrame.origin.y; - imageRect.size.width = cellFrame.size.width; - imageRect.size.height - = titleRect.origin.y - GSCellTextImageYDist - imageRect.origin.y; + imageRect.origin.x = cellFrame.origin.x; + imageRect.origin.y = cellFrame.origin.y; + imageRect.size.width = cellFrame.size.width; + imageRect.size.height + = titleRect.origin.y - GSCellTextImageYDist - imageRect.origin.y; - if (_cell.is_bordered || _cell.is_bezeled) - { - imageRect.origin.y += 3; - imageRect.size.height -= 3; - } - if (titleSize.width + 6 <= titleRect.size.width) - { - titleRect.origin.x += 3; - titleRect.size.width -= 6; - } - break; + if (_cell.is_bordered || _cell.is_bezeled) + { + imageRect.origin.y += 3; + imageRect.size.height -= 3; + } + if (titleSize.width + 6 <= titleRect.size.width) + { + titleRect.origin.x += 3; + titleRect.size.width -= 6; + } + break; - case NSImageOverlaps: - imageRect = cellFrame; - titleRect = cellFrame; - if (titleSize.width + 6 <= titleRect.size.width) - { - titleRect.origin.x += 3; - titleRect.size.width -= 6; - } - break; - } + case NSImageOverlaps: + imageRect = cellFrame; + titleRect = cellFrame; + if (titleSize.width + 6 <= titleRect.size.width) + { + titleRect.origin.x += 3; + titleRect.size.width -= 6; + } + break; + } // Draw gradient if (!_cell.is_highlighted && _gradient_type != NSGradientNone) - { - // FIXME: I think this method is wrong. - [self drawGradientWithFrame: cellFrame inView: controlView]; - } + { + // FIXME: I think this method is wrong. + [self drawGradientWithFrame: cellFrame inView: controlView]; + } // Draw image if (imageToDisplay != nil) - { - [self drawImage: imageToDisplay - withFrame: imageRect - inView: controlView]; - } + { + [self drawImage: imageToDisplay + withFrame: imageRect + inView: controlView]; + } // Draw title if (titleToDisplay != nil) - { - [self drawTitle: titleToDisplay withFrame: titleRect inView: controlView]; - } + { + [self drawTitle: titleToDisplay withFrame: titleRect inView: controlView]; + } } - (NSSize) cellSize @@ -1283,103 +1283,103 @@ NSAttributedString *titleToDisplay; NSSize imageSize = NSZeroSize; NSSize titleSize = NSZeroSize; - + /* The size calculations here must be kept in sync with - -drawInteriorWithFrame. */ + -drawInteriorWithFrame. */ if (_cell.is_highlighted) - { - mask = _highlightsByMask; + { + mask = _highlightsByMask; - if (_cell.state) - mask &= ~_showAltStateMask; - } + if (_cell.state) + mask &= ~_showAltStateMask; + } else if (_cell.state) mask = _showAltStateMask; else mask = NSNoCellMask; - + if (mask & NSContentsCellMask) + { + imageToDisplay = _altImage; + if (!imageToDisplay) { - imageToDisplay = _altImage; - if (!imageToDisplay) - { - imageToDisplay = _cell_image; - } - titleToDisplay = [self attributedAlternateTitle]; - if (titleToDisplay == nil || [titleToDisplay length] == 0) - { - titleToDisplay = [self attributedTitle]; - } + imageToDisplay = _cell_image; } - else + titleToDisplay = [self attributedAlternateTitle]; + if (titleToDisplay == nil || [titleToDisplay length] == 0) { - imageToDisplay = _cell_image; titleToDisplay = [self attributedTitle]; } - + } + else + { + imageToDisplay = _cell_image; + titleToDisplay = [self attributedTitle]; + } + if (imageToDisplay) - { - imageSize = [imageToDisplay size]; - } + { + imageSize = [imageToDisplay size]; + } if (titleToDisplay != nil) - { - titleSize = [titleToDisplay size]; - } - + { + titleSize = [titleToDisplay size]; + } + switch (_cell.image_position) - { - default: - case NSNoImage: - s = titleSize; - break; - - case NSImageOnly: - s = imageSize; - break; - - case NSImageLeft: - case NSImageRight: - s.width = imageSize.width + titleSize.width + GSCellTextImageXDist; - s.height = MAX(imageSize.height, titleSize.height); - break; - - case NSImageBelow: - case NSImageAbove: - s.width = MAX(imageSize.width, titleSize.width); - s.height = imageSize.height + titleSize.height + GSCellTextImageYDist; - break; - - case NSImageOverlaps: - s.width = MAX(imageSize.width, titleSize.width); - s.height = MAX(imageSize.height, titleSize.height); - break; - } - + { + default: + case NSNoImage: + s = titleSize; + break; + + case NSImageOnly: + s = imageSize; + break; + + case NSImageLeft: + case NSImageRight: + s.width = imageSize.width + titleSize.width + GSCellTextImageXDist; + s.height = MAX(imageSize.height, titleSize.height); + break; + + case NSImageBelow: + case NSImageAbove: + s.width = MAX(imageSize.width, titleSize.width); + s.height = imageSize.height + titleSize.height + GSCellTextImageYDist; + break; + + case NSImageOverlaps: + s.width = MAX(imageSize.width, titleSize.width); + s.height = MAX(imageSize.height, titleSize.height); + break; + } + // Get border size if (_cell.is_bordered) + { + 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)) { - GSThemeControlState buttonState = GSThemeNormalState; + buttonState = GSThemeHighlightedState; + } - /* 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; - } + /* Pushed in buttons contents are displaced to the bottom right 1px. */ + if (mask & NSPushInCellMask) + { + buttonState = GSThemeSelectedState; + } - borderSize = [[GSTheme theme] buttonBorderForStyle: _bezel_style - state: buttonState]; - } + borderSize = [[GSTheme theme] buttonBorderForStyle: _bezel_style + state: buttonState]; + } else borderSize = NSZeroSize; @@ -1393,50 +1393,54 @@ - (NSRect) drawingRectForBounds: (NSRect)theRect { if (_cell.is_bordered) + { + //NSSize borderSize; + unsigned mask; + GSThemeControlState buttonState = GSThemeNormalState; + NSRect interiorFrame; + + if (_cell.is_highlighted) { - NSSize borderSize; - unsigned mask; - GSThemeControlState buttonState = GSThemeNormalState; - NSRect interiorFrame; + mask = _highlightsByMask; - if (_cell.is_highlighted) - { - mask = _highlightsByMask; + if (_cell.state) + mask &= ~_showAltStateMask; + } + else if (_cell.state) + mask = _showAltStateMask; + else + mask = NSNoCellMask; - 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; - } + /* 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; + } - borderSize = [[GSTheme theme] buttonBorderForStyle: _bezel_style - state: buttonState]; - interiorFrame = NSInsetRect(theRect, borderSize.width, borderSize.height); + if (mask & NSPushInCellMask) + { + buttonState = GSThemeSelectedState; + } - /* 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; + //borderSize = [[GSTheme theme] buttonBorderForStyle: _bezel_style + // state: buttonState]; + //interiorFrame = NSInsetRect(theRect, borderSize.width, borderSize.height); + interiorFrame = [[GSTheme theme] buttonContentRect:theRect + forStyle:_bezel_style + state:buttonState]; + + /* 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 { return theRect; Index: Source/NSMenuItemCell.m =================================================================== --- Source/NSMenuItemCell.m (revision 25093) +++ Source/NSMenuItemCell.m (working copy) @@ -593,7 +593,8 @@ - (void) drawBorderAndBackgroundWithFrame: (NSRect)cellFrame inView: (NSView *)controlView { - if ([_menuView isHorizontal] == YES) + GSThemeControlState state; +/* if ([_menuView isHorizontal] == YES) { cellFrame = [self drawingRectForBounds: cellFrame]; [[self backgroundColor] set]; @@ -602,8 +603,8 @@ } // Set cell's background color - [[self backgroundColor] set]; - NSRectFill(cellFrame); + //[[self backgroundColor] set]; + //NSRectFill(cellFrame); if (!_cell.is_bordered) return; @@ -615,7 +616,15 @@ else { [[GSTheme theme] drawButton: cellFrame withClip: NSZeroRect]; - } + }*/ + if (_cell.is_highlighted && (_highlightsByMask & NSPushInCellMask)) + state = GSThemeHighlightedState; + else + state = GSThemeNormalState; + [[GSTheme theme] drawMenuItemBorderAndBackground:cellFrame + in:self + view:controlView + state:state]; } - (void) drawImageWithFrame: (NSRect)cellFrame Index: Source/NSScroller.m =================================================================== --- Source/NSScroller.m (revision 25093) +++ Source/NSScroller.m (working copy) @@ -42,6 +42,8 @@ #include "AppKit/NSColor.h" #include "AppKit/NSGraphics.h" +#include "GNUstepGUI/GSTheme.h" + /**

TODO Description

*/ @implementation NSScroller @@ -55,13 +57,13 @@ static NSButtonCell* downCell = nil; static NSButtonCell* leftCell = nil; static NSButtonCell* rightCell = nil; -static NSButtonCell* knobCell = nil; +static NSCell* horizontalKnobCell = nil; +static NSCell* verticalKnobCell = nil; +static NSCell* horizontalKnobSlotCell = nil; +static NSCell* verticalKnobSlotCell = nil; -static const float scrollerWidth = 18; static const float buttonsOffset = 2; // buttonsWidth = sw - buttonsOffset -static NSColor *scrollBarColor = nil; - /* * Class methods */ @@ -70,7 +72,6 @@ if (self == [NSScroller class]) { [self setVersion: 1]; - ASSIGN (scrollBarColor, [NSColor scrollBarColor]); } } @@ -80,7 +81,7 @@ */ + (float) scrollerWidth { - return scrollerWidth; + return [[GSTheme theme] defaultScrollerWidth]; } - (BOOL) isFlipped @@ -320,54 +321,37 @@ */ - (void) drawParts { - /* - * Create the class variable button cells if they do not yet exist. - */ - if (knobCell) + GSTheme *theme = [GSTheme theme] ; + + if (upCell) return; - upCell = [NSButtonCell new]; - [upCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; - [upCell setImage: [NSImage imageNamed: @"common_ArrowUp"]]; - [upCell setAlternateImage: [NSImage imageNamed: @"common_ArrowUpH"]]; - [upCell setImagePosition: NSImageOnly]; - [upCell setContinuous: YES]; - [upCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)]; - [upCell setPeriodicDelay: 0.3 interval: 0.03]; + upCell = RETAIN([theme cellForScrollerArrow:NSScrollerDecrementArrow horizontal:NO]); + downCell = RETAIN([theme cellForScrollerArrow:NSScrollerIncrementArrow horizontal:NO]); + leftCell = RETAIN([theme cellForScrollerArrow:NSScrollerDecrementArrow horizontal:YES]); + rightCell = RETAIN([theme cellForScrollerArrow:NSScrollerIncrementArrow horizontal:YES]); + verticalKnobCell = RETAIN([theme cellForScrollerKnob:NO]); + horizontalKnobCell = RETAIN([theme cellForScrollerKnob:YES]); + verticalKnobSlotCell = RETAIN([theme cellForScrollerKnobSlot:NO]); + horizontalKnobSlotCell = RETAIN([theme cellForScrollerKnobSlot:YES]); - downCell = [NSButtonCell new]; - [downCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; - [downCell setImage: [NSImage imageNamed: @"common_ArrowDown"]]; - [downCell setAlternateImage: [NSImage imageNamed: @"common_ArrowDownH"]]; - [downCell setImagePosition: NSImageOnly]; [downCell setContinuous: YES]; [downCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)]; [downCell setPeriodicDelay: 0.3 interval: 0.03]; - - leftCell = [NSButtonCell new]; - [leftCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; - [leftCell setImage: [NSImage imageNamed: @"common_ArrowLeft"]]; - [leftCell setAlternateImage: [NSImage imageNamed: @"common_ArrowLeftH"]]; - [leftCell setImagePosition: NSImageOnly]; + [leftCell setContinuous: YES]; [leftCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)]; [leftCell setPeriodicDelay: 0.3 interval: 0.03]; - - rightCell = [NSButtonCell new]; - [rightCell setHighlightsBy: NSChangeBackgroundCellMask | NSContentsCellMask]; - [rightCell setImage: [NSImage imageNamed: @"common_ArrowRight"]]; - [rightCell setAlternateImage: [NSImage imageNamed: @"common_ArrowRightH"]]; - [rightCell setImagePosition: NSImageOnly]; + [rightCell setContinuous: YES]; [rightCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)]; [rightCell setPeriodicDelay: 0.3 interval: 0.03]; - - knobCell = [NSButtonCell new]; - [knobCell setButtonType: NSMomentaryChangeButton]; - [knobCell setImage: [NSImage imageNamed: @"common_Dimple"]]; - [knobCell setImagePosition: NSImageOnly]; -} - + + [upCell setContinuous: YES]; + [upCell sendActionOn: (NSLeftMouseDownMask | NSPeriodicMask)]; + [upCell setPeriodicDelay: 0.3 interval: 0.03]; +} + - (void) _setTargetAndActionToCells { [upCell setTarget: _target]; @@ -382,8 +366,11 @@ [rightCell setTarget: _target]; [rightCell setAction: _action]; - [knobCell setTarget: _target]; - [knobCell setAction: _action]; + [horizontalKnobCell setTarget: _target]; + [horizontalKnobCell setAction: _action]; + + [verticalKnobCell setTarget:_target]; + [horizontalKnobCell setTarget:_target]; } - (void) checkSpaceForParts @@ -945,7 +932,10 @@ */ - (void) drawKnob { - [knobCell drawWithFrame: [self rectForPart: NSScrollerKnob] inView: self]; + if (_isHorizontal) + [horizontalKnobCell drawWithFrame: [self rectForPart: NSScrollerKnob] inView: self]; + else + [verticalKnobCell drawWithFrame: [self rectForPart: NSScrollerKnob] inView: self]; } - (void) drawKnobSlot @@ -957,8 +947,10 @@ rect = [self rectForPart: NSScrollerKnobSlot]; } - [scrollBarColor set]; - NSRectFill (rect); + if (_isHorizontal) + [horizontalKnobSlotCell drawWithFrame:rect inView:self]; + else + [verticalKnobSlotCell drawWithFrame:rect inView:self]; } /**

Highlights the button whose under the mouse. Does nothing if the mouse @@ -988,11 +980,30 @@ - (NSRect) rectForPart: (NSScrollerPart)partCode { NSRect scrollerFrame = _frame; - float x = 1, y = 1; + float x, y; float width, height; - float buttonsWidth = ([isa scrollerWidth] - buttonsOffset); - float buttonsSize = 2 * buttonsWidth + 2; + float buttonsWidth; + float buttonsSize; NSUsableScrollerParts usableParts; + + NSInterfaceStyle interfaceStyle = NSInterfaceStyleForKey(@"NSScrollerInterfaceStyle",self); + + + /* We use the button offset if we in the NeXTstep interface style. */ + if (interfaceStyle==NSNextStepInterfaceStyle || interfaceStyle==GSWindowMakerInterfaceStyle) + { + buttonsWidth = ([isa scrollerWidth] - buttonsOffset); + x = y = 1.0; + buttonsSize = 2 * buttonsWidth + 2; + } + else + { + buttonsWidth = [isa scrollerWidth]; + x = y = 1.0; + buttonsSize = 2 * buttonsWidth; + } + + /* * If the scroller is disabled then the scroller buttons and the * knob are not displayed at all. @@ -1054,11 +1065,22 @@ /* calc actual position */ - y += knobPosition + ((_arrowsPosition == NSScrollerArrowsMaxEnd - || _arrowsPosition == NSScrollerArrowsNone) - ? 0 : buttonsSize); + if (interfaceStyle==NSNextStepInterfaceStyle || + interfaceStyle==GSWindowMakerInterfaceStyle) + { + y += knobPosition + ((_arrowsPosition == NSScrollerArrowsMaxEnd + || _arrowsPosition == NSScrollerArrowsNone) + ? 0 : buttonsSize); + width = buttonsWidth; + } + else + { + y += knobPosition + ((_arrowsPosition == NSScrollerArrowsNone) + ? 0 : buttonsWidth); + width = buttonsWidth ; + } + height = knobHeight; - width = buttonsWidth; break; } @@ -1073,11 +1095,19 @@ break; } height -= buttonsSize; - if (_arrowsPosition == NSScrollerArrowsMinEnd) + if ( (interfaceStyle==NSNextStepInterfaceStyle || + interfaceStyle==GSWindowMakerInterfaceStyle) + && _arrowsPosition == NSScrollerArrowsMinEnd) { y += buttonsSize; } - break; + else if (interfaceStyle!=NSNextStepInterfaceStyle && + interfaceStyle!=GSWindowMakerInterfaceStyle) + { + y += buttonsWidth; + width = buttonsWidth; + } + break; case NSScrollerDecrementLine: case NSScrollerDecrementPage: @@ -1086,7 +1116,9 @@ { return NSZeroRect; } - else if (_arrowsPosition == NSScrollerArrowsMaxEnd) + else if ((interfaceStyle==NSNextStepInterfaceStyle || + interfaceStyle==GSWindowMakerInterfaceStyle) + && _arrowsPosition == NSScrollerArrowsMaxEnd) { y += (height - buttonsSize + 1); } @@ -1101,14 +1133,22 @@ { return NSZeroRect; } - else if (_arrowsPosition == NSScrollerArrowsMaxEnd) - { - y += (height - buttonsWidth); - } - else if (_arrowsPosition == NSScrollerArrowsMinEnd) - { - y += (buttonsWidth + 1); - } + else if (interfaceStyle==NSNextStepInterfaceStyle + || interfaceStyle==GSWindowMakerInterfaceStyle) + { + if (_arrowsPosition == NSScrollerArrowsMaxEnd) + { + y += (height - buttonsWidth); + } + else if (_arrowsPosition == NSScrollerArrowsMinEnd) + { + y += (buttonsWidth + 1); + } + } + else + { + y += (height - buttonsWidth); + } height = buttonsWidth; width = buttonsWidth; break; @@ -1130,7 +1170,7 @@ + (float) scrollerWidthForControlSize: (NSControlSize)controlSize { // FIXME - return scrollerWidth; + return [self scrollerWidth]; } - (void) setControlSize: (NSControlSize)controlSize Index: Source/NSMenuView.m =================================================================== --- Source/NSMenuView.m (revision 25093) +++ Source/NSMenuView.m (working copy) @@ -41,6 +41,7 @@ #include "AppKit/NSImage.h" #include "GNUstepGUI/GSTitleView.h" +#include "GNUstepGUI/GSTheme.h" #include @@ -1097,23 +1098,9 @@ { int i; int howMany = [_itemCells count]; - NSRectEdge sides[2]; - float grays[] = {NSDarkGray, NSDarkGray}; - if (_horizontal == YES) - { - sides[0] = NSMinYEdge; - sides[1] = NSMinYEdge; - NSDrawTiledRects(_bounds, rect, sides, grays, 2); - } - else - { - sides[0] = NSMinXEdge; - sides[1] = NSMaxYEdge; - // Draw the dark gray upper left lines. - NSDrawTiledRects(_bounds, rect, sides, grays, 2); - } - + [[GSTheme theme] drawMenuViewBackground:_bounds view:self]; + // Draw the menu cells. for (i = 0; i < howMany; i++) { Index: Headers/Additions/GNUstepGUI/GSTheme.h =================================================================== --- Headers/Additions/GNUstepGUI/GSTheme.h (revision 25093) +++ Headers/Additions/GNUstepGUI/GSTheme.h (working copy) @@ -136,16 +136,22 @@ #include #include // For gradient types -#include "AppKit/NSButtonCell.h" +#include +#include #if OS_API_VERSION(GS_API_NONE,GS_API_NONE) @class NSArray; @class NSBundle; + @class NSColor; @class NSDictionary; @class NSImage; @class GSDrawTiles; +@class NSButton; +@class NSMenuView; +@class NSMenuItemCell; + /** * This defines how the values in a tile array should be used when * drawing a rectangle. Mostly this just effects the center, middle @@ -190,7 +196,7 @@ This is a class used for 'theming', which is mostly a matter of encapsulating common drawing behaviors so that GUI appearance can be easily modified, but also includes mechanisms for altering - some GUI behavior (such mas orientation and position of menus). + some GUI behavior (such mass orientation and position of menus).

Methods in this class standardize drawing of buttons, borders @@ -392,6 +398,14 @@ - (NSSize) buttonBorderForStyle: (int)style state: (GSThemeControlState)state; +/** + * The drawing frame for button content. Defaults to the amount inset by + * the button border. + */ +- (NSRect) buttonContentRect: (NSRect)frame + forStyle: (int)style + state: (GSThemeControlState)state; + /** * Draws the indicator (normally a dotted rectangle) to show that * the view currently has keyboard focus. @@ -404,6 +418,26 @@ */ - (void) drawWindowBackground: (NSRect)frame view: (NSView*)view; +/** + * Draw the background for a menu view. This is normally a fill with the + * default window background colour and a standard button border. + */ +- (void) drawMenuViewBackground: (NSRect)frame view: (NSMenuView*)view; + +/** + * Draw the border for a menu item. + */ +- (void) drawMenuItemBorderAndBackground: (NSRect)frame + in: (NSMenuItemCell*)cell + view: (NSView*)view + state: (GSThemeControlState)state; + +- (float) defaultScrollerWidth; + +- (NSButtonCell*) cellForScrollerArrow:(NSScrollerArrow)part horizontal:(BOOL)horizontal; +- (NSCell*) cellForScrollerKnob:(BOOL)horizontal; +- (NSCell*) cellForScrollerKnobSlot:(BOOL)horizontal; + @end /**