diff options
author | Hans Breuer <hans@breuer.org> | 2004-05-08 16:25:15 +0000 |
---|---|---|
committer | Hans Breuer <hans@src.gnome.org> | 2004-05-08 16:25:15 +0000 |
commit | 805abff3cfb818d42520a24735b71d09a82e816f (patch) | |
tree | 5502b9d8a8fedf9016978ec0b08eb0e864f636f5 /gtk/gtkfilesystemwin32.c | |
parent | a4f0cc112b133b624559781b4e95087e525b30be (diff) | |
download | gtk+-805abff3cfb818d42520a24735b71d09a82e816f.tar.gz |
finally also create the correct mask for 'pseudo mime' icons
2004-05-08 Hans Breuer <hans@breuer.org>
* gtk/gtkfilesystemwin32.c (extract_icon) : finally also
create the correct mask for 'pseudo mime' icons
* gdk/win32/gdkwindow-win32.c(show_window_internal) : also
take focus_on_map into account
* gtk/gtkselection.c : g_message() only with DEBUG_SELECTION
* gtk/gtkactiongroup.c gtk/gtkcombobox.c :
... must return a value
* gdk/gdk.def gtk/gtk.def demos/gtk-demo/makefile.msc.in : updated
Diffstat (limited to 'gtk/gtkfilesystemwin32.c')
-rw-r--r-- | gtk/gtkfilesystemwin32.c | 103 |
1 files changed, 71 insertions, 32 deletions
diff --git a/gtk/gtkfilesystemwin32.c b/gtk/gtkfilesystemwin32.c index 3d2c5aec16..1ecc940478 100644 --- a/gtk/gtkfilesystemwin32.c +++ b/gtk/gtkfilesystemwin32.c @@ -1,6 +1,7 @@ /* GTK - The GIMP Toolkit * gtkfilesystemwin32.c: Default implementation of GtkFileSystem for Windows * Copyright (C) 2003, Red Hat, Inc. + * Copyright (C) 2004, Hans Breuer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -933,53 +934,91 @@ extract_icon (const char* filename) GdkPixbuf *pixbuf = NULL; WORD iicon; HICON hicon; + char filename_copy[MAX_PATH]; if (!filename || !filename[0]) return NULL; - hicon = ExtractAssociatedIcon (GetModuleHandle (NULL), filename, &iicon); + /* the ugly ExtractAssociatedIcon modifies filename in place - at least on win98 */ + strcpy(filename_copy, filename); + hicon = ExtractAssociatedIcon (GetModuleHandle (NULL), filename_copy, &iicon); if (hicon > (HICON)1) { ICONINFO ii; if (GetIconInfo (hicon, &ii)) { - SIZE size; - GdkPixmap *pixmap; - GdkGC *gc; - HDC hdc; - - if (!GetBitmapDimensionEx (ii.hbmColor, &size)) - g_warning ("GetBitmapDimensionEx failed."); - - if (size.cx < 1) size.cx = 32; - if (size.cy < 1) size.cy = 32; - - pixmap = gdk_pixmap_new (NULL, size.cx, size.cy, - gdk_screen_get_system_visual (gdk_screen_get_default ())->depth); - gc = gdk_gc_new (pixmap); - hdc = gdk_win32_hdc_get (GDK_DRAWABLE (pixmap), gc, 0); - - if (!DrawIcon (hdc, 0, 0, hicon)) - g_warning ("DrawIcon failed"); - - gdk_win32_hdc_release (GDK_DRAWABLE (pixmap), gc, 0); - - pixbuf = gdk_pixbuf_get_from_drawable ( - NULL, pixmap, - gdk_screen_get_system_colormap (gdk_screen_get_default ()), - 0, 0, 0, 0, size.cx, size.cy); - g_object_unref (pixmap); - g_object_unref (gc); + struct + { + BITMAPINFOHEADER bi; + RGBQUAD colors[2]; + } bmi; + HDC hdc; + + memset (&bmi, 0, sizeof (bmi)); + bmi.bi.biSize = sizeof (bmi.bi); + hdc = CreateCompatibleDC (NULL); + + if (GetDIBits (hdc, ii.hbmColor, 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)) + { + gchar *pixels, *bits; + gint rowstride, x, y, w = bmi.bi.biWidth, h = bmi.bi.biHeight; + + bmi.bi.biBitCount = 24; + bmi.bi.biCompression = BI_RGB; + bmi.bi.biHeight = -h; + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h); + bits = g_malloc (4 * w * h); + + /* color data */ + if (!GetDIBits (hdc, ii.hbmColor, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)) + g_warning(G_STRLOC ": Failed to get dibits"); + + pixels = gdk_pixbuf_get_pixels (pixbuf); + rowstride = gdk_pixbuf_get_rowstride (pixbuf); + for (y = 0; y < h; y++) + { + for (x = 0; x < w; x++) + { + pixels[2] = bits[(x+y*w) * 3]; + pixels[1] = bits[(x+y*w) * 3 + 1]; + pixels[0] = bits[(x+y*w) * 3 + 2]; + pixels += 4; + } + pixels += (w * 4 - rowstride); + } + /* transparency */ + if (!GetDIBits (hdc, ii.hbmMask, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)) + g_warning(G_STRLOC ": Failed to get dibits"); + 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) * 3]; + pixels += 4; + } + pixels += (w * 4 - rowstride); + } + + /* release temporary resources */ + g_free (bits); + if (!DeleteObject (ii.hbmColor) || !DeleteObject (ii.hbmMask)) + g_warning(G_STRLOC ": Leaking Icon Bitmaps ?"); + } + else + g_warning(G_STRLOC ": GetDIBits () failed, %s", g_win32_error_message (GetLastError ())); + + DeleteDC (hdc); } else - g_print ("GetIconInfo failed: %s\n", g_win32_error_message (GetLastError ())); + g_warning(G_STRLOC ": GetIconInfo failed: %s\n", g_win32_error_message (GetLastError ())); if (!DestroyIcon (hicon)) - g_warning ("DestroyIcon failed"); + g_warning(G_STRLOC ": DestroyIcon failed"); } else - g_print ("ExtractAssociatedIcon failed: %s\n", g_win32_error_message (GetLastError ())); + g_print ("ExtractAssociatedIcon(%s) failed: %s\n", filename, g_win32_error_message (GetLastError ())); return pixbuf; } @@ -1048,7 +1087,7 @@ gtk_file_system_win32_render_icon (GtkFileSystem *file_system, case DRIVE_CDROM : icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_CDROM); break; - case DRIVE_FIXED : /* need a hard disk icon */ + case DRIVE_FIXED : icon_set = gtk_style_lookup_icon_set (widget->style, GTK_STOCK_HARDDISK); break; default : |