Author: mlytwyn
Date: Sat Jun 20 18:06:26 2015
New Revision: 38659

URL: http://svn.gna.org/viewcvs/gnustep?rev=38659&view=rev
Log:
Merge additional code to fix tab drawing

Modified:
    libs/gui/branches/gnustep_testplant_branch/Source/GSThemeMenu.m
    libs/gui/branches/gnustep_testplant_branch/Source/GSThemeTools.m
    libs/gui/branches/gnustep_testplant_branch/Source/NSTabView.m
    libs/gui/branches/gnustep_testplant_branch/Source/NSTabViewItem.m

Modified: libs/gui/branches/gnustep_testplant_branch/Source/GSThemeMenu.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/GSThemeMenu.m?rev=38659&r1=38658&r2=38659&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/GSThemeMenu.m     
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/GSThemeMenu.m     Sat Jun 
20 18:06:26 2015
@@ -39,6 +39,7 @@
 
 #import "NSToolbarFrameworkPrivate.h"
 #import "GSGuiPrivate.h"
+
 
 @interface NSWindow (Private)
 - (GSWindowDecorationView *) windowView;
@@ -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];
     }

Modified: libs/gui/branches/gnustep_testplant_branch/Source/GSThemeTools.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/GSThemeTools.m?rev=38659&r1=38658&r2=38659&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/GSThemeTools.m    
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/GSThemeTools.m    Sat Jun 
20 18:06:26 2015
@@ -615,6 +615,15 @@
   return [self fillRect: rect
              withTiles: tiles
             background: color
+             fillStyle: [tiles fillStyle]];
+}
+
+- (NSRect) fillRect: (NSRect)rect
+         withTiles: (GSDrawTiles*)tiles
+{
+  return [self fillRect: rect
+             withTiles: tiles
+            background: [NSColor clearColor]
              fillStyle: [tiles fillStyle]];
 }
 
@@ -783,8 +792,8 @@
 {
   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 @@
   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 @@
       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 @@
       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 @@
   // ; 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;
@@ -900,6 +912,59 @@
       contentRect.origin.y = s.height - y2 - 1;
       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 @@
 {
   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 @@
         {
           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 @@
   return tsz;
 }
 
+- (GSThemeMargins) themeMargins
+{
+  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
-{
-  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;
+                   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 @@
   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 @@
   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 @@
 {
   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 @@
   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 @@
   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
 

Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSTabView.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSTabView.m?rev=38659&r1=38658&r2=38659&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSTabView.m       
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSTabView.m       Sat Jun 
20 18:06:26 2015
@@ -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];
-         
              // 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,53 +405,11 @@
 
 - (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;
-    }
-
-  return cRect;
-}
+  NSRect result = [[GSTheme theme] tabViewContentRectForBounds: _bounds
+                                                  tabViewType: [self 
tabViewType]
+                                                      tabView: self];
+  return result;
+    }
 
 // Drawing.
 
@@ -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;
 }

Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSTabViewItem.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSTabViewItem.m?rev=38659&r1=38658&r2=38659&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSTabViewItem.m   
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSTabViewItem.m   Sat Jun 
20 18:06:26 2015
@@ -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);
 }
 


_______________________________________________
Gnustep-cvs mailing list
Gnustep-cvs@gna.org
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to