forked from AuroraMiddleware/gtk
Add comment about the current named cursor implementation, and what it
2005-07-06 Tor Lillqvist <tml@novell.com> * gdk/win32/gdkcursor-win32.c: Add comment about the current named cursor implementation, and what it maybe really should do. (gdk_win32_icon_to_pixbuf_libgtk_only): New function, code moved here from gtk/gtkfilesystemwin32.c:extract_icon(). (gdk_cursor_get_image): Use gdk_win32_icon_to_pixbuf_libgtk_only(). * gdk/gdk.symbols * gdk/win32/gdkwin32.h: Declare gdk_win32_icon_to_pixbuf_libgtk_only(). * gtk/gtkfilesystemwin32.c (extract_icon): Use gdk_win32_icon_to_pixbuf_libgtk_only().
This commit is contained in:
parent
8821161c38
commit
db343ee03d
15
ChangeLog
15
ChangeLog
@ -1,3 +1,18 @@
|
||||
2005-07-06 Tor Lillqvist <tml@novell.com>
|
||||
|
||||
* gdk/win32/gdkcursor-win32.c: Add comment about the current named
|
||||
cursor implementation, and what it maybe really should do.
|
||||
(gdk_win32_icon_to_pixbuf_libgtk_only): New function, code moved
|
||||
here from gtk/gtkfilesystemwin32.c:extract_icon().
|
||||
(gdk_cursor_get_image): Use
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
* gdk/gdk.symbols
|
||||
* gdk/win32/gdkwin32.h: Declare gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
* gtk/gtkfilesystemwin32.c (extract_icon): Use
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
2005-07-05 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkmenu.c (gtk_menu_grab_notify): Take window
|
||||
|
@ -1,3 +1,18 @@
|
||||
2005-07-06 Tor Lillqvist <tml@novell.com>
|
||||
|
||||
* gdk/win32/gdkcursor-win32.c: Add comment about the current named
|
||||
cursor implementation, and what it maybe really should do.
|
||||
(gdk_win32_icon_to_pixbuf_libgtk_only): New function, code moved
|
||||
here from gtk/gtkfilesystemwin32.c:extract_icon().
|
||||
(gdk_cursor_get_image): Use
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
* gdk/gdk.symbols
|
||||
* gdk/win32/gdkwin32.h: Declare gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
* gtk/gtkfilesystemwin32.c (extract_icon): Use
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
2005-07-05 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkmenu.c (gtk_menu_grab_notify): Take window
|
||||
|
@ -1,3 +1,18 @@
|
||||
2005-07-06 Tor Lillqvist <tml@novell.com>
|
||||
|
||||
* gdk/win32/gdkcursor-win32.c: Add comment about the current named
|
||||
cursor implementation, and what it maybe really should do.
|
||||
(gdk_win32_icon_to_pixbuf_libgtk_only): New function, code moved
|
||||
here from gtk/gtkfilesystemwin32.c:extract_icon().
|
||||
(gdk_cursor_get_image): Use
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
* gdk/gdk.symbols
|
||||
* gdk/win32/gdkwin32.h: Declare gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
* gtk/gtkfilesystemwin32.c (extract_icon): Use
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only().
|
||||
|
||||
2005-07-05 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtkmenu.c (gtk_menu_grab_notify): Take window
|
||||
|
@ -1068,6 +1068,12 @@ gdk_win32_handle_table_lookup
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if IN_HEADER(__GDK_WIN32_H__)
|
||||
#if IN_FILE(__GDK_CURSOR_WIN32_C__)
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if IN_HEADER(__GDK_WIN32_H__)
|
||||
#if IN_FILE(__GDK_DRAWABLE_WIN32_C__)
|
||||
gdk_win32_drawable_get_handle
|
||||
|
@ -19,6 +19,7 @@
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
#define GDK_PIXBUF_ENABLE_BACKEND /* Ugly? */
|
||||
#include "gdkdisplay.h"
|
||||
#include "gdkscreen.h"
|
||||
#include "gdkcursor.h"
|
||||
@ -322,6 +323,20 @@ gdk_cursor_new_from_pixmap (GdkPixmap *source,
|
||||
return _gdk_win32_cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);
|
||||
}
|
||||
|
||||
/* The named cursors below are presumably not really useful, as the
|
||||
* names are Win32-specific. No GTK+ application developed on Unix
|
||||
* (and most cross-platform GTK+ apps are developed on Unix) is going
|
||||
* to look for cursors under these Win32 names anyway.
|
||||
*
|
||||
* Would the following make any sense: The ms-windows theme engine
|
||||
* calls some (to-be-defined private) API here in gdk/win32 to
|
||||
* register the relevant cursors used by the currently active XP
|
||||
* visual style under the names that libgtk uses to look for them
|
||||
* ("color-picker", "dnd-ask", "dnd-copy", etc), and then when libgtk
|
||||
* asks for those we return the ones registered by the ms-windows
|
||||
* theme engine, if any.
|
||||
*/
|
||||
|
||||
static struct {
|
||||
char *name;
|
||||
char *id;
|
||||
@ -329,7 +344,7 @@ static struct {
|
||||
{ "appstarting", IDC_APPSTARTING },
|
||||
{ "arrow", IDC_ARROW },
|
||||
{ "cross", IDC_CROSS },
|
||||
#if 0 /* in the SDK docs but not the headers ? */
|
||||
#ifdef IDC_HAND
|
||||
{ "hand", IDC_HAND },
|
||||
#endif
|
||||
{ "help", IDC_HELP },
|
||||
@ -350,6 +365,8 @@ gdk_cursor_new_from_name (GdkDisplay *display,
|
||||
HCURSOR hcursor = NULL;
|
||||
int i;
|
||||
|
||||
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(_default_cursors); i++)
|
||||
{
|
||||
if (0 == strcmp(_default_cursors[i].name, name))
|
||||
@ -391,11 +408,106 @@ gdk_cursor_get_display (GdkCursor *cursor)
|
||||
return gdk_display_get_default ();
|
||||
}
|
||||
|
||||
GdkPixbuf *
|
||||
gdk_win32_icon_to_pixbuf_libgtk_only (HICON hicon)
|
||||
{
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
ICONINFO ii;
|
||||
struct
|
||||
{
|
||||
BITMAPINFOHEADER bi;
|
||||
RGBQUAD colors[2];
|
||||
} bmi;
|
||||
HDC hdc;
|
||||
gchar *pixels, *bits, buf[32];
|
||||
gint rowstride, x, y, w, h;
|
||||
gboolean no_alpha;
|
||||
|
||||
if (!GDI_CALL (GetIconInfo, (hicon, &ii)))
|
||||
return NULL;
|
||||
|
||||
memset (&bmi, 0, sizeof (bmi));
|
||||
bmi.bi.biSize = sizeof (bmi.bi);
|
||||
if (!(hdc = CreateCompatibleDC (NULL)))
|
||||
{
|
||||
WIN32_GDI_FAILED ("CreateCompatibleDC");
|
||||
goto out0;
|
||||
}
|
||||
|
||||
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;
|
||||
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, 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;
|
||||
|
||||
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[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);
|
||||
}
|
||||
}
|
||||
|
||||
g_snprintf (buf, sizeof (buf), "%ld", ii.xHotspot);
|
||||
gdk_pixbuf_set_option (pixbuf, "x_hot", buf);
|
||||
|
||||
g_snprintf (buf, sizeof (buf), "%ld", ii.yHotspot);
|
||||
gdk_pixbuf_set_option (pixbuf, "y_hot", buf);
|
||||
|
||||
/* release temporary resources */
|
||||
out2:
|
||||
g_free (bits);
|
||||
out1:
|
||||
DeleteDC (hdc);
|
||||
out0:
|
||||
DeleteObject (ii.hbmColor);
|
||||
DeleteObject (ii.hbmMask);
|
||||
|
||||
return pixbuf;
|
||||
}
|
||||
|
||||
GdkPixbuf*
|
||||
gdk_cursor_get_image (GdkCursor *cursor)
|
||||
{
|
||||
/* could certainly be implmented but from docs may also */
|
||||
return NULL;
|
||||
g_return_val_if_fail (cursor != NULL, NULL);
|
||||
|
||||
return gdk_win32_icon_to_pixbuf_libgtk_only (((GdkCursorPrivate *) cursor)->hcursor);
|
||||
}
|
||||
|
||||
GdkCursor *
|
||||
|
@ -84,6 +84,9 @@ void gdk_win32_selection_add_targets (GdkWindow *owner,
|
||||
gint n_targets,
|
||||
GdkAtom *targets);
|
||||
|
||||
/* For internal GTK use only */
|
||||
GdkPixbuf * gdk_win32_icon_to_pixbuf_libgtk_only (HICON hicon);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GDK_WIN32_H__ */
|
||||
|
@ -38,12 +38,12 @@
|
||||
#ifdef G_OS_WIN32
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define STRICT
|
||||
#include <windows.h>
|
||||
#include "gdk/win32/gdkwin32.h"
|
||||
#undef STRICT
|
||||
#include <shlobj.h>
|
||||
#include <shellapi.h>
|
||||
#else
|
||||
#error "The implementation is win32 only."
|
||||
#error "The implementation is Win32 only."
|
||||
#endif /* G_OS_WIN32 */
|
||||
|
||||
typedef struct _GtkFileSystemWin32Class GtkFileSystemWin32Class;
|
||||
@ -1042,7 +1042,6 @@ extract_icon (const char* filename)
|
||||
{
|
||||
GdkPixbuf *pixbuf = NULL;
|
||||
HICON hicon;
|
||||
ICONINFO ii;
|
||||
|
||||
if (!filename || !filename[0])
|
||||
return NULL;
|
||||
@ -1125,79 +1124,7 @@ extract_icon (const char* filename)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (GetIconInfo (hicon, &ii))
|
||||
{
|
||||
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;
|
||||
gboolean no_alpha;
|
||||
|
||||
bmi.bi.biBitCount = 32;
|
||||
bmi.bi.biCompression = BI_RGB;
|
||||
bmi.bi.biHeight = -h;
|
||||
pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
|
||||
bits = g_malloc0 (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);
|
||||
no_alpha = TRUE;
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
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);
|
||||
}
|
||||
/* mask */
|
||||
if (no_alpha) {
|
||||
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) * 4];
|
||||
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_warning (G_STRLOC ": GetIconInfo failed: %s\n", g_win32_error_message (GetLastError ()));
|
||||
pixbuf = gdk_win32_icon_to_pixbuf_libgtk_only (hicon);
|
||||
|
||||
if (!DestroyIcon (hicon))
|
||||
g_warning (G_STRLOC ": DestroyIcon failed: %s\n", g_win32_error_message (GetLastError ()));
|
||||
|
Loading…
Reference in New Issue
Block a user