Evan: please, enter this patch relatively to the last svn of FLTK-1.3,
it should repair the fl_push_clip bug. Let me know if yes or no.
Manolo

Index: src/fl_rect.cxx
===================================================================
--- src/fl_rect.cxx     (revision 6985)
+++ src/fl_rect.cxx     (working copy)
@@ -684,10 +684,10 @@
     r = CreateRectRgn(0,0,0,0);
 #elif defined(__APPLE_QUARTZ__)
 #ifdef __APPLE_COCOA__
-               r = NULL;
+    r = XRectangleRegion(0,0,0,0);
 #else
-               r = NewRgn();
-               SetEmptyRgn(r);
+    r = NewRgn();
+    SetEmptyRgn(r);
 #endif
 #else
 # error unsupported platform
@@ -747,12 +747,13 @@
 #elif defined(__APPLE_QUARTZ__)
   if (!r) return 1;
 #ifdef __APPLE_COCOA__
-       CGRect arg = CGRectMake(x,y,w - 1,h - 1);
-       for(int i = 0; i < r->count; i++) {
-               CGRect test = CGRectIntersection(r->rects[i], arg);
-               if( ! CGRectIsEmpty(test)) return 1;
-       }
-       return 0;
+  //CGRect arg = CGRectMake(x,y,w - 1,h - 1);
+  CGRect arg = CGRectMake(x,y,w - 0.9,h - 0.9);
+  for(int i = 0; i < r->count; i++) {
+    CGRect test = CGRectIntersection(r->rects[i], arg);
+    if( ! CGRectIsEmpty(test)) return 1;
+  }
+  return 0;
 #else
   Rect rect;
   rect.left = x; rect.top = y; rect.right = x+w; rect.bottom = y+h;
@@ -825,7 +826,8 @@
   return ret;
 #elif defined(__APPLE_QUARTZ__)
 #ifdef __APPLE_COCOA__
-       CGRect arg = CGRectMake(x,y,w - 1,h - 1);
+       //CGRect arg = CGRectMake(x,y,w - 1,h - 1);
+       CGRect arg = CGRectMake(x,y,w - 0.9,h - 0.9);
        CGRect u = CGRectMake(0,0,0,0);
        CGRect test;
        for(int i = 0; i < r->count; i++) {
@@ -837,8 +839,8 @@
                }
        X = u.origin.x;
        Y = u.origin.y;
-       W = u.size.width;
-       H = u.size.height;
+       W = u.size.width + 1;
+       H = u.size.height + 1;
        if(CGRectIsEmpty(u)) W = H = 0;
        return ! CGRectEqualToRect(arg, u);
 #else
Index: src/Fl_cocoa.mm
===================================================================
--- src/Fl_cocoa.mm     (revision 7011)
+++ src/Fl_cocoa.mm     (working copy)
@@ -122,7 +122,6 @@
 // forward declarations of variables in this file
 static int got_events = 0;
 static Fl_Window* resize_from_system;
-static NSView *viewWithLockedFocus = nil;
 static SInt32 MACsystemVersion;

 #if CONSOLIDATE_MOTION
@@ -1533,13 +1532,7 @@
 void Fl_X::flush()
 {
   w->flush();
-  if (fl_gc) {
-    CGContextFlush(fl_gc);
-    if (viewWithLockedFocus) {
-      [viewWithLockedFocus unlockFocus];
-      viewWithLockedFocus = nil;
-    }
-  }
+  if (fl_gc) CGContextFlush(fl_gc);
 }

 /*
@@ -2222,8 +2215,8 @@
     win = (Fl_Window*)win->window();
   }

-  viewWithLockedFocus = [(NSWindow*)i->xid contentView];
-  [viewWithLockedFocus lockFocusIfCanDraw];// important
+  [[NSView focusView] unlockFocus];
+  [[(NSWindow*)i->xid contentView]  lockFocus];
   i->gc = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
   fl_gc = i->gc;
   if ( fl_window_region ) XDestroyRegion(fl_window_region);
@@ -2604,7 +2597,8 @@
   Fl_Region outr = (Fl_Region)malloc(sizeof(*outr));
   outr->rects = (CGRect*)malloc(4 * r->count * sizeof(CGRect));
   outr->count = 0;
-  CGRect rect = CGRectMake(x,y,w - 1,h - 1);
+  //CGRect rect = CGRectMake(x,y,w - 1,h - 1);
+  CGRect rect = CGRectMake(x,y,w - 0.9,h - 0.9);
   for( int i = 0; i < r->count; i++) {
     CGRect A = r->rects[i];
     CGRect test = CGRectIntersection(A, rect);
@@ -2649,7 +2643,8 @@
  */
 {
   if (current == NULL) return XRectangleRegion(x,y,w,h);
-  CGRect r = CGRectMake(x, y, w - 1, h - 1);
+  CGRect r = CGRectMake(x, y, w - 0.9, h - 0.9);
+  //CGRect r = CGRectMake(x, y, w - 1, h - 1);
   Fl_Region outr = (Fl_Region)malloc(sizeof(*outr));
   outr->count = current->count;
   outr->rects =(CGRect*)malloc(outr->count * sizeof(CGRect));
@@ -3213,8 +3208,6 @@
     y += win->y();
     win = win->window();
   }
