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 _gdk_win32_data_to_wcursor (GdkCursorType cursor_type)
69 guchar *and_plane, *xor_plane;
71 for (i = 0; i < G_N_ELEMENTS (cursors); i++)
72 if (cursors[i].type == cursor_type)
75 if (i >= G_N_ELEMENTS (cursors) || !cursors[i].name)
78 /* use real win32 cursor if possible */
79 if (cursors[i].builtin)
81 return LoadCursor (NULL, cursors[i].builtin);
84 w = GetSystemMetrics (SM_CXCURSOR);
85 h = GetSystemMetrics (SM_CYCURSOR);
87 and_plane = g_malloc ((w/8) * h);
88 memset (and_plane, 0xff, (w/8) * h);
89 xor_plane = g_malloc ((w/8) * h);
90 memset (xor_plane, 0, (w/8) * h);
92 #define SET_BIT(v,b) (v |= (1 << b))
93 #define RESET_BIT(v,b) (v &= ~(1 << b))
95 for (j = 0, y = 0; y < cursors[i].height && y < h ; y++)
98 j = y * cursors[i].width;
100 for (x = 0; x < cursors[i].width && x < w ; x++, j++)
102 gint pofs = ofs + x / 8;
103 guchar data = (cursors[i].data[j/4] & (0xc0 >> (2 * (j%4)))) >> (2 * (3 - (j%4)));
104 gint bit = 7 - (j % cursors[i].width) % 8;
108 RESET_BIT (and_plane[pofs], bit);
110 SET_BIT (xor_plane[pofs], bit);
118 rv = CreateCursor (_gdk_app_hmodule, cursors[i].hotx, cursors[i].hoty,
119 w, h, and_plane, xor_plane);
121 WIN32_API_FAILED ("CreateCursor");
129 _gdk_win32_cursor_new_from_hcursor (HCURSOR hcursor, GdkCursorType cursor_type)
131 GdkCursorPrivate *private;
134 private = g_new (GdkCursorPrivate, 1);
135 private->hcursor = hcursor;
136 cursor = (GdkCursor*) private;
137 cursor->type = cursor_type;
138 cursor->ref_count = 1;
144 gdk_cursor_new_for_display (GdkDisplay *display,
145 GdkCursorType cursor_type)
149 g_return_val_if_fail (display == _gdk_display, NULL);
151 hcursor = _gdk_win32_data_to_wcursor (cursor_type);
154 g_warning ("gdk_cursor_new_for_display: no cursor %d found", cursor_type);
156 GDK_NOTE (MISC, g_print ("gdk_cursor_new_for_display: %d: %p\n",
157 cursor_type, hcursor));
159 return _gdk_win32_cursor_new_from_hcursor (hcursor, cursor_type);
163 color_is_white (const GdkColor *color)
165 return (color->red == 0xFFFF
166 && color->green == 0xFFFF
167 && color->blue == 0xFFFF);
171 gdk_cursor_new_from_pixmap (GdkPixmap *source,
178 GdkPixmapImplWin32 *source_impl, *mask_impl;
179 guchar *source_bits, *mask_bits;
180 gint source_bpl, mask_bpl;
182 guchar *p, *q, *xor_mask, *and_mask;
183 gint width, height, cursor_width, cursor_height;
186 const gboolean bg_is_white = color_is_white (bg);
188 g_return_val_if_fail (GDK_IS_PIXMAP (source), NULL);
189 g_return_val_if_fail (GDK_IS_PIXMAP (mask), NULL);
190 g_return_val_if_fail (fg != NULL, NULL);
191 g_return_val_if_fail (bg != NULL, NULL);
193 source_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (source)->impl);
194 mask_impl = GDK_PIXMAP_IMPL_WIN32 (GDK_PIXMAP_OBJECT (mask)->impl);
196 g_return_val_if_fail (source_impl->width == mask_impl->width
197 && source_impl->height == mask_impl->height,
199 width = source_impl->width;
200 height = source_impl->height;
201 cursor_width = GetSystemMetrics (SM_CXCURSOR);
202 cursor_height = GetSystemMetrics (SM_CYCURSOR);
204 g_return_val_if_fail (width <= cursor_width && height <= cursor_height,
207 residue = (1 << ((8-(width%8))%8)) - 1;
209 source_bits = source_impl->bits;
210 mask_bits = mask_impl->bits;
212 g_return_val_if_fail (GDK_PIXMAP_OBJECT (source)->depth == 1
213 && GDK_PIXMAP_OBJECT (mask)->depth == 1,
216 source_bpl = ((width - 1)/32 + 1)*4;
217 mask_bpl = ((mask_impl->width - 1)/32 + 1)*4;
219 #ifdef G_ENABLE_DEBUG
220 if (_gdk_debug_flags & GDK_DEBUG_CURSOR)
222 g_print ("gdk_cursor_new_from_pixmap: source=%p:\n",
223 source_impl->parent_instance.handle);
224 for (iy = 0; iy < height; iy++)
229 p = source_bits + iy*source_bpl;
230 for (ix = 0; ix < width; ix++)
234 g_print ("%c", ".X"[((*p)>>(7-(ix%8)))&1]);
240 g_print ("...mask=%p:\n", mask_impl->parent_instance.handle);
241 for (iy = 0; iy < height; iy++)
246 p = mask_bits + iy*source_bpl;
247 for (ix = 0; ix < width; ix++)
251 g_print ("%c", ".X"[((*p)>>(7-(ix%8)))&1]);
260 /* Such complex bit manipulation for this simple task, sigh.
261 * The X cursor and Windows cursor concepts are quite different.
262 * We assume here that we are always called with fg == black and
263 * bg == white, *or* the other way around. Random colours won't work.
264 * (Well, you will get a cursor, but not in those colours.)
267 /* Note: The comments below refer to the case fg==black and
268 * bg==white, as that was what was implemented first. The fg==white
269 * (the "if (fg->pixel)" branches) case was added later.
272 /* First set masked-out source bits, as all source bits matter on Windoze.
273 * As we invert them below, they will be clear in the final xor_mask.
275 for (iy = 0; iy < height; iy++)
277 p = source_bits + iy*source_bpl;
278 q = mask_bits + iy*mask_bpl;
280 for (ix = 0; ix < ((width-1)/8+1); ix++)
287 /* XOR mask is initialized to zero */
288 xor_mask = g_malloc0 (cursor_width/8 * cursor_height);
290 for (iy = 0; iy < height; iy++)
292 p = source_bits + iy*source_bpl;
293 q = xor_mask + iy*cursor_width/8;
295 for (ix = 0; ix < ((width-1)/8+1); ix++)
301 q[-1] &= ~residue; /* Clear left-over bits */
304 /* AND mask is initialized to ones */
305 and_mask = g_malloc (cursor_width/8 * cursor_height);
306 memset (and_mask, 0xFF, cursor_width/8 * cursor_height);
308 for (iy = 0; iy < height; iy++)
310 p = mask_bits + iy*mask_bpl;
311 q = and_mask + iy*cursor_width/8;
313 for (ix = 0; ix < ((width-1)/8+1); ix++)
316 q[-1] |= residue; /* Set left-over bits */
319 hcursor = CreateCursor (_gdk_app_hmodule, x, y, cursor_width, cursor_height,
322 GDK_NOTE (MISC, g_print ("gdk_cursor_new_from_pixmap: "
323 "%p (%dx%d) %p (%dx%d) = %p (%dx%d)\n",
324 GDK_PIXMAP_HBITMAP (source),
325 source_impl->width, source_impl->height,
326 GDK_PIXMAP_HBITMAP (mask),
327 mask_impl->width, mask_impl->height,
328 hcursor, cursor_width, cursor_height));
333 return _gdk_win32_cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);
336 /* The named cursors below are presumably not really useful, as the
337 * names are Win32-specific. No GTK+ application developed on Unix
338 * (and most cross-platform GTK+ apps are developed on Unix) is going
339 * to look for cursors under these Win32 names anyway.
341 * Would the following make any sense: The ms-windows theme engine
342 * calls some (to-be-defined private) API here in gdk/win32 to
343 * register the relevant cursors used by the currently active XP
344 * visual style under the names that libgtk uses to look for them
345 * ("color-picker", "dnd-ask", "dnd-copy", etc), and then when libgtk
346 * asks for those we return the ones registered by the ms-windows
347 * theme engine, if any.
353 } _default_cursors[] = {
354 { "appstarting", IDC_APPSTARTING },
355 { "arrow", IDC_ARROW },
356 { "cross", IDC_CROSS },
358 { "hand", IDC_HAND },
360 { "help", IDC_HELP },
361 { "ibeam", IDC_IBEAM },
362 { "sizeall", IDC_SIZEALL },
363 { "sizenesw", IDC_SIZENESW },
364 { "sizens", IDC_SIZENS },
365 { "sizenwse", IDC_SIZENWSE },
366 { "sizewe", IDC_SIZEWE },
367 { "uparrow", IDC_UPARROW },
372 gdk_cursor_new_from_name (GdkDisplay *display,
375 HCURSOR hcursor = NULL;
378 g_return_val_if_fail (display == _gdk_display, NULL);
380 for (i = 0; i < G_N_ELEMENTS(_default_cursors); i++)
382 if (0 == strcmp(_default_cursors[i].name, name))
383 hcursor = LoadCursor (NULL, _default_cursors[i].id);
385 /* allow to load named cursor resources linked into the executable */
387 hcursor = LoadCursor (_gdk_app_hmodule, name);
390 return _gdk_win32_cursor_new_from_hcursor (hcursor, GDK_X_CURSOR);
396 _gdk_cursor_destroy (GdkCursor *cursor)
398 GdkCursorPrivate *private;
400 g_return_if_fail (cursor != NULL);
401 private = (GdkCursorPrivate *) cursor;
403 GDK_NOTE (MISC, g_print ("_gdk_cursor_destroy: %p\n",
404 (cursor->type == GDK_CURSOR_IS_PIXMAP) ? private->hcursor : 0));
406 if (GetCursor () == private->hcursor)
409 if (!DestroyCursor (private->hcursor))
410 WIN32_API_FAILED ("DestroyCursor");
416 gdk_cursor_get_display (GdkCursor *cursor)
418 return gdk_display_get_default ();
422 gdk_win32_icon_to_pixbuf_libgtk_only (HICON hicon)
424 GdkPixbuf *pixbuf = NULL;
432 gchar *pixels, *bits, buf[32];
433 gint rowstride, x, y, w, h;
435 if (!GDI_CALL (GetIconInfo, (hicon, &ii)))
438 if (!(hdc = CreateCompatibleDC (NULL)))
440 WIN32_GDI_FAILED ("CreateCompatibleDC");
444 memset (&bmi, 0, sizeof (bmi));
445 bmi.bi.biSize = sizeof (bmi.bi);
447 if (ii.hbmColor != NULL)
453 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, 1, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
459 bmi.bi.biBitCount = 32;
460 bmi.bi.biCompression = BI_RGB;
461 bmi.bi.biHeight = -h;
463 bits = g_malloc0 (4 * w * h);
466 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmColor, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
469 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
470 pixels = gdk_pixbuf_get_pixels (pixbuf);
471 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
473 for (y = 0; y < h; y++)
475 for (x = 0; x < w; x++)
477 pixels[2] = bits[(x+y*w) * 4];
478 pixels[1] = bits[(x+y*w) * 4 + 1];
479 pixels[0] = bits[(x+y*w) * 4 + 2];
480 pixels[3] = bits[(x+y*w) * 4 + 3];
481 if (no_alpha && pixels[3] > 0)
485 pixels += (w * 4 - rowstride);
490 GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
492 pixels = gdk_pixbuf_get_pixels (pixbuf);
493 for (y = 0; y < h; y++)
495 for (x = 0; x < w; x++)
497 pixels[3] = 255 - bits[(x + y * w) * 4];
500 pixels += (w * 4 - rowstride);
510 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, 0, NULL, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
514 h = ABS (bmi.bi.biHeight) / 2;
516 bits = g_malloc0 (4 * w * h);
519 if (!GDI_CALL (GetDIBits, (hdc, ii.hbmMask, 0, h*2, bits, (BITMAPINFO *)&bmi, DIB_RGB_COLORS)))
522 pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, w, h);
523 pixels = gdk_pixbuf_get_pixels (pixbuf);
524 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
525 bpl = ((w-1)/32 + 1)*4;
527 for (y = 0; y < h*2; y++)
529 for (x = 0; x < w; x++)
531 const gint bit = 7 - (x % 8);
532 printf ("%c ", ((bits[bpl*y+x/8])&(1<<bit)) ? ' ' : 'X');
538 for (y = 0; y < h; y++)
540 const guchar *andp, *xorp;
541 if (bmi.bi.biHeight < 0)
544 xorp = bits + bpl*(h+y);
548 andp = bits + bpl*(h-y-1);
549 xorp = bits + bpl*(h+h-y-1);
551 for (x = 0; x < w; x++)
553 const gint bit = 7 - (x % 8);
554 if ((*andp) & (1<<bit))
556 if ((*xorp) & (1<<bit))
557 pixels[2] = pixels[1] = pixels[0] = 0xFF;
559 pixels[2] = pixels[1] = pixels[0] = 0;
564 pixels[2] = pixels[1] = pixels[0] = 0;
574 pixels += (w * 4 - rowstride);
578 g_snprintf (buf, sizeof (buf), "%ld", ii.xHotspot);
579 gdk_pixbuf_set_option (pixbuf, "x_hot", buf);
581 g_snprintf (buf, sizeof (buf), "%ld", ii.yHotspot);
582 gdk_pixbuf_set_option (pixbuf, "y_hot", buf);
584 /* release temporary resources */
590 DeleteObject (ii.hbmColor);
591 DeleteObject (ii.hbmMask);
597 gdk_cursor_get_image (GdkCursor *cursor)
599 g_return_val_if_fail (cursor != NULL, NULL);
601 return gdk_win32_icon_to_pixbuf_libgtk_only (((GdkCursorPrivate *) cursor)->hcursor);
605 gdk_cursor_new_from_pixbuf (GdkDisplay *display,
612 g_return_val_if_fail (display == _gdk_display, NULL);
613 g_return_val_if_fail (GDK_IS_PIXBUF (pixbuf), NULL);
614 g_return_val_if_fail (0 <= x && x < gdk_pixbuf_get_width (pixbuf), NULL);
615 g_return_val_if_fail (0 <= y && y < gdk_pixbuf_get_height (pixbuf), NULL);
617 hcursor = _gdk_win32_pixbuf_to_hcursor (pixbuf, x, y);
620 return _gdk_win32_cursor_new_from_hcursor (hcursor, GDK_CURSOR_IS_PIXMAP);
624 gdk_display_supports_cursor_alpha (GdkDisplay *display)
626 g_return_val_if_fail (display == _gdk_display, FALSE);
628 return _gdk_win32_pixbuf_to_hicon_supports_alpha ();
632 gdk_display_supports_cursor_color (GdkDisplay *display)
634 g_return_val_if_fail (display == _gdk_display, FALSE);
640 gdk_display_get_default_cursor_size (GdkDisplay *display)
642 g_return_val_if_fail (display == _gdk_display, 0);
644 return MIN (GetSystemMetrics (SM_CXCURSOR), GetSystemMetrics (SM_CYCURSOR));
648 gdk_display_get_maximal_cursor_size (GdkDisplay *display,
652 g_return_if_fail (display == _gdk_display);
655 *width = GetSystemMetrics (SM_CXCURSOR);
657 *height = GetSystemMetrics (SM_CYCURSOR);
661 /* Convert a pixbuf to an HICON (or HCURSOR). Supports alpha under
662 * Windows XP, thresholds alpha otherwise. Also used from
663 * gdkwindow-win32.c for creating application icons.
667 create_alpha_bitmap (gint size,
674 ZeroMemory (&bi, sizeof (BITMAPV5HEADER));
675 bi.bV5Size = sizeof (BITMAPV5HEADER);
676 bi.bV5Height = bi.bV5Width = size;
679 bi.bV5Compression = BI_BITFIELDS;
680 /* The following mask specification specifies a supported 32 BPP
681 * alpha format for Windows XP (BGRA format).
683 bi.bV5RedMask = 0x00FF0000;
684 bi.bV5GreenMask = 0x0000FF00;
685 bi.bV5BlueMask = 0x000000FF;
686 bi.bV5AlphaMask = 0xFF000000;
688 /* Create the DIB section with an alpha channel. */
692 WIN32_GDI_FAILED ("GetDC");
695 hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bi, DIB_RGB_COLORS,
696 (PVOID *) outdata, NULL, (DWORD)0);
698 WIN32_GDI_FAILED ("CreateDIBSection");
699 ReleaseDC (NULL, hdc);
705 create_color_bitmap (gint size,
710 BITMAPV4HEADER bmiHeader;
711 RGBQUAD bmiColors[2];
716 ZeroMemory (&bmi, sizeof (bmi));
717 bmi.bmiHeader.bV4Size = sizeof (BITMAPV4HEADER);
718 bmi.bmiHeader.bV4Height = bmi.bmiHeader.bV4Width = size;
719 bmi.bmiHeader.bV4Planes = 1;
720 bmi.bmiHeader.bV4BitCount = bits;
721 bmi.bmiHeader.bV4V4Compression = BI_RGB;
723 /* when bits is 1, these will be used.
724 * bmiColors[0] already zeroed from ZeroMemory()
726 bmi.bmiColors[1].rgbBlue = 0xFF;
727 bmi.bmiColors[1].rgbGreen = 0xFF;
728 bmi.bmiColors[1].rgbRed = 0xFF;
733 WIN32_GDI_FAILED ("GetDC");
736 hBitmap = CreateDIBSection (hdc, (BITMAPINFO *)&bmi, DIB_RGB_COLORS,
737 (PVOID *) outdata, NULL, (DWORD)0);
739 WIN32_GDI_FAILED ("CreateDIBSection");
740 ReleaseDC (NULL, hdc);
746 pixbuf_to_hbitmaps_alpha_winxp (GdkPixbuf *pixbuf,
750 /* Based on code from
751 * http://www.dotnet247.com/247reference/msgs/13/66301.aspx
753 HBITMAP hColorBitmap, hMaskBitmap;
754 guchar *indata, *inrow;
755 guchar *colordata, *colorrow, *maskdata, *maskbyte;
756 gint width, height, size, i, i_offset, j, j_offset, rowstride;
757 guint maskstride, mask_bit;
759 width = gdk_pixbuf_get_width (pixbuf); /* width of icon */
760 height = gdk_pixbuf_get_height (pixbuf); /* height of icon */
762 /* The bitmaps are created square */
763 size = MAX (width, height);
765 hColorBitmap = create_alpha_bitmap (size, &colordata);
768 hMaskBitmap = create_color_bitmap (size, &maskdata, 1);
771 DeleteObject (hColorBitmap);
775 /* MSDN says mask rows are aligned to "LONG" boundaries */
776 maskstride = (((size + 31) & ~31) >> 3);
778 indata = gdk_pixbuf_get_pixels (pixbuf);
779 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
784 j_offset = (width - height) / 2;
788 i_offset = (height - width) / 2;
792 for (j = 0; j < height; j++)
794 colorrow = colordata + 4*(j+j_offset)*size + 4*i_offset;
795 maskbyte = maskdata + (j+j_offset)*maskstride + i_offset/8;
796 mask_bit = (0x80 >> (i_offset % 8));
797 inrow = indata + (height-j-1)*rowstride;
798 for (i = 0; i < width; i++)
800 colorrow[4*i+0] = inrow[4*i+2];
801 colorrow[4*i+1] = inrow[4*i+1];
802 colorrow[4*i+2] = inrow[4*i+0];
803 colorrow[4*i+3] = inrow[4*i+3];
804 if (inrow[4*i+3] == 0)
805 maskbyte[0] |= mask_bit; /* turn ON bit */
807 maskbyte[0] &= ~mask_bit; /* turn OFF bit */
817 *color = hColorBitmap;
824 pixbuf_to_hbitmaps_normal (GdkPixbuf *pixbuf,
828 /* Based on code from
829 * http://www.dotnet247.com/247reference/msgs/13/66301.aspx
831 HBITMAP hColorBitmap, hMaskBitmap;
832 guchar *indata, *inrow;
833 guchar *colordata, *colorrow, *maskdata, *maskbyte;
834 gint width, height, size, i, i_offset, j, j_offset, rowstride, nc, bmstride;
836 guint maskstride, mask_bit;
838 width = gdk_pixbuf_get_width (pixbuf); /* width of icon */
839 height = gdk_pixbuf_get_height (pixbuf); /* height of icon */
841 /* The bitmaps are created square */
842 size = MAX (width, height);
844 hColorBitmap = create_color_bitmap (size, &colordata, 24);
847 hMaskBitmap = create_color_bitmap (size, &maskdata, 1);
850 DeleteObject (hColorBitmap);
854 /* rows are always aligned on 4-byte boundarys */
856 if (bmstride % 4 != 0)
857 bmstride += 4 - (bmstride % 4);
859 /* MSDN says mask rows are aligned to "LONG" boundaries */
860 maskstride = (((size + 31) & ~31) >> 3);
862 indata = gdk_pixbuf_get_pixels (pixbuf);
863 rowstride = gdk_pixbuf_get_rowstride (pixbuf);
864 nc = gdk_pixbuf_get_n_channels (pixbuf);
865 has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
870 j_offset = (width - height) / 2;
874 i_offset = (height - width) / 2;
878 for (j = 0; j < height; j++)
880 colorrow = colordata + (j+j_offset)*bmstride + 3*i_offset;
881 maskbyte = maskdata + (j+j_offset)*maskstride + i_offset/8;
882 mask_bit = (0x80 >> (i_offset % 8));
883 inrow = indata + (height-j-1)*rowstride;
884 for (i = 0; i < width; i++)
886 if (has_alpha && inrow[nc*i+3] < 128)
888 colorrow[3*i+0] = colorrow[3*i+1] = colorrow[3*i+2] = 0;
889 maskbyte[0] |= mask_bit; /* turn ON bit */
893 colorrow[3*i+0] = inrow[nc*i+2];
894 colorrow[3*i+1] = inrow[nc*i+1];
895 colorrow[3*i+2] = inrow[nc*i+0];
896 maskbyte[0] &= ~mask_bit; /* turn OFF bit */
907 *color = hColorBitmap;
914 pixbuf_to_hicon (GdkPixbuf *pixbuf,
926 if (_gdk_win32_pixbuf_to_hicon_supports_alpha() && gdk_pixbuf_get_has_alpha (pixbuf))
927 success = pixbuf_to_hbitmaps_alpha_winxp (pixbuf, &ii.hbmColor, &ii.hbmMask);
929 success = pixbuf_to_hbitmaps_normal (pixbuf, &ii.hbmColor, &ii.hbmMask);
937 icon = CreateIconIndirect (&ii);
938 DeleteObject (ii.hbmColor);
939 DeleteObject (ii.hbmMask);
944 _gdk_win32_pixbuf_to_hicon (GdkPixbuf *pixbuf)
946 return pixbuf_to_hicon (pixbuf, TRUE, 0, 0);
950 _gdk_win32_pixbuf_to_hcursor (GdkPixbuf *pixbuf,
954 return pixbuf_to_hicon (pixbuf, FALSE, x_hotspot, y_hotspot);
958 _gdk_win32_pixbuf_to_hicon_supports_alpha (void)
960 static gboolean is_win_xp=FALSE, is_win_xp_checked=FALSE;
962 if (!is_win_xp_checked)
964 OSVERSIONINFO version;
966 is_win_xp_checked = TRUE;
968 memset (&version, 0, sizeof (version));
969 version.dwOSVersionInfoSize = sizeof (version);
970 is_win_xp = GetVersionEx (&version)
971 && version.dwPlatformId == VER_PLATFORM_WIN32_NT
972 && (version.dwMajorVersion > 5
973 || (version.dwMajorVersion == 5 && version.dwMinorVersion >= 1));
979 gdk_win32_pixbuf_to_hicon_libgtk_only (GdkPixbuf *pixbuf)
981 return _gdk_win32_pixbuf_to_hicon (pixbuf);