📄 gdkcursor-win32.c
字号:
g_return_if_fail (cursor != NULL); private = (GdkCursorPrivate *) cursor; GDK_NOTE (MISC, g_print ("_gdk_cursor_destroy: %p\n", (cursor->type == GDK_CURSOR_IS_PIXMAP) ? private->hcursor : 0)); if (GetCursor () == private->hcursor) SetCursor (NULL); if (!DestroyCursor (private->hcursor)) WIN32_API_FAILED ("DestroyCursor"); g_free (private);}GdkDisplay *gdk_cursor_get_display (GdkCursor *cursor){ return gdk_display_get_default ();}GdkCursor *gdk_cursor_new_from_pixbuf (GdkDisplay *display, GdkPixbuf *pixbuf, gint x, gint y){ HCURSOR hcursor; g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL); g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL); g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL); g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL); hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y); if (!hcursor) return NULL; return _gdk_win32_cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);}gboolean gdk_display_supports_cursor_alpha (GdkDisplay *display){ g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE); return _gdk_win32_pixbuf_to_hicon_supports_alpha ();}gboolean gdk_display_supports_cursor_color (GdkDisplay *display){ g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE); return TRUE;}guint gdk_display_get_default_cursor_size (GdkDisplay *display){ g_return_val_if_fail (GDK_IS_DISPLAY (display), 0); return MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR));}void gdk_display_get_maximal_cursor_size (GdkDisplay *display, guint *width, guint *height){ g_return_if_fail (GDK_IS_DISPLAY (display)); if (width) *width = GetSystemMetrics (SM_CXCURSOR); if (height) *height = GetSystemMetrics (SM_CYCURSOR);}/* Convert a pixbuf to an HICON (or HCURSOR). Supports alpha under * Windows XP, thresholds alpha otherwise. Also used from * gdkwindow-win32.c for creating application icons. */static HBITMAPcreate_alpha_bitmap (gint width, gint height, guchar **outdata){ BITMAPV5HEADER bi; HDC hdc; HBITMAP hBitmap; ZeroMemory (&bi, sizeof (BITMAPV5HEADER)); bi.bV5Size = sizeof (BITMAPV5HEADER); bi.bV5Width = width; bi.bV5Height = height; bi.bV5Planes = 1; bi.bV5BitCount = 32; bi.bV5Compression = BI_BITFIELDS; /* The following mask specification specifies a supported 32 BPP * alpha format for Windows XP (BGRA format). */ bi.bV5RedMask = 0x00FF0000; bi.bV5GreenMask = 0x0000FF00; bi.bV5BlueMask = 0x000000FF; bi.bV5AlphaMask = 0xFF000000; /* Create the DIB section with an alpha channel. */ hdc = GetDC (NULL); if (!hdc) { WIN32_GDI_FAILED ("GetDC"); return NULL; } hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (PVOID *) outdata, NULL, (DWORD)0); if (hBitmap == NULL) WIN32_GDI_FAILED ("CreateDIBSection"); ReleaseDC (NULL, hdc); return hBitmap;}static HBITMAPcreate_color_bitmap (gint width, gint height, guchar **outdata){ BITMAPV4HEADER bi; HDC hdc; HBITMAP hBitmap; ZeroMemory (&bi, sizeof (BITMAPV4HEADER)); bi.bV4Size = sizeof (BITMAPV4HEADER); bi.bV4Width = width; bi.bV4Height = height; bi.bV4Planes = 1; bi.bV4BitCount = 24; bi.bV4V4Compression = BI_RGB; hdc = GetDC (NULL); if (!hdc) { WIN32_GDI_FAILED ("GetDC"); return NULL; } hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS, (PVOID *) outdata, NULL, (DWORD)0); if (hBitmap == NULL) WIN32_GDI_FAILED ("CreateDIBSection"); ReleaseDC (NULL, hdc); return hBitmap;}static gbooleanpixbuf_to_hbitmaps_alpha_winxp (GdkPixbuf *pixbuf, HBITMAP *color, HBITMAP *mask){ /* Based on code from * http://www.dotnet247.com/247reference/msgs/13/66301.aspx */ HBITMAP hColorBitmap, hMaskBitmap; guchar *indata, *inrow; guchar *outdata, *outrow; gint width, height, i, j, rowstride; width = gdk_pixbuf_get_width (pixbuf); /* width of icon */ height = gdk_pixbuf_get_height (pixbuf); /* height of icon */ hColorBitmap = create_alpha_bitmap (width, height, &outdata); if (!hColorBitmap) return FALSE; hMaskBitmap = CreateBitmap (width, height, 1, 1, NULL); if (!hMaskBitmap) { DeleteObject (hColorBitmap); return FALSE; } /* rows are always aligned on 4-byte boundarys, but here our pixels are always 4 bytes */ indata = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); for (j=0; j<height; j++) { outrow = outdata + 4*j*width; inrow = indata + (height-j-1)*rowstride; for (i=0; i<width; i++) { outrow[4*i+0] = inrow[4*i+2]; outrow[4*i+1] = inrow[4*i+1]; outrow[4*i+2] = inrow[4*i+0]; outrow[4*i+3] = inrow[4*i+3]; } } if (color) *color = hColorBitmap; if (mask) *mask = hMaskBitmap; return TRUE;}static gbooleanpixbuf_to_hbitmaps_normal (GdkPixbuf *pixbuf, HBITMAP *color, HBITMAP *mask){ /* Based on code from * http://www.dotnet247.com/247reference/msgs/13/66301.aspx */ HBITMAP hColorBitmap, hMaskBitmap; guchar *indata, *inrow; guchar *colordata, *colorrow, *maskdata, *maskrow; gint width, height, i, j, rowstride, nc, bmstride; gboolean has_alpha; width = gdk_pixbuf_get_width (pixbuf); /* width of icon */ height = gdk_pixbuf_get_height (pixbuf); /* height of icon */ hColorBitmap = create_color_bitmap (width, height, &colordata); if (!hColorBitmap) return FALSE; hMaskBitmap = create_color_bitmap (width, height, &maskdata); if (!hMaskBitmap) { DeleteObject (hColorBitmap); return FALSE; } /* rows are always aligned on 4-byte boundarys */ bmstride = width * 3; if (bmstride % 4 != 0) bmstride += 4 - (bmstride % 4); indata = gdk_pixbuf_get_pixels (pixbuf); rowstride = gdk_pixbuf_get_rowstride (pixbuf); nc = gdk_pixbuf_get_n_channels (pixbuf); has_alpha = gdk_pixbuf_get_has_alpha (pixbuf); for (j=0; j<height; j++) { colorrow = colordata + j*bmstride; maskrow = maskdata + j*bmstride; inrow = indata + (height-j-1)*rowstride; for (i=0; i<width; i++) { if (has_alpha && inrow[nc*i+3] < 128) { colorrow[3*i+0] = colorrow[3*i+1] = colorrow[3*i+2] = 0; maskrow[3*i+0] = maskrow[3*i+1] = maskrow[3*i+2] = 255; } else { colorrow[3*i+0] = inrow[nc*i+2]; colorrow[3*i+1] = inrow[nc*i+1]; colorrow[3*i+2] = inrow[nc*i+0]; maskrow[3*i+0] = maskrow[3*i+1] = maskrow[3*i+2] = 0; } } } if (color) *color = hColorBitmap; if (mask) *mask = hMaskBitmap; return TRUE;}static HICONpixbuf_to_hicon (GdkPixbuf *pixbuf, gboolean is_icon, gint x, gint y){ ICONINFO ii; HICON icon; gboolean success; if (pixbuf == NULL) return NULL; if (_gdk_win32_pixbuf_to_hicon_supports_alpha() && gdk_pixbuf_get_has_alpha (pixbuf)) success = pixbuf_to_hbitmaps_alpha_winxp (pixbuf, &ii.hbmColor, &ii.hbmMask); else success = pixbuf_to_hbitmaps_normal (pixbuf, &ii.hbmColor, &ii.hbmMask); if (!success) return NULL; ii.fIcon = is_icon; ii.xHotspot = x; ii.yHotspot = y; icon = CreateIconIndirect (&ii); DeleteObject (ii.hbmColor); DeleteObject (ii.hbmMask); return icon;}HICON_gdk_win32_pixbuf_to_hicon (GdkPixbuf *pixbuf){ return pixbuf_to_hicon (pixbuf, TRUE, 0, 0);}HICON_gdk_win32_pixbuf_to_hcursor (GdkPixbuf *pixbuf, gint x_hotspot, gint y_hotspot){ return pixbuf_to_hicon (pixbuf, FALSE, x_hotspot, y_hotspot);}gboolean_gdk_win32_pixbuf_to_hicon_supports_alpha (void){ static gboolean is_win_xp=FALSE, is_win_xp_checked=FALSE; if (!is_win_xp_checked) { OSVERSIONINFO version; is_win_xp_checked = TRUE; memset (&version, 0, sizeof (version)); version.dwOSVersionInfoSize = sizeof (version); is_win_xp = GetVersionEx (&version) && version.dwPlatformId == VER_PLATFORM_WIN32_NT && (version.dwMajorVersion > 5 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1)); } return is_win_xp;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -