]> Pileus Git - ~andy/gtk/blobdiff - gdk/quartz/gdkdrawable-quartz.c
Whitespace cleanup. (synthesize_crossing_events): Add comments and prevent
[~andy/gtk] / gdk / quartz / gdkdrawable-quartz.c
index 617daf962e4f31af150bcf390fadc76101a93114..3142fa4c3529d34b7a77381d8ea7b96965ff839d 100644 (file)
@@ -20,7 +20,7 @@
 
 #include <config.h>
 
-#include <cairo/cairo-quartz.h>
+#include <cairo-quartz.h>
 #include "gdkprivate-quartz.h"
 
 static gpointer parent_class;
@@ -37,7 +37,7 @@ surface_info_destroy (void *data)
 {
   SurfaceInfo *info = data;
 
-  _gdk_quartz_drawable_release_context (info->drawable, info->context);
+  gdk_quartz_drawable_release_context (info->drawable, info->context);
 
   g_free (info);
 }
@@ -55,7 +55,7 @@ gdk_quartz_ref_cairo_surface (GdkDrawable *drawable)
       GDK_WINDOW_DESTROYED (impl->wrapper))
     return NULL;
 
-  context = _gdk_quartz_drawable_get_context (drawable, TRUE);
+  context = gdk_quartz_drawable_get_context (drawable, TRUE);
   if (!context)
     return NULL;
 
@@ -116,72 +116,76 @@ gdk_quartz_get_depth (GdkDrawable *drawable)
 
 static void
 gdk_quartz_draw_rectangle (GdkDrawable *drawable,
-                         GdkGC       *gc,
-                         gboolean     filled,
-                         gint         x,
-                         gint         y,
-                         gint         width,
-                         gint         height)
+                          GdkGC       *gc,
+                          gboolean     filled,
+                          gint         x,
+                          gint         y,
+                          gint         width,
+                          gint         height)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
-  CGRect rect = CGRectMake (x + 0.5, y + 0.5, width, height);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
 
   if (!context)
     return;
 
-  _gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_update_context_from_gc (context, gc);
 
   if (filled)
     {
-      _gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+      CGRect rect = CGRectMake (x, y, width, height);
+
+      gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
                                                    _gdk_gc_get_fg_pixel (gc));
       CGContextFillRect (context, rect);
     }
   else
     {
-      _gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+      CGRect rect = CGRectMake (x + 0.5, y + 0.5, width, height);
+
+      gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
                                                      _gdk_gc_get_fg_pixel (gc));
       CGContextStrokeRect (context, rect);
     }
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
 gdk_quartz_draw_arc (GdkDrawable *drawable,
-                   GdkGC       *gc,
-                   gboolean     filled,
-                   gint         x,
-                   gint         y,
-                   gint         width,
-                   gint         height,
-                   gint         angle1,
-                   gint         angle2)
+                    GdkGC       *gc,
+                    gboolean     filled,
+                    gint         x,
+                    gint         y,
+                    gint         width,
+                    gint         height,
+                    gint         angle1,
+                    gint         angle2)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   float start_angle, end_angle;
 
   if (!context)
     return;
 
-  _gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_update_context_from_gc (context, gc);
 
   CGContextSaveGState (context);
 
-  CGContextTranslateCTM (context, 
-                        x + width / 2 + 0.5, 
-                        y + height / 2 + 0.5);
-  CGContextScaleCTM (context, 1.0, (float)height / width);
   start_angle = (2 - (angle1 / (180.0 * 64.0))) * G_PI;
   end_angle = start_angle - (angle2 / (180.0 * 64.0)) * G_PI;
 
   if (filled)
     {
-      _gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+      gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
                                                     _gdk_gc_get_fg_pixel (gc));
 
+      CGContextTranslateCTM (context,
+                             x + width / 2.0,
+                             y + height / 2.0);
+      CGContextScaleCTM (context, 1.0, (double)height / (double)width);
+
       CGContextMoveToPoint (context, 0, 0);
