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 _gdk_input_locale = GetKeyboardLayout (0);
102 _gdk_input_locale_is_ime = ImmIsIME (_gdk_input_locale);
103 GetLocaleInfo (MAKELCID (LOWORD (_gdk_input_locale), SORT_DEFAULT),
104 LOCALE_IDEFAULTANSICODEPAGE,
106 _gdk_input_codepage = atoi (buf);
107 GDK_NOTE (EVENTS, g_print ("input_locale:%p, codepage:%d\n",
108 _gdk_input_locale, _gdk_input_codepage));
112 _cf_rtf = RegisterClipboardFormat ("Rich Text Format");
113 _cf_utf8_string = RegisterClipboardFormat ("UTF8_STRING");
115 _utf8_string = gdk_atom_intern ("UTF8_STRING", FALSE);
116 _text_uri_list = gdk_atom_intern ("text/uri-list", FALSE);
117 _targets = gdk_atom_intern ("TARGETS", FALSE);
119 _local_dnd = gdk_atom_intern ("LocalDndSelection", FALSE);
120 _gdk_win32_dropfiles = gdk_atom_intern ("DROPFILES_DND", FALSE);
121 _gdk_ole2_dnd = gdk_atom_intern ("OLE2_DND", FALSE);
123 _gdk_selection_property = gdk_atom_intern ("GDK_SELECTION", FALSE);
125 _wm_transient_for = gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE);
127 _gdk_win32_selection_init ();
131 _gdk_win32_api_failed (const gchar *where,
135 gchar *msg = g_win32_error_message (GetLastError ());
136 g_warning ("%s:%d: %s failed: %s", where, line, api, msg);
141 _gdk_other_api_failed (const gchar *where,
145 g_warning ("%s:%d: %s failed", where, line, api);
149 _gdk_win32_gdi_failed (const gchar *where,
153 /* On Win9x GDI calls are implemented in 16-bit code and thus
154 * don't set the 32-bit error code, sigh.
156 if (G_WIN32_IS_NT_BASED ())
157 _gdk_win32_api_failed (where, line, api);
159 _gdk_other_api_failed (where, line, api);
163 gdk_set_use_xshm (gboolean use_xshm)
169 gdk_get_use_xshm (void)
175 gdk_screen_get_width (GdkScreen *screen)
177 return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->width;
181 gdk_screen_get_height (GdkScreen *screen)
183 return GDK_WINDOW_IMPL_WIN32 (GDK_WINDOW_OBJECT (_gdk_parent_root)->impl)->height;
186 gdk_screen_get_width_mm (GdkScreen *screen)
188 return (double) GetDeviceCaps (_gdk_display_hdc, HORZRES) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSX) * 25.4;
192 gdk_screen_get_height_mm (GdkScreen *screen)
194 return (double) GetDeviceCaps (_gdk_display_hdc, VERTRES) / GetDeviceCaps (_gdk_display_hdc, LOGPIXELSY) * 25.4;
198 _gdk_windowing_display_set_sm_client_id (GdkDisplay *display,
199 const gchar *sm_client_id)
201 g_warning("gdk_set_sm_client_id %s", sm_client_id ? sm_client_id : "NULL");
205 gdk_display_beep (GdkDisplay *display)
207 g_return_if_fail (display == gdk_display_get_default());
212 _gdk_windowing_exit (void)
214 _gdk_win32_dnd_exit ();
216 DeleteDC (_gdk_display_hdc);
217 _gdk_display_hdc = NULL;
221 gdk_get_display (void)
223 return g_strdup (gdk_display_get_name (gdk_display_get_default ()));
227 gdk_error_trap_push (void)
232 gdk_error_trap_pop (void)
238 gdk_notify_startup_complete (void)
242 #ifdef G_ENABLE_DEBUG
245 * Like g_strdup_printf, but to a static buffer. Return value does not
246 * have to be g_free()d. The buffer is of bounded size and reused
247 * cyclically. Thus the return value is valid only until that part of
248 * the buffer happens to get reused. This doesn't matter as this
249 * function's return value is used in debugging output right after the call,
250 * and the return value isn't used after that.
253 static_printf (const gchar *format,
256 static gchar buf[10000];
258 static gchar *bufp = buf;
262 va_start (args, format);
263 msg = g_strdup_vprintf (format, args);
266 g_assert (strlen (msg) < sizeof (buf));
268 if (bufp + strlen (msg) + 1 > buf + sizeof (buf))
273 bufp += strlen (msg) + 1;
280 _gdk_win32_color_to_string (const GdkColor *color)
282 return static_printf ("(%.04x,%.04x,%.04x):%.06x",
283 color->red, color->green,
284 color->blue, color->pixel);
288 _gdk_win32_print_paletteentries (const PALETTEENTRY *pep,
294 for (i = 0; i < nentries; i++)
295 g_print (" %3d %02x: %02x %02x %02x%s\n",
297 pep[i].peRed, pep[i].peGreen, pep[i].peBlue,
298 (pep[i].peFlags == 0 ? "" :
299 (pep[i].peFlags == PC_EXPLICIT ? " PC_EXPLICIT" :
300 (pep[i].peFlags == PC_NOCOLLAPSE ? " PC_NOCOLLAPSE" :
301 (pep[i].peFlags == PC_RESERVED ? " PC_RESERVED" :
302 (g_sprintf (buf, " %d", pep[i].peFlags), buf))))));
306 _gdk_win32_print_system_palette (void)
311 k = GetSystemPaletteEntries (_gdk_display_hdc, 0, 0, NULL);
312 pe = g_new (PALETTEENTRY, k);
313 k = GetSystemPaletteEntries (_gdk_display_hdc, 0, k, pe);
316 g_print ("GetSystemPaletteEntries failed: %s\n",
317 g_win32_error_message (GetLastError ()));
320 g_print ("System palette: %d entries\n", k);
321 _gdk_win32_print_paletteentries (pe, k);
327 palette_size (HPALETTE hpal)
331 if (!GetObject (hpal, sizeof (npal), &npal))
332 WIN32_GDI_FAILED ("GetObject (HPALETTE)");
338 _gdk_win32_print_hpalette (HPALETTE hpal)
343 npal = palette_size (hpal);
344 pe = g_new (PALETTEENTRY, npal);
345 n = GetPaletteEntries (hpal, 0, npal, pe);
348 g_print ("HPALETTE %p: GetPaletteEntries failed: %s\n",
349 hpal, g_win32_error_message (GetLastError ()));
352 g_print ("HPALETTE %p: %d (%d) entries\n", hpal, n, npal);
353 _gdk_win32_print_paletteentries (pe, n);
359 _gdk_win32_print_dc (HDC hdc)
368 g_print ("%p:\n", hdc);
369 obj = GetCurrentObject (hdc, OBJ_BRUSH);
370 GetObject (obj, sizeof (LOGBRUSH), &logbrush);
371 g_print ("brush: %s color=%06lx hatch=%p\n",
372 _gdk_win32_lbstyle_to_string (logbrush.lbStyle),
373 logbrush.lbColor, (gpointer) logbrush.lbHatch);
374 obj = GetCurrentObject (hdc, OBJ_PEN);
375 GetObject (obj, sizeof (EXTLOGPEN), &extlogpen);
376 g_print ("pen: %s %s %s %s w=%d %s\n",
377 _gdk_win32_pstype_to_string (extlogpen.elpPenStyle),
378 _gdk_win32_psstyle_to_string (extlogpen.elpPenStyle),
379 _gdk_win32_psendcap_to_string (extlogpen.elpPenStyle),
380 _gdk_win32_psjoin_to_string (extlogpen.elpPenStyle),
382 _gdk_win32_lbstyle_to_string (extlogpen.elpBrushStyle));
383 g_print ("rop2: %s textcolor=%06lx\n",
384 _gdk_win32_rop2_to_string (GetROP2 (hdc)),
386 hrgn = CreateRectRgn (0, 0, 0, 0);
387 if ((flag = GetClipRgn (hdc, hrgn)) == -1)
388 WIN32_API_FAILED ("GetClipRgn");
390 g_print ("no clip region\n");
393 GetRgnBox (hrgn, &rect);
394 g_print ("clip region: %p bbox: %s\n",
395 hrgn, _gdk_win32_rect_to_string (&rect));
401 _gdk_win32_cap_style_to_string (GdkCapStyle cap_style)
405 #define CASE(x) case GDK_CAP_##x: return #x
411 default: return static_printf ("illegal_%d", cap_style);
418 _gdk_win32_fill_style_to_string (GdkFill fill)
422 #define CASE(x) case GDK_##x: return #x
426 CASE (OPAQUE_STIPPLED);
428 default: return static_printf ("illegal_%d", fill);
435 _gdk_win32_function_to_string (GdkFunction function)
439 #define CASE(x) case GDK_##x: return #x
456 default: return static_printf ("illegal_%d", function);
463 _gdk_win32_join_style_to_string (GdkJoinStyle join_style)
467 #define CASE(x) case GDK_JOIN_##x: return #x
472 default: return static_printf ("illegal_%d", join_style);
479 _gdk_win32_line_style_to_string (GdkLineStyle line_style)
483 #define CASE(x) case GDK_LINE_##x: return #x
488 default: return static_printf ("illegal_%d", line_style);
495 _gdk_win32_gcvalues_mask_to_string (GdkGCValuesMask mask)
504 if (mask & GDK_GC_##x) \
505 (bufp += g_sprintf (bufp, "%s" #x, s), s = "|")
527 return static_printf ("%s", buf);
531 _gdk_win32_window_state_to_string (GdkWindowState state)
540 if (state & GDK_WINDOW_STATE_ ## x) \
541 (bufp += sprintf (bufp, "%s" #x, s), s = "|")
543 /* For clarity, also show the complement of WITHDRAWN, i.e. "MAPPED" */
544 if (!(state & GDK_WINDOW_STATE_WITHDRAWN))
545 (bufp += sprintf (bufp, "MAPPED"), s = "|");
553 return static_printf ("%s", buf);
557 _gdk_win32_rop2_to_string (int rop2)
561 #define CASE(x) case R2_##x: return #x
579 default: return static_printf ("illegal_%x", rop2);
586 _gdk_win32_lbstyle_to_string (UINT brush_style)
590 #define CASE(x) case BS_##x: return #x
598 default: return static_printf ("illegal_%d", brush_style);
605 _gdk_win32_pstype_to_string (DWORD pen_style)
607 switch (pen_style & PS_TYPE_MASK)
609 case PS_GEOMETRIC: return "GEOMETRIC";
610 case PS_COSMETIC: return "COSMETIC";
611 default: return static_printf ("illegal_%d", pen_style & PS_TYPE_MASK);
618 _gdk_win32_psstyle_to_string (DWORD pen_style)
620 switch (pen_style & PS_STYLE_MASK)
622 #define CASE(x) case PS_##x: return #x
632 default: return static_printf ("illegal_%d", pen_style & PS_STYLE_MASK);
639 _gdk_win32_psendcap_to_string (DWORD pen_style)
641 switch (pen_style & PS_ENDCAP_MASK)
643 #define CASE(x) case PS_ENDCAP_##x: return #x
648 default: return static_printf ("illegal_%d", pen_style & PS_ENDCAP_MASK);
655 _gdk_win32_psjoin_to_string (DWORD pen_style)
657 switch (pen_style & PS_JOIN_MASK)
659 #define CASE(x) case PS_JOIN_##x: return #x
664 default: return static_printf ("illegal_%d", pen_style & PS_JOIN_MASK);
671 _gdk_win32_message_to_string (UINT msg)
675 #define CASE(x) case x: return #x
688 CASE (WM_GETTEXTLENGTH);
691 CASE (WM_QUERYENDSESSION);
693 CASE (WM_ENDSESSION);
695 CASE (WM_ERASEBKGND);
696 CASE (WM_SYSCOLORCHANGE);
697 CASE (WM_SHOWWINDOW);
698 CASE (WM_WININICHANGE);
699 CASE (WM_DEVMODECHANGE);
700 CASE (WM_ACTIVATEAPP);
701 CASE (WM_FONTCHANGE);
702 CASE (WM_TIMECHANGE);
703 CASE (WM_CANCELMODE);
705 CASE (WM_MOUSEACTIVATE);
706 CASE (WM_CHILDACTIVATE);
708 CASE (WM_GETMINMAXINFO);
710 CASE (WM_ICONERASEBKGND);
711 CASE (WM_NEXTDLGCTL);
712 CASE (WM_SPOOLERSTATUS);
714 CASE (WM_MEASUREITEM);
715 CASE (WM_DELETEITEM);
716 CASE (WM_VKEYTOITEM);
717 CASE (WM_CHARTOITEM);
722 CASE (WM_QUERYDRAGICON);
723 CASE (WM_COMPAREITEM);
725 CASE (WM_COMPACTING);
726 CASE (WM_WINDOWPOSCHANGING);
727 CASE (WM_WINDOWPOSCHANGED);
730 CASE (WM_CANCELJOURNAL);
732 CASE (WM_INPUTLANGCHANGEREQUEST);
733 CASE (WM_INPUTLANGCHANGE);
736 CASE (WM_USERCHANGED);
737 CASE (WM_NOTIFYFORMAT);
738 CASE (WM_CONTEXTMENU);
739 CASE (WM_STYLECHANGING);
740 CASE (WM_STYLECHANGED);
741 CASE (WM_DISPLAYCHANGE);
746 CASE (WM_NCCALCSIZE);
749 CASE (WM_NCACTIVATE);
750 CASE (WM_GETDLGCODE);
752 CASE (WM_NCMOUSEMOVE);
753 CASE (WM_NCLBUTTONDOWN);
754 CASE (WM_NCLBUTTONUP);
755 CASE (WM_NCLBUTTONDBLCLK);
756 CASE (WM_NCRBUTTONDOWN);
757 CASE (WM_NCRBUTTONUP);
758 CASE (WM_NCRBUTTONDBLCLK);
759 CASE (WM_NCMBUTTONDOWN);
760 CASE (WM_NCMBUTTONUP);
761 CASE (WM_NCMBUTTONDBLCLK);
762 CASE (WM_NCXBUTTONDOWN);
763 CASE (WM_NCXBUTTONUP);
764 CASE (WM_NCXBUTTONDBLCLK);
769 CASE (WM_SYSKEYDOWN);
772 CASE (WM_SYSDEADCHAR);
774 CASE (WM_IME_STARTCOMPOSITION);
775 CASE (WM_IME_ENDCOMPOSITION);
776 CASE (WM_IME_COMPOSITION);
777 CASE (WM_INITDIALOG);
779 CASE (WM_SYSCOMMAND);
784 CASE (WM_INITMENUPOPUP);
785 CASE (WM_MENUSELECT);
788 CASE (WM_MENURBUTTONUP);
790 CASE (WM_MENUGETOBJECT);
791 CASE (WM_UNINITMENUPOPUP);
792 CASE (WM_MENUCOMMAND);
793 CASE (WM_CHANGEUISTATE);
794 CASE (WM_UPDATEUISTATE);
795 CASE (WM_QUERYUISTATE);
796 CASE (WM_CTLCOLORMSGBOX);
797 CASE (WM_CTLCOLOREDIT);
798 CASE (WM_CTLCOLORLISTBOX);
799 CASE (WM_CTLCOLORBTN);
800 CASE (WM_CTLCOLORDLG);
801 CASE (WM_CTLCOLORSCROLLBAR);
802 CASE (WM_CTLCOLORSTATIC);
804 CASE (WM_LBUTTONDOWN);
806 CASE (WM_LBUTTONDBLCLK);
807 CASE (WM_RBUTTONDOWN);
809 CASE (WM_RBUTTONDBLCLK);
810 CASE (WM_MBUTTONDOWN);
812 CASE (WM_MBUTTONDBLCLK);
813 CASE (WM_MOUSEWHEEL);
814 CASE (WM_XBUTTONDOWN);
816 CASE (WM_XBUTTONDBLCLK);
817 CASE (WM_PARENTNOTIFY);
818 CASE (WM_ENTERMENULOOP);
819 CASE (WM_EXITMENULOOP);
822 CASE (WM_CAPTURECHANGED);
824 CASE (WM_POWERBROADCAST);
825 CASE (WM_DEVICECHANGE);
827 CASE (WM_MDIDESTROY);
828 CASE (WM_MDIACTIVATE);
829 CASE (WM_MDIRESTORE);
831 CASE (WM_MDIMAXIMIZE);
833 CASE (WM_MDICASCADE);
834 CASE (WM_MDIICONARRANGE);
835 CASE (WM_MDIGETACTIVE);
836 CASE (WM_MDISETMENU);
837 CASE (WM_ENTERSIZEMOVE);
838 CASE (WM_EXITSIZEMOVE);
840 CASE (WM_MDIREFRESHMENU);
841 CASE (WM_IME_SETCONTEXT);
842 CASE (WM_IME_NOTIFY);
843 CASE (WM_IME_CONTROL);
844 CASE (WM_IME_COMPOSITIONFULL);
845 CASE (WM_IME_SELECT);
847 CASE (WM_IME_REQUEST);
848 CASE (WM_IME_KEYDOWN);
850 CASE (WM_MOUSEHOVER);
851 CASE (WM_MOUSELEAVE);
852 CASE (WM_NCMOUSEHOVER);
853 CASE (WM_NCMOUSELEAVE);
859 CASE (WM_RENDERFORMAT);
860 CASE (WM_RENDERALLFORMATS);
861 CASE (WM_DESTROYCLIPBOARD);
862 CASE (WM_DRAWCLIPBOARD);
863 CASE (WM_PAINTCLIPBOARD);
864 CASE (WM_VSCROLLCLIPBOARD);
865 CASE (WM_SIZECLIPBOARD);
866 CASE (WM_ASKCBFORMATNAME);
867 CASE (WM_CHANGECBCHAIN);
868 CASE (WM_HSCROLLCLIPBOARD);
869 CASE (WM_QUERYNEWPALETTE);
870 CASE (WM_PALETTEISCHANGING);
871 CASE (WM_PALETTECHANGED);
874 CASE (WM_PRINTCLIENT);
875 CASE (WM_APPCOMMAND);
876 CASE (WM_HANDHELDFIRST);
877 CASE (WM_HANDHELDLAST);
880 CASE (WM_PENWINFIRST);
881 CASE (WM_PENWINLAST);
890 if (msg >= WM_HANDHELDFIRST && msg <= WM_HANDHELDLAST)
891 return static_printf ("WM_HANDHELDFIRST+%d", msg - WM_HANDHELDFIRST);
892 else if (msg >= WM_AFXFIRST && msg <= WM_AFXLAST)
893 return static_printf ("WM_AFXFIRST+%d", msg - WM_AFXFIRST);
894 else if (msg >= WM_PENWINFIRST && msg <= WM_PENWINLAST)
895 return static_printf ("WM_PENWINFIRST+%d", msg - WM_PENWINFIRST);
896 else if (msg >= WM_USER && msg <= 0x7FFF)
897 return static_printf ("WM_USER+%d", msg - WM_USER);
898 else if (msg >= 0xC000 && msg <= 0xFFFF)
899 return static_printf ("reg-%#x", msg);
901 return static_printf ("unk-%#x", msg);
908 _gdk_win32_key_to_string (LONG lParam)
913 if (GetKeyNameText (lParam, buf, sizeof (buf)) &&
914 (keyname_utf8 = g_locale_to_utf8 (buf, -1, NULL, NULL, NULL)) != NULL)
916 gchar *retval = static_printf ("%s", keyname_utf8);
918 g_free (keyname_utf8);
923 return static_printf ("unk-%#lx", lParam);
928 _gdk_win32_rect_to_string (const RECT *rect)
930 return static_printf ("%ldx%ld@%+ld%+ld",
931 (rect->right - rect->left), (rect->bottom - rect->top),
932 rect->left, rect->top);
936 _gdk_win32_gdkrectangle_to_string (const GdkRectangle *rect)
938 return static_printf ("%dx%d@%+d%+d",
939 rect->width, rect->height,
944 _gdk_win32_gdkregion_to_string (const GdkRegion *rgn)
946 return static_printf ("%dx%d@%+d%+d",
947 (rgn->extents.x2 - rgn->extents.x1),
948 (rgn->extents.y2 - rgn->extents.y1),
949 rgn->extents.x1, rgn->extents.y1);
953 _gdk_win32_drawable_description (GdkDrawable *d)
955 gint width, height, depth;
957 gdk_drawable_get_size (d, &width, &height);
958 depth = gdk_drawable_get_depth (d);
962 G_OBJECT_TYPE_NAME (d),
963 GDK_DRAWABLE_HANDLE (d),
964 width, height, depth);
967 #endif /* G_ENABLE_DEBUG */