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/.
27 #include "gdkprivate-x11.h"
28 #include <pango/pangox.h>
30 static void gdk_x11_drawable_destroy (GdkDrawable *drawable);
32 static void gdk_x11_draw_rectangle (GdkDrawable *drawable,
39 static void gdk_x11_draw_arc (GdkDrawable *drawable,
48 static void gdk_x11_draw_polygon (GdkDrawable *drawable,
53 static void gdk_x11_draw_text (GdkDrawable *drawable,
60 static void gdk_x11_draw_text_wc (GdkDrawable *drawable,
67 static void gdk_x11_draw_drawable (GdkDrawable *drawable,
76 static void gdk_x11_draw_points (GdkDrawable *drawable,
80 static void gdk_x11_draw_segments (GdkDrawable *drawable,
84 static void gdk_x11_draw_lines (GdkDrawable *drawable,
88 static void gdk_x11_draw_glyphs (GdkDrawable *drawable,
93 PangoGlyphString *glyphs);
95 GdkDrawableClass _gdk_x11_drawable_class = {
96 gdk_x11_drawable_destroy,
98 gdk_x11_draw_rectangle,
100 gdk_x11_draw_polygon,
102 gdk_x11_draw_text_wc,
103 gdk_x11_draw_drawable,
105 gdk_x11_draw_segments,
110 /*****************************************************
111 * X11 specific implementations of generic functions *
112 *****************************************************/
115 gdk_drawable_get_colormap (GdkDrawable *drawable)
117 GdkDrawablePrivate *drawable_private;
118 XWindowAttributes window_attributes;
120 g_return_val_if_fail (drawable != NULL, NULL);
121 drawable_private = (GdkDrawablePrivate*) drawable;
123 if (!GDK_DRAWABLE_DESTROYED (drawable))
125 if (drawable_private->colormap == NULL &&
126 GDK_IS_WINDOW (drawable))
128 XGetWindowAttributes (GDK_DRAWABLE_XDISPLAY (drawable),
129 GDK_DRAWABLE_XID (drawable),
131 drawable_private->colormap = gdk_colormap_lookup (window_attributes.colormap);
134 return drawable_private->colormap;
141 gdk_drawable_set_colormap (GdkDrawable *drawable,
142 GdkColormap *colormap)
144 GdkDrawablePrivate *drawable_private;
145 GdkColormapPrivateX *colormap_private;
147 g_return_if_fail (drawable != NULL);
148 g_return_if_fail (colormap != NULL);
150 drawable_private = (GdkDrawablePrivate *)drawable;
151 colormap_private = (GdkColormapPrivateX *)colormap;
153 if (!GDK_DRAWABLE_DESTROYED (drawable))
155 if (GDK_IS_WINDOW (drawable))
157 g_return_if_fail (colormap_private->base.visual !=
158 ((GdkColormapPrivate *)(drawable_private->colormap))->visual);
160 XSetWindowColormap (GDK_DRAWABLE_XDISPLAY (drawable),
161 GDK_DRAWABLE_XID (drawable),
162 colormap_private->xcolormap);
165 if (drawable_private->colormap)
166 gdk_colormap_unref (drawable_private->colormap);
167 drawable_private->colormap = colormap;
168 gdk_colormap_ref (drawable_private->colormap);
170 if (GDK_IS_WINDOW (drawable) &&
171 drawable_private->window_type != GDK_WINDOW_TOPLEVEL)
172 gdk_window_add_colormap_windows (drawable);
179 gdk_x11_drawable_destroy (GdkDrawable *drawable)
185 gdk_x11_draw_rectangle (GdkDrawable *drawable,
194 XFillRectangle (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
195 GDK_GC_GET_XGC (gc), x, y, width, height);
197 XDrawRectangle (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
198 GDK_GC_GET_XGC (gc), x, y, width, height);
202 gdk_x11_draw_arc (GdkDrawable *drawable,
213 XFillArc (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
214 GDK_GC_GET_XGC (gc), x, y, width, height, angle1, angle2);
216 XDrawArc (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
217 GDK_GC_GET_XGC (gc), x, y, width, height, angle1, angle2);
221 gdk_x11_draw_polygon (GdkDrawable *drawable,
231 (points[0].x != points[npoints-1].x || points[0].y != points[npoints-1].y))
233 tmp_npoints = npoints + 1;
234 tmp_points = g_new (XPoint, tmp_npoints);
235 tmp_points[npoints].x = points[0].x;
236 tmp_points[npoints].y = points[0].y;
240 tmp_npoints = npoints;
241 tmp_points = g_new (XPoint, tmp_npoints);
244 for (i=0; i<npoints; i++)
246 tmp_points[i].x = points[i].x;
247 tmp_points[i].y = points[i].y;
251 XFillPolygon (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
252 GDK_GC_GET_XGC (gc), tmp_points, tmp_npoints, Complex, CoordModeOrigin);
254 XDrawLines (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
255 GDK_GC_GET_XGC (gc), tmp_points, tmp_npoints, CoordModeOrigin);
262 * Modified by Li-Da Lho to draw 16 bits and Multibyte strings
264 * Interface changed: add "GdkFont *font" to specify font or fontset explicitely
267 gdk_x11_draw_text (GdkDrawable *drawable,
275 if (font->type == GDK_FONT_FONT)
277 XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT (font);
278 XSetFont(GDK_DRAWABLE_XDISPLAY (drawable), GDK_GC_GET_XGC (gc), xfont->fid);
279 if ((xfont->min_byte1 == 0) && (xfont->max_byte1 == 0))
281 XDrawString (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
282 GDK_GC_GET_XGC (gc), x, y, text, text_length);
286 XDrawString16 (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
287 GDK_GC_GET_XGC (gc), x, y, (XChar2b *) text, text_length / 2);
290 else if (font->type == GDK_FONT_FONTSET)
292 XFontSet fontset = (XFontSet) GDK_FONT_XFONT (font);
293 XmbDrawString (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
294 fontset, GDK_GC_GET_XGC (gc), x, y, text, text_length);
297 g_error("undefined font type\n");
301 gdk_x11_draw_text_wc (GdkDrawable *drawable,
306 const GdkWChar *text,
309 if (font->type == GDK_FONT_FONT)
311 XFontStruct *xfont = (XFontStruct *) GDK_FONT_XFONT (font);
314 XSetFont(GDK_DRAWABLE_XDISPLAY (drawable), GDK_GC_GET_XGC (gc), xfont->fid);
315 text_8bit = g_new (gchar, text_length);
316 for (i=0; i<text_length; i++) text_8bit[i] = text[i];
317 XDrawString (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
318 GDK_GC_GET_XGC (gc), x, y, text_8bit, text_length);
321 else if (font->type == GDK_FONT_FONTSET)
323 if (sizeof(GdkWChar) == sizeof(wchar_t))
325 XwcDrawString (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
326 (XFontSet) GDK_FONT_XFONT (font),
327 GDK_GC_GET_XGC (gc), x, y, (wchar_t *)text, text_length);
333 text_wchar = g_new (wchar_t, text_length);
334 for (i=0; i<text_length; i++) text_wchar[i] = text[i];
335 XwcDrawString (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
336 (XFontSet) GDK_FONT_XFONT (font),
337 GDK_GC_GET_XGC (gc), x, y, text_wchar, text_length);
342 g_error("undefined font type\n");
346 gdk_x11_draw_drawable (GdkDrawable *drawable,
356 int src_depth = gdk_drawable_get_depth (src);
357 int dest_depth = gdk_drawable_get_depth (drawable);
361 XCopyArea (GDK_DRAWABLE_XDISPLAY (drawable),
362 GDK_DRAWABLE_XID (src),
363 GDK_DRAWABLE_XID (drawable),
369 else if (dest_depth != 0 && src_depth == dest_depth)
371 XCopyArea (GDK_DRAWABLE_XDISPLAY (drawable),
372 GDK_DRAWABLE_XID (src),
373 GDK_DRAWABLE_XID (drawable),
380 g_warning ("Attempt to copy between drawables of mismatched depths!\n");
384 gdk_x11_draw_points (GdkDrawable *drawable,
389 /* We special-case npoints == 1, because X will merge multiple
390 * consecutive XDrawPoint requests into a PolyPoint request
394 XDrawPoint (GDK_DRAWABLE_XDISPLAY (drawable),
395 GDK_DRAWABLE_XID (drawable),
397 points[0].x, points[0].y);
402 XPoint *tmp_points = g_new (XPoint, npoints);
404 for (i=0; i<npoints; i++)
406 tmp_points[i].x = points[i].x;
407 tmp_points[i].y = points[i].y;
410 XDrawPoints (GDK_DRAWABLE_XDISPLAY (drawable),
411 GDK_DRAWABLE_XID (drawable),
422 gdk_x11_draw_segments (GdkDrawable *drawable,
427 /* We special-case nsegs == 1, because X will merge multiple
428 * consecutive XDrawLine requests into a PolySegment request
432 XDrawLine (GDK_DRAWABLE_XDISPLAY (drawable), GDK_DRAWABLE_XID (drawable),
433 GDK_GC_GET_XGC (gc), segs[0].x1, segs[0].y1,
434 segs[0].x2, segs[0].y2);
439 XSegment *tmp_segs = g_new (XSegment, nsegs);
441 for (i=0; i<nsegs; i++)
443 tmp_segs[i].x1 = segs[i].x1;
444 tmp_segs[i].x2 = segs[i].x2;
445 tmp_segs[i].y1 = segs[i].y1;
446 tmp_segs[i].y2 = segs[i].y2;
449 XDrawSegments (GDK_DRAWABLE_XDISPLAY (drawable),
450 GDK_DRAWABLE_XID (drawable),
459 gdk_x11_draw_lines (GdkDrawable *drawable,
465 XPoint *tmp_points = g_new (XPoint, npoints);
467 for (i=0; i<npoints; i++)
469 tmp_points[i].x = points[i].x;
470 tmp_points[i].y = points[i].y;
473 XDrawLines (GDK_DRAWABLE_XDISPLAY (drawable),
474 GDK_DRAWABLE_XID (drawable),
483 gdk_x11_draw_glyphs (GdkDrawable *drawable,
488 PangoGlyphString *glyphs)
490 pango_x_render (GDK_DRAWABLE_XDISPLAY (drawable),
491 GDK_DRAWABLE_XID (drawable),