1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 * Copyright (C) 1998-2002 Tor Lillqvist
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 #define GDK_PIXBUF_ENABLE_BACKEND /* Ugly? */
23 #include "gdkdisplay.h"
24 #include "gdkscreen.h"
25 #include "gdkcursor.h"
26 #include "gdkprivate-win32.h"
34 #if (defined(__MINGW32__) && (__W32API_MAJOR_VERSION < 3 || (__W32API_MAJOR_VERSION == 3 && __W32API_MINOR_VERSION < 8))) || (defined(_MSC_VER) && (WINVER < 0x0500))
43 LONG bV5XPelsPerMeter;
44 LONG bV5YPelsPerMeter;
46 DWORD bV5ClrImportant;
52 CIEXYZTRIPLE bV5Endpoints;
64 hcursor_from_type (GdkCursorType cursor_type)
69 guchar *and_plane, *xor_plane;
71 if (cursor_type != GDK_BLANK_CURSOR)
73 for (i = 0; i < G_N_ELEMENTS (cursors); i++)
74 if (cursors[i].type == cursor_type)
77 if (i >= G_N_ELEMENTS (cursors) || !cursors[i].name)
80 /* Use real Win32 cursor if possible */
81 if (cursors[i].builtin)
82 return LoadCursor (NULL, cursors[i].builtin);
85 w = GetSystemMetrics (SM_CXCURSOR);
86 h = GetSystemMetrics (SM_CYCURSOR);
88 and_plane = g_malloc ((w/8) * h);
89 memset (and_plane, 0xff, (w/8) * h);
90 xor_plane = g_malloc ((w/8) * h);
91 memset (xor_plane, 0, (w/8) * h);
93 if (cursor_type != GDK_BLANK_CURSOR)
96 #define SET_BIT(v,b) (v |= (1 << b))
97 #define RESET_BIT(v,b) (v &= ~(1 << b))
99 for (j = 0, y = 0; y < cursors[i].height && y < h ; y++)
102 j = y * cursors[i].width;
104 for (x = 0; x < cursors[i].width && x < w ; x++, j++)
106 gint pofs = ofs + x / 8;
107 guchar data = (cursors[i].data[j/4] & (0xc0 >> (2 * (j%4)))) >> (2 * (3 - (j%4)));
108 gint bit = 7 - (j % cursors[i].width) % 8;
112 RESET_BIT (and_plane[pofs], bit);
114 SET_BIT (xor_plane[pofs], bit);
122 rv = CreateCursor (_gdk_app_hmodule, cursors[i].hotx, cursors[i].hoty,
123 w, h, and_plane, xor_plane);
127 rv = CreateCursor (_gdk_app_hmodule, 0, 0,
128 w, h, and_plane, xor_plane);
131 WIN32_API_FAILED ("CreateCursor");
139 cursor_new_from_hcursor (HCURSOR hcursor,
140 GdkCursorType cursor_type)
142 GdkCursorPrivate *private;
145 private = g_new (GdkCursorPrivate, 1);
146 private->hcursor = hcursor;
147 cursor = (GdkCursor*) private;
148 cursor->type = cursor_type;
149 cursor->ref_count = 1;
155 gdk_cursor_new_for_display (GdkDisplay *display,
156 GdkCursorType cursor_type)
160 g_return_val_if_fail (display == _gdk_display, NULL);
162 hcursor = hcursor_from_type (cursor_type);
165 g_warning ("gdk_cursor_new_for_display: no cursor %d found", cursor_type);
167 GDK_NOTE (CURSOR, g_print ("gdk_cursor_new_for_display: %d: %p\n",
168 cursor_type, hcursor));
170 return cursor_new_from_hcursor (hcursor, cursor_type);
174 color_is_white (const GdkColor *color)
176 return (color->red == 0xFFFF
177 && color->green == 0xFFFF
178 && color->blue == 0xFFFF);
182 gdk_cursor_new_from_pixmap (GdkPixmap *source,
189 GdkPixmapImplWin32 *source_impl, *mask_impl;
190 guchar *source_bits, *mask_bits;
191 gint source_bpl, mask_bpl;
193 guchar *p, *q, *xor_mask, *and_mask;
194 gint width, height, cursor_width, cursor_height;
197 const gboolean bg_is_white = color_is_white (bg);
199 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
200 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
201 g_return_val_if_fail (fg != NULL, NULL);
202 g_return_val_if_fail (bg != NULL, NULL);
204 source_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (source)->impl);
205 mask_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (mask)->impl);
207 g_return_val_if_fail (source_impl->width == mask_impl->width
208 && source_impl->height == mask_impl->height,
210 width = source_impl->width;
211 height = source_impl->height;
212 cursor_width = GetSystemMetrics (SM_CXCURSOR);
213 cursor_height = GetSystemMetrics (SM_CYCURSOR);
215 g_return_val_if_fail (width <= cursor_width && height <= cursor_height,
218 residue = (1 << ((8-(width%8))%8)) - 1;
220 source_bits = source_impl->bits;
221 mask_bits = mask_impl->bits;
223 g_return_val_if_fail (GDK_PIXMAP_OBJECT (source)->depth == 1
224 && GDK_PIXMAP_OBJECT (mask)->depth == 1,
227 source_bpl = ((width - 1)/32 + 1)*4;
228 mask_bpl = ((mask_impl->width - 1)/32 + 1)*4;
231 g_print ("gdk_cursor_new_from_pixmap: source=%p:\n",
232 source_impl->parent_instance.handle);
233 for (iy = 0; iy < height; iy++)
238 p = source_bits + iy*source_bpl;
239 for (ix = 0; ix < width; ix++)
243 g_print ("%c", ".X"[((*p)>>(7-(ix%8)))&1]);
249 g_print ("...mask=%p:\n", mask_impl->parent_instance.handle);
250 for (iy = 0; iy < height; iy++)
255 p = mask_bits + iy*source_bpl;
256 for (ix = 0; ix < width; ix++)
260 g_print ("%c", ".X"[((*p)>>(7-(ix%8)))&1]);
268 /* Such complex bit manipulation for this simple task, sigh.
269 * The X cursor and Windows cursor concepts are quite different.
270 * We assume here that we are always called with fg == black and
271 * bg == white, *or* the other way around. Random colours won't work.
272 * (Well, you will get a cursor, but not in those colours.)
275 /* Note: The comments below refer to the case fg==black and
276 * bg==white, as that was what was implemented first. The fg==white
277 * (the "if (fg->pixel)" branches) case was added later.
280 /* First set masked-out source bits, as all source bits matter on Windoze.
281 * As we invert them below, they will be clear in the final xor_mask.
283 for (iy = 0; iy < height; iy++)
285 p = source_bits + iy*source_bpl;
286 q = mask_bits + iy*mask_bpl;
288 for (ix = 0; ix < ((width-1)/8+1); ix++)
295 /* XOR mask is initialized to zero */
296 xor_mask = g_malloc0 (cursor_width/8 * cursor_height);
298 for (iy = 0; iy < height; iy++)
300 p = source_bits + iy*source_bpl;
301 q = xor_mask + iy*cursor_width/8;
303 for (ix = 0; ix < ((width-1)/8+1); ix++)
309 q[-1] &= ~residue; /* Clear left-over bits */
312 /* AND mask is initialized to ones */
313 and_mask = g_malloc (cursor_width/8 * cursor_height);
314 memset (and_mask, 0xFF, cursor_width/8 * cursor_height);
316 for (iy = 0; iy < height; iy++)
318 p = mask_bits + iy*mask_bpl;
319 q = and_mask + iy*cursor_width/8;
321 for (ix = 0; ix < ((width-1)/8+1); ix++)
324 q[-1] |= residue; /* Set left-over bits */
327 hcursor = CreateCursor (_gdk_app_hmodule, x, y, cursor_width, cursor_height,
330 GDK_NOTE (CURSOR, g_print ("gdk_cursor_new_from_pixmap: "
331 "%p (%dx%d) %p (%dx%d) = %p (%dx%d)\n",
332 GDK_PIXMAP_HBITMAP (source),
333 source_impl->width, source_impl->height,
334 GDK_PIXMAP_HBITMAP (mask),
335 mask_impl->width, mask_impl->height,
336 hcursor, cursor_width, cursor_height));
341 return cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);
344 /* FIXME: The named cursors below are presumably not really useful, as
345 * the names are Win32-specific. No GTK+ application developed on Unix
346 * (and most cross-platform GTK+ apps are developed on Unix) is going
347 * to look for cursors under these Win32 names anyway.
349 * Would the following make any sense: The ms-windows theme engine
350 * calls some (to-be-defined private) API here in gdk/win32 to
351 * register the relevant cursors used by the currently active XP
352 * visual style under the names that libgtk uses to look for them
353 * ("color-picker", "dnd-ask", "dnd-copy", etc), and then when libgtk
354 * asks for those we return the ones registered by the ms-windows
355 * theme engine, if any.
361 } default_cursors[] = {
362 { "appstarting", IDC_APPSTARTING },
363 { "arrow", IDC_ARROW },
364 { "cross", IDC_CROSS },
366 { "hand", IDC_HAND },
368 { "help", IDC_HELP },
369 { "ibeam", IDC_IBEAM },
370 { "sizeall", IDC_SIZEALL },
371 { "sizenesw", IDC_SIZENESW },
372 { "sizens", IDC_SIZENS },
373 { "sizenwse", IDC_SIZENWSE },
374 { "sizewe", IDC_SIZEWE },
375 { "uparrow", IDC_UPARROW },
380 gdk_cursor_new_from_name (GdkDisplay *display,
383 HCURSOR hcursor = NULL;
386 g_return_val_if_fail (display == _gdk_display, NULL);
388 for (i = 0; i < G_N_ELEMENTS(default_cursors); i++)
390 if (0 == strcmp(default_cursors[i].name, name))
391 hcursor = LoadCursor (NULL, default_cursors[i].id);
393 /* allow to load named cursor resources linked into the executable */
395 hcursor = LoadCursor (_gdk_app_hmodule, name);
398 return cursor_new_from_hcursor (hcursor, GDK_X_CURSOR);
404 _gdk_cursor_destroy (GdkCursor *cursor)
406 GdkCursorPrivate *private;
408 g_return_if_fail (cursor != NULL);
409 private = (GdkCursorPrivate *) cursor;
411 GDK_NOTE (CURSOR, g_print ("_gdk_cursor_destroy: %p\n",
412 (cursor->type == GDK_CURSOR_IS_PIXMAP) ? private->hcursor : 0));
414 if (GetCursor () == private->hcursor)
417 if (!DestroyCursor (private->hcursor))
418 WIN32_API_FAILED ("DestroyCursor");
424 gdk_cursor_get_display (GdkCursor *cursor)
426 return gdk_display_get_default ();
430 gdk_win32_icon_to_pixbuf_libgtk_only (HICON hicon)
432 GdkPixbuf *pixbuf = NULL;
440 guchar *pixels, *bits;
442 gint rowstride, x, y, w, h;
444 if (!GDI_CALL (GetIconInfo, (hicon, &ii)))
447 if (!(hdc = CreateCompatibleDC (NULL)))
449 WIN32_GDI_FAILED ("CreateCompatibleDC");
453 memset (&bmi, 0, sizeof (bmi));
454 bmi.bi.biSize = sizeof (bmi.bi);
456 if (ii.hbmColor != NULL)
462 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
468 bmi.bi.biBitCount = 32;
469 bmi.bi.biCompression = BI_RGB;
470 bmi.bi.biHeight = -h;
472 bits = g_malloc0 (4 * w * h);
475 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
478 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
479 pixels = gdk_pixbuf_get_pixels (pixbuf);
480 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
482 for (y = 0; y < h; y++)
484 for (x = 0; x < w; x++)
486 pixels[2] = bits[(x+y*w) * 4];
487 pixels[1] = bits[(x+y*w) * 4 + 1];
488 pixels[0] = bits[(x+y*w) * 4 + 2];
489 pixels[3] = bits[(x+y*w) * 4 + 3];
490 if (no_alpha && pixels[3] > 0)
494 pixels += (w * 4 - rowstride);
499 GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
501 pixels = gdk_pixbuf_get_pixels (pixbuf);
502 for (y = 0; y < h; y++)
504 for (x = 0; x < w; x++)
506 pixels[3] = 255 - bits[(x + y * w) * 4];
509 pixels += (w * 4 - rowstride);
519 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, 0, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
523 h = ABS (bmi.bi.biHeight) / 2;
525 bits = g_malloc0 (4 * w * h);
528 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h*2, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
531 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
532 pixels = gdk_pixbuf_get_pixels (pixbuf);
533 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
534 bpl = ((w-1)/32 + 1)*4;
536 for (y = 0; y < h*2; y++)
538 for (x = 0; x < w; x++)
540 const gint bit = 7 - (x % 8);
541 printf ("%c ", ((bits[bpl*y+x/8])&(1<<bit)) ? ' ' : 'X');
547 for (y = 0; y < h; y++)
549 const guchar *andp, *xorp;
550 if (bmi.bi.biHeight < 0)
553 xorp = bits + bpl*(h+y);
557 andp = bits + bpl*(h-y-1);
558 xorp = bits + bpl*(h+h-y-1);
560 for (x = 0; x < w; x++)
562 const gint bit = 7 - (x % 8);
563 if ((*andp) & (1<<bit))
565 if ((*xorp) & (1<<bit))
566 pixels[2] = pixels[1] = pixels[0] = 0xFF;
568 pixels[2] = pixels[1] = pixels[0] = 0;
573 pixels[2] = pixels[1] = pixels[0] = 0;
583 pixels += (w * 4 - rowstride);
587 g_snprintf (buf, sizeof (buf), "%ld", ii.xHotspot);
588 gdk_pixbuf_set_option (pixbuf, "x_hot", buf);
590 g_snprintf (buf, sizeof (buf), "%ld", ii.yHotspot);
591 gdk_pixbuf_set_option (pixbuf, "y_hot", buf);
593 /* release temporary resources */
599 DeleteObject (ii.hbmColor);
600 DeleteObject (ii.hbmMask);
606 gdk_cursor_get_image (GdkCursor *cursor)
608 g_return_val_if_fail (cursor != NULL, NULL);
610 return gdk_win32_icon_to_pixbuf_libgtk_only (((GdkCursorPrivate *) cursor)->hcursor);
614 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
621 g_return_val_if_fail (display == _gdk_display, NULL);
622 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
623 g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
624 g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
626 hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y);
629 return cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);
633 gdk_display_supports_cursor_alpha (GdkDisplay *display)
635 g_return_val_if_fail (display == _gdk_display, FALSE);
637 return _gdk_win32_pixbuf_to_hicon_supports_alpha ();
641 gdk_display_supports_cursor_color (GdkDisplay *display)
643 g_return_val_if_fail (display == _gdk_display, FALSE);
649 gdk_display_get_default_cursor_size (GdkDisplay *display)
651 g_return_val_if_fail (display == _gdk_display, 0);
653 return MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR));
657 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
661 g_return_if_fail (display == _gdk_display);
664 *width = GetSystemMetrics (SM_CXCURSOR);
666 *height = GetSystemMetrics (SM_CYCURSOR);
670 /* Convert a pixbuf to an HICON (or HCURSOR). Supports alpha under
671 * Windows XP, thresholds alpha otherwise. Also used from
672 * gdkwindow-win32.c for creating application icons.
676 create_alpha_bitmap (gint size,
683 ZeroMemory (&bi, sizeof (BITMAPV5HEADER));
684 bi.bV5Size = sizeof (BITMAPV5HEADER);
685 bi.bV5Height = bi.bV5Width = size;
688 bi.bV5Compression = BI_BITFIELDS;
689 /* The following mask specification specifies a supported 32 BPP
690 * alpha format for Windows XP (BGRA format).
692 bi.bV5RedMask = 0x00FF0000;
693 bi.bV5GreenMask = 0x0000FF00;
694 bi.bV5BlueMask = 0x000000FF;
695 bi.bV5AlphaMask = 0xFF000000;
697 /* Create the DIB section with an alpha channel. */
701 WIN32_GDI_FAILED ("GetDC");
704 hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS,
705 (PVOID *) outdata, NULL, (DWORD)0);
707 WIN32_GDI_FAILED ("CreateDIBSection");
708 ReleaseDC (NULL, hdc);
714 create_color_bitmap (gint size,
719 BITMAPV4HEADER bmiHeader;
720 RGBQUAD bmiColors[2];
725 ZeroMemory (&bmi, sizeof (bmi));
726 bmi.bmiHeader.bV4Size = sizeof (BITMAPV4HEADER);
727 bmi.bmiHeader.bV4Height = bmi.bmiHeader.bV4Width = size;
728 bmi.bmiHeader.bV4Planes = 1;
729 bmi.bmiHeader.bV4BitCount = bits;
730 bmi.bmiHeader.bV4V4Compression = BI_RGB;
732 /* when bits is 1, these will be used.
733 * bmiColors[0] already zeroed from ZeroMemory()
735 bmi.bmiColors[1].rgbBlue = 0xFF;
736 bmi.bmiColors[1].rgbGreen = 0xFF;
737 bmi.bmiColors[1].rgbRed = 0xFF;
742 WIN32_GDI_FAILED ("GetDC");
745 hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bmi, DIB_RGB_COLORS,
746 (PVOID *) outdata, NULL, (DWORD)0);
748 WIN32_GDI_FAILED ("CreateDIBSection");
749 ReleaseDC (NULL, hdc);
755 pixbuf_to_hbitmaps_alpha_winxp (GdkPixbuf *pixbuf,
759 /* Based on code from
760 * http://www.dotnet247.com/247reference/msgs/13/66301.aspx
762 HBITMAP hColorBitmap, hMaskBitmap;
763 guchar *indata, *inrow;
764 guchar *colordata, *colorrow, *maskdata, *maskbyte;
765 gint width, height, size, i, i_offset, j, j_offset, rowstride;
766 guint maskstride, mask_bit;
768 width = gdk_pixbuf_get_width (pixbuf); /* width of icon */
769 height = gdk_pixbuf_get_height (pixbuf); /* height of icon */
771 /* The bitmaps are created square */
772 size = MAX (width, height);
774 hColorBitmap = create_alpha_bitmap (size, &colordata);
777 hMaskBitmap = create_color_bitmap (size, &maskdata, 1);
780 DeleteObject (hColorBitmap);
784 /* MSDN says mask rows are aligned to "LONG" boundaries */
785 maskstride = (((size + 31) & ~31) >> 3);
787 indata = gdk_pixbuf_get_pixels (pixbuf);
788 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
793 j_offset = (width - height) / 2;
797 i_offset = (height - width) / 2;
801 for (j = 0; j < height; j++)
803 colorrow = colordata + 4*(j+j_offset)*size + 4*i_offset;
804 maskbyte = maskdata + (j+j_offset)*maskstride + i_offset/8;
805 mask_bit = (0x80 >> (i_offset % 8));
806 inrow = indata + (height-j-1)*rowstride;
807 for (i = 0; i < width; i++)
809 colorrow[4*i+0] = inrow[4*i+2];
810 colorrow[4*i+1] = inrow[4*i+1];
811 colorrow[4*i+2] = inrow[4*i+0];
812 colorrow[4*i+3] = inrow[4*i+3];
813 if (inrow[4*i+3] == 0)
814 maskbyte[0] |= mask_bit; /* turn ON bit */
816 maskbyte[0] &= ~mask_bit; /* turn OFF bit */
826 *color = hColorBitmap;
833 pixbuf_to_hbitmaps_normal (GdkPixbuf *pixbuf,
837 /* Based on code from
838 * http://www.dotnet247.com/247reference/msgs/13/66301.aspx
840 HBITMAP hColorBitmap, hMaskBitmap;
841 guchar *indata, *inrow;
842 guchar *colordata, *colorrow, *maskdata, *maskbyte;
843 gint width, height, size, i, i_offset, j, j_offset, rowstride, nc, bmstride;
845 guint maskstride, mask_bit;
847 width = gdk_pixbuf_get_width (pixbuf); /* width of icon */
848 height = gdk_pixbuf_get_height (pixbuf); /* height of icon */
850 /* The bitmaps are created square */
851 size = MAX (width, height);
853 hColorBitmap = create_color_bitmap (size, &colordata, 24);
856 hMaskBitmap = create_color_bitmap (size, &maskdata, 1);
859 DeleteObject (hColorBitmap);
863 /* rows are always aligned on 4-byte boundarys */
865 if (bmstride % 4 != 0)
866 bmstride += 4 - (bmstride % 4);
868 /* MSDN says mask rows are aligned to "LONG" boundaries */
869 maskstride = (((size + 31) & ~31) >> 3);
871 indata = gdk_pixbuf_get_pixels (pixbuf);
872 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
873 nc = gdk_pixbuf_get_n_channels (pixbuf);
874 has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
879 j_offset = (width - height) / 2;
883 i_offset = (height - width) / 2;
887 for (j = 0; j < height; j++)
889 colorrow = colordata + (j+j_offset)*bmstride + 3*i_offset;
890 maskbyte = maskdata + (j+j_offset)*maskstride + i_offset/8;
891 mask_bit = (0x80 >> (i_offset % 8));
892 inrow = indata + (height-j-1)*rowstride;
893 for (i = 0; i < width; i++)
895 if (has_alpha && inrow[nc*i+3] < 128)
897 colorrow[3*i+0] = colorrow[3*i+1] = colorrow[3*i+2] = 0;
898 maskbyte[0] |= mask_bit; /* turn ON bit */
902 colorrow[3*i+0] = inrow[nc*i+2];
903 colorrow[3*i+1] = inrow[nc*i+1];
904 colorrow[3*i+2] = inrow[nc*i+0];
905 maskbyte[0] &= ~mask_bit; /* turn OFF bit */
916 *color = hColorBitmap;
923 pixbuf_to_hicon (GdkPixbuf *pixbuf,
935 if (_gdk_win32_pixbuf_to_hicon_supports_alpha() && gdk_pixbuf_get_has_alpha (pixbuf))
936 success = pixbuf_to_hbitmaps_alpha_winxp (pixbuf, &ii.hbmColor, &ii.hbmMask);
938 success = pixbuf_to_hbitmaps_normal (pixbuf, &ii.hbmColor, &ii.hbmMask);
946 icon = CreateIconIndirect (&ii);
947 DeleteObject (ii.hbmColor);
948 DeleteObject (ii.hbmMask);
953 _gdk_win32_pixbuf_to_hicon (GdkPixbuf *pixbuf)
955 return pixbuf_to_hicon (pixbuf, TRUE, 0, 0);
959 _gdk_win32_pixbuf_to_hcursor (GdkPixbuf *pixbuf,
963 return pixbuf_to_hicon (pixbuf, FALSE, x_hotspot, y_hotspot);
967 _gdk_win32_pixbuf_to_hicon_supports_alpha (void)
969 static gboolean is_win_xp=FALSE, is_win_xp_checked=FALSE;
971 if (!is_win_xp_checked)
973 OSVERSIONINFO version;
975 is_win_xp_checked = TRUE;
977 memset (&version, 0, sizeof (version));
978 version.dwOSVersionInfoSize = sizeof (version);
979 is_win_xp = GetVersionEx (&version)
980 && version.dwPlatformId == VER_PLATFORM_WIN32_NT
981 && (version.dwMajorVersion > 5
982 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1));
988 gdk_win32_pixbuf_to_hicon_libgtk_only (GdkPixbuf *pixbuf)
990 return _gdk_win32_pixbuf_to_hicon (pixbuf);