/* GDK - The GIMP Drawing Kit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ * Copyright (C) 1998-2004 Tor Lillqvist
+ * Copyright (C) 2000-2004 Hans Breuer
*
* This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
+ * 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
- * Library General Public License for more details.
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU Library General Public
+ * 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-1999. See the AUTHORS
+ * 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 "config.h"
+#define LINE_ATTRIBUTES (GDK_GC_LINE_WIDTH|GDK_GC_LINE_STYLE| \
+ GDK_GC_CAP_STYLE|GDK_GC_JOIN_STYLE)
+#include <config.h>
#include <string.h>
#include "gdkgc.h"
#include "gdkfont.h"
#include "gdkpixmap.h"
-#include "gdkprivate.h"
-#include "gdkx.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;
-GdkGC*
-gdk_gc_new (GdkWindow *window)
+ 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)
{
- return gdk_gc_new_with_values (window, NULL, 0);
+ 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;
}
-GdkGC*
-gdk_gc_new_with_values (GdkWindow *window,
- GdkGCValues *values,
- GdkGCValuesMask values_mask)
+static void
+gdk_gc_win32_finalize (GObject *object)
{
- GdkGC *gc;
- GdkGCPrivate *private;
- static GdkColor black;
- static GdkColor white;
- static gboolean beenhere = FALSE;
+ 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->pen_dashes)
+ g_free (win32_gc->pen_dashes);
+
+ G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+fixup_pen (GdkGCWin32 *win32_gc)
+{
+ win32_gc->pen_style = 0;
- if (!beenhere)
+ /* First look at GDK width and end cap style, set GDI pen type and
+ * end cap.
+ */
+ if (win32_gc->pen_width == 0 &&
+ win32_gc->cap_style == GDK_CAP_NOT_LAST)
{
- gdk_color_black (gdk_colormap_get_system (), &black);
- gdk_color_white (gdk_colormap_get_system (), &white);
- beenhere = TRUE;
+ /* Use a cosmetic pen, always width 1 */
+ win32_gc->pen_style |= PS_COSMETIC;
+ }
+ else if (win32_gc->pen_width <= 1 &&
+ win32_gc->cap_style == GDK_CAP_BUTT)
+ {
+ /* For 1 pixel wide lines PS_ENDCAP_ROUND means draw both ends,
+ * even for one pixel length lines. But if we are drawing dashed
+ * lines we can't use PS_ENDCAP_ROUND.
+ */
+ if (win32_gc->line_style == GDK_LINE_SOLID)
+ win32_gc->pen_style |= PS_GEOMETRIC | PS_ENDCAP_ROUND;
+ else
+ win32_gc->pen_style |= PS_GEOMETRIC | PS_ENDCAP_FLAT;
+ }
+ else
+ {
+ win32_gc->pen_style |= PS_GEOMETRIC;
+ switch (win32_gc->cap_style)
+ {
+ /* For non-zero-width lines X11's CapNotLast works like CapButt */
+ 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;
+ }
}
- g_return_val_if_fail (window != NULL, NULL);
-
- if (GDK_DRAWABLE_DESTROYED (window))
- return NULL;
+ /* Next look at GDK line style, set GDI pen style attribute */
+ switch (win32_gc->line_style)
+ {
+ case GDK_LINE_SOLID:
+ win32_gc->pen_style |= PS_SOLID;
+ break;
+ case GDK_LINE_ON_OFF_DASH:
+ case GDK_LINE_DOUBLE_DASH:
+ if (win32_gc->pen_dashes == NULL)
+ {
+ win32_gc->pen_dashes = g_new (DWORD, 1);
+ win32_gc->pen_dashes[0] = 4;
+ win32_gc->pen_num_dashes = 1;
+ }
+ if (G_WIN32_IS_NT_BASED ())
+ {
+ if (!(win32_gc->pen_style & PS_TYPE_MASK) == PS_GEOMETRIC &&
+ win32_gc->pen_dashes[0] == 1 &&
+ (win32_gc->pen_num_dashes == 1 ||
+ (win32_gc->pen_num_dashes == 2 && win32_gc->pen_dashes[0] == 1)))
+ win32_gc->pen_style |= PS_ALTERNATE;
+ else
+ win32_gc->pen_style |= PS_USERSTYLE;
+ }
+ else
+ {
+ /* Render "short" on-off dashes drawn with R2_COPYPEN and a
+ * cosmetic pen using PS_DOT
+ */
+ if (win32_gc->line_style == GDK_LINE_ON_OFF_DASH &&
+ win32_gc->rop2 == R2_COPYPEN &&
+ (win32_gc->pen_style & PS_TYPE_MASK) == PS_COSMETIC &&
+ win32_gc->pen_dashes[0] <= 2 &&
+ (win32_gc->pen_num_dashes == 1 ||
+ (win32_gc->pen_num_dashes == 2 && win32_gc->pen_dashes[1] <= 2)))
+ win32_gc->pen_style |= PS_DOT;
+ else
+ /* Otherwise render opaque lines solid, horizontal or
+ * vertical ones will be dashed manually, see
+ * gdkdrawable-win32.c.
+ */
+ win32_gc->pen_style |= PS_SOLID;
+ }
+ break;
+ }
- private = g_new (GdkGCPrivate, 1);
- gc = (GdkGC*) private;
+ /* Last, for if the GDI pen is geometric, set the join attribute */
+ if ((win32_gc->pen_style & PS_TYPE_MASK) == PS_GEOMETRIC)
+ {
+ switch (win32_gc->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;
+ }
+ }
+}
- private->ref_count = 1;
- private->rop2 = R2_COPYPEN;
- private->fill_style = GDK_SOLID;
- private->values_mask = values_mask;
- private->values_mask |= GDK_GC_FUNCTION | GDK_GC_FILL;
+static void
+gdk_win32_gc_values_to_win32values (GdkGCValues *values,
+ GdkGCValuesMask mask,
+ GdkGCWin32 *win32_gc)
+{
+ char *s = "";
- GDK_NOTE (MISC, g_print ("gdk_gc_new: {"));
+ GDK_NOTE (GC, g_print ("{"));
- if (values_mask & GDK_GC_FOREGROUND)
+ if (mask & GDK_GC_FOREGROUND)
{
- private->foreground = values->foreground;
+ win32_gc->values_mask |= GDK_GC_FOREGROUND;
+ GDK_NOTE (GC, (g_print ("fg=%.06x",
+ _gdk_gc_get_fg_pixel (&win32_gc->parent_instance)),
+ s = ","));
}
- else
- private->foreground = black;
- if (values_mask & GDK_GC_BACKGROUND)
+ if (mask & GDK_GC_BACKGROUND)
{
- private->background = values->background;
+ win32_gc->values_mask |= GDK_GC_BACKGROUND;
+ GDK_NOTE (GC, (g_print ("%sbg=%.06x", s,
+ _gdk_gc_get_bg_pixel (&win32_gc->parent_instance)),
+ s = ","));
}
- else
- private->background = white;
- if ((values_mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT
- || values->font->type == GDK_FONT_FONTSET))
+ if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT
+ || values->font->type == GDK_FONT_FONTSET))
{
- private->font = values->font;
- gdk_font_ref (private->font);
- GDK_NOTE (MISC, g_print (" font"));
+ 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 = ","));
+ }
}
- else
- private->font = NULL;
- if (values_mask & GDK_GC_FUNCTION)
+ if (mask & GDK_GC_FUNCTION)
{
+ GDK_NOTE (GC, (g_print ("%srop2=", s),
+ s = ","));
switch (values->function)
{
- case GDK_COPY:
- private->rop2 = R2_COPYPEN; break;
- case GDK_INVERT:
- private->rop2 = R2_NOT; break;
- case GDK_XOR:
- private->rop2 = R2_XORPEN; break;
- case GDK_CLEAR:
- private->rop2 = R2_BLACK; break;
- case GDK_AND:
- private->rop2 = R2_MASKPEN; break;
- case GDK_AND_REVERSE:
- private->rop2 = R2_MASKPENNOT; break;
- case GDK_AND_INVERT:
- private->rop2 = R2_MASKNOTPEN; break;
- case GDK_NOOP:
- private->rop2 = R2_NOP; break;
- case GDK_OR:
- private->rop2 = R2_MERGEPEN; break;
- case GDK_EQUIV:
- private->rop2 = R2_NOTXORPEN; break;
- case GDK_OR_REVERSE:
- private->rop2 = R2_MERGEPENNOT; break;
- case GDK_COPY_INVERT:
- private->rop2 = R2_NOTCOPYPEN; break;
- case GDK_OR_INVERT:
- private->rop2 = R2_MERGENOTPEN; break;
- case GDK_NAND:
- private->rop2 = R2_NOTMASKPEN; break;
- case GDK_SET:
- private->rop2 = R2_WHITE; break;
+#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
}
- GDK_NOTE (MISC, g_print (" function=%d", private->rop2));
+ win32_gc->values_mask |= GDK_GC_FUNCTION;
}
- if (values_mask & GDK_GC_FILL)
+ if (mask & GDK_GC_FILL)
{
- private->fill_style = values->fill;
- GDK_NOTE (MISC, g_print (" fill=%d", private->fill_style));
+ win32_gc->values_mask |= GDK_GC_FILL;
+ GDK_NOTE (GC, (g_print ("%sfill=%s", s,
+ _gdk_win32_fill_style_to_string (values->fill)),
+ s = ","));
}
- if (values_mask & GDK_GC_TILE)
+ if (mask & GDK_GC_TILE)
{
- private->tile = values->tile;
- gdk_pixmap_ref (private->tile);
- GDK_NOTE (MISC, g_print (" tile=%#x", GDK_DRAWABLE_XID (private->tile)));
+ if (values->tile != NULL)
+ {
+ win32_gc->values_mask |= GDK_GC_TILE;
+ GDK_NOTE (GC,
+ (g_print ("%stile=%p", s,
+ GDK_PIXMAP_HBITMAP (values->tile)),
+ s = ","));
+ }
+ else
+ {
+ win32_gc->values_mask &= ~GDK_GC_TILE;
+ GDK_NOTE (GC, (g_print ("%stile=NULL", s),
+ s = ","));
+ }
}
- else
- private->tile = NULL;
- if (values_mask & GDK_GC_STIPPLE)
+ if (mask & GDK_GC_STIPPLE)
{
- private->stipple = values->stipple;
- gdk_pixmap_ref (private->stipple);
- GDK_NOTE (MISC, g_print (" stipple=%#x", GDK_DRAWABLE_XID (private->stipple)));
+ if (values->stipple != NULL)
+ {
+ win32_gc->values_mask |= GDK_GC_STIPPLE;
+ GDK_NOTE (GC,
+ (g_print ("%sstipple=%p", s,
+ GDK_PIXMAP_HBITMAP (values->stipple)),
+ s = ","));
+ }
+ else
+ {
+ win32_gc->values_mask &= ~GDK_GC_STIPPLE;
+ GDK_NOTE (GC, (g_print ("%sstipple=NULL", s),
+ s = ","));
+ }
}
- else
- private->stipple = NULL;
- if (values_mask & GDK_GC_CLIP_MASK)
+ if (mask & GDK_GC_CLIP_MASK)
{
- private->clip_region =
- BitmapToRegion ((HBITMAP) GDK_DRAWABLE_XID (values->clip_mask));
- GDK_NOTE (MISC, g_print (" clip=%#x", private->clip_region));
+ 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 = ","));
}
- else
- private->clip_region = NULL;
- if (values_mask & GDK_GC_SUBWINDOW)
+ if (mask & GDK_GC_SUBWINDOW)
{
- private->subwindow_mode = values->subwindow_mode;
- GDK_NOTE (MISC, g_print (" subw=%d", private->subwindow_mode));
+ 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 (values_mask & GDK_GC_TS_X_ORIGIN)
+ if (mask & GDK_GC_TS_X_ORIGIN)
{
- private->ts_x_origin = values->ts_x_origin;
- GDK_NOTE (MISC, g_print (" ts_x=%d", private->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 (values_mask & GDK_GC_TS_Y_ORIGIN)
+ if (mask & GDK_GC_TS_Y_ORIGIN)
{
- private->ts_y_origin = values->ts_y_origin;
- GDK_NOTE (MISC, g_print (" ts_y=%d", private->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 (values_mask & GDK_GC_CLIP_X_ORIGIN)
+ if (mask & GDK_GC_CLIP_X_ORIGIN)
{
- private->clip_x_origin = values->clip_x_origin;
- GDK_NOTE (MISC, g_print (" clip_x=%d", private->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 (values_mask & GDK_GC_CLIP_Y_ORIGIN)
+ if (mask & GDK_GC_CLIP_Y_ORIGIN)
{
- private->clip_y_origin = values->clip_y_origin;
- GDK_NOTE (MISC, g_print (" clip_y=%d", private->clip_y_origin));
- }
-
- if (values_mask & GDK_GC_EXPOSURES)
- {
- private->graphics_exposures = values->graphics_exposures;
- GDK_NOTE (MISC, g_print (" exp=%d", private->graphics_exposures));
+ win32_gc->values_mask |= GDK_GC_CLIP_Y_ORIGIN;
+ GDK_NOTE (GC, (g_print ("%sclip_y=%d", s, values->clip_y_origin),
+ s = ","));
}
- private->pen_style = PS_GEOMETRIC;
- private->pen_width = 1;
+ 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 (values_mask & (GDK_GC_LINE_WIDTH | GDK_GC_LINE_STYLE))
+ if (mask & GDK_GC_LINE_WIDTH)
{
- if (values_mask & GDK_GC_LINE_WIDTH)
- {
- private->pen_width = values->line_width;
- GDK_NOTE (MISC, g_print (" pw=%d", private->pen_width));
- }
- if (values_mask & GDK_GC_LINE_STYLE)
- {
- switch (values->line_style)
- {
- case GDK_LINE_SOLID:
- private->pen_style |= PS_SOLID; break;
- case GDK_LINE_ON_OFF_DASH:
- case GDK_LINE_DOUBLE_DASH: /* ??? */
- private->pen_style |= PS_DASH; break;
- }
- GDK_NOTE (MISC, g_print (" ps=%#x", private->pen_style));
- }
+ 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 (values_mask & GDK_GC_CAP_STYLE)
+ if (mask & GDK_GC_LINE_STYLE)
{
- switch (values->cap_style)
- {
- case GDK_CAP_NOT_LAST: /* ??? */
- case GDK_CAP_BUTT:
- private->pen_style |= PS_ENDCAP_FLAT; break;
- case GDK_CAP_ROUND:
- private->pen_style |= PS_ENDCAP_ROUND; break;
- case GDK_CAP_PROJECTING:
- private->pen_style |= PS_ENDCAP_SQUARE; break;
- }
- GDK_NOTE (MISC, g_print (" ps=%#x", private->pen_style));
+ win32_gc->line_style = values->line_style;
+ win32_gc->values_mask |= GDK_GC_LINE_STYLE;
}
- if (values_mask & GDK_GC_JOIN_STYLE)
+ if (mask & GDK_GC_CAP_STYLE)
{
- switch (values->join_style)
- {
- case GDK_JOIN_MITER:
- private->pen_style |= PS_JOIN_MITER;
- break;
- case GDK_JOIN_ROUND:
- private->pen_style |= PS_JOIN_ROUND;
- break;
- case GDK_JOIN_BEVEL:
- private->pen_style |= PS_JOIN_BEVEL;
- break;
- }
- GDK_NOTE (MISC, g_print (" ps=%#x", private->pen_style));
+ win32_gc->cap_style = values->cap_style;
+ win32_gc->values_mask |= GDK_GC_CAP_STYLE;
}
- private->hwnd = NULL;
- private->xgc = NULL;
+ if (mask & GDK_GC_JOIN_STYLE)
+ {
+ win32_gc->join_style = values->join_style;
+ win32_gc->values_mask |= GDK_GC_JOIN_STYLE;
+ }
- GDK_NOTE (MISC, g_print ("} = %p\n", private));
+ if (mask & (GDK_GC_LINE_WIDTH|GDK_GC_LINE_STYLE|GDK_GC_CAP_STYLE|GDK_GC_JOIN_STYLE))
+ {
+ fixup_pen (win32_gc);
+ GDK_NOTE (GC, (g_print ("%sps|=PS_STYLE_%s|PS_ENDCAP_%s|PS_JOIN_%s", s,
+ _gdk_win32_psstyle_to_string (win32_gc->pen_style),
+ _gdk_win32_psendcap_to_string (win32_gc->pen_style),
+ _gdk_win32_psjoin_to_string (win32_gc->pen_style)),
+ s = ","));
+ }
- return gc;
+ GDK_NOTE (GC, g_print ("} mask=(%s)", _gdk_win32_gcvalues_mask_to_string (win32_gc->values_mask)));
}
-void
-gdk_gc_destroy (GdkGC *gc)
+GdkGC*
+_gdk_win32_gc_new (GdkDrawable *drawable,
+ GdkGCValues *values,
+ GdkGCValuesMask values_mask)
{
- gdk_gc_unref (gc);
-}
+ GdkGC *gc;
+ GdkGCWin32 *win32_gc;
-GdkGC *
-gdk_gc_ref (GdkGC *gc)
-{
- GdkGCPrivate *private = (GdkGCPrivate*) 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);
- g_return_val_if_fail (gc != NULL, NULL);
- private->ref_count += 1;
+ gc = g_object_new (_gdk_gc_win32_get_type (), NULL);
+ win32_gc = GDK_GC_WIN32 (gc);
- return gc;
-}
+ _gdk_gc_init (gc, drawable, values, values_mask);
-void
-gdk_gc_unref (GdkGC *gc)
-{
- GdkGCPrivate *private = (GdkGCPrivate*) gc;
-
- g_return_if_fail (gc != NULL);
-
- if (private->ref_count > 1)
- private->ref_count -= 1;
- else
- {
- if (private->values_mask & GDK_GC_FONT)
- gdk_font_unref (private->font);
+ win32_gc->hcliprgn = NULL;
- if (private->values_mask & GDK_GC_TILE)
- gdk_pixmap_unref (private->tile);
-
- if (private->values_mask & GDK_GC_STIPPLE)
- gdk_pixmap_unref (private->stipple);
-
- if (private->values_mask & GDK_GC_CLIP_MASK)
- DeleteObject (private->clip_region);
+ win32_gc->font = NULL;
+ win32_gc->rop2 = R2_COPYPEN;
+ win32_gc->subwindow_mode = GDK_CLIP_BY_CHILDREN;
+ win32_gc->graphics_exposures = TRUE;
+ win32_gc->pen_width = 0;
+ /* Don't get confused by the PS_ENDCAP_ROUND. For narrow GDI pens
+ * (width == 1), PS_GEOMETRIC|PS_ENDCAP_ROUND works like X11's
+ * CapButt.
+ */
+ win32_gc->pen_style = PS_GEOMETRIC|PS_ENDCAP_ROUND|PS_JOIN_MITER;
+ win32_gc->line_style = GDK_LINE_SOLID;
+ win32_gc->cap_style = GDK_CAP_BUTT;
+ win32_gc->join_style = GDK_JOIN_MITER;
+ win32_gc->pen_dashes = NULL;
+ win32_gc->pen_num_dashes = 0;
+ win32_gc->pen_dash_offset = 0;
+ win32_gc->pen_hbrbg = NULL;
- g_free (gc);
- }
-}
+ win32_gc->values_mask = GDK_GC_FUNCTION | GDK_GC_FILL;
-void
-gdk_gc_get_values (GdkGC *gc,
- GdkGCValues *values)
-{
- GdkGCPrivate *private;
+ GDK_NOTE (GC, g_print ("_gdk_win32_gc_new: %p: ", win32_gc));
+ gdk_win32_gc_values_to_win32values (values, values_mask, win32_gc);
+ GDK_NOTE (GC, g_print ("\n"));
- g_return_if_fail (gc != NULL);
- g_return_if_fail (values != NULL);
+ win32_gc->hdc = NULL;
- private = (GdkGCPrivate*) gc;
+ return gc;
+}
- values->foreground = private->foreground;
- values->background = private->background;
- values->font = private->font;
+static void
+gdk_win32_gc_get_values (GdkGC *gc,
+ GdkGCValues *values)
+{
+ GdkGCWin32 *win32_gc = GDK_GC_WIN32 (gc);
- switch (private->rop2)
+ values->foreground.pixel = _gdk_gc_get_fg_pixel (gc);
+ values->background.pixel = _gdk_gc_get_bg_pixel (gc);
+ values->font = win32_gc->font;
+
+ switch (win32_gc->rop2)
{
case R2_COPYPEN:
values->function = GDK_COPY; break;
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 = private->fill_style;
+ values->fill = _gdk_gc_get_fill (gc);
+ values->tile = _gdk_gc_get_tile (gc);
+ values->stipple = _gdk_gc_get_stipple (gc);
- values->tile = private->tile;
- values->stipple = private->stipple;
- if (private->clip_region != NULL)
- {
- RECT rect;
- HBRUSH hbr;
- HDC hdc;
- HGDIOBJ oldbitmap;
- GdkPixmap *pixmap;
-
- GetRgnBox (private->clip_region, &rect);
- pixmap =
- gdk_pixmap_new (NULL, rect.right - rect.left, rect.bottom - rect.top,
- 1);
- hbr = GetStockObject (WHITE_BRUSH);
- if ((hdc = CreateCompatibleDC (NULL)) == NULL)
- g_warning ("gdk_gc_get_values: CreateCompatibleDC failed");
- if ((oldbitmap =
- SelectObject (hdc, GDK_DRAWABLE_XID (pixmap))) == NULL)
- g_warning ("gdk_gc_get_values: SelectObject #1 failed");
- hbr = GetStockObject (BLACK_BRUSH);
- if (!FillRect (hdc, &rect, hbr))
- g_warning ("gdk_gc_get_values: FillRect failed");
- hbr = GetStockObject (WHITE_BRUSH);
- if (!FillRgn (hdc, private->clip_region, hbr))
- g_warning ("gdk_gc_get_values: FillRgn failed");
- if (SelectObject (hdc, oldbitmap) == NULL)
- g_warning ("gdk_gc_get_values: SelectObject #2 failed");
- DeleteDC (hdc);
- values->clip_mask = pixmap;
- }
- else
- values->clip_mask = NULL;
- values->subwindow_mode = private->subwindow_mode;
- values->ts_x_origin = private->ts_x_origin;
- values->ts_y_origin = private->ts_y_origin;
- values->clip_x_origin = private->clip_x_origin;
- values->clip_y_origin = private->clip_y_origin;
- values->graphics_exposures = private->graphics_exposures;
- values->line_width = private->pen_width;
-
- if (private->pen_style & PS_SOLID)
- values->line_style = GDK_LINE_SOLID;
- else if (private->pen_style & PS_DASH)
- values->line_style = GDK_LINE_ON_OFF_DASH;
- else
- values->line_style = GDK_LINE_SOLID;
+ /* Also the X11 backend always returns a NULL clip_mask */
+ values->clip_mask = NULL;
- /* PS_ENDCAP_ROUND is zero */
- if (private->pen_style & PS_ENDCAP_FLAT)
- values->cap_style = GDK_CAP_BUTT;
- else if (private->pen_style & PS_ENDCAP_SQUARE)
- values->cap_style = GDK_CAP_PROJECTING;
- else
- values->cap_style = GDK_CAP_ROUND;
-
- /* PS_JOIN_ROUND is zero */
- if (private->pen_style & PS_JOIN_MITER)
- values->join_style = GDK_JOIN_MITER;
- else if (private->pen_style & PS_JOIN_BEVEL)
- values->join_style = GDK_JOIN_BEVEL;
- else
- values->join_style = GDK_JOIN_ROUND;
+ 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;
+
+ values->line_style = win32_gc->line_style;
+ values->cap_style = win32_gc->cap_style;
+ values->join_style = win32_gc->join_style;
}
-void
-gdk_gc_set_foreground (GdkGC *gc,
- GdkColor *color)
+static void
+gdk_win32_gc_set_values (GdkGC *gc,
+ GdkGCValues *values,
+ GdkGCValuesMask mask)
{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
- g_return_if_fail (color != NULL);
-
- private = (GdkGCPrivate*) gc;
- {
- GDK_NOTE (MISC, g_print ("gdk_gc_set_foreground: (%d) %s\n",
- private, gdk_color_to_string (color)));
- private->foreground = *color;
- private->values_mask |= GDK_GC_FOREGROUND;
- }
+ g_return_if_fail (GDK_IS_GC (gc));
+
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_values: %p: ", GDK_GC_WIN32 (gc)));
+ gdk_win32_gc_values_to_win32values (values, mask, GDK_GC_WIN32 (gc));
+ GDK_NOTE (GC, g_print ("\n"));
}
-void
-gdk_gc_set_background (GdkGC *gc,
- GdkColor *color)
+static void
+gdk_win32_gc_set_dashes (GdkGC *gc,
+ gint dash_offset,
+ gint8 dash_list[],
+ gint n)
{
- GdkGCPrivate *private;
+ GdkGCWin32 *win32_gc;
+ int i;
- g_return_if_fail (gc != NULL);
- g_return_if_fail (color != NULL);
+ g_return_if_fail (GDK_IS_GC (gc));
+ g_return_if_fail (dash_list != NULL);
- private = (GdkGCPrivate*) gc;
+ win32_gc = GDK_GC_WIN32 (gc);
- GDK_NOTE (MISC, g_print ("gdk_gc_set_backround: (%d) %s\n",
- private, gdk_color_to_string(color)));
- private->background = *color;
- private->values_mask |= GDK_GC_BACKGROUND;
+ win32_gc->pen_num_dashes = n;
+ g_free (win32_gc->pen_dashes);
+ win32_gc->pen_dashes = g_new (DWORD, n);
+ for (i = 0; i < n; i++)
+ win32_gc->pen_dashes[i] = dash_list[i];
+ win32_gc->pen_dash_offset = dash_offset;
+ fixup_pen (win32_gc);
}
void
-gdk_gc_set_font (GdkGC *gc,
- GdkFont *font)
+_gdk_windowing_gc_set_clip_region (GdkGC *gc,
+ GdkRegion *region)
{
- GdkGCPrivate *gc_private;
- GdkFontPrivate *font_private;
- gchar *xlfd;
+ GdkGCWin32 *win32_gc = GDK_GC_WIN32 (gc);
- g_return_if_fail (gc != NULL);
- g_return_if_fail (font != NULL);
+ if (win32_gc->hcliprgn)
+ DeleteObject (win32_gc->hcliprgn);
- if (font->type == GDK_FONT_FONT
- || font->type == GDK_FONT_FONTSET)
+ if (region)
{
- gc_private = (GdkGCPrivate*) gc;
-
- GDK_NOTE (MISC, (xlfd = gdk_font_xlfd_create (font),
- g_print ("gdk_gc_set_font: (%d) %s\n",
- gc_private, xlfd),
- gdk_font_xlfd_free (xlfd)));
-
- if (gc_private->font != NULL)
- gdk_font_unref (gc_private->font);
- gc_private->font = font;
- gdk_font_ref (gc_private->font);
- gc_private->values_mask |= GDK_GC_FONT;
- }
-}
-
-void
-gdk_gc_set_function (GdkGC *gc,
- GdkFunction function)
-{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- GDK_NOTE (MISC, g_print ("gdk_gc_set_function: (%d) %d\n", private, function));
+ GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: %p: %s\n",
+ win32_gc,
+ _gdk_win32_gdkregion_to_string (region)));
- switch (function)
- {
- case GDK_COPY:
- private->rop2 = R2_COPYPEN; break;
- case GDK_INVERT:
- private->rop2 = R2_NOT; break;
- case GDK_XOR:
- private->rop2 = R2_XORPEN; break;
- case GDK_CLEAR:
- private->rop2 = R2_BLACK; break;
- case GDK_AND:
- private->rop2 = R2_MASKPEN; break;
- case GDK_AND_REVERSE:
- private->rop2 = R2_MASKPENNOT; break;
- case GDK_AND_INVERT:
- private->rop2 = R2_MASKNOTPEN; break;
- case GDK_NOOP:
- private->rop2 = R2_NOP; break;
- case GDK_OR:
- private->rop2 = R2_MERGEPEN; break;
- case GDK_EQUIV:
- private->rop2 = R2_NOTXORPEN; break;
- case GDK_OR_REVERSE:
- private->rop2 = R2_MERGEPENNOT; break;
- case GDK_COPY_INVERT:
- private->rop2 = R2_NOTCOPYPEN; break;
- case GDK_OR_INVERT:
- private->rop2 = R2_MERGENOTPEN; break;
- case GDK_NAND:
- private->rop2 = R2_NOTMASKPEN; break;
- case GDK_SET:
- private->rop2 = R2_WHITE; break;
+ win32_gc->hcliprgn = _gdk_win32_gdkregion_to_hrgn (region, 0, 0);
+ win32_gc->values_mask |= GDK_GC_CLIP_MASK;
}
- private->values_mask |= GDK_GC_FUNCTION;
-}
-
-void
-gdk_gc_set_fill (GdkGC *gc,
- GdkFill fill)
-{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- private->fill_style = fill;
- private->values_mask |= GDK_GC_FILL;
-}
-
-void
-gdk_gc_set_tile (GdkGC *gc,
- GdkPixmap *tile)
-{
- GdkGCPrivate *private;
- HBITMAP pixmap;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- pixmap = NULL;
-
- if (tile)
- pixmap = GDK_DRAWABLE_XID (tile);
-
- if (private->tile != NULL)
- gdk_pixmap_unref (private->tile);
- private->tile = tile;
- if (tile)
- gdk_pixmap_ref (tile);
- if (pixmap != NULL)
- private->values_mask |= GDK_GC_TILE;
else
- private->values_mask &= ~GDK_GC_TILE;
-}
-
-void
-gdk_gc_set_stipple (GdkGC *gc,
- GdkPixmap *stipple)
-{
- GdkGCPrivate *private;
- HBITMAP pixmap;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- pixmap = NULL;
-
- if (stipple)
- pixmap = GDK_DRAWABLE_XID (stipple);
-
- if (private->stipple != NULL)
- gdk_pixmap_unref (private->stipple);
- private->stipple = stipple;
- if (stipple)
- gdk_pixmap_ref (stipple);
- if (pixmap != NULL)
- private->values_mask |= GDK_GC_STIPPLE;
- else
- private->values_mask &= ~GDK_GC_STIPPLE;
-}
-
-void
-gdk_gc_set_ts_origin (GdkGC *gc,
- gint x,
- gint y)
-{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
+ {
+ GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: NULL\n"));
- private = (GdkGCPrivate*) gc;
+ win32_gc->hcliprgn = NULL;
+ win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
+ }
- private->ts_x_origin = x;
- private->ts_y_origin = y;
- private->values_mask |= GDK_GC_TS_X_ORIGIN |GDK_GC_TS_Y_ORIGIN;
+ 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_origin (GdkGC *gc,
- gint x,
- gint y)
+_gdk_windowing_gc_copy (GdkGC *dst_gc,
+ GdkGC *src_gc)
{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
+ GdkGCWin32 *dst_win32_gc = GDK_GC_WIN32 (dst_gc);
+ GdkGCWin32 *src_win32_gc = GDK_GC_WIN32 (src_gc);
- private = (GdkGCPrivate*) gc;
+ GDK_NOTE (GC, g_print ("gdk_gc_copy: %p := %p\n", dst_win32_gc, src_win32_gc));
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_origin: (%d) +%d+%d\n",
- private, x, y));
+ if (dst_win32_gc->hcliprgn != NULL)
+ DeleteObject (dst_win32_gc->hcliprgn);
- private->clip_x_origin = x;
- private->clip_y_origin = y;
- private->values_mask |= GDK_GC_CLIP_X_ORIGIN |GDK_GC_CLIP_Y_ORIGIN;
-}
+ if (dst_win32_gc->font != NULL)
+ gdk_font_unref (dst_win32_gc->font);
-void
-gdk_gc_set_clip_mask (GdkGC *gc,
- GdkBitmap *mask)
-{
- GdkGCPrivate *private;
- HBITMAP xmask;
-
- g_return_if_fail (gc != NULL);
+ if (dst_win32_gc->pen_dashes)
+ g_free (dst_win32_gc->pen_dashes);
- if (mask)
+ dst_win32_gc->hcliprgn = src_win32_gc->hcliprgn;
+ if (dst_win32_gc->hcliprgn)
{
- if (GDK_DRAWABLE_DESTROYED (mask))
- return;
- xmask = GDK_DRAWABLE_XID (mask);
+ /* 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);
}
- else
- xmask = NULL;
- private = (GdkGCPrivate*) gc;
+ dst_win32_gc->values_mask = src_win32_gc->values_mask;
+ dst_win32_gc->font = src_win32_gc->font;
+ if (dst_win32_gc->font != NULL)
+ gdk_font_ref (dst_win32_gc->font);
+
+ dst_win32_gc->rop2 = src_win32_gc->rop2;
+
+ dst_win32_gc->subwindow_mode = src_win32_gc->subwindow_mode;
+ dst_win32_gc->graphics_exposures = src_win32_gc->graphics_exposures;
+ dst_win32_gc->pen_width = src_win32_gc->pen_width;
+ dst_win32_gc->pen_style = src_win32_gc->pen_style;
+ dst_win32_gc->line_style = src_win32_gc->line_style;
+ dst_win32_gc->cap_style = src_win32_gc->cap_style;
+ dst_win32_gc->join_style = src_win32_gc->join_style;
+ if (src_win32_gc->pen_dashes)
+ dst_win32_gc->pen_dashes = g_memdup (src_win32_gc->pen_dashes,
+ sizeof (DWORD) * src_win32_gc->pen_num_dashes);
+ else
+ dst_win32_gc->pen_dashes = NULL;
+ dst_win32_gc->pen_num_dashes = src_win32_gc->pen_num_dashes;
+ dst_win32_gc->pen_dash_offset = src_win32_gc->pen_dash_offset;
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_mask: (%d) %#x\n", private, xmask));
- if (private->clip_region != NULL)
- if (!DeleteObject (private->clip_region))
- g_warning ("gdk_gc_set_clip_mask: DeleteObject failed");
- if (xmask != NULL)
- {
- private->clip_region = BitmapToRegion (xmask);
- {
- RECT rect;
- GetRgnBox (private->clip_region, &rect);
- GDK_NOTE (MISC, g_print ("...box = %dx%d@+%d+%d\n",
- rect.right - rect.left, rect.bottom - rect.top,
- rect.left, rect.top));
- }
-#if 0
- /* Test code that sets clip region to whole of mask */
- {
- BITMAP bm;
- GetObject (xmask, sizeof (bm), &bm);
- private->clip_region = CreateRectRgn (0, 0, bm.bmWidth, bm.bmHeight);
- }
-#endif
- private->values_mask |= GDK_GC_CLIP_MASK;
- }
- else
- {
- private->values_mask &= ~GDK_GC_CLIP_MASK;
- private->clip_region = NULL;
- }
+ dst_win32_gc->hdc = NULL;
+ dst_win32_gc->saved_dc = FALSE;
+ dst_win32_gc->holdpal = NULL;
+ dst_win32_gc->pen_hbrbg = NULL;
}
-void
-gdk_gc_set_clip_rectangle (GdkGC *gc,
- GdkRectangle *rectangle)
+GdkScreen *
+gdk_gc_get_screen (GdkGC *gc)
{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
+ g_return_val_if_fail (GDK_IS_GC_WIN32 (gc), NULL);
+
+ return _gdk_screen;
+}
- private = (GdkGCPrivate*) gc;
+static guint bitmask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
- if (private->clip_region != NULL)
- if (!DeleteObject (private->clip_region))
- g_warning ("gdk_gc_set_clip_rectangle: DeleteObject failed");
- if (rectangle)
- {
- GDK_NOTE (MISC,
- g_print ("gdk_gc_set_clip_rectangle: (%d) %dx%d@+%d+%d\n",
- private,
- rectangle->width, rectangle->height,
- rectangle->x, rectangle->y));
- if ((private->clip_region =
- CreateRectRgn (rectangle->x, rectangle->y,
- rectangle->x + rectangle->width,
- rectangle->y + rectangle->height)) == NULL)
- g_warning ("gdk_gc_set_clip_rectangle: CreateRectRgn failed");
-
- private->values_mask |= GDK_GC_CLIP_MASK;
- }
- else
- {
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_rectangle: (%d) None\n",
- private));
- private->clip_region = NULL;
- private->values_mask &= ~GDK_GC_CLIP_MASK;
- }
- private->values_mask &= ~(GDK_GC_CLIP_X_ORIGIN |GDK_GC_CLIP_Y_ORIGIN);
-}
-
-void
-gdk_gc_set_clip_region (GdkGC *gc,
- GdkRegion *region)
+COLORREF
+_gdk_win32_colormap_color (GdkColormap *colormap,
+ gulong pixel)
{
- GdkGCPrivate *private;
+ const GdkVisual *visual;
+ GdkColormapPrivateWin32 *colormap_private;
+ guchar r, g, b;
- g_return_if_fail (gc != NULL);
+ if (colormap == NULL)
+ return DIBINDEX (pixel & 1);
- private = (GdkGCPrivate*) gc;
+ colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_region: (%d) %s\n",
- private, (region != NULL ? "xxx" : "None")));
+ g_assert (colormap_private != NULL);
- if (private->clip_region != NULL)
- if (!DeleteObject (private->clip_region))
- g_warning ("gdk_gc_set_clip_region: DeleteObject failed");
- if (region)
+ visual = colormap->visual;
+ switch (visual->type)
{
- GdkRegionPrivate *region_private;
+ 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);
- region_private = (GdkRegionPrivate*) region;
- private->clip_region = CreateRectRgn (1, 1, 0, 0);
- CombineRgn (private->clip_region, region_private->xregion, NULL, RGN_COPY);
- private->values_mask |= GDK_GC_CLIP_MASK;
- }
- else
- {
- private->clip_region = NULL;
- private->values_mask &= ~GDK_GC_CLIP_MASK;
+ default:
+ g_assert_not_reached ();
+ return 0;
}
}
-void
-gdk_gc_set_subwindow (GdkGC *gc,
- GdkSubwindowMode mode)
+gboolean
+predraw (GdkGC *gc,
+ GdkColormap *colormap)
{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- private->subwindow_mode = mode;
- private->values_mask |= GDK_GC_SUBWINDOW;
-}
-
-void
-gdk_gc_set_exposures (GdkGC *gc,
- gint exposures)
-{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- private->graphics_exposures = exposures;
- private->values_mask |= GDK_GC_EXPOSURES;;
-}
-
-void
-gdk_gc_set_line_attributes (GdkGC *gc,
- gint line_width,
- GdkLineStyle line_style,
- GdkCapStyle cap_style,
- GdkJoinStyle join_style)
-{
- GdkGCPrivate *private;
- int xline_style;
- int xcap_style;
- int xjoin_style;
-
- g_return_if_fail (gc != NULL);
-
- private = (GdkGCPrivate*) gc;
-
- GDK_NOTE (MISC,
- g_print ("gdk_gc_set_line_attributes: (%d) %d %s %s %s\n",
- private, line_width,
- (line_style == GDK_LINE_SOLID ? "SOLID" :
- (line_style == GDK_LINE_ON_OFF_DASH ? "ON_OFF_DASH" :
- (line_style == GDK_LINE_DOUBLE_DASH ? "DOUBLE_DASH" :
- "???"))),
- (cap_style == GDK_CAP_BUTT ? "BUTT" :
- (cap_style == GDK_CAP_ROUND ? "ROUND" :
- (cap_style == GDK_CAP_PROJECTING ? "PROJECTING" :
- "???"))),
- (join_style == GDK_JOIN_MITER ? "MITER" :
- (join_style == GDK_JOIN_ROUND ? "ROUND" :
- (join_style == GDK_JOIN_BEVEL ? "BEVEL" :
- "???")))));
-
- private->pen_width = line_width;
-
- /* Mask old style bits away */
- private->pen_style &= ~(PS_STYLE_MASK|PS_ENDCAP_MASK|PS_JOIN_MASK);
-
- /* Add new bits */
- switch (line_style)
+ GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
+ GdkColormapPrivateWin32 *colormap_private;
+ gint k;
+ gboolean ok = TRUE;
+
+ if (colormap &&
+ (colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
+ colormap->visual->type == GDK_VISUAL_STATIC_COLOR))
{
- case GDK_LINE_SOLID:
- private->pen_style |= PS_SOLID; break;
- case GDK_LINE_ON_OFF_DASH:
- case GDK_LINE_DOUBLE_DASH: /* ??? */
- private->pen_style |= PS_DASH; break;
- }
+ colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
- switch (cap_style)
- {
- case GDK_CAP_NOT_LAST:
- /* ??? */
- break;
- case GDK_CAP_BUTT:
- private->pen_style |= PS_ENDCAP_FLAT; break;
- case GDK_CAP_ROUND:
- private->pen_style |= PS_ENDCAP_ROUND; break;
- case GDK_CAP_PROJECTING:
- private->pen_style |= PS_ENDCAP_SQUARE; break;
- }
+ g_assert (colormap_private != NULL);
- switch (join_style)
- {
- case GDK_JOIN_MITER:
- private->pen_style |= PS_JOIN_MITER;
- break;
- case GDK_JOIN_ROUND:
- private->pen_style |= PS_JOIN_ROUND;
- break;
- case GDK_JOIN_BEVEL:
- private->pen_style |= PS_JOIN_BEVEL;
- break;
+ 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: realized %p: %d colors\n",
+ colormap_private->hpal, k));
}
-}
-void
-gdk_gc_set_dashes (GdkGC *gc,
- gint dash_offset,
- gchar dash_list[],
- gint n)
-{
- GdkGCPrivate *private;
-
- g_return_if_fail (gc != NULL);
- g_return_if_fail (dash_list != NULL);
-
- /* XXX ??? */
-
- private = (GdkGCPrivate *) gc;
-
- private->pen_style &= ~(PS_STYLE_MASK);
- private->pen_style |= PS_DASH;
+ return ok;
}
-void
-gdk_gc_copy (GdkGC *dst_gc, GdkGC *src_gc)
+static GdkDrawableImplWin32 *
+get_impl_drawable (GdkDrawable *drawable)
{
- GdkGCPrivate *dst_private, *src_private;
-
- src_private = (GdkGCPrivate *) src_gc;
- dst_private = (GdkGCPrivate *) dst_gc;
+ if (GDK_IS_DRAWABLE_IMPL_WIN32 (drawable))
+ return GDK_DRAWABLE_IMPL_WIN32(drawable);
+ else if (GDK_IS_WINDOW (drawable))
+ return GDK_DRAWABLE_IMPL_WIN32 ((GDK_WINDOW_OBJECT (drawable))->impl);
+ else if (GDK_IS_PIXMAP (drawable))
+ return GDK_DRAWABLE_IMPL_WIN32 ((GDK_PIXMAP_OBJECT (drawable))->impl);
+ else
+ g_assert_not_reached ();
- *dst_private = *src_private;
+ return NULL;
}
+/**
+ * gdk_win32_hdc_get:
+ * @drawable: destination #GdkDrawable
+ * @gc: #GdkGC to use for drawing on @drawable
+ * @usage: mask indicating what properties needs to be set up
+ *
+ * Allocates a Windows device context handle (HDC) for drawing into
+ * @drawable, and sets it up appropriately according to @usage.
+ *
+ * Each #GdkGC can at one time have only one HDC associated with it.
+ *
+ * The following flags in @mask are handled:
+ *
+ * If %GDK_GC_FOREGROUND is set in @mask, a solid brush of the
+ * foreground color in @gc is selected into the HDC. The text color of
+ * the HDC is also set. If the @drawable has a palette (256-color
+ * mode), the palette is selected and realized.
+ *
+ * If any of the line attribute flags (%GDK_GC_LINE_WIDTH,
+ * %GDK_GC_LINE_STYLE, %GDK_GC_CAP_STYLE and %GDK_GC_JOIN_STYLE) is
+ * set in @mask, a solid pen of the foreground color and appropriate
+ * width and stule is created and selected into the HDC. Note that the
+ * dash properties are not completely implemented.
+ *
+ * If the %GDK_GC_FONT flag is set, the background mix mode is set to
+ * %TRANSPARENT. and the text alignment is set to
+ * %TA_BASELINE|%TA_LEFT. Note that no font gets selected into the HDC
+ * by this function.
+ *
+ * Some things are done regardless of @mask: If the function in @gc is
+ * any other than %GDK_COPY, the raster operation of the HDC is
+ * set. If @gc has a clip mask, the clip region of the HDC is set.
+ *
+ * Note that the fill style, tile, stipple, and tile and stipple
+ * origins in the @gc are ignored by this function. (In general, tiles
+ * and stipples can't be implemented directly on Win32; you need to do
+ * multiple pass drawing and blitting to implement tiles or
+ * stipples. GDK does just that when you call the GDK drawing
+ * functions with a GC that asks for tiles or stipples.)
+ *
+ * When the HDC is no longer used, it should be released by calling
+ * <function>gdk_win32_hdc_release()</function> with the same
+ * parameters.
+ *
+ * If you modify the HDC by calling <function>SelectObject</function>
+ * you should undo those modifications before calling
+ * <function>gdk_win32_hdc_release()</function>.
+ *
+ * Return value: The HDC.
+ **/
HDC
-gdk_gc_predraw (GdkDrawable *drawable,
- GdkGCPrivate *gc_private)
+gdk_win32_hdc_get (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkGCValuesMask usage)
{
- GdkDrawablePrivate *drawable_private = (GdkDrawablePrivate *) drawable;
- GdkColormapPrivate *colormap_private =
- (GdkColormapPrivate *) drawable_private->colormap;
- GdkVisual *visual;
- COLORREF bg;
- COLORREF fg;
- LOGBRUSH logbrush;
+ GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
+ GdkDrawableImplWin32 *impl = NULL;
+ gboolean ok = TRUE;
+ COLORREF fg = RGB (0, 0, 0), bg = RGB (255, 255, 255);
HPEN hpen;
HBRUSH hbr;
- guchar r, g, b;
- static guint mask[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 };
- g_assert (gc_private->xgc == NULL);
+ g_assert (win32_gc->hdc == NULL);
- if (GDK_DRAWABLE_TYPE (drawable) == GDK_DRAWABLE_PIXMAP)
- {
- if ((gc_private->xgc = CreateCompatibleDC (NULL)) == NULL)
- g_warning ("gdk_gc_predraw: CreateCompatibleDC failed");
+ impl = get_impl_drawable (drawable);
+
+ win32_gc->hdc = _gdk_win32_drawable_acquire_dc (GDK_DRAWABLE (impl));
+ ok = win32_gc->hdc != NULL;
- if ((gc_private->saved_dc = SaveDC (gc_private->xgc)) == 0)
- g_warning ("gdk_gc_predraw: SaveDC #1 failed");
-
- if (SelectObject (gc_private->xgc, drawable_private->xwindow) == NULL)
- g_warning ("gdk_gc_predraw: SelectObject #1 failed");
- }
- else
- {
- if ((gc_private->xgc = GetDC (drawable_private->xwindow)) == NULL)
- g_warning ("gdk_gc_predraw: GetDC failed");
+ if (ok && (win32_gc->saved_dc = SaveDC (win32_gc->hdc)) == 0)
+ WIN32_GDI_FAILED ("SaveDC"), ok = FALSE;
- if ((gc_private->saved_dc = SaveDC (gc_private->xgc)) == 0)
- g_warning ("gdk_gc_predraw: SaveDC #2 failed");
- }
-
- gc_private->hwnd = drawable_private->xwindow;
-
- if (colormap_private == NULL)
- {
- /* A 1 bit deep bitmap */
- struct
- {
- WORD palVersion;
- WORD palNumEntries;
- PALETTEENTRY palPalEntry[2];
- } logpal;
- static HPALETTE hpal = NULL;
+ if (ok && (usage & (GDK_GC_FOREGROUND | GDK_GC_BACKGROUND)))
+ ok = predraw (gc, impl->colormap);
- if (hpal == NULL)
- {
- /* Create a b&w palette */
- logpal.palVersion = 0x300;
- logpal.palNumEntries = 2;
- logpal.palPalEntry[0].peRed =
- logpal.palPalEntry[0].peGreen =
- logpal.palPalEntry[0].peBlue = 0x00;
- logpal.palPalEntry[0].peFlags = 0x00;
- logpal.palPalEntry[1].peRed =
- logpal.palPalEntry[1].peGreen =
- logpal.palPalEntry[1].peBlue = 0xFF;
- logpal.palPalEntry[1].peFlags = 0x00;
- if ((hpal = CreatePalette ((LOGPALETTE *) &logpal)) == NULL)
- g_warning ("gdk_gc_predraw: CreatePalette failed");
- }
- SelectPalette (gc_private->xgc, hpal, FALSE);
- RealizePalette (gc_private->xgc);
- fg = PALETTEINDEX (gc_private->foreground.pixel);
- }
- else if (colormap_private->xcolormap->rc_palette)
+ if (ok && (usage & GDK_GC_FOREGROUND))
{
- int k;
- if (SelectPalette (gc_private->xgc,
- colormap_private->xcolormap->palette, FALSE) == NULL)
- g_warning ("gdk_gc_predraw: SelectPalette failed");
- if (TRUE || colormap_private->xcolormap->stale)
- {
- if ((k = RealizePalette (gc_private->xgc)) == GDI_ERROR)
- g_warning ("gdk_gc_predraw: RealizePalette failed");
- colormap_private->xcolormap->stale = FALSE;
- }
-#if 0
- g_print ("Selected palette %#x for gc %#x, realized %d colors\n",
- colormap_private->xcolormap->palette, gc_private->xgc, k);
-#endif
- fg = PALETTEINDEX (gc_private->foreground.pixel);
- }
- else
- {
- visual = colormap_private->visual;
- r = (gc_private->foreground.pixel & visual->red_mask) >> visual->red_shift;
- r = (r * 255) / mask[visual->red_prec];
- g = (gc_private->foreground.pixel & visual->green_mask) >> visual->green_shift;
- g = (g * 255) / mask[visual->green_prec];
- b = (gc_private->foreground.pixel & visual->blue_mask) >> visual->blue_shift;
- b = (b * 255) / mask[visual->blue_prec];
-
- fg = GetNearestColor (gc_private->xgc, RGB (r, g, b));
- }
- logbrush.lbStyle = BS_SOLID;
- logbrush.lbColor = fg;
- if ((hpen = ExtCreatePen (gc_private->pen_style, gc_private->pen_width,
- &logbrush, 0, NULL)) == NULL)
- g_warning ("gdk_gc_predraw: CreatePen failed");
-
- if (SelectObject (gc_private->xgc, hpen) == NULL)
- g_warning ("gdk_gc_predraw: SelectObject #2 failed");
+ fg = _gdk_win32_colormap_color (impl->colormap, _gdk_gc_get_fg_pixel (gc));
+ if ((hbr = CreateSolidBrush (fg)) == NULL)
+ WIN32_GDI_FAILED ("CreateSolidBrush"), ok = FALSE;
- if (SetTextColor (gc_private->xgc, fg) == CLR_INVALID)
- g_warning ("gdk_gc_predraw: SetTextColor failed");
+ if (ok && SelectObject (win32_gc->hdc, hbr) == NULL)
+ WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
-#if 0
- switch (gc_private->fill_style)
- {
- case GDK_STIPPLED:
- {
- GdkPixmap *stipple = gc_private->stipple;
- GdkPixmapPrivate *stipple_private = (GdkPixmapPrivate *) stipple;
- HBITMAP hbm = stipple_private->xwindow;
- if (NULL == (hbr = CreatePatternBrush (hbm)))
- g_warning ("gdk_gc_predraw: CreatePatternBrush failed");
-
-#ifdef NATIVE_WIN16
- SetBrushOrg (gc_private->xgc, gc_private->ts_x_origin,
- gc_private->ts_y_origin);
-#else
- SetBrushOrgEx(gc_private->xgc, gc_private->ts_x_origin,
- gc_private->ts_y_origin, NULL);
-#endif
- }
- break;
- case GDK_SOLID:
- default:
- if ((hbr = CreateSolidBrush (fg)) == NULL)
- g_warning ("gdk_gc_predraw: CreateSolidBrush failed");
- break;
- }
-#else
- if ((hbr = CreateSolidBrush (fg)) == NULL)
- g_warning ("gdk_gc_predraw: CreateSolidBrush failed");
-#endif
- if (SelectObject (gc_private->xgc, hbr) == NULL)
- g_warning ("gdk_gc_predraw: SelectObject #3 failed");
-
- if (gc_private->values_mask & GDK_GC_BACKGROUND)
+ if (ok && SetTextColor (win32_gc->hdc, fg) == CLR_INVALID)
+ WIN32_GDI_FAILED ("SetTextColor"), ok = FALSE;
+ }
+
+ if (ok && (usage & LINE_ATTRIBUTES))
{
- if (colormap_private == NULL)
- {
- /* a bitmap */
- bg = PALETTEINDEX (gc_private->background.pixel);
- }
- else if (colormap_private->xcolormap->rc_palette)
- {
- bg = PALETTEINDEX (gc_private->background.pixel);
- }
- else
- {
- visual = colormap_private->visual;
- r = (gc_private->background.pixel & visual->red_mask) >> visual->red_shift;
- r = (r * 255) / mask[visual->red_prec];
- g = (gc_private->background.pixel & visual->green_mask) >> visual->green_shift;
- g = (g * 255) / mask[visual->green_prec];
- b = (gc_private->background.pixel & visual->blue_mask) >> visual->blue_shift;
- b = (b * 255) / mask[visual->green_prec];
+ /* For drawing GDK_LINE_DOUBLE_DASH */
+ if ((usage & GDK_GC_BACKGROUND) && win32_gc->line_style == GDK_LINE_DOUBLE_DASH)
+ {
+ bg = _gdk_win32_colormap_color (impl->colormap, _gdk_gc_get_bg_pixel (gc));
+ if ((win32_gc->pen_hbrbg = CreateSolidBrush (bg)) == NULL)
+ WIN32_GDI_FAILED ("CreateSolidBrush"), ok = FALSE;
+ }
+
+ if (ok)
+ {
+ LOGBRUSH logbrush;
+ DWORD style_count = 0;
+ const DWORD *style = NULL;
+
+ /* Create and select pen */
+ logbrush.lbStyle = BS_SOLID;
+ logbrush.lbColor = fg;
+ logbrush.lbHatch = 0;
+
+ if ((win32_gc->pen_style & PS_STYLE_MASK) == PS_USERSTYLE)
+ {
+ style_count = win32_gc->pen_num_dashes;
+ style = win32_gc->pen_dashes;
+ }
+
+ if ((hpen = ExtCreatePen (win32_gc->pen_style,
+ MAX (win32_gc->pen_width, 1),
+ &logbrush,
+ style_count, style)) == NULL)
+ WIN32_GDI_FAILED ("ExtCreatePen"), ok = FALSE;
- fg = GetNearestColor (gc_private->xgc, RGB (r, g, b));
+ if (ok && SelectObject (win32_gc->hdc, hpen) == NULL)
+ WIN32_GDI_FAILED ("SelectObject"), ok = FALSE;
}
- if (SetBkColor (gc_private->xgc, bg) == CLR_INVALID)
- g_warning ("gdk_gc_predraw: SetBkColor failed");
}
+
+ if (ok && (usage & GDK_GC_FONT))
+ {
+ if (SetBkMode (win32_gc->hdc, TRANSPARENT) == 0)
+ WIN32_GDI_FAILED ("SetBkMode"), ok = FALSE;
- if (SetBkMode (gc_private->xgc, TRANSPARENT) == 0)
- g_warning ("gdk_gc_predraw: SetBkMode failed");
-
- if (SetTextAlign (gc_private->xgc, TA_BASELINE) == GDI_ERROR)
- g_warning ("gdk_gc_predraw: SetTextAlign failed");
+ if (ok && SetTextAlign (win32_gc->hdc, TA_BASELINE|TA_LEFT|TA_NOUPDATECP) == GDI_ERROR)
+ WIN32_GDI_FAILED ("SetTextAlign"), ok = FALSE;
+ }
- if (gc_private->values_mask & GDK_GC_FUNCTION)
- if (SetROP2 (gc_private->xgc, gc_private->rop2) == 0)
- g_warning ("gdk_gc_predraw: SetROP2 failed");
+ if (ok && win32_gc->rop2 != R2_COPYPEN)
+ if (SetROP2 (win32_gc->hdc, win32_gc->rop2) == 0)
+ WIN32_GDI_FAILED ("SetROP2"), ok = FALSE;
- if (gc_private->values_mask & GDK_GC_CLIP_MASK
- && gc_private->clip_region != NULL)
+ if (ok &&
+ (win32_gc->values_mask & GDK_GC_CLIP_MASK) &&
+ win32_gc->hcliprgn != NULL)
{
- if (gc_private->values_mask & (GDK_GC_CLIP_X_ORIGIN | GDK_GC_CLIP_Y_ORIGIN))
- OffsetRgn (gc_private->clip_region,
- gc_private->clip_x_origin, gc_private->clip_y_origin);
- SelectClipRgn (gc_private->xgc, gc_private->clip_region);
+ if (SelectClipRgn (win32_gc->hdc, win32_gc->hcliprgn) == ERROR)
+ WIN32_API_FAILED ("SelectClipRgn"), ok = FALSE;
+
+ 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;
}
- return gc_private->xgc;
+ GDK_NOTE (GC, (g_print ("gdk_win32_hdc_get: %p (%s): ",
+ win32_gc, _gdk_win32_gcvalues_mask_to_string (usage)),
+ _gdk_win32_print_dc (win32_gc->hdc)));
+
+ return win32_gc->hdc;
}
+/**
+ * gdk_win32_hdc_release:
+ * @drawable: destination #GdkDrawable
+ * @gc: #GdkGC to use for drawing on @drawable
+ * @usage: mask indicating what properties were set up
+ *
+ * This function deallocates the Windows device context allocated by
+ * <funcion>gdk_win32_hdc_get()</function>. It should be called with
+ * the same parameters.
+ **/
void
-gdk_gc_postdraw (GdkDrawable *drawable_private,
- GdkGCPrivate *gc_private)
+gdk_win32_hdc_release (GdkDrawable *drawable,
+ GdkGC *gc,
+ GdkGCValuesMask usage)
{
- GdkDrawablePrivate *drawable_private = (GdkDrawablePrivate *) drawable;
- GdkColormapPrivate *colormap_private =
- (GdkColormapPrivate *) drawable_private->colormap;
- HGDIOBJ hpen;
- HGDIOBJ hbr;
-
- if ((hpen = GetCurrentObject (gc_private->xgc, OBJ_PEN)) == NULL)
- g_warning ("gdk_gc_postdraw: GetCurrentObject #1 failed");
-
- if ((hbr = GetCurrentObject (gc_private->xgc, OBJ_BRUSH)) == NULL)
- g_warning ("gdk_gc_postdraw: GetCurrentObject #2 failed");
-
- if (!RestoreDC (gc_private->xgc, gc_private->saved_dc))
- g_warning ("gdk_gc_postdraw: RestoreDC failed");
-#if 0
- if (colormap_private != NULL
- && colormap_private->xcolormap->rc_palette
- && colormap_private->xcolormap->stale)
- {
- SelectPalette (gc_private->xgc, GetStockObject (DEFAULT_PALETTE), FALSE);
- if (!UnrealizeObject (colormap_private->xcolormap->palette))
- g_warning ("gdk_gc_postraw: UnrealizeObject failed");
- }
-#endif
- if (GDK_DRAWABLE_TYPE (drawable) == GDK_DRAWABLE_PIXMAP)
- {
- if (!DeleteDC (gc_private->xgc))
- g_warning ("gdk_gc_postdraw: DeleteDC failed");
- }
- else
+ GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
+ GdkDrawableImplWin32 *impl = NULL;
+ HGDIOBJ hpen = NULL;
+ HGDIOBJ hbr = NULL;
+
+ GDK_NOTE (GC, g_print ("gdk_win32_hdc_release: %p: %p (%s)\n",
+ win32_gc, win32_gc->hdc,
+ _gdk_win32_gcvalues_mask_to_string (usage)));
+
+ impl = get_impl_drawable (drawable);
+
+ if (win32_gc->holdpal != NULL)
{
- ReleaseDC (gc_private->hwnd, gc_private->xgc);
+ 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 & LINE_ATTRIBUTES)
+ if ((hpen = GetCurrentObject (win32_gc->hdc, OBJ_PEN)) == NULL)
+ WIN32_GDI_FAILED ("GetCurrentObject");
+
+ if (usage & GDK_GC_FOREGROUND)
+ if ((hbr = GetCurrentObject (win32_gc->hdc, OBJ_BRUSH)) == NULL)
+ WIN32_GDI_FAILED ("GetCurrentObject");
+
+ GDI_CALL (RestoreDC, (win32_gc->hdc, win32_gc->saved_dc));
+
+ _gdk_win32_drawable_release_dc (GDK_DRAWABLE (impl));
+
if (hpen != NULL)
- if (!DeleteObject (hpen))
- g_warning ("gdk_gc_postdraw: DeleteObject #1 failed");
+ GDI_CALL (DeleteObject, (hpen));
if (hbr != NULL)
- if (!DeleteObject (hbr))
- g_warning ("gdk_gc_postdraw: DeleteObject #2 failed");
+ GDI_CALL (DeleteObject, (hbr));
- gc_private->xgc = NULL;
+ if (win32_gc->pen_hbrbg != NULL)
+ GDI_CALL (DeleteObject, (win32_gc->pen_hbrbg));
+
+ win32_gc->hdc = NULL;
}
/* This function originally from Jean-Edouard Lachand-Robert, and
- * available at www.codeguru.com. Simplified for our needs, now
- * handles just one-bit deep bitmaps (in Window parlance, ie those
- * that GDK calls bitmaps (and not pixmaps), with zero pixels being
- * transparent.
+ * 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.
*/
-/*
- * BitmapToRegion : Create a region from the "non-transparent" pixels of
- * a bitmap
- * Author : Jean-Edouard Lachand-Robert
- * (http://www.geocities.com/Paris/LeftBank/1160/resume.htm), June 1998.
+/* _gdk_win32_bitmap_to_hrgn : Create a region from the
+ * "non-transparent" pixels of a bitmap.
*/
HRGN
-BitmapToRegion (HBITMAP hBmp)
+_gdk_win32_bitmap_to_hrgn (GdkPixmap *pixmap)
{
HRGN hRgn = NULL;
- HDC hMemDC;
- BITMAP bm;
-
- struct
- {
- BITMAPINFOHEADER bmiHeader;
-#if 1
- WORD bmiColors[2];
-#else
- RGBQUAD bmiColors[2];
-#endif
- } bmi;
- VOID *pbits8;
- HBITMAP hbm8;
- struct
- {
- WORD palVersion;
- WORD palNumEntries;
- PALETTEENTRY palPalEntry[2];
- } logpal;
- static HPALETTE bwPalette = NULL;
-
- HBITMAP holdBmp;
- HDC hDC;
-
- BITMAP bm8;
- HBITMAP holdBmp2;
+ HRGN h;
DWORD maxRects;
RGNDATA *pData;
- BYTE *p8;
- int x, y;
- HRGN h;
+ guchar *bits;
+ gint width, height, bpl;
+ guchar *p;
+ gint x, y;
- /* Create a B&W palette */
- if (bwPalette == NULL)
- {
- /* Create a b&w palette */
- logpal.palVersion = 0x300;
- logpal.palNumEntries = 2;
- logpal.palPalEntry[0].peRed =
- logpal.palPalEntry[0].peGreen =
- logpal.palPalEntry[0].peBlue = 0;
- logpal.palPalEntry[0].peFlags = 0;
- logpal.palPalEntry[1].peRed =
- logpal.palPalEntry[1].peGreen =
- logpal.palPalEntry[1].peBlue = 0xFF;
- logpal.palPalEntry[1].peFlags = 0;
- if ((bwPalette = CreatePalette ((LOGPALETTE *) &logpal)) == NULL)
- g_warning ("BitmapToRegion: CreatePalette failed");
- }
+ g_assert (GDK_PIXMAP_OBJECT(pixmap)->depth == 1);
- /* Create a memory DC inside which we will scan the bitmap content */
- hMemDC = CreateCompatibleDC (NULL);
- if (!hMemDC)
- {
- g_warning ("BitmapToRegion: CreateCompatibleDC #1 failed");
- return NULL;
- }
-
- SelectPalette (hMemDC, bwPalette, FALSE);
- RealizePalette (hMemDC);
-
- /* Get bitmap size */
- GetObject(hBmp, sizeof(bm), &bm);
-
- /* Create a 8 bits depth bitmap and select it into the memory DC */
- bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
- bmi.bmiHeader.biWidth = bm.bmWidth;
- bmi.bmiHeader.biHeight = bm.bmHeight;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biBitCount = 8;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biSizeImage = 0;
- bmi.bmiHeader.biXPelsPerMeter = 0;
- bmi.bmiHeader.biYPelsPerMeter = 0;
- bmi.bmiHeader.biClrUsed = 2;
- bmi.bmiHeader.biClrImportant = 2;
-#if 1
- bmi.bmiColors[0] = 0;
- bmi.bmiColors[1] = 1;
- hbm8 = CreateDIBSection (hMemDC, (BITMAPINFO *)&bmi,
- DIB_PAL_COLORS, &pbits8, NULL, 0);
-#else
- bmi.bmiColors[0].rgbBlue =
- bmi.bmiColors[0].rgbGreen =
- bmi.bmiColors[0].rgbRed = 0x00;
- bmi.bmiColors[0].rgbReserved = 0x00;
-
- bmi.bmiColors[1].rgbBlue =
- bmi.bmiColors[1].rgbGreen =
- bmi.bmiColors[1].rgbRed = 0xFF;
- bmi.bmiColors[0].rgbReserved = 0x00;
-
- hbm8 = CreateDIBSection (hMemDC, (BITMAPINFO *)&bmi,
- DIB_RGB_COLORS, &pbits8, NULL, 0);
-#endif
- if (!hbm8)
- {
- g_warning ("BitmapToRegion: CreateDIBSection failed");
- DeleteDC (hMemDC);
- return NULL;
- }
-
- holdBmp = (HBITMAP) SelectObject (hMemDC, hbm8);
-
- /* Create a DC just to copy the bitmap into the memory DC*/
- hDC = CreateCompatibleDC (hMemDC);
- if (!hDC)
- {
- g_warning ("BitmapToRegion: CreateCompatibleDC #2 failed");
- SelectObject (hMemDC, holdBmp);
- DeleteObject (hbm8);
- DeleteDC (hMemDC);
- return NULL;
- }
-
- /* Get how many bytes per row we have for the bitmap bits */
- GetObject (hbm8, sizeof (bm8), &bm8);
-
- /* Hans Breuer found a fix to the long-standing erroneous behaviour
- * on NT 4.0: There seems to be a bug in Win NT 4.0 GDI: scanlines
- * in bitmaps are dword aligned on both Win95 and NT. In the case of
- * a bitmap with 22 bytes worth of width, GetObject above returns
- * with bmWidth == 22. On Win95 bmWidthBytes == 24, as it should be,
- * but on NT is it 22. We need to correct this here.
- */
- bm8.bmWidthBytes = (((bm8.bmWidthBytes-1)/4)+1)*4; /* dword aligned!! */
-
- /* Copy the bitmap into the memory DC*/
- holdBmp2 = (HBITMAP) SelectObject (hDC, hBmp);
-
- if (!BitBlt (hMemDC, 0, 0, bm.bmWidth, bm.bmHeight, hDC, 0, 0, SRCCOPY))
- {
- g_warning ("BitmapToRegion: BitBlt failed");
- SelectObject (hDC, holdBmp2);
- SelectObject (hMemDC, holdBmp);
- DeleteObject (hbm8);
- DeleteDC (hMemDC);
- return NULL;
- }
- SelectObject (hDC, holdBmp2);
- DeleteDC (hDC);
+ bits = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->bits;
+ width = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->width;
+ height = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (pixmap)->impl)->height;
+ bpl = ((width - 1)/32 + 1)*4;
/* For better performances, we will use the ExtCreateRegion()
* function to create the region. This function take a RGNDATA
pData->rdh.nCount = pData->rdh.nRgnSize = 0;
SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0);
- /* Scan each bitmap from bottom to top (the bitmap is inverted vertically)*/
- p8 = (BYTE *) pbits8 + (bm8.bmHeight - 1) * bm8.bmWidthBytes;
- for (y = 0; y < bm.bmHeight; y++)
+ for (y = 0; y < height; y++)
{
/* Scan each bitmap row from left to right*/
- for (x = 0; x < bm.bmWidth; x++)
+ p = (guchar *) bits + y * bpl;
+ for (x = 0; x < width; x++)
{
/* Search for a continuous range of "non transparent pixels"*/
- int x0 = x;
- BYTE *p = p8 + x;
- while (x < bm.bmWidth)
+ gint x0 = x;
+ while (x < width)
{
- if (*p == 0)
+ if ((((p[x/8])>>(7-(x%8)))&1) == 0)
/* This pixel is "transparent"*/
break;
- p++;
x++;
}
}
}
}
-
- /* Go to next row (remember, the bitmap is inverted vertically)*/
- p8 -= bm8.bmWidthBytes;
}
/* Create or extend the region with the remaining rectangles*/
hRgn = h;
/* Clean up*/
- SelectObject(hMemDC, holdBmp);
- DeleteObject (hbm8);
- DeleteDC (hMemDC);
+ 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_MAXLONG, G_MAXLONG, G_MINLONG, G_MINLONG);
+
+ for (i = 0; i < region->numRects; i++)
+ {
+ rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++;
+
+ rect->left = boxes[i].x1 + x_origin;
+ rect->right = boxes[i].x2 + x_origin;
+ rect->top = boxes[i].y1 + y_origin;
+ rect->bottom = boxes[i].y2 + y_origin;
+
+ 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);
+}