]> Pileus Git - ~andy/gtk/blobdiff - gdk/gdkgc.c
Ignore calls with <= width or height.
[~andy/gtk] / gdk / gdkgc.c
index 3dc11ce6cca8e1eb97b04c60d69fcdcb4fa4ede0..07f80e94ab49d46f3af40d8c3013037a6ef7ac11 100644 (file)
  *
  * 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
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.         See the GNU
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * 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
+ * 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/. 
+ */
+
 #include <string.h>
-#include <X11/Xlib.h>
-#include "gdk.h"
+
+#include "gdkgc.h"
+#include "gdkrgb.h"
 #include "gdkprivate.h"
 
+static void gdk_gc_class_init (GObjectClass *class);
+static void gdk_gc_finalize   (GObject      *object);
+
+GObjectClass *parent_class;
+
+GType
+gdk_gc_get_type (void)
+{
+  static GType object_type = 0;
+
+  if (!object_type)
+    {
+      static const GTypeInfo object_info =
+      {
+        sizeof (GdkGCClass),
+        (GBaseInitFunc) NULL,
+        (GBaseFinalizeFunc) NULL,
+        (GClassInitFunc) gdk_gc_class_init,
+        NULL,           /* class_finalize */
+        NULL,           /* class_data */
+        sizeof (GdkGC),
+        0,              /* n_preallocs */
+        (GInstanceInitFunc) NULL,
+      };
+      
+      object_type = g_type_register_static (G_TYPE_OBJECT,
+                                            "GdkGC",
+                                            &object_info);
+    }
+  
+  return object_type;
+}
+
+static void
+gdk_gc_class_init (GObjectClass *class)
+{
+  parent_class = g_type_class_peek_parent (class);
+  
+  class->finalize = gdk_gc_finalize;
+}
 
 GdkGC*
-gdk_gc_new (GdkWindow *window)
+gdk_gc_new (GdkDrawable *drawable)
 {
-  return gdk_gc_new_with_values (window, NULL, 0);
+  g_return_val_if_fail (drawable != NULL, NULL);
+
+  return gdk_gc_new_with_values (drawable, NULL, 0);
 }
 
 GdkGC*
