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/.
33 #include "gdkpixmap.h"
34 #include "gdkregion-generic.h"
35 #include "gdkinternals.h"
36 #include "gdkprivate-win32.h"
37 #include "gdkdrawable-win32.h"
38 #include "gdkwindow-win32.h"
39 #include "gdkpixmap-win32.h"
41 static void gdk_win32_gc_destroy (GdkGC *gc);
42 static void gdk_win32_gc_get_values (GdkGC *gc,
44 static void gdk_win32_gc_set_values (GdkGC *gc,
46 GdkGCValuesMask values_mask);
47 static void gdk_win32_gc_set_dashes (GdkGC *gc,
52 static void gdk_gc_win32_class_init (GdkGCWin32Class *klass);
53 static void gdk_gc_win32_finalize (GObject *object);
55 static gpointer parent_class = NULL;
58 gdk_gc_win32_get_type (void)
60 static GType object_type = 0;
64 static const GTypeInfo object_info =
66 sizeof (GdkGCWin32Class),
68 (GBaseFinalizeFunc) NULL,
69 (GClassInitFunc) gdk_gc_win32_class_init,
70 NULL, /* class_finalize */
71 NULL, /* class_data */
74 (GInstanceInitFunc) NULL,
77 object_type = g_type_register_static (GDK_TYPE_GC,
86 gdk_gc_win32_class_init (GdkGCWin32Class *klass)
88 GObjectClass *object_class = G_OBJECT_CLASS (klass);
89 GdkGCClass *gc_class = GDK_GC_CLASS (klass);
91 parent_class = g_type_class_peek_parent (klass);
93 object_class->finalize = gdk_gc_win32_finalize;
95 gc_class->get_values = gdk_win32_gc_get_values;
96 gc_class->set_values = gdk_win32_gc_set_values;
97 gc_class->set_dashes = gdk_win32_gc_set_dashes;
101 gdk_gc_win32_finalize (GObject *object)
103 GdkGCWin32 *win32_gc = GDK_GC_WIN32 (object);
105 if (win32_gc->clip_region)
106 gdk_region_destroy (win32_gc->clip_region);
108 if (win32_gc->values_mask & GDK_GC_FONT)
109 gdk_font_unref (win32_gc->font);
111 if (win32_gc->values_mask & GDK_GC_TILE)
112 gdk_drawable_unref (win32_gc->tile);
114 if (win32_gc->values_mask & GDK_GC_STIPPLE)
115 gdk_drawable_unref (win32_gc->stipple);
117 G_OBJECT_CLASS (parent_class)->finalize (object);
121 gdk_win32_gc_values_to_win32values (GdkGCValues *values,
122 GdkGCValuesMask mask,
123 GdkGCWin32 *win32_gc)
128 GDK_NOTE (MISC, g_print ("{"));
130 if (mask & GDK_GC_FOREGROUND)
132 win32_gc->foreground = values->foreground.pixel;
133 win32_gc->values_mask |= GDK_GC_FOREGROUND;
134 GDK_NOTE (MISC, (g_print ("fg=%.06x", win32_gc->foreground),
138 if (mask & GDK_GC_BACKGROUND)
140 win32_gc->background = values->background.pixel;
141 win32_gc->values_mask |= GDK_GC_BACKGROUND;
142 GDK_NOTE (MISC, (g_print ("%sbg=%.06x", s, win32_gc->background),
146 if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT
147 || values->font->type == GDK_FONT_FONTSET))
149 if (win32_gc->font != NULL)
150 gdk_font_unref (win32_gc->font);
151 win32_gc->font = values->font;
152 if (win32_gc->font != NULL)
156 gdk_font_ref (win32_gc->font);
157 win32_gc->values_mask |= GDK_GC_FONT;
158 GDK_NOTE (MISC, (xlfd = gdk_font_full_name_get (win32_gc->font),
159 g_print ("%sfont=%s", s, xlfd),
161 gdk_font_full_name_free (xlfd)));
165 win32_gc->values_mask &= ~GDK_GC_FONT;
166 GDK_NOTE (MISC, (g_print ("%sfont=NULL"),
171 if (mask & GDK_GC_FUNCTION)
173 GDK_NOTE (MISC, (g_print ("%srop2=", s),
175 switch (values->function)
178 win32_gc->rop2 = R2_COPYPEN;
179 GDK_NOTE (MISC, g_print ("COPYPEN"));
182 win32_gc->rop2 = R2_NOT;
183 GDK_NOTE (MISC, g_print ("NOT"));
186 win32_gc->rop2 = R2_XORPEN;
187 GDK_NOTE (MISC, g_print ("XORPEN"));
190 win32_gc->rop2 = R2_BLACK;
191 GDK_NOTE (MISC, g_print ("BLACK"));
194 win32_gc->rop2 = R2_MASKPEN;
195 GDK_NOTE (MISC, g_print ("MASKPEN"));
197 case GDK_AND_REVERSE:
198 win32_gc->rop2 = R2_MASKPENNOT;
199 GDK_NOTE (MISC, g_print ("MASKPENNOT"));
202 win32_gc->rop2 = R2_MASKNOTPEN;
203 GDK_NOTE (MISC, g_print ("MASKNOTPEN"));
206 win32_gc->rop2 = R2_NOP;
207 GDK_NOTE (MISC, g_print ("NOP"));
210 win32_gc->rop2 = R2_MERGEPEN;
211 GDK_NOTE (MISC, g_print ("MERGEPEN"));
214 win32_gc->rop2 = R2_NOTXORPEN;
215 GDK_NOTE (MISC, g_print ("NOTXORPEN"));
218 win32_gc->rop2 = R2_MERGEPENNOT;
219 GDK_NOTE (MISC, g_print ("MERGEPENNOT"));
221 case GDK_COPY_INVERT:
222 win32_gc->rop2 = R2_NOTCOPYPEN;
223 GDK_NOTE (MISC, g_print ("NOTCOPYPEN"));
226 win32_gc->rop2 = R2_MERGENOTPEN;
227 GDK_NOTE (MISC, g_print ("MERGENOTPEN"));
230 win32_gc->rop2 = R2_NOTMASKPEN;
231 GDK_NOTE (MISC, g_print ("NOTMASKPEN"));
234 win32_gc->rop2 = R2_NOTMERGEPEN;
235 GDK_NOTE (MISC, g_print ("NOTMERGEPEN"));
238 win32_gc->rop2 = R2_WHITE;
239 GDK_NOTE (MISC, g_print ("WHITE"));
242 win32_gc->values_mask |= GDK_GC_FUNCTION;
245 if (mask & GDK_GC_FILL)
247 win32_gc->fill_style = values->fill;
248 win32_gc->values_mask |= GDK_GC_FILL;
249 GDK_NOTE (MISC, (g_print ("%sfill=%d", s, win32_gc->fill_style),
253 if (mask & GDK_GC_TILE)
255 if (win32_gc->tile != NULL)
256 gdk_drawable_unref (win32_gc->tile);
257 win32_gc->tile = values->tile;
258 if (win32_gc->tile != NULL)
260 gdk_drawable_ref (win32_gc->tile);
261 win32_gc->values_mask |= GDK_GC_TILE;
262 GDK_NOTE (MISC, (g_print ("%stile=%#x", s,
263 GDK_PIXMAP_HBITMAP (win32_gc->tile)),
268 win32_gc->values_mask &= ~GDK_GC_TILE;
269 GDK_NOTE (MISC, (g_print ("%stile=NULL", s),
274 if (mask & GDK_GC_STIPPLE)
276 if (win32_gc->stipple != NULL)
277 gdk_drawable_unref (win32_gc->stipple);
278 win32_gc->stipple = values->stipple;
279 if (win32_gc->stipple != NULL)
281 gdk_drawable_get_size (win32_gc->stipple, &sw, &sh);
283 if (sw != 8 || sh != 8)
285 /* It seems that it *must* be 8x8, at least on my machine.
286 * Thus, tile an 8x8 bitmap with the stipple in case it is
287 * smaller, or simply use just the top left 8x8 in case it is
291 GdkPixmap *bm = gdk_bitmap_create_from_data (NULL, dummy, 8, 8);
292 GdkGC *gc = gdk_gc_new (bm);
301 gdk_draw_drawable (bm, gc, win32_gc->stipple, 0, 0, i, j, sw, sh);
306 win32_gc->stipple = bm;
310 gdk_drawable_ref (win32_gc->stipple);
311 win32_gc->values_mask |= GDK_GC_STIPPLE;
312 GDK_NOTE (MISC, (g_print ("%sstipple=%#x", s,
313 GDK_PIXMAP_HBITMAP (win32_gc->stipple)),
318 win32_gc->values_mask &= ~GDK_GC_STIPPLE;
319 GDK_NOTE (MISC, (g_print ("%sstipple=NULL", s),
324 if (mask & GDK_GC_CLIP_MASK)
326 if (win32_gc->clip_region != NULL)
328 gdk_region_destroy (win32_gc->clip_region);
329 win32_gc->clip_region = NULL;
331 if (win32_gc->hcliprgn != NULL)
332 DeleteObject (win32_gc->hcliprgn);
334 if (values->clip_mask != NULL)
337 BitmapToRegion ((HBITMAP) GDK_PIXMAP_HBITMAP (values->clip_mask));
338 win32_gc->values_mask |= GDK_GC_CLIP_MASK;
339 OffsetRgn (win32_gc->hcliprgn,
340 win32_gc->parent_instance.clip_x_origin,
341 win32_gc->parent_instance.clip_y_origin);
345 win32_gc->hcliprgn = NULL;
346 win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
348 GDK_NOTE (MISC, (g_print ("%sclip=%#x", s, win32_gc->hcliprgn),
352 if (mask & GDK_GC_SUBWINDOW)
354 win32_gc->subwindow_mode = values->subwindow_mode;
355 win32_gc->values_mask |= GDK_GC_SUBWINDOW;
356 GDK_NOTE (MISC, (g_print ("%ssubw=%d", s, win32_gc->subwindow_mode),
360 if (mask & GDK_GC_TS_X_ORIGIN)
362 win32_gc->values_mask |= GDK_GC_TS_X_ORIGIN;
363 GDK_NOTE (MISC, (g_print ("%sts_x=%d", s, values->ts_x_origin),
367 if (mask & GDK_GC_TS_Y_ORIGIN)
369 win32_gc->values_mask |= GDK_GC_TS_Y_ORIGIN;
370 GDK_NOTE (MISC, (g_print ("%sts_y=%d", s, values->ts_y_origin),
374 if (mask & GDK_GC_CLIP_X_ORIGIN)
376 win32_gc->values_mask |= GDK_GC_CLIP_X_ORIGIN;
377 GDK_NOTE (MISC, (g_print ("%sclip_x=%d", s, values->clip_x_origin),
381 if (mask & GDK_GC_CLIP_Y_ORIGIN)
383 win32_gc->values_mask |= GDK_GC_CLIP_Y_ORIGIN;
384 GDK_NOTE (MISC, (g_print ("%sclip_y=%d", s, values->clip_y_origin),
388 if (mask & GDK_GC_EXPOSURES)
390 win32_gc->graphics_exposures = values->graphics_exposures;
391 win32_gc->values_mask |= GDK_GC_EXPOSURES;
392 GDK_NOTE (MISC, (g_print ("%sexp=%d", s, win32_gc->graphics_exposures),
396 if (mask & GDK_GC_LINE_WIDTH)
398 win32_gc->pen_width = values->line_width;
399 win32_gc->values_mask |= GDK_GC_LINE_WIDTH;
400 GDK_NOTE (MISC, (g_print ("%spw=%d", s, win32_gc->pen_width),
404 if (mask & GDK_GC_LINE_STYLE)
406 win32_gc->pen_style &= ~(PS_STYLE_MASK);
407 GDK_NOTE (MISC, (g_print ("%sps|=", s),
409 switch (values->line_style)
412 GDK_NOTE (MISC, g_print ("LINE_SOLID"));
413 win32_gc->pen_style |= PS_SOLID;
415 case GDK_LINE_ON_OFF_DASH:
416 case GDK_LINE_DOUBLE_DASH: /* ??? */
417 GDK_NOTE (MISC, g_print ("DASH"));
418 win32_gc->pen_style |= PS_DASH;
421 win32_gc->values_mask |= GDK_GC_LINE_STYLE;
424 if (mask & GDK_GC_CAP_STYLE)
426 win32_gc->pen_style &= ~(PS_ENDCAP_MASK);
427 GDK_NOTE (MISC, (g_print ("%sps|=", s),
429 switch (values->cap_style)
431 case GDK_CAP_NOT_LAST: /* ??? */
433 GDK_NOTE (MISC, g_print ("ENDCAP_FLAT"));
434 win32_gc->pen_style |= PS_ENDCAP_FLAT;
437 GDK_NOTE (MISC, g_print ("ENDCAP_ROUND"));
438 win32_gc->pen_style |= PS_ENDCAP_ROUND;
440 case GDK_CAP_PROJECTING:
441 GDK_NOTE (MISC, g_print ("ENDCAP_SQUARE"));
442 win32_gc->pen_style |= PS_ENDCAP_SQUARE;
445 win32_gc->values_mask |= GDK_GC_CAP_STYLE;
448 if (mask & GDK_GC_JOIN_STYLE)
450 win32_gc->pen_style &= ~(PS_JOIN_MASK);
451 GDK_NOTE (MISC, (g_print ("%sps|=", s),
453 switch (values->join_style)
456 GDK_NOTE (MISC, g_print ("JOIN_MITER"));
457 win32_gc->pen_style |= PS_JOIN_MITER;
460 GDK_NOTE (MISC, g_print ("JOIN_ROUND"));
461 win32_gc->pen_style |= PS_JOIN_ROUND;
464 GDK_NOTE (MISC, g_print ("JOIN_BEVEL"));
465 win32_gc->pen_style |= PS_JOIN_BEVEL;
468 win32_gc->values_mask |= GDK_GC_JOIN_STYLE;
470 GDK_NOTE (MISC, g_print ("}\n"));
474 _gdk_win32_gc_new (GdkDrawable *drawable,
476 GdkGCValuesMask mask)
479 GdkGCWin32 *win32_gc;
481 /* NOTICE that the drawable here has to be the impl drawable,
482 * not the publically-visible drawables.
484 g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable), NULL);
486 gc = g_object_new (gdk_gc_win32_get_type (), NULL);
487 win32_gc = GDK_GC_WIN32 (gc);
489 win32_gc->hdc = NULL;
490 win32_gc->clip_region = NULL;
491 win32_gc->hcliprgn = NULL;
493 /* Use the same default values as X11 does, even if they don't make
494 * sense per se. But apps always set fg and bg anyway.
496 win32_gc->foreground = 0;
497 win32_gc->background = 1;
498 win32_gc->font = NULL;
499 win32_gc->rop2 = R2_COPYPEN;
500 win32_gc->fill_style = GDK_SOLID;
501 win32_gc->tile = NULL;
502 win32_gc->stipple = NULL;
503 win32_gc->pen_style = PS_GEOMETRIC|PS_ENDCAP_FLAT|PS_JOIN_MITER;
504 win32_gc->pen_width = 0;
506 win32_gc->values_mask = GDK_GC_FUNCTION | GDK_GC_FILL;
508 GDK_NOTE (MISC, g_print ("_gdk_win32_gc_new: "));
509 gdk_win32_gc_values_to_win32values (values, mask, win32_gc);
511 win32_gc->hwnd = NULL;
513 GDK_NOTE (MISC, g_print (" = %p\n", gc));
519 gdk_win32_gc_get_values (GdkGC *gc,
522 GdkGCWin32 *win32_gc = GDK_GC_WIN32 (gc);
524 values->foreground.pixel = win32_gc->foreground;
525 values->background.pixel = win32_gc->background;
526 values->font = win32_gc->font;
528 switch (win32_gc->rop2)
531 values->function = GDK_COPY; break;
533 values->function = GDK_INVERT; break;
535 values->function = GDK_XOR; break;
537 values->function = GDK_CLEAR; break;
539 values->function = GDK_AND; break;
541 values->function = GDK_AND_REVERSE; break;
543 values->function = GDK_AND_INVERT; break;
545 values->function = GDK_NOOP; break;
547 values->function = GDK_OR; break;
549 values->function = GDK_EQUIV; break;
551 values->function = GDK_OR_REVERSE; break;
553 values->function = GDK_COPY_INVERT; break;
555 values->function = GDK_OR_INVERT; break;
557 values->function = GDK_NAND; break;
559 values->function = GDK_NOR; break;
561 values->function = GDK_SET; break;
564 values->fill = win32_gc->fill_style;
566 values->tile = win32_gc->tile;
567 values->stipple = win32_gc->stipple;
569 /* Also the X11 backend always returns a NULL clip_mask */
570 values->clip_mask = NULL;
572 values->subwindow_mode = win32_gc->subwindow_mode;
573 values->ts_x_origin = win32_gc->parent_instance.ts_x_origin;
574 values->ts_y_origin = win32_gc->parent_instance.ts_y_origin;
575 values->clip_x_origin = win32_gc->parent_instance.clip_x_origin;
576 values->clip_y_origin = win32_gc->parent_instance.clip_y_origin;
577 values->graphics_exposures = win32_gc->graphics_exposures;
578 values->line_width = win32_gc->pen_width;
580 if (win32_gc->pen_style & PS_SOLID)
581 values->line_style = GDK_LINE_SOLID;
582 else if (win32_gc->pen_style & PS_DASH)
583 values->line_style = GDK_LINE_ON_OFF_DASH;
585 values->line_style = GDK_LINE_SOLID;
587 /* PS_ENDCAP_ROUND is zero */
588 if (win32_gc->pen_style & PS_ENDCAP_FLAT)
589 values->cap_style = GDK_CAP_BUTT;
590 else if (win32_gc->pen_style & PS_ENDCAP_SQUARE)
591 values->cap_style = GDK_CAP_PROJECTING;
593 values->cap_style = GDK_CAP_ROUND;
595 /* PS_JOIN_ROUND is zero */
596 if (win32_gc->pen_style & PS_JOIN_MITER)
597 values->join_style = GDK_JOIN_MITER;
598 else if (win32_gc->pen_style & PS_JOIN_BEVEL)
599 values->join_style = GDK_JOIN_BEVEL;
601 values->join_style = GDK_JOIN_ROUND;
605 gdk_win32_gc_set_values (GdkGC *gc,
607 GdkGCValuesMask mask)
609 g_return_if_fail (GDK_IS_GC (gc));
611 GDK_NOTE (MISC, g_print ("gdk_win32_gc_set_values: "));
613 gdk_win32_gc_values_to_win32values (values, mask, GDK_GC_WIN32 (gc));
617 gdk_win32_gc_set_dashes (GdkGC *gc,
622 GdkGCWin32 *win32_gc;
624 g_return_if_fail (GDK_IS_GC (gc));
625 g_return_if_fail (dash_list != NULL);
627 win32_gc = GDK_GC_WIN32 (gc);
629 win32_gc->pen_style &= ~(PS_STYLE_MASK);
630 win32_gc->pen_style |= PS_DASH;
633 * Set the extended line style. This could be done by
634 * PS_USERSTYLE and ExtCreatePen; but ONLY on WinNT,
635 * so let's make a guess (based on the implementation
636 * in DIA). On Win9x this does only work for lines
639 * More workarounds for Win9x descibed at:
640 * http://www.codeguru.com/gdi/dashed.shtml
642 if (!IS_WIN_NT () && win32_gc->pen_width > 1)
644 GDK_NOTE (MISC, g_print ("gdk_win32_gc_set_dashes: not fully supported\n"));
645 win32_gc->pen_style |= PS_SOLID;
649 /* win32_gc->pen_style = PS_COSMETIC; ??? */
652 if ((dash_list[0] == dash_list[1]) && (dash_list[0] > 2))
654 win32_gc->pen_style |= PS_DASH;
655 GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DASH (%d,%d)\n",
656 dash_list[0], dash_list[1]));
660 win32_gc->pen_style |= PS_DOT;
661 GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DOT (%d,%d)\n",
662 dash_list[0], dash_list[1]));
667 win32_gc->pen_style |= PS_DASHDOT;
668 GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DASHDOT (%d,%d,%d,%d)\n",
669 dash_list[0], dash_list[1],
670 dash_list[2], dash_list[3]));
674 win32_gc->pen_style |= PS_DASHDOTDOT;
675 GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DASHDOTDOT (%d,%d,%d,%d,%d,%d)\n",
676 dash_list[0], dash_list[1],
677 dash_list[2], dash_list[3],
678 dash_list[4], dash_list[5]));
682 win32_gc->pen_style |= PS_DASH;
683 GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: no guess for %d dashes\n", n));
688 gdk_gc_set_clip_rectangle (GdkGC *gc,
689 GdkRectangle *rectangle)
691 GdkGCWin32 *win32_gc;
693 g_return_if_fail (GDK_IS_GC (gc));
695 win32_gc = GDK_GC_WIN32 (gc);
697 if (win32_gc->clip_region)
698 gdk_region_destroy (win32_gc->clip_region);
703 g_print ("gdk_gc_set_clip_rectangle: (%d) %dx%d@+%d+%d\n",
705 rectangle->width, rectangle->height,
706 rectangle->x, rectangle->y));
707 win32_gc->clip_region = gdk_region_rectangle (rectangle);
708 win32_gc->values_mask |= GDK_GC_CLIP_MASK;
712 GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_rectangle: (%d) NULL\n",
714 win32_gc->clip_region = NULL;
715 win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
717 win32_gc->values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
721 gdk_gc_set_clip_region (GdkGC *gc,
724 GdkGCWin32 *win32_gc;
726 g_return_if_fail (GDK_IS_GC (gc));
728 win32_gc = GDK_GC_WIN32 (gc);
730 if (win32_gc->clip_region)
731 gdk_region_destroy (win32_gc->clip_region);
735 GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_region: %d %dx%d+%d+%d\n",
737 region->extents.x2 - region->extents.x1,
738 region->extents.y2 - region->extents.y1,
739 region->extents.x1, region->extents.y1));
740 win32_gc->clip_region = gdk_region_copy (region);
741 win32_gc->values_mask |= GDK_GC_CLIP_MASK;
745 GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_region: %d NULL\n",
747 win32_gc->clip_region = NULL;
748 win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
751 gc->clip_x_origin = 0;
752 gc->clip_y_origin = 0;
754 win32_gc->values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
758 gdk_gc_copy (GdkGC *dst_gc,
761 GdkGCWin32 *dst_win32_gc;
762 GdkGCWin32 *src_win32_gc;
766 g_return_if_fail (GDK_IS_GC_WIN32 (dst_gc));
767 g_return_if_fail (GDK_IS_GC_WIN32 (src_gc));
769 dst_win32_gc = GDK_GC_WIN32 (dst_gc);
770 src_win32_gc = GDK_GC_WIN32 (src_gc);
772 if (dst_win32_gc->font != NULL)
773 gdk_font_unref (dst_win32_gc->font);
774 if (dst_win32_gc->tile != NULL)
775 gdk_drawable_unref (dst_win32_gc->tile);
776 if (dst_win32_gc->stipple != NULL)
777 gdk_drawable_unref (dst_win32_gc->stipple);
778 if (dst_win32_gc->clip_region != NULL)
779 gdk_region_destroy (dst_win32_gc->clip_region);
781 *dst_win32_gc = *src_win32_gc;
783 if (dst_win32_gc->clip_region != NULL)
784 dst_win32_gc->clip_region = gdk_region_copy (dst_win32_gc->clip_region);
785 if (dst_win32_gc->font != NULL)
786 gdk_font_ref (dst_win32_gc->font);
787 if (dst_win32_gc->tile != NULL)
788 gdk_drawable_ref (dst_win32_gc->tile);
789 if (dst_win32_gc->stipple != NULL)
790 gdk_drawable_ref (dst_win32_gc->stipple);
793 static guint bitmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
796 gdk_colormap_color (GdkColormap *colormap,
799 const GdkVisual *visual;
800 GdkColormapPrivateWin32 *colormap_private;
803 if (colormap == NULL)
804 return PALETTEINDEX (pixel);
806 colormap_private = GDK_COLORMAP_PRIVATE_DATA (colormap);
808 if (colormap_private->xcolormap->rc_palette)
809 return PALETTEINDEX (pixel);
811 visual = colormap->visual;
812 r = (pixel & visual->red_mask) >> visual->red_shift;
813 r = (r * 255) / bitmask[visual->red_prec];
814 g = (pixel & visual->green_mask) >> visual->green_shift;
815 g = (g * 255) / bitmask[visual->green_prec];
816 b = (pixel & visual->blue_mask) >> visual->blue_shift;
817 b = (b * 255) / bitmask[visual->blue_prec];
819 return RGB (r, g, b);
823 predraw_set_foreground (GdkGC *gc,
824 GdkColormap *colormap,
827 GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
828 GdkColormapPrivateWin32 *colormap_private;
834 if (colormap == NULL)
836 /* A 1 bit deep bitmap */
841 PALETTEENTRY palPalEntry[2];
843 static HPALETTE hpal = NULL;
847 /* Create a b&w palette */
848 logpal.palVersion = 0x300;
849 logpal.palNumEntries = 2;
850 logpal.palPalEntry[0].peRed =
851 logpal.palPalEntry[0].peGreen =
852 logpal.palPalEntry[0].peBlue = 0x00;
853 logpal.palPalEntry[0].peFlags = 0x00;
854 logpal.palPalEntry[1].peRed =
855 logpal.palPalEntry[1].peGreen =
856 logpal.palPalEntry[1].peBlue = 0xFF;
857 logpal.palPalEntry[1].peFlags = 0x00;
858 if ((hpal = CreatePalette ((LOGPALETTE *) &logpal)) == NULL)
859 WIN32_GDI_FAILED ("CreatePalette"), *ok = FALSE;
861 SelectPalette (win32_gc->hdc, hpal, FALSE);
862 RealizePalette (win32_gc->hdc);
863 fg = PALETTEINDEX (win32_gc->foreground);
867 colormap_private = GDK_COLORMAP_PRIVATE_DATA (colormap);
868 if (colormap_private->xcolormap->rc_palette)
871 if (SelectPalette (win32_gc->hdc, colormap_private->xcolormap->palette,
873 WIN32_GDI_FAILED ("SelectPalette"), *ok = FALSE;
874 if (TRUE || colormap_private->xcolormap->stale)
876 if ((k = RealizePalette (win32_gc->hdc)) == GDI_ERROR)
877 WIN32_GDI_FAILED ("RealizePalette"), *ok = FALSE;
878 colormap_private->xcolormap->stale = FALSE;
881 g_print ("Selected palette %#x for gc %#x, realized %d colors\n",
882 colormap_private->xcolormap->palette, win32_gc->hdc, k);
887 fg = gdk_colormap_color (colormap, win32_gc->foreground);
889 if (SetTextColor (win32_gc->hdc, fg) == CLR_INVALID)
890 WIN32_GDI_FAILED ("SetTextColor"), *ok = FALSE;
892 /* Create and select pen and brush. */
894 logbrush.lbStyle = BS_SOLID;
895 logbrush.lbColor = fg;
897 if (*ok && (hpen = ExtCreatePen (win32_gc->pen_style,
898 (win32_gc->pen_width > 0 ? win32_gc->pen_width : 1),
899 &logbrush, 0, NULL)) == NULL)
900 WIN32_GDI_FAILED ("ExtCreatePen");
902 if (SelectObject (win32_gc->hdc, hpen) == NULL)
903 WIN32_GDI_FAILED ("SelectObject"), *ok = FALSE;
905 switch (win32_gc->fill_style)
907 case GDK_OPAQUE_STIPPLED:
908 if (*ok && (hbr = CreatePatternBrush (GDK_PIXMAP_HBITMAP (win32_gc->stipple))) == NULL)
909 WIN32_GDI_FAILED ("CreatePatternBrush"), *ok = FALSE;
911 if (*ok && !SetBrushOrgEx(win32_gc->hdc, gc->ts_x_origin,
912 gc->ts_y_origin, NULL))
913 WIN32_GDI_FAILED ("SetBrushOrgEx"), *ok = FALSE;
918 if (*ok && (hbr = CreateSolidBrush (fg)) == NULL)
919 WIN32_GDI_FAILED ("CreateSolidBrush"), *ok = FALSE;
922 if (*ok && SelectObject (win32_gc->hdc, hbr) == NULL)
923 WIN32_GDI_FAILED ("SelectObject"), *ok = FALSE;
927 predraw_set_background (GdkGC *gc,
928 GdkColormap *colormap,
931 GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
932 COLORREF bg = gdk_colormap_color (colormap, win32_gc->background);
934 if (SetBkColor (win32_gc->hdc, bg) == CLR_INVALID)
935 WIN32_GDI_FAILED ("SetBkColor"), *ok = FALSE;
939 gdk_win32_hdc_get (GdkDrawable *drawable,
941 GdkGCValuesMask usage)
943 GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
944 GdkColormapPrivateWin32 *colormap_private =
945 (GdkColormapPrivateWin32 *) GDK_DRAWABLE_IMPL_WIN32 (drawable)->colormap;
949 g_assert (win32_gc->hdc == NULL);
951 win32_gc->hwnd = GDK_DRAWABLE_HANDLE (drawable);
953 if (GDK_IS_PIXMAP (drawable))
955 if ((win32_gc->hdc = CreateCompatibleDC (NULL)) == NULL)
956 WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
958 if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
959 WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
961 if (ok && SelectObject (win32_gc->hdc, win32_gc->hwnd) == NULL)
962 WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
966 if ((win32_gc->hdc = GetDC (win32_gc->hwnd)) == NULL)
967 WIN32_GDI_FAILED ("GetDC");
969 if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
970 WIN32_GDI_FAILED ("SaveDC");
973 if (ok && (usage & GDK_GC_FOREGROUND))
974 predraw_set_foreground (gc, GDK_DRAWABLE_IMPL_WIN32 (drawable)->colormap, &ok);
977 && (usage & GDK_GC_BACKGROUND)
978 && (win32_gc->values_mask & GDK_GC_BACKGROUND))
979 predraw_set_background (gc, GDK_DRAWABLE_IMPL_WIN32 (drawable)->colormap, &ok);
981 if (ok && (usage & GDK_GC_FONT))
983 if (SetBkMode (win32_gc->hdc, TRANSPARENT) == 0)
984 WIN32_GDI_FAILED ("SetBkMode"), ok = FALSE;
986 if (ok && SetTextAlign (win32_gc->hdc, TA_BASELINE) == GDI_ERROR)
987 WIN32_GDI_FAILED ("SetTextAlign"), ok = FALSE;
990 if (ok && (win32_gc->values_mask & GDK_GC_FUNCTION))
991 if (SetROP2 (win32_gc->hdc, win32_gc->rop2) == 0)
992 WIN32_GDI_FAILED ("SetROP2"), ok = FALSE;
994 if (win32_gc->values_mask & GDK_GC_CLIP_MASK)
995 g_assert ((win32_gc->clip_region != NULL) != (win32_gc->hcliprgn != NULL));
998 && (win32_gc->values_mask & GDK_GC_CLIP_MASK)
999 && win32_gc->clip_region != NULL)
1004 GdkRegionBox *boxes = win32_gc->clip_region->rects;
1006 sizeof (RGNDATAHEADER) + (sizeof (RECT) * win32_gc->clip_region->numRects);
1009 rgndata = g_malloc (nbytes);
1010 rgndata->rdh.dwSize = sizeof (RGNDATAHEADER);
1011 rgndata->rdh.iType = RDH_RECTANGLES;
1012 rgndata->rdh.nCount = rgndata->rdh.nRgnSize = 0;
1013 SetRect (&rgndata->rdh.rcBound,
1014 G_MAXSHORT, G_MAXSHORT, G_MINSHORT, G_MINSHORT);
1016 for (i = 0; i < win32_gc->clip_region->numRects; i++)
1018 rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++;
1020 rect->left = CLAMP (boxes[i].x1 + gc->clip_x_origin,
1021 G_MINSHORT, G_MAXSHORT);
1022 rect->right = CLAMP (boxes[i].x2 + gc->clip_x_origin,
1023 G_MINSHORT, G_MAXSHORT);
1024 rect->top = CLAMP (boxes[i].y1 + gc->clip_y_origin,
1025 G_MINSHORT, G_MAXSHORT);
1026 rect->bottom = CLAMP (boxes[i].y2 + gc->clip_y_origin,
1027 G_MINSHORT, G_MAXSHORT);
1029 GDK_NOTE (MISC, g_print ("clip rgn box %d: %dx%d@+%d+%d\n",
1031 rect->right-rect->left,
1032 rect->bottom-rect->top,
1033 rect->left, rect->top));
1035 if (rect->left < rgndata->rdh.rcBound.left)
1036 rgndata->rdh.rcBound.left = rect->left;
1037 if (rect->right > rgndata->rdh.rcBound.right)
1038 rgndata->rdh.rcBound.right = rect->right;
1039 if (rect->top < rgndata->rdh.rcBound.top)
1040 rgndata->rdh.rcBound.top = rect->top;
1041 if (rect->bottom > rgndata->rdh.rcBound.bottom)
1042 rgndata->rdh.rcBound.bottom = rect->bottom;
1044 if ((hrgn = ExtCreateRegion (NULL, nbytes, rgndata)) == NULL)
1045 WIN32_API_FAILED ("ExtCreateRegion"), ok = FALSE;
1047 if (ok && SelectClipRgn (win32_gc->hdc, hrgn) == ERROR)
1048 WIN32_API_FAILED ("SelectClipRgn"), ok = FALSE;
1051 DeleteObject (hrgn);
1054 && (win32_gc->values_mask & GDK_GC_CLIP_MASK)
1055 && win32_gc->hcliprgn != NULL)
1057 if (SelectClipRgn (win32_gc->hdc, win32_gc->hcliprgn) == ERROR)
1058 WIN32_API_FAILED ("SelectClipRgn"), ok = FALSE;
1061 if (gdk_debug_flags & GDK_DEBUG_MISC)
1065 EXTLOGPEN extlogpen;
1069 g_print ("gdk_win32_hdc_get: %d: %#x\n", win32_gc, win32_gc->hdc);
1070 obj = GetCurrentObject (win32_gc->hdc, OBJ_BRUSH);
1071 GetObject (obj, sizeof (LOGBRUSH), &logbrush);
1072 g_print ("brush: style: %s color: %.06x hatch: %#x\n",
1073 (logbrush.lbStyle == BS_HOLLOW ? "HOLLOW" :
1074 (logbrush.lbStyle == BS_PATTERN ? "PATTERN" :
1075 (logbrush.lbStyle == BS_SOLID ? "SOLID" :
1079 obj = GetCurrentObject (win32_gc->hdc, OBJ_PEN);
1080 GetObject (obj, sizeof (EXTLOGPEN), &extlogpen);
1081 g_print ("pen: type: %s style: %s endcap: %s join: %s width: %d brush: %s\n",
1082 ((extlogpen.elpPenStyle & PS_TYPE_MASK) ==
1083 PS_GEOMETRIC ? "GEOMETRIC" : "COSMETIC"),
1084 ((extlogpen.elpPenStyle & PS_STYLE_MASK) ==
1086 ((extlogpen.elpPenStyle & PS_STYLE_MASK) ==
1087 PS_SOLID ? "SOLID" : "???")),
1088 ((extlogpen.elpPenStyle & PS_ENDCAP_MASK) ==
1089 PS_ENDCAP_FLAT ? "FLAT" :
1090 ((extlogpen.elpPenStyle & PS_ENDCAP_MASK) ==
1091 PS_ENDCAP_ROUND ? "ROUND" :
1092 ((extlogpen.elpPenStyle & PS_ENDCAP_MASK) ==
1093 PS_ENDCAP_SQUARE ? "ROUND" :
1094 ((extlogpen.elpPenStyle & PS_ENDCAP_MASK) ==
1095 PS_ENDCAP_SQUARE ? "ROUND" : "???")))),
1096 ((extlogpen.elpPenStyle & PS_JOIN_MASK) ==
1097 PS_JOIN_BEVEL ? "BEVEL" :
1098 ((extlogpen.elpPenStyle & PS_JOIN_MASK) ==
1099 PS_JOIN_MITER ? "MITER" :
1100 ((extlogpen.elpPenStyle & PS_JOIN_MASK) ==
1101 PS_JOIN_ROUND ? "ROUND" : "???"))),
1103 (extlogpen.elpBrushStyle == BS_DIBPATTERN ? "DIBPATTERN" :
1104 (extlogpen.elpBrushStyle == BS_DIBPATTERNPT ? "DIBPATTERNPT" :
1105 (extlogpen.elpBrushStyle == BS_HATCHED ? "HATCHED" :
1106 (extlogpen.elpBrushStyle == BS_HOLLOW ? "HOLLOW" :
1107 (extlogpen.elpBrushStyle == BS_PATTERN ? "PATTERN" :
1108 (extlogpen.elpBrushStyle == BS_SOLID ? "SOLID" : "???")))))));
1109 hrgn = CreateRectRgn (0, 0, 0, 0);
1110 if ((flag = GetClipRgn (win32_gc->hdc, hrgn)) == -1)
1111 WIN32_API_FAILED ("GetClipRgn");
1113 g_print ("no clip region\n");
1116 GetRgnBox (hrgn, &rect);
1117 g_print ("clip region bbox: %dx%d@+%d+%d\n",
1118 rect.right - rect.left,
1119 rect.bottom - rect.top,
1120 rect.left, rect.top);
1124 return win32_gc->hdc;
1128 gdk_win32_hdc_release (GdkDrawable *drawable,
1130 GdkGCValuesMask usage)
1132 GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
1133 HGDIOBJ hpen = NULL;
1136 if (usage & GDK_GC_FOREGROUND)
1138 if ((hpen = GetCurrentObject (win32_gc->hdc, OBJ_PEN)) == NULL)
1139 WIN32_GDI_FAILED ("GetCurrentObject");
1141 if ((hbr = GetCurrentObject (win32_gc->hdc, OBJ_BRUSH)) == NULL)
1142 WIN32_GDI_FAILED ("GetCurrentObject");
1145 if (!RestoreDC (win32_gc->hdc, win32_gc->saved_dc))
1146 WIN32_GDI_FAILED ("RestoreDC");
1148 if (colormap_private != NULL
1149 && colormap_private->xcolormap->rc_palette
1150 && colormap_private->xcolormap->stale)
1152 SelectPalette (win32_gc->hdc, GetStockObject (DEFAULT_PALETTE), FALSE);
1153 if (!UnrealizeObject (colormap_private->xcolormap->palette))
1154 WIN32_GDI_FAILED ("UnrealizeObject");
1157 if (GDK_IS_PIXMAP (drawable))
1159 if (!DeleteDC (win32_gc->hdc))
1160 WIN32_GDI_FAILED ("DeleteDC");
1164 ReleaseDC (win32_gc->hwnd, win32_gc->hdc);
1168 if (!DeleteObject (hpen))
1169 WIN32_GDI_FAILED ("DeleteObject");
1172 if (!DeleteObject (hbr))
1173 WIN32_GDI_FAILED ("DeleteObject");
1175 win32_gc->hdc = NULL;
1178 /* This function originally from Jean-Edouard Lachand-Robert, and
1179 * available at www.codeguru.com. Simplified for our needs, now
1180 * handles just one-bit deep bitmaps (in Window parlance, ie those
1181 * that GDK calls bitmaps (and not pixmaps), with zero pixels being
1186 * BitmapToRegion : Create a region from the "non-transparent" pixels of
1188 * Author : Jean-Edouard Lachand-Robert
1189 * (http://www.geocities.com/Paris/LeftBank/1160/resume.htm), June 1998.
1193 BitmapToRegion (HBITMAP hBmp)
1201 BITMAPINFOHEADER bmiHeader;
1205 RGBQUAD bmiColors[2];
1214 PALETTEENTRY palPalEntry[2];
1216 static HPALETTE bwPalette = NULL;
1229 /* Create a B&W palette */
1230 if (bwPalette == NULL)
1232 /* Create a b&w palette */
1233 logpal.palVersion = 0x300;
1234 logpal.palNumEntries = 2;
1235 logpal.palPalEntry[0].peRed =
1236 logpal.palPalEntry[0].peGreen =
1237 logpal.palPalEntry[0].peBlue = 0;
1238 logpal.palPalEntry[0].peFlags = 0;
1239 logpal.palPalEntry[1].peRed =
1240 logpal.palPalEntry[1].peGreen =
1241 logpal.palPalEntry[1].peBlue = 0xFF;
1242 logpal.palPalEntry[1].peFlags = 0;
1243 if ((bwPalette = CreatePalette ((LOGPALETTE *) &logpal)) == NULL)
1244 WIN32_GDI_FAILED ("CreatePalette");
1247 /* Create a memory DC inside which we will scan the bitmap content */
1248 hMemDC = CreateCompatibleDC (NULL);
1251 WIN32_GDI_FAILED ("CreateCompatibleDC");
1255 SelectPalette (hMemDC, bwPalette, FALSE);
1256 RealizePalette (hMemDC);
1258 /* Get bitmap size */
1259 GetObject(hBmp, sizeof(bm), &bm);
1261 /* Create a 8 bits depth bitmap and select it into the memory DC */
1262 bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
1263 bmi.bmiHeader.biWidth = bm.bmWidth;
1264 bmi.bmiHeader.biHeight = bm.bmHeight;
1265 bmi.bmiHeader.biPlanes = 1;
1266 bmi.bmiHeader.biBitCount = 8;
1267 bmi.bmiHeader.biCompression = BI_RGB;
1268 bmi.bmiHeader.biSizeImage = 0;
1269 bmi.bmiHeader.biXPelsPerMeter = 0;
1270 bmi.bmiHeader.biYPelsPerMeter = 0;
1271 bmi.bmiHeader.biClrUsed = 2;
1272 bmi.bmiHeader.biClrImportant = 2;
1274 bmi.bmiColors[0] = 0;
1275 bmi.bmiColors[1] = 1;
1276 hbm8 = CreateDIBSection (hMemDC, (BITMAPINFO *)&bmi,
1277 DIB_PAL_COLORS, &pbits8, NULL, 0);
1279 bmi.bmiColors[0].rgbBlue =
1280 bmi.bmiColors[0].rgbGreen =
1281 bmi.bmiColors[0].rgbRed = 0x00;
1282 bmi.bmiColors[0].rgbReserved = 0x00;
1284 bmi.bmiColors[1].rgbBlue =
1285 bmi.bmiColors[1].rgbGreen =
1286 bmi.bmiColors[1].rgbRed = 0xFF;
1287 bmi.bmiColors[0].rgbReserved = 0x00;
1289 hbm8 = CreateDIBSection (hMemDC, (BITMAPINFO *)&bmi,
1290 DIB_RGB_COLORS, &pbits8, NULL, 0);
1294 WIN32_GDI_FAILED ("CreateDIBSection");
1299 holdBmp = (HBITMAP) SelectObject (hMemDC, hbm8);
1301 /* Create a DC just to copy the bitmap into the memory DC*/
1302 hDC = CreateCompatibleDC (hMemDC);
1305 WIN32_GDI_FAILED ("CreateCompatibleDC");
1306 SelectObject (hMemDC, holdBmp);
1307 DeleteObject (hbm8);
1312 /* Get how many bytes per row we have for the bitmap bits */
1313 GetObject (hbm8, sizeof (bm8), &bm8);
1315 /* Hans Breuer found a fix to the long-standing erroneous behaviour
1316 * on NT 4.0: There seems to be a bug in Win NT 4.0 GDI: scanlines
1317 * in bitmaps are dword aligned on both Win95 and NT. In the case of
1318 * a bitmap with 22 bytes worth of width, GetObject above returns
1319 * with bmWidth == 22. On Win95 bmWidthBytes == 24, as it should be,
1320 * but on NT is it 22. We need to correct this here.
1322 bm8.bmWidthBytes = (((bm8.bmWidthBytes-1)/4)+1)*4; /* dword aligned!! */
1324 /* Copy the bitmap into the memory DC*/
1325 holdBmp2 = (HBITMAP) SelectObject (hDC, hBmp);
1327 if (!BitBlt (hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY))
1329 WIN32_GDI_FAILED ("BitBlt");
1330 SelectObject (hDC, holdBmp2);
1331 SelectObject (hMemDC, holdBmp);
1332 DeleteObject (hbm8);
1336 SelectObject (hDC, holdBmp2);
1339 /* For better performances, we will use the ExtCreateRegion()
1340 * function to create the region. This function take a RGNDATA
1341 * structure on entry. We will add rectangles by amount of
1342 * ALLOC_UNIT number in this structure.
1344 #define ALLOC_UNIT 100
1345 maxRects = ALLOC_UNIT;
1347 pData = g_malloc (sizeof (RGNDATAHEADER) + (sizeof (RECT) * maxRects));
1348 pData->rdh.dwSize = sizeof (RGNDATAHEADER);
1349 pData->rdh.iType = RDH_RECTANGLES;
1350 pData->rdh.nCount = pData->rdh.nRgnSize = 0;
1351 SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
1353 /* Scan each bitmap from bottom to top (the bitmap is inverted vertically)*/
1354 p8 = (BYTE *) pbits8 + (bm8.bmHeight - 1) * bm8.bmWidthBytes;
1355 for (y = 0; y < bm.bmHeight; y++)
1357 /* Scan each bitmap row from left to right*/
1358 for (x = 0; x < bm.bmWidth; x++)
1360 /* Search for a continuous range of "non transparent pixels"*/
1363 while (x < bm.bmWidth)
1366 /* This pixel is "transparent"*/
1375 /* Add the pixels (x0, y) to (x, y+1) as a new rectangle
1378 if (pData->rdh.nCount >= maxRects)
1380 maxRects += ALLOC_UNIT;
1381 pData = g_realloc (pData, sizeof(RGNDATAHEADER)
1382 + (sizeof(RECT) * maxRects));
1384 pr = (RECT *) &pData->Buffer;
1385 SetRect (&pr[pData->rdh.nCount], x0, y, x, y+1);
1386 if (x0 < pData->rdh.rcBound.left)
1387 pData->rdh.rcBound.left = x0;
1388 if (y < pData->rdh.rcBound.top)
1389 pData->rdh.rcBound.top = y;
1390 if (x > pData->rdh.rcBound.right)
1391 pData->rdh.rcBound.right = x;
1392 if (y+1 > pData->rdh.rcBound.bottom)
1393 pData->rdh.rcBound.bottom = y+1;
1394 pData->rdh.nCount++;
1396 /* On Windows98, ExtCreateRegion() may fail if the
1397 * number of rectangles is too large (ie: >
1398 * 4000). Therefore, we have to create the region by
1401 if (pData->rdh.nCount == 2000)
1403 HRGN h = ExtCreateRegion (NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
1406 CombineRgn(hRgn, hRgn, h, RGN_OR);
1411 pData->rdh.nCount = 0;
1412 SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
1417 /* Go to next row (remember, the bitmap is inverted vertically)*/
1418 p8 -= bm8.bmWidthBytes;
1421 /* Create or extend the region with the remaining rectangles*/
1422 h = ExtCreateRegion (NULL, sizeof (RGNDATAHEADER)
1423 + (sizeof (RECT) * maxRects), pData);
1426 CombineRgn (hRgn, hRgn, h, RGN_OR);
1433 SelectObject(hMemDC, holdBmp);
1434 DeleteObject (hbm8);