]> Pileus Git - ~andy/gtk/blob - gdk/gdkgc.c
Merges from gtk-1-2
[~andy/gtk] / gdk / gdkgc.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include <string.h>
28
29 #include "gdkgc.h"
30 #include "gdkprivate.h"
31
32 GdkGC*
33 gdk_gc_alloc (void)
34 {
35   GdkGCPrivate *private;
36
37   private = g_new (GdkGCPrivate, 1);
38   private->ref_count = 1;
39   private->klass = NULL;
40   private->klass_data = NULL;
41
42   return (GdkGC *)private;
43 }
44
45 GdkGC*
46 gdk_gc_new (GdkDrawable *drawable)
47 {
48   g_return_val_if_fail (drawable != NULL, NULL);
49
50   if (GDK_DRAWABLE_DESTROYED (drawable))
51     return NULL;
52
53   return gdk_gc_new_with_values (drawable, NULL, 0);
54 }
55
56 GdkGC*
57 gdk_gc_new_with_values (GdkDrawable     *drawable,
58                         GdkGCValues     *values,
59                         GdkGCValuesMask  values_mask)
60 {
61   g_return_val_if_fail (drawable != NULL, NULL);
62
63   if (GDK_DRAWABLE_DESTROYED (drawable))
64     return NULL;
65
66   return ((GdkDrawablePrivate *)drawable)->klass->create_gc (drawable,
67                                                              values,
68                                                              values_mask);
69 }
70
71 GdkGC *
72 gdk_gc_ref (GdkGC *gc)
73 {
74   GdkGCPrivate *private = (GdkGCPrivate*) gc;
75
76   g_return_val_if_fail (gc != NULL, NULL);
77   private->ref_count += 1;
78
79   return gc;
80 }
81
82 void
83 gdk_gc_unref (GdkGC *gc)
84 {
85   GdkGCPrivate *private = (GdkGCPrivate*) gc;
86   
87   g_return_if_fail (gc != NULL);
88   g_return_if_fail (private->ref_count > 0);
89   
90   private->ref_count--;
91
92   if (private->ref_count == 0)
93     private->klass->destroy (gc);
94 }
95
96 void
97 gdk_gc_get_values (GdkGC       *gc,
98                    GdkGCValues *values)
99 {
100   g_return_if_fail (gc != NULL);
101   g_return_if_fail (values != NULL);
102
103   ((GdkGCPrivate *)gc)->klass->get_values (gc, values);
104 }
105
106 void
107 gdk_gc_set_values (GdkGC           *gc,
108                    GdkGCValues     *values,
109                    GdkGCValuesMask  values_mask)
110 {
111   g_return_if_fail (gc != NULL);
112   g_return_if_fail (values != NULL);
113
114   ((GdkGCPrivate *)gc)->klass->set_values (gc, values, values_mask);
115 }
116
117 void
118 gdk_gc_set_foreground (GdkGC    *gc,
119                        GdkColor *color)
120 {
121   GdkGCValues values;
122
123   g_return_if_fail (gc != NULL);
124   g_return_if_fail (color != NULL);
125
126   values.foreground = *color;
127   gdk_gc_set_values (gc, &values, GDK_GC_FOREGROUND);
128 }
129
130 void
131 gdk_gc_set_background (GdkGC    *gc,
132                        GdkColor *color)
133 {
134   GdkGCValues values;
135
136   g_return_if_fail (gc != NULL);
137   g_return_if_fail (color != NULL);
138
139   values.background = *color;
140   gdk_gc_set_values (gc, &values, GDK_GC_BACKGROUND);
141 }
142
143 void
144 gdk_gc_set_font (GdkGC   *gc,
145                  GdkFont *font)
146 {
147   GdkGCValues values;
148
149   g_return_if_fail (gc != NULL);
150   g_return_if_fail (font != NULL);
151
152   values.font = font;
153   gdk_gc_set_values (gc, &values, GDK_GC_FONT);
154 }
155
156 void
157 gdk_gc_set_function (GdkGC       *gc,
158                      GdkFunction  function)
159 {
160   GdkGCValues values;
161
162   g_return_if_fail (gc != NULL);
163
164   values.function = function;
165   gdk_gc_set_values (gc, &values, GDK_GC_FUNCTION);
166 }
167
168 void
169 gdk_gc_set_fill (GdkGC   *gc,
170                  GdkFill  fill)
171 {
172   GdkGCValues values;
173
174   g_return_if_fail (gc != NULL);
175
176   values.fill = fill;
177   gdk_gc_set_values (gc, &values, GDK_GC_FILL);
178 }
179
180 void
181 gdk_gc_set_tile (GdkGC     *gc,
182                  GdkPixmap *tile)
183 {
184   GdkGCValues values;
185
186   g_return_if_fail (gc != NULL);
187
188   values.tile = tile;
189   gdk_gc_set_values (gc, &values, GDK_GC_TILE);
190 }
191
192 void
193 gdk_gc_set_stipple (GdkGC     *gc,
194                     GdkPixmap *stipple)
195 {
196   GdkGCValues values;
197
198   g_return_if_fail (gc != NULL);
199
200   values.stipple = stipple;
201   gdk_gc_set_values (gc, &values, GDK_GC_STIPPLE);
202 }
203
204 void
205 gdk_gc_set_ts_origin (GdkGC *gc,
206                       gint   x,
207                       gint   y)
208 {
209   GdkGCValues values;
210
211   g_return_if_fail (gc != NULL);
212
213   values.ts_x_origin = x;
214   values.ts_y_origin = y;
215   
216   gdk_gc_set_values (gc, &values,
217                      GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN);
218 }
219
220 void
221 gdk_gc_set_clip_origin (GdkGC *gc,
222                         gint   x,
223                         gint   y)
224 {
225   GdkGCValues values;
226
227   g_return_if_fail (gc != NULL);
228
229   values.clip_x_origin = x;
230   values.clip_y_origin = y;
231   
232   gdk_gc_set_values (gc, &values,
233                      GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
234 }
235
236 void
237 gdk_gc_set_clip_mask (GdkGC     *gc,
238                       GdkBitmap *mask)
239 {
240   GdkGCValues values;
241   
242   g_return_if_fail (gc != NULL);
243   
244   values.clip_mask = mask;
245   gdk_gc_set_values (gc, &values, GDK_GC_CLIP_MASK);
246 }
247
248
249 void
250 gdk_gc_set_subwindow (GdkGC            *gc,
251                       GdkSubwindowMode  mode)
252 {
253   GdkGCValues values;
254
255   g_return_if_fail (gc != NULL);
256
257   values.subwindow_mode = mode;
258   gdk_gc_set_values (gc, &values, GDK_GC_SUBWINDOW);
259 }
260
261 void
262 gdk_gc_set_exposures (GdkGC     *gc,
263                       gboolean   exposures)
264 {
265   GdkGCValues values;
266
267   g_return_if_fail (gc != NULL);
268
269   values.graphics_exposures = exposures;
270   gdk_gc_set_values (gc, &values, GDK_GC_EXPOSURES);
271 }
272
273 void
274 gdk_gc_set_line_attributes (GdkGC       *gc,
275                             gint         line_width,
276                             GdkLineStyle line_style,
277                             GdkCapStyle  cap_style,
278                             GdkJoinStyle join_style)
279 {
280   GdkGCValues values;
281
282   values.line_width = line_width;
283   values.line_style = line_style;
284   values.cap_style = cap_style;
285   values.join_style = join_style;
286
287   gdk_gc_set_values (gc, &values,
288                      GDK_GC_LINE_WIDTH |
289                      GDK_GC_LINE_STYLE |
290                      GDK_GC_CAP_STYLE |
291                      GDK_GC_JOIN_STYLE);
292 }
293
294 void
295 gdk_gc_set_dashes (GdkGC *gc,
296                    gint   dash_offset,
297                    gint8  dash_list[],
298                    gint   n)
299 {
300   g_return_if_fail (gc != NULL);
301   g_return_if_fail (dash_list != NULL);
302
303   ((GdkGCPrivate *)gc)->klass->set_dashes (gc, dash_offset, dash_list, n);
304 }