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 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
30 #include <glib/gprintf.h>
37 #include "gdkregion-generic.h"
38 #include "gdkkeysyms.h"
39 #include "gdkinternals.h"
41 #include "gdkprivate-win32.h"
42 #include "gdkinput-win32.h"
46 #if defined (__GNUC__) && defined (HAVE_DIMM_H)
47 /* The w32api imm.h clashes a bit with the IE5.5 dimm.h */
48 # define IMEMENUITEMINFOA hidden_IMEMENUITEMINFOA
49 # define IMEMENUITEMINFOW hidden_IMEMENUITEMINFOW
54 static gboolean gdk_synchronize = FALSE;
56 static gboolean dummy;
58 GOptionEntry _gdk_windowing_args[] = {
59 { "sync", 0, 0, G_OPTION_ARG_NONE, &gdk_synchronize,
60 /* Description of --sync in --help output */ N_("Don't batch GDI requests"), NULL },
61 { "no-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab,
62 /* Description of --no-wintab in --help output */ N_("Don't use the Wintab API for tablet support"), NULL },
63 { "ignore-wintab", 0, 0, G_OPTION_ARG_NONE, &_gdk_input_ignore_wintab,
64 /* Description of --ignore-wintab in --help output */ N_("Same as --no-wintab"), NULL },
65 { "use-wintab", 0, 0, G_OPTION_ARG_NONE, &dummy,
66 /* Description of --use-wintab in --help output */ N_("Do use the Wintab API [default]"), NULL },
67 { "max-colors", 0, 0, G_OPTION_ARG_INT, &_gdk_max_colors,
68 /* Description of --max-colors=COLORS in --help output */ N_("Size of the palette in 8 bit mode"),
69 /* Placeholder in --max-colors=COLORS in --help output */ N_("COLORS") },
74 DllMain (HINSTANCE hinstDLL,
78 _gdk_dll_hinstance = hinstDLL;
84 _gdk_windowing_init (void)
89 if (getenv ("GDK_IGNORE_WINTAB") != NULL)
90 _gdk_input_ignore_wintab = TRUE;
91 else if (getenv ("GDK_USE_WINTAB") != NULL)
92 _gdk_input_ignore_wintab = FALSE;
98 _gdk_app_hmodule = GetModuleHandle (NULL);
99 _gdk_display_hdc = CreateDC ("DISPLAY", NULL, NULL, NULL);
100 _gdk_root_window = GetDesktopWindow ();
101 _windows_version = GetVersion ();
103 if (getenv ("PRETEND_WIN9X"))
104 _windows_version = 0x80000004;
106 GDK_NOTE (MISC, g_print ("Windows version: %08x\n", (guint) _windows_version));
108 _gdk_input_locale = GetKeyboardLayout (0);
109 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
110 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
111 LOCALE_IDEFAULTANSICODEPAGE,
113 _gdk_input_codepage = atoi (buf);
114 GDK_NOTE (EVENTS, g_print ("input_locale:%p, codepage:%d\n",
115 _gdk_input_locale, _gdk_input_codepage));
119 _cf_rtf = RegisterClipboardFormat ("Rich Text Format");
120 _cf_utf8_string = RegisterClipboardFormat ("UTF8_STRING");
122 _utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE);
123 _text_uri_list = gdk_atom_intern ("text/uri-list", FALSE);
124 _targets = gdk_atom_intern ("TARGETS", FALSE);
126 _local_dnd = gdk_atom_intern ("LocalDndSelection", FALSE);
127 _gdk_win32_dropfiles = gdk_atom_intern ("DROPFILES_DND", FALSE);
128 _gdk_ole2_dnd = gdk_atom_intern ("OLE2_DND", FALSE);
130 _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
132 _wm_transient_for = gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE);
134 _gdk_win32_selection_init ();
138 _gdk_win32_api_failed (const gchar *where,
142 gchar *msg = g_win32_error_message (GetLastError ());
143 g_warning ("%s:%d: %s failed: %s", where, line, api, msg);
148 _gdk_other_api_failed (const gchar *where,
152 g_warning ("%s:%d: %s failed", where, line, api);
156 _gdk_win32_gdi_failed (const gchar *where,
160 /* On Win9x GDI calls are implemented in 16-bit code and thus
161 * don't set the 32-bit error code, sigh.
164 _gdk_win32_api_failed (where, line, api);
166 _gdk_other_api_failed (where, line, api);
170 gdk_set_use_xshm (gboolean use_xshm)
176 gdk_get_use_xshm (void)
182 gdk_screen_get_width (GdkScreen *screen)
184 return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->width;
188 gdk_screen_get_height (GdkScreen *screen)
190 return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->height;
193 gdk_screen_get_width_mm (GdkScreen *screen)
195 return (double) GetDeviceCaps (_gdk_display_hdc, HORZRES) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4;
199 gdk_screen_get_height_mm (GdkScreen *screen)
201 return (double) GetDeviceCaps (_gdk_display_hdc, VERTRES) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4;
205 _gdk_windowing_display_set_sm_client_id (GdkDisplay *display,
206 const gchar *sm_client_id)
208 g_warning("gdk_set_sm_client_id %s", sm_client_id ? sm_client_id : "NULL");
212 gdk_display_beep (GdkDisplay *display)
214 g_return_if_fail (display == gdk_display_get_default());
219 _gdk_windowing_exit (void)
221 _gdk_win32_dnd_exit ();
223 DeleteDC (_gdk_display_hdc);
224 _gdk_display_hdc = NULL;
228 gdk_get_display (void)
230 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
234 gdk_error_trap_push (void)
239 gdk_error_trap_pop (void)
245 gdk_notify_startup_complete (void)
249 #ifdef G_ENABLE_DEBUG
252 * Like g_strdup_printf, but to a static buffer. Return value does not
253 * have to be g_free()d. The buffer is of bounded size and reused
254 * cyclically. Thus the return value is valid only until that part of
255 * the buffer happens to get reused. This doesn't matter as this
256 * function's return value is used in debugging output right after the call,
257 * and the return value isn't used after that.
260 static_printf (const gchar *format,
263 static gchar buf[10000];
265 static gchar *bufp = buf;
269 va_start (args, format);
270 msg = g_strdup_vprintf (format, args);
273 g_assert (strlen (msg) < sizeof (buf));
275 if (bufp + strlen (msg) + 1 > buf + sizeof (buf))
280 bufp += strlen (msg) + 1;
287 _gdk_win32_color_to_string (const GdkColor *color)
289 return static_printf ("(%.04x,%.04x,%.04x):%.06x",
290 color->red, color->green,
291 color->blue, color->pixel);
295 _gdk_win32_print_paletteentries (const PALETTEENTRY *pep,
301 for (i = 0; i < nentries; i++)
302 g_print (" %3d %02x: %02x %02x %02x%s\n",
304 pep[i].peRed, pep[i].peGreen, pep[i].peBlue,
305 (pep[i].peFlags == 0 ? "" :
306 (pep[i].peFlags == PC_EXPLICIT ? " PC_EXPLICIT" :
307 (pep[i].peFlags == PC_NOCOLLAPSE ? " PC_NOCOLLAPSE" :
308 (pep[i].peFlags == PC_RESERVED ? " PC_RESERVED" :
309 (g_sprintf (buf, " %d", pep[i].peFlags), buf))))));
313 _gdk_win32_print_system_palette (void)
318 k = GetSystemPaletteEntries (_gdk_display_hdc, 0, 0, NULL);
319 pe = g_new (PALETTEENTRY, k);
320 k = GetSystemPaletteEntries (_gdk_display_hdc, 0, k, pe);
323 g_print ("GetSystemPaletteEntries failed: %s\n",
324 g_win32_error_message (GetLastError ()));
327 g_print ("System palette: %d entries\n", k);
328 _gdk_win32_print_paletteentries (pe, k);
334 palette_size (HPALETTE hpal)
338 if (!GetObject (hpal, sizeof (npal), &npal))
339 WIN32_GDI_FAILED ("GetObject (HPALETTE)");
345 _gdk_win32_print_hpalette (HPALETTE hpal)
350 npal = palette_size (hpal);
351 pe = g_new (PALETTEENTRY, npal);
352 n = GetPaletteEntries (hpal, 0, npal, pe);
355 g_print ("HPALETTE %p: GetPaletteEntries failed: %s\n",
356 hpal, g_win32_error_message (GetLastError ()));
359 g_print ("HPALETTE %p: %d (%d) entries\n", hpal, n, npal);
360 _gdk_win32_print_paletteentries (pe, n);
366 _gdk_win32_print_dc (HDC hdc)
375 g_print ("%p:\n", hdc);
376 obj = GetCurrentObject (hdc, OBJ_BRUSH);
377 GetObject (obj, sizeof (LOGBRUSH), &logbrush);
378 g_print ("brush: %s color=%06lx hatch=%p\n",
379 _gdk_win32_lbstyle_to_string (logbrush.lbStyle),
380 logbrush.lbColor, (gpointer) logbrush.lbHatch);
381 obj = GetCurrentObject (hdc, OBJ_PEN);
382 GetObject (obj, sizeof (EXTLOGPEN), &extlogpen);
383 g_print ("pen: %s %s %s %s w=%d %s\n",
384 _gdk_win32_pstype_to_string (extlogpen.elpPenStyle),
385 _gdk_win32_psstyle_to_string (extlogpen.elpPenStyle),
386 _gdk_win32_psendcap_to_string (extlogpen.elpPenStyle),
387 _gdk_win32_psjoin_to_string (extlogpen.elpPenStyle),
389 _gdk_win32_lbstyle_to_string (extlogpen.elpBrushStyle));
390 g_print ("rop2: %s textcolor=%06lx\n",
391 _gdk_win32_rop2_to_string (GetROP2 (hdc)),
393 hrgn = CreateRectRgn (0, 0, 0, 0);
394 if ((flag = GetClipRgn (hdc, hrgn)) == -1)
395 WIN32_API_FAILED ("GetClipRgn");
397 g_print ("no clip region\n");
400 GetRgnBox (hrgn, &rect);
401 g_print ("clip region: %p bbox: %s\n",
402 hrgn, _gdk_win32_rect_to_string (&rect));
408 _gdk_win32_cap_style_to_string (GdkCapStyle cap_style)
412 #define CASE(x) case GDK_CAP_##x: return #x
418 default: return static_printf ("illegal_%d", cap_style);
425 _gdk_win32_fill_style_to_string (GdkFill fill)
429 #define CASE(x) case GDK_##x: return #x
433 CASE (OPAQUE_STIPPLED);
435 default: return static_printf ("illegal_%d", fill);
442 _gdk_win32_function_to_string (GdkFunction function)
446 #define CASE(x) case GDK_##x: return #x
463 default: return static_printf ("illegal_%d", function);
470 _gdk_win32_join_style_to_string (GdkJoinStyle join_style)
474 #define CASE(x) case GDK_JOIN_##x: return #x
479 default: return static_printf ("illegal_%d", join_style);
486 _gdk_win32_line_style_to_string (GdkLineStyle line_style)
490 #define CASE(x) case GDK_LINE_##x: return #x
495 default: return static_printf ("illegal_%d", line_style);
502 _gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask)
511 if (mask & GDK_GC_##x) \
512 (bufp += g_sprintf (bufp, "%s" #x, s), s = "|")
534 return static_printf ("%s", buf);
538 _gdk_win32_window_state_to_string (GdkWindowState state)
547 if (state & GDK_WINDOW_STATE_ ## x) \
548 (bufp += sprintf (bufp, "%s" #x, s), s = "|")
550 /* For clarity, also show the complement of WITHDRAWN, i.e. "MAPPED" */
551 if (!(state & GDK_WINDOW_STATE_WITHDRAWN))
552 (bufp += sprintf (bufp, "MAPPED"), s = "|");
560 return static_printf ("%s", buf);
564 _gdk_win32_rop2_to_string (int rop2)
568 #define CASE(x) case R2_##x: return #x
586 default: return static_printf ("illegal_%x", rop2);
593 _gdk_win32_lbstyle_to_string (UINT brush_style)
597 #define CASE(x) case BS_##x: return #x
605 default: return static_printf ("illegal_%d", brush_style);
612 _gdk_win32_pstype_to_string (DWORD pen_style)
614 switch (pen_style & PS_TYPE_MASK)
616 case PS_GEOMETRIC: return "GEOMETRIC";
617 case PS_COSMETIC: return "COSMETIC";
618 default: return static_printf ("illegal_%d", pen_style & PS_TYPE_MASK);
625 _gdk_win32_psstyle_to_string (DWORD pen_style)
627 switch (pen_style & PS_STYLE_MASK)
629 #define CASE(x) case PS_##x: return #x
639 default: return static_printf ("illegal_%d", pen_style & PS_STYLE_MASK);
646 _gdk_win32_psendcap_to_string (DWORD pen_style)
648 switch (pen_style & PS_ENDCAP_MASK)
650 #define CASE(x) case PS_ENDCAP_##x: return #x
655 default: return static_printf ("illegal_%d", pen_style & PS_ENDCAP_MASK);
662 _gdk_win32_psjoin_to_string (DWORD pen_style)
664 switch (pen_style & PS_JOIN_MASK)
666 #define CASE(x) case PS_JOIN_##x: return #x
671 default: return static_printf ("illegal_%d", pen_style & PS_JOIN_MASK);
678 _gdk_win32_message_to_string (UINT msg)
682 #define CASE(x) case x: return #x
695 CASE (WM_GETTEXTLENGTH);
698 CASE (WM_QUERYENDSESSION);
700 CASE (WM_ENDSESSION);
702 CASE (WM_ERASEBKGND);
703 CASE (WM_SYSCOLORCHANGE);
704 CASE (WM_SHOWWINDOW);
705 CASE (WM_WININICHANGE);
706 CASE (WM_DEVMODECHANGE);
707 CASE (WM_ACTIVATEAPP);
708 CASE (WM_FONTCHANGE);
709 CASE (WM_TIMECHANGE);
710 CASE (WM_CANCELMODE);
712 CASE (WM_MOUSEACTIVATE);
713 CASE (WM_CHILDACTIVATE);
715 CASE (WM_GETMINMAXINFO);
717 CASE (WM_ICONERASEBKGND);
718 CASE (WM_NEXTDLGCTL);
719 CASE (WM_SPOOLERSTATUS);
721 CASE (WM_MEASUREITEM);
722 CASE (WM_DELETEITEM);
723 CASE (WM_VKEYTOITEM);
724 CASE (WM_CHARTOITEM);
729 CASE (WM_QUERYDRAGICON);
730 CASE (WM_COMPAREITEM);
732 CASE (WM_COMPACTING);
733 CASE (WM_WINDOWPOSCHANGING);
734 CASE (WM_WINDOWPOSCHANGED);
737 CASE (WM_CANCELJOURNAL);
739 CASE (WM_INPUTLANGCHANGEREQUEST);
740 CASE (WM_INPUTLANGCHANGE);
743 CASE (WM_USERCHANGED);
744 CASE (WM_NOTIFYFORMAT);
745 CASE (WM_CONTEXTMENU);
746 CASE (WM_STYLECHANGING);
747 CASE (WM_STYLECHANGED);
748 CASE (WM_DISPLAYCHANGE);
753 CASE (WM_NCCALCSIZE);
756 CASE (WM_NCACTIVATE);
757 CASE (WM_GETDLGCODE);
759 CASE (WM_NCMOUSEMOVE);
760 CASE (WM_NCLBUTTONDOWN);
761 CASE (WM_NCLBUTTONUP);
762 CASE (WM_NCLBUTTONDBLCLK);
763 CASE (WM_NCRBUTTONDOWN);
764 CASE (WM_NCRBUTTONUP);
765 CASE (WM_NCRBUTTONDBLCLK);
766 CASE (WM_NCMBUTTONDOWN);
767 CASE (WM_NCMBUTTONUP);
768 CASE (WM_NCMBUTTONDBLCLK);
769 CASE (WM_NCXBUTTONDOWN);
770 CASE (WM_NCXBUTTONUP);
771 CASE (WM_NCXBUTTONDBLCLK);
776 CASE (WM_SYSKEYDOWN);
779 CASE (WM_SYSDEADCHAR);
781 CASE (WM_IME_STARTCOMPOSITION);
782 CASE (WM_IME_ENDCOMPOSITION);
783 CASE (WM_IME_COMPOSITION);
784 CASE (WM_INITDIALOG);
786 CASE (WM_SYSCOMMAND);
791 CASE (WM_INITMENUPOPUP);
792 CASE (WM_MENUSELECT);
795 CASE (WM_MENURBUTTONUP);
797 CASE (WM_MENUGETOBJECT);
798 CASE (WM_UNINITMENUPOPUP);
799 CASE (WM_MENUCOMMAND);
800 CASE (WM_CHANGEUISTATE);
801 CASE (WM_UPDATEUISTATE);
802 CASE (WM_QUERYUISTATE);
803 CASE (WM_CTLCOLORMSGBOX);
804 CASE (WM_CTLCOLOREDIT);
805 CASE (WM_CTLCOLORLISTBOX);
806 CASE (WM_CTLCOLORBTN);
807 CASE (WM_CTLCOLORDLG);
808 CASE (WM_CTLCOLORSCROLLBAR);
809 CASE (WM_CTLCOLORSTATIC);
811 CASE (WM_LBUTTONDOWN);
813 CASE (WM_LBUTTONDBLCLK);
814 CASE (WM_RBUTTONDOWN);
816 CASE (WM_RBUTTONDBLCLK);
817 CASE (WM_MBUTTONDOWN);
819 CASE (WM_MBUTTONDBLCLK);
820 CASE (WM_MOUSEWHEEL);
821 CASE (WM_XBUTTONDOWN);
823 CASE (WM_XBUTTONDBLCLK);
824 CASE (WM_PARENTNOTIFY);
825 CASE (WM_ENTERMENULOOP);
826 CASE (WM_EXITMENULOOP);
829 CASE (WM_CAPTURECHANGED);
831 CASE (WM_POWERBROADCAST);
832 CASE (WM_DEVICECHANGE);
834 CASE (WM_MDIDESTROY);
835 CASE (WM_MDIACTIVATE);
836 CASE (WM_MDIRESTORE);
838 CASE (WM_MDIMAXIMIZE);
840 CASE (WM_MDICASCADE);
841 CASE (WM_MDIICONARRANGE);
842 CASE (WM_MDIGETACTIVE);
843 CASE (WM_MDISETMENU);
844 CASE (WM_ENTERSIZEMOVE);
845 CASE (WM_EXITSIZEMOVE);
847 CASE (WM_MDIREFRESHMENU);
848 CASE (WM_IME_SETCONTEXT);
849 CASE (WM_IME_NOTIFY);
850 CASE (WM_IME_CONTROL);
851 CASE (WM_IME_COMPOSITIONFULL);
852 CASE (WM_IME_SELECT);
854 CASE (WM_IME_REQUEST);
855 CASE (WM_IME_KEYDOWN);
857 CASE (WM_MOUSEHOVER);
858 CASE (WM_MOUSELEAVE);
859 CASE (WM_NCMOUSEHOVER);
860 CASE (WM_NCMOUSELEAVE);
866 CASE (WM_RENDERFORMAT);
867 CASE (WM_RENDERALLFORMATS);
868 CASE (WM_DESTROYCLIPBOARD);
869 CASE (WM_DRAWCLIPBOARD);
870 CASE (WM_PAINTCLIPBOARD);
871 CASE (WM_VSCROLLCLIPBOARD);
872 CASE (WM_SIZECLIPBOARD);
873 CASE (WM_ASKCBFORMATNAME);
874 CASE (WM_CHANGECBCHAIN);
875 CASE (WM_HSCROLLCLIPBOARD);
876 CASE (WM_QUERYNEWPALETTE);
877 CASE (WM_PALETTEISCHANGING);
878 CASE (WM_PALETTECHANGED);
881 CASE (WM_PRINTCLIENT);
882 CASE (WM_APPCOMMAND);
883 CASE (WM_HANDHELDFIRST);
884 CASE (WM_HANDHELDLAST);
887 CASE (WM_PENWINFIRST);
888 CASE (WM_PENWINLAST);
897 if (msg >= WM_HANDHELDFIRST && msg <= WM_HANDHELDLAST)
898 return static_printf ("WM_HANDHELDFIRST+%d", msg - WM_HANDHELDFIRST);
899 else if (msg >= WM_AFXFIRST && msg <= WM_AFXLAST)
900 return static_printf ("WM_AFXFIRST+%d", msg - WM_AFXFIRST);
901 else if (msg >= WM_PENWINFIRST && msg <= WM_PENWINLAST)
902 return static_printf ("WM_PENWINFIRST+%d", msg - WM_PENWINFIRST);
903 else if (msg >= WM_USER && msg <= 0x7FFF)
904 return static_printf ("WM_USER+%d", msg - WM_USER);
905 else if (msg >= 0xC000 && msg <= 0xFFFF)
906 return static_printf ("reg-%#x", msg);
908 return static_printf ("unk-%#x", msg);
915 _gdk_win32_rect_to_string (const RECT *rect)
917 return static_printf ("%ldx%ld@+%ld+%ld",
918 (rect->right - rect->left), (rect->bottom - rect->top),
919 rect->left, rect->top);
923 _gdk_win32_gdkrectangle_to_string (const GdkRectangle *rect)
925 return static_printf ("%dx%d@+%d+%d",
926 rect->width, rect->height,
931 _gdk_win32_gdkregion_to_string (const GdkRegion *rgn)
933 return static_printf ("%dx%d@+%d+%d",
934 (rgn->extents.x2 - rgn->extents.x1),
935 (rgn->extents.y2 - rgn->extents.y1),
936 rgn->extents.x1, rgn->extents.y1);
940 _gdk_win32_drawable_description (GdkDrawable *d)
942 gint width, height, depth;
944 gdk_drawable_get_size (d, &width, &height);
945 depth = gdk_drawable_get_depth (d);
949 G_OBJECT_TYPE_NAME (d),
950 GDK_DRAWABLE_HANDLE (d),
951 width, height, depth);
954 #endif /* G_ENABLE_DEBUG */