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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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-1999. 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/.
30 #include "gdkprivate.h"
35 GdkGCPrivate *private;
37 private = g_new (GdkGCPrivate, 1);
38 private->ref_count = 1;
39 private->klass = NULL;
40 private->klass_data = NULL;
42 return (GdkGC *)private;
46 gdk_gc_new (GdkDrawable *drawable)
48 g_return_val_if_fail (drawable != NULL, NULL);
50 if (GDK_DRAWABLE_DESTROYED (drawable))
53 return gdk_gc_new_with_values (drawable, NULL, 0);
57 gdk_gc_new_with_values (GdkDrawable *drawable,
59 GdkGCValuesMask values_mask)
61 g_return_val_if_fail (drawable != NULL, NULL);
63 if (GDK_DRAWABLE_DESTROYED (drawable))
66 return ((GdkDrawablePrivate *)drawable)->klass->create_gc (drawable,
72 gdk_gc_ref (GdkGC *gc)
74 GdkGCPrivate *private = (GdkGCPrivate*) gc;
76 g_return_val_if_fail (gc != NULL, NULL);
77 private->ref_count += 1;
83 gdk_gc_unref (GdkGC *gc)
85 GdkGCPrivate *private = (GdkGCPrivate*) gc;
87 g_return_if_fail (gc != NULL);
88 g_return_if_fail (private->ref_count > 0);
92 if (private->ref_count == 0)
93 private->klass->destroy (gc);
97 gdk_gc_get_values (GdkGC *gc,
100 g_return_if_fail (gc != NULL);
101 g_return_if_fail (values != NULL);
103 ((GdkGCPrivate *)gc)->klass->get_values (gc, values);
107 gdk_gc_set_values (GdkGC *gc,
109 GdkGCValuesMask values_mask)
111 g_return_if_fail (gc != NULL);
112 g_return_if_fail (values != NULL);
114 ((GdkGCPrivate *)gc)->klass->set_values (gc, values, values_mask);
118 gdk_gc_set_foreground (GdkGC *gc,
123 g_return_if_fail (gc != NULL);
124 g_return_if_fail (color != NULL);
126 values.foreground = *color;
127 gdk_gc_set_values (gc, &values, GDK_GC_FOREGROUND);
131 gdk_gc_set_background (GdkGC *gc,
136 g_return_if_fail (gc != NULL);
137 g_return_if_fail (color != NULL);
139 values.background = *color;
140 gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
144 gdk_gc_set_font (GdkGC *gc,
149 g_return_if_fail (gc != NULL);
150 g_return_if_fail (font != NULL);
153 gdk_gc_set_values (gc, &values, GDK_GC_FONT);
157 gdk_gc_set_function (GdkGC *gc,
158 GdkFunction function)
162 g_return_if_fail (gc != NULL);
164 values.function = function;
165 gdk_gc_set_values (gc, &values, GDK_GC_FUNCTION);
169 gdk_gc_set_fill (GdkGC *gc,
174 g_return_if_fail (gc != NULL);
177 gdk_gc_set_values (gc, &values, GDK_GC_FILL);
181 gdk_gc_set_tile (GdkGC *gc,
186 g_return_if_fail (gc != NULL);
189 gdk_gc_set_values (gc, &values, GDK_GC_TILE);
193 gdk_gc_set_stipple (GdkGC *gc,
198 g_return_if_fail (gc != NULL);
200 values.stipple = stipple;
201 gdk_gc_set_values (gc, &values, GDK_GC_STIPPLE);
205 gdk_gc_set_ts_origin (GdkGC *gc,
211 g_return_if_fail (gc != NULL);
213 values.ts_x_origin = x;
214 values.ts_y_origin = y;
216 gdk_gc_set_values (gc, &values,
217 GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
221 gdk_gc_set_clip_origin (GdkGC *gc,
227 g_return_if_fail (gc != NULL);
229 values.clip_x_origin = x;
230 values.clip_y_origin = y;
232 gdk_gc_set_values (gc, &values,
233 GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
237 gdk_gc_set_clip_mask (GdkGC *gc,
242 g_return_if_fail (gc != NULL);
244 values.clip_mask = mask;
245 gdk_gc_set_values (gc, &values, GDK_GC_CLIP_MASK);
250 gdk_gc_set_subwindow (GdkGC *gc,
251 GdkSubwindowMode mode)
255 g_return_if_fail (gc != NULL);
257 values.subwindow_mode = mode;
258 gdk_gc_set_values (gc, &values, GDK_GC_SUBWINDOW);
262 gdk_gc_set_exposures (GdkGC *gc,
267 g_return_if_fail (gc != NULL);
269 values.graphics_exposures = exposures;
270 gdk_gc_set_values (gc, &values, GDK_GC_EXPOSURES);
274 gdk_gc_set_line_attributes (GdkGC *gc,
276 GdkLineStyle line_style,
277 GdkCapStyle cap_style,
278 GdkJoinStyle join_style)
282 values.line_width = line_width;
283 values.line_style = line_style;
284 values.cap_style = cap_style;
285 values.join_style = join_style;
287 gdk_gc_set_values (gc, &values,
295 gdk_gc_set_dashes (GdkGC *gc,
300 g_return_if_fail (gc != NULL);
301 g_return_if_fail (dash_list != NULL);
303 ((GdkGCPrivate *)gc)->klass->set_dashes (gc, dash_offset, dash_list, n);