Merge additional code to fix tab drawing

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/gnustep_testplant_branch@38659 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Marcian Lytwyn 2015-06-20 16:06:26 +00:00
parent 3d60883d2a
commit 060fca2f50
4 changed files with 164 additions and 86 deletions

View file

@ -40,6 +40,7 @@
#import "NSToolbarFrameworkPrivate.h"
#import "GSGuiPrivate.h"
@interface NSWindow (Private)
- (GSWindowDecorationView *) windowView;
- (void) _setMenu: (NSMenu *)menu;
@ -105,17 +106,17 @@
preferredEdge: (NSRectEdge)edge
selectedItem: (int)selectedItem
{
BOOL pe = [[GSTheme theme] doesProcessEventsForPopUpMenu];
/* Ensure the window responds when run in modal and should
* process events. Or revert this if theme has changed.
*/
if ([[GSTheme theme] doesProcessEventsForPopUpMenu] &&
![[mr window] worksWhenModal])
if (pe && ![[mr window] worksWhenModal])
{
[(NSPanel *)[mr window] setWorksWhenModal: YES];
}
if (![[GSTheme theme] doesProcessEventsForPopUpMenu] &&
[[mr window] worksWhenModal])
if (!pe && [[mr window] worksWhenModal])
{
[(NSPanel *)[mr window] setWorksWhenModal: NO];
}

View file

@ -618,6 +618,15 @@ withRepeatedImage: (NSImage*)image
fillStyle: [tiles fillStyle]];
}
- (NSRect) fillRect: (NSRect)rect
withTiles: (GSDrawTiles*)tiles
{
return [self fillRect: rect
withTiles: tiles
background: [NSColor clearColor]
fillStyle: [tiles fillStyle]];
}
- (NSRect) fillRect: (NSRect)rect
withTiles: (GSDrawTiles*)tiles
background: (NSColor*)color
@ -783,8 +792,8 @@ withRepeatedImage: (NSImage*)image
{
int i;
CGFloat r,g,b,a;
int x1 = -1;
int x2 = -1;
int x1 = -1; // x1, x2, y1, y2, are in flipped coordinates
int x2 = -1; // 0,0 is the top-left pixel
int y1 = -1;
int y2 = -1;
NSSize s = [image size];
@ -825,6 +834,7 @@ withRepeatedImage: (NSImage*)image
scaleFactor = 1.0f;
style = GSThemeFillStyleScaleAll;
// These are all in _unflipped_ coordinates
rects[TileTL] = NSMakeRect(1, s.height - y1, x1 - 1, y1 - 1);
rects[TileTM] = NSMakeRect(x1, s.height - y1, 1 + x2 - x1, y1 - 1);
rects[TileTR] = NSMakeRect(x2 + 1, s.height - y1, s.width - x2 - 2, y1 - 1);
@ -848,11 +858,11 @@ withRepeatedImage: (NSImage*)image
NSColor *pixelColor = [rep colorAtX: i y: s.height - 1];
[pixelColor getRed: &r green: &g blue: &b alpha: &a];
if (a > 0 && x1 == -1)
if ((a == 1 && r == 0 && g == 0 && b == 0) && x1 == -1)
{
x1 = i;
}
else if (a == 0 && x1 != -1)
else if (!(a == 1 && r == 0 && g == 0 && b == 0) && x1 != -1)
{
x2 = i - 1;
break;
@ -864,11 +874,11 @@ withRepeatedImage: (NSImage*)image
NSColor *pixelColor = [rep colorAtX: s.width - 1 y: i];
[pixelColor getRed: &r green: &g blue: &b alpha: &a];
if (a > 0 && y1 == -1)
if ((a == 1 && r == 0 && g == 0 && b == 0) && y1 == -1)
{
y1 = i;
}
else if (a == 0 && y1 != -1)
else if (!(a == 1 && r == 0 && g == 0 && b == 0) && y1 != -1)
{
y2 = i - 1;
break;
@ -879,6 +889,8 @@ withRepeatedImage: (NSImage*)image
// ; if either the horizontal or vertical information is missing, use the
// geometry from rects[TileCM]
// contentRect is in unflipped coordinates, like rects[]
if (x1 == -1)
{
contentRect.origin.x = rects[TileCM].origin.x;
@ -901,6 +913,59 @@ withRepeatedImage: (NSImage*)image
contentRect.size.height = 1 + y2 - y1;
}
// Measure the layout rect (the right and bottom edges of the nine-patch
// data which _isn't_ red pixels)
x1 = -1;
x2 = -1;
y1 = -1;
y2 = -1;
for (i = 1; i < (s.width - 1); i++)
{
NSColor *pixelColor = [rep colorAtX: i y: s.height - 1];
[pixelColor getRed: &r green: &g blue: &b alpha: &a];
if (!(a == 1 && r == 1 && g == 0 && b == 0) && x1 == -1)
{
x1 = i;
}
else if ((a == 1 && r == 1 && g == 0 && b == 0) && x1 != -1)
{
x2 = i - 1;
break;
}
}
for (i = 1; i < (s.height - 1); i++)
{
NSColor *pixelColor = [rep colorAtX: s.width - 1 y: i];
[pixelColor getRed: &r green: &g blue: &b alpha: &a];
if (!(a == 1 && r == 1 && g == 0 && b == 0) && y1 == -1)
{
y1 = i;
}
else if ((a == 1 && r == 1 && g == 0 && b == 0) && y1 != -1)
{
y2 = i - 1;
break;
}
}
if (x2 == -1)
{
x2 = s.width - 2;
}
if (y2 == -1)
{
y2 = s.height - 2;
}
layoutRect = NSMakeRect(x1, s.height - y2 - 1, 1 + x2 - x1, 1 + y2 - y1);
[self validateTilesSizeWithImage: image];
return self;
}
@ -923,6 +988,8 @@ withRepeatedImage: (NSImage*)image
{
int i;
originalRectCM = rects[TileCM];
for (i = 0; i < 9; i++)
{
if (rects[i].origin.x < 0.0 || rects[i].origin.y < 0.0
@ -935,6 +1002,8 @@ withRepeatedImage: (NSImage*)image
{
images[i]
= [[self extractImageFrom: image withRect: rects[i]] retain];
// FIXME: This makes no sense to me, why not leave the
// rect origins at their original values?
rects[i].origin.x = 0;
rects[i].origin.y = 0;
}
@ -1078,20 +1147,44 @@ withRepeatedImage: (NSImage*)image
return tsz;
}
- (NSRect) contentRectForRect: (NSRect)rect
- (GSThemeMargins) themeMargins
{
NSSize total = [self computeTotalTilesSize];
NSRect inFill = NSMakeRect(
rect.origin.x + contentRect.origin.x,
rect.origin.y + contentRect.origin.y,
rect.size.width - (total.width - contentRect.size.width),
rect.size.height - (total.height - contentRect.size.height));
return inFill;
NSRect cm = originalRectCM;
GSThemeMargins margins;
margins.left = rects[TileCL].size.width;
margins.right = rects[TileCR].size.width;
margins.top = rects[TileTM].size.height;
margins.bottom = rects[TileBM].size.height;
// Adjust for contentRect != cm
margins.left += (contentRect.origin.x - cm.origin.x);
margins.bottom += (contentRect.origin.y - cm.origin.y);
margins.right += (NSMaxX(cm) - NSMaxX(contentRect));
margins.top += (NSMaxY(cm) - NSMaxY(contentRect));
return margins;
}
- (NSRect) contentRectForRect: (NSRect)rect
isFlipped: (BOOL)flipped
{
GSThemeMargins margins = [self themeMargins];
rect.origin.x += margins.left;
rect.origin.y += flipped ? margins.top : margins.bottom;
rect.size.width -= (margins.left + margins.right);
rect.size.height -= (margins.top + margins.bottom);
return rect;
}
- (NSRect) noneStyleFillRect: (NSRect)rect
{
NSRect inFill = [self contentRectForRect: rect];
NSRect inFill = [self contentRectForRect: rect isFlipped: NO];
[self repeatFillRect: rect];
[self drawCornersRect: rect];
return inFill;
@ -1102,7 +1195,7 @@ withRepeatedImage: (NSImage*)image
BOOL flipped = [[GSCurrentContext() focusView] isFlipped];
NSRect r = rects[TileCM];
NSRect inFill = [self contentRectForRect: rect];
NSRect inFill = [self contentRectForRect: rect isFlipped: flipped];
[self repeatFillRect: rect];
[self drawCornersRect: rect];
@ -1126,7 +1219,7 @@ withRepeatedImage: (NSImage*)image
BOOL flipped = [[GSCurrentContext() focusView] isFlipped];
NSSize tsz = [self computeTotalTilesSize];
NSRect inFill = [self contentRectForRect: rect];
NSRect inFill = [self contentRectForRect: rect isFlipped: flipped];
[self repeatFillRect: rect];
[self drawCornersRect: rect];
@ -1145,7 +1238,7 @@ withRepeatedImage: (NSImage*)image
{
BOOL flipped = [[GSCurrentContext() focusView] isFlipped];
NSRect inFill = [self contentRectForRect: rect];
NSRect inFill = [self contentRectForRect: rect isFlipped: flipped];
NSImage *im = [images[TileCM] copy];
NSRect r = rects[TileCM];
@ -1189,7 +1282,7 @@ withRepeatedImage: (NSImage*)image
NSImage *img;
NSRect imgRect;
NSRect inFill = [self contentRectForRect: rect];
NSRect inFill = [self contentRectForRect: rect isFlipped: flipped];
[self scaleFillRect: rect];
[self drawCornersRect: rect];
@ -1609,5 +1702,18 @@ withRepeatedImage: (NSImage*)image
style = aStyle;
}
- (NSSize) size
{
const CGFloat width = rects[TileCL].size.width
+ rects[TileCM].size.width
+ rects[TileCR].size.width;
const CGFloat height = rects[TileTM].size.height
+ rects[TileCM].size.height
+ rects[TileBM].size.height;
return NSMakeSize(width, height);
}
@end

View file

@ -88,20 +88,16 @@
{
// Reset the _selected attribute to prevent crash when -dealloc calls
// -setNextKeyView:
_original_nextKeyView = nil;
_selected = nil;
RELEASE(_items);
RELEASE(_font);
[super dealloc];
}
/*
// FIXME: This should be defined
- (BOOL) isFlipped
{
return YES;
}
*/
// tab management.
@ -267,8 +263,8 @@
if (selectedView != nil)
{
NSView *firstResponder;
[self addSubview: selectedView];
[self addSubview: selectedView];
// FIXME: We should not change this mask
[selectedView setAutoresizingMask:
NSViewWidthSizable | NSViewHeightSizable];
@ -278,9 +274,10 @@
{
firstResponder = [_selected view];
[_selected setInitialFirstResponder: firstResponder];
[firstResponder _setUpKeyViewLoopWithNextKeyView: _original_nextKeyView];
[firstResponder _setUpKeyViewLoopWithNextKeyView:
_original_nextKeyView];
}
[super setNextKeyView: firstResponder];
[self setNextKeyView: firstResponder];
[_window makeFirstResponder: firstResponder];
}
@ -386,21 +383,20 @@
- (NSSize) minimumSize
{
// FIXME: This should allow some space for the tabs
switch (_type)
{
case NSTopTabsBezelBorder:
return NSMakeSize(2, 19.5);
return NSMakeSize(3, 19);
case NSNoTabsBezelBorder:
return NSMakeSize(2, 3);
return NSMakeSize(3, 3);
case NSNoTabsLineBorder:
return NSMakeSize(2, 3);
return NSMakeSize(2, 2);
case NSBottomTabsBezelBorder:
return NSMakeSize(2, 16);
return NSMakeSize(3, 19);
case NSLeftTabsBezelBorder:
return NSMakeSize(16, 3);
return NSMakeSize(21, 3);
case NSRightTabsBezelBorder:
return NSMakeSize(16, 3);
return NSMakeSize(21, 3);
case NSNoTabsNoBorder:
default:
return NSZeroSize;
@ -409,54 +405,12 @@
- (NSRect) contentRect
{
NSRect cRect = _bounds;
switch (_type)
{
case NSTopTabsBezelBorder:
cRect.origin.x += 1;
cRect.origin.y += 1;
cRect.size.width -= 3;
cRect.size.height -= 19;
break;
case NSNoTabsBezelBorder:
cRect.origin.x += 1;
cRect.origin.y += 1;
cRect.size.width -= 3;
cRect.size.height -= 3;
break;
case NSNoTabsLineBorder:
cRect.origin.y += 1;
cRect.origin.x += 1;
cRect.size.width -= 2;
cRect.size.height -= 2;
break;
case NSBottomTabsBezelBorder:
cRect.origin.x += 1;
cRect.origin.y += 19;
cRect.size.width -= 3;
cRect.size.height -= 19;
break;
case NSLeftTabsBezelBorder:
cRect.origin.x += 21;
cRect.origin.y += 1;
cRect.size.width -= 21;
cRect.size.height -= 3;
break;
case NSRightTabsBezelBorder:
cRect.origin.x += 1;
cRect.origin.y += 1;
cRect.size.width -= 21;
cRect.size.height -= 3;
break;
case NSNoTabsNoBorder:
default:
break;
NSRect result = [[GSTheme theme] tabViewContentRectForBounds: _bounds
tabViewType: [self tabViewType]
tabView: self];
return result;
}
return cRect;
}
// Drawing.
- (void) drawRect: (NSRect)rect
@ -609,6 +563,15 @@
}
if ([aDecoder containsValueForKey: @"NSSelectedTabViewItem"])
{
// N.B.: As a side effect, this discards the subview frame
// and sets it to [self contentRect].
//
// This is desirable because the subview frame will be different
// depending on whether the arcive is from Cocoa or GNUstep,
// and which GNUstep theme was active at save time.
//
// However, it does mean that the tab view contents should be
// prepared to resize slightly.
[self selectTabViewItem: [aDecoder decodeObjectForKey:
@"NSSelectedTabViewItem"]];
}
@ -665,8 +628,8 @@
[aDecoder decodeValueOfObjCType: @encode(NSUInteger) at: &selected_item];
}
if (selected_item != NSNotFound)
_selected = [_items objectAtIndex: selected_item];
// N.B. Recalculates subview frame; see comment above.
[self selectTabViewItemAtIndex: selected_item];
}
return self;
}

View file

@ -194,7 +194,15 @@
[NSColor controlTextColor], NSForegroundColorAttributeName,
nil];
[string drawInRect: tabRect withAttributes: attr];
{
NSSize size = [string sizeWithAttributes: attr];
NSRect labelRect = tabRect;
labelRect.origin.y = tabRect.origin.y + ((tabRect.size.height - size.height) / 2);
labelRect.size.height = size.height;
[string drawInRect: labelRect withAttributes: attr];
}
RELEASE(attr);
}