1
/* GTK - The GIMP Toolkit
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/.
33
typedef struct _GtkGCKey GtkGCKey;
34
typedef struct _GtkGCDrawable GtkGCDrawable;
39
GdkColormap *colormap;
51
static void gtk_gc_init (void);
52
static GtkGCKey* gtk_gc_key_dup (GtkGCKey *key);
53
static void gtk_gc_key_destroy (GtkGCKey *key);
54
static gpointer gtk_gc_new (gpointer key);
55
static void gtk_gc_destroy (gpointer value);
56
static guint gtk_gc_key_hash (gpointer key);
57
static guint gtk_gc_value_hash (gpointer value);
58
static gint gtk_gc_key_equal (gpointer a,
60
static guint gtk_gc_drawable_hash (GtkGCDrawable *d);
61
static gint gtk_gc_drawable_equal (GtkGCDrawable *a,
65
static gint initialize = TRUE;
66
static GCache *gc_cache = NULL;
67
static GQuark quark_gtk_gc_drawable_ht = 0;
70
gtk_gc_get (gint depth,
71
GdkColormap *colormap,
73
GdkGCValuesMask values_mask)
82
key.colormap = colormap;
84
key.mask = values_mask;
86
gc = g_cache_insert (gc_cache, &key);
92
gtk_gc_release (GdkGC *gc)
97
g_cache_remove (gc_cache, gc);
101
free_gc_drawable (gpointer data)
103
GtkGCDrawable *drawable = data;
104
g_object_unref (drawable->drawable);
105
g_slice_free (GtkGCDrawable, drawable);
109
gtk_gc_get_drawable_ht (GdkScreen *screen)
111
GHashTable *ht = g_object_get_qdata (G_OBJECT (screen), quark_gtk_gc_drawable_ht);
114
ht = g_hash_table_new_full ((GHashFunc) gtk_gc_drawable_hash,
115
(GEqualFunc) gtk_gc_drawable_equal,
116
NULL, free_gc_drawable);
117
g_object_set_qdata_full (G_OBJECT (screen),
118
quark_gtk_gc_drawable_ht, ht,
119
(GDestroyNotify)g_hash_table_destroy);
130
quark_gtk_gc_drawable_ht = g_quark_from_static_string ("gtk-gc-drawable-ht");
132
gc_cache = g_cache_new ((GCacheNewFunc) gtk_gc_new,
133
(GCacheDestroyFunc) gtk_gc_destroy,
134
(GCacheDupFunc) gtk_gc_key_dup,
135
(GCacheDestroyFunc) gtk_gc_key_destroy,
136
(GHashFunc) gtk_gc_key_hash,
137
(GHashFunc) gtk_gc_value_hash,
138
(GEqualFunc) gtk_gc_key_equal);
142
gtk_gc_key_dup (GtkGCKey *key)
146
new_key = g_slice_new (GtkGCKey);
154
gtk_gc_key_destroy (GtkGCKey *key)
156
g_slice_free (GtkGCKey, key);
160
gtk_gc_new (gpointer key)
163
GtkGCDrawable *drawable;
169
screen = gdk_colormap_get_screen (keyval->colormap);
171
ht = gtk_gc_get_drawable_ht (screen);
172
drawable = g_hash_table_lookup (ht, &keyval->depth);
175
drawable = g_slice_new (GtkGCDrawable);
176
drawable->depth = keyval->depth;
177
drawable->drawable = gdk_pixmap_new (gdk_screen_get_root_window (screen),
178
1, 1, drawable->depth);
179
g_hash_table_insert (ht, &drawable->depth, drawable);
182
gc = gdk_gc_new_with_values (drawable->drawable, &keyval->values, keyval->mask);
183
gdk_gc_set_colormap (gc, keyval->colormap);
185
return (gpointer) gc;
189
gtk_gc_destroy (gpointer value)
191
g_object_unref (value);
195
gtk_gc_key_hash (gpointer key)
203
if (keyval->mask & GDK_GC_FOREGROUND)
205
hash_val += keyval->values.foreground.pixel;
207
if (keyval->mask & GDK_GC_BACKGROUND)
209
hash_val += keyval->values.background.pixel;
211
if (keyval->mask & GDK_GC_FONT)
213
hash_val += gdk_font_id (keyval->values.font);
215
if (keyval->mask & GDK_GC_FUNCTION)
217
hash_val += (gint) keyval->values.function;
219
if (keyval->mask & GDK_GC_FILL)
221
hash_val += (gint) keyval->values.fill;
223
if (keyval->mask & GDK_GC_TILE)
225
hash_val += (glong) keyval->values.tile;
227
if (keyval->mask & GDK_GC_STIPPLE)
229
hash_val += (glong) keyval->values.stipple;
231
if (keyval->mask & GDK_GC_CLIP_MASK)
233
hash_val += (glong) keyval->values.clip_mask;
235
if (keyval->mask & GDK_GC_SUBWINDOW)
237
hash_val += (gint) keyval->values.subwindow_mode;
239
if (keyval->mask & GDK_GC_TS_X_ORIGIN)
241
hash_val += (gint) keyval->values.ts_x_origin;
243
if (keyval->mask & GDK_GC_TS_Y_ORIGIN)
245
hash_val += (gint) keyval->values.ts_y_origin;
247
if (keyval->mask & GDK_GC_CLIP_X_ORIGIN)
249
hash_val += (gint) keyval->values.clip_x_origin;
251
if (keyval->mask & GDK_GC_CLIP_Y_ORIGIN)
253
hash_val += (gint) keyval->values.clip_y_origin;
255
if (keyval->mask & GDK_GC_EXPOSURES)
257
hash_val += (gint) keyval->values.graphics_exposures;
259
if (keyval->mask & GDK_GC_LINE_WIDTH)
261
hash_val += (gint) keyval->values.line_width;
263
if (keyval->mask & GDK_GC_LINE_STYLE)
265
hash_val += (gint) keyval->values.line_style;
267
if (keyval->mask & GDK_GC_CAP_STYLE)
269
hash_val += (gint) keyval->values.cap_style;
271
if (keyval->mask & GDK_GC_JOIN_STYLE)
273
hash_val += (gint) keyval->values.join_style;
280
gtk_gc_value_hash (gpointer value)
282
return (gulong) value;
286
gtk_gc_key_equal (gpointer a,
291
GdkGCValues *avalues;
292
GdkGCValues *bvalues;
297
avalues = &akey->values;
298
bvalues = &bkey->values;
300
if (akey->mask != bkey->mask)
303
if (akey->depth != bkey->depth)
306
if (akey->colormap != bkey->colormap)
309
if (akey->mask & GDK_GC_FOREGROUND)
311
if (avalues->foreground.pixel != bvalues->foreground.pixel)
314
if (akey->mask & GDK_GC_BACKGROUND)
316
if (avalues->background.pixel != bvalues->background.pixel)
319
if (akey->mask & GDK_GC_FONT)
321
if (!gdk_font_equal (avalues->font, bvalues->font))
324
if (akey->mask & GDK_GC_FUNCTION)
326
if (avalues->function != bvalues->function)
329
if (akey->mask & GDK_GC_FILL)
331
if (avalues->fill != bvalues->fill)
334
if (akey->mask & GDK_GC_TILE)
336
if (avalues->tile != bvalues->tile)
339
if (akey->mask & GDK_GC_STIPPLE)
341
if (avalues->stipple != bvalues->stipple)
344
if (akey->mask & GDK_GC_CLIP_MASK)
346
if (avalues->clip_mask != bvalues->clip_mask)
349
if (akey->mask & GDK_GC_SUBWINDOW)
351
if (avalues->subwindow_mode != bvalues->subwindow_mode)
354
if (akey->mask & GDK_GC_TS_X_ORIGIN)
356
if (avalues->ts_x_origin != bvalues->ts_x_origin)
359
if (akey->mask & GDK_GC_TS_Y_ORIGIN)
361
if (avalues->ts_y_origin != bvalues->ts_y_origin)
364
if (akey->mask & GDK_GC_CLIP_X_ORIGIN)
366
if (avalues->clip_x_origin != bvalues->clip_x_origin)
369
if (akey->mask & GDK_GC_CLIP_Y_ORIGIN)
371
if (avalues->clip_y_origin != bvalues->clip_y_origin)
374
if (akey->mask & GDK_GC_EXPOSURES)
376
if (avalues->graphics_exposures != bvalues->graphics_exposures)
379
if (akey->mask & GDK_GC_LINE_WIDTH)
381
if (avalues->line_width != bvalues->line_width)
384
if (akey->mask & GDK_GC_LINE_STYLE)
386
if (avalues->line_style != bvalues->line_style)
389
if (akey->mask & GDK_GC_CAP_STYLE)
391
if (avalues->cap_style != bvalues->cap_style)
394
if (akey->mask & GDK_GC_JOIN_STYLE)
396
if (avalues->join_style != bvalues->join_style)
404
gtk_gc_drawable_hash (GtkGCDrawable *d)
410
gtk_gc_drawable_equal (GtkGCDrawable *a,
413
return (a->depth == b->depth);
417
#include "gtkaliasdef.c"