gtk/gdk/win32/gdkgc-win32.c
Tor Lillqvist e96a41be45 gdk/win32/gdkprivate-win32.h Rename all global variables and functions to
2002-11-12  Tor Lillqvist  <tml@iki.fi>

	* gdk/win32/gdkprivate-win32.h
	* gdk/win32/*.c: Rename all global variables and functions to
	start with underscore.

	Merge from stable:

	More work on the Win32 backend. The cause of some scrolling
	problems was that SetWindowPos() and ScrollWindowEx() don't blit
	those parts of the window they think are invalid. As we didn't
	keep Windows's update region in synch with GDK's, Windows thought
	those areas that in fact had been updated were invalid. Calling
	ValidateRgn() in _gdk_windowing_window_queue_antiexpose() seems to
	be an elegant and efficient solution, removing from Windows's
	update region those areas we are about to repaint proactively.

	In some cases garbage leftover values were used for the clip
	origin in GdkGCWin32. This showed up as odd blank areas around the
	pixmaps included in the Text Widget in gtk-demo.

	Having the clip region either as a GdkRegion or a HRGN in
	GdkGCWin32 was unnecessary, it's better to just use a HRGN.

	The translation and antiexpose queue handling in
	gdkgeometry-win32.c seems unnecessary (and not implementable in
	the same way as on X11 anyway, no serial numbers) on Windows,
	ifdeffed out.

	Don't (try to) do guffaw scrolling as there is no static window
	gravity on Windows. Guffaw scrolling would be unnecessary anyway,
	as there is the ScrollWindow() API. This improves the behaviour of
	the Text Widget demo in gtk-demo a lot. But I have no idea how the
	lack of static win gravity should be handled in other places where
	the X11 code uses it. Especially _gdk_window_move_resize_child().

	There is still some problem in expose handling. By moving an
	obscuring window back and forth over testgtk's main window, for
	instance, every now and then you typically get narrow vertical or
	horizontal strips of pixels that haven't been properly redrawn
	after being exposed. A fencepost error somewhere?

	Otherwise, all of testgtk and gtk-demo except "big windows" now
	seem to work pretty well.

	Bug #79720 should be fixed now.

	* gdk/win32/gdkcolor-win32.c (gdk_win32_color_to_string,
	gdk_win32_print_paletteentries, gdk_win32_print_system_palette,
	gdk_win32_print_hpalette)
	* gdk/win32/gdkdrawable-win32.c (gdk_win32_drawable_description)
	* gdk/win32/gdkevents-win32.c (gdk_win32_message_name):
	Move all debugging helper functions to gdkmain-win32.c.

	* gdk/win32/gdkdrawable-win32.c (_gdk_win32_draw_tiles):
	Rewrite. Make static. Must take tile origin parameters, too.

	(gdk_win32_draw_rectangle): Pass the tile/stipple origin to
	_gdk_win32_draw_tiles(). Remove #if 0 code.

	(blit_inside_window): Don't call ScrollDC(), that didn't work at
	all like I thought. A simple call to BitBlt() is enough.

	* gdk/win32/gdkevents-win32.c (gdk_event_translate) Remove unused
	latin_locale_loaded variable.

	(_gdk_win32_get_next_tick): New function. Used to make sure
	timestamps of events are always increasing, both in events
	generated from the window procedure and in events gotten via
	PeekMessage(). Not sure whether this is actually useful, but it
	seemed as a good idea.

	(real_window_procedure): Don't use a local GdkEventPrivate
	variable. Don't attempt any compression of configure or expose
	events here, handled elsewhere.

	(erase_background): Accumulate window offsets when traversing up
	the parent chain for GDK_PARENT_RELATIVE_BG, in order to get
	correct alignment of background pixmaps. Don't fill with
	BLACK_BRUSH if GDK_NO_BG.

	(gdk_event_get_graphics_expose): A bit more verbose debugging output.

	(gdk_event_translate): Use _gdk_win32_get_next_tick(). In the
	WM_PAINT handler, don't check for empty update rect. When we get a
	WM_PAINT, the update region isn't empty. And if it for some
	strange reason is, that will be handled later anyway. Call
	GetUpdateRgn() before calling BeginPaint() and EndPaint() (which
	empty the update region).

	* gdk/win32/gdkdnd-win32.c
	* gdk/win32/gdkinput-win32.c:
	Use _gdk_win32_get_next_tick().

	* gdk/win32/gdkfont-win32.c: Use %p to print HFONTs.

	(gdk_text_size): Remove, unused.

	* gdk/win32/gdkgc-win32.c:  Set clip origins to zero
	when appropriate.

	(gdk_gc_copy): Increase refcount on colormap if present.

	(gdk_win32_hdc_get): Handle just hcliprgn. If we have a stipple,
	combine it with clip region after selecting into the DC.

	(_gdk_win32_bitmap_to_hrgn): Rename from _gdk_win32_bitmap_to_region.

	(_gdk_win3_gdkregion_to_hrgn): New function, code snippet
	extracted from gdk_win32_hdc_get().

	* gdk/win32/gdkgeometry-win32.c: Ifdef out the translate_queue
	handling.

	(gdk_window_copy_area_scroll): Increase clipRect to avoid
	ScrollWindowEx() not scrolling pixels it thinks are invalid.
	Scroll also children with the ScrollWindowEx() call. No need to
	call gdk_window_move() on the children.

	(gdk_window_scroll): Don't do guffaw scrolling.

	(gdk_window_compute_position): Fix typo, used win32_y where x was
	intended.

	(gdk_window_premove, gdk_window_postmove,
	gdk_window_clip_changed): Add debugging output.

	(_gdk_windowing_window_queue_antiexpose): Just call ValidateRgn()
	on the region.

	(_gdk_window_process_expose): No use for the serial number
	parameter now. Instead of a rectangle, take a region parameter, as
	Windows gives us one in WM_PAINT.

	* gdk/win32/gdkmain-win32.c (_gdk_win32_lbstyle_to_string,
	_gdk_win32_pstype_to_string, _gdk_win32_psstyle_to_string,
	_gdk_win32_psendcap_to_string, _gdk_win32_psjoin_to_string,
	_gdk_win32_rect_to_string, _gdk_win32_gdkrectangle_to_string,
	_gdk_win32_gdkregion_to_string): New debugging functions.

	(static_printf): Helper function for the above. sprintfs into a
	static circular buffer, return value should be used "soon".

	* gdk/win32/gdkwindow-win32.c (gdk_propagate_shapes): Plug memory
	leak, free list after use.

	(gdk_window_gravity_works): Remove, we know that there is no such
	thing on Windows.

	(gdk_window_set_static_bit_gravity,
	gdk_window_set_static_win_gravity): Ditto, remove, they didn't do
	anything anyway.

	(_gdk_windowing_window_init, gdk_window_foreign_new): Call
	_gdk_window_init_position() like in the X11 backend.

	(gdk_window_reparent): Don't call the now nonexistent
	gdk_window_set_static_win_gravity(). No idea what should be done
	instead.

	(gdk_window_get_geometry): The returned x and y should be relative
	to parent. Used to be always zero..

	(gdk_window_set_static_gravities): Return FALSE if trying to set
	static gravity.

	* gdk/win32/gdkprivate-win32.h: Drop the clip_region field from
	GdkGCWin32. Only use the HRGN hcliprgn. Declare new
	functions.

	* gdk/win32/*.c: Use new debugging functions.

	* gdk/win32/rc/gdk.rc.in: Update copyright year.
2002-11-12 22:17:48 +00:00

1219 lines
34 KiB
C

/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
* Copyright (C) 1998-2002 Tor Lillqvist
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
/*
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#include <string.h>
#include "gdkgc.h"
#include "gdkfont.h"
#include "gdkpixmap.h"
#include "gdkregion-generic.h"
#include "gdkprivate-win32.h"
static void gdk_win32_gc_get_values (GdkGC *gc,
GdkGCValues *values);
static void gdk_win32_gc_set_values (GdkGC *gc,
GdkGCValues *values,
GdkGCValuesMask values_mask);
static void gdk_win32_gc_set_dashes (GdkGC *gc,
gint dash_offset,
gint8 dash_list[],
gint n);
static void gdk_gc_win32_class_init (GdkGCWin32Class *klass);
static void gdk_gc_win32_finalize (GObject *object);
static gpointer parent_class = NULL;
GType
_gdk_gc_win32_get_type (void)
{
static GType object_type = 0;
if (!object_type)
{
static const GTypeInfo object_info =
{
sizeof (GdkGCWin32Class),
(GBaseInitFunc) NULL,
(GBaseFinalizeFunc) NULL,
(GClassInitFunc) gdk_gc_win32_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GdkGCWin32),
0, /* n_preallocs */
(GInstanceInitFunc) NULL,
};
object_type = g_type_register_static (GDK_TYPE_GC,
"GdkGCWin32",
&object_info, 0);
}
return object_type;
}
static void
gdk_gc_win32_class_init (GdkGCWin32Class *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GdkGCClass *gc_class = GDK_GC_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
object_class->finalize = gdk_gc_win32_finalize;
gc_class->get_values = gdk_win32_gc_get_values;
gc_class->set_values = gdk_win32_gc_set_values;
gc_class->set_dashes = gdk_win32_gc_set_dashes;
}
static void
gdk_gc_win32_finalize (GObject *object)
{
GdkGCWin32 *win32_gc = GDK_GC_WIN32 (object);
if (win32_gc->hcliprgn != NULL)
DeleteObject (win32_gc->hcliprgn);
if (win32_gc->values_mask & GDK_GC_FONT)
gdk_font_unref (win32_gc->font);
if (win32_gc->values_mask & GDK_GC_TILE)
gdk_drawable_unref (win32_gc->tile);
if (win32_gc->values_mask & GDK_GC_STIPPLE)
gdk_drawable_unref (win32_gc->stipple);
if (win32_gc->pen_dashes)
g_free (win32_gc->pen_dashes);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static void
gdk_win32_gc_values_to_win32values (GdkGCValues *values,
GdkGCValuesMask mask,
GdkGCWin32 *win32_gc)
{
char *s = "";
gint sw, sh;
GDK_NOTE (GC, g_print ("{"));
if (mask & GDK_GC_FOREGROUND)
{
win32_gc->foreground = values->foreground.pixel;
win32_gc->values_mask |= GDK_GC_FOREGROUND;
GDK_NOTE (GC, (g_print ("fg=%.06lx", win32_gc->foreground),
s = ","));
}
if (mask & GDK_GC_BACKGROUND)
{
win32_gc->background = values->background.pixel;
win32_gc->values_mask |= GDK_GC_BACKGROUND;
GDK_NOTE (GC, (g_print ("%sbg=%.06lx", s, win32_gc->background),
s = ","));
}
if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT
|| values->font->type == GDK_FONT_FONTSET))
{
if (win32_gc->font != NULL)
gdk_font_unref (win32_gc->font);
win32_gc->font = values->font;
if (win32_gc->font != NULL)
{
gdk_font_ref (win32_gc->font);
win32_gc->values_mask |= GDK_GC_FONT;
GDK_NOTE (GC, (g_print ("%sfont=%p", s, win32_gc->font),
s = ","));
}
else
{
win32_gc->values_mask &= ~GDK_GC_FONT;
GDK_NOTE (GC, (g_print ("%sfont=NULL", s),
s = ","));
}
}
if (mask & GDK_GC_FUNCTION)
{
GDK_NOTE (GC, (g_print ("%srop2=", s),
s = ","));
switch (values->function)
{
#define CASE(x,y) case GDK_##x: win32_gc->rop2 = R2_##y; GDK_NOTE (GC, g_print (#y)); break
CASE (COPY, COPYPEN);
CASE (INVERT, NOT);
CASE (XOR, XORPEN);
CASE (CLEAR, BLACK);
CASE (AND, MASKPEN);
CASE (AND_REVERSE, MASKPENNOT);
CASE (AND_INVERT, MASKNOTPEN);
CASE (NOOP, NOP);
CASE (OR, MERGEPEN);
CASE (EQUIV, NOTXORPEN);
CASE (OR_REVERSE, MERGEPENNOT);
CASE (COPY_INVERT, NOTCOPYPEN);
CASE (OR_INVERT, MERGENOTPEN);
CASE (NAND, NOTMASKPEN);
CASE (NOR, NOTMERGEPEN);
CASE (SET, WHITE);
#undef CASE
}
win32_gc->values_mask |= GDK_GC_FUNCTION;
}
if (mask & GDK_GC_FILL)
{
win32_gc->fill_style = values->fill;
win32_gc->values_mask |= GDK_GC_FILL;
GDK_NOTE (GC, (g_print ("%sfill=%d", s, win32_gc->fill_style),
s = ","));
}
if (mask & GDK_GC_TILE)
{
if (win32_gc->tile != NULL)
gdk_drawable_unref (win32_gc->tile);
win32_gc->tile = values->tile;
if (win32_gc->tile != NULL)
{
gdk_drawable_ref (win32_gc->tile);
win32_gc->values_mask |= GDK_GC_TILE;
GDK_NOTE (GC,
(g_print ("%stile=%p", s,
GDK_PIXMAP_HBITMAP (win32_gc->tile)),
s = ","));
}
else
{
win32_gc->values_mask &= ~GDK_GC_TILE;
GDK_NOTE (GC, (g_print ("%stile=NULL", s),
s = ","));
}
}
if (mask & GDK_GC_STIPPLE)
{
if (win32_gc->stipple != NULL)
gdk_drawable_unref (win32_gc->stipple);
win32_gc->stipple = values->stipple;
if (win32_gc->stipple != NULL)
{
gdk_drawable_get_size (win32_gc->stipple, &sw, &sh);
#if 0 /* HB: this size limitation is disabled to make radio and check
* buttons work. I got the impression from the API docs, that
* it shouldn't be necessary at all, but win9x would do the clipping
*/
if ( (sw != 8 || sh != 8)
&& !IS_WIN_NT ()) /* HB: the MSDN says it's a Win95 limitation */
{
/* It seems that it *must* be 8x8, at least on my machine.
* Thus, tile an 8x8 bitmap with the stipple in case it is
* smaller, or simply use just the top left 8x8 in case it is
* larger.
*/
gchar dummy[8];
GdkPixmap *bm = gdk_bitmap_create_from_data (NULL, dummy, 8, 8);
GdkGC *gc = gdk_gc_new (bm);
gint i, j;
i = 0;
while (i < 8)
{
j = 0;
while (j < 8)
{
gdk_draw_drawable (bm, gc, win32_gc->stipple, 0, 0, i, j, sw, sh);
j += sh;
}
i += sw;
}
win32_gc->stipple = bm;
gdk_gc_unref (gc);
}
else
#endif
gdk_drawable_ref (win32_gc->stipple);
win32_gc->values_mask |= GDK_GC_STIPPLE;
GDK_NOTE (GC,
(g_print ("%sstipple=%p", s,
GDK_PIXMAP_HBITMAP (win32_gc->stipple)),
s = ","));
}
else
{
win32_gc->values_mask &= ~GDK_GC_STIPPLE;
GDK_NOTE (GC, (g_print ("%sstipple=NULL", s),
s = ","));
}
}
if (mask & GDK_GC_CLIP_MASK)
{
if (win32_gc->hcliprgn != NULL)
DeleteObject (win32_gc->hcliprgn);
if (values->clip_mask != NULL)
{
win32_gc->hcliprgn = _gdk_win32_bitmap_to_hrgn (values->clip_mask);
win32_gc->values_mask |= GDK_GC_CLIP_MASK;
}
else
{
win32_gc->hcliprgn = NULL;
win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
}
GDK_NOTE (GC, (g_print ("%sclip=%p", s, win32_gc->hcliprgn),
s = ","));
}
if (mask & GDK_GC_SUBWINDOW)
{
win32_gc->subwindow_mode = values->subwindow_mode;
win32_gc->values_mask |= GDK_GC_SUBWINDOW;
GDK_NOTE (GC, (g_print ("%ssubw=%d", s, win32_gc->subwindow_mode),
s = ","));
}
if (mask & GDK_GC_TS_X_ORIGIN)
{
win32_gc->values_mask |= GDK_GC_TS_X_ORIGIN;
GDK_NOTE (GC, (g_print ("%sts_x=%d", s, values->ts_x_origin),
s = ","));
}
if (mask & GDK_GC_TS_Y_ORIGIN)
{
win32_gc->values_mask |= GDK_GC_TS_Y_ORIGIN;
GDK_NOTE (GC, (g_print ("%sts_y=%d", s, values->ts_y_origin),
s = ","));
}
if (mask & GDK_GC_CLIP_X_ORIGIN)
{
win32_gc->values_mask |= GDK_GC_CLIP_X_ORIGIN;
GDK_NOTE (GC, (g_print ("%sclip_x=%d", s, values->clip_x_origin),
s = ","));
}
if (mask & GDK_GC_CLIP_Y_ORIGIN)
{
win32_gc->values_mask |= GDK_GC_CLIP_Y_ORIGIN;
GDK_NOTE (GC, (g_print ("%sclip_y=%d", s, values->clip_y_origin),
s = ","));
}
if (mask & GDK_GC_EXPOSURES)
{
win32_gc->graphics_exposures = values->graphics_exposures;
win32_gc->values_mask |= GDK_GC_EXPOSURES;
GDK_NOTE (GC, (g_print ("%sexp=%d", s, win32_gc->graphics_exposures),
s = ","));
}
if (mask & GDK_GC_LINE_WIDTH)
{
win32_gc->pen_width = values->line_width;
win32_gc->values_mask |= GDK_GC_LINE_WIDTH;
GDK_NOTE (GC, (g_print ("%spw=%d", s, win32_gc->pen_width),
s = ","));
}
if (mask & GDK_GC_LINE_STYLE)
{
switch (values->line_style)
{
case GDK_LINE_SOLID:
if (win32_gc->pen_dashes)
{
g_free (win32_gc->pen_dashes);
win32_gc->pen_dashes = NULL;
win32_gc->pen_num_dashes = 0;
}
win32_gc->pen_style &= ~(PS_STYLE_MASK);
win32_gc->pen_style |= PS_SOLID;
break;
case GDK_LINE_ON_OFF_DASH:
case GDK_LINE_DOUBLE_DASH:
if (!win32_gc->pen_dashes)
{
/* setting to PS_DASH probably isn't correct. If I understand the
* xlib docs correctly it should influence the handling of
* line endings ? --hb
*/
win32_gc->pen_style &= ~(PS_STYLE_MASK);
win32_gc->pen_style |= PS_DASH;
}
break;
}
GDK_NOTE (GC, (g_print ("%sps|=PS_STYLE_%s", s, _gdk_win32_psstyle_to_string (win32_gc->pen_style)),
s = ","));
win32_gc->values_mask |= GDK_GC_LINE_STYLE;
}
if (mask & GDK_GC_CAP_STYLE)
{
win32_gc->pen_style &= ~(PS_ENDCAP_MASK);
switch (values->cap_style)
{
case GDK_CAP_NOT_LAST: /* ??? */
case GDK_CAP_BUTT:
win32_gc->pen_style |= PS_ENDCAP_FLAT;
break;
case GDK_CAP_ROUND:
win32_gc->pen_style |= PS_ENDCAP_ROUND;
break;
case GDK_CAP_PROJECTING:
win32_gc->pen_style |= PS_ENDCAP_SQUARE;
break;
}
GDK_NOTE (GC, (g_print ("%sps|=PS_ENDCAP_%s", s, _gdk_win32_psendcap_to_string (win32_gc->pen_style)),
s = ","));
win32_gc->values_mask |= GDK_GC_CAP_STYLE;
}
if (mask & GDK_GC_JOIN_STYLE)
{
win32_gc->pen_style &= ~(PS_JOIN_MASK);
switch (values->join_style)
{
case GDK_JOIN_MITER:
win32_gc->pen_style |= PS_JOIN_MITER;
break;
case GDK_JOIN_ROUND:
win32_gc->pen_style |= PS_JOIN_ROUND;
break;
case GDK_JOIN_BEVEL:
win32_gc->pen_style |= PS_JOIN_BEVEL;
break;
}
GDK_NOTE (GC, (g_print ("%sps|=PS_JOIN_%s", s, _gdk_win32_psjoin_to_string (win32_gc->pen_style)),
s = ","));
win32_gc->values_mask |= GDK_GC_JOIN_STYLE;
}
GDK_NOTE (GC, g_print ("}\n"));
}
GdkGC*
_gdk_win32_gc_new (GdkDrawable *drawable,
GdkGCValues *values,
GdkGCValuesMask mask)
{
GdkGC *gc;
GdkGCWin32 *win32_gc;
/* NOTICE that the drawable here has to be the impl drawable,
* not the publically-visible drawables.
*/
g_return_val_if_fail (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable), NULL);
gc = g_object_new (_gdk_gc_win32_get_type (), NULL);
win32_gc = GDK_GC_WIN32 (gc);
win32_gc->hcliprgn = NULL;
/* Use the same default values as X11 does, even if they don't make
* sense per se. But apps always set fg and bg anyway.
*/
win32_gc->foreground = 0;
win32_gc->background = 1;
win32_gc->font = NULL;
win32_gc->rop2 = R2_COPYPEN;
win32_gc->fill_style = GDK_SOLID;
win32_gc->tile = NULL;
win32_gc->stipple = NULL;
win32_gc->pen_style = PS_GEOMETRIC|PS_ENDCAP_FLAT|PS_JOIN_MITER;
win32_gc->pen_width = 0;
win32_gc->pen_dashes = NULL;
win32_gc->pen_num_dashes = 0;
win32_gc->values_mask = GDK_GC_FUNCTION | GDK_GC_FILL;
GDK_NOTE (GC, g_print ("_gdk_win32_gc_new: "));
gdk_win32_gc_values_to_win32values (values, mask, win32_gc);
win32_gc->hdc = NULL;
win32_gc->hwnd = NULL;
GDK_NOTE (GC, g_print (" = %p\n", gc));
return gc;
}
static void
gdk_win32_gc_get_values (GdkGC *gc,
GdkGCValues *values)
{
GdkGCWin32 *win32_gc = GDK_GC_WIN32 (gc);
values->foreground.pixel = win32_gc->foreground;
values->background.pixel = win32_gc->background;
values->font = win32_gc->font;
switch (win32_gc->rop2)
{
case R2_COPYPEN:
values->function = GDK_COPY; break;
case R2_NOT:
values->function = GDK_INVERT; break;
case R2_XORPEN:
values->function = GDK_XOR; break;
case R2_BLACK:
values->function = GDK_CLEAR; break;
case R2_MASKPEN:
values->function = GDK_AND; break;
case R2_MASKPENNOT:
values->function = GDK_AND_REVERSE; break;
case R2_MASKNOTPEN:
values->function = GDK_AND_INVERT; break;
case R2_NOP:
values->function = GDK_NOOP; break;
case R2_MERGEPEN:
values->function = GDK_OR; break;
case R2_NOTXORPEN:
values->function = GDK_EQUIV; break;
case R2_MERGEPENNOT:
values->function = GDK_OR_REVERSE; break;
case R2_NOTCOPYPEN:
values->function = GDK_COPY_INVERT; break;
case R2_MERGENOTPEN:
values->function = GDK_OR_INVERT; break;
case R2_NOTMASKPEN:
values->function = GDK_NAND; break;
case R2_NOTMERGEPEN:
values->function = GDK_NOR; break;
case R2_WHITE:
values->function = GDK_SET; break;
}
values->fill = win32_gc->fill_style;
values->tile = win32_gc->tile;
values->stipple = win32_gc->stipple;
/* Also the X11 backend always returns a NULL clip_mask */
values->clip_mask = NULL;
values->subwindow_mode = win32_gc->subwindow_mode;
values->ts_x_origin = win32_gc->parent_instance.ts_x_origin;
values->ts_y_origin = win32_gc->parent_instance.ts_y_origin;
values->clip_x_origin = win32_gc->parent_instance.clip_x_origin;
values->clip_y_origin = win32_gc->parent_instance.clip_y_origin;
values->graphics_exposures = win32_gc->graphics_exposures;
values->line_width = win32_gc->pen_width;
if (win32_gc->pen_style & PS_SOLID)
values->line_style = GDK_LINE_SOLID;
else if (win32_gc->pen_style & PS_DASH)
values->line_style = GDK_LINE_ON_OFF_DASH;
else
values->line_style = GDK_LINE_SOLID;
/* PS_ENDCAP_ROUND is zero */
if (win32_gc->pen_style & PS_ENDCAP_FLAT)
values->cap_style = GDK_CAP_BUTT;
else if (win32_gc->pen_style & PS_ENDCAP_SQUARE)
values->cap_style = GDK_CAP_PROJECTING;
else
values->cap_style = GDK_CAP_ROUND;
/* PS_JOIN_ROUND is zero */
if (win32_gc->pen_style & PS_JOIN_MITER)
values->join_style = GDK_JOIN_MITER;
else if (win32_gc->pen_style & PS_JOIN_BEVEL)
values->join_style = GDK_JOIN_BEVEL;
else
values->join_style = GDK_JOIN_ROUND;
}
static void
gdk_win32_gc_set_values (GdkGC *gc,
GdkGCValues *values,
GdkGCValuesMask mask)
{
g_return_if_fail (GDK_IS_GC (gc));
GDK_NOTE (GC, g_print ("gdk_win32_gc_set_values: "));
gdk_win32_gc_values_to_win32values (values, mask, GDK_GC_WIN32 (gc));
}
static void
gdk_win32_gc_set_dashes (GdkGC *gc,
gint dash_offset,
gint8 dash_list[],
gint n)
{
GdkGCWin32 *win32_gc;
int i;
g_return_if_fail (GDK_IS_GC (gc));
g_return_if_fail (dash_list != NULL);
win32_gc = GDK_GC_WIN32 (gc);
/* mark as set, see gdk_win32_gc_values_to_win32values () for the reason */
win32_gc->values_mask |= GDK_GC_LINE_STYLE;
win32_gc->pen_style &= ~(PS_STYLE_MASK);
win32_gc->pen_style |= (PS_GEOMETRIC | PS_USERSTYLE);
win32_gc->pen_num_dashes = n;
win32_gc->pen_dashes = g_new (DWORD, n);
for (i = 0; i < n; i++)
win32_gc->pen_dashes[i] = dash_list[i];
}
void
gdk_gc_set_clip_rectangle (GdkGC *gc,
GdkRectangle *rectangle)
{
GdkGCWin32 *win32_gc;
g_return_if_fail (GDK_IS_GC (gc));
win32_gc = GDK_GC_WIN32 (gc);
if (win32_gc->hcliprgn)
DeleteObject (win32_gc->hcliprgn);
if (rectangle)
{
GDK_NOTE (GC, g_print ("gdk_gc_set_clip_rectangle: %s\n",
_gdk_win32_gdkrectangle_to_string (rectangle)));
win32_gc->hcliprgn = CreateRectRgn (rectangle->x, rectangle->y,
rectangle->x + rectangle->width,
rectangle->y + rectangle->height);
win32_gc->values_mask |= GDK_GC_CLIP_MASK;
}
else
{
GDK_NOTE (GC, g_print ("gdk_gc_set_clip_rectangle: NULL\n"));
win32_gc->hcliprgn = NULL;
win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
}
gc->clip_x_origin = 0;
gc->clip_y_origin = 0;
win32_gc->values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
}
void
gdk_gc_set_clip_region (GdkGC *gc,
GdkRegion *region)
{
GdkGCWin32 *win32_gc;
g_return_if_fail (GDK_IS_GC (gc));
win32_gc = GDK_GC_WIN32 (gc);
if (win32_gc->hcliprgn)
DeleteObject (win32_gc->hcliprgn);
if (region)
{
GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: %s\n",
_gdk_win32_gdkregion_to_string (region)));
win32_gc->hcliprgn = _gdk_win32_gdkregion_to_hrgn (region, 0, 0);
win32_gc->values_mask |= GDK_GC_CLIP_MASK;
}
else
{
GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: NULL\n"));
win32_gc->hcliprgn = NULL;
win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
}
gc->clip_x_origin = 0;
gc->clip_y_origin = 0;
win32_gc->values_mask &= ~(GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN);
}
void
gdk_gc_copy (GdkGC *dst_gc,
GdkGC *src_gc)
{
GdkGCWin32 *dst_win32_gc;
GdkGCWin32 *src_win32_gc;
g_return_if_fail (GDK_IS_GC_WIN32 (dst_gc));
g_return_if_fail (GDK_IS_GC_WIN32 (src_gc));
dst_win32_gc = GDK_GC_WIN32 (dst_gc);
src_win32_gc = GDK_GC_WIN32 (src_gc);
if (dst_gc->colormap)
g_object_unref (G_OBJECT (dst_gc->colormap));
if (dst_win32_gc->hcliprgn != NULL)
DeleteObject (dst_win32_gc->hcliprgn);
if (dst_win32_gc->font != NULL)
gdk_font_unref (dst_win32_gc->font);
if (dst_win32_gc->tile != NULL)
gdk_drawable_unref (dst_win32_gc->tile);
if (dst_win32_gc->stipple != NULL)
gdk_drawable_unref (dst_win32_gc->stipple);
if (dst_win32_gc->pen_dashes)
g_free (dst_win32_gc->pen_dashes);
*dst_win32_gc = *src_win32_gc;
if (dst_gc->colormap)
g_object_ref (G_OBJECT (dst_gc->colormap));
if (dst_win32_gc->hcliprgn)
{
/* create a new region, to copy to */
dst_win32_gc->hcliprgn = CreateRectRgn (0,0,1,1);
/* overwrite from source */
CombineRgn (dst_win32_gc->hcliprgn, src_win32_gc->hcliprgn,
NULL, RGN_COPY);
}
if (dst_win32_gc->font != NULL)
gdk_font_ref (dst_win32_gc->font);
if (dst_win32_gc->tile != NULL)
gdk_drawable_ref (dst_win32_gc->tile);
if (dst_win32_gc->stipple != NULL)
gdk_drawable_ref (dst_win32_gc->stipple);
if (dst_win32_gc->pen_dashes)
dst_win32_gc->pen_dashes = g_memdup (src_win32_gc->pen_dashes,
sizeof (DWORD) * src_win32_gc->pen_num_dashes);
}
static guint bitmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
COLORREF
_gdk_win32_colormap_color (GdkColormap *colormap,
gulong pixel)
{
const GdkVisual *visual;
GdkColormapPrivateWin32 *colormap_private;
guchar r, g, b;
if (colormap == NULL)
return DIBINDEX (pixel & 1);
colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
g_assert (colormap_private != NULL);
visual = colormap->visual;
switch (visual->type)
{
case GDK_VISUAL_GRAYSCALE:
case GDK_VISUAL_PSEUDO_COLOR:
case GDK_VISUAL_STATIC_COLOR:
return PALETTEINDEX (pixel);
case GDK_VISUAL_TRUE_COLOR:
r = (pixel & visual->red_mask) >> visual->red_shift;
r = (r * 255) / bitmask[visual->red_prec];
g = (pixel & visual->green_mask) >> visual->green_shift;
g = (g * 255) / bitmask[visual->green_prec];
b = (pixel & visual->blue_mask) >> visual->blue_shift;
b = (b * 255) / bitmask[visual->blue_prec];
return RGB (r, g, b);
default:
g_assert_not_reached ();
return 0;
}
}
static void
predraw_set_foreground (GdkGC *gc,
GdkColormap *colormap,
gboolean *ok)
{
COLORREF fg;
LOGBRUSH logbrush;
HPEN hpen;
HBRUSH hbr;
GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
GdkColormapPrivateWin32 *colormap_private;
gint k;
if (colormap &&
(colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
colormap->visual->type == GDK_VISUAL_STATIC_COLOR))
{
colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
g_assert (colormap_private != NULL);
if (!(win32_gc->holdpal = SelectPalette (win32_gc->hdc, colormap_private->hpal, FALSE)))
WIN32_GDI_FAILED ("SelectPalette"), *ok = FALSE;
else if ((k = RealizePalette (win32_gc->hdc)) == GDI_ERROR)
WIN32_GDI_FAILED ("RealizePalette"), *ok = FALSE;
else if (k > 0)
GDK_NOTE (COLORMAP, g_print ("predraw_set_foreground: realized %p: %d colors\n",
colormap_private->hpal, k));
}
fg = _gdk_win32_colormap_color (colormap, win32_gc->foreground);
GDK_NOTE (GC, g_print ("predraw_set_foreground: fg=%06lx\n", fg));
if (SetTextColor (win32_gc->hdc, fg) == CLR_INVALID)
WIN32_GDI_FAILED ("SetTextColor"), *ok = FALSE;
/* Create and select pen and brush. */
logbrush.lbStyle = BS_SOLID;
logbrush.lbColor = fg;
logbrush.lbHatch = 0;
if (win32_gc->pen_num_dashes > 0 && !IS_WIN_NT ())
{
/* The Win9x GDI is rather limited so we either draw dotted
* lines ourselve (only horizontal and vertical) or let them
* be drawn solid to avoid implementing a whole line renderer
*/
if (*ok && (hpen = ExtCreatePen (
(win32_gc->pen_style & ~(PS_STYLE_MASK)) | PS_SOLID,
(win32_gc->pen_width > 0 ? win32_gc->pen_width : 1),
&logbrush,
0, NULL)) == NULL)
WIN32_GDI_FAILED ("ExtCreatePen"), *ok = FALSE;
}
else
{
if (*ok && (hpen = ExtCreatePen (win32_gc->pen_style,
(win32_gc->pen_width > 0 ? win32_gc->pen_width : 1),
&logbrush,
win32_gc->pen_num_dashes,
win32_gc->pen_dashes)) == NULL)
WIN32_GDI_FAILED ("ExtCreatePen"), *ok = FALSE;
}
if (*ok && SelectObject (win32_gc->hdc, hpen) == NULL)
WIN32_GDI_FAILED ("SelectObject"), *ok = FALSE;
switch (win32_gc->fill_style)
{
case GDK_OPAQUE_STIPPLED:
if (*ok && (hbr = CreatePatternBrush (GDK_PIXMAP_HBITMAP (win32_gc->stipple))) == NULL)
WIN32_GDI_FAILED ("CreatePatternBrush"), *ok = FALSE;
if (*ok && !SetBrushOrgEx(win32_gc->hdc, gc->ts_x_origin,
gc->ts_y_origin, NULL))
WIN32_GDI_FAILED ("SetBrushOrgEx"), *ok = FALSE;
break;
case GDK_SOLID:
default:
if (*ok && (hbr = CreateSolidBrush (fg)) == NULL)
WIN32_GDI_FAILED ("CreateSolidBrush"), *ok = FALSE;
break;
}
if (*ok)
{
HBRUSH old_hbr = SelectObject (win32_gc->hdc, hbr);
if (old_hbr == NULL)
WIN32_GDI_FAILED ("SelectObject"), *ok = FALSE;
}
}
static void
predraw_set_background (GdkGC *gc,
GdkColormap *colormap,
gboolean *ok)
{
GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
if (win32_gc->values_mask & GDK_GC_BACKGROUND)
{
COLORREF bg = _gdk_win32_colormap_color (colormap, win32_gc->background);
if (SetBkColor (win32_gc->hdc, bg) == CLR_INVALID)
WIN32_GDI_FAILED ("SetBkColor"), *ok = FALSE;
}
else
{
if (!SetBkMode (win32_gc->hdc, TRANSPARENT))
WIN32_GDI_FAILED ("SetBkMode"), *ok = FALSE;
}
}
HDC
gdk_win32_hdc_get (GdkDrawable *drawable,
GdkGC *gc,
GdkGCValuesMask usage)
{
GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
GdkDrawableImplWin32 *impl = NULL;
gboolean ok = TRUE;
g_assert (win32_gc->hdc == NULL);
if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
impl = GDK_DRAWABLE_IMPL_WIN32(drawable);
else if (GDK_IS_WINDOW (drawable))
impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
else if (GDK_IS_PIXMAP (drawable))
impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
else
g_assert_not_reached ();
win32_gc->hwnd = impl->handle;
if (GDK_IS_PIXMAP_IMPL_WIN32 (impl))
{
if ((win32_gc->hdc = CreateCompatibleDC (NULL)) == NULL)
WIN32_GDI_FAILED ("CreateCompatibleDC"), ok = FALSE;
if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
if (ok && SelectObject (win32_gc->hdc, win32_gc->hwnd) == NULL)
WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
}
else
{
if ((win32_gc->hdc = GetDC (win32_gc->hwnd)) == NULL)
WIN32_GDI_FAILED ("GetDC");
if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
WIN32_GDI_FAILED ("SaveDC");
}
if (ok && (usage & GDK_GC_FOREGROUND))
predraw_set_foreground (gc, impl->colormap, &ok);
if (ok && (usage & GDK_GC_BACKGROUND))
predraw_set_background (gc, impl->colormap, &ok);
if (ok && (usage & GDK_GC_FONT))
{
if (SetBkMode (win32_gc->hdc, TRANSPARENT) == 0)
WIN32_GDI_FAILED ("SetBkMode"), ok = FALSE;
if (ok && SetTextAlign (win32_gc->hdc, TA_BASELINE) == GDI_ERROR)
WIN32_GDI_FAILED ("SetTextAlign"), ok = FALSE;
}
if (ok && (win32_gc->values_mask & GDK_GC_FUNCTION))
if (SetROP2 (win32_gc->hdc, win32_gc->rop2) == 0)
WIN32_GDI_FAILED ("SetROP2"), ok = FALSE;
if (ok &&
(win32_gc->values_mask & GDK_GC_CLIP_MASK) &&
win32_gc->hcliprgn != NULL)
{
if (SelectClipRgn (win32_gc->hdc, win32_gc->hcliprgn) == ERROR)
WIN32_API_FAILED ("SelectClipRgn"), ok = FALSE;
/* Combine the fillmode-stipple with the clip region */
if (ok &&
(win32_gc->values_mask & GDK_GC_STIPPLE) &&
(win32_gc->values_mask & GDK_GC_FILL) &&
(win32_gc->fill_style == GDK_STIPPLED))
{
HRGN hstipplergn;
if ((hstipplergn = _gdk_win32_bitmap_to_hrgn (win32_gc->stipple)) == NULL)
;
else if (win32_gc->values_mask & (GDK_GC_TS_X_ORIGIN | GDK_GC_TS_Y_ORIGIN) &&
OffsetRgn (hstipplergn,
win32_gc->values_mask & GDK_GC_TS_X_ORIGIN ? gc->ts_x_origin : 0,
win32_gc->values_mask & GDK_GC_TS_Y_ORIGIN ? gc->ts_y_origin : 0) == ERROR)
WIN32_API_FAILED ("OffsetRgn");
else if (ExtSelectClipRgn (win32_gc->hdc, hstipplergn, RGN_AND) == ERROR)
WIN32_API_FAILED ("ExtSelectClipRgn");
if (hstipplergn != NULL && !DeleteObject (hstipplergn))
WIN32_API_FAILED ("DeleteObject");
}
if (ok && win32_gc->values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN) &&
OffsetClipRgn (win32_gc->hdc,
win32_gc->values_mask & GDK_GC_CLIP_X_ORIGIN ? gc->clip_x_origin : 0,
win32_gc->values_mask & GDK_GC_CLIP_Y_ORIGIN ? gc->clip_y_origin : 0) == ERROR)
WIN32_API_FAILED ("OffsetClipRgn"), ok = FALSE;
}
GDK_NOTE (GC, (g_print ("gdk_win32_hdc_get: "),
_gdk_win32_print_dc (win32_gc->hdc)));
return win32_gc->hdc;
}
void
gdk_win32_hdc_release (GdkDrawable *drawable,
GdkGC *gc,
GdkGCValuesMask usage)
{
GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
GdkDrawableImplWin32 *impl = NULL;
HGDIOBJ hpen = NULL;
HGDIOBJ hbr = NULL;
GDK_NOTE (GC, g_print ("gdk_win32_hdc_release: %p\n", win32_gc->hdc));
if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
impl = GDK_DRAWABLE_IMPL_WIN32(drawable);
else if (GDK_IS_WINDOW (drawable))
impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
else if (GDK_IS_PIXMAP (drawable))
impl = GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
else
g_assert_not_reached ();
if (win32_gc->holdpal != NULL)
{
gint k;
if (!SelectPalette (win32_gc->hdc, win32_gc->holdpal, FALSE))
WIN32_GDI_FAILED ("SelectPalette");
else if ((k = RealizePalette (win32_gc->hdc)) == GDI_ERROR)
WIN32_GDI_FAILED ("RealizePalette");
else if (k > 0)
GDK_NOTE (COLORMAP, g_print ("gdk_win32_hdc_release: realized %p: %d colors\n",
win32_gc->holdpal, k));
win32_gc->holdpal = NULL;
}
if (usage & GDK_GC_FOREGROUND)
{
if ((hpen = GetCurrentObject (win32_gc->hdc, OBJ_PEN)) == NULL)
WIN32_GDI_FAILED ("GetCurrentObject");
if ((hbr = GetCurrentObject (win32_gc->hdc, OBJ_BRUSH)) == NULL)
WIN32_GDI_FAILED ("GetCurrentObject");
}
if (!RestoreDC (win32_gc->hdc, win32_gc->saved_dc))
WIN32_GDI_FAILED ("RestoreDC");
if (GDK_IS_PIXMAP_IMPL_WIN32 (impl))
{
if (!DeleteDC (win32_gc->hdc))
WIN32_GDI_FAILED ("DeleteDC");
}
else
{
if (!ReleaseDC (win32_gc->hwnd, win32_gc->hdc))
WIN32_GDI_FAILED ("ReleaseDC");
}
if (hpen != NULL)
if (!DeleteObject (hpen))
WIN32_GDI_FAILED ("DeleteObject");
if (hbr != NULL)
if (!DeleteObject (hbr))
WIN32_GDI_FAILED ("DeleteObject");
win32_gc->hdc = NULL;
}
/* This function originally from Jean-Edouard Lachand-Robert, and
* available at www.codeguru.com. Simplified for our needs, not sure
* how much of the original code left any longer. Now handles just
* one-bit deep bitmaps (in Window parlance, ie those that GDK calls
* bitmaps (and not pixmaps), with zero pixels being transparent.
*/
/* _gdk_win32_bitmap_to_hrgn : Create a region from the
* "non-transparent" pixels of a bitmap.
*/
HRGN
_gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap)
{
HRGN hRgn = NULL;
HRGN h;
DWORD maxRects;
RGNDATA *pData;
GdkImage *image;
guchar *p;
gint x, y;
image = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->image;
g_assert (image->depth == 1);
/* For better performances, we will use the ExtCreateRegion()
* function to create the region. This function take a RGNDATA
* structure on entry. We will add rectangles by amount of
* ALLOC_UNIT number in this structure.
*/
#define ALLOC_UNIT 100
maxRects = ALLOC_UNIT;
pData = g_malloc (sizeof (RGNDATAHEADER) + (sizeof (RECT) * maxRects));
pData->rdh.dwSize = sizeof (RGNDATAHEADER);
pData->rdh.iType = RDH_RECTANGLES;
pData->rdh.nCount = pData->rdh.nRgnSize = 0;
SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
for (y = 0; y < image->height; y++)
{
/* Scan each bitmap row from left to right*/
p = (guchar *) image->mem + y * image->bpl;
for (x = 0; x < image->width; x++)
{
/* Search for a continuous range of "non transparent pixels"*/
gint x0 = x;
while (x < image->width)
{
if ((((p[x/8])>>(7-(x%8)))&1) == 0)
/* This pixel is "transparent"*/
break;
x++;
}
if (x > x0)
{
RECT *pr;
/* Add the pixels (x0, y) to (x, y+1) as a new rectangle
* in the region
*/
if (pData->rdh.nCount >= maxRects)
{
maxRects += ALLOC_UNIT;
pData = g_realloc (pData, sizeof(RGNDATAHEADER)
+ (sizeof(RECT) * maxRects));
}
pr = (RECT *) &pData->Buffer;
SetRect (&pr[pData->rdh.nCount], x0, y, x, y+1);
if (x0 < pData->rdh.rcBound.left)
pData->rdh.rcBound.left = x0;
if (y < pData->rdh.rcBound.top)
pData->rdh.rcBound.top = y;
if (x > pData->rdh.rcBound.right)
pData->rdh.rcBound.right = x;
if (y+1 > pData->rdh.rcBound.bottom)
pData->rdh.rcBound.bottom = y+1;
pData->rdh.nCount++;
/* On Windows98, ExtCreateRegion() may fail if the
* number of rectangles is too large (ie: >
* 4000). Therefore, we have to create the region by
* multiple steps.
*/
if (pData->rdh.nCount == 2000)
{
HRGN h = ExtCreateRegion (NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData);
if (hRgn)
{
CombineRgn(hRgn, hRgn, h, RGN_OR);
DeleteObject(h);
}
else
hRgn = h;
pData->rdh.nCount = 0;
SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
}
}
}
}
/* Create or extend the region with the remaining rectangles*/
h = ExtCreateRegion (NULL, sizeof (RGNDATAHEADER)
+ (sizeof (RECT) * maxRects), pData);
if (hRgn)
{
CombineRgn (hRgn, hRgn, h, RGN_OR);
DeleteObject (h);
}
else
hRgn = h;
/* Clean up*/
g_free (pData);
return hRgn;
}
HRGN
_gdk_win32_gdkregion_to_hrgn (GdkRegion *region,
gint x_origin,
gint y_origin)
{
HRGN hrgn;
RGNDATA *rgndata;
RECT *rect;
GdkRegionBox *boxes = region->rects;
guint nbytes =
sizeof (RGNDATAHEADER) + (sizeof (RECT) * region->numRects);
int i;
rgndata = g_malloc (nbytes);
rgndata->rdh.dwSize = sizeof (RGNDATAHEADER);
rgndata->rdh.iType = RDH_RECTANGLES;
rgndata->rdh.nCount = rgndata->rdh.nRgnSize = 0;
SetRect (&rgndata->rdh.rcBound,
G_MAXSHORT, G_MAXSHORT, G_MINSHORT, G_MINSHORT);
for (i = 0; i < region->numRects; i++)
{
rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++;
rect->left = CLAMP (boxes[i].x1 + x_origin,
G_MINSHORT, G_MAXSHORT);
rect->right = CLAMP (boxes[i].x2 + x_origin,
G_MINSHORT, G_MAXSHORT);
rect->top = CLAMP (boxes[i].y1 + y_origin,
G_MINSHORT, G_MAXSHORT);
rect->bottom = CLAMP (boxes[i].y2 + y_origin,
G_MINSHORT, G_MAXSHORT);
if (rect->left < rgndata->rdh.rcBound.left)
rgndata->rdh.rcBound.left = rect->left;
if (rect->right > rgndata->rdh.rcBound.right)
rgndata->rdh.rcBound.right = rect->right;
if (rect->top < rgndata->rdh.rcBound.top)
rgndata->rdh.rcBound.top = rect->top;
if (rect->bottom > rgndata->rdh.rcBound.bottom)
rgndata->rdh.rcBound.bottom = rect->bottom;
}
if ((hrgn = ExtCreateRegion (NULL, nbytes, rgndata)) == NULL)
WIN32_API_FAILED ("ExtCreateRegion");
g_free (rgndata);
return (hrgn);
}