From 4e2decaceeddfc670f13927ee0fab1420703fdc7 Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Wed, 12 Sep 2007 12:54:38 +0000 Subject: [PATCH] Made working for a flipped view. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25478 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++ Source/NSToolbarItem.m | 82 ++++++++++++++++++++++++++++++------------ 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 29a5ead7c..d19d10dbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-09-12 Fred Kiefer + + * Source/NSToolbarItem.m (GSToolbarButtonCell-drawInteriorWithFrame:inView:): + Made working for a flipped view. + 2007-09-11 Fred Kiefer * Source/NSSplitView.m (-displayRectIgnoringOpacity:inContext:): diff --git a/Source/NSToolbarItem.m b/Source/NSToolbarItem.m index 476fdf147..032edf266 100644 --- a/Source/NSToolbarItem.m +++ b/Source/NSToolbarItem.m @@ -392,6 +392,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType"; @end +// FIXME: Why does this class exists at all? @implementation GSToolbarButtonCell /* Overriden NSButtonCell method to handle cell type in a basic way which avoids @@ -413,29 +414,64 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType"; } } -// Overriden NSButtonCell method +// Overriden NSButtonCell method to make sure all test is at the same height. - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView { - NSSize titleSize = [[self attributedTitle] size]; + BOOL flippedView = [controlView isFlipped]; + NSCellImagePosition ipos = _cell.image_position; // We ignore alternateAttributedTitle, it is not needed + NSSize titleSize = [[self attributedTitle] size]; + if (flippedView == YES) + { + if (ipos == NSImageAbove) + { + ipos = NSImageBelow; + } + else if (ipos == NSImageBelow) + { + ipos = NSImageAbove; + } + } + /* We store the values we need to customize the drawing into titleRect and imageRect. */ - - titleRect.origin.x = cellFrame.origin.x; - titleRect.origin.y = cellFrame.origin.y + InsetItemTextY; - titleRect.size.width = cellFrame.size.width; - titleRect.size.height = titleSize.height; - - imageRect.origin.x = cellFrame.origin.x; - imageRect.origin.y = cellFrame.origin.y; - if ([self imagePosition] != NSImageOnly) - imageRect.origin.y += titleRect.size.height; - imageRect.size.width = cellFrame.size.width; - imageRect.size.height = cellFrame.size.height; - if ([self imagePosition] != NSImageOnly) - imageRect.size.height -= titleRect.size.height; - + switch (ipos) + { + case NSNoImage: + titleRect = cellFrame; + break; + + case NSImageOnly: + imageRect = cellFrame; + break; + + default: + case NSImageBelow: + titleRect.origin.x = cellFrame.origin.x; + titleRect.origin.y = NSMaxY(cellFrame) - titleSize.height - InsetItemTextY; + titleRect.size.width = cellFrame.size.width; + titleRect.size.height = titleSize.height; + + imageRect.origin.x = cellFrame.origin.x; + imageRect.origin.y = cellFrame.origin.y; + imageRect.size.width = cellFrame.size.width; + imageRect.size.height = cellFrame.size.height - titleRect.size.height; + break; + + case NSImageAbove: + titleRect.origin.x = cellFrame.origin.x; + titleRect.origin.y = cellFrame.origin.y + InsetItemTextY; + titleRect.size.width = cellFrame.size.width; + titleRect.size.height = titleSize.height; + + imageRect.origin.x = cellFrame.origin.x; + imageRect.origin.y = cellFrame.origin.y + titleRect.size.height; + imageRect.size.width = cellFrame.size.width; + imageRect.size.height = cellFrame.size.height - titleRect.size.height; + break; + } + [super drawInteriorWithFrame: cellFrame inView: controlView]; } @@ -1086,16 +1122,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType"; button = [[GSToolbarButton alloc] initWithToolbarItem: self]; cell = [button cell]; - [button setTitle: @""]; - [button setEnabled: NO]; + [button setTitle: @""]; + [button setEnabled: NO]; [button setBordered: NO]; [button setImagePosition: NSImageAbove]; - [cell setBezeled: YES]; + [cell setBezeled: YES]; [cell setHighlightsBy: - NSChangeGrayCellMask | NSChangeBackgroundCellMask]; + NSChangeGrayCellMask | NSChangeBackgroundCellMask]; [cell setFont: [NSFont systemFontOfSize: 11]]; - /* [NSFont smallSystemFontSize] or better should be - controlContentFontSize. */ + /* [NSFont smallSystemFontSize] or better should be + controlContentFontSize. */ [_backView release]; _backView = button;