-gdk_gc_new_with_values (GdkWindow       *window,
-                       GdkGCValues     *values,
-                       GdkGCValuesMask  values_mask)
+gdk_gc_new_with_values (GdkDrawable    *drawable,
+                       GdkGCValues     *values,
+                       GdkGCValuesMask  values_mask)
 {
   GdkGC *gc;
-  GdkGCPrivate *private;
-  Window xwindow;
-  XGCValues xvalues;
-  unsigned long xvalues_mask;
 
-  private = g_new (GdkGCPrivate, 1);
-  gc = (GdkGC*) private;
+  g_return_val_if_fail (drawable != NULL, NULL);
 
-  xwindow = ((GdkWindowPrivate*) window)->xwindow;
-  private->xdisplay = ((GdkWindowPrivate*) window)->xdisplay;
+  gc = GDK_DRAWABLE_GET_CLASS (drawable)->create_gc (drawable,
+                                                     values,
+                                                     values_mask);
 
-  xvalues.function = GXcopy;
-  xvalues.fill_style = FillSolid;
-  xvalues.arc_mode = ArcPieSlice;
-  xvalues.subwindow_mode = ClipByChildren;
-  xvalues.graphics_exposures = True;
-  xvalues_mask = GCFunction | GCFillStyle | GCArcMode | GCSubwindowMode | GCGraphicsExposures;
-
-  if (values_mask & GDK_GC_FOREGROUND)
-    {
-      xvalues.foreground = values->foreground.pixel;
-      xvalues_mask |= GCForeground;
-    }
-  if (values_mask & GDK_GC_BACKGROUND)
-    {
-      xvalues.background = values->background.pixel;
-      xvalues_mask |= GCBackground;
-    }
-  if ((values_mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT))
-    {
-      xvalues.font = ((XFontStruct *) ((GdkFontPrivate*) values->font)->xfont)->fid;
-      xvalues_mask |= GCFont;
-    }
-  if (values_mask & GDK_GC_FUNCTION)
-    {
-      switch (values->function)
-       {
-       case GDK_COPY:
-         xvalues.function = GXcopy;
-         break;
-       case GDK_INVERT:
-         xvalues.function = GXinvert;
-         break;
-       case GDK_XOR:
-         xvalues.function = GXxor;
-         break;
-       }
-      xvalues_mask |= GCFunction;
-    }
-  if (values_mask & GDK_GC_FILL)
-    {
-      switch (values->fill)
-       {
-       case GDK_SOLID:
-         xvalues.fill_style = FillSolid;
-         break;
-       case GDK_TILED:
-         xvalues.fill_style = FillTiled;
-         break;
-       case GDK_STIPPLED:
-         xvalues.fill_style = FillStippled;
-         break;
-       case GDK_OPAQUE_STIPPLED:
-         xvalues.fill_style = FillOpaqueStippled;
-         break;
-       }
-      xvalues_mask |= GCFillStyle;
-    }
-  if (values_mask & GDK_GC_TILE)
-    {
-      xvalues.tile = ((GdkPixmapPrivate*) values->tile)->xwindow;
-      xvalues_mask |= GCTile;
-    }
-  if (values_mask & GDK_GC_STIPPLE)
-    {
-      xvalues.stipple = ((GdkPixmapPrivate*) values->stipple)->xwindow;
-      xvalues_mask |= GCStipple;
-    }
-  if (values_mask & GDK_GC_CLIP_MASK)
-    {
-      xvalues.clip_mask = ((GdkPixmapPrivate*) values->clip_mask)->xwindow;
-      xvalues_mask |= GCClipMask;
-    }
-  if (values_mask & GDK_GC_SUBWINDOW)
-    {
-      xvalues.subwindow_mode = values->subwindow_mode;
-      xvalues_mask |= GCSubwindowMode;
-    }
-  if (values_mask & GDK_GC_TS_X_ORIGIN)
-    {
-      xvalues.ts_x_origin = values->ts_x_origin;
-      xvalues_mask |= GCTileStipXOrigin;
-    }
-  if (values_mask & GDK_GC_TS_Y_ORIGIN)
-    {
-      xvalues.ts_y_origin = values->ts_y_origin;
-      xvalues_mask |= GCTileStipYOrigin;
-    }
+  if (gc == NULL) /* This would mean the drawable was destroyed. */
+    return NULL;
+  
   if (values_mask & GDK_GC_CLIP_X_ORIGIN)
-    {
-      xvalues.clip_x_origin = values->clip_x_origin;
-      xvalues_mask |= GCClipXOrigin;
-    }
+    gc->clip_x_origin = values->clip_x_origin;
   if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
-    {
-      xvalues.clip_y_origin = values->clip_y_origin;
-      xvalues_mask |= GCClipYOrigin;
-    }
-  if (values_mask & GDK_GC_EXPOSURES)
-    {
-      xvalues.graphics_exposures = values->graphics_exposures;
-      xvalues_mask |= GCGraphicsExposures;
-    }
-  if (values_mask & GDK_GC_LINE_WIDTH)
-    {
-      xvalues.line_width = values->line_width;
-      xvalues_mask |= GCLineWidth;
-    }
-  if (values_mask & GDK_GC_LINE_STYLE)
-    {
-      switch (values->line_style)
-       {
-       case GDK_LINE_SOLID:
-         xvalues.line_style = LineSolid;
-         break;
-       case GDK_LINE_ON_OFF_DASH:
-         xvalues.line_style = LineOnOffDash;
-         break;
-       case GDK_LINE_DOUBLE_DASH:
-         xvalues.line_style = LineDoubleDash;
-         break;
-       }
-      xvalues_mask |= GCLineStyle;
-    }
-  if (values_mask & GDK_GC_CAP_STYLE)
-    {
-      switch (values->cap_style)
-       {
-       case GDK_CAP_NOT_LAST:
-         xvalues.cap_style = CapNotLast;
-         break;
-       case GDK_CAP_BUTT:
-         xvalues.cap_style = CapButt;
-         break;
-       case GDK_CAP_ROUND:
-         xvalues.cap_style = CapRound;
-         break;
-       case GDK_CAP_PROJECTING:
-         xvalues.cap_style = CapProjecting;
-         break;
-       }
-      xvalues_mask |= GCCapStyle;
-    }
-  if (values_mask & GDK_GC_JOIN_STYLE)
-    {
-      switch (values->join_style)
-       {
-       case GDK_JOIN_MITER:
-         xvalues.join_style = JoinMiter;
-         break;
-       case GDK_JOIN_ROUND:
-         xvalues.join_style = JoinRound;
-         break;
-       case GDK_JOIN_BEVEL:
-         xvalues.join_style = JoinBevel;
-         break;
-       }
-      xvalues_mask |= GCJoinStyle;
-    }
-
-  private->xgc = XCreateGC (private->xdisplay, xwindow, xvalues_mask, &xvalues);
+    gc->clip_y_origin = values->clip_y_origin;
+  if (values_mask & GDK_GC_TS_X_ORIGIN)
+    gc->ts_x_origin = values->ts_x_origin;
+  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));
+  
   return gc;
 }
 
