]> Pileus Git - ~andy/gtk/blob - gdk/directfb/gdkgc-directfb.c
#undef GDK_DISABLE_DEPRECATED to get prototype for gdk_font_ref().
[~andy/gtk] / gdk / directfb / gdkgc-directfb.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 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.
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  * Lesser General Public License for more details.
13  *
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.
18  */
19
20 /*
21  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
22  * file for a list of people on the GTK+ Team.
23  */
24
25 /*
26  * GTK+ DirectFB backend
27  * Copyright (C) 2001-2002  convergence integrated media GmbH
28  * Copyright (C) 2002-2004  convergence GmbH
29  * Written by Denis Oliver Kropp <dok@convergence.de> and
30  *            Sven Neumann <sven@convergence.de>
31  */
32
33 #undef GDK_DISABLE_DEPRECATED
34
35 #include <config.h>
36 #include "gdk.h"
37
38 #include <string.h>
39
40 #include "gdkdirectfb.h"
41 #include "gdkprivate-directfb.h"
42
43 #include "gdkgc.h"
44 #include "gdkfont.h"
45 #include "gdkpixmap.h"
46 #include "gdkregion-generic.h"
47
48 #include "gdkalias.h"
49
50 static void gdk_directfb_gc_get_values (GdkGC           *gc,
51                                         GdkGCValues     *values);
52 static void gdk_directfb_gc_set_values (GdkGC           *gc,
53                                         GdkGCValues     *values,
54                                         GdkGCValuesMask  values_mask);
55 static void gdk_directfb_gc_set_dashes (GdkGC           *gc,
56                                         gint             dash_offset,
57                                         gint8            dash_list[],
58                                         gint             n);
59
60 static void gdk_gc_directfb_class_init (GdkGCDirectFBClass *klass);
61 static void gdk_gc_directfb_finalize   (GObject            *object);
62
63
64 static gpointer parent_class = NULL;
65
66
67 GType
68 gdk_gc_directfb_get_type (void)
69 {
70   static GType object_type = 0;
71
72   if (!object_type)
73     {
74       static const GTypeInfo object_info =
75       {
76         sizeof (GdkGCDirectFBClass),
77         (GBaseInitFunc) NULL,
78         (GBaseFinalizeFunc) NULL,
79         (GClassInitFunc) gdk_gc_directfb_class_init,
80         NULL,           /* class_finalize */
81         NULL,           /* class_data */
82         sizeof (GdkGCDirectFB),
83         0,              /* n_preallocs */
84         (GInstanceInitFunc) NULL,
85       };
86
87       object_type = g_type_register_static (GDK_TYPE_GC,
88                                             "GdkGCDirectFB",
89                                             &object_info, 0);
90     }
91
92   return object_type;
93 }
94
95 static void
96 gdk_gc_directfb_class_init (GdkGCDirectFBClass *klass)
97 {
98   GObjectClass *object_class = G_OBJECT_CLASS (klass);
99   GdkGCClass   *gc_class     = GDK_GC_CLASS (klass);
100
101   parent_class = g_type_class_peek_parent (klass);
102
103   object_class->finalize = gdk_gc_directfb_finalize;
104
105   gc_class->get_values = gdk_directfb_gc_get_values;
106   gc_class->set_values = gdk_directfb_gc_set_values;
107   gc_class->set_dashes = gdk_directfb_gc_set_dashes;
108 }
109
110 static void
111 gdk_gc_directfb_finalize (GObject *object)
112 {
113   GdkGC         *gc      = GDK_GC (object);
114   GdkGCDirectFB *private = GDK_GC_DIRECTFB (gc);
115
116   if (private->clip_region)
117     gdk_region_destroy (private->clip_region);
118   if (private->values.clip_mask)
119     g_object_unref (private->values.clip_mask);
120   if (private->values.stipple)
121     g_object_unref (private->values.stipple);
122   if (private->values.tile)
123     g_object_unref (private->values.tile);
124
125   if (G_OBJECT_CLASS (parent_class)->finalize)
126     G_OBJECT_CLASS (parent_class)->finalize (object);
127 }
128
129 GdkGC*
130 _gdk_directfb_gc_new (GdkDrawable     *drawable,
131                       GdkGCValues     *values,
132                       GdkGCValuesMask  values_mask)
133 {
134   GdkGC         *gc;
135   GdkGCDirectFB *private;
136
137   g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_DIRECTFB (drawable), NULL);
138
139   gc = GDK_GC (g_object_new (gdk_gc_directfb_get_type (), NULL));
140
141   _gdk_gc_init (gc, drawable, values, values_mask);
142
143   private = GDK_GC_DIRECTFB (gc);
144 #if 0
145   private->values.background.pixel = 0;
146   private->values.background.red   =
147   private->values.background.green =
148   private->values.background.blue  = 0;
149
150   private->values.foreground.pixel = 0;
151   private->values.foreground.red   =
152   private->values.foreground.green =
153   private->values.foreground.blue  = 0;
154 #endif
155
156   private->values.cap_style = GDK_CAP_BUTT;
157
158   gdk_directfb_gc_set_values (gc, values, values_mask);
159
160   return gc;
161 }
162
163 static void
164 gdk_directfb_gc_get_values (GdkGC       *gc,
165                             GdkGCValues *values)
166 {
167   *values = GDK_GC_DIRECTFB (gc)->values;
168 }
169
170 #if 0
171 void
172 _gdk_windowing_gc_get_foreground (GdkGC    *gc,
173                                   GdkColor *color)
174 {
175   GdkGCDirectFB *private;
176   private = GDK_GC_DIRECTFB (gc);
177   *color =private->values.foreground;
178
179
180 }
181 #endif
182
183 static void
184 gdk_directfb_gc_set_values (GdkGC           *gc,
185                             GdkGCValues     *values,
186                             GdkGCValuesMask  values_mask)
187 {
188   GdkGCDirectFB *private = GDK_GC_DIRECTFB (gc);
189
190   if (values_mask & GDK_GC_FOREGROUND)
191     {
192       private->values.foreground = values->foreground;
193       private->values_mask |= GDK_GC_FOREGROUND;
194     }
195
196   if (values_mask & GDK_GC_BACKGROUND)
197     {
198       private->values.background = values->background;
199       private->values_mask |= GDK_GC_BACKGROUND;
200     }
201
202   if (values_mask & GDK_GC_FONT)
203     {
204       GdkFont *oldf = private->values.font;
205
206       private->values.font = gdk_font_ref (values->font);
207       private->values_mask |= GDK_GC_FONT;
208
209       if (oldf)
210         gdk_font_unref (oldf);
211     }
212
213   if (values_mask & GDK_GC_FUNCTION)
214     {
215       private->values.function = values->function;
216       private->values_mask |= GDK_GC_FUNCTION;
217     }
218
219   if (values_mask & GDK_GC_FILL)
220     {
221       private->values.fill = values->fill;
222       private->values_mask |= GDK_GC_FILL;
223     }
224
225   if (values_mask & GDK_GC_TILE)
226     {
227       GdkPixmap *oldpm = private->values.tile;
228
229       if (values->tile)
230         g_assert (GDK_PIXMAP_OBJECT (values->tile)->depth > 1);
231
232       private->values.tile = values->tile ? g_object_ref (values->tile) : NULL;
233       private->values_mask |= GDK_GC_TILE;
234
235       if (oldpm)
236         g_object_unref (oldpm);
237     }
238
239   if (values_mask & GDK_GC_STIPPLE)
240     {
241       GdkPixmap *oldpm = private->values.stipple;
242
243       if (values->stipple)
244         g_assert (GDK_PIXMAP_OBJECT (values->stipple)->depth == 1);
245
246       private->values.stipple = (values->stipple ?
247                                  g_object_ref (values->stipple) : NULL);
248       private->values_mask |= GDK_GC_STIPPLE;
249
250       if (oldpm)
251         g_object_unref (oldpm);
252     }
253
254   if (values_mask & GDK_GC_CLIP_MASK)
255     {
256       GdkPixmap *oldpm = private->values.clip_mask;
257
258       private->values.clip_mask = (values->clip_mask ?
259                                    g_object_ref (values->clip_mask) : NULL);
260       private->values_mask |= GDK_GC_CLIP_MASK;
261
262       if (oldpm)
263         g_object_unref (oldpm);
264
265       if (private->clip_region)
266         {
267           gdk_region_destroy (private->clip_region);
268           private->clip_region = NULL;
269         }
270     }
271
272   if (values_mask & GDK_GC_SUBWINDOW)
273     {
274       private->values.subwindow_mode = values->subwindow_mode;
275       private->values_mask |= GDK_GC_SUBWINDOW;
276     }
277
278   if (values_mask & GDK_GC_TS_X_ORIGIN)
279     {
280       private->values.ts_x_origin = values->ts_x_origin;
281       private->values_mask |= GDK_GC_TS_X_ORIGIN;
282     }
283
284   if (values_mask & GDK_GC_TS_Y_ORIGIN)
285     {
286       private->values.ts_y_origin = values->ts_y_origin;
287       private->values_mask |= GDK_GC_TS_Y_ORIGIN;
288     }
289
290   if (values_mask & GDK_GC_CLIP_X_ORIGIN)
291     {
292       private->values.clip_x_origin = GDK_GC (gc)->clip_x_origin = values->clip_x_origin;
293       private->values_mask |= GDK_GC_CLIP_X_ORIGIN;
294     }
295
296   if (values_mask & GDK_GC_CLIP_Y_ORIGIN)
297     {
298       private->values.clip_y_origin = GDK_GC (gc)->clip_y_origin = values->clip_y_origin;
299       private->values_mask |= GDK_GC_CLIP_Y_ORIGIN;
300     }
301
302   if (values_mask & GDK_GC_EXPOSURES)
303     {
304       private->values.graphics_exposures = values->graphics_exposures;
305       private->values_mask |= GDK_GC_EXPOSURES;
306     }
307
308   if (values_mask & GDK_GC_LINE_WIDTH)
309     {
310       private->values.line_width = values->line_width;
311       private->values_mask |= GDK_GC_LINE_WIDTH;
312     }
313
314   if (values_mask & GDK_GC_LINE_STYLE)
315     {
316       private->values.line_style = values->line_style;
317       private->values_mask |= GDK_GC_LINE_STYLE;
318     }
319
320   if (values_mask & GDK_GC_CAP_STYLE)
321     {
322       private->values.cap_style = values->cap_style;
323       private->values_mask |= GDK_GC_CAP_STYLE;
324     }
325
326   if (values_mask & GDK_GC_JOIN_STYLE)
327     {
328       private->values.join_style = values->join_style;
329       private->values_mask |= GDK_GC_JOIN_STYLE;
330     }
331 }
332
333 static void
334 gdk_directfb_gc_set_dashes (GdkGC *gc,
335                             gint   dash_offset,
336                             gint8  dash_list[],
337                             gint   n)
338 {
339   g_warning ("gdk_directfb_gc_set_dashes not implemented");
340 }
341
342 static void
343 gc_unset_clip_mask (GdkGC *gc)
344 {
345   GdkGCDirectFB *data = GDK_GC_DIRECTFB (gc);
346
347   if (data->values.clip_mask)
348     {
349       g_object_unref (data->values.clip_mask);
350       data->values.clip_mask = NULL;
351       data->values_mask &= ~ GDK_GC_CLIP_MASK;
352     }
353 }
354
355
356 void
357 _gdk_windowing_gc_set_clip_region (GdkGC     *gc,
358                         GdkRegion *region)
359 {
360   GdkGCDirectFB *data;
361
362   g_return_if_fail (gc != NULL);
363
364   data = GDK_GC_DIRECTFB (gc);
365
366   if (region == data->clip_region)
367     return;
368
369   if (data->clip_region)
370     {
371       gdk_region_destroy (data->clip_region);
372       data->clip_region = NULL;
373     }
374
375   if (region)
376     data->clip_region = gdk_region_copy (region);
377
378   gc->clip_x_origin = 0;
379   gc->clip_y_origin = 0;
380   data->values.clip_x_origin = 0;
381   data->values.clip_y_origin = 0;
382
383   gc_unset_clip_mask (gc);
384 }
385
386 void
387 _gdk_windowing_gc_copy (GdkGC *dst_gc,
388              GdkGC *src_gc)
389 {
390   GdkGCDirectFB *dst_private;
391
392   g_return_if_fail (dst_gc != NULL);
393   g_return_if_fail (src_gc != NULL);
394
395   dst_private = GDK_GC_DIRECTFB (dst_gc);
396
397   if (dst_private->clip_region)
398     gdk_region_destroy(dst_private->clip_region);
399
400   if (dst_private->values_mask & GDK_GC_FONT)
401     gdk_font_unref (dst_private->values.font);
402   if (dst_private->values_mask & GDK_GC_TILE)
403     g_object_unref (dst_private->values.tile);
404   if (dst_private->values_mask & GDK_GC_STIPPLE)
405     g_object_unref (dst_private->values.stipple);
406   if (dst_private->values_mask & GDK_GC_CLIP_MASK)
407     g_object_unref (dst_private->values.clip_mask);
408
409   *dst_gc = *src_gc;
410   if (dst_private->values_mask & GDK_GC_FONT)
411     gdk_font_ref (dst_private->values.font);
412   if (dst_private->values_mask & GDK_GC_TILE)
413     g_object_ref (dst_private->values.tile);
414   if (dst_private->values_mask & GDK_GC_STIPPLE)
415     g_object_ref (dst_private->values.stipple);
416   if (dst_private->values_mask & GDK_GC_CLIP_MASK)
417     g_object_ref (dst_private->values.clip_mask);
418   if (dst_private->clip_region)
419     dst_private->clip_region = gdk_region_copy (dst_private->clip_region);
420 }
421
422 /**
423  * gdk_gc_get_screen:
424  * @gc: a #GdkGC.
425  *
426  * Gets the #GdkScreen for which @gc was created
427  *
428  * Returns: the #GdkScreen for @gc.
429  *
430  * Since: 2.2
431  */
432 GdkScreen *  
433 gdk_gc_get_screen (GdkGC *gc)
434 {
435   g_return_val_if_fail (GDK_IS_GC_DIRECTFB (gc), NULL);
436   
437   return _gdk_screen;
438 }
439 #define __GDK_GC_X11_C__
440 #include "gdkaliasdef.c"