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/.
30 #include <pango/pangowin32.h>
32 #include "gdkinternals.h"
33 #include "gdkprivate-win32.h"
34 #include "gdkdrawable-win32.h"
35 #include "gdkpixmap-win32.h"
37 static void gdk_win32_draw_rectangle (GdkDrawable *drawable,
44 static void gdk_win32_draw_arc (GdkDrawable *drawable,
53 static void gdk_win32_draw_polygon (GdkDrawable *drawable,
58 static void gdk_win32_draw_text (GdkDrawable *drawable,
65 static void gdk_win32_draw_text_wc (GdkDrawable *drawable,
72 static void gdk_win32_draw_drawable (GdkDrawable *drawable,
81 static void gdk_win32_draw_points (GdkDrawable *drawable,
85 static void gdk_win32_draw_segments (GdkDrawable *drawable,
89 static void gdk_win32_draw_lines (GdkDrawable *drawable,
93 static void gdk_win32_draw_glyphs (GdkDrawable *drawable,
98 PangoGlyphString *glyphs);
99 static void gdk_win32_draw_image (GdkDrawable *drawable,
109 static void gdk_win32_set_colormap (GdkDrawable *drawable,
110 GdkColormap *colormap);
112 static GdkColormap* gdk_win32_get_colormap (GdkDrawable *drawable);
114 static gint gdk_win32_get_depth (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;
174 /*****************************************************
175 * Win32 specific implementations of generic functions *
176 *****************************************************/
179 gdk_win32_get_colormap (GdkDrawable *drawable)
181 GdkDrawableImplWin32 *impl;
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 (%d) %s%dx%d@+%d+%d\n",
227 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 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
325 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
327 int nXStartArc, nYStartArc, nXEndArc, nYEndArc;
329 GDK_NOTE (MISC, g_print ("gdk_draw_arc: %#x %d,%d,%d,%d %d %d\n",
330 GDK_DRAWABLE_HANDLE (drawable),
331 x, y, width, height, angle1, angle2));
333 /* Seems that drawing arcs with width or height <= 2 fails, at least
336 if (width <= 2 || height <= 2 || angle2 == 0)
339 hdc = gdk_win32_hdc_get (drawable, gc, mask);
341 if (angle2 >= 360*64)
343 nXStartArc = nYStartArc = nXEndArc = nYEndArc = 0;
347 /* The 100. is just an arbitrary value */
348 nXStartArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
349 nYStartArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
350 nXEndArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
351 nYEndArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
355 nXEndArc = x + width/2 + 100. * cos(angle1/64.*2.*G_PI/360.);
356 nYEndArc = y + height/2 + -100. * sin(angle1/64.*2.*G_PI/360.);
357 nXStartArc = x + width/2 + 100. * cos((angle1+angle2)/64.*2.*G_PI/360.);
358 nYStartArc = y + height/2 + -100. * sin((angle1+angle2)/64.*2.*G_PI/360.);
361 /* GDK_OPAQUE_STIPPLED arcs not implemented. */
365 GDK_NOTE (MISC, g_print ("...Pie(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
366 x, y, x+width, y+height,
367 nXStartArc, nYStartArc,
368 nXEndArc, nYEndArc));
369 if (!Pie (hdc, x, y, x+width, y+height,
370 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
371 WIN32_GDI_FAILED ("Pie");
375 GDK_NOTE (MISC, g_print ("...Arc(hdc,%d,%d,%d,%d,%d,%d,%d,%d)\n",
376 x, y, x+width, y+height,
377 nXStartArc, nYStartArc,
378 nXEndArc, nYEndArc));
379 if (!Arc (hdc, x, y, x+width, y+height,
380 nXStartArc, nYStartArc, nXEndArc, nYEndArc))
381 WIN32_GDI_FAILED ("Arc");
383 gdk_win32_hdc_release (drawable, gc, mask);
387 gdk_win32_draw_polygon (GdkDrawable *drawable,
393 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
394 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
401 GDK_NOTE (MISC, g_print ("gdk_win32_draw_polygon: %#x (%d) %d\n",
402 GDK_DRAWABLE_HANDLE (drawable), gc_private,
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 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
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 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 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
566 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_FONT;
569 gdk_draw_text_arg arg;
571 if (text_length == 0)
574 g_assert (font->type == GDK_FONT_FONT || font->type == GDK_FONT_FONTSET);
578 arg.hdc = gdk_win32_hdc_get (drawable, gc, mask);
580 GDK_NOTE (MISC, g_print ("gdk_draw_text_wc: %#x (%d,%d) len: %d\n",
581 GDK_DRAWABLE_HANDLE (drawable),
584 if (sizeof (wchar_t) != sizeof (GdkWChar))
586 wcstr = g_new (wchar_t, text_length);
587 for (i = 0; i < text_length; i++)
591 wcstr = (wchar_t *) text;
593 gdk_wchar_text_handle (font, wcstr, text_length,
594 gdk_draw_text_handler, &arg);
596 if (sizeof (wchar_t) != sizeof (GdkWChar))
599 gdk_win32_hdc_release (drawable, gc, mask);
603 gdk_win32_draw_drawable (GdkDrawable *drawable,
613 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
614 GdkDrawableImplWin32 *src_impl = GDK_DRAWABLE_IMPL_WIN32 (src);
618 HRGN src_rgn, draw_rgn, outside_rgn;
620 gint src_width, src_height;
623 GDK_NOTE (MISC, g_print ("gdk_draw_pixmap: dest: %#x @+%d+%d"
624 "src: %#x %dx%d@+%d+%d\n",
625 GDK_DRAWABLE_HANDLE (drawable), xdest, ydest,
626 GDK_PIXMAP_HBITMAP (src),
627 width, height, xsrc, ysrc));
629 hdc = gdk_win32_hdc_get (drawable, gc, 0);
631 gdk_drawable_get_size (src, &src_width, &src_height);
632 src_rgn = CreateRectRgn (0, 0, src_width + 1, src_height + 1);
633 draw_rgn = CreateRectRgn (xsrc, ysrc, xsrc + width + 1, ysrc + height + 1);
635 if (GDK_IS_WINDOW (drawable))
637 /* If we are drawing on a window, calculate the region that is
638 * outside the source pixmap, and invalidate that, causing it to
642 outside_rgn = CreateRectRgnIndirect (&r);
643 if (CombineRgn (outside_rgn, draw_rgn, src_rgn, RGN_DIFF) != NULLREGION)
645 OffsetRgn (outside_rgn, xdest, ydest);
646 GDK_NOTE (MISC, (GetRgnBox (outside_rgn, &r),
647 g_print ("...calling InvalidateRgn, "
648 "bbox: %dx%d@+%d+%d\n",
649 r.right - r.left - 1, r.bottom - r.top - 1,
651 InvalidateRgn (GDK_DRAWABLE_HANDLE (drawable), outside_rgn, TRUE);
653 DeleteObject (outside_rgn);
656 #if 1 /* Don't know if this is necessary */
657 if (CombineRgn (draw_rgn, draw_rgn, src_rgn, RGN_AND) == COMPLEXREGION)
658 g_warning ("gdk_win32_draw_drawable: CombineRgn returned a COMPLEXREGION");
660 GetRgnBox (draw_rgn, &r);
663 || r.right != xsrc + width + 1
664 || r.bottom != ysrc + height + 1)
666 xdest += r.left - xsrc;
668 ydest += r.top - ysrc;
670 width = r.right - xsrc - 1;
671 height = r.bottom - ysrc - 1;
673 GDK_NOTE (MISC, g_print ("... restricted to src: %dx%d@+%d+%d, "
675 width, height, xsrc, ysrc,
680 DeleteObject (src_rgn);
681 DeleteObject (draw_rgn);
683 /* This function is called also to bitblt from a window.
685 if (GDK_IS_PIXMAP (src))
687 if ((srcdc = CreateCompatibleDC (hdc)) == NULL)
688 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
690 if (ok && (hgdiobj = SelectObject (srcdc, GDK_PIXMAP_HBITMAP (src))) == NULL)
691 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
693 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
694 srcdc, xsrc, ysrc, SRCCOPY))
695 WIN32_GDI_FAILED ("BitBlt");
697 if (ok && (SelectObject (srcdc, hgdiobj) == NULL))
698 WIN32_GDI_FAILED ("SelectObject");
700 if (srcdc != NULL && !DeleteDC (srcdc))
701 WIN32_GDI_FAILED ("DeleteDC");
703 else if (GDK_DRAWABLE_HANDLE (drawable) == GDK_DRAWABLE_HANDLE (src))
705 /* Blitting inside a window, use ScrollDC */
706 RECT scrollRect, clipRect, emptyRect;
709 scrollRect.left = MIN (xsrc, xdest);
710 scrollRect.top = MIN (ysrc, ydest);
711 scrollRect.right = MAX (xsrc + width + 1, xdest + width + 1);
712 scrollRect.bottom = MAX (ysrc + height + 1, ydest + height + 1);
714 clipRect.left = xdest;
715 clipRect.top = ydest;
716 clipRect.right = xdest + width + 1;
717 clipRect.bottom = ydest + height + 1;
719 SetRectEmpty (&emptyRect);
720 updateRgn = CreateRectRgnIndirect (&emptyRect);
721 if (!ScrollDC (hdc, xdest - xsrc, ydest - ysrc,
722 &scrollRect, &clipRect,
724 WIN32_GDI_FAILED ("ScrollDC"), ok = FALSE;
725 if (ok && !InvalidateRgn (GDK_WINDOW_HWND (drawable), updateRgn, FALSE))
726 WIN32_GDI_FAILED ("InvalidateRgn"), ok = FALSE;
727 if (ok && !UpdateWindow (GDK_WINDOW_HWND (drawable)))
728 WIN32_GDI_FAILED ("UpdateWindow");
729 DeleteObject (updateRgn);
733 if ((srcdc = GetDC (GDK_WINDOW_HWND (src))) == NULL)
734 WIN32_GDI_FAILED ("GetDC"), ok = FALSE;
736 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
737 srcdc, xsrc, ysrc, SRCCOPY))
738 WIN32_GDI_FAILED ("BitBlt");
739 ReleaseDC (GDK_WINDOW_HWND (src), srcdc);
741 gdk_win32_hdc_release (drawable, gc, 0);
745 gdk_win32_draw_points (GdkDrawable *drawable,
752 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
753 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
756 hdc = gdk_win32_hdc_get (drawable, gc, 0);
758 fg = gdk_colormap_color (impl->colormap, gc_private->foreground);
760 GDK_NOTE (MISC, g_print ("gdk_draw_points: %#x %dx%.06x\n",
761 GDK_DRAWABLE_HANDLE (drawable), npoints, fg));
763 for (i = 0; i < npoints; i++)
764 SetPixel (hdc, points[i].x, points[i].y, fg);
766 gdk_win32_hdc_release (drawable, gc, 0);
770 gdk_win32_draw_segments (GdkDrawable *drawable,
775 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
776 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
782 GDK_NOTE (MISC, g_print ("gdk_win32_draw_segments: %#x nsegs: %d\n",
783 GDK_DRAWABLE_HANDLE (drawable), nsegs));
785 hdc = gdk_win32_hdc_get (drawable, gc, mask);
787 if (gc_private->fill_style == GDK_OPAQUE_STIPPLED)
789 if (!BeginPath (hdc))
790 WIN32_GDI_FAILED ("BeginPath"), ok = FALSE;
792 for (i = 0; ok && i < nsegs; i++)
794 if (ok && !MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
795 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
796 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
797 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
800 if (ok && gc_private->pen_width <= 1)
801 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
802 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
805 if (ok && !EndPath (hdc))
806 WIN32_GDI_FAILED ("EndPath"), ok = FALSE;
808 if (ok && !WidenPath (hdc))
809 WIN32_GDI_FAILED ("WidenPath"), ok = FALSE;
811 if (ok && !FillPath (hdc))
812 WIN32_GDI_FAILED ("FillPath"), ok = FALSE;
815 if (!DeleteObject (hbr))
816 WIN32_GDI_FAILED ("DeleteObject");
820 for (i = 0; ok && i < nsegs; i++)
822 if (!MoveToEx (hdc, segs[i].x1, segs[i].y1, NULL))
823 WIN32_GDI_FAILED ("MoveToEx"), ok = FALSE;
824 if (ok && !LineTo (hdc, segs[i].x2, segs[i].y2))
825 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
828 if (ok && gc_private->pen_width <= 1)
829 if (!LineTo (hdc, segs[i].x2 + 1, segs[i].y2))
830 WIN32_GDI_FAILED ("LineTo"), ok = FALSE;
833 gdk_win32_hdc_release (drawable, gc, mask);
837 gdk_win32_draw_lines (GdkDrawable *drawable,
842 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
843 const GdkGCValuesMask mask = GDK_GC_FOREGROUND|GDK_GC_BACKGROUND;
852 hdc = gdk_win32_hdc_get (drawable, gc, mask);
854 pts = g_new (POINT, npoints);
856 for (i = 0; i < npoints; i++)
858 pts[i].x = points[i].x;
859 pts[i].y = points[i].y;
862 if (!Polyline (hdc, pts, npoints))
863 WIN32_GDI_FAILED ("Polyline"), ok = FALSE;
868 if (ok && gc_private->pen_width <= 1)
870 MoveToEx (hdc, points[npoints-1].x, points[npoints-1].y, NULL);
871 if (!LineTo (hdc, points[npoints-1].x + 1, points[npoints-1].y))
872 WIN32_GDI_FAILED ("LineTo");
874 gdk_win32_hdc_release (drawable, gc, mask);
878 gdk_win32_draw_glyphs (GdkDrawable *drawable,
883 PangoGlyphString *glyphs)
885 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
886 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
887 const GdkGCValuesMask mask = GDK_GC_FOREGROUND;
890 hdc = gdk_win32_hdc_get (drawable, gc, mask);
892 pango_win32_render (hdc, font, glyphs, x, y);
894 gdk_win32_hdc_release (drawable, gc, mask);
898 gdk_win32_draw_image (GdkDrawable *drawable,
908 GdkDrawableImplWin32 *impl = GDK_DRAWABLE_IMPL_WIN32 (drawable);
909 GdkGCWin32 *gc_private = GDK_GC_WIN32 (gc);
910 GdkImagePrivateWin32 *image_private = (GdkImagePrivateWin32 *) image;
911 GdkColormapPrivateWin32 *colormap_private = (GdkColormapPrivateWin32 *) impl->colormap;
916 BITMAPINFOHEADER bmiHeader;
917 WORD bmiIndices[256];
919 static gboolean bmi_inited = FALSE;
923 hdc = gdk_win32_hdc_get (drawable, gc, 0);
925 if (colormap_private && colormap_private->xcolormap->rc_palette)
929 for (i = 0; i < 256; i++)
930 bmi.bmiIndices[i] = i;
934 if (GetObject (image_private->hbitmap, sizeof (DIBSECTION),
935 &ds) != sizeof (DIBSECTION))
936 WIN32_GDI_FAILED ("GetObject"), ok = FALSE;
938 g_print("xdest = %d, ydest = %d, xsrc = %d, ysrc = %d, width = %d, height = %d\n",
939 xdest, ydest, xsrc, ysrc, width, height);
940 g_print("bmWidth = %d, bmHeight = %d, bmBitsPixel = %d, bmBits = %p\n",
941 ds.dsBm.bmWidth, ds.dsBm.bmHeight, ds.dsBm.bmBitsPixel, ds.dsBm.bmBits);
942 g_print("biWidth = %d, biHeight = %d, biBitCount = %d, biClrUsed = %d\n",
943 ds.dsBmih.biWidth, ds.dsBmih.biHeight, ds.dsBmih.biBitCount, ds.dsBmih.biClrUsed);
945 bmi.bmiHeader = ds.dsBmih;
946 /* I have spent hours on getting the parameters to
947 * SetDIBitsToDevice right. I wonder what drugs the guys in
948 * Redmond were on when they designed this API.
950 if (ok && SetDIBitsToDevice (hdc,
953 xsrc, (-ds.dsBmih.biHeight)-height-ysrc,
954 0, -ds.dsBmih.biHeight,
956 (CONST BITMAPINFO *) &bmi,
957 DIB_PAL_COLORS) == 0)
958 WIN32_GDI_FAILED ("SetDIBitsToDevice");
963 if ((memdc = CreateCompatibleDC (hdc)) == NULL)
964 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
966 if (ok && (oldbitmap = SelectObject (memdc, image_private->hbitmap)) == NULL)
967 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
969 if (ok && !BitBlt (hdc, xdest, ydest, width, height,
970 memdc, xsrc, ysrc, SRCCOPY))
971 WIN32_GDI_FAILED ("BitBlt");
973 if (oldbitmap != NULL && SelectObject (memdc, oldbitmap) == NULL)
974 WIN32_GDI_FAILED ("SelectObject");
976 if (memdc != NULL && !DeleteDC (memdc))
977 WIN32_GDI_FAILED ("DeleteDC");
979 gdk_win32_hdc_release (drawable, gc, 0);
983 gdk_win32_get_depth (GdkDrawable *drawable)
985 /* This is a bit bogus but I'm not sure the other way is better */
987 return gdk_drawable_get_depth (GDK_DRAWABLE_IMPL_WIN32 (drawable)->wrapper);