summaryrefslogtreecommitdiff
path: root/gdk/win32/gdkgc-win32.c
diff options
context:
space:
mode:
authorTor Lillqvist <tml@iki.fi>2002-02-17 00:25:05 +0000
committerTor Lillqvist <tml@src.gnome.org>2002-02-17 00:25:05 +0000
commitbc1ec5c14adf484dc05d1818c99a382f3a6a330f (patch)
tree0e20f2f645aedf80a71300c7c322586de685fff2 /gdk/win32/gdkgc-win32.c
parentff612419cd913694ca33a8bb8adc7e6dfe9e7400 (diff)
downloadgtk+-bc1ec5c14adf484dc05d1818c99a382f3a6a330f.tar.gz
Massive changes. Too many to list here, but I'll try a summary:
2002-02-17 Tor Lillqvist <tml@iki.fi> * gdk/win32/*.c: Massive changes. Too many to list here, but I'll try a summary: 1) Unify GdkPixmap and GdkImage implementation: For each GdkPixmap, allocate a GdkImage, and vice versa. GdkPixmapImplWin32Data has a pointer to the GdkImage. GdkImage::windowing_data is a pointer to the GdkPixmap. This simplifies many pixmap and image related functions a lot, and reduces duplicated code snippets. For instance, there is only one place in gdk/win32 where CreateDIBSection() is called, in the function _gdk_win32_new_pixmap(). Converting a bitmap (GdkPixmap) to a Windows region is almost trivial, with the bitmap bits being readily accessible in the associated GdkImage. All blitting between GdkPixmaps, GdkWindows and GdkImages goes through handled the _gdk_win32_blit() function, which calls different functions to handle the cases of blitting from pixmaps, inside windows (scrolling), or from windows, which all require somewhat different handling. 2) Support 256-color mode. This has long been very broken, now it works more or less OK. Keep the logical palette for each colormap as small as possible while allocating and freeing colors. Select and realize the logical palette associated with a GdkColormap into a DC before drawing or blitting. When the display is in 256-color mode, make it possible for the user to override the size of the palette(s) used with either the GDK_WIN32_MAX_COLORS environment variable, or a -max-colors command line option. It is possible to reduce the palette size all the way down to using just the 16 static colors (which causes the system visual to be of type GDK_VISUAL_STATIC_COLOR. This could possibly be useful if one desperately wants to avoid color flashing. (Note that in order for this to work properly, an as of yet not commited fix to gdkrgb.c is needed.) Handle the palette messages. On WM_PALETTECHANGED, call UpdateColors() for the given window hierarchy. Do this only if a window in some other top-level window hierarchy caused the palette change (realized a palette). Do this max five times in a row (an arbitrarily chosen limit), though, otherwise redraw by generating expose events. On WM_QUERYNEWPALETTE, cause a redraw of the whole window hierarchy by generating GDK_EXPOSE events. 3) Code cleanup in general. For instance, remove the "emulated" X11 structs ColormapStruct, Visual and XStandardColormap. Use the new GDK_DEBUG_* flags for debugging output in the relevant source files. Remove the unused colormap hash table in gdkcolor-win32.c 4) Plug some resource leaks. 2002-02-14 Tor Lillqvist <tml@iki.fi> * gdk/win32/gdkdnd-win32.c (gdk_dropfiles_filter): Use g_filename_to_uri() to actually create legal URIs in the text/uri-list data.
Diffstat (limited to 'gdk/win32/gdkgc-win32.c')
-rw-r--r--gdk/win32/gdkgc-win32.c616
1 files changed, 204 insertions, 412 deletions
diff --git a/gdk/win32/gdkgc-win32.c b/gdk/win32/gdkgc-win32.c
index 670a4bb590..a5efc8b2c9 100644
--- a/gdk/win32/gdkgc-win32.c
+++ b/gdk/win32/gdkgc-win32.c
@@ -1,5 +1,6 @@
/* 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
@@ -118,22 +119,22 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
char *s = "";
gint sw, sh;
- GDK_NOTE (MISC, g_print ("{"));
+ 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 (MISC, (g_print ("fg=%.06lx", win32_gc->foreground),
- s = ","));
+ 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 (MISC, (g_print ("%sbg=%.06lx", s, win32_gc->background),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%sbg=%.06lx", s, win32_gc->background),
+ s = ","));
}
if ((mask & GDK_GC_FONT) && (values->font->type == GDK_FONT_FONT
@@ -148,89 +149,43 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
gdk_font_ref (win32_gc->font);
win32_gc->values_mask |= GDK_GC_FONT;
- GDK_NOTE (MISC, (xlfd = gdk_font_full_name_get (win32_gc->font),
- g_print ("%sfont=%s", s, xlfd),
- s = ",",
- gdk_font_full_name_free (xlfd)));
+ GDK_NOTE (GC, (xlfd = gdk_font_full_name_get (win32_gc->font),
+ g_print ("%sfont=%s", s, xlfd),
+ s = ",",
+ gdk_font_full_name_free (xlfd)));
}
else
{
win32_gc->values_mask &= ~GDK_GC_FONT;
- GDK_NOTE (MISC, (g_print ("%sfont=NULL", s),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%sfont=NULL", s),
+ s = ","));
}
}
if (mask & GDK_GC_FUNCTION)
{
- GDK_NOTE (MISC, (g_print ("%srop2=", s),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%srop2=", s),
+ s = ","));
switch (values->function)
{
- case GDK_COPY:
- win32_gc->rop2 = R2_COPYPEN;
- GDK_NOTE (MISC, g_print ("COPYPEN"));
- break;
- case GDK_INVERT:
- win32_gc->rop2 = R2_NOT;
- GDK_NOTE (MISC, g_print ("NOT"));
- break;
- case GDK_XOR:
- win32_gc->rop2 = R2_XORPEN;
- GDK_NOTE (MISC, g_print ("XORPEN"));
- break;
- case GDK_CLEAR:
- win32_gc->rop2 = R2_BLACK;
- GDK_NOTE (MISC, g_print ("BLACK"));
- break;
- case GDK_AND:
- win32_gc->rop2 = R2_MASKPEN;
- GDK_NOTE (MISC, g_print ("MASKPEN"));
- break;
- case GDK_AND_REVERSE:
- win32_gc->rop2 = R2_MASKPENNOT;
- GDK_NOTE (MISC, g_print ("MASKPENNOT"));
- break;
- case GDK_AND_INVERT:
- win32_gc->rop2 = R2_MASKNOTPEN;
- GDK_NOTE (MISC, g_print ("MASKNOTPEN"));
- break;
- case GDK_NOOP:
- win32_gc->rop2 = R2_NOP;
- GDK_NOTE (MISC, g_print ("NOP"));
- break;
- case GDK_OR:
- win32_gc->rop2 = R2_MERGEPEN;
- GDK_NOTE (MISC, g_print ("MERGEPEN"));
- break;
- case GDK_EQUIV:
- win32_gc->rop2 = R2_NOTXORPEN;
- GDK_NOTE (MISC, g_print ("NOTXORPEN"));
- break;
- case GDK_OR_REVERSE:
- win32_gc->rop2 = R2_MERGEPENNOT;
- GDK_NOTE (MISC, g_print ("MERGEPENNOT"));
- break;
- case GDK_COPY_INVERT:
- win32_gc->rop2 = R2_NOTCOPYPEN;
- GDK_NOTE (MISC, g_print ("NOTCOPYPEN"));
- break;
- case GDK_OR_INVERT:
- win32_gc->rop2 = R2_MERGENOTPEN;
- GDK_NOTE (MISC, g_print ("MERGENOTPEN"));
- break;
- case GDK_NAND:
- win32_gc->rop2 = R2_NOTMASKPEN;
- GDK_NOTE (MISC, g_print ("NOTMASKPEN"));
- break;
- case GDK_NOR:
- win32_gc->rop2 = R2_NOTMERGEPEN;
- GDK_NOTE (MISC, g_print ("NOTMERGEPEN"));
- break;
- case GDK_SET:
- win32_gc->rop2 = R2_WHITE;
- GDK_NOTE (MISC, g_print ("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
}
win32_gc->values_mask |= GDK_GC_FUNCTION;
}
@@ -239,8 +194,8 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
{
win32_gc->fill_style = values->fill;
win32_gc->values_mask |= GDK_GC_FILL;
- GDK_NOTE (MISC, (g_print ("%sfill=%d", s, win32_gc->fill_style),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%sfill=%d", s, win32_gc->fill_style),
+ s = ","));
}
if (mask & GDK_GC_TILE)
@@ -252,16 +207,16 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
{
gdk_drawable_ref (win32_gc->tile);
win32_gc->values_mask |= GDK_GC_TILE;
- GDK_NOTE (MISC,
- (g_print ("%stile=%#x", s,
- (guint) GDK_PIXMAP_HBITMAP (win32_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 (MISC, (g_print ("%stile=NULL", s),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%stile=NULL", s),
+ s = ","));
}
}
@@ -309,16 +264,16 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
#endif
gdk_drawable_ref (win32_gc->stipple);
win32_gc->values_mask |= GDK_GC_STIPPLE;
- GDK_NOTE (MISC,
- (g_print ("%sstipple=%#x", s,
- (guint) GDK_PIXMAP_HBITMAP (win32_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 (MISC, (g_print ("%sstipple=NULL", s),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%sstipple=NULL", s),
+ s = ","));
}
}
@@ -339,7 +294,7 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
if (values->clip_mask != NULL)
{
win32_gc->hcliprgn =
- BitmapToRegion ((HBITMAP) GDK_PIXMAP_HBITMAP (values->clip_mask));
+ _gdk_win32_bitmap_to_region (values->clip_mask);
win32_gc->values_mask |= GDK_GC_CLIP_MASK;
}
else
@@ -347,82 +302,82 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
win32_gc->hcliprgn = NULL;
win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
}
- GDK_NOTE (MISC, (g_print ("%sclip=%#x", s, (guint) win32_gc->hcliprgn),
- s = ","));
+ 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 (MISC, (g_print ("%ssubw=%d", s, win32_gc->subwindow_mode),
- s = ","));
+ 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 (MISC, (g_print ("%sts_x=%d", s, values->ts_x_origin),
- s = ","));
+ 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 (MISC, (g_print ("%sts_y=%d", s, values->ts_y_origin),
- s = ","));
+ 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 (MISC, (g_print ("%sclip_x=%d", s, values->clip_x_origin),
- s = ","));
+ 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 (MISC, (g_print ("%sclip_y=%d", s, values->clip_y_origin),
- s = ","));
+ 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 (MISC, (g_print ("%sexp=%d", s, win32_gc->graphics_exposures),
- s = ","));
+ 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 (MISC, (g_print ("%spw=%d", s, win32_gc->pen_width),
- s = ","));
+ GDK_NOTE (GC, (g_print ("%spw=%d", s, win32_gc->pen_width),
+ s = ","));
}
if (mask & GDK_GC_LINE_STYLE)
{
- GDK_NOTE (MISC, (g_print ("%sps|=", s),
- s = ","));
switch (values->line_style)
{
case GDK_LINE_SOLID:
win32_gc->pen_style &= ~(PS_STYLE_MASK);
- GDK_NOTE (MISC, g_print ("LINE_SOLID"));
+ GDK_NOTE (GC, (g_print ("%sps|=LINE_SOLID", s),
+ s = ","));
win32_gc->pen_style |= PS_SOLID;
break;
case GDK_LINE_ON_OFF_DASH:
case GDK_LINE_DOUBLE_DASH: /* ??? */
- /* only set the linestyle here, if it isn't already set
+ /* Only set the linestyle here, if it isn't already set
* gdk_win32_gc_set_dashes () knows better
*/
if (0 == (win32_gc->values_mask & GDK_GC_LINE_STYLE))
{
win32_gc->pen_style &= ~(PS_STYLE_MASK);
- GDK_NOTE (MISC, g_print ("DASH"));
+ GDK_NOTE (GC, (g_print ("%sps|=DASH", s),
+ s = ","));
win32_gc->pen_style |= PS_DASH;
}
break;
@@ -433,21 +388,22 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
if (mask & GDK_GC_CAP_STYLE)
{
win32_gc->pen_style &= ~(PS_ENDCAP_MASK);
- GDK_NOTE (MISC, (g_print ("%sps|=", s),
- s = ","));
switch (values->cap_style)
{
case GDK_CAP_NOT_LAST: /* ??? */
case GDK_CAP_BUTT:
- GDK_NOTE (MISC, g_print ("ENDCAP_FLAT"));
+ GDK_NOTE (GC, (g_print ("%sps|=ENDCAP_FLAT", s),
+ s = ","));
win32_gc->pen_style |= PS_ENDCAP_FLAT;
break;
case GDK_CAP_ROUND:
- GDK_NOTE (MISC, g_print ("ENDCAP_ROUND"));
+ GDK_NOTE (GC, (g_print ("%sps|=ENDCAP_ROUND", s),
+ s = ","));
win32_gc->pen_style |= PS_ENDCAP_ROUND;
break;
case GDK_CAP_PROJECTING:
- GDK_NOTE (MISC, g_print ("ENDCAP_SQUARE"));
+ GDK_NOTE (GC, (g_print ("%sps|=ENDCAP_SQUARE", s),
+ s = ","));
win32_gc->pen_style |= PS_ENDCAP_SQUARE;
break;
}
@@ -457,26 +413,27 @@ gdk_win32_gc_values_to_win32values (GdkGCValues *values,
if (mask & GDK_GC_JOIN_STYLE)
{
win32_gc->pen_style &= ~(PS_JOIN_MASK);
- GDK_NOTE (MISC, (g_print ("%sps|=", s),
- s = ","));
switch (values->join_style)
{
case GDK_JOIN_MITER:
- GDK_NOTE (MISC, g_print ("JOIN_MITER"));
+ GDK_NOTE (GC, (g_print ("%sps|=JOIN_MITER", s),
+ s = ","));
win32_gc->pen_style |= PS_JOIN_MITER;
break;
case GDK_JOIN_ROUND:
- GDK_NOTE (MISC, g_print ("JOIN_ROUND"));
+ GDK_NOTE (GC, (g_print ("%sps|=JOIN_ROUND", s),
+ s = ","));
win32_gc->pen_style |= PS_JOIN_ROUND;
break;
case GDK_JOIN_BEVEL:
- GDK_NOTE (MISC, g_print ("JOIN_BEVEL"));
+ GDK_NOTE (GC, (g_print ("%sps|=JOIN_BEVEL", s),
+ s = ","));
win32_gc->pen_style |= PS_JOIN_BEVEL;
break;
}
win32_gc->values_mask |= GDK_GC_JOIN_STYLE;
}
- GDK_NOTE (MISC, g_print ("}\n"));
+ GDK_NOTE (GC, g_print ("}\n"));
}
GdkGC*
@@ -514,12 +471,12 @@ _gdk_win32_gc_new (GdkDrawable *drawable,
win32_gc->values_mask = GDK_GC_FUNCTION | GDK_GC_FILL;
- GDK_NOTE (MISC, g_print ("_gdk_win32_gc_new: "));
+ GDK_NOTE (GC, g_print ("_gdk_win32_gc_new: "));
gdk_win32_gc_values_to_win32values (values, mask, win32_gc);
win32_gc->hwnd = NULL;
- GDK_NOTE (MISC, g_print (" = %p\n", gc));
+ GDK_NOTE (GC, g_print (" = %p\n", gc));
return gc;
}
@@ -617,7 +574,7 @@ gdk_win32_gc_set_values (GdkGC *gc,
{
g_return_if_fail (GDK_IS_GC (gc));
- GDK_NOTE (MISC, g_print ("gdk_win32_gc_set_values: "));
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_values: "));
gdk_win32_gc_values_to_win32values (values, mask, GDK_GC_WIN32 (gc));
}
@@ -652,46 +609,48 @@ gdk_win32_gc_set_dashes (GdkGC *gc,
*/
if (!IS_WIN_NT () && win32_gc->pen_width > 1)
{
- GDK_NOTE (MISC, g_print ("gdk_win32_gc_set_dashes: not fully supported\n"));
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: not fully supported\n"));
win32_gc->pen_style |= PS_SOLID;
return;
}
win32_gc->pen_style = PS_COSMETIC; /* ??? */
- if (2 == n)
+ switch (n)
{
+ case 2:
if ((dash_list[0] == dash_list[1]) && (dash_list[0] > 2))
{
win32_gc->pen_style |= PS_DASH;
- GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DASH (%d,%d)\n",
- dash_list[0], dash_list[1]));
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: PS_DASH (%d,%d)\n",
+ dash_list[0], dash_list[1]));
}
else
{
win32_gc->pen_style |= PS_DOT;
- GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DOT (%d,%d)\n",
- dash_list[0], dash_list[1]));
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: PS_DOT (%d,%d)\n",
+ dash_list[0], dash_list[1]));
}
- }
- else if (4 == n)
- {
+ break;
+
+ case 4:
win32_gc->pen_style |= PS_DASHDOT;
- GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DASHDOT (%d,%d,%d,%d)\n",
- dash_list[0], dash_list[1],
- dash_list[2], dash_list[3]));
- }
- else if (6 == n)
- {
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: PS_DASHDOT (%d,%d,%d,%d)\n",
+ dash_list[0], dash_list[1],
+ dash_list[2], dash_list[3]));
+ break;
+
+ case 6:
win32_gc->pen_style |= PS_DASHDOTDOT;
- GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: PS_DASHDOTDOT (%d,%d,%d,%d,%d,%d)\n",
- dash_list[0], dash_list[1],
- dash_list[2], dash_list[3],
- dash_list[4], dash_list[5]));
- }
- else
- {
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: PS_DASHDOTDOT (%d,%d,%d,%d,%d,%d)\n",
+ dash_list[0], dash_list[1],
+ dash_list[2], dash_list[3],
+ dash_list[4], dash_list[5]));
+ break;
+
+ default:
win32_gc->pen_style |= PS_DASH;
- GDK_NOTE (MISC, g_print("gdk_win32_gc_set_dashes: no guess for %d dashes\n", n));
+ GDK_NOTE (GC, g_print ("gdk_win32_gc_set_dashes: no guess for %d dashes\n", n));
+ break;
}
}
@@ -716,7 +675,7 @@ gdk_gc_set_clip_rectangle (GdkGC *gc,
if (rectangle)
{
- GDK_NOTE (MISC,
+ GDK_NOTE (GC,
g_print ("gdk_gc_set_clip_rectangle: %dx%d@+%d+%d\n",
rectangle->width, rectangle->height,
rectangle->x, rectangle->y));
@@ -725,7 +684,7 @@ gdk_gc_set_clip_rectangle (GdkGC *gc,
}
else
{
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_rectangle: NULL\n"));
+ GDK_NOTE (GC, g_print ("gdk_gc_set_clip_rectangle: NULL\n"));
win32_gc->clip_region = NULL;
win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
@@ -748,7 +707,7 @@ gdk_gc_set_clip_region (GdkGC *gc,
if (region)
{
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_region: %dx%d+%d+%d\n",
+ GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: %dx%d+%d+%d\n",
region->extents.x2 - region->extents.x1,
region->extents.y2 - region->extents.y1,
region->extents.x1, region->extents.y1));
@@ -758,7 +717,7 @@ gdk_gc_set_clip_region (GdkGC *gc,
}
else
{
- GDK_NOTE (MISC, g_print ("gdk_gc_set_clip_region: NULL\n"));
+ GDK_NOTE (GC, g_print ("gdk_gc_set_clip_region: NULL\n"));
win32_gc->clip_region = NULL;
win32_gc->values_mask &= ~GDK_GC_CLIP_MASK;
@@ -799,7 +758,7 @@ gdk_gc_copy (GdkGC *dst_gc,
if (dst_win32_gc->hcliprgn)
{
/* create a new region, to copy to */
- dst_win32_gc->hcliprgn = CreateRectRgn(0,0,1,1);
+ dst_win32_gc->hcliprgn = CreateRectRgn (0,0,1,1);
/* overwrite from source */
CombineRgn (dst_win32_gc->hcliprgn, src_win32_gc->hcliprgn,
NULL, RGN_COPY);
@@ -825,24 +784,33 @@ _gdk_win32_colormap_color (GdkColormap *colormap,
guchar r, g, b;
if (colormap == NULL)
- return PALETTEINDEX (pixel);
+ return DIBINDEX (pixel);
- colormap_private = GDK_COLORMAP_PRIVATE_DATA (colormap);
+ colormap_private = GDK_WIN32_COLORMAP_DATA (colormap);
- g_return_val_if_fail(colormap_private != NULL, RGB (0,0,0));
-
- if (colormap_private->xcolormap->rc_palette)
- return PALETTEINDEX (pixel);
+ g_assert (colormap_private != NULL);
visual = colormap->visual;
- 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);
+ 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
@@ -850,71 +818,35 @@ predraw_set_foreground (GdkGC *gc,
GdkColormap *colormap,
gboolean *ok)
{
- GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
- GdkColormapPrivateWin32 *colormap_private;
COLORREF fg;
LOGBRUSH logbrush;
HPEN hpen;
HBRUSH hbr;
+ GdkGCWin32 *win32_gc = (GdkGCWin32 *) gc;
+ GdkColormapPrivateWin32 *colormap_private;
+ gint k;
- if (colormap == NULL)
+ if (colormap &&
+ (colormap->visual->type == GDK_VISUAL_PSEUDO_COLOR ||
+ colormap->visual->type == GDK_VISUAL_STATIC_COLOR))
{
- /* A 1 bit deep bitmap */
- struct
- {
- WORD palVersion;
- WORD palNumEntries;
- PALETTEENTRY palPalEntry[2];
- } logpal;
- static HPALETTE hpal = NULL;
+ colormap_private = GDK_WIN32_COLORMAP_DATA (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)
- WIN32_GDI_FAILED ("CreatePalette"), *ok = FALSE;
- }
- SelectPalette (win32_gc->hdc, hpal, FALSE);
- RealizePalette (win32_gc->hdc);
- fg = PALETTEINDEX (win32_gc->foreground);
- }
- else
- {
- colormap_private = GDK_COLORMAP_PRIVATE_DATA (colormap);
- /* maybe this should bail out with g_return_if_fail
- * (colormap_private != NULL) ?
- */
- if (colormap_private && colormap_private->xcolormap->rc_palette)
- {
- int k;
- if (SelectPalette (win32_gc->hdc, colormap_private->xcolormap->palette,
- FALSE) == NULL)
- WIN32_GDI_FAILED ("SelectPalette"), *ok = FALSE;
- if (TRUE || colormap_private->xcolormap->stale)
- {
- if ((k = RealizePalette (win32_gc->hdc)) == GDI_ERROR)
- WIN32_GDI_FAILED ("RealizePalette"), *ok = FALSE;
- colormap_private->xcolormap->stale = FALSE;
- }
-#if 0
- g_print ("Selected palette %#x for gc %#x, realized %d colors\n",
- colormap_private->xcolormap->palette, win32_gc->hdc, k);
-#endif
- }
+ 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;
@@ -942,6 +874,7 @@ predraw_set_foreground (GdkGC *gc,
WIN32_GDI_FAILED ("SetBrushOrgEx"), *ok = FALSE;
break;
+
case GDK_SOLID:
default:
if (*ok && (hbr = CreateSolidBrush (fg)) == NULL)
@@ -953,8 +886,6 @@ predraw_set_foreground (GdkGC *gc,
HBRUSH old_hbr = SelectObject (win32_gc->hdc, hbr);
if (old_hbr == NULL)
WIN32_GDI_FAILED ("SelectObject"), *ok = FALSE;
- else if (!DeleteObject (old_hbr))
- WIN32_GDI_FAILED ("DeleteObject");
}
}
@@ -974,7 +905,7 @@ predraw_set_background (GdkGC *gc,
}
else
{
- if (0 == SetBkMode (win32_gc->hdc, TRANSPARENT))
+ if (!SetBkMode (win32_gc->hdc, TRANSPARENT))
WIN32_GDI_FAILED ("SetBkMode"), *ok = FALSE;
}
}
@@ -1025,9 +956,7 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
if (ok && (usage & GDK_GC_FOREGROUND))
predraw_set_foreground (gc, impl->colormap, &ok);
- if (ok
- && (usage & GDK_GC_BACKGROUND)
- /* && (win32_gc->values_mask & GDK_GC_BACKGROUND) */)
+ if (ok && (usage & GDK_GC_BACKGROUND))
predraw_set_background (gc, impl->colormap, &ok);
if (ok && (usage & GDK_GC_FONT))
@@ -1078,11 +1007,11 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
rect->bottom = CLAMP (boxes[i].y2 + gc->clip_y_origin,
G_MINSHORT, G_MAXSHORT);
- GDK_NOTE (MISC, g_print ("clip rgn box %d: %ldx%ld@+%ld+%ld\n",
- i,
- rect->right-rect->left,
- rect->bottom-rect->top,
- rect->left, rect->top));
+ GDK_NOTE (GC, g_print ("clip rgn box %d: %ldx%ld@+%ld+%ld\n",
+ i,
+ rect->right-rect->left,
+ rect->bottom-rect->top,
+ rect->left, rect->top));
if (rect->left < rgndata->rdh.rcBound.left)
rgndata->rdh.rcBound.left = rect->left;
@@ -1104,7 +1033,7 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
if ( (win32_gc->values_mask & GDK_GC_STIPPLE)
&& (win32_gc->values_mask & GDK_GC_FILL) && (win32_gc->fill_style == GDK_STIPPLED))
{
- HRGN hstipplergn = BitmapToRegion ((HBITMAP) GDK_PIXMAP_HBITMAP (win32_gc->stipple));
+ HRGN hstipplergn = _gdk_win32_bitmap_to_region (win32_gc->stipple);
if (OffsetRgn (hstipplergn,
win32_gc->values_mask & GDK_GC_TS_X_ORIGIN ? gc->ts_x_origin : 0,
@@ -1132,8 +1061,8 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
win32_gc->values_mask & GDK_GC_CLIP_Y_ORIGIN ? gc->clip_y_origin : 0))
WIN32_API_FAILED ("OffsetClipRgn"), ok = FALSE;
}
-
- if (_gdk_debug_flags & GDK_DEBUG_MISC)
+#ifdef G_ENABLE_DEBUG
+ if (_gdk_debug_flags & GDK_DEBUG_GC)
{
HGDIOBJ obj;
LOGBRUSH logbrush;
@@ -1141,10 +1070,10 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
HRGN hrgn;
RECT rect;
- g_print ("gdk_win32_hdc_get: %#x\n", (guint) win32_gc->hdc);
+ g_print ("gdk_win32_hdc_get: %p\n", win32_gc->hdc);
obj = GetCurrentObject (win32_gc->hdc, OBJ_BRUSH);
GetObject (obj, sizeof (LOGBRUSH), &logbrush);
- g_print ("brush: style: %s color: %.06lx hatch: %#lx\n",
+ g_print ("brush: style: %s color: %06lx hatch: %#lx\n",
(logbrush.lbStyle == BS_HOLLOW ? "HOLLOW" :
(logbrush.lbStyle == BS_PATTERN ? "PATTERN" :
(logbrush.lbStyle == BS_SOLID ? "SOLID" :
@@ -1196,8 +1125,9 @@ gdk_win32_hdc_get (GdkDrawable *drawable,
rect.bottom - rect.top,
rect.left, rect.top);
}
+ DeleteObject (hrgn);
}
-
+#endif
return win32_gc->hdc;
}
@@ -1211,6 +1141,8 @@ gdk_win32_hdc_release (GdkDrawable *drawable,
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))
@@ -1220,6 +1152,20 @@ gdk_win32_hdc_release (GdkDrawable *drawable,
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)
@@ -1231,16 +1177,7 @@ gdk_win32_hdc_release (GdkDrawable *drawable,
if (!RestoreDC (win32_gc->hdc, win32_gc->saved_dc))
WIN32_GDI_FAILED ("RestoreDC");
-#if 0
- if (colormap_private != NULL
- && colormap_private->xcolormap->rc_palette
- && colormap_private->xcolormap->stale)
- {
- SelectPalette (win32_gc->hdc, GetStockObject (DEFAULT_PALETTE), FALSE);
- if (!UnrealizeObject (colormap_private->xcolormap->palette))
- WIN32_GDI_FAILED ("UnrealizeObject");
- }
-#endif
+
if (GDK_IS_PIXMAP_IMPL_WIN32 (impl))
{
if (!DeleteDC (win32_gc->hdc))
@@ -1264,165 +1201,29 @@ gdk_win32_hdc_release (GdkDrawable *drawable,
}
/* 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_region : Create a region from the
+ * "non-transparent" pixels of a bitmap.
*/
HRGN
-BitmapToRegion (HBITMAP hBmp)
+_gdk_win32_bitmap_to_region (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;
-
- /* 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)
- WIN32_GDI_FAILED ("CreatePalette");
- }
+ GdkImage *image;
+ guchar *p;
+ gint x, y;
- /* Create a memory DC inside which we will scan the bitmap content */
- hMemDC = CreateCompatibleDC (NULL);
- if (!hMemDC)
- {
- WIN32_GDI_FAILED ("CreateCompatibleDC");
- 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)
- {
- WIN32_GDI_FAILED ("CreateDIBSection");
- 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)
- {
- WIN32_GDI_FAILED ("CreateCompatibleDC");
- 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))
- {
- WIN32_GDI_FAILED ("BitBlt");
- SelectObject (hDC, holdBmp2);
- SelectObject (hMemDC, holdBmp);
- DeleteObject (hbm8);
- DeleteDC (hMemDC);
- return NULL;
- }
- SelectObject (hDC, holdBmp2);
- DeleteDC (hDC);
+ 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
@@ -1438,22 +1239,19 @@ BitmapToRegion (HBITMAP hBmp)
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 < image->height; y++)
{
/* Scan each bitmap row from left to right*/
- for (x = 0; x < bm.bmWidth; x++)
+ p = (guchar *) image->mem + y * image->bpl;
+ for (x = 0; x < image->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 < image->width)
{
- if (*p == 0)
+ if ((((p[x/8])>>(7-(x%8)))&1) == 0)
/* This pixel is "transparent"*/
break;
- p++;
x++;
}
@@ -1501,9 +1299,6 @@ BitmapToRegion (HBITMAP hBmp)
}
}
}
-
- /* Go to next row (remember, the bitmap is inverted vertically)*/
- p8 -= bm8.bmWidthBytes;
}
/* Create or extend the region with the remaining rectangles*/
@@ -1519,9 +1314,6 @@ BitmapToRegion (HBITMAP hBmp)
/* Clean up*/
g_free (pData);
- SelectObject(hMemDC, holdBmp);
- DeleteObject (hbm8);
- DeleteDC (hMemDC);
return hRgn;
}