-      CGContextAddArc (context, 0, 0, width / 2,
+      CGContextAddArc (context, 0, 0, width / 2.0,
                       start_angle, end_angle,
                       TRUE);
       CGContextClosePath (context);
@@ -189,9 +193,15 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
     }
   else
     {
-      _gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+      gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
                                                      _gdk_gc_get_fg_pixel (gc));
-      CGContextAddArc (context, 0, 0, width / 2,
+
+      CGContextTranslateCTM (context,
+                             x + width / 2.0 + 0.5,
+                             y + height / 2.0 + 0.5);
+      CGContextScaleCTM (context, 1.0, (double)height / (double)width);
+
+      CGContextAddArc (context, 0, 0, width / 2.0,
                       start_angle, end_angle,
                       TRUE);
       CGContextStrokePath (context);
@@ -199,7 +209,7 @@ gdk_quartz_draw_arc (GdkDrawable *drawable,
 
   CGContextRestoreGState (context);
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
@@ -209,33 +219,40 @@ gdk_quartz_draw_polygon (GdkDrawable *drawable,
                         GdkPoint    *points,
                         gint         npoints)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   int i;
 
   if (!context)
     return;
 
-  _gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_update_context_from_gc (context, gc);
 
   if (filled)
-    _gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
-                                                  _gdk_gc_get_fg_pixel (gc));
-  else
-    _gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
-                                                    _gdk_gc_get_fg_pixel (gc));
-
-  CGContextMoveToPoint (context, points[0].x + 0.5, points[0].y + 0.5);
-  for (i = 1; i < npoints; i++)
-    CGContextAddLineToPoint (context, points[i].x + 0.5, points[i].y + 0.5);
+    {
+      gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+                                                   _gdk_gc_get_fg_pixel (gc));
 
-  CGContextClosePath (context);
+      CGContextMoveToPoint (context, points[0].x, points[0].y);
+      for (i = 1; i < npoints; i++)
+       CGContextAddLineToPoint (context, points[i].x, points[i].y);
 
-  if (filled)
-    CGContextFillPath (context);
+      CGContextClosePath (context);
+      CGContextFillPath (context);
+    }
   else
