1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdkprivate.h"
33 static void gdk_gc_class_init (GObjectClass *class);
34 static void gdk_gc_finalize (GObject *object);
36 static GObjectClass *parent_class;
39 gdk_gc_get_type (void)
41 static GType object_type = 0;
45 static const GTypeInfo object_info =
49 (GBaseFinalizeFunc) NULL,
50 (GClassInitFunc) gdk_gc_class_init,
51 NULL, /* class_finalize */
52 NULL, /* class_data */
55 (GInstanceInitFunc) NULL,
58 object_type = g_type_register_static (G_TYPE_OBJECT,
67 gdk_gc_class_init (GObjectClass *class)
69 parent_class = g_type_class_peek_parent (class);
71 class->finalize = gdk_gc_finalize;
75 gdk_gc_new (GdkDrawable *drawable)
77 g_return_val_if_fail (drawable != NULL, NULL);
79 return gdk_gc_new_with_values (drawable, NULL, 0);
83 gdk_gc_new_with_values (GdkDrawable *drawable,
85 GdkGCValuesMask values_mask)
89 g_return_val_if_fail (drawable != NULL, NULL);
91 gc = GDK_DRAWABLE_GET_CLASS (drawable)->create_gc (drawable,
95 if (gc == NULL) /* This would mean the drawable was destroyed. */
98 if (values_mask & GDK_GC_CLIP_X_ORIGIN)
99 gc->clip_x_origin = values->clip_x_origin;
100 if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
101 gc->clip_y_origin = values->clip_y_origin;
102 if (values_mask & GDK_GC_TS_X_ORIGIN)
103 gc->ts_x_origin = values->ts_x_origin;
104 if (values_mask & GDK_GC_TS_Y_ORIGIN)
105 gc->ts_y_origin = values->ts_y_origin;
107 gc->colormap = gdk_drawable_get_colormap (drawable);
109 g_object_ref (G_OBJECT (gc->colormap));
115 gdk_gc_finalize (GObject *object)
117 GdkGC *gc = GDK_GC (object);
120 g_object_unref (G_OBJECT (gc->colormap));
122 parent_class->finalize (object);
126 gdk_gc_ref (GdkGC *gc)
128 return (GdkGC *) g_object_ref (G_OBJECT (gc));
132 gdk_gc_unref (GdkGC *gc)
134 g_object_unref (G_OBJECT (gc));
138 gdk_gc_get_values (GdkGC *gc,
141 g_return_if_fail (GDK_IS_GC (gc));
142 g_return_if_fail (values != NULL);
144 GDK_GC_GET_CLASS (gc)->get_values (gc, values);
148 gdk_gc_set_values (GdkGC *gc,
150 GdkGCValuesMask values_mask)
152 g_return_if_fail (GDK_IS_GC (gc));
153 g_return_if_fail (values != NULL);
155 if (values_mask & GDK_GC_CLIP_X_ORIGIN)
156 gc->clip_x_origin = values->clip_x_origin;
157 if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
158 gc->clip_y_origin = values->clip_y_origin;
159 if (values_mask & GDK_GC_TS_X_ORIGIN)
160 gc->ts_x_origin = values->ts_x_origin;
161 if (values_mask & GDK_GC_TS_Y_ORIGIN)
162 gc->ts_y_origin = values->ts_y_origin;
164 GDK_GC_GET_CLASS (gc)->set_values (gc, values, values_mask);
168 gdk_gc_set_foreground (GdkGC *gc,
173 g_return_if_fail (GDK_IS_GC (gc));
174 g_return_if_fail (color != NULL);
176 values.foreground = *color;
177 gdk_gc_set_values (gc, &values, GDK_GC_FOREGROUND);
181 gdk_gc_set_background (GdkGC *gc,
186 g_return_if_fail (GDK_IS_GC (gc));
187 g_return_if_fail (color != NULL);
189 values.background = *color;
190 gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
194 gdk_gc_set_font (GdkGC *gc,
199 g_return_if_fail (GDK_IS_GC (gc));
200 g_return_if_fail (font != NULL);
203 gdk_gc_set_values (gc, &values, GDK_GC_FONT);
207 gdk_gc_set_function (GdkGC *gc,
208 GdkFunction function)
212 g_return_if_fail (GDK_IS_GC (gc));
214 values.function = function;
215 gdk_gc_set_values (gc, &values, GDK_GC_FUNCTION);
219 gdk_gc_set_fill (GdkGC *gc,
224 g_return_if_fail (GDK_IS_GC (gc));
227 gdk_gc_set_values (gc, &values, GDK_GC_FILL);
231 gdk_gc_set_tile (GdkGC *gc,
236 g_return_if_fail (GDK_IS_GC (gc));
239 gdk_gc_set_values (gc, &values, GDK_GC_TILE);
243 gdk_gc_set_stipple (GdkGC *gc,
248 g_return_if_fail (GDK_IS_GC (gc));
250 values.stipple = stipple;
251 gdk_gc_set_values (gc, &values, GDK_GC_STIPPLE);
255 gdk_gc_set_ts_origin (GdkGC *gc,
261 g_return_if_fail (GDK_IS_GC (gc));
263 values.ts_x_origin = x;
264 values.ts_y_origin = y;
266 gdk_gc_set_values (gc, &values,
267 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
271 gdk_gc_set_clip_origin (GdkGC *gc,
277 g_return_if_fail (GDK_IS_GC (gc));
279 values.clip_x_origin = x;
280 values.clip_y_origin = y;
282 gdk_gc_set_values (gc, &values,
283 GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
287 gdk_gc_set_clip_mask (GdkGC *gc,
292 g_return_if_fail (GDK_IS_GC (gc));
294 values.clip_mask = mask;
295 gdk_gc_set_values (gc, &values, GDK_GC_CLIP_MASK);
300 gdk_gc_set_subwindow (GdkGC *gc,
301 GdkSubwindowMode mode)
305 g_return_if_fail (GDK_IS_GC (gc));
307 values.subwindow_mode = mode;
308 gdk_gc_set_values (gc, &values, GDK_GC_SUBWINDOW);
312 gdk_gc_set_exposures (GdkGC *gc,
317 g_return_if_fail (GDK_IS_GC (gc));
319 values.graphics_exposures = exposures;
320 gdk_gc_set_values (gc, &values, GDK_GC_EXPOSURES);
324 gdk_gc_set_line_attributes (GdkGC *gc,
326 GdkLineStyle line_style,
327 GdkCapStyle cap_style,
328 GdkJoinStyle join_style)
332 values.line_width = line_width;
333 values.line_style = line_style;
334 values.cap_style = cap_style;
335 values.join_style = join_style;
337 gdk_gc_set_values (gc, &values,
345 gdk_gc_set_dashes (GdkGC *gc,
350 g_return_if_fail (GDK_IS_GC (gc));
351 g_return_if_fail (dash_list != NULL);
353 GDK_GC_GET_CLASS (gc)->set_dashes (gc, dash_offset, dash_list, n);
357 * gdk_gc_set_colormap:
359 * @colormap: a #GdkColormap
361 * Sets the colormap for the GC to the given colormap. The depth
362 * of the colormap's visual must match the depth of the drawable
363 * for which the GC was created.
366 gdk_gc_set_colormap (GdkGC *gc,
367 GdkColormap *colormap)
369 g_return_if_fail (GDK_IS_GC (gc));
370 g_return_if_fail (GDK_IS_COLORMAP (colormap));
372 if (gc->colormap != colormap)
375 g_object_unref (G_OBJECT (gc->colormap));
377 gc->colormap = colormap;
378 g_object_ref (G_OBJECT (gc->colormap));
384 * gdk_gc_get_colormap:
387 * Retrieves the colormap for a given GC, if it exists.
388 * A GC will have a colormap if the drawable for which it was created
389 * has a colormap, or if a colormap was set explicitely with
390 * gdk_gc_set_colormap.
395 gdk_gc_get_colormap (GdkGC *gc)
397 g_return_val_if_fail (GDK_IS_GC (gc), NULL);
403 gdk_gc_get_colormap_warn (GdkGC *gc)
405 GdkColormap *colormap = gdk_gc_get_colormap (gc);
408 g_warning ("gdk_gc_set_rgb_fg_color() and gdk_gc_set_rgb_bg_color() can\n"
409 "only be used on GC's with a colormap. A GC will have a colormap\n"
410 "if it is created for a drawable with a colormap, or if a\n"
411 "colormap has been set explicitly with gdk_gc_set_colormap.\n");
419 * gdk_gc_set_rgb_fg_color:
421 * @color: an unallocated #GdkColor.
423 * Set the foreground color of a GC using an unallocated color. The
424 * pixel value for the color will be determined using GdkRGB. If the
425 * colormap for the GC has not previously been initialized for GdkRGB,
426 * then for pseudo-color colormaps (colormaps with a small modifiable
427 * number of colors), a colorcube will be allocated in the colormap.
429 * Calling this function for a GC without a colormap is an error.
432 gdk_gc_set_rgb_fg_color (GdkGC *gc, GdkColor *color)
437 g_return_if_fail (GDK_IS_GC (gc));
438 g_return_if_fail (color != NULL);
440 cmap = gdk_gc_get_colormap_warn (gc);
445 gdk_rgb_find_color (cmap, &tmp_color);
446 gdk_gc_set_foreground (gc, &tmp_color);
450 * gdk_gc_set_rgb_bg_color:
452 * @color: an unallocated #GdkColor.
454 * Set the background color of a GC using an unallocated color. The
455 * pixel value for the color will be determined using GdkRGB. If the
456 * colormap for the GC has not previously been initialized for GdkRGB,
457 * then for pseudo-color colormaps (colormaps with a small modifiable
458 * number of colors), a colorcube will be allocated in the colormap.
460 * Calling this function for a GC without a colormap is an error.
463 gdk_gc_set_rgb_bg_color (GdkGC *gc, GdkColor *color)
468 g_return_if_fail (GDK_IS_GC (gc));
469 g_return_if_fail (color != NULL);
471 cmap = gdk_gc_get_colormap_warn (gc);
476 gdk_rgb_find_color (cmap, &tmp_color);
477 gdk_gc_set_foreground (gc, &tmp_color);