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 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/.
30 #include <pango/pangowin32.h>
32 #include "gdkprivate-win32.h"
34 static void gdk_win32_draw_rectangle (GdkDrawable *drawable,
41 static void gdk_win32_draw_arc (GdkDrawable *drawable,
50 static void gdk_win32_draw_polygon (GdkDrawable *drawable,
55 static void gdk_win32_draw_text (GdkDrawable *drawable,
62 static void gdk_win32_draw_text_wc (GdkDrawable *drawable,
69 static void gdk_win32_draw_drawable (GdkDrawable *drawable,
78 static void gdk_win32_draw_points (GdkDrawable *drawable,
82 static void gdk_win32_draw_segments (GdkDrawable *drawable,
86 static void gdk_win32_draw_lines (GdkDrawable *drawable,
90 static void gdk_win32_draw_glyphs (GdkDrawable *drawable,
95 PangoGlyphString *glyphs);
96 static void gdk_win32_draw_image (GdkDrawable *drawable,
106 static void gdk_win32_set_colormap (GdkDrawable *drawable,
107 GdkColormap *colormap);
109 static GdkColormap* gdk_win32_get_colormap (GdkDrawable *drawable);
111 static gint gdk_win32_get_depth (GdkDrawable *drawable);
113 static GdkVisual* gdk_win32_get_visual (GdkDrawable *drawable);
115 static void gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass);
117 static gpointer parent_class = NULL;
120 gdk_drawable_impl_win32_get_type (void)
122 static GType object_type = 0;
126 static const GTypeInfo object_info =
128 sizeof (GdkDrawableImplWin32Class),
129 (GBaseInitFunc) NULL,
130 (GBaseFinalizeFunc) NULL,
131 (GClassInitFunc) gdk_drawable_impl_win32_class_init,
132 NULL, /* class_finalize */
133 NULL, /* class_data */
134 sizeof (GdkDrawableImplWin32),
136 (GInstanceInitFunc) NULL,
139 object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
140 "GdkDrawableImplWin32",
148 gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass)
150 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
152 parent_class = g_type_class_peek_parent (klass);
154 drawable_class->create_gc = _gdk_win32_gc_new;
155 drawable_class->draw_rectangle = gdk_win32_draw_rectangle;
156 drawable_class->draw_arc = gdk_win32_draw_arc;
157 drawable_class->draw_polygon = gdk_win32_draw_polygon;
158 drawable_class->draw_text = gdk_win32_draw_text;
159 drawable_class->draw_text_wc = gdk_win32_draw_text_wc;
160 drawable_class->draw_drawable = gdk_win32_draw_drawable;
161 drawable_class->draw_points = gdk_win32_draw_points;
162 drawable_class->draw_segments = gdk_win32_draw_segments;
163 drawable_class->draw_lines = gdk_win32_draw_lines;
164 drawable_class->draw_glyphs = gdk_win32_draw_glyphs;
165 drawable_class->draw_image = gdk_win32_draw_image;
167 drawable_class->set_colormap = gdk_win32_set_colormap;
168 drawable_class->get_colormap = gdk_win32_get_colormap;
170 drawable_class->get_depth = gdk_win32_get_depth;
171 drawable_class->get_visual = gdk_win32_get_visual;
173 drawable_class->get_image = _gdk_win32_get_image;
176 /*****************************************************
177 * Win32 specific implementations of generic functions *
178 *****************************************************/
181 gdk_win32_get_colormap (GdkDrawable *drawable)
183 GdkDrawableImplWin32 *impl;
185 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
187 return impl->colormap;
191 gdk_win32_set_colormap (GdkDrawable *drawable,
192 GdkColormap *colormap)
194 GdkDrawableImplWin32 *impl;
196 g_return_if_fail (colormap != NULL);
198 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
200 if (impl->colormap == colormap)
204 gdk_colormap_unref (impl->colormap);
205 impl->colormap = colormap;
207 gdk_colormap_ref (impl->colormap);
214 gdk_win32_draw_rectangle (GdkDrawable *drawable,
222 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
223 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
225 HGDIOBJ old_pen_or_brush;
229 GDK_NOTE (MISC, g_print ("gdk_win32_draw_rectangle: %#x (%p) %s%dx%d@+%d+%d\n",
230 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
232 (filled ? "fill " : ""),
233 width, height, x, y));
236 && (gc_private->tile)
237 && (gc_private->values_mask & GDK_GC_TILE)
238 && (gc_private->values_mask & GDK_GC_FILL))
240 _gdk_win32_draw_tiles (drawable, gc, gc_private->tile, x, y, width, height);
244 hdc = gdk_win32_hdc_get (drawable, gc, mask);
248 HBRUSH hbr = GetCurrentObject (hdc, OBJ_BRUSH);
249 HPEN hpen = GetCurrentObject (hdc, OBJ_PEN);
252 GetObject (hbr, sizeof (lbr), &lbr);
253 GetObject (hpen, sizeof (lpen), &lpen);
255 g_print ("current brush: style = %s, color = 0x%.08x\n",
256 (lbr.lbStyle == BS_SOLID ? "SOLID" : "???"),
258 g_print ("current pen: style = %s, width = %d, color = 0x%.08x\n",
259 (lpen.lopnStyle == PS_SOLID ? "SOLID" : "???"),
265 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
267 if (!BeginPath (hdc))
268 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
270 /* Win9x doesn't support Rectangle calls in a path,
276 pts[1].x = x + width + 1;
278 pts[2].x = x + width + 1;
279 pts[2].y = y + height + 1;
281 pts[3].y = y + height + 1;
284 MoveToEx (hdc, x, y, NULL);
286 if (ok && !Polyline (hdc, pts, 4))
287 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
289 if (ok && !CloseFigure (hdc))
290 WIN32_GDI_FAILED ("CloseFigure"), ok = FALSE;
292 if (ok && !EndPath (hdc))
293 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
296 if (!WidenPath (hdc))
297 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
299 if (ok && !FillPath (hdc))
300 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
305 old_pen_or_brush = SelectObject (hdc, GetStockObject (NULL_PEN));
307 old_pen_or_brush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
309 if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
310 WIN32_GDI_FAILED ("Rectangle");
312 SelectObject (hdc, old_pen_or_brush);
315 gdk_win32_hdc_release (drawable, gc, mask);
319 gdk_win32_draw_arc (GdkDrawable *drawable,
329 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
331 int nXStartArc, nYStartArc, nXEndArc, nYEndArc;
333 GDK_NOTE (MISC, g_print ("gdk_draw_arc: %#x %d,%d,%d,%d %d %d\n",
334 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
335 x, y, width, height, angle1, angle2));
337 /* Seems that drawing arcs with width or height <= 2 fails, at least
340 if (width <= 2 || height <= 2 || angle2 == 0)
343 hdc = gdk_win32_hdc_get (drawable, gc, mask);
345 if (angle2 >= 360*64)
347 nXStartArc = nYStartArc = nXEndArc = nYEndArc = 0;
351 /* The 100. is just an arbitrary value */
352 nXStartArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
353 nYStartArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
354 nXEndArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
355 nYEndArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
359 nXEndArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
360 nYEndArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
361 nXStartArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
362 nYStartArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
365 /* GDK_OPAQUE_STIPPLED arcs not implemented. */
369 GDK_NOTE (MISC, g_print ("...Pie(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
370 x, y, x+width, y+height,
371 nXStartArc, nYStartArc,
372 nXEndArc, nYEndArc));
373 if (!Pie (hdc, x, y, x+width, y+height,
374 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
375 WIN32_GDI_FAILED ("Pie");
379 GDK_NOTE (MISC, g_print ("...Arc(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
380 x, y, x+width, y+height,
381 nXStartArc, nYStartArc,
382 nXEndArc, nYEndArc));
383 if (!Arc (hdc, x, y, x+width, y+height,
384 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
385 WIN32_GDI_FAILED ("Arc");
387 gdk_win32_hdc_release (drawable, gc, mask);
391 gdk_win32_draw_polygon (GdkDrawable *drawable,
397 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
398 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
404 GDK_NOTE (MISC, g_print ("gdk_win32_draw_polygon: %#x (%p) %d\n",
405 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
412 hdc = gdk_win32_hdc_get (drawable, gc, mask);
413 pts = g_new (POINT, npoints+1);
415 for (i = 0; i < npoints; i++)
417 pts[i].x = points[i].x;
418 pts[i].y = points[i].y;
421 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
423 if (!BeginPath (hdc))
424 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
427 MoveToEx (hdc, points[0].x, points[0].y, NULL);
429 if (pts[0].x == pts[npoints-1].x && pts[0].y == pts[npoints-1].y)
432 if (ok && !Polyline (hdc, pts, 4))
433 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
435 if (ok && !CloseFigure (hdc))
436 WIN32_GDI_FAILED ("CloseFigure"), ok = FALSE;
438 if (ok && !EndPath (hdc))
439 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
442 if (!WidenPath (hdc))
443 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
445 if (ok && !FillPath (hdc))
446 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
450 if (points[0].x != points[npoints-1].x
451 || points[0].y != points[npoints-1].y)
453 pts[npoints].x = points[0].x;
454 pts[npoints].y = points[0].y;
460 if (!Polygon (hdc, pts, npoints))
461 WIN32_GDI_FAILED ("Polygon");
465 if (!Polyline (hdc, pts, npoints))
466 WIN32_GDI_FAILED ("Polyline");
470 gdk_win32_hdc_release (drawable, gc, mask);
480 gdk_draw_text_handler (GdkWin32SingleFont *singlefont,
481 const wchar_t *wcstr,
487 gdk_draw_text_arg *argp = (gdk_draw_text_arg *) arg;
492 if ((oldfont = SelectObject (argp->hdc, singlefont->hfont)) == NULL)
494 WIN32_GDI_FAILED ("SelectObject");
498 if (!TextOutW (argp->hdc, argp->x, argp->y, wcstr, wclen))
499 WIN32_GDI_FAILED ("TextOutW");
500 GetTextExtentPoint32W (argp->hdc, wcstr, wclen, &size);
503 SelectObject (argp->hdc, oldfont);
507 gdk_win32_draw_text (GdkDrawable *drawable,
515 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;
518 gdk_draw_text_arg arg;
520 if (text_length == 0)
523 g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
527 arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);
529 GDK_NOTE (MISC, g_print ("gdk_draw_text: %#x (%d,%d) \"%.*s\" (len %d)\n",
530 (guint) GDK_DRAWABLE_HANDLE (drawable),
532 (text_length > 10 ? 10 : text_length),
535 if (text_length == 1)
537 /* For single characters, don't try to interpret as UTF-8. */
538 wc = (guchar) text[0];
539 _gdk_wchar_text_handle (font, &wc, 1, gdk_draw_text_handler, &arg);
543 wcstr = g_new (wchar_t, text_length);
544 if ((wlen = _gdk_win32_nmbstowchar_ts (wcstr, text, text_length, text_length)) == -1)
545 g_warning ("gdk_win32_draw_text: _gdk_win32_nmbstowchar_ts failed");
547 _gdk_wchar_text_handle (font, wcstr, wlen, gdk_draw_text_handler, &arg);
552 gdk_win32_hdc_release (drawable, gc, mask);
556 gdk_win32_draw_text_wc (GdkDrawable *drawable,
561 const GdkWChar *text,
564 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;
567 gdk_draw_text_arg arg;
569 if (text_length == 0)
572 g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
576 arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);
578 GDK_NOTE (MISC, g_print ("gdk_draw_text_wc: %#x (%d,%d) len: %d\n",
579 (guint) GDK_DRAWABLE_HANDLE (drawable),
582 if (sizeof (wchar_t) != sizeof (GdkWChar))
584 wcstr = g_new (wchar_t, text_length);
585 for (i = 0; i < text_length; i++)
589 wcstr = (wchar_t *) text;
591 _gdk_wchar_text_handle (font, wcstr, text_length,
592 gdk_draw_text_handler, &arg);
594 if (sizeof (wchar_t) != sizeof (GdkWChar))
597 gdk_win32_hdc_release (drawable, gc, mask);
601 gdk_win32_draw_drawable (GdkDrawable *drawable,
614 HRGN src_rgn, draw_rgn, outside_rgn;
616 gint src_width, src_height;
618 GdkDrawableImplWin32 *impl;
621 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
622 if (GDK_IS_DRAWABLE_IMPL_WIN32(src))
623 src_handle = GDK_DRAWABLE_IMPL_WIN32 (src)->handle;
625 src_handle = GDK_DRAWABLE_HANDLE (src);
627 GDK_NOTE (MISC, g_print ("gdk_win32_draw_drawable: dest: %#x @+%d+%d"
628 " src: %#x %dx%d@+%d+%d\n",
629 (guint) impl->handle,
632 width, height, xsrc, ysrc));
634 hdc = gdk_win32_hdc_get (drawable, gc, 0);
636 gdk_drawable_get_size (src, &src_width, &src_height);
637 src_rgn = CreateRectRgn (0, 0, src_width + 1, src_height + 1);
638 draw_rgn = CreateRectRgn (xsrc, ysrc, xsrc + width + 1, ysrc + height + 1);
640 #if 0 /* HB: I dont't see reason to do this ... */
641 if (GDK_IS_WINDOW_IMPL_WIN32 (drawable))
643 /* If we are drawing on a window, calculate the region that is
644 * outside the source pixmap, and invalidate that, causing it to
648 outside_rgn = CreateRectRgnIndirect (&r);
649 if (CombineRgn (outside_rgn, draw_rgn, src_rgn, RGN_DIFF) != NULLREGION)
651 if (ERROR == OffsetRgn (outside_rgn, xdest, ydest))
652 WIN32_GDI_FAILED ("OffsetRgn");
653 GDK_NOTE (MISC, (GetRgnBox (outside_rgn, &r),
654 g_print ("...calling InvalidateRgn, "
655 "bbox: %ldx%ld@+%ld+%ld\n",
656 r.right - r.left - 1, r.bottom - r.top - 1,
658 if (!InvalidateRgn (impl->handle, outside_rgn, TRUE))
659 WIN32_GDI_FAILED ("InvalidateRgn");
661 if (!DeleteObject (outside_rgn))
662 WIN32_GDI_FAILED ("DeleteObject");
666 #if 1 /* Don't know if this is necessary */
667 if (CombineRgn (draw_rgn, draw_rgn, src_rgn, RGN_AND) == COMPLEXREGION)
668 g_warning ("gdk_win32_draw_drawable: CombineRgn returned a COMPLEXREGION");
670 if (0 == GetRgnBox (draw_rgn, &r))
671 WIN32_GDI_FAILED("GetRgnBox");
674 || r.right != xsrc + width + 1
675 || r.bottom != ysrc + height + 1)
677 xdest += r.left - xsrc;
679 ydest += r.top - ysrc;
681 width = r.right - xsrc - 1;
682 height = r.bottom - ysrc - 1;
684 GDK_NOTE (MISC, g_print ("... restricted to src: %dx%d@+%d+%d, "
686 width, height, xsrc, ysrc,
691 if (!DeleteObject (src_rgn))
692 WIN32_GDI_FAILED ("DeleteObject");
693 if (!DeleteObject (draw_rgn))
694 WIN32_GDI_FAILED ("DeleteObject");
696 /* This function is called also to bitblt from a window.
698 if (GDK_IS_PIXMAP_IMPL_WIN32 (src) || GDK_IS_PIXMAP(src))
700 if ((srcdc = CreateCompatibleDC (hdc)) == NULL)
701 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
703 if (ok && (hgdiobj = SelectObject (srcdc, src_handle)) == NULL)
704 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
706 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
707 srcdc, xsrc, ysrc, SRCCOPY))
708 WIN32_GDI_FAILED ("BitBlt");
710 if (ok && (SelectObject (srcdc, hgdiobj) == NULL))
711 WIN32_GDI_FAILED ("SelectObject");
713 if (srcdc != NULL && !DeleteDC (srcdc))
714 WIN32_GDI_FAILED ("DeleteDC");
716 else if (impl->handle == src_handle)
718 /* Blitting inside a window, use ScrollDC */
719 RECT scrollRect, clipRect, emptyRect;
722 scrollRect.left = MIN (xsrc, xdest);
723 scrollRect.top = MIN (ysrc, ydest);
724 scrollRect.right = MAX (xsrc + width + 1, xdest + width + 1);
725 scrollRect.bottom = MAX (ysrc + height + 1, ydest + height + 1);
727 clipRect.left = xdest;
728 clipRect.top = ydest;
729 clipRect.right = xdest + width + 1;
730 clipRect.bottom = ydest + height + 1;
732 SetRectEmpty (&emptyRect);
733 updateRgn = CreateRectRgnIndirect (&emptyRect);
734 if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc,
735 &scrollRect, &clipRect,
737 WIN32_GDI_FAILED ("ScrollDC"), ok = FALSE;
738 if (ok && !InvalidateRgn (impl->handle, updateRgn, FALSE))
739 WIN32_GDI_FAILED ("InvalidateRgn"), ok = FALSE;
740 if (ok && !UpdateWindow (impl->handle))
741 WIN32_GDI_FAILED ("UpdateWindow");
742 if (!DeleteObject (updateRgn))
743 WIN32_GDI_FAILED ("DeleteObject");
747 if ((srcdc = GetDC (src_handle)) == NULL)
748 WIN32_GDI_FAILED ("GetDC"), ok = FALSE;
750 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
751 srcdc, xsrc, ysrc, SRCCOPY))
752 WIN32_GDI_FAILED ("BitBlt");
753 if (ok && !ReleaseDC (src_handle, srcdc))
754 WIN32_GDI_FAILED ("ReleaseDC");
756 gdk_win32_hdc_release (drawable, gc, 0);
760 _gdk_win32_draw_tiles (GdkDrawable *drawable,
768 gint x = x_from, y = y_from;
769 gint tile_width, tile_height;
772 gdk_drawable_get_size (drawable, &width, &height);
773 gdk_drawable_get_size (tile, &tile_width, &tile_height);
775 width = MIN (width, max_width);
776 height = MIN (height, max_height);
778 tile_width = MIN (tile_width, max_width);
779 tile_height = MIN (tile_height, max_height);
786 gdk_win32_draw_drawable (drawable, gc, tile,
787 x % tile_width, /* xsrc */
788 y % tile_height, /* ysrc */
790 tile_width, tile_height);
798 gdk_win32_draw_points (GdkDrawable *drawable,
805 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
806 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
809 hdc = gdk_win32_hdc_get (drawable, gc, 0);
811 fg = _gdk_win32_colormap_color (impl->colormap, gc_private->foreground);
813 GDK_NOTE (MISC, g_print ("gdk_draw_points: %#x %dx%.06x\n",
814 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
815 npoints, (guint) fg));
817 for (i = 0; i < npoints; i++)
818 SetPixel (hdc, points[i].x, points[i].y, fg);
820 gdk_win32_hdc_release (drawable, gc, 0);
824 gdk_win32_draw_segments (GdkDrawable *drawable,
829 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
830 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
835 GDK_NOTE (MISC, g_print ("gdk_win32_draw_segments: %#x nsegs: %d\n",
836 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle, nsegs));
838 hdc = gdk_win32_hdc_get (drawable, gc, mask);
840 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
842 if (!BeginPath (hdc))
843 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
845 for (i = 0; ok && i < nsegs; i++)
847 if (ok && !MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
848 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
849 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
850 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
853 if (ok && gc_private->pen_width <= 1)
854 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
855 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
858 if (ok && !EndPath (hdc))
859 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
861 if (ok && !WidenPath (hdc))
862 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
864 if (ok && !FillPath (hdc))
865 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
869 const gboolean maybe_patblt =
870 gc_private->rop2 == R2_COPYPEN &&
871 gc_private->pen_width <= 1 &&
872 (gc_private->pen_style & PS_STYLE_MASK) == PS_SOLID;
874 for (i = 0; ok && i < nsegs; i++)
876 /* PatBlt() is much faster than LineTo(), says
877 * jpe@archaeopteryx.com. Hmm. Use it if we have a solid
878 * colour pen, then we know that the brush is also solid and
879 * of the same colour.
881 if (maybe_patblt && segs[i].x1 == segs[i].x2)
885 if (segs[i].y1 <= segs[i].y2)
886 y1 = segs[i].y1, y2 = segs[i].y2;
888 y1 = segs[i].y2, y2 = segs[i].y1;
890 if (!PatBlt (hdc, segs[i].x1, y1,
891 1, y2 - y1 + 1, PATCOPY))
892 WIN32_GDI_FAILED ("PatBlt"), ok = FALSE;
894 else if (maybe_patblt && segs[i].y1 == segs[i].y2)
898 if (segs[i].x1 <= segs[i].x2)
899 x1 = segs[i].x1, x2 = segs[i].x2;
901 x1 = segs[i].x2, x2 = segs[i].x1;
903 if (!PatBlt (hdc, x1, segs[i].y1,
904 x2 - x1 + 1, 1, PATCOPY))
905 WIN32_GDI_FAILED ("PatBlt"), ok = FALSE;
909 if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
910 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
911 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
912 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
915 if (ok && gc_private->pen_width <= 1)
916 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
917 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
921 gdk_win32_hdc_release (drawable, gc, mask);
925 gdk_win32_draw_lines (GdkDrawable *drawable,
930 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
931 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
940 hdc = gdk_win32_hdc_get (drawable, gc, mask);
942 pts = g_new (POINT, npoints);
944 for (i = 0; i < npoints; i++)
946 pts[i].x = points[i].x;
947 pts[i].y = points[i].y;
950 if (!Polyline (hdc, pts, npoints))
951 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
956 if (ok && gc_private->pen_width <= 1)
958 MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
959 if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
960 WIN32_GDI_FAILED ("LineTo");
962 gdk_win32_hdc_release (drawable, gc, mask);
966 gdk_win32_draw_glyphs (GdkDrawable *drawable,
971 PangoGlyphString *glyphs)
973 const GdkGCValuesMask mask = GDK_GC_FOREGROUND;
976 hdc = gdk_win32_hdc_get (drawable, gc, mask);
978 /* HB: Maybe there should be a GDK_GC_PANGO flag for hdc_get */
979 /* default write mode is transparent (leave background) */
980 if (SetBkMode (hdc, TRANSPARENT) == 0)
981 WIN32_GDI_FAILED ("SetBkMode");
983 if (GDI_ERROR == SetTextAlign (hdc, TA_LEFT|TA_BASELINE|TA_NOUPDATECP))
984 WIN32_GDI_FAILED ("SetTextAlign");
986 pango_win32_render (hdc, font, glyphs, x, y);
988 gdk_win32_hdc_release (drawable, gc, mask);
992 gdk_win32_draw_image (GdkDrawable *drawable,
1002 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
1003 GdkImagePrivateWin32 *image_private = IMAGE_PRIVATE_DATA (image);
1004 GdkColormapPrivateWin32 *colormap_private = (GdkColormapPrivateWin32 *) impl->colormap;
1009 BITMAPINFOHEADER bmiHeader;
1010 WORD bmiIndices[256];
1012 static gboolean bmi_inited = FALSE;
1016 hdc = gdk_win32_hdc_get (drawable, gc, 0);
1018 if (image->visual->type == GDK_VISUAL_PSEUDO_COLOR &&
1019 colormap_private && colormap_private->xcolormap->rc_palette)
1023 for (i = 0; i < 256; i++)
1024 bmi.bmiIndices[i] = i;
1028 if (GetObject (image_private->hbitmap, sizeof (DIBSECTION),
1029 &ds) != sizeof (DIBSECTION))
1030 WIN32_GDI_FAILED ("GetObject"), ok = FALSE;
1032 g_print("xdest = %d, ydest = %d, xsrc = %d, ysrc = %d, width = %d, height = %d\n",
1033 xdest, ydest, xsrc, ysrc, width, height);
1034 g_print("bmWidth = %d, bmHeight = %d, bmBitsPixel = %d, bmBits = %p\n",
1035 ds.dsBm.bmWidth, ds.dsBm.bmHeight, ds.dsBm.bmBitsPixel, ds.dsBm.bmBits);
1036 g_print("biWidth = %d, biHeight = %d, biBitCount = %d, biClrUsed = %d\n",
1037 ds.dsBmih.biWidth, ds.dsBmih.biHeight, ds.dsBmih.biBitCount, ds.dsBmih.biClrUsed);
1039 bmi.bmiHeader = ds.dsBmih;
1040 /* I have spent hours on getting the parameters to
1041 * SetDIBitsToDevice right. I wonder what drugs the guys in
1042 * Redmond were on when they designed this API.
1044 if (ok && SetDIBitsToDevice (hdc,
1047 xsrc, (-ds.dsBmih.biHeight)-height-ysrc,
1048 0, -ds.dsBmih.biHeight,
1050 (CONST BITMAPINFO *) &bmi,
1051 DIB_PAL_COLORS) == 0)
1052 WIN32_GDI_FAILED ("SetDIBitsToDevice");
1057 if ((memdc = CreateCompatibleDC (hdc)) == NULL)
1058 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
1060 if (ok && (oldbitmap = SelectObject (memdc, image_private->hbitmap)) == NULL)
1061 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
1063 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
1064 memdc, xsrc, ysrc, SRCCOPY))
1065 WIN32_GDI_FAILED ("BitBlt");
1067 if (oldbitmap != NULL && SelectObject (memdc, oldbitmap) == NULL)
1068 WIN32_GDI_FAILED ("SelectObject");
1070 if (memdc != NULL && !DeleteDC (memdc))
1071 WIN32_GDI_FAILED ("DeleteDC");
1073 gdk_win32_hdc_release (drawable, gc, 0);
1077 gdk_win32_get_depth (GdkDrawable *drawable)
1079 /* This is a bit bogus but I'm not sure the other way is better */
1081 return gdk_drawable_get_depth (GDK_DRAWABLE_IMPL_WIN32 (drawable)->wrapper);
1085 gdk_win32_get_visual (GdkDrawable *drawable)
1087 return gdk_drawable_get_visual (GDK_DRAWABLE_IMPL_WIN32 (drawable)->wrapper);
1091 gdk_win32_drawable_get_handle (GdkDrawable *drawable)
1093 return GDK_DRAWABLE_HANDLE(drawable);