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 "gdkinternals.h"
33 #include "gdkprivate-win32.h"
35 static void gdk_win32_draw_rectangle (GdkDrawable *drawable,
42 static void gdk_win32_draw_arc (GdkDrawable *drawable,
51 static void gdk_win32_draw_polygon (GdkDrawable *drawable,
56 static void gdk_win32_draw_text (GdkDrawable *drawable,
63 static void gdk_win32_draw_text_wc (GdkDrawable *drawable,
70 static void gdk_win32_draw_drawable (GdkDrawable *drawable,
79 static void gdk_win32_draw_points (GdkDrawable *drawable,
83 static void gdk_win32_draw_segments (GdkDrawable *drawable,
87 static void gdk_win32_draw_lines (GdkDrawable *drawable,
91 static void gdk_win32_draw_glyphs (GdkDrawable *drawable,
96 PangoGlyphString *glyphs);
97 static void gdk_win32_draw_image (GdkDrawable *drawable,
107 static void gdk_win32_set_colormap (GdkDrawable *drawable,
108 GdkColormap *colormap);
110 static GdkColormap* gdk_win32_get_colormap (GdkDrawable *drawable);
112 static gint gdk_win32_get_depth (GdkDrawable *drawable);
114 static GdkVisual* gdk_win32_get_visual (GdkDrawable *drawable);
116 static void gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass);
118 static gpointer parent_class = NULL;
121 gdk_drawable_impl_win32_get_type (void)
123 static GType object_type = 0;
127 static const GTypeInfo object_info =
129 sizeof (GdkDrawableImplWin32Class),
130 (GBaseInitFunc) NULL,
131 (GBaseFinalizeFunc) NULL,
132 (GClassInitFunc) gdk_drawable_impl_win32_class_init,
133 NULL, /* class_finalize */
134 NULL, /* class_data */
135 sizeof (GdkDrawableImplWin32),
137 (GInstanceInitFunc) NULL,
140 object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
141 "GdkDrawableImplWin32",
149 gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass)
151 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
153 parent_class = g_type_class_peek_parent (klass);
155 drawable_class->create_gc = _gdk_win32_gc_new;
156 drawable_class->draw_rectangle = gdk_win32_draw_rectangle;
157 drawable_class->draw_arc = gdk_win32_draw_arc;
158 drawable_class->draw_polygon = gdk_win32_draw_polygon;
159 drawable_class->draw_text = gdk_win32_draw_text;
160 drawable_class->draw_text_wc = gdk_win32_draw_text_wc;
161 drawable_class->draw_drawable = gdk_win32_draw_drawable;
162 drawable_class->draw_points = gdk_win32_draw_points;
163 drawable_class->draw_segments = gdk_win32_draw_segments;
164 drawable_class->draw_lines = gdk_win32_draw_lines;
165 drawable_class->draw_glyphs = gdk_win32_draw_glyphs;
166 drawable_class->draw_image = gdk_win32_draw_image;
168 drawable_class->set_colormap = gdk_win32_set_colormap;
169 drawable_class->get_colormap = gdk_win32_get_colormap;
171 drawable_class->get_depth = gdk_win32_get_depth;
172 drawable_class->get_visual = gdk_win32_get_visual;
174 drawable_class->get_image = _gdk_win32_get_image;
177 /*****************************************************
178 * Win32 specific implementations of generic functions *
179 *****************************************************/
182 gdk_win32_get_colormap (GdkDrawable *drawable)
184 GdkDrawableImplWin32 *impl;
186 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
188 return impl->colormap;
192 gdk_win32_set_colormap (GdkDrawable *drawable,
193 GdkColormap *colormap)
195 GdkDrawableImplWin32 *impl;
197 g_return_if_fail (colormap != NULL);
199 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
201 if (impl->colormap == colormap)
205 gdk_colormap_unref (impl->colormap);
206 impl->colormap = colormap;
208 gdk_colormap_ref (impl->colormap);
215 gdk_win32_draw_rectangle (GdkDrawable *drawable,
223 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
224 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
226 HGDIOBJ old_pen_or_brush;
230 GDK_NOTE (MISC, g_print ("gdk_win32_draw_rectangle: %#x (%p) %s%dx%d@+%d+%d\n",
231 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
233 (filled ? "fill " : ""),
234 width, height, x, y));
237 && (gc_private->tile)
238 && (gc_private->values_mask & GDK_GC_TILE)
239 && (gc_private->values_mask & GDK_GC_FILL))
241 gdk_win32_draw_tiles (drawable, gc, gc_private->tile, x, y, width, height);
245 hdc = gdk_win32_hdc_get (drawable, gc, mask);
249 HBRUSH hbr = GetCurrentObject (hdc, OBJ_BRUSH);
250 HPEN hpen = GetCurrentObject (hdc, OBJ_PEN);
253 GetObject (hbr, sizeof (lbr), &lbr);
254 GetObject (hpen, sizeof (lpen), &lpen);
256 g_print ("current brush: style = %s, color = 0x%.08x\n",
257 (lbr.lbStyle == BS_SOLID ? "SOLID" : "???"),
259 g_print ("current pen: style = %s, width = %d, color = 0x%.08x\n",
260 (lpen.lopnStyle == PS_SOLID ? "SOLID" : "???"),
266 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
268 if (!BeginPath (hdc))
269 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
271 /* Win9x doesn't support Rectangle calls in a path,
277 pts[1].x = x + width + 1;
279 pts[2].x = x + width + 1;
280 pts[2].y = y + height + 1;
282 pts[3].y = y + height + 1;
285 MoveToEx (hdc, x, y, NULL);
287 if (ok && !Polyline (hdc, pts, 4))
288 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
290 if (ok && !CloseFigure (hdc))
291 WIN32_GDI_FAILED ("CloseFigure"), ok = FALSE;
293 if (ok && !EndPath (hdc))
294 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
297 if (!WidenPath (hdc))
298 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
300 if (ok && !FillPath (hdc))
301 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
306 old_pen_or_brush = SelectObject (hdc, GetStockObject (NULL_PEN));
308 old_pen_or_brush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
310 if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
311 WIN32_GDI_FAILED ("Rectangle");
313 SelectObject (hdc, old_pen_or_brush);
316 gdk_win32_hdc_release (drawable, gc, mask);
320 gdk_win32_draw_arc (GdkDrawable *drawable,
330 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
332 int nXStartArc, nYStartArc, nXEndArc, nYEndArc;
334 GDK_NOTE (MISC, g_print ("gdk_draw_arc: %#x %d,%d,%d,%d %d %d\n",
335 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
336 x, y, width, height, angle1, angle2));
338 /* Seems that drawing arcs with width or height <= 2 fails, at least
341 if (width <= 2 || height <= 2 || angle2 == 0)
344 hdc = gdk_win32_hdc_get (drawable, gc, mask);
346 if (angle2 >= 360*64)
348 nXStartArc = nYStartArc = nXEndArc = nYEndArc = 0;
352 /* The 100. is just an arbitrary value */
353 nXStartArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
354 nYStartArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
355 nXEndArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
356 nYEndArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
360 nXEndArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
361 nYEndArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
362 nXStartArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
363 nYStartArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
366 /* GDK_OPAQUE_STIPPLED arcs not implemented. */
370 GDK_NOTE (MISC, g_print ("...Pie(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
371 x, y, x+width, y+height,
372 nXStartArc, nYStartArc,
373 nXEndArc, nYEndArc));
374 if (!Pie (hdc, x, y, x+width, y+height,
375 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
376 WIN32_GDI_FAILED ("Pie");
380 GDK_NOTE (MISC, g_print ("...Arc(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
381 x, y, x+width, y+height,
382 nXStartArc, nYStartArc,
383 nXEndArc, nYEndArc));
384 if (!Arc (hdc, x, y, x+width, y+height,
385 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
386 WIN32_GDI_FAILED ("Arc");
388 gdk_win32_hdc_release (drawable, gc, mask);
392 gdk_win32_draw_polygon (GdkDrawable *drawable,
398 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
399 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
405 GDK_NOTE (MISC, g_print ("gdk_win32_draw_polygon: %#x (%p) %d\n",
406 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
413 hdc = gdk_win32_hdc_get (drawable, gc, mask);
414 pts = g_new (POINT, npoints+1);
416 for (i = 0; i < npoints; i++)
418 pts[i].x = points[i].x;
419 pts[i].y = points[i].y;
422 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
424 if (!BeginPath (hdc))
425 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
428 MoveToEx (hdc, points[0].x, points[0].y, NULL);
430 if (pts[0].x == pts[npoints-1].x && pts[0].y == pts[npoints-1].y)
433 if (ok && !Polyline (hdc, pts, 4))
434 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
436 if (ok && !CloseFigure (hdc))
437 WIN32_GDI_FAILED ("CloseFigure"), ok = FALSE;
439 if (ok && !EndPath (hdc))
440 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
443 if (!WidenPath (hdc))
444 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
446 if (ok && !FillPath (hdc))
447 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
451 if (points[0].x != points[npoints-1].x
452 || points[0].y != points[npoints-1].y)
454 pts[npoints].x = points[0].x;
455 pts[npoints].y = points[0].y;
461 if (!Polygon (hdc, pts, npoints))
462 WIN32_GDI_FAILED ("Polygon");
466 if (!Polyline (hdc, pts, npoints))
467 WIN32_GDI_FAILED ("Polyline");
471 gdk_win32_hdc_release (drawable, gc, mask);
481 gdk_draw_text_handler (GdkWin32SingleFont *singlefont,
482 const wchar_t *wcstr,
488 gdk_draw_text_arg *argp = (gdk_draw_text_arg *) arg;
493 if ((oldfont = SelectObject (argp->hdc, singlefont->hfont)) == NULL)
495 WIN32_GDI_FAILED ("SelectObject");
499 if (!TextOutW (argp->hdc, argp->x, argp->y, wcstr, wclen))
500 WIN32_GDI_FAILED ("TextOutW");
501 GetTextExtentPoint32W (argp->hdc, wcstr, wclen, &size);
504 SelectObject (argp->hdc, oldfont);
508 gdk_win32_draw_text (GdkDrawable *drawable,
516 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;
519 gdk_draw_text_arg arg;
521 if (text_length == 0)
524 g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
528 arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);
530 GDK_NOTE (MISC, g_print ("gdk_draw_text: %#x (%d,%d) \"%.*s\" (len %d)\n",
531 (guint) GDK_DRAWABLE_HANDLE (drawable),
533 (text_length > 10 ? 10 : text_length),
536 if (text_length == 1)
538 /* For single characters, don't try to interpret as UTF-8. */
539 wc = (guchar) text[0];
540 gdk_wchar_text_handle (font, &wc, 1, gdk_draw_text_handler, &arg);
544 wcstr = g_new (wchar_t, text_length);
545 if ((wlen = gdk_nmbstowchar_ts (wcstr, text, text_length, text_length)) == -1)
546 g_warning ("gdk_win32_draw_text: gdk_nmbstowchar_ts failed");
548 gdk_wchar_text_handle (font, wcstr, wlen, gdk_draw_text_handler, &arg);
553 gdk_win32_hdc_release (drawable, gc, mask);
557 gdk_win32_draw_text_wc (GdkDrawable *drawable,
562 const GdkWChar *text,
565 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;
568 gdk_draw_text_arg arg;
570 if (text_length == 0)
573 g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
577 arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);
579 GDK_NOTE (MISC, g_print ("gdk_draw_text_wc: %#x (%d,%d) len: %d\n",
580 (guint) GDK_DRAWABLE_HANDLE (drawable),
583 if (sizeof (wchar_t) != sizeof (GdkWChar))
585 wcstr = g_new (wchar_t, text_length);
586 for (i = 0; i < text_length; i++)
590 wcstr = (wchar_t *) text;
592 gdk_wchar_text_handle (font, wcstr, text_length,
593 gdk_draw_text_handler, &arg);
595 if (sizeof (wchar_t) != sizeof (GdkWChar))
598 gdk_win32_hdc_release (drawable, gc, mask);
602 gdk_win32_draw_drawable (GdkDrawable *drawable,
615 HRGN src_rgn, draw_rgn, outside_rgn;
617 gint src_width, src_height;
619 GdkDrawableImplWin32 *impl;
622 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
623 if (GDK_IS_DRAWABLE_IMPL_WIN32(src))
624 src_handle = GDK_DRAWABLE_IMPL_WIN32 (src)->handle;
626 src_handle = GDK_DRAWABLE_HANDLE (src);
628 GDK_NOTE (MISC, g_print ("gdk_win32_draw_drawable: dest: %#x @+%d+%d"
629 " src: %#x %dx%d@+%d+%d\n",
630 (guint) impl->handle,
633 width, height, xsrc, ysrc));
635 hdc = gdk_win32_hdc_get (drawable, gc, 0);
637 gdk_drawable_get_size (src, &src_width, &src_height);
638 src_rgn = CreateRectRgn (0, 0, src_width + 1, src_height + 1);
639 draw_rgn = CreateRectRgn (xsrc, ysrc, xsrc + width + 1, ysrc + height + 1);
641 #if 0 /* HB: I dont't see reason to do this ... */
642 if (GDK_IS_WINDOW_IMPL_WIN32 (drawable))
644 /* If we are drawing on a window, calculate the region that is
645 * outside the source pixmap, and invalidate that, causing it to
649 outside_rgn = CreateRectRgnIndirect (&r);
650 if (CombineRgn (outside_rgn, draw_rgn, src_rgn, RGN_DIFF) != NULLREGION)
652 if (ERROR == OffsetRgn (outside_rgn, xdest, ydest))
653 WIN32_GDI_FAILED ("OffsetRgn");
654 GDK_NOTE (MISC, (GetRgnBox (outside_rgn, &r),
655 g_print ("...calling InvalidateRgn, "
656 "bbox: %ldx%ld@+%ld+%ld\n",
657 r.right - r.left - 1, r.bottom - r.top - 1,
659 if (!InvalidateRgn (impl->handle, outside_rgn, TRUE))
660 WIN32_GDI_FAILED ("InvalidateRgn");
662 if (!DeleteObject (outside_rgn))
663 WIN32_GDI_FAILED ("DeleteObject");
667 #if 1 /* Don't know if this is necessary */
668 if (CombineRgn (draw_rgn, draw_rgn, src_rgn, RGN_AND) == COMPLEXREGION)
669 g_warning ("gdk_win32_draw_drawable: CombineRgn returned a COMPLEXREGION");
671 if (0 == GetRgnBox (draw_rgn, &r))
672 WIN32_GDI_FAILED("GetRgnBox");
675 || r.right != xsrc + width + 1
676 || r.bottom != ysrc + height + 1)
678 xdest += r.left - xsrc;
680 ydest += r.top - ysrc;
682 width = r.right - xsrc - 1;
683 height = r.bottom - ysrc - 1;
685 GDK_NOTE (MISC, g_print ("... restricted to src: %dx%d@+%d+%d, "
687 width, height, xsrc, ysrc,
692 if (!DeleteObject (src_rgn))
693 WIN32_GDI_FAILED ("DeleteObject");
694 if (!DeleteObject (draw_rgn))
695 WIN32_GDI_FAILED ("DeleteObject");
697 /* This function is called also to bitblt from a window.
699 if (GDK_IS_PIXMAP_IMPL_WIN32 (src) || GDK_IS_PIXMAP(src))
701 if ((srcdc = CreateCompatibleDC (hdc)) == NULL)
702 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
704 if (ok && (hgdiobj = SelectObject (srcdc, src_handle)) == NULL)
705 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
707 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
708 srcdc, xsrc, ysrc, SRCCOPY))
709 WIN32_GDI_FAILED ("BitBlt");
711 if (ok && (SelectObject (srcdc, hgdiobj) == NULL))
712 WIN32_GDI_FAILED ("SelectObject");
714 if (srcdc != NULL && !DeleteDC (srcdc))
715 WIN32_GDI_FAILED ("DeleteDC");
717 else if (impl->handle == src_handle)
719 /* Blitting inside a window, use ScrollDC */
720 RECT scrollRect, clipRect, emptyRect;
723 scrollRect.left = MIN (xsrc, xdest);
724 scrollRect.top = MIN (ysrc, ydest);
725 scrollRect.right = MAX (xsrc + width + 1, xdest + width + 1);
726 scrollRect.bottom = MAX (ysrc + height + 1, ydest + height + 1);
728 clipRect.left = xdest;
729 clipRect.top = ydest;
730 clipRect.right = xdest + width + 1;
731 clipRect.bottom = ydest + height + 1;
733 SetRectEmpty (&emptyRect);
734 updateRgn = CreateRectRgnIndirect (&emptyRect);
735 if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc,
736 &scrollRect, &clipRect,
738 WIN32_GDI_FAILED ("ScrollDC"), ok = FALSE;
739 if (ok && !InvalidateRgn (impl->handle, updateRgn, FALSE))
740 WIN32_GDI_FAILED ("InvalidateRgn"), ok = FALSE;
741 if (ok && !UpdateWindow (impl->handle))
742 WIN32_GDI_FAILED ("UpdateWindow");
743 if (!DeleteObject (updateRgn))
744 WIN32_GDI_FAILED ("DeleteObject");
748 if ((srcdc = GetDC (src_handle)) == NULL)
749 WIN32_GDI_FAILED ("GetDC"), ok = FALSE;
751 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
752 srcdc, xsrc, ysrc, SRCCOPY))
753 WIN32_GDI_FAILED ("BitBlt");
754 if (ok && !ReleaseDC (src_handle, srcdc))
755 WIN32_GDI_FAILED ("ReleaseDC");
757 gdk_win32_hdc_release (drawable, gc, 0);
761 gdk_win32_draw_tiles (GdkDrawable *drawable,
769 gint x = x_from, y = y_from;
770 gint tile_width, tile_height;
773 gdk_drawable_get_size (drawable, &width, &height);
774 gdk_drawable_get_size (tile, &tile_width, &tile_height);
776 width = MIN (width, max_width);
777 height = MIN (height, max_height);
779 tile_width = MIN (tile_width, max_width);
780 tile_height = MIN (tile_height, max_height);
787 gdk_win32_draw_drawable (drawable, gc, tile,
788 x % tile_width, /* xsrc */
789 y % tile_height, /* ysrc */
791 tile_width, tile_height);
799 gdk_win32_draw_points (GdkDrawable *drawable,
806 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
807 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
810 hdc = gdk_win32_hdc_get (drawable, gc, 0);
812 fg = gdk_colormap_color (impl->colormap, gc_private->foreground);
814 GDK_NOTE (MISC, g_print ("gdk_draw_points: %#x %dx%.06x\n",
815 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle,
816 npoints, (guint) fg));
818 for (i = 0; i < npoints; i++)
819 SetPixel (hdc, points[i].x, points[i].y, fg);
821 gdk_win32_hdc_release (drawable, gc, 0);
825 gdk_win32_draw_segments (GdkDrawable *drawable,
830 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
831 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
836 GDK_NOTE (MISC, g_print ("gdk_win32_draw_segments: %#x nsegs: %d\n",
837 (guint) GDK_DRAWABLE_IMPL_WIN32 (drawable)->handle, nsegs));
839 hdc = gdk_win32_hdc_get (drawable, gc, mask);
841 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
843 if (!BeginPath (hdc))
844 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
846 for (i = 0; ok && i < nsegs; i++)
848 if (ok && !MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
849 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
850 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
851 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
854 if (ok && gc_private->pen_width <= 1)
855 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
856 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
859 if (ok && !EndPath (hdc))
860 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
862 if (ok && !WidenPath (hdc))
863 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
865 if (ok && !FillPath (hdc))
866 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
870 for (i = 0; ok && i < nsegs; i++)
872 if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
873 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
874 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
875 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
878 if (ok && gc_private->pen_width <= 1)
879 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
880 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
883 gdk_win32_hdc_release (drawable, gc, mask);
887 gdk_win32_draw_lines (GdkDrawable *drawable,
892 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
893 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
902 hdc = gdk_win32_hdc_get (drawable, gc, mask);
904 pts = g_new (POINT, npoints);
906 for (i = 0; i < npoints; i++)
908 pts[i].x = points[i].x;
909 pts[i].y = points[i].y;
912 if (!Polyline (hdc, pts, npoints))
913 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
918 if (ok && gc_private->pen_width <= 1)
920 MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
921 if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
922 WIN32_GDI_FAILED ("LineTo");
924 gdk_win32_hdc_release (drawable, gc, mask);
928 gdk_win32_draw_glyphs (GdkDrawable *drawable,
933 PangoGlyphString *glyphs)
935 const GdkGCValuesMask mask = GDK_GC_FOREGROUND;
938 hdc = gdk_win32_hdc_get (drawable, gc, mask);
940 /* HB: Maybe there should be a GDK_GC_PANGO flag for hdc_get */
941 /* default write mode is transparent (leave background) */
942 if (SetBkMode (hdc, TRANSPARENT) == 0)
943 WIN32_GDI_FAILED ("SetBkMode");
945 if (GDI_ERROR == SetTextAlign (hdc, TA_LEFT|TA_BASELINE|TA_NOUPDATECP))
946 WIN32_GDI_FAILED ("SetTextAlign");
948 pango_win32_render (hdc, font, glyphs, x, y);
950 gdk_win32_hdc_release (drawable, gc, mask);
954 gdk_win32_draw_image (GdkDrawable *drawable,
964 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
965 GdkImagePrivateWin32 *image_private = IMAGE_PRIVATE_DATA (image);
966 GdkColormapPrivateWin32 *colormap_private = (GdkColormapPrivateWin32 *) impl->colormap;
971 BITMAPINFOHEADER bmiHeader;
972 WORD bmiIndices[256];
974 static gboolean bmi_inited = FALSE;
978 hdc = gdk_win32_hdc_get (drawable, gc, 0);
980 if (image->visual->type == GDK_VISUAL_PSEUDO_COLOR &&
981 colormap_private && colormap_private->xcolormap->rc_palette)
985 for (i = 0; i < 256; i++)
986 bmi.bmiIndices[i] = i;
990 if (GetObject (image_private->hbitmap, sizeof (DIBSECTION),
991 &ds) != sizeof (DIBSECTION))
992 WIN32_GDI_FAILED ("GetObject"), ok = FALSE;
994 g_print("xdest = %d, ydest = %d, xsrc = %d, ysrc = %d, width = %d, height = %d\n",
995 xdest, ydest, xsrc, ysrc, width, height);
996 g_print("bmWidth = %d, bmHeight = %d, bmBitsPixel = %d, bmBits = %p\n",
997 ds.dsBm.bmWidth, ds.dsBm.bmHeight, ds.dsBm.bmBitsPixel, ds.dsBm.bmBits);
998 g_print("biWidth = %d, biHeight = %d, biBitCount = %d, biClrUsed = %d\n",
999 ds.dsBmih.biWidth, ds.dsBmih.biHeight, ds.dsBmih.biBitCount, ds.dsBmih.biClrUsed);
1001 bmi.bmiHeader = ds.dsBmih;
1002 /* I have spent hours on getting the parameters to
1003 * SetDIBitsToDevice right. I wonder what drugs the guys in
1004 * Redmond were on when they designed this API.
1006 if (ok && SetDIBitsToDevice (hdc,
1009 xsrc, (-ds.dsBmih.biHeight)-height-ysrc,
1010 0, -ds.dsBmih.biHeight,
1012 (CONST BITMAPINFO *) &bmi,
1013 DIB_PAL_COLORS) == 0)
1014 WIN32_GDI_FAILED ("SetDIBitsToDevice");
1019 if ((memdc = CreateCompatibleDC (hdc)) == NULL)
1020 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
1022 if (ok && (oldbitmap = SelectObject (memdc, image_private->hbitmap)) == NULL)
1023 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
1025 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
1026 memdc, xsrc, ysrc, SRCCOPY))
1027 WIN32_GDI_FAILED ("BitBlt");
1029 if (oldbitmap != NULL && SelectObject (memdc, oldbitmap) == NULL)
1030 WIN32_GDI_FAILED ("SelectObject");
1032 if (memdc != NULL && !DeleteDC (memdc))
1033 WIN32_GDI_FAILED ("DeleteDC");
1035 gdk_win32_hdc_release (drawable, gc, 0);
1039 gdk_win32_get_depth (GdkDrawable *drawable)
1041 /* This is a bit bogus but I'm not sure the other way is better */
1043 return gdk_drawable_get_depth (GDK_DRAWABLE_IMPL_WIN32 (drawable)->wrapper);
1047 gdk_win32_get_visual (GdkDrawable *drawable)
1049 return gdk_drawable_get_visual (GDK_DRAWABLE_IMPL_WIN32 (drawable)->wrapper);