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 void gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass);
116 static gpointer parent_class = NULL;
119 gdk_drawable_impl_win32_get_type (void)
121 static GType object_type = 0;
125 static const GTypeInfo object_info =
127 sizeof (GdkDrawableImplWin32Class),
128 (GBaseInitFunc) NULL,
129 (GBaseFinalizeFunc) NULL,
130 (GClassInitFunc) gdk_drawable_impl_win32_class_init,
131 NULL, /* class_finalize */
132 NULL, /* class_data */
133 sizeof (GdkDrawableImplWin32),
135 (GInstanceInitFunc) NULL,
138 object_type = g_type_register_static (GDK_TYPE_DRAWABLE,
139 "GdkDrawableImplWin32",
147 gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass)
149 GdkDrawableClass *drawable_class = GDK_DRAWABLE_CLASS (klass);
151 parent_class = g_type_class_peek_parent (klass);
153 drawable_class->create_gc = _gdk_win32_gc_new;
154 drawable_class->draw_rectangle = gdk_win32_draw_rectangle;
155 drawable_class->draw_arc = gdk_win32_draw_arc;
156 drawable_class->draw_polygon = gdk_win32_draw_polygon;
157 drawable_class->draw_text = gdk_win32_draw_text;
158 drawable_class->draw_text_wc = gdk_win32_draw_text_wc;
159 drawable_class->draw_drawable = gdk_win32_draw_drawable;
160 drawable_class->draw_points = gdk_win32_draw_points;
161 drawable_class->draw_segments = gdk_win32_draw_segments;
162 drawable_class->draw_lines = gdk_win32_draw_lines;
163 drawable_class->draw_glyphs = gdk_win32_draw_glyphs;
164 drawable_class->draw_image = gdk_win32_draw_image;
166 drawable_class->set_colormap = gdk_win32_set_colormap;
167 drawable_class->get_colormap = gdk_win32_get_colormap;
169 drawable_class->get_depth = gdk_win32_get_depth;
172 /*****************************************************
173 * Win32 specific implementations of generic functions *
174 *****************************************************/
177 gdk_win32_get_colormap (GdkDrawable *drawable)
179 GdkDrawableImplWin32 *impl;
181 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
183 return impl->colormap;
187 gdk_win32_set_colormap (GdkDrawable *drawable,
188 GdkColormap *colormap)
190 GdkDrawableImplWin32 *impl;
192 g_return_if_fail (colormap != NULL);
194 impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
196 if (impl->colormap == colormap)
200 gdk_colormap_unref (impl->colormap);
201 impl->colormap = colormap;
203 gdk_colormap_ref (impl->colormap);
210 gdk_win32_draw_rectangle (GdkDrawable *drawable,
218 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
219 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
221 HGDIOBJ oldpen, oldbrush;
226 GDK_NOTE (MISC, g_print ("gdk_win32_draw_rectangle: %#x (%p) %s%dx%d@+%d+%d\n",
227 (guint) GDK_DRAWABLE_HANDLE (drawable),
229 (filled ? "fill " : ""),
230 width, height, x, y));
232 hdc = gdk_win32_hdc_get (drawable, gc, mask);
236 HBRUSH hbr = GetCurrentObject (hdc, OBJ_BRUSH);
237 HPEN hpen = GetCurrentObject (hdc, OBJ_PEN);
240 GetObject (hbr, sizeof (lbr), &lbr);
241 GetObject (hpen, sizeof (lpen), &lpen);
243 g_print ("current brush: style = %s, color = 0x%.08x\n",
244 (lbr.lbStyle == BS_SOLID ? "SOLID" : "???"),
246 g_print ("current pen: style = %s, width = %d, color = 0x%.08x\n",
247 (lpen.lopnStyle == PS_SOLID ? "SOLID" : "???"),
253 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
255 if (!BeginPath (hdc))
256 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
258 /* Win9x doesn't support Rectangle calls in a path,
264 pts[1].x = x + width + 1;
266 pts[2].x = x + width + 1;
267 pts[2].y = y + height + 1;
269 pts[3].y = y + height + 1;
272 MoveToEx (hdc, x, y, NULL);
274 if (ok && !Polyline (hdc, pts, 4))
275 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
277 if (ok && !CloseFigure (hdc))
278 WIN32_GDI_FAILED ("CloseFigure"), ok = FALSE;
280 if (ok && !EndPath (hdc))
281 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
284 if (!WidenPath (hdc))
285 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
287 if (ok && !FillPath (hdc))
288 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
291 if (!DeleteObject (hbr))
292 WIN32_GDI_FAILED ("DeleteObject");
297 oldpen = SelectObject (hdc, GetStockObject (NULL_PEN));
299 oldbrush = SelectObject (hdc, GetStockObject (HOLLOW_BRUSH));
301 if (!Rectangle (hdc, x, y, x+width+1, y+height+1))
302 WIN32_GDI_FAILED ("Rectangle");
305 SelectObject (hdc, oldpen);
307 SelectObject (hdc, oldbrush);
310 gdk_win32_hdc_release (drawable, gc, mask);
314 gdk_win32_draw_arc (GdkDrawable *drawable,
324 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
326 int nXStartArc, nYStartArc, nXEndArc, nYEndArc;
328 GDK_NOTE (MISC, g_print ("gdk_draw_arc: %#x %d,%d,%d,%d %d %d\n",
329 (guint) GDK_DRAWABLE_HANDLE (drawable),
330 x, y, width, height, angle1, angle2));
332 /* Seems that drawing arcs with width or height <= 2 fails, at least
335 if (width <= 2 || height <= 2 || angle2 == 0)
338 hdc = gdk_win32_hdc_get (drawable, gc, mask);
340 if (angle2 >= 360*64)
342 nXStartArc = nYStartArc = nXEndArc = nYEndArc = 0;
346 /* The 100. is just an arbitrary value */
347 nXStartArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
348 nYStartArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
349 nXEndArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
350 nYEndArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
354 nXEndArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
355 nYEndArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
356 nXStartArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
357 nYStartArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
360 /* GDK_OPAQUE_STIPPLED arcs not implemented. */
364 GDK_NOTE (MISC, g_print ("...Pie(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
365 x, y, x+width, y+height,
366 nXStartArc, nYStartArc,
367 nXEndArc, nYEndArc));
368 if (!Pie (hdc, x, y, x+width, y+height,
369 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
370 WIN32_GDI_FAILED ("Pie");
374 GDK_NOTE (MISC, g_print ("...Arc(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
375 x, y, x+width, y+height,
376 nXStartArc, nYStartArc,
377 nXEndArc, nYEndArc));
378 if (!Arc (hdc, x, y, x+width, y+height,
379 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
380 WIN32_GDI_FAILED ("Arc");
382 gdk_win32_hdc_release (drawable, gc, mask);
386 gdk_win32_draw_polygon (GdkDrawable *drawable,
392 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
393 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
400 GDK_NOTE (MISC, g_print ("gdk_win32_draw_polygon: %#x (%p) %d\n",
401 (guint) GDK_DRAWABLE_HANDLE (drawable),
408 hdc = gdk_win32_hdc_get (drawable, gc, mask);
409 pts = g_new (POINT, npoints+1);
411 for (i = 0; i < npoints; i++)
413 pts[i].x = points[i].x;
414 pts[i].y = points[i].y;
417 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
419 if (!BeginPath (hdc))
420 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
423 MoveToEx (hdc, points[0].x, points[0].y, NULL);
425 if (pts[0].x == pts[npoints-1].x && pts[0].y == pts[npoints-1].y)
428 if (ok && !Polyline (hdc, pts, 4))
429 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
431 if (ok && !CloseFigure (hdc))
432 WIN32_GDI_FAILED ("CloseFigure"), ok = FALSE;
434 if (ok && !EndPath (hdc))
435 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
438 if (!WidenPath (hdc))
439 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
441 if (ok && !FillPath (hdc))
442 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
445 if (!DeleteObject (hbr))
446 WIN32_GDI_FAILED ("DeleteObject");
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_nmbstowchar_ts (wcstr, text, text_length, text_length)) == -1)
545 g_warning ("gdk_win32_draw_text: gdk_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;
619 GDK_NOTE (MISC, g_print ("gdk_draw_pixmap: dest: %#x @+%d+%d"
620 "src: %#x %dx%d@+%d+%d\n",
621 (guint) GDK_DRAWABLE_HANDLE (drawable),
623 (guint) GDK_PIXMAP_HBITMAP (src),
624 width, height, xsrc, ysrc));
626 hdc = gdk_win32_hdc_get (drawable, gc, 0);
628 gdk_drawable_get_size (src, &src_width, &src_height);
629 src_rgn = CreateRectRgn (0, 0, src_width + 1, src_height + 1);
630 draw_rgn = CreateRectRgn (xsrc, ysrc, xsrc + width + 1, ysrc + height + 1);
632 if (GDK_IS_WINDOW (drawable))
634 /* If we are drawing on a window, calculate the region that is
635 * outside the source pixmap, and invalidate that, causing it to
639 outside_rgn = CreateRectRgnIndirect (&r);
640 if (CombineRgn (outside_rgn, draw_rgn, src_rgn, RGN_DIFF) != NULLREGION)
642 OffsetRgn (outside_rgn, xdest, ydest);
643 GDK_NOTE (MISC, (GetRgnBox (outside_rgn, &r),
644 g_print ("...calling InvalidateRgn, "
645 "bbox: %ldx%ld@+%ld+%ld\n",
646 r.right - r.left - 1, r.bottom - r.top - 1,
648 InvalidateRgn (GDK_DRAWABLE_HANDLE (drawable), outside_rgn, TRUE);
650 DeleteObject (outside_rgn);
653 #if 1 /* Don't know if this is necessary */
654 if (CombineRgn (draw_rgn, draw_rgn, src_rgn, RGN_AND) == COMPLEXREGION)
655 g_warning ("gdk_win32_draw_drawable: CombineRgn returned a COMPLEXREGION");
657 GetRgnBox (draw_rgn, &r);
660 || r.right != xsrc + width + 1
661 || r.bottom != ysrc + height + 1)
663 xdest += r.left - xsrc;
665 ydest += r.top - ysrc;
667 width = r.right - xsrc - 1;
668 height = r.bottom - ysrc - 1;
670 GDK_NOTE (MISC, g_print ("... restricted to src: %dx%d@+%d+%d, "
672 width, height, xsrc, ysrc,
677 DeleteObject (src_rgn);
678 DeleteObject (draw_rgn);
680 /* This function is called also to bitblt from a window.
682 if (GDK_IS_PIXMAP (src))
684 if ((srcdc = CreateCompatibleDC (hdc)) == NULL)
685 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
687 if (ok && (hgdiobj = SelectObject (srcdc, GDK_PIXMAP_HBITMAP (src))) == NULL)
688 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
690 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
691 srcdc, xsrc, ysrc, SRCCOPY))
692 WIN32_GDI_FAILED ("BitBlt");
694 if (ok && (SelectObject (srcdc, hgdiobj) == NULL))
695 WIN32_GDI_FAILED ("SelectObject");
697 if (srcdc != NULL && !DeleteDC (srcdc))
698 WIN32_GDI_FAILED ("DeleteDC");
700 else if (GDK_DRAWABLE_HANDLE (drawable) == GDK_DRAWABLE_HANDLE (src))
702 /* Blitting inside a window, use ScrollDC */
703 RECT scrollRect, clipRect, emptyRect;
706 scrollRect.left = MIN (xsrc, xdest);
707 scrollRect.top = MIN (ysrc, ydest);
708 scrollRect.right = MAX (xsrc + width + 1, xdest + width + 1);
709 scrollRect.bottom = MAX (ysrc + height + 1, ydest + height + 1);
711 clipRect.left = xdest;
712 clipRect.top = ydest;
713 clipRect.right = xdest + width + 1;
714 clipRect.bottom = ydest + height + 1;
716 SetRectEmpty (&emptyRect);
717 updateRgn = CreateRectRgnIndirect (&emptyRect);
718 if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc,
719 &scrollRect, &clipRect,
721 WIN32_GDI_FAILED ("ScrollDC"), ok = FALSE;
722 if (ok && !InvalidateRgn (GDK_WINDOW_HWND (drawable), updateRgn, FALSE))
723 WIN32_GDI_FAILED ("InvalidateRgn"), ok = FALSE;
724 if (ok && !UpdateWindow (GDK_WINDOW_HWND (drawable)))
725 WIN32_GDI_FAILED ("UpdateWindow");
726 DeleteObject (updateRgn);
730 if ((srcdc = GetDC (GDK_WINDOW_HWND (src))) == NULL)
731 WIN32_GDI_FAILED ("GetDC"), ok = FALSE;
733 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
734 srcdc, xsrc, ysrc, SRCCOPY))
735 WIN32_GDI_FAILED ("BitBlt");
736 ReleaseDC (GDK_WINDOW_HWND (src), srcdc);
738 gdk_win32_hdc_release (drawable, gc, 0);
742 gdk_win32_draw_points (GdkDrawable *drawable,
749 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
750 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
753 hdc = gdk_win32_hdc_get (drawable, gc, 0);
755 fg = gdk_colormap_color (impl->colormap, gc_private->foreground);
757 GDK_NOTE (MISC, g_print ("gdk_draw_points: %#x %dx%.06x\n",
758 (guint) GDK_DRAWABLE_HANDLE (drawable),
759 npoints, (guint) fg));
761 for (i = 0; i < npoints; i++)
762 SetPixel (hdc, points[i].x, points[i].y, fg);
764 gdk_win32_hdc_release (drawable, gc, 0);
768 gdk_win32_draw_segments (GdkDrawable *drawable,
773 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
774 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
780 GDK_NOTE (MISC, g_print ("gdk_win32_draw_segments: %#x nsegs: %d\n",
781 (guint) GDK_DRAWABLE_HANDLE (drawable), nsegs));
783 hdc = gdk_win32_hdc_get (drawable, gc, mask);
785 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
787 if (!BeginPath (hdc))
788 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
790 for (i = 0; ok && i < nsegs; i++)
792 if (ok && !MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
793 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
794 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
795 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
798 if (ok && gc_private->pen_width <= 1)
799 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
800 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
803 if (ok && !EndPath (hdc))
804 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
806 if (ok && !WidenPath (hdc))
807 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
809 if (ok && !FillPath (hdc))
810 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
813 if (!DeleteObject (hbr))
814 WIN32_GDI_FAILED ("DeleteObject");
818 for (i = 0; ok && i < nsegs; i++)
820 if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
821 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
822 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
823 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
826 if (ok && gc_private->pen_width <= 1)
827 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
828 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
831 gdk_win32_hdc_release (drawable, gc, mask);
835 gdk_win32_draw_lines (GdkDrawable *drawable,
840 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
841 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
850 hdc = gdk_win32_hdc_get (drawable, gc, mask);
852 pts = g_new (POINT, npoints);
854 for (i = 0; i < npoints; i++)
856 pts[i].x = points[i].x;
857 pts[i].y = points[i].y;
860 if (!Polyline (hdc, pts, npoints))
861 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
866 if (ok && gc_private->pen_width <= 1)
868 MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
869 if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
870 WIN32_GDI_FAILED ("LineTo");
872 gdk_win32_hdc_release (drawable, gc, mask);
876 gdk_win32_draw_glyphs (GdkDrawable *drawable,
881 PangoGlyphString *glyphs)
883 const GdkGCValuesMask mask = GDK_GC_FOREGROUND;
886 hdc = gdk_win32_hdc_get (drawable, gc, mask);
888 /* HB: Maybe there should be a GDK_GC_PANGO flag for hdc_get */
889 /* default write mode is transparent (leave background) */
890 if (SetBkMode (hdc, TRANSPARENT) == 0)
891 WIN32_GDI_FAILED ("SetBkMode");
893 if (GDI_ERROR == SetTextAlign (hdc, TA_LEFT|TA_BOTTOM|TA_NOUPDATECP))
894 WIN32_GDI_FAILED ("SetTextAlign");
896 pango_win32_render (hdc, font, glyphs, x, y);
898 gdk_win32_hdc_release (drawable, gc, mask);
902 gdk_win32_draw_image (GdkDrawable *drawable,
912 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
913 GdkImagePrivateWin32 *image_private = (GdkImagePrivateWin32 *) image;
914 GdkColormapPrivateWin32 *colormap_private = (GdkColormapPrivateWin32 *) impl->colormap;
919 BITMAPINFOHEADER bmiHeader;
920 WORD bmiIndices[256];
922 static gboolean bmi_inited = FALSE;
926 hdc = gdk_win32_hdc_get (drawable, gc, 0);
928 if (colormap_private && colormap_private->xcolormap->rc_palette)
932 for (i = 0; i < 256; i++)
933 bmi.bmiIndices[i] = i;
937 if (GetObject (image_private->hbitmap, sizeof (DIBSECTION),
938 &ds) != sizeof (DIBSECTION))
939 WIN32_GDI_FAILED ("GetObject"), ok = FALSE;
941 g_print("xdest = %d, ydest = %d, xsrc = %d, ysrc = %d, width = %d, height = %d\n",
942 xdest, ydest, xsrc, ysrc, width, height);
943 g_print("bmWidth = %d, bmHeight = %d, bmBitsPixel = %d, bmBits = %p\n",
944 ds.dsBm.bmWidth, ds.dsBm.bmHeight, ds.dsBm.bmBitsPixel, ds.dsBm.bmBits);
945 g_print("biWidth = %d, biHeight = %d, biBitCount = %d, biClrUsed = %d\n",
946 ds.dsBmih.biWidth, ds.dsBmih.biHeight, ds.dsBmih.biBitCount, ds.dsBmih.biClrUsed);
948 bmi.bmiHeader = ds.dsBmih;
949 /* I have spent hours on getting the parameters to
950 * SetDIBitsToDevice right. I wonder what drugs the guys in
951 * Redmond were on when they designed this API.
953 if (ok && SetDIBitsToDevice (hdc,
956 xsrc, (-ds.dsBmih.biHeight)-height-ysrc,
957 0, -ds.dsBmih.biHeight,
959 (CONST BITMAPINFO *) &bmi,
960 DIB_PAL_COLORS) == 0)
961 WIN32_GDI_FAILED ("SetDIBitsToDevice");
966 if ((memdc = CreateCompatibleDC (hdc)) == NULL)
967 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
969 if (ok && (oldbitmap = SelectObject (memdc, image_private->hbitmap)) == NULL)
970 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
972 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
973 memdc, xsrc, ysrc, SRCCOPY))
974 WIN32_GDI_FAILED ("BitBlt");
976 if (oldbitmap != NULL && SelectObject (memdc, oldbitmap) == NULL)
977 WIN32_GDI_FAILED ("SelectObject");
979 if (memdc != NULL && !DeleteDC (memdc))
980 WIN32_GDI_FAILED ("DeleteDC");
982 gdk_win32_hdc_release (drawable, gc, 0);
986 gdk_win32_get_depth (GdkDrawable *drawable)
988 /* This is a bit bogus but I'm not sure the other way is better */
990 return gdk_drawable_get_depth (GDK_DRAWABLE_IMPL_WIN32 (drawable)->wrapper);