-void
-gdk_gc_destroy (GdkGC *gc)
+static void
+gdk_gc_finalize (GObject *object)
 {
-  GdkGCPrivate *private;
+  GdkGC *gc = GDK_GC (object);
+  
+  if (gc->colormap)
+    g_object_unref (G_OBJECT (gc->colormap));
 
-  g_return_if_fail (gc != NULL);
+  parent_class->finalize (object);
+}
 
-  private = (GdkGCPrivate*) gc;
-  XFreeGC (private->xdisplay, private->xgc);
+GdkGC *
+gdk_gc_ref (GdkGC *gc)
+{
+  return (GdkGC *) g_object_ref (G_OBJECT (gc));
+}
 
-  memset (gc, 0, sizeof (GdkGCPrivate));
-  g_free (gc);
+void
+gdk_gc_unref (GdkGC *gc)
+{
+  g_object_unref (G_OBJECT (gc));
 }
 
 void
 gdk_gc_get_values (GdkGC       *gc,
                   GdkGCValues *values)
 {
-  GdkGCPrivate *private;
-  XGCValues xvalues;
-
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
   g_return_if_fail (values != NULL);
 
-  private = (GdkGCPrivate*) gc;
+  GDK_GC_GET_CLASS (gc)->get_values (gc, values);
+}
+
+void
+gdk_gc_set_values (GdkGC           *gc,
+                  GdkGCValues     *values,
+                  GdkGCValuesMask  values_mask)
+{
+  g_return_if_fail (GDK_IS_GC (gc));
+  g_return_if_fail (values != NULL);
 
-  if (XGetGCValues (private->xdisplay, private->xgc,
-                   GCForeground | GCBackground | GCFont |
-                   GCFunction | GCTile | GCStipple | /* GCClipMask | */
-                   GCSubwindowMode | GCGraphicsExposures |
-                   GCTileStipXOrigin | GCTileStipYOrigin |
-                   GCClipXOrigin | GCClipYOrigin |
-                   GCLineWidth | GCLineStyle | GCCapStyle |
-                   GCFillStyle | GCJoinStyle, &xvalues))
-    {
-      values->foreground.pixel = xvalues.foreground;
-      values->background.pixel = xvalues.background;
-      values->font = gdk_font_lookup (xvalues.font);
-
-      switch (xvalues.function)
-       {
-       case GXcopy:
-         values->function = GDK_COPY;
-         break;
-       case GXinvert:
-         values->function = GDK_INVERT;
-         break;
-       case GXxor:
-         values->function = GDK_XOR;
-         break;
-       }
-
-      switch (xvalues.fill_style)
-       {
-       case FillSolid:
-         values->fill = GDK_SOLID;
-         break;
-       case FillTiled:
-         values->fill = GDK_TILED;
-         break;
-       case FillStippled:
-         values->fill = GDK_STIPPLED;
-         break;
-       case FillOpaqueStippled:
-         values->fill = GDK_OPAQUE_STIPPLED;
-         break;
-       }
-
-      values->tile = gdk_pixmap_lookup (xvalues.tile);
-      values->stipple = gdk_pixmap_lookup (xvalues.stipple);
-      values->clip_mask = NULL;
-      values->subwindow_mode = xvalues.subwindow_mode;
-      values->ts_x_origin = xvalues.ts_x_origin;
-      values->ts_y_origin = xvalues.ts_y_origin;
-      values->clip_x_origin = xvalues.clip_x_origin;
-      values->clip_y_origin = xvalues.clip_y_origin;
-      values->graphics_exposures = xvalues.graphics_exposures;
-      values->line_width = xvalues.line_width;
-
-      switch (xvalues.line_style)
-       {
-       case LineSolid:
-         values->line_style = GDK_LINE_SOLID;
-         break;
-       case LineOnOffDash:
-         values->line_style = GDK_LINE_ON_OFF_DASH;
-         break;
-       case LineDoubleDash:
-         values->line_style = GDK_LINE_DOUBLE_DASH;
-         break;
-       }
-
-      switch (xvalues.cap_style)
-       {
-       case CapNotLast:
-         values->cap_style = GDK_CAP_NOT_LAST;
-         break;
-       case CapButt:
-         values->cap_style = GDK_CAP_BUTT;
-         break;
-       case CapRound:
-         values->cap_style = GDK_CAP_ROUND;
-         break;
-       case CapProjecting:
-         values->cap_style = GDK_CAP_PROJECTING;
-         break;
-       }
-
-      switch (xvalues.join_style)
-       {
-       case JoinMiter:
-         values->join_style = GDK_JOIN_MITER;
-         break;
-       case JoinRound:
-         values->join_style = GDK_JOIN_ROUND;
-         break;
-       case JoinBevel:
-         values->join_style = GDK_JOIN_BEVEL;
-         break;
-       }
-    }
-  else
-    {
-      memset (values, 0, sizeof (GdkGCValues));
-    }
+  if (values_mask & GDK_GC_CLIP_X_ORIGIN)
+    gc->clip_x_origin = values->clip_x_origin;
+  if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
+    gc->clip_y_origin = values->clip_y_origin;
+  if (values_mask & GDK_GC_TS_X_ORIGIN)
+    gc->ts_x_origin = values->ts_x_origin;
+  if (values_mask & GDK_GC_TS_Y_ORIGIN)
+    gc->ts_y_origin = values->ts_y_origin;
+  
+  GDK_GC_GET_CLASS (gc)->set_values (gc, values, values_mask);
 }
 
 void
