diff options
author | Tor Lillqvist <tml@iki.fi> | 2010-08-23 18:49:30 +0300 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2010-08-23 18:55:54 +0300 |
commit | 56f71f0123d12e46029a2494a0421f6f50176675 (patch) | |
tree | a3f0b223678725b5260c1c57d9336aa5d447dba1 | |
parent | 29a758d4c267efc3d8beb7329cb9e831627764f2 (diff) | |
download | gtk+-56f71f0123d12e46029a2494a0421f6f50176675.tar.gz |
Fix Win32 build
Builds now, except for the ms-windows theme engine. It doesn't really
work, though.
-rw-r--r-- | gdk/gdk.symbols | 7 | ||||
-rw-r--r-- | gdk/win32/gdkdrawable-win32.c | 404 | ||||
-rw-r--r-- | gdk/win32/gdkmain-win32.c | 129 | ||||
-rw-r--r-- | gdk/win32/gdkpixmap-win32.c | 33 | ||||
-rw-r--r-- | gdk/win32/gdkprivate-win32.h | 17 | ||||
-rw-r--r-- | gdk/win32/gdkvisual-win32.c | 8 | ||||
-rw-r--r-- | gdk/win32/gdkwin32.h | 16 | ||||
-rw-r--r-- | gdk/win32/gdkwindow-win32.c | 179 | ||||
-rw-r--r-- | gtk/Makefile.am | 4 |
9 files changed, 209 insertions, 588 deletions
diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index 21207fbf64..acf147074b 100644 --- a/gdk/gdk.symbols +++ b/gdk/gdk.symbols @@ -989,13 +989,6 @@ gdk_win32_set_modal_dialog_libgtk_only #endif #if IN_HEADER(__GDK_WIN32_H__) -#if IN_FILE(__GDK_GC_WIN32_C__) -gdk_win32_hdc_get -gdk_win32_hdc_release -#endif -#endif - -#if IN_HEADER(__GDK_WIN32_H__) #if IN_FILE(__GDK_SELECTION_WIN32_C__) gdk_win32_selection_add_targets #endif diff --git a/gdk/win32/gdkdrawable-win32.c b/gdk/win32/gdkdrawable-win32.c index 403ffad12b..7fd01d8434 100644 --- a/gdk/win32/gdkdrawable-win32.c +++ b/gdk/win32/gdkdrawable-win32.c @@ -76,8 +76,6 @@ _gdk_drawable_impl_win32_class_init (GdkDrawableImplWin32Class *klass) object_class->finalize = gdk_drawable_impl_win32_finalize; - drawable_class->create_gc = _gdk_win32_gc_new; - drawable_class->ref_cairo_surface = gdk_win32_ref_cairo_surface; drawable_class->set_colormap = gdk_win32_set_colormap; @@ -130,408 +128,6 @@ gdk_win32_set_colormap (GdkDrawable *drawable, /* Drawing */ -static int -rop2_to_rop3 (int rop2) -{ - switch (rop2) - { - /* Oh, Microsoft's silly names for binary and ternary rops. */ -#define CASE(rop2,rop3) case R2_##rop2: return rop3 - CASE (BLACK, BLACKNESS); - CASE (NOTMERGEPEN, NOTSRCERASE); - CASE (MASKNOTPEN, 0x00220326); - CASE (NOTCOPYPEN, NOTSRCCOPY); - CASE (MASKPENNOT, SRCERASE); - CASE (NOT, DSTINVERT); - CASE (XORPEN, SRCINVERT); - CASE (NOTMASKPEN, 0x007700E6); - CASE (MASKPEN, SRCAND); - CASE (NOTXORPEN, 0x00990066); - CASE (NOP, 0x00AA0029); - CASE (MERGENOTPEN, MERGEPAINT); - CASE (COPYPEN, SRCCOPY); - CASE (MERGEPENNOT, 0x00DD0228); - CASE (MERGEPEN, SRCPAINT); - CASE (WHITE, WHITENESS); -#undef CASE - default: return SRCCOPY; - } -} - -static int -rop2_to_patblt_rop (int rop2) -{ - switch (rop2) - { -#define CASE(rop2,patblt_rop) case R2_##rop2: return patblt_rop - CASE (COPYPEN, PATCOPY); - CASE (XORPEN, PATINVERT); - CASE (NOT, DSTINVERT); - CASE (BLACK, BLACKNESS); - CASE (WHITE, WHITENESS); -#undef CASE - default: - g_warning ("Unhandled rop2 in GC to be used in PatBlt: %#x", rop2); - return PATCOPY; - } -} - -static inline int -align_with_dash_offset (int a, DWORD *dashes, int num_dashes, GdkGCWin32 *gcwin32) -{ - int n = 0; - int len_sum = 0; - /* - * We can't simply add the dashoffset, it can be an arbitrary larger - * or smaller value not even between x1 and x2. It just says use the - * dash pattern aligned to the offset. So ensure x1 is smaller _x1 - * and we start with the appropriate dash. - */ - for (n = 0; n < num_dashes; n++) - len_sum += dashes[n]; - if ( len_sum > 0 /* pathological api usage? */ - && gcwin32->pen_dash_offset > a) - a -= (((gcwin32->pen_dash_offset/len_sum - a/len_sum) + 1) * len_sum); - else - a = gcwin32->pen_dash_offset; - - return a; -} - -/* Render a dashed line 'by hand'. Used for all dashes on Win9x (where - * GDI is way too limited), and for double dashes on all Windowses. - */ -static inline gboolean -render_line_horizontal (GdkGCWin32 *gcwin32, - int x1, - int x2, - int y) -{ - int n = 0; - const int pen_width = MAX (gcwin32->pen_width, 1); - const int _x1 = x1; - - g_assert (gcwin32->pen_dashes); - - x1 = align_with_dash_offset (x1, gcwin32->pen_dashes, gcwin32->pen_num_dashes, gcwin32); - - for (n = 0; x1 < x2; n++) - { - int len = gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - if (x1 + len > x2) - len = x2 - x1; - - if (n % 2 == 0 && x1 + len > _x1) - if (!GDI_CALL (PatBlt, (gcwin32->hdc, - x1 < _x1 ? _x1 : x1, - y - pen_width / 2, - len, pen_width, - rop2_to_patblt_rop (gcwin32->rop2)))) - return FALSE; - - x1 += gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - } - - if (gcwin32->line_style == GDK_LINE_DOUBLE_DASH) - { - HBRUSH hbr; - - if ((hbr = SelectObject (gcwin32->hdc, gcwin32->pen_hbrbg)) == HGDI_ERROR) - return FALSE; - x1 = _x1; - x1 += gcwin32->pen_dash_offset; - for (n = 0; x1 < x2; n++) - { - int len = gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - if (x1 + len > x2) - len = x2 - x1; - - if (n % 2) - if (!GDI_CALL (PatBlt, (gcwin32->hdc, x1, y - pen_width / 2, - len, pen_width, - rop2_to_patblt_rop (gcwin32->rop2)))) - return FALSE; - - x1 += gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - } - if (SelectObject (gcwin32->hdc, hbr) == HGDI_ERROR) - return FALSE; - } - - return TRUE; -} - -static inline gboolean -render_line_vertical (GdkGCWin32 *gcwin32, - int x, - int y1, - int y2) -{ - int n; - const int pen_width = MAX (gcwin32->pen_width, 1); - const int _y1 = y1; - - g_assert (gcwin32->pen_dashes); - - y1 = align_with_dash_offset (y1, gcwin32->pen_dashes, gcwin32->pen_num_dashes, gcwin32); - for (n = 0; y1 < y2; n++) - { - int len = gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - if (y1 + len > y2) - len = y2 - y1; - if (n % 2 == 0 && y1 + len > _y1) - if (!GDI_CALL (PatBlt, (gcwin32->hdc, x - pen_width / 2, - y1 < _y1 ? _y1 : y1, - pen_width, len, - rop2_to_patblt_rop (gcwin32->rop2)))) - return FALSE; - - y1 += gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - } - - if (gcwin32->line_style == GDK_LINE_DOUBLE_DASH) - { - HBRUSH hbr; - - if ((hbr = SelectObject (gcwin32->hdc, gcwin32->pen_hbrbg)) == HGDI_ERROR) - return FALSE; - y1 = _y1; - y1 += gcwin32->pen_dash_offset; - for (n = 0; y1 < y2; n++) - { - int len = gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - if (y1 + len > y2) - len = y2 - y1; - if (n % 2) - if (!GDI_CALL (PatBlt, (gcwin32->hdc, x - pen_width / 2, y1, - pen_width, len, - rop2_to_patblt_rop (gcwin32->rop2)))) - return FALSE; - - y1 += gcwin32->pen_dashes[n % gcwin32->pen_num_dashes]; - } - if (SelectObject (gcwin32->hdc, hbr) == HGDI_ERROR) - return FALSE; - } - - return TRUE; -} - -static cairo_region_t * -widen_bounds (GdkRectangle *bounds, - gint pen_width) -{ - if (pen_width == 0) - pen_width = 1; - - bounds->x -= pen_width; - bounds->y -= pen_width; - bounds->width += 2 * pen_width; - bounds->height += 2 * pen_width; - - return cairo_region_create_rectangle (bounds); -} - -static void -blit_from_pixmap (gboolean use_fg_bg, - GdkDrawableImplWin32 *dest, - HDC hdc, - GdkPixmapImplWin32 *src, - GdkGC *gc, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height) -{ - GdkGCWin32 *gcwin32 = GDK_GC_WIN32 (gc); - HDC srcdc; - HBITMAP holdbitmap; - RGBQUAD oldtable[256], newtable[256]; - COLORREF bg, fg; - - gint newtable_size = 0, oldtable_size = 0; - gboolean ok = TRUE; - - GDK_NOTE (DRAW, g_print ("blit_from_pixmap\n")); - - srcdc = _gdk_win32_drawable_acquire_dc (GDK_DRAWABLE (src)); - if (!srcdc) - return; - - if (!(holdbitmap = SelectObject (srcdc, ((GdkDrawableImplWin32 *) src)->handle))) - WIN32_GDI_FAILED ("SelectObject"); - else - { - if (GDK_PIXMAP_OBJECT (src->parent_instance.wrapper)->depth <= 8) - { - /* Blitting from a 1, 4 or 8-bit pixmap */ - - if ((oldtable_size = GetDIBColorTable (srcdc, 0, 256, oldtable)) == 0) - WIN32_GDI_FAILED ("GetDIBColorTable"); - else if (GDK_PIXMAP_OBJECT (src->parent_instance.wrapper)->depth == 1) - { - /* Blitting from an 1-bit pixmap */ - - gint bgix, fgix; - - if (use_fg_bg) - { - bgix = _gdk_gc_get_bg_pixel (gc); - fgix = _gdk_gc_get_fg_pixel (gc); - } - else - { - bgix = 0; - fgix = 1; - } - - if (GDK_IS_PIXMAP_IMPL_WIN32 (dest) && - GDK_PIXMAP_OBJECT (dest->wrapper)->depth <= 8) - { - /* Destination is also pixmap, get fg and bg from - * its palette. Either use the foreground and - * background pixel values in the GC, or 0 - * and 1 to index the palette. - */ - if (!GDI_CALL (GetDIBColorTable, (hdc, bgix, 1, newtable)) || - !GDI_CALL (GetDIBColorTable, (hdc, fgix, 1, newtable+1))) - ok = FALSE; - } - else - { - /* Destination is a window, get fg and bg from its - * colormap - */ - - bg = _gdk_win32_colormap_color (dest->colormap, bgix); - fg = _gdk_win32_colormap_color (dest->colormap, fgix); - newtable[0].rgbBlue = GetBValue (bg); - newtable[0].rgbGreen = GetGValue (bg); - newtable[0].rgbRed = GetRValue (bg); - newtable[0].rgbReserved = 0; - newtable[1].rgbBlue = GetBValue (fg); - newtable[1].rgbGreen = GetGValue (fg); - newtable[1].rgbRed = GetRValue (fg); - newtable[1].rgbReserved = 0; - } - if (ok) - GDK_NOTE (DRAW, g_print ("bg: %02x %02x %02x " - "fg: %02x %02x %02x\n", - newtable[0].rgbRed, - newtable[0].rgbGreen, - newtable[0].rgbBlue, - newtable[1].rgbRed, - newtable[1].rgbGreen, - newtable[1].rgbBlue)); - newtable_size = 2; - } - else if (GDK_IS_PIXMAP_IMPL_WIN32 (dest)) - { - /* Destination is pixmap, get its color table */ - - if ((newtable_size = GetDIBColorTable (hdc, 0, 256, newtable)) == 0) - WIN32_GDI_FAILED ("GetDIBColorTable"), ok = FALSE; - } - - /* If blitting between pixmaps, set source's color table */ - if (ok && newtable_size > 0) - { - GDK_NOTE (MISC_OR_COLORMAP, - g_print ("blit_from_pixmap: set color table" - " hdc=%p count=%d\n", - srcdc, newtable_size)); - if (!GDI_CALL (SetDIBColorTable, (srcdc, 0, newtable_size, newtable))) - ok = FALSE; - } - } - - if (ok) - if (!BitBlt (hdc, xdest, ydest, width, height, - srcdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2)) && - GetLastError () != ERROR_INVALID_HANDLE) - WIN32_GDI_FAILED ("BitBlt"); - - /* Restore source's color table if necessary */ - if (ok && newtable_size > 0 && oldtable_size > 0) - { - GDK_NOTE (MISC_OR_COLORMAP, - g_print ("blit_from_pixmap: reset color table" - " hdc=%p count=%d\n", - srcdc, oldtable_size)); - GDI_CALL (SetDIBColorTable, (srcdc, 0, oldtable_size, oldtable)); - } - - GDI_CALL (SelectObject, (srcdc, holdbitmap)); - } - - _gdk_win32_drawable_release_dc (GDK_DRAWABLE (src)); -} - -static void -blit_inside_drawable (HDC hdc, - GdkGCWin32 *gcwin32, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height) - -{ - GDK_NOTE (DRAW, g_print ("blit_inside_drawable\n")); - - GDI_CALL (BitBlt, (hdc, xdest, ydest, width, height, - hdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2))); -} - -static void -blit_from_window (HDC hdc, - GdkGCWin32 *gcwin32, - GdkDrawableImplWin32 *src, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height) -{ - HDC srcdc; - HPALETTE holdpal = NULL; - GdkColormap *cmap = gdk_colormap_get_system (); - - GDK_NOTE (DRAW, g_print ("blit_from_window\n")); - - if ((srcdc = GetDC (src->handle)) == NULL) - { - WIN32_GDI_FAILED ("GetDC"); - return; - } - - if (cmap->visual->type == GDK_VISUAL_PSEUDO_COLOR || - cmap->visual->type == GDK_VISUAL_STATIC_COLOR) - { - gint k; - - if (!(holdpal = SelectPalette (srcdc, GDK_WIN32_COLORMAP_DATA (cmap)->hpal, FALSE))) - WIN32_GDI_FAILED ("SelectPalette"); - else if ((k = RealizePalette (srcdc)) == GDI_ERROR) - WIN32_GDI_FAILED ("RealizePalette"); - else if (k > 0) - GDK_NOTE (MISC_OR_COLORMAP, - g_print ("blit_from_window: realized %d\n", k)); - } - - GDI_CALL (BitBlt, (hdc, xdest, ydest, width, height, - srcdc, xsrc, ysrc, rop2_to_rop3 (gcwin32->rop2))); - - if (holdpal != NULL) - GDI_CALL (SelectPalette, (srcdc, holdpal, FALSE)); - - GDI_CALL (ReleaseDC, (src->handle, srcdc)); -} - /** * _gdk_win32_drawable_acquire_dc * @drawable: a Win32 #GdkDrawable implementation diff --git a/gdk/win32/gdkmain-win32.c b/gdk/win32/gdkmain-win32.c index 8c684d0223..02ab4eab31 100644 --- a/gdk/win32/gdkmain-win32.c +++ b/gdk/win32/gdkmain-win32.c @@ -389,100 +389,6 @@ _gdk_win32_print_dc (HDC hdc) } gchar * -_gdk_win32_cap_style_to_string (GdkCapStyle cap_style) -{ - switch (cap_style) - { -#define CASE(x) case GDK_CAP_##x: return #x - CASE (NOT_LAST); - CASE (BUTT); - CASE (ROUND); - CASE (PROJECTING); -#undef CASE - default: return static_printf ("illegal_%d", cap_style); - } - /* NOTREACHED */ - return NULL; -} - -gchar * -_gdk_win32_fill_style_to_string (GdkFill fill) -{ - switch (fill) - { -#define CASE(x) case GDK_##x: return #x - CASE (SOLID); - CASE (TILED); - CASE (STIPPLED); - CASE (OPAQUE_STIPPLED); -#undef CASE - default: return static_printf ("illegal_%d", fill); - } - /* NOTREACHED */ - return NULL; -} - -gchar * -_gdk_win32_function_to_string (GdkFunction function) -{ - switch (function) - { -#define CASE(x) case GDK_##x: return #x - CASE (COPY); - CASE (INVERT); - CASE (XOR); - CASE (CLEAR); - CASE (AND); - CASE (AND_REVERSE); - CASE (AND_INVERT); - CASE (NOOP); - CASE (OR); - CASE (EQUIV); - CASE (OR_REVERSE); - CASE (COPY_INVERT); - CASE (OR_INVERT); - CASE (NAND); - CASE (SET); -#undef CASE - default: return static_printf ("illegal_%d", function); - } - /* NOTREACHED */ - return NULL; -} - -gchar * -_gdk_win32_join_style_to_string (GdkJoinStyle join_style) -{ - switch (join_style) - { -#define CASE(x) case GDK_JOIN_##x: return #x - CASE (MITER); - CASE (ROUND); - CASE (BEVEL); -#undef CASE - default: return static_printf ("illegal_%d", join_style); - } - /* NOTREACHED */ - return NULL; -} - -gchar * -_gdk_win32_line_style_to_string (GdkLineStyle line_style) -{ - switch (line_style) - { -#define CASE(x) case GDK_LINE_##x: return #x - CASE(SOLID); - CASE(ON_OFF_DASH); - CASE(DOUBLE_DASH); -#undef CASE - default: return static_printf ("illegal_%d", line_style); - } - /* NOTREACHED */ - return NULL; -} - -gchar * _gdk_win32_drag_protocol_to_string (GdkDragProtocol protocol) { switch (protocol) @@ -503,41 +409,6 @@ _gdk_win32_drag_protocol_to_string (GdkDragProtocol protocol) } gchar * -_gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask) -{ - gchar buf[400]; - gchar *bufp = buf; - gchar *s = ""; - - buf[0] = '\0'; - -#define BIT(x) \ - if (mask & GDK_GC_##x) \ - (bufp += g_sprintf (bufp, "%s" #x, s), s = "|") - - BIT (FOREGROUND); - BIT (BACKGROUND); - BIT (FUNCTION); - BIT (FILL); - BIT (TILE); - BIT (STIPPLE); - BIT (CLIP_MASK); - BIT (SUBWINDOW); - BIT (TS_X_ORIGIN); - BIT (TS_Y_ORIGIN); - BIT (CLIP_X_ORIGIN); - BIT (CLIP_Y_ORIGIN); - BIT (EXPOSURES); - BIT (LINE_WIDTH); - BIT (LINE_STYLE); - BIT (CAP_STYLE); - BIT (JOIN_STYLE); -#undef BIT - - return static_printf ("%s", buf); -} - -gchar * _gdk_win32_window_state_to_string (GdkWindowState state) { gchar buf[100]; diff --git a/gdk/win32/gdkpixmap-win32.c b/gdk/win32/gdkpixmap-win32.c index ad706a0ba2..f711ef766f 100644 --- a/gdk/win32/gdkpixmap-win32.c +++ b/gdk/win32/gdkpixmap-win32.c @@ -129,6 +129,37 @@ gdk_pixmap_impl_win32_get_size (GdkDrawable *drawable, *height = GDK_PIXMAP_IMPL_WIN32 (drawable)->height; } +static int +bits_for_depth (gint depth) +{ + switch (depth) + { + case 1: + return 1; + + case 2: + case 3: + case 4: + return 4; + + case 5: + case 6: + case 7: + case 8: + return 8; + + case 15: + case 16: + return 16; + + case 24: + case 32: + return 32; + } + g_assert_not_reached (); + return 0; +} + GdkPixmap* _gdk_pixmap_new (GdkDrawable *drawable, gint width, @@ -210,7 +241,7 @@ _gdk_pixmap_new (GdkDrawable *drawable, case 1: case 24: case 32: - bmi.bmiHeader.biBitCount = _gdk_windowing_get_bits_for_depth (gdk_display_get_default (), depth); + bmi.bmiHeader.biBitCount = bits_for_depth (depth); break; case 4: diff --git a/gdk/win32/gdkprivate-win32.h b/gdk/win32/gdkprivate-win32.h index 6e97ac50a5..b7b279ebf2 100644 --- a/gdk/win32/gdkprivate-win32.h +++ b/gdk/win32/gdkprivate-win32.h @@ -181,17 +181,6 @@ void gdk_win32_handle_table_insert (HANDLE *handle, gpointer data); void gdk_win32_handle_table_remove (HANDLE handle); -void _gdk_win32_blit (gboolean use_fg_bg, - GdkDrawableImplWin32 *drawable, - GdkGC *gc, - GdkDrawable *src, - gint xsrc, - gint ysrc, - gint xdest, - gint ydest, - gint width, - gint height); - COLORREF _gdk_win32_colormap_color (GdkColormap *colormap, gulong pixel); @@ -223,13 +212,7 @@ void _gdk_win32_print_system_palette (void); void _gdk_win32_print_hpalette (HPALETTE hpal); void _gdk_win32_print_dc (HDC hdc); -gchar *_gdk_win32_cap_style_to_string (GdkCapStyle cap_style); -gchar *_gdk_win32_fill_style_to_string (GdkFill fill); -gchar *_gdk_win32_function_to_string (GdkFunction function); -gchar *_gdk_win32_join_style_to_string (GdkJoinStyle join_style); -gchar *_gdk_win32_line_style_to_string (GdkLineStyle line_style); gchar *_gdk_win32_drag_protocol_to_string (GdkDragProtocol protocol); -gchar *_gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask); gchar *_gdk_win32_window_state_to_string (GdkWindowState state); gchar *_gdk_win32_window_style_to_string (LONG style); gchar *_gdk_win32_window_exstyle_to_string (LONG style); diff --git a/gdk/win32/gdkvisual-win32.c b/gdk/win32/gdkvisual-win32.c index 440f6ce844..b3d20b7031 100644 --- a/gdk/win32/gdkvisual-win32.c +++ b/gdk/win32/gdkvisual-win32.c @@ -122,34 +122,26 @@ _gdk_visual_init (void) if (map_entries >= 16 && map_entries < sizepalette) { - /* The calls to gdk_rgb_set_min_colors() here have knowledge - * of what color cubes gdk_rgb_do_colormaps() will try, and - * of the static system palette colors... XXX - */ if (map_entries < 32) { map_entries = 16; system_visual->type = GDK_VISUAL_STATIC_COLOR; bitspixel = 4; - gdk_rgb_set_min_colors (2*2*2); } else if (map_entries < 64) { map_entries = 32; bitspixel = 5; - gdk_rgb_set_min_colors (3*3*3); } else if (map_entries < 128) { map_entries = 64; bitspixel = 6; - gdk_rgb_set_min_colors (3*3*3); } else if (map_entries < 256) { map_entries = 128; bitspixel = 7; - gdk_rgb_set_min_colors (5*5*4); } else g_assert_not_reached (); diff --git a/gdk/win32/gdkwin32.h b/gdk/win32/gdkwin32.h index fef1400996..df76effd2c 100644 --- a/gdk/win32/gdkwin32.h +++ b/gdk/win32/gdkwin32.h @@ -82,22 +82,6 @@ gpointer gdk_win32_handle_table_lookup (GdkNativeWindow handle); /* Translate from drawable to Windows handle */ HGDIOBJ gdk_win32_drawable_get_handle (GdkDrawable *drawable); -/* Return a device context to draw in a drawable, given a GDK GC, - * and a mask indicating which GC values might be used (for efficiency, - * no need to muck around with text-related stuff if we aren't going - * to output text, for instance). - */ -HDC gdk_win32_hdc_get (GdkDrawable *drawable, - GdkGC *gc, - GdkGCValuesMask usage); - -/* Each HDC returned from gdk_win32_hdc_get must be released with - * this function - */ -void gdk_win32_hdc_release (GdkDrawable *drawable, - GdkGC *gc, - GdkGCValuesMask usage); - void gdk_win32_selection_add_targets (GdkWindow *owner, GdkAtom selection, gint n_targets, diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index d93e57eec5..71b3dedc03 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -3130,6 +3130,54 @@ gdk_window_get_type_hint (GdkWindow *window) return GDK_WINDOW_IMPL_WIN32 (((GdkWindowObject *) window)->impl)->type_hint; } +static HRGN +cairo_region_to_hrgn (const cairo_region_t *region, + gint x_origin, + gint y_origin) +{ + HRGN hrgn; + RGNDATA *rgndata; + RECT *rect; + cairo_rectangle_int_t r; + const int nrects = cairo_region_num_rectangles (region); + guint nbytes = + sizeof (RGNDATAHEADER) + (sizeof (RECT) * nrects); + 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 < nrects; i++) + { + rect = ((RECT *) rgndata->Buffer) + rgndata->rdh.nCount++; + + cairo_region_get_rectangle (region, i, &r); + rect->left = r.x + x_origin; + rect->right = rect->left + r.width; + rect->top = r.y + y_origin; + rect->bottom = rect->top + r.height; + + 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); +} + static void gdk_win32_window_shape_combine_region (GdkWindow *window, const cairo_region_t *shape_region, @@ -3149,7 +3197,7 @@ gdk_win32_window_shape_combine_region (GdkWindow *window, { HRGN hrgn; - hrgn = _gdk_win32_cairo_region_to_hrgn (shape_region, 0, 0); + hrgn = cairo_region_to_hrgn (shape_region, 0, 0); GDK_NOTE (MISC, g_print ("gdk_win32_window_shape_combine_region: %p: %p\n", GDK_WINDOW_HWND (window), @@ -3224,11 +3272,134 @@ gdk_window_set_opacity (GdkWindow *window, } } +/* This function originally from Jean-Edouard Lachand-Robert, and + * available at www.codeguru.com. Simplified for our needs, not sure + * how much of the original code left any longer. Now handles just + * one-bit deep bitmaps (in Window parlance, ie those that GDK calls + * bitmaps (and not pixmaps), with zero pixels being transparent. + */ + +/* bitmap_to_hrgn : Create a region from the + * "non-transparent" pixels of a bitmap. + */ + +static HRGN +bitmap_to_hrgn (GdkPixmap *pixmap) +{ + HRGN hRgn = NULL; + HRGN h; + DWORD maxRects; + RGNDATA *pData; + guchar *bits; + gint width, height, bpl; + guchar *p; + gint x, y; + + g_assert (GDK_PIXMAP_OBJECT(pixmap)->depth == 1); + + 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 + * structure on entry. We will add rectangles by amount of + * ALLOC_UNIT number in this structure. + */ + #define ALLOC_UNIT 100 + maxRects = ALLOC_UNIT; + + pData = g_malloc (sizeof (RGNDATAHEADER) + (sizeof (RECT) * maxRects)); + pData->rdh.dwSize = sizeof (RGNDATAHEADER); + pData->rdh.iType = RDH_RECTANGLES; + pData->rdh.nCount = pData->rdh.nRgnSize = 0; + SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0); + + for (y = 0; y < height; y++) + { + /* Scan each bitmap row from left to right*/ + p = (guchar *) bits + y * bpl; + for (x = 0; x < width; x++) + { + /* Search for a continuous range of "non transparent pixels"*/ + gint x0 = x; + while (x < width) + { + if ((((p[x/8])>>(7-(x%8)))&1) == 0) + /* This pixel is "transparent"*/ + break; + x++; + } + + if (x > x0) + { + RECT *pr; + /* Add the pixels (x0, y) to (x, y+1) as a new rectangle + * in the region + */ + if (pData->rdh.nCount >= maxRects) + { + maxRects += ALLOC_UNIT; + pData = g_realloc (pData, sizeof(RGNDATAHEADER) + + (sizeof(RECT) * maxRects)); + } + pr = (RECT *) &pData->Buffer; + SetRect (&pr[pData->rdh.nCount], x0, y, x, y+1); + if (x0 < pData->rdh.rcBound.left) + pData->rdh.rcBound.left = x0; + if (y < pData->rdh.rcBound.top) + pData->rdh.rcBound.top = y; + if (x > pData->rdh.rcBound.right) + pData->rdh.rcBound.right = x; + if (y+1 > pData->rdh.rcBound.bottom) + pData->rdh.rcBound.bottom = y+1; + pData->rdh.nCount++; + + /* On Windows98, ExtCreateRegion() may fail if the + * number of rectangles is too large (ie: > + * 4000). Therefore, we have to create the region by + * multiple steps. + */ + if (pData->rdh.nCount == 2000) + { + HRGN h = ExtCreateRegion (NULL, sizeof(RGNDATAHEADER) + (sizeof(RECT) * maxRects), pData); + if (hRgn) + { + CombineRgn(hRgn, hRgn, h, RGN_OR); + DeleteObject(h); + } + else + hRgn = h; + pData->rdh.nCount = 0; + SetRect (&pData->rdh.rcBound, MAXLONG, MAXLONG, 0, 0); + } + } + } + } + + /* Create or extend the region with the remaining rectangles*/ + h = ExtCreateRegion (NULL, sizeof (RGNDATAHEADER) + + (sizeof (RECT) * maxRects), pData); + if (hRgn) + { + CombineRgn (hRgn, hRgn, h, RGN_OR); + DeleteObject (h); + } + else + hRgn = h; + + /* Clean up*/ + g_free (pData); + + return hRgn; +} + cairo_region_t * _gdk_windowing_get_shape_for_mask (GdkBitmap *mask) { cairo_region_t *region; - HRGN hrgn = _gdk_win32_bitmap_to_hrgn (mask); + HRGN hrgn = bitmap_to_hrgn (mask); region = _gdk_win32_hrgn_to_region (hrgn); DeleteObject (hrgn); @@ -3269,7 +3440,7 @@ static gboolean _gdk_win32_window_queue_antiexpose (GdkWindow *window, cairo_region_t *area) { - HRGN hrgn = _gdk_win32_cairo_region_to_hrgn (area, 0, 0); + HRGN hrgn = cairo_region_to_hrgn (area, 0, 0); GDK_NOTE (EVENTS, g_print ("_gdk_windowing_window_queue_antiexpose: ValidateRgn %p %s\n", GDK_WINDOW_HWND (window), @@ -3308,7 +3479,7 @@ _gdk_win32_window_translate (GdkWindow *window, else if (ret != NULLREGION) { /* Get current updateregion, move any part of it that intersects area by dx,dy */ - HRGN update = _gdk_win32_cairo_region_to_hrgn (area, 0, 0); + HRGN update = cairo_region_to_hrgn (area, 0, 0); ret = CombineRgn (update, hrgn, update, RGN_AND); if (ret == ERROR) WIN32_API_FAILED ("CombineRgn"); diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 79afe9b8a9..80ebe57112 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -942,14 +942,14 @@ if OS_WIN32 # Workaround for UAC silliness: programs with "update" in their name # are believed to be installers and require elevated privileges to be # used... Use a manifest file to tell Windows that -# gtk-update-icon-cache.exe doesn't require any special privileges. +# gtk-update-icon-cache-3.0.exe doesn't require any special privileges. GTK_UPDATE_ICON_CACHE_MANIFEST = gtk-update-icon-cache-3.0.exe.manifest bin_SCRIPTS += \ $(GTK_UPDATE_ICON_CACHE_MANIFEST) -gtk-update-icon-cache.exe.manifest: +$(GTK_UPDATE_ICON_CACHE_MANIFEST): (echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' ; \ echo '<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">' ; \ echo ' <assemblyIdentity version="1.0.0.0"' ; \ |