summaryrefslogtreecommitdiffstats
path: root/macosx/tkMacOSXDraw.c
diff options
context:
space:
mode:
authorculler <culler>2019-04-17 14:05:33 (GMT)
committerculler <culler>2019-04-17 14:05:33 (GMT)
commit7eaee2f2e59cbbb043964d94313d3f22a6d877a5 (patch)
tree234a219579591d68652019df28397ade8a81a33e /macosx/tkMacOSXDraw.c
parent9b521b370e0520f6a489be15b65269a33761501a (diff)
downloadtk-7eaee2f2e59cbbb043964d94313d3f22a6d877a5.zip
tk-7eaee2f2e59cbbb043964d94313d3f22a6d877a5.tar.gz
tk-7eaee2f2e59cbbb043964d94313d3f22a6d877a5.tar.bz2
Mitigate future merge conflict headaches.
Diffstat (limited to 'macosx/tkMacOSXDraw.c')
-rw-r--r--macosx/tkMacOSXDraw.c465
1 files changed, 260 insertions, 205 deletions
diff --git a/macosx/tkMacOSXDraw.c b/macosx/tkMacOSXDraw.c
index faad137..dceb3a6 100644
--- a/macosx/tkMacOSXDraw.c
+++ b/macosx/tkMacOSXDraw.c
@@ -1,9 +1,8 @@
/*
* tkMacOSXDraw.c --
*
- * This file contains functions that perform drawing to
- * Xlib windows. Most of the functions simple emulate
- * Xlib functions.
+ * This file contains functions that perform drawing to Xlib windows. Most
+ * of the functions simple emulate Xlib functions.
*
* Copyright (c) 1995-1997 Sun Microsystems, Inc.
* Copyright 2001-2009, Apple Inc.
@@ -31,7 +30,7 @@
#endif
*/
-#define radians(d) ((d) * (M_PI/180.0))
+#define radians(d) ((d) * (M_PI/180.0))
/*
* Non-antialiased CG drawing looks better and more like X11 drawing when using
@@ -40,7 +39,7 @@
#define NON_AA_CG_OFFSET .999
static int cgAntiAliasLimit = 0;
-#define notAA(w) ((w) < cgAntiAliasLimit)
+#define notAA(w) ((w) < cgAntiAliasLimit)
static int useThemedToplevel = 0;
static int useThemedFrame = 0;
@@ -119,24 +118,24 @@ TkMacOSXInitCGDrawing(
* replacement is [NSView cacheDisplayInRect: toBitmapImageRep:] and that
* is what is being used here. However, that method only works when the
* view has a valid CGContext, and a view is only guaranteed to have a
- * valid context during a call to [NSView drawRect]. To further
- * complicate matters, cacheDisplayInRect calls [NSView drawRect].
- * Essentially it is asking the view to draw a subrectangle of itself into
- * a special graphics context which is linked to the BitmapImageRep. But
- * our implementation of [NSView drawRect] does not allow recursive calls.
- * If called recursively it returns immediately without doing any drawing.
+ * valid context during a call to [NSView drawRect]. To further complicate
+ * matters, cacheDisplayInRect calls [NSView drawRect]. Essentially it is
+ * asking the view to draw a subrectangle of itself into a special
+ * graphics context which is linked to the BitmapImageRep. But our
+ * implementation of [NSView drawRect] does not allow recursive calls. If
+ * called recursively it returns immediately without doing any drawing.
* So the bottom line is that this function either returns a NULL pointer
- * or a black image. To make it useful would require a significant amount
- * of rewriting of the drawRect method. Perhaps the next release of OSX
+ * or a black image. To make it useful would require a significant amount
+ * of rewriting of the drawRect method. Perhaps the next release of OSX
* will include some more helpful ways of doing this.
*
* Results:
- * Returns an NSBitmapRep representing the image of the given
- * rectangle of the given drawable. This object is retained.
- * The caller is responsible for releasing it.
+ * Returns an NSBitmapRep representing the image of the given rectangle of
+ * the given drawable. This object is retained. The caller is responsible
+ * for releasing it.
*
- * NOTE: The x,y coordinates should be relative to a coordinate system with
- * origin at the top left, as used by XImage and CGImage, not bottom
+ * NOTE: The x,y coordinates should be relative to a coordinate system
+ * with origin at the top left, as used by XImage and CGImage, not bottom
* left as used by NSView.
*
* Side effects:
@@ -144,46 +143,46 @@ TkMacOSXInitCGDrawing(
*
*----------------------------------------------------------------------
*/
-NSBitmapImageRep*
+
+NSBitmapImageRep *
TkMacOSXBitmapRepFromDrawableRect(
- Drawable drawable,
- int x,
- int y,
- unsigned int width,
- unsigned int height)
+ Drawable drawable,
+ int x,
+ int y,
+ unsigned int width,
+ unsigned int height)
{
MacDrawable *mac_drawable = (MacDrawable *) drawable;
CGContextRef cg_context = NULL;
- CGImageRef cg_image=NULL, sub_cg_image = NULL;
+ CGImageRef cg_image = NULL, sub_cg_image = NULL;
NSBitmapImageRep *bitmap_rep = NULL;
- NSView *view=NULL;
- if ( mac_drawable->flags & TK_IS_PIXMAP ) {
-
+ NSView *view = NULL;
+ if (mac_drawable->flags & TK_IS_PIXMAP) {
/*
* This MacDrawable is a bitmap, so its view is NULL.
*/
- cg_context = TkMacOSXGetCGContextForDrawable(drawable);
CGRect image_rect = CGRectMake(x, y, width, height);
- cg_image = CGBitmapContextCreateImage( (CGContextRef) cg_context);
+
+ cg_context = TkMacOSXGetCGContextForDrawable(drawable);
+ cg_image = CGBitmapContextCreateImage((CGContextRef) cg_context);
sub_cg_image = CGImageCreateWithImageInRect(cg_image, image_rect);
- if ( sub_cg_image ) {
+ if (sub_cg_image) {
bitmap_rep = [NSBitmapImageRep alloc];
[bitmap_rep initWithCGImage:sub_cg_image];
}
- if ( cg_image ) {
+ if (cg_image) {
CGImageRelease(cg_image);
}
- } else if ( (view = TkMacOSXDrawableView(mac_drawable)) ) {
-
+ } else if ((view = TkMacOSXDrawableView(mac_drawable)) != NULL) {
/*
* Convert Tk top-left to NSView bottom-left coordinates.
*/
int view_height = [view bounds].size.height;
NSRect view_rect = NSMakeRect(x + mac_drawable->xOff,
- view_height - height - y - mac_drawable->yOff,
- width, height);
+ view_height - height - y - mac_drawable->yOff,
+ width, height);
/*
* Attempt to copy from the view to a bitmapImageRep. If the view does
@@ -218,8 +217,7 @@ TkMacOSXBitmapRepFromDrawableRect(
* None.
*
* Side effects:
- * Data is moved from a window or bitmap to a second window or
- * bitmap.
+ * Data is moved from a window or bitmap to a second window or bitmap.
*
*----------------------------------------------------------------------
*/
@@ -229,10 +227,10 @@ XCopyArea(
Display *display, /* Display. */
Drawable src, /* Source drawable. */
Drawable dst, /* Destination drawable. */
- GC gc, /* GC to use. */
+ GC gc, /* GC to use. */
int src_x, /* X & Y, width & height */
int src_y, /* define the source rectangle */
- unsigned int width, /* that will be copied. */
+ unsigned int width, /* that will be copied. */
unsigned int height,
int dest_x, /* Dest X & Y on dest rect. */
int dest_y)
@@ -249,37 +247,36 @@ XCopyArea(
}
if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) {
- return;
TkMacOSXDbgMsg("Failed to setup drawing context.");
+ return;
}
- if ( dc.context ) {
- if (srcDraw->flags & TK_IS_PIXMAP) {
- img = TkMacOSXCreateCGImageWithDrawable(src);
- }else if (TkMacOSXDrawableWindow(src)) {
- bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src,
- src_x, src_y, width, height);
- if ( bitmap_rep ) {
- img = [bitmap_rep CGImage];
- }
- } else {
- TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap.");
- }
+ if (!dc.context) {
+ TkMacOSXDbgMsg("Invalid destination drawable - no context.");
+ return;
+ }
- if (img) {
- bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
- srcRect = CGRectMake(src_x, src_y, width, height);
- dstRect = CGRectMake(dest_x, dest_y, width, height);
- TkMacOSXDrawCGImage(dst, gc, dc.context, img,
- gc->foreground, gc->background, bounds, srcRect, dstRect);
- CFRelease(img);
- } else {
- TkMacOSXDbgMsg("Failed to construct CGImage.");
+ if (srcDraw->flags & TK_IS_PIXMAP) {
+ img = TkMacOSXCreateCGImageWithDrawable(src);
+ } else if (TkMacOSXDrawableWindow(src)) {
+ bitmap_rep = TkMacOSXBitmapRepFromDrawableRect(src,
+ src_x, src_y, width, height);
+ if (bitmap_rep) {
+ img = [bitmap_rep CGImage];
}
+ } else {
+ TkMacOSXDbgMsg("Invalid source drawable - neither window nor pixmap.");
+ }
+ if (img) {
+ bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
+ srcRect = CGRectMake(src_x, src_y, width, height);
+ dstRect = CGRectMake(dest_x, dest_y, width, height);
+ TkMacOSXDrawCGImage(dst, gc, dc.context, img,
+ gc->foreground, gc->background, bounds, srcRect, dstRect);
+ CFRelease(img);
} else {
- TkMacOSXDbgMsg("Invalid destination drawable - no context.");
- return;
+ TkMacOSXDbgMsg("Failed to construct CGImage.");
}
TkMacOSXRestoreDrawingContext(&dc);
@@ -290,10 +287,9 @@ XCopyArea(
*
* XCopyPlane --
*
- * Copies a bitmap from a source drawable to a destination
- * drawable. The plane argument specifies which bit plane of
- * the source contains the bitmap. Note that this implementation
- * ignores the gc->function.
+ * Copies a bitmap from a source drawable to a destination drawable. The
+ * plane argument specifies which bit plane of the source contains the
+ * bitmap. Note that this implementation ignores the gc->function.
*
* Results:
* None.
@@ -334,29 +330,50 @@ XCopyPlane(
if (!TkMacOSXSetupDrawingContext(dst, gc, 1, &dc)) {
return;
}
+
CGContextRef context = dc.context;
+
if (context) {
CGImageRef img = TkMacOSXCreateCGImageWithDrawable(src);
+
if (img) {
TkpClipMask *clipPtr = (TkpClipMask *) gc->clip_mask;
unsigned long imageBackground = gc->background;
- if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP){
+
+ if (clipPtr && clipPtr->type == TKP_CLIP_PIXMAP) {
srcRect = CGRectMake(src_x, src_y, width, height);
- CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(clipPtr->value.pixmap);
- CGImageRef submask = CGImageCreateWithImageInRect(img, srcRect);
+ CGImageRef mask = TkMacOSXCreateCGImageWithDrawable(
+ clipPtr->value.pixmap);
+ CGImageRef submask = CGImageCreateWithImageInRect(
+ img, srcRect);
CGRect rect = CGRectMake(dest_x, dest_y, width, height);
+
rect = CGRectOffset(rect, dstDraw->xOff, dstDraw->yOff);
CGContextSaveGState(context);
- /* Move the origin of the destination to top left. */
- CGContextTranslateCTM(context, 0, rect.origin.y + CGRectGetMaxY(rect));
+
+ /*
+ * Move the origin of the destination to top left.
+ */
+
+ CGContextTranslateCTM(context,
+ 0, rect.origin.y + CGRectGetMaxY(rect));
CGContextScaleCTM(context, 1, -1);
- /* Fill with the background color, clipping to the mask. */
+
+ /*
+ * Fill with the background color, clipping to the mask.
+ */
+
CGContextClipToMask(context, rect, submask);
TkMacOSXSetColorInContext(gc, gc->background, dc.context);
CGContextFillRect(context, rect);
- /* Fill with the foreground color, clipping to the
- intersection of img and mask. */
- CGImageRef subimage = CGImageCreateWithImageInRect(img, srcRect);
+
+ /*
+ * Fill with the foreground color, clipping to the
+ * intersection of img and mask.
+ */
+
+ CGImageRef subimage = CGImageCreateWithImageInRect(
+ img, srcRect);
CGContextClipToMask(context, rect, subimage);
TkMacOSXSetColorInContext(gc, gc->foreground, context);
CGContextFillRect(context, rect);
@@ -366,22 +383,31 @@ XCopyPlane(
CGImageRelease(submask);
CGImageRelease(subimage);
} else {
- bounds = CGRectMake(0, 0, srcDraw->size.width, srcDraw->size.height);
+ bounds = CGRectMake(0, 0,
+ srcDraw->size.width, srcDraw->size.height);
srcRect = CGRectMake(src_x, src_y, width, height);
dstRect = CGRectMake(dest_x, dest_y, width, height);
- TkMacOSXDrawCGImage(dst, gc, dc.context, img, gc->foreground,
- imageBackground, bounds, srcRect, dstRect);
+ TkMacOSXDrawCGImage(dst, gc, dc.context, img,
+ gc->foreground, imageBackground, bounds,
+ srcRect, dstRect);
CGImageRelease(img);
}
- } else { /* no image */
+ } else {
+ /* no image */
TkMacOSXDbgMsg("Invalid source drawable");
}
} else {
- TkMacOSXDbgMsg("Invalid destination drawable - could not get a bitmap context.");
+ TkMacOSXDbgMsg("Invalid destination drawable - "
+ "could not get a bitmap context.");
}
TkMacOSXRestoreDrawingContext(&dc);
- } else { /* source drawable is a window, not a Pixmap */
- XCopyArea(display, src, dst, gc, src_x, src_y, width, height, dest_x, dest_y);
+ } else {
+ /*
+ * Source drawable is a Window, not a Pixmap.
+ */
+
+ XCopyArea(display, src, dst, gc, src_x, src_y, width, height,
+ dest_x, dest_y);
}
}
@@ -430,7 +456,7 @@ TkMacOSXCreateCGImageWithDrawable(
*----------------------------------------------------------------------
*/
-static NSImage*
+static NSImage *
CreateNSImageWithPixmap(
Pixmap pixmap,
int width,
@@ -466,7 +492,7 @@ CreateNSImageWithPixmap(
*----------------------------------------------------------------------
*/
-NSImage*
+NSImage *
TkMacOSXGetNSImageWithTkImage(
Display *display,
Tk_Image image,
@@ -499,7 +525,7 @@ TkMacOSXGetNSImageWithTkImage(
*----------------------------------------------------------------------
*/
-NSImage*
+NSImage *
TkMacOSXGetNSImageWithBitmap(
Display *display,
Pixmap bitmap,
@@ -550,23 +576,24 @@ TkMacOSXGetCGContextForDrawable(
CGColorSpaceRef colorspace = NULL;
CGBitmapInfo bitmapInfo =
#ifdef __LITTLE_ENDIAN__
- kCGBitmapByteOrder32Host;
+ kCGBitmapByteOrder32Host;
#else
- kCGBitmapByteOrderDefault;
+ kCGBitmapByteOrderDefault;
#endif
char *data;
- CGRect bounds = CGRectMake(0, 0, macDraw->size.width, macDraw->size.height);
+ CGRect bounds = CGRectMake(0, 0,
+ macDraw->size.width, macDraw->size.height);
if (macDraw->flags & TK_IS_BW_PIXMAP) {
bitsPerPixel = 8;
- bitmapInfo = (CGBitmapInfo)kCGImageAlphaOnly;
+ bitmapInfo = (CGBitmapInfo) kCGImageAlphaOnly;
} else {
colorspace = CGColorSpaceCreateDeviceRGB();
bitsPerPixel = 32;
bitmapInfo |= kCGImageAlphaPremultipliedFirst;
}
- bytesPerRow = ((size_t) macDraw->size.width * bitsPerPixel + 127) >> 3
- & ~15;
+ bytesPerRow = ((size_t)
+ macDraw->size.width * bitsPerPixel + 127) >> 3 & ~15;
len = macDraw->size.height * bytesPerRow;
data = ckalloc(len);
bzero(data, len);
@@ -630,8 +657,8 @@ TkMacOSXDrawCGImage(
dstBounds = CGRectOffset(dstBounds, macDraw->xOff, macDraw->yOff);
if (CGImageIsMask(image)) {
if (macDraw->flags & TK_IS_BW_PIXMAP) {
-
- /* Set fill color to black; background comes from the context,
+ /*
+ * Set fill color to black; background comes from the context,
* or is transparent.
*/
@@ -655,11 +682,13 @@ TkMacOSXDrawCGImage(
CGContextSetRGBFillColor(context, 0, 1, 0, 0.1);
CGContextFillRect(context, dstBounds);
CGContextStrokeRect(context, dstBounds);
+
CGPoint p[4] = {dstBounds.origin,
CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMaxY(dstBounds)),
CGPointMake(CGRectGetMinX(dstBounds), CGRectGetMaxY(dstBounds)),
CGPointMake(CGRectGetMaxX(dstBounds), CGRectGetMinY(dstBounds))
};
+
CGContextStrokeLineSegments(context, p, 4);
CGContextRestoreGState(context);
TkMacOSXDbgMsg("Drawing CGImage at (x=%f, y=%f), (w=%f, h=%f)",
@@ -736,12 +765,13 @@ XDrawLines(
CGContextAddLineToPoint(dc.context, prevx, prevy);
}
}
+
/*
- * In the case of closed polylines, the first and last points
- * are the same. We want miter or bevel join be rendered also
- * at this point, this needs telling CoreGraphics that the
- * path is closed.
+ * In the case of closed polylines, the first and last points are the
+ * same. We want miter or bevel join be rendered also at this point,
+ * this needs telling CoreGraphics that the path is closed.
*/
+
if ((points[0].x == points[npoints-1].x) &&
(points[0].y == points[npoints-1].y)) {
CGContextClosePath(dc.context);
@@ -820,10 +850,10 @@ XDrawSegments(
void
XFillPolygon(
- Display* display, /* Display. */
+ Display *display, /* Display. */
Drawable d, /* Draw on this. */
GC gc, /* Use this GC. */
- XPoint* points, /* Array of points. */
+ XPoint *points, /* Array of points. */
int npoints, /* Number of points. */
int shape, /* Shape to draw. */
int mode) /* Drawing mode. */
@@ -902,8 +932,7 @@ XDrawRectangle(
double o = (lw % 2) ? .5 : 0;
rect = CGRectMake(
- macWin->xOff + x + o,
- macWin->yOff + y + o,
+ macWin->xOff + x + o, macWin->yOff + y + o,
width, height);
CGContextStrokeRect(dc.context, rect);
}
@@ -916,17 +945,15 @@ XDrawRectangle(
*
* XDrawRectangles --
*
- * Draws the outlines of the specified rectangles as if a
- * five-point PolyLine protocol request were specified for each
- * rectangle:
+ * Draws the outlines of the specified rectangles as if a five-point
+ * PolyLine protocol request were specified for each rectangle:
*
* [x,y] [x+width,y] [x+width,y+height] [x,y+height] [x,y]
*
- * For the specified rectangles, these functions do not draw a
- * pixel more than once. XDrawRectangles draws the rectangles in
- * the order listed in the array. If rectangles intersect, the
- * intersecting pixels are drawn multiple times. Draws a
- * rectangle.
+ * For the specified rectangles, these functions do not draw a pixel more
+ * than once. XDrawRectangles draws the rectangles in the order listed in
+ * the array. If rectangles intersect, the intersecting pixels are drawn
+ * multiple times. Draws a rectangle.
*
* Results:
* None.
@@ -991,7 +1018,7 @@ XDrawRectangles(
int
XFillRectangles(
- Display* display, /* Display. */
+ Display *display, /* Display. */
Drawable d, /* Draw on this. */
GC gc, /* Use this GC. */
XRectangle *rectangles, /* Rectangle array. */
@@ -1042,7 +1069,7 @@ XFillRectangles(
void
XDrawArc(
- Display* display, /* Display. */
+ Display *display, /* Display. */
Drawable d, /* Draw on this. */
GC gc, /* Use this GC. */
int x, int y, /* Upper left of bounding rect. */
@@ -1099,14 +1126,13 @@ XDrawArc(
*
* XDrawArcs --
*
- * Draws multiple circular or elliptical arcs. Each arc is
- * specified by a rectangle and two angles. The center of the
- * circle or ellipse is the center of the rect- angle, and the
- * major and minor axes are specified by the width and height.
- * Positive angles indicate counterclock- wise motion, and
- * negative angles indicate clockwise motion. If the magnitude
- * of angle2 is greater than 360 degrees, XDrawArcs truncates it
- * to 360 degrees.
+ * Draws multiple circular or elliptical arcs. Each arc is specified by a
+ * rectangle and two angles. The center of the circle or ellipse is the
+ * center of the rect- angle, and the major and minor axes are specified
+ * by the width and height. Positive angles indicate counterclock- wise
+ * motion, and negative angles indicate clockwise motion. If the magnitude
+ * of angle2 is greater than 360 degrees, XDrawArcs truncates it to 360
+ * degrees.
*
* Results:
* None.
@@ -1125,7 +1151,6 @@ XDrawArcs(
XArc *arcArr,
int nArcs)
{
-
MacDrawable *macWin = (MacDrawable *) d;
TkMacOSXDrawingContext dc;
XArc *arcPtr;
@@ -1195,7 +1220,7 @@ XDrawArcs(
void
XFillArc(
- Display* display, /* Display. */
+ Display *display, /* Display. */
Drawable d, /* Draw on this. */
GC gc, /* Use this GC. */
int x, int y, /* Upper left of bounding rect. */
@@ -1360,13 +1385,12 @@ XMaxRequestSize(
*
* TkScrollWindow --
*
- * Scroll a rectangle of the specified window and accumulate
- * a damage region.
+ * Scroll a rectangle of the specified window and accumulate a damage
+ * region.
*
* Results:
- * Returns 0 if the scroll generated no additional damage.
- * Otherwise, sets the region that needs to be repainted after
- * scrolling and returns 1.
+ * Returns 0 if the scroll generated no additional damage. Otherwise, sets
+ * the region that needs to be repainted after scrolling and returns 1.
*
* Side effects:
* Scrolls the bits in the window.
@@ -1385,47 +1409,63 @@ TkScrollWindow(
{
Drawable drawable = Tk_WindowId(tkwin);
MacDrawable *macDraw = (MacDrawable *) drawable;
- TKContentView *view = (TKContentView *)TkMacOSXDrawableView(macDraw);
+ TKContentView *view = (TKContentView *) TkMacOSXDrawableView(macDraw);
CGRect srcRect, dstRect;
HIShapeRef dmgRgn = NULL, extraRgn = NULL;
NSRect bounds, visRect, scrollSrc, scrollDst;
int result = 0;
- if ( view ) {
- /* Get the scroll area in NSView coordinates (origin at bottom left). */
+ if (view) {
+ /*
+ * Get the scroll area in NSView coordinates (origin at bottom left).
+ */
+
bounds = [view bounds];
scrollSrc = NSMakeRect(macDraw->xOff + x,
- bounds.size.height - height - (macDraw->yOff + y),
- width, height);
+ bounds.size.height - height - (macDraw->yOff + y),
+ width, height);
scrollDst = NSOffsetRect(scrollSrc, dx, -dy);
- /* Limit scrolling to the window content area. */
+ /*
+ * Limit scrolling to the window content area.
+ */
+
visRect = [view visibleRect];
scrollSrc = NSIntersectionRect(scrollSrc, visRect);
scrollDst = NSIntersectionRect(scrollDst, visRect);
- if ( !NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst) ) {
+ if (!NSIsEmptyRect(scrollSrc) && !NSIsEmptyRect(scrollDst)) {
/*
* Mark the difference between source and destination as damaged.
- * This region is described in NSView coordinates (y=0 at the bottom)
- * and converted to Tk coordinates later.
+ * This region is described in NSView coordinates (y=0 at the
+ * bottom) and converted to Tk coordinates later.
*/
srcRect = CGRectMake(x, y, width, height);
dstRect = CGRectOffset(srcRect, dx, dy);
- /* Compute the damage. */
+ /*
+ * Compute the damage.
+ */
+
dmgRgn = HIShapeCreateMutableWithRect(&srcRect);
extraRgn = HIShapeCreateWithRect(&dstRect);
- ChkErr(HIShapeDifference, dmgRgn, extraRgn, (HIMutableShapeRef) dmgRgn);
+ ChkErr(HIShapeDifference, dmgRgn, extraRgn,
+ (HIMutableShapeRef) dmgRgn);
result = HIShapeIsEmpty(dmgRgn) ? 0 : 1;
- /* Convert to Tk coordinates, offset by the window origin. */
+ /*
+ * Convert to Tk coordinates, offset by the window origin.
+ */
+
TkMacOSXSetWithNativeRegion(damageRgn, dmgRgn);
if (extraRgn) {
CFRelease(extraRgn);
}
- /* Scroll the rectangle. */
+ /*
+ * Scroll the rectangle.
+ */
+
[view scrollRect:scrollSrc by:NSMakeSize(dx, -dy)];
}
} else {
@@ -1472,8 +1512,8 @@ TkMacOSXSetUpGraphicsPort(
* Set up a drawing context for the given drawable and GC.
*
* Results:
- * Boolean indicating whether it is ok to draw; if false, drawing
- * context was not setup, so do not attempt to draw and do not call
+ * Boolean indicating whether it is ok to draw; if false, drawing context
+ * was not setup, so do not attempt to draw and do not call
* TkMacOSXRestoreDrawingContext().
*
* Side effects:
@@ -1486,18 +1526,18 @@ Bool
TkMacOSXSetupDrawingContext(
Drawable d,
GC gc,
- int useCG, /* advisory only ! */
+ int useCG, /* advisory only ! */
TkMacOSXDrawingContext *dcPtr)
{
- MacDrawable *macDraw = ((MacDrawable*)d);
+ MacDrawable *macDraw = (MacDrawable *) d;
Bool canDraw = true;
NSWindow *win = NULL;
TkMacOSXDrawingContext dc = {};
CGRect clipBounds;
/*
- * If the drawable is not a pixmap and it has an associated
- * NSWindow then we know we are drawing to a window.
+ * If the drawable is not a pixmap and it has an associated NSWindow then
+ * we know we are drawing to a window.
*/
if (!(macDraw->flags & TK_IS_PIXMAP)) {
@@ -1516,9 +1556,8 @@ TkMacOSXSetupDrawingContext(
}
/*
- * If we already have a CGContext, use it. Otherwise, if we
- * are drawing to a window then we can get one from the
- * window.
+ * If we already have a CGContext, use it. Otherwise, if we are drawing to
+ * a window then we can get one from the window.
*/
dc.context = TkMacOSXGetCGContextForDrawable(d);
@@ -1526,35 +1565,34 @@ TkMacOSXSetupDrawingContext(
dc.portBounds = clipBounds = CGContextGetClipBoundingBox(dc.context);
} else if (win) {
NSView *view = TkMacOSXDrawableView(macDraw);
- if (view) {
-
- /*
- * We can only draw into the view when the current CGContext is
- * valid and belongs to the view. Validity can only be guaranteed
- * inside of a view's drawRect or setFrame methods. The isDrawing
- * attribute tells us whether we are being called from one of those
- * methods.
- *
- * If the CGContext is not valid, or belongs to a different View,
- * then we mark our view as needing display and return failure.
- * It should get drawn in a later call to drawRect.
- */
- if (view != [NSView focusView]) {
- [view setNeedsDisplay:YES];
- canDraw = false;
- goto end;
- }
- dc.view = view;
- dc.context = GET_CGCONTEXT;
- dc.portBounds = NSRectToCGRect([view bounds]);
- if (dc.clipRgn) {
- clipBounds = CGContextGetClipBoundingBox(dc.context);
- }
- } else {
+ if (!view) {
Tcl_Panic("TkMacOSXSetupDrawingContext(): "
"no NSView to draw into !");
}
+
+ /*
+ * We can only draw into the view when the current CGContext is valid
+ * and belongs to the view. Validity can only be guaranteed inside of
+ * a view's drawRect or setFrame methods. The isDrawing attribute
+ * tells us whether we are being called from one of those methods.
+ *
+ * If the CGContext is not valid, or belongs to a different View, then
+ * we mark our view as needing display and return failure. It should
+ * get drawn in a later call to drawRect.
+ */
+
+ if (view != [NSView focusView]) {
+ [view setNeedsDisplay:YES];
+ canDraw = false;
+ goto end;
+ }
+ dc.view = view;
+ dc.context = GET_CGCONTEXT;
+ dc.portBounds = NSRectToCGRect([view bounds]);
+ if (dc.clipRgn) {
+ clipBounds = CGContextGetClipBoundingBox(dc.context);
+ }
} else {
Tcl_Panic("TkMacOSXSetupDrawingContext(): "
"no context to draw into !");
@@ -1565,8 +1603,13 @@ TkMacOSXSetupDrawingContext(
*/
if (dc.context) {
- CGAffineTransform t = { .a = 1, .b = 0, .c = 0, .d = -1, .tx = 0,
- .ty = dc.portBounds.size.height};
+ CGAffineTransform t = {
+ .a = 1, .b = 0,
+ .c = 0, .d = -1,
+ .tx = 0,
+ .ty = dc.portBounds.size.height
+ };
+
dc.portBounds.origin.x += macDraw->xOff;
dc.portBounds.origin.y += macDraw->yOff;
CGContextSaveGState(dc.context);
@@ -1581,6 +1624,7 @@ TkMacOSXSetupDrawingContext(
CGContextRestoreGState(dc.context);
#endif /* TK_MAC_DEBUG_DRAWING */
CGRect r;
+
if (!HIShapeIsRectangular(dc.clipRgn) || !CGRectContainsRect(
*HIShapeGetBounds(dc.clipRgn, &r),
CGRectApplyAffineTransform(clipBounds, t))) {
@@ -1608,21 +1652,28 @@ TkMacOSXSetupDrawingContext(
CGContextSetPatternPhase(dc.context, CGSizeMake(
dc.portBounds.size.width, dc.portBounds.size.height));
}
- if(gc->function != GXcopy) {
+ if (gc->function != GXcopy) {
TkMacOSXDbgMsg("Logical functions other than GXcopy are "
"not supported for CG drawing!");
}
- /* When should we antialias? */
+
+ /*
+ * When should we antialias?
+ */
+
shouldAntialias = !notAA(gc->line_width);
if (!shouldAntialias) {
- /* Make non-antialiased CG drawing look more like X11 */
+ /*
+ * Make non-antialiased CG drawing look more like X11.
+ */
+
w -= (gc->line_width ? NON_AA_CG_OFFSET : 0);
}
CGContextSetShouldAntialias(dc.context, shouldAntialias);
CGContextSetLineWidth(dc.context, w);
if (gc->line_style != LineSolid) {
int num = 0;
- char *p = &(gc->dashes);
+ char *p = &gc->dashes;
CGFloat dashOffset = gc->dash_offset;
CGFloat lengths[10];
@@ -1632,13 +1683,13 @@ TkMacOSXSetupDrawingContext(
}
CGContextSetLineDash(dc.context, dashOffset, lengths, num);
}
- if ((unsigned)gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) {
+ if ((unsigned) gc->cap_style < sizeof(cgCap)/sizeof(CGLineCap)) {
CGContextSetLineCap(dc.context,
- cgCap[(unsigned)gc->cap_style]);
+ cgCap[(unsigned) gc->cap_style]);
}
if ((unsigned)gc->join_style < sizeof(cgJoin)/sizeof(CGLineJoin)) {
CGContextSetLineJoin(dc.context,
- cgJoin[(unsigned)gc->join_style]);
+ cgJoin[(unsigned) gc->join_style]);
}
}
}
@@ -1647,8 +1698,11 @@ end:
#ifdef TK_MAC_DEBUG_DRAWING
if (!canDraw && win != NULL) {
TkWindow *winPtr = TkMacOSXGetTkWindow(win);
- if (winPtr) fprintf(stderr, "Cannot draw in %s - postponing.\n",
- Tk_PathName(winPtr));
+
+ if (winPtr) {
+ fprintf(stderr, "Cannot draw in %s - postponing.\n",
+ Tk_PathName(winPtr));
+ }
}
#endif
if (!canDraw && dc.clipRgn) {
@@ -1719,7 +1773,9 @@ TkMacOSXGetClipRgn(
TkMacOSXUpdateClipRgn(macDraw->winPtr);
#ifdef TK_MAC_DEBUG_DRAWING
TkMacOSXDbgMsg("%s", macDraw->winPtr->pathName);
+
NSView *view = TkMacOSXDrawableView(macDraw);
+
CGContextSaveGState(context);
CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0,
-1.0, 0.0, [view bounds].size.height));
@@ -1743,8 +1799,8 @@ TkMacOSXGetClipRgn(
*
* TkMacOSXSetUpClippingRgn --
*
- * Set up the clipping region so that drawing only occurs on the
- * specified X subwindow.
+ * Set up the clipping region so that drawing only occurs on the specified
+ * X subwindow.
*
* Results:
* None.
@@ -1766,8 +1822,8 @@ TkMacOSXSetUpClippingRgn(
*
* TkpClipDrawableToRect --
*
- * Clip all drawing into the drawable d to the given rectangle.
- * If width or height are negative, reset to no clipping.
+ * Clip all drawing into the drawable d to the given rectangle. If width
+ * or height are negative, reset to no clipping.
*
* Results:
* None.
@@ -1832,8 +1888,8 @@ ClipToGC(
HIShapeRef *clipRgnPtr) /* must point to initialized variable */
{
if (gc && gc->clip_mask &&
- ((TkpClipMask*)gc->clip_mask)->type == TKP_CLIP_REGION) {
- TkRegion gcClip = ((TkpClipMask*)gc->clip_mask)->value.region;
+ ((TkpClipMask *) gc->clip_mask)->type == TKP_CLIP_REGION) {
+ TkRegion gcClip = ((TkpClipMask *) gc->clip_mask)->value.region;
int xOffset = ((MacDrawable *) d)->xOff + gc->clip_x_origin;
int yOffset = ((MacDrawable *) d)->yOff + gc->clip_y_origin;
HIShapeRef clipRgn = *clipRgnPtr, gcClipRgn;
@@ -1856,10 +1912,9 @@ ClipToGC(
*
* TkMacOSXMakeStippleMap --
*
- * Given a drawable and a stipple pattern this function draws the
- * pattern repeatedly over the drawable. The drawable can then
- * be used as a mask for bit-bliting a stipple pattern over an
- * object.
+ * Given a drawable and a stipple pattern this function draws the pattern
+ * repeatedly over the drawable. The drawable can then be used as a mask
+ * for bit-bliting a stipple pattern over an object.
*
* Results:
* A BitMap data structure.
@@ -1883,12 +1938,12 @@ TkMacOSXMakeStippleMap(
*
* TkpDrawHighlightBorder --
*
- * This procedure draws a rectangular ring around the outside of
- * a widget to indicate that it has received the input focus.
+ * This procedure draws a rectangular ring around the outside of a widget
+ * to indicate that it has received the input focus.
*
- * On the Macintosh, this puts a 1 pixel border in the bgGC color
- * between the widget and the focus ring, except in the case where
- * highlightWidth is 1, in which case the border is left out.
+ * On the Macintosh, this puts a 1 pixel border in the bgGC color between
+ * the widget and the focus ring, except in the case where highlightWidth
+ * is 1, in which case the border is left out.
*
* For proper Mac L&F, use highlightWidth of 3.
*
@@ -1896,8 +1951,8 @@ TkMacOSXMakeStippleMap(
* None.
*
* Side effects:
- * A rectangle "width" pixels wide is drawn in "drawable",
- * corresponding to the outer area of "tkwin".
+ * A rectangle "width" pixels wide is drawn in "drawable", corresponding
+ * to the outer area of "tkwin".
*
*----------------------------------------------------------------------
*/
@@ -1926,8 +1981,8 @@ TkpDrawHighlightBorder (
*
* TkpDrawFrame --
*
- * This procedure draws the rectangular frame area. If the user
- * has requested themeing, it draws with the background theme.
+ * This procedure draws the rectangular frame area. If the user has
+ * requested themeing, it draws with the background theme.
*
* Results:
* None.