-gdk_gc_set_foreground (GdkGC    *gc,
+gdk_gc_set_foreground (GdkGC   *gc,
                       GdkColor *color)
 {
-  GdkGCPrivate *private;
+  GdkGCValues values;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
   g_return_if_fail (color != NULL);
 
-  private = (GdkGCPrivate*) gc;
-  XSetForeground (private->xdisplay, private->xgc, color->pixel);
+  values.foreground = *color;
+  gdk_gc_set_values (gc, &values, GDK_GC_FOREGROUND);
 }
 
 void
-gdk_gc_set_background (GdkGC    *gc,
+gdk_gc_set_background (GdkGC   *gc,
                       GdkColor *color)
 {
-  GdkGCPrivate *private;
+  GdkGCValues values;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
   g_return_if_fail (color != NULL);
 
-  private = (GdkGCPrivate*) gc;
-  XSetBackground (private->xdisplay, private->xgc, color->pixel);
+  values.background = *color;
+  gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
 }
 
 void
-gdk_gc_set_font (GdkGC   *gc,
+gdk_gc_set_font (GdkGC  *gc,
                 GdkFont *font)
 {
-  GdkGCPrivate *gc_private;
-  GdkFontPrivate *font_private;
+  GdkGCValues values;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
   g_return_if_fail (font != NULL);
 
-  gc_private = (GdkGCPrivate*) gc;
-  font_private = (GdkFontPrivate*) font;
-
-  XSetFont (gc_private->xdisplay, gc_private->xgc,
-           ((XFontStruct *) font_private->xfont)->fid);
+  values.font = font;
+  gdk_gc_set_values (gc, &values, GDK_GC_FONT);
 }
 
 void
-gdk_gc_set_function (GdkGC       *gc,
+gdk_gc_set_function (GdkGC      *gc,
                     GdkFunction  function)
 {
-  GdkGCPrivate *private;
+  GdkGCValues values;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  private = (GdkGCPrivate*) gc;
-
-  switch (function)
-    {
-    case GDK_COPY:
-      XSetFunction (private->xdisplay, private->xgc, GXcopy);
-      break;
-    case GDK_INVERT:
-      XSetFunction (private->xdisplay, private->xgc, GXinvert);
-      break;
-    case GDK_XOR:
-      XSetFunction (private->xdisplay, private->xgc, GXor);
-      break;
-    }
+  values.function = function;
+  gdk_gc_set_values (gc, &values, GDK_GC_FUNCTION);
 }
 
 void
-gdk_gc_set_fill (GdkGC   *gc,
+gdk_gc_set_fill (GdkGC  *gc,
                 GdkFill  fill)
 {
-  GdkGCPrivate *private;
-
-  g_return_if_fail (gc != NULL);
+  GdkGCValues values;
 
-  private = (GdkGCPrivate*) gc;
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  switch (fill)
-    {
-    case GDK_SOLID:
-      XSetFillStyle (private->xdisplay, private->xgc, FillSolid);
-      break;
-    case GDK_TILED:
-      XSetFillStyle (private->xdisplay, private->xgc, FillTiled);
-      break;
-    case GDK_STIPPLED:
-      XSetFillStyle (private->xdisplay, private->xgc, FillStippled);
-      break;
-    case GDK_OPAQUE_STIPPLED:
-      XSetFillStyle (private->xdisplay, private->xgc, FillOpaqueStippled);
-      break;
-    }
+  values.fill = fill;
+  gdk_gc_set_values (gc, &values, GDK_GC_FILL);
 }
 
 void
-gdk_gc_set_tile (GdkGC     *gc,
+gdk_gc_set_tile (GdkGC    *gc,
                 GdkPixmap *tile)
 {
-  GdkGCPrivate *private;
-  GdkPixmapPrivate *pixmap_private;
-  Pixmap pixmap;
-
-  g_return_if_fail (gc != NULL);
-
-  private = (GdkGCPrivate*) gc;
+  GdkGCValues values;
 
-  pixmap = None;
-  if (tile)
-    {
-      pixmap_private = (GdkPixmapPrivate*) tile;
-      pixmap = pixmap_private->xwindow;
-    }
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  XSetTile (private->xdisplay, private->xgc, pixmap);
+  values.tile = tile;
+  gdk_gc_set_values (gc, &values, GDK_GC_TILE);
 }
 
 void
 gdk_gc_set_stipple (GdkGC     *gc,
                    GdkPixmap *stipple)
 {
-  GdkGCPrivate *private;
-  GdkPixmapPrivate *pixmap_private;
-  Pixmap pixmap;
-
-  g_return_if_fail (gc != NULL);
-
-  private = (GdkGCPrivate*) gc;
+  GdkGCValues values;
 
-  pixmap = None;
-  if (stipple)
-    {
-      pixmap_private = (GdkPixmapPrivate*) stipple;
-      pixmap = pixmap_private->xwindow;
-    }
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  XSetStipple (private->xdisplay, private->xgc, pixmap);
+  values.stipple = stipple;
+  gdk_gc_set_values (gc, &values, GDK_GC_STIPPLE);
 }
 
 void
@@ -478,13 +256,15 @@ gdk_gc_set_ts_origin (GdkGC *gc,
                      gint   x,
                      gint   y)
 {
-  GdkGCPrivate *private;
+  GdkGCValues values;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  private = (GdkGCPrivate*) gc;
-
-  XSetTSOrigin (private->xdisplay, private->xgc, x, y);
+  values.ts_x_origin = x;
+  values.ts_y_origin = y;
+  
+  gdk_gc_set_values (gc, &values,
+                    GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
 }
 
 void
@@ -492,145 +272,207 @@ gdk_gc_set_clip_origin (GdkGC *gc,
                        gint   x,
                        gint   y)
 {
-  GdkGCPrivate *private;
-
-  g_return_if_fail (gc != NULL);
+  GdkGCValues values;
 
-  private = (GdkGCPrivate*) gc;
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  XSetClipOrigin (private->xdisplay, private->xgc, x, y);
+  values.clip_x_origin = x;
+  values.clip_y_origin = y;
+  
+  gdk_gc_set_values (gc, &values,
+                    GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
 }
 
 void
-gdk_gc_set_clip_mask (GdkGC     *gc,
+gdk_gc_set_clip_mask (GdkGC    *gc,
                      GdkBitmap *mask)
 {
-  GdkGCPrivate *private;
-  Pixmap xmask;
+  GdkGCValues values;
+  
+  g_return_if_fail (GDK_IS_GC (gc));
+  
+  values.clip_mask = mask;
+  gdk_gc_set_values (gc, &values, GDK_GC_CLIP_MASK);
+}
 
-  g_return_if_fail (gc != NULL);
 
-  private = (GdkGCPrivate*) gc;
+void
+gdk_gc_set_subwindow (GdkGC           *gc,
+                     GdkSubwindowMode  mode)
+{
+  GdkGCValues values;
 
-  if (mask)
-    xmask = ((GdkWindowPrivate*) mask)->xwindow;
-  else
-    xmask = None;
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  XSetClipMask (private->xdisplay, private->xgc, xmask);
+  values.subwindow_mode = mode;
+  gdk_gc_set_values (gc, &values, GDK_GC_SUBWINDOW);
 }
 
-
 void
-gdk_gc_set_clip_rectangle (GdkGC        *gc,
-                           GdkRectangle *rectangle)
+gdk_gc_set_exposures (GdkGC     *gc,
+                     gboolean   exposures)
 {
-  GdkGCPrivate *private;
-  XRectangle xrectangle;
+  GdkGCValues values;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
 
-  private = (GdkGCPrivate*) gc;
-
-  xrectangle.x = rectangle->x; 
-  xrectangle.y = rectangle->y;
-  xrectangle.width = rectangle->width;
-  xrectangle.height = rectangle->height;
+  values.graphics_exposures = exposures;
+  gdk_gc_set_values (gc, &values, GDK_GC_EXPOSURES);
+}
 
-  XSetClipRectangles (private->xdisplay, private->xgc, 0, 0,
-                      &xrectangle, 1, Unsorted);
-} 
+void
+gdk_gc_set_line_attributes (GdkGC      *gc,
+                           gint         line_width,
+                           GdkLineStyle line_style,
+                           GdkCapStyle  cap_style,
+                           GdkJoinStyle join_style)
+{
+  GdkGCValues values;
+
+  values.line_width = line_width;
+  values.line_style = line_style;
+  values.cap_style = cap_style;
+  values.join_style = join_style;
+
+  gdk_gc_set_values (gc, &values,
+                    GDK_GC_LINE_WIDTH |
+                    GDK_GC_LINE_STYLE |
+                    GDK_GC_CAP_STYLE |
+                    GDK_GC_JOIN_STYLE);
+}
 
 void
-gdk_gc_set_subwindow (GdkGC            *gc,
-                     GdkSubwindowMode  mode)
+gdk_gc_set_dashes (GdkGC *gc,
+                  gint   dash_offset,
+                  gint8  dash_list[],
+                  gint   n)
 {
-  GdkGCPrivate *private;
+  g_return_if_fail (GDK_IS_GC (gc));
+  g_return_if_fail (dash_list != NULL);
+
+  GDK_GC_GET_CLASS (gc)->set_dashes (gc, dash_offset, dash_list, n);
+}
 
-  g_return_if_fail (gc != NULL);
+/**
+ * gdk_gc_set_colormap:
+ * @gc: a #GdkGC
+ * @colormap: a #GdkColormap
+ * 
+ * Sets the colormap for the GC to the given colormap. The depth
+ * of the colormap's visual must match the depth of the drawable
+ * for which the GC was created.
+ **/
+void
+gdk_gc_set_colormap (GdkGC       *gc,
+                    GdkColormap *colormap)
+{
+  g_return_if_fail (GDK_IS_GC (gc));
+  g_return_if_fail (GDK_IS_COLORMAP (colormap));
 
-  private = (GdkGCPrivate*) gc;
+  if (gc->colormap != colormap)
+    {
+      if (gc->colormap)
+       g_object_unref (G_OBJECT (gc->colormap));
 
-  XSetSubwindowMode (private->xdisplay, private->xgc, mode);
+      gc->colormap = colormap;
+      g_object_ref (G_OBJECT (gc->colormap));
+    }
+    
 }
 
-void
-gdk_gc_set_exposures (GdkGC *gc,
-                     gint   exposures)
+/**
+ * gdk_gc_get_colormap:
+ * @gc: a #GdkGC
+ * 
+ * Retrieves the colormap for a given GC, if it exists.
+ * A GC will have a colormap if the drawable for which it was created
+ * has a colormap, or if a colormap was set explicitely with
+ * gdk_gc_set_colormap.
+ * 
+ * Return value: 
+ **/
+GdkColormap *
+gdk_gc_get_colormap (GdkGC *gc)
 {
-  GdkGCPrivate *private;
+  g_return_val_if_fail (GDK_IS_GC (gc), NULL);
 
-  g_return_if_fail (gc != NULL);
+  return gc->colormap;
+}
 
-  private = (GdkGCPrivate*) gc;
+static GdkColormap *
+gdk_gc_get_colormap_warn (GdkGC *gc)
+{
+  GdkColormap *colormap = gdk_gc_get_colormap (gc);
+  if (!colormap)
+    {
+      g_warning ("gdk_gc_set_rgb_fg_color() and gdk_gc_set_rgb_bg_color() can\n"
+                "only be used on GC's with a colormap. A GC will have a colormap\n"
+                "if it is created for a drawable with a colormap, or if a\n"
+                "colormap has been set explicitly with gdk_gc_set_colormap.\n");
+      return NULL;
+    }
 
-  XSetGraphicsExposures (private->xdisplay, private->xgc, exposures);
+  return colormap;
 }
 
+/**
+ * gdk_gc_set_rgb_fg_color:
+ * @gc: a #GdkGC
+ * @color: an unallocated #GdkColor.
+ * 
+ * Set the foreground color of a GC using an unallocated color. The
+ * pixel value for the color will be determined using GdkRGB. If the
+ * colormap for the GC has not previously been initialized for GdkRGB,
+ * then for pseudo-color colormaps (colormaps with a small modifiable
+ * number of colors), a colorcube will be allocated in the colormap.
+ * 
+ * Calling this function for a GC without a colormap is an error.
+ **/
 void
-gdk_gc_set_line_attributes (GdkGC       *gc,
-                           gint         line_width,
-                           GdkLineStyle line_style,
-                           GdkCapStyle  cap_style,
-                           GdkJoinStyle join_style)
+gdk_gc_set_rgb_fg_color (GdkGC *gc, GdkColor *color)
 {
-  GdkGCPrivate *private;
-  int xline_style;
-  int xcap_style;
-  int xjoin_style;
+  GdkColormap *cmap;
+  GdkColor tmp_color;
 
-  g_return_if_fail (gc != NULL);
+  g_return_if_fail (GDK_IS_GC (gc));
+  g_return_if_fail (color != NULL);
 
-  private = (GdkGCPrivate*) gc;
+  cmap = gdk_gc_get_colormap_warn (gc);
+  if (!cmap)
+    return;
 
-  switch (line_style)
-    {
-    case GDK_LINE_SOLID:
-      xline_style = LineSolid;
-      break;
-    case GDK_LINE_ON_OFF_DASH:
-      xline_style = LineOnOffDash;
-      break;
-    case GDK_LINE_DOUBLE_DASH:
-      xline_style = LineDoubleDash;
-      break;
-    default:
-      xline_style = None;
-    }
+  tmp_color = *color;
+  gdk_rgb_find_color (cmap, &tmp_color);
+  gdk_gc_set_foreground (gc, &tmp_color);
+}
 
-  switch (cap_style)
-    {
-    case GDK_CAP_NOT_LAST:
-      xcap_style = CapNotLast;
-      break;
-    case GDK_CAP_BUTT:
-      xcap_style = CapButt;
-      break;
-    case GDK_CAP_ROUND:
-      xcap_style = CapRound;
-      break;
-    case GDK_CAP_PROJECTING:
-      xcap_style = CapProjecting;
-      break;
-    default:
-      xcap_style = None;
-    }
+/**
+ * gdk_gc_set_rgb_bg_color:
+ * @gc: a #GdkGC
+ * @color: an unallocated #GdkColor.
+ * 
+ * Set the background color of a GC using an unallocated color. The
+ * pixel value for the color will be determined using GdkRGB. If the
+ * colormap for the GC has not previously been initialized for GdkRGB,
+ * then for pseudo-color colormaps (colormaps with a small modifiable
+ * number of colors), a colorcube will be allocated in the colormap.
+ * 
+ * Calling this function for a GC without a colormap is an error.
+ **/
+void
+gdk_gc_set_rgb_bg_color (GdkGC *gc, GdkColor *color)
+{
+  GdkColormap *cmap;
+  GdkColor tmp_color;
 
-  switch (join_style)
-    {
-    case GDK_JOIN_MITER:
-      xjoin_style = JoinMiter;
-      break;
-    case GDK_JOIN_ROUND:
-      xjoin_style = JoinRound;
-      break;
-    case GDK_JOIN_BEVEL:
-      xjoin_style = JoinBevel;
-      break;
-    default:
-      xjoin_style = None;
-    }
+  g_return_if_fail (GDK_IS_GC (gc));
+  g_return_if_fail (color != NULL);
+
+  cmap = gdk_gc_get_colormap_warn (gc);
+  if (!cmap)
+    return;
 
-  XSetLineAttributes (private->xdisplay, private->xgc, line_width,
-                     xline_style, xcap_style, xjoin_style);
+  tmp_color = *color;
+  gdk_rgb_find_color (cmap, &tmp_color);
+  gdk_gc_set_foreground (gc, &tmp_color);
 }