-  NSView *myview = [(NSWindow*)Fl_X::i(win)->xid contentView];
-  [myview lockFocus];
   CGFloat epsilon = 0;
   if (MACsystemVersion >= 0x1060) epsilon = 0.001;
   // The epsilon offset is absolutely necessary under 10.6. Without it, the 
top pixel row and
@@ -3222,10 +3215,23 @@
   // Under 10.5, we want no offset.
   NSRect rect = NSMakeRect(x - epsilon, y - epsilon, w, h);
   NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] 
initWithFocusedViewRect:rect];
-  [myview unlockFocus];
   *bytesPerPixel = [bitmap bitsPerPixel]/8;
+  int bpp = (int)[bitmap bytesPerPlane];
+  int bpr = (int)[bitmap bytesPerRow];
+  int hh = bpp/bpr; // sometimes hh = h-1 for unclear reason
+  int ww = bpr/(*bytesPerPixel); // sometimes ww = w-1
   unsigned char *data = new unsigned char[w * h *  *bytesPerPixel];
-  memcpy(data, [bitmap bitmapData], w * h *  *bytesPerPixel);
+  if (w == ww) {
+    memcpy(data, [bitmap bitmapData], w * hh *  *bytesPerPixel);
+  } else {
+    unsigned char *p = [bitmap bitmapData];
+    unsigned char *q = data;
+    for(int i = 0;i < hh; i++) {
+      memcpy(q, p, *bytesPerPixel * ww);
+      p += bpr;
+      q += w * *bytesPerPixel;
+      }
+  }
   [bitmap release];
   return data;
 }
Index: src/Fl.cxx
===================================================================
--- src/Fl.cxx  (revision 6985)
+++ src/Fl.cxx  (working copy)
@@ -1474,7 +1474,8 @@
       XDestroyRegion(R);
 #elif defined(__APPLE_QUARTZ__)
 #ifdef __APPLE_COCOA__
-         CGRect arg = CGRectMake(X,Y,W - 1,H - 1);
+         //CGRect arg = CGRectMake(X,Y,W - 1,H - 1);
+         CGRect arg = CGRectMake(X,Y,W - 0.9,H - 0.9);
          int j;//don't add a rectangle totally inside the Fl_Region
          for(j = 0; j < i->region->count; j++) {
                if(CGRectContainsRect(i->region->rects[j], arg)) break;
Index: FL/mac.H
===================================================================
--- FL/mac.H    (revision 7008)
+++ FL/mac.H    (working copy)
@@ -83,7 +83,8 @@
   Fl_Region R = (Fl_Region)malloc(sizeof(*R));
   R->count = 1;
   R->rects = (CGRect *)malloc(sizeof(CGRect));
-  *(R->rects) = CGRectMake(x, y, w - 1, h - 1);
+  *(R->rects) = CGRectMake(x, y, w > 0 ? w - 0.9 : 0, h > 0 ? h - 0.9 : 0);
+  //*(R->rects) = CGRectMake(x, y, w - 1, h - 1);
   return R;
 }
 inline void XDestroyRegion(Fl_Region r) {


_______________________________________________
fltk-dev mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-dev

Reply via email to