diff --git a/ChangeLog b/ChangeLog index 159e0b529b..57c0edbd14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,12 @@ * gdk/win32/gdkwindow-win32.c (RegisterGdkClass): Improve handling of the small icon of the window class. (#152620, Kazuki Iwamoto) +2006-10-29 Tor Lillqvist + + * gdk/win32/gdkcursor-win32.c + (gdk_win32_icon_to_pixbuf_libgtk_only): Implement for B&W cursors, + for instance the built-in GDK ones. + 2006-10-27 Kristian Rietveld * gtk/gtktreeview.c (validate_visible_area): rework the area_above == 0 diff --git a/gdk/win32/gdkcursor-win32.c b/gdk/win32/gdkcursor-win32.c index f1d3099972..a0e702e5c6 100644 --- a/gdk/win32/gdkcursor-win32.c +++ b/gdk/win32/gdkcursor-win32.c @@ -421,7 +421,6 @@ gdk_win32_icon_to_pixbuf_libgtk_only (HICON hicon) HDC hdc; gchar *pixels, *bits, buf[32]; gint rowstride, x, y, w, h; - gboolean no_alpha; if (!GDI_CALL (GetIconInfo, (hicon, &ii))) return NULL; @@ -435,55 +434,135 @@ gdk_win32_icon_to_pixbuf_libgtk_only (HICON hicon) memset (&bmi, 0, sizeof (bmi)); bmi.bi.biSize = sizeof (bmi.bi); - if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) - goto out1; - - w = bmi.bi.biWidth; - h = bmi.bi.biHeight; - - bmi.bi.biBitCount = 32; - bmi.bi.biCompression = BI_RGB; - bmi.bi.biHeight = -h; - - bits = g_malloc0 (4 * w * h); - - /* color data */ - if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) - goto out2; - - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h); - pixels = gdk_pixbuf_get_pixels (pixbuf); - rowstride = gdk_pixbuf_get_rowstride (pixbuf); - no_alpha = TRUE; - for (y = 0; y < h; y++) + if (ii.hbmColor != NULL) { - for (x = 0; x < w; x++) - { - pixels[2] = bits[(x+y*w) * 4]; - pixels[1] = bits[(x+y*w) * 4 + 1]; - pixels[0] = bits[(x+y*w) * 4 + 2]; - pixels[3] = bits[(x+y*w) * 4 + 3]; - if (no_alpha && pixels[3] > 0) - no_alpha = FALSE; - pixels += 4; - } - pixels += (w * 4 - rowstride); - } + /* Colour cursor */ - /* mask */ - if (no_alpha && - GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) - { + gboolean no_alpha; + + if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) + goto out1; + + w = bmi.bi.biWidth; + h = bmi.bi.biHeight; + + bmi.bi.biBitCount = 32; + bmi.bi.biCompression = BI_RGB; + bmi.bi.biHeight = -h; + + bits = g_malloc0 (4 * w * h); + + /* color data */ + if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) + goto out2; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h); pixels = gdk_pixbuf_get_pixels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + no_alpha = TRUE; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { - pixels[3] = 255 - bits[(x + y * w) * 4]; + pixels[2] = bits[(x+y*w) * 4]; + pixels[1] = bits[(x+y*w) * 4 + 1]; + pixels[0] = bits[(x+y*w) * 4 + 2]; + pixels[3] = bits[(x+y*w) * 4 + 3]; + if (no_alpha && pixels[3] > 0) + no_alpha = FALSE; pixels += 4; } pixels += (w * 4 - rowstride); } + + /* mask */ + if (no_alpha && + GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) + { + pixels = gdk_pixbuf_get_pixels (pixbuf); + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + pixels[3] = 255 - bits[(x + y * w) * 4]; + pixels += 4; + } + pixels += (w * 4 - rowstride); + } + } + } + else + { + /* B&W cursor */ + + int bpl; + + if (!GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, 0, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) + goto out1; + + w = bmi.bi.biWidth; + h = ABS (bmi.bi.biHeight) / 2; + + bits = g_malloc0 (4 * w * h); + + /* masks */ + if (!GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h*2, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS))) + goto out2; + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h); + pixels = gdk_pixbuf_get_pixels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + bpl = ((w-1)/32 + 1)*4; +#if 0 + for (y = 0; y < h*2; y++) + { + for (x = 0; x < w; x++) + { + const gint bit = 7 - (x % 8); + printf ("%c ", ((bits[bpl*y+x/8])&(1<