-    CGContextStrokePath (context);
+    {
+      gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+                                                     _gdk_gc_get_fg_pixel (gc));
+
+      CGContextMoveToPoint (context, points[0].x + 0.5, points[0].y + 0.5);
+      for (i = 1; i < npoints; i++)
+       CGContextAddLineToPoint (context, points[i].x + 0.5, points[i].y + 0.5);
+
+      CGContextClosePath (context);
+      CGContextStrokePath (context);
+    }
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
@@ -264,26 +281,31 @@ gdk_quartz_draw_text_wc (GdkDrawable    *drawable,
 
 static void
 gdk_quartz_draw_drawable (GdkDrawable *drawable,
-                        GdkGC       *gc,
-                        GdkPixmap   *src,
-                        gint         xsrc,
-                        gint         ysrc,
-                        gint         xdest,
-                        gint         ydest,
-                        gint         width,
-                        gint         height)
+                         GdkGC       *gc,
+                         GdkPixmap   *src,
+                         gint         xsrc,
+                         gint         ysrc,
+                         gint         xdest,
+                         gint         ydest,
+                         gint         width,
+                         gint         height)
 {
   int src_depth = gdk_drawable_get_depth (src);
   int dest_depth = gdk_drawable_get_depth (drawable);
-  GdkDrawableImplQuartz *impl;
   GdkDrawableImplQuartz *src_impl;
-  
-  impl = GDK_DRAWABLE_IMPL_QUARTZ (drawable);
 
   if (GDK_IS_DRAWABLE_IMPL_QUARTZ (src))
     src_impl = GDK_DRAWABLE_IMPL_QUARTZ (src);
-  else
+  else if (GDK_IS_PIXMAP (src))
     src_impl = GDK_DRAWABLE_IMPL_QUARTZ (GDK_PIXMAP_OBJECT (src)->impl);
+  else if (GDK_IS_WINDOW (src))
+    {
+      src_impl = GDK_DRAWABLE_IMPL_QUARTZ (GDK_WINDOW_OBJECT (src)->impl);
+      /* FIXME: Implement drawing a window. */
+      return;
+    }
+  else
+    g_assert_not_reached ();
   
   if (src_depth == 1)
     {
@@ -291,23 +313,24 @@ gdk_quartz_draw_drawable (GdkDrawable *drawable,
     }
   else if (dest_depth != 0 && src_depth == dest_depth)
     {
-      CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+      CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
 
       if (!context)
        return;
 
-      _gdk_quartz_update_context_from_gc (context, gc);
+      gdk_quartz_update_context_from_gc (context, gc);
 
       CGContextSetBlendMode (context, kCGBlendModeNormal);
 
       CGContextClipToRect (context, CGRectMake (xdest, ydest, width, height));
       CGContextTranslateCTM (context, xdest - xsrc, ydest - ysrc);
-      CGContextDrawImage (context, CGRectMake(0, 0, 
-                                             GDK_PIXMAP_IMPL_QUARTZ (src_impl)->width, 
-                                             GDK_PIXMAP_IMPL_QUARTZ (src_impl)->height), 
+      CGContextDrawImage (context, 
+                         CGRectMake(0, 0, 
+                                    GDK_PIXMAP_IMPL_QUARTZ (src_impl)->width, 
+                                    GDK_PIXMAP_IMPL_QUARTZ (src_impl)->height), 
                          GDK_PIXMAP_IMPL_QUARTZ (src_impl)->image);
 
-      _gdk_quartz_drawable_release_context (drawable, context);
+      gdk_quartz_drawable_release_context (drawable, context);
     }
   else
     g_warning ("Attempt to draw a drawable with depth %d to a drawable with depth %d",
@@ -316,35 +339,44 @@ gdk_quartz_draw_drawable (GdkDrawable *drawable,
 
 static void
 gdk_quartz_draw_points (GdkDrawable *drawable,
-                      GdkGC       *gc,
-                      GdkPoint    *points,
-                      gint         npoints)
+                       GdkGC       *gc,
+                       GdkPoint    *points,
+                       gint         npoints)
 {
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   int i;
 
+  if (!context)
+    return;
+
+  gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_set_context_fill_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+                                               _gdk_gc_get_fg_pixel (gc));
+
   /* Just draw 1x1 rectangles */
   for (i = 0; i < npoints; i++) 
     {
-      gdk_draw_rectangle (drawable, gc, TRUE, 
-                         points[i].x, points[i].y,
-                         1, 1);
+      CGRect rect = CGRectMake (points[i].x, points[i].y, 1, 1);
+      CGContextFillRect (context, rect);
     }
+
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
 gdk_quartz_draw_segments (GdkDrawable    *drawable,
-                        GdkGC          *gc,
-                        GdkSegment     *segs,
-                        gint            nsegs)
+                         GdkGC          *gc,
+                         GdkSegment     *segs,
+                         gint            nsegs)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   int i;
 
   if (!context)
     return;
 
-  _gdk_quartz_update_context_from_gc (context, gc);
-  _gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+  gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
                                                  _gdk_gc_get_fg_pixel (gc));
 
   for (i = 0; i < nsegs; i++)
@@ -355,7 +387,7 @@ gdk_quartz_draw_segments (GdkDrawable    *drawable,
   
   CGContextStrokePath (context);
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
@@ -364,15 +396,15 @@ gdk_quartz_draw_lines (GdkDrawable *drawable,
                       GdkPoint    *points,
                       gint         npoints)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   int i;
 
   if (!context)
     return;
 
-  _gdk_quartz_update_context_from_gc (context, gc);
-  _gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
-                                                  _gdk_gc_get_fg_pixel (gc));
+  gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_set_context_stroke_color_from_pixel (context, gdk_drawable_get_colormap (drawable),
+                                                 _gdk_gc_get_fg_pixel (gc));
   
   for (i = 1; i < npoints; i++)
     {
@@ -382,24 +414,24 @@ gdk_quartz_draw_lines (GdkDrawable *drawable,
   
   CGContextStrokePath (context);
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
 gdk_quartz_draw_pixbuf (GdkDrawable     *drawable,
-                      GdkGC           *gc,
-                      GdkPixbuf       *pixbuf,
-                      gint             src_x,
-                      gint             src_y,
-                      gint             dest_x,
-                      gint             dest_y,
-                      gint             width,
-                      gint             height,
-                      GdkRgbDither     dither,
-                      gint             x_dither,
-                      gint             y_dither)
+                       GdkGC           *gc,
+                       GdkPixbuf       *pixbuf,
+                       gint             src_x,
+                       gint             src_y,
+                       gint             dest_x,
+                       gint             dest_y,
+                       gint             width,
+                       gint             height,
+                       GdkRgbDither     dither,
+                       gint             x_dither,
+                       gint             y_dither)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   CGColorSpaceRef colorspace;
   CGDataProviderRef data_provider;
   CGImageRef image;
@@ -430,7 +462,7 @@ gdk_quartz_draw_pixbuf (GdkDrawable     *drawable,
   CGDataProviderRelease (data_provider);
   CGColorSpaceRelease (colorspace);
 
-  _gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_update_context_from_gc (context, gc);
 
   CGContextSetBlendMode (context, kCGBlendModeNormal);
 
@@ -441,21 +473,21 @@ gdk_quartz_draw_pixbuf (GdkDrawable     *drawable,
   CGContextDrawImage (context, CGRectMake (0, 0, pixbuf_width, pixbuf_height), image);
   CGImageRelease (image);
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
 gdk_quartz_draw_image (GdkDrawable     *drawable,
-                     GdkGC           *gc,
-                     GdkImage        *image,
-                     gint             xsrc,
-                     gint             ysrc,
-                     gint             xdest,
-                     gint             ydest,
-                     gint             width,
-                     gint             height)
+                      GdkGC           *gc,
+                      GdkImage        *image,
+                      gint             xsrc,
+                      gint             ysrc,
+                      gint             xdest,
+                      gint             ydest,
+                      gint             width,
+                      gint             height)
 {
-  CGContextRef context = _gdk_quartz_drawable_get_context (drawable, FALSE);
+  CGContextRef context = gdk_quartz_drawable_get_context (drawable, FALSE);
   CGColorSpaceRef colorspace;
   CGDataProviderRef data_provider;
   CGImageRef cgimage;
@@ -477,7 +509,7 @@ gdk_quartz_draw_image (GdkDrawable     *drawable,
   CGDataProviderRelease (data_provider);
   CGColorSpaceRelease (colorspace);
 
-  _gdk_quartz_update_context_from_gc (context, gc);
+  gdk_quartz_update_context_from_gc (context, gc);
 
   CGContextSetBlendMode (context, kCGBlendModeNormal);
 
@@ -488,7 +520,7 @@ gdk_quartz_draw_image (GdkDrawable     *drawable,
   CGContextDrawImage (context, CGRectMake (0, 0, image->width, image->height), cgimage);
   CGImageRelease (cgimage);
 
-  _gdk_quartz_drawable_release_context (drawable, context);
+  gdk_quartz_drawable_release_context (drawable, context);
 }
 
 static void
@@ -566,7 +598,8 @@ gdk_drawable_impl_quartz_get_type (void)
 }
 
 CGContextRef 
-_gdk_quartz_drawable_get_context (GdkDrawable *drawable, gboolean antialias)
+gdk_quartz_drawable_get_context (GdkDrawable *drawable,
+                                gboolean     antialias)
 {
   if (GDK_IS_WINDOW_IMPL_QUARTZ (drawable))
     {
@@ -642,7 +675,8 @@ _gdk_quartz_drawable_get_context (GdkDrawable *drawable, gboolean antialias)
 }
 
 void
-_gdk_quartz_drawable_release_context (GdkDrawable *drawable, CGContextRef context)
+gdk_quartz_drawable_release_context (GdkDrawable  *drawable,
+                                    CGContextRef  context)
 {
   if (!context)
     return;