]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkgc.c
Merge from stable:
[~andy/gtk] / gdk / gdkgc.c
index 8a54612e28c2c17013e31604a0f54388a4d56126..e1757e4bd1be3fc6b68872187f32a1cd522b50ee 100644 (file)
@@ -2,23 +2,23 @@
  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
  *
  * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU Library General Public
+ * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */
 
 /*
- * Modified by the GTK+ Team and others 1997-1999.  See the AUTHORS
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
  * file for a list of people on the GTK+ Team.  See the ChangeLog
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
@@ -33,7 +33,7 @@
 static void gdk_gc_class_init (GObjectClass *class);
 static void gdk_gc_finalize   (GObject      *object);
 
-GObjectClass *parent_class;
+static GObjectClass *parent_class;
 
 GType
 gdk_gc_get_type (void)
@@ -57,7 +57,8 @@ gdk_gc_get_type (void)
       
       object_type = g_type_register_static (G_TYPE_OBJECT,
                                             "GdkGC",
-                                            &object_info);
+                                            &object_info, 
+                                           G_TYPE_FLAG_ABSTRACT);
     }
   
   return object_type;
@@ -104,9 +105,15 @@ gdk_gc_new_with_values (GdkDrawable        *drawable,
   if (values_mask & GDK_GC_TS_Y_ORIGIN)
     gc->ts_y_origin = values->ts_y_origin;
 
-  gc->colormap = gdk_drawable_get_colormap (drawable);
-  if (gc->colormap)
-    g_object_ref (G_OBJECT (gc->colormap));
+  /* gc->colormap will already be set if gdk_gc_new_with_values()
+   * recurses - as in GdkPixmap => impl object.
+   */
+  if (!gc->colormap)
+    {
+      gc->colormap = gdk_drawable_get_colormap (drawable);
+      if (gc->colormap)
+       g_object_ref (gc->colormap);
+    }
   
   return gc;
 }
@@ -117,21 +124,35 @@ gdk_gc_finalize (GObject *object)
   GdkGC *gc = GDK_GC (object);
   
   if (gc->colormap)
-    g_object_unref (G_OBJECT (gc->colormap));
+    g_object_unref (gc->colormap);
 
   parent_class->finalize (object);
 }
 
+/**
+ * gdk_gc_ref:
+ * @gc: a #GdkGC
+ *
+ * Deprecated function; use g_object_ref() instead.
+ *
+ * Return value: the gc.
+ **/
 GdkGC *
 gdk_gc_ref (GdkGC *gc)
 {
-  return (GdkGC *) g_object_ref (G_OBJECT (gc));
+  return (GdkGC *) g_object_ref (gc);
 }
 
+/**
+ * gdk_gc_unref:
+ * @gc: a #GdkGC
+ *
+ * Deprecated function; use g_object_unref() instead.
+ **/
 void
 gdk_gc_unref (GdkGC *gc)
 {
-  g_object_unref (G_OBJECT (gc));
+  g_object_unref (gc);
 }
 
 void
@@ -144,6 +165,19 @@ gdk_gc_get_values (GdkGC       *gc,
   GDK_GC_GET_CLASS (gc)->get_values (gc, values);
 }
 
+/**
+ * gdk_gc_set_values:
+ * @gc: a #GdkGC
+ * @values: struct containing the new values
+ * @values_mask: mask indicating which struct fields are to be used
+ *
+ * Sets attributes of a graphics context in bulk. For each flag set in
+ * @values_mask, the corresponding field will be read from @values and
+ * set as the new value for @gc. If you're only setting a few values
+ * on @gc, calling individual "setter" functions is likely more
+ * convenient.
+ * 
+ **/
 void
 gdk_gc_set_values (GdkGC           *gc,
                   GdkGCValues     *values,
@@ -353,6 +387,39 @@ gdk_gc_set_dashes (GdkGC *gc,
   GDK_GC_GET_CLASS (gc)->set_dashes (gc, dash_offset, dash_list, n);
 }
 
+/**
+ * gdk_gc_offset:
+ * @gc: a #GdkGC
+ * @x_offset: amount by which to offset the GC in the X direction
+ * @y_offset: amount by which to offset the GC in the Y direction
+ * 
+ * Offset attributes such as the clip and tile-stipple origins
+ * of the GC so that drawing at x - x_offset, y - y_offset with
+ * the offset GC  has the same effect as drawing at x, y with the original
+ * GC.
+ **/
+void
+gdk_gc_offset (GdkGC *gc,
+              gint   x_offset,
+              gint   y_offset)
+{
+  if (x_offset != 0 || y_offset != 0)
+    {
+      GdkGCValues values;
+
+      values.clip_x_origin = gc->clip_x_origin - x_offset;
+      values.clip_y_origin = gc->clip_y_origin - y_offset;
+      values.ts_x_origin = gc->ts_x_origin - x_offset;
+      values.ts_y_origin = gc->ts_y_origin - y_offset;
+      
+      gdk_gc_set_values (gc, &values,
+                        GDK_GC_CLIP_X_ORIGIN |
+                        GDK_GC_CLIP_Y_ORIGIN |
+                        GDK_GC_TS_X_ORIGIN |
+                        GDK_GC_TS_Y_ORIGIN);
+    }
+}
+
 /**
  * gdk_gc_set_colormap:
  * @gc: a #GdkGC
@@ -372,10 +439,10 @@ gdk_gc_set_colormap (GdkGC       *gc,
   if (gc->colormap != colormap)
     {
       if (gc->colormap)
-       g_object_unref (G_OBJECT (gc->colormap));
+       g_object_unref (gc->colormap);
 
       gc->colormap = colormap;
-      g_object_ref (G_OBJECT (gc->colormap));
+      g_object_ref (gc->colormap);
     }
     
 }
@@ -443,7 +510,7 @@ gdk_gc_set_rgb_fg_color (GdkGC *gc, GdkColor *color)
 
   tmp_color = *color;
   gdk_rgb_find_color (cmap, &tmp_color);
-  gdk_gc_set_foreground (cmap, &tmp_color);
+  gdk_gc_set_foreground (gc, &tmp_color);
 }
 
 /**
@@ -474,5 +541,5 @@ gdk_gc_set_rgb_bg_color (GdkGC *gc, GdkColor *color)
 
   tmp_color = *color;
   gdk_rgb_find_color (cmap, &tmp_color);
-  gdk_gc_set_foreground (cmap, &tmp_color);
+  gdk_gc_set_background (gc, &tmp_color);
 }