aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGeoff Voelker1998-11-10 20:50:40 +0000
committerGeoff Voelker1998-11-10 20:50:40 +0000
commit0eaf592609ab8a3cd6a7836b28f0891740098ae8 (patch)
tree7b6379a69d4af6783b5359e7002ca4139602e776 /src
parentf98169a0231db236d7f989c4f6e94504e6d48a71 (diff)
downloademacs-0eaf592609ab8a3cd6a7836b28f0891740098ae8.tar.gz
emacs-0eaf592609ab8a3cd6a7836b28f0891740098ae8.zip
(sys_kill): Set extended key flag when faking
Ctrl-Break keystrokes. (Fw32_get_locale_info): Allow LONGFORM parameter to specify an arbitrary locale property using a numerical index. (Vw32_valid_codepages): New variable. (enum_codepage_fn): (Fw32_get_valid_codepages): (Fw32_get_console_codepage): (Fw32_set_console_codepage): (Fw32_get_console_output_codepage): (Fw32_set_console_output_codepage): (Fw32_get_codepage_charset): (Fw32_get_valid_keyboard_layouts): (Fw32_get_keyboard_layout): (Fw32_set_keyboard_layout): New functions, exposing Windows locale handling functions. (syms_of_ntproc): Register them.
Diffstat (limited to 'src')
-rw-r--r--src/w32proc.c208
1 files changed, 202 insertions, 6 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index b579c946bb6..f02419e9ad3 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1351,10 +1351,14 @@ sys_kill (int pid, int sig)
1351 foreground_window = GetForegroundWindow (); 1351 foreground_window = GetForegroundWindow ();
1352 if (foreground_window && SetForegroundWindow (cp->hwnd)) 1352 if (foreground_window && SetForegroundWindow (cp->hwnd))
1353 { 1353 {
1354 /* Generate keystrokes as if user had typed Ctrl-Break or Ctrl-C. */ 1354 /* Generate keystrokes as if user had typed Ctrl-Break or
1355 Ctrl-C. */
1355 keybd_event (VK_CONTROL, control_scan_code, 0, 0); 1356 keybd_event (VK_CONTROL, control_scan_code, 0, 0);
1356 keybd_event (vk_break_code, break_scan_code, 0, 0); 1357 keybd_event (vk_break_code, break_scan_code,
1357 keybd_event (vk_break_code, break_scan_code, KEYEVENTF_KEYUP, 0); 1358 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY), 0);
1359 keybd_event (vk_break_code, break_scan_code,
1360 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY)
1361 | KEYEVENTF_KEYUP, 0);
1358 keybd_event (VK_CONTROL, control_scan_code, KEYEVENTF_KEYUP, 0); 1362 keybd_event (VK_CONTROL, control_scan_code, KEYEVENTF_KEYUP, 0);
1359 1363
1360 /* Sleep for a bit to give time for Emacs frame to respond 1364 /* Sleep for a bit to give time for Emacs frame to respond
@@ -1713,8 +1717,10 @@ language as the first two characters, and the country or regionial variant\n\
1713as the third letter. For example, ENU refers to `English (United States)',\n\ 1717as the third letter. For example, ENU refers to `English (United States)',\n\
1714while ENC means `English (Canadian)'.\n\ 1718while ENC means `English (Canadian)'.\n\
1715\n\ 1719\n\
1716If the optional argument LONGFORM is non-nil, the long form of the locale\n\ 1720If the optional argument LONGFORM is t, the long form of the locale\n\
1717name is returned, e.g. `English (United States)' instead.\n\ 1721name is returned, e.g. `English (United States)' instead; if LONGFORM\n\
1722is a number, it is interpreted as an LCTYPE constant and the corresponding\n\
1723locale information is returned.\n\
1718\n\ 1724\n\
1719If LCID (a 16-bit number) is not a valid locale, the result is nil.") 1725If LCID (a 16-bit number) is not a valid locale, the result is nil.")
1720 (lcid, longform) 1726 (lcid, longform)
@@ -1738,7 +1744,7 @@ If LCID (a 16-bit number) is not a valid locale, the result is nil.")
1738 if (got_abbrev) 1744 if (got_abbrev)
1739 return build_string (abbrev_name); 1745 return build_string (abbrev_name);
1740 } 1746 }
1741 else 1747 else if (EQ (longform, Qt))
1742 { 1748 {
1743 got_full = GetLocaleInfo (XINT (lcid), 1749 got_full = GetLocaleInfo (XINT (lcid),
1744 LOCALE_SLANGUAGE | LOCALE_USE_CP_ACP, 1750 LOCALE_SLANGUAGE | LOCALE_USE_CP_ACP,
@@ -1746,6 +1752,14 @@ If LCID (a 16-bit number) is not a valid locale, the result is nil.")
1746 if (got_full) 1752 if (got_full)
1747 return build_string (full_name); 1753 return build_string (full_name);
1748 } 1754 }
1755 else if (NUMBERP (longform))
1756 {
1757 got_full = GetLocaleInfo (XINT (lcid),
1758 XINT (longform),
1759 full_name, sizeof (full_name));
1760 if (got_full)
1761 return make_unibyte_string (full_name, got_full);
1762 }
1749 1763
1750 return Qnil; 1764 return Qnil;
1751} 1765}
@@ -1840,6 +1854,177 @@ If successful, the new locale id is returned, otherwise nil.")
1840 return make_number (GetThreadLocale ()); 1854 return make_number (GetThreadLocale ());
1841} 1855}
1842 1856
1857
1858/* We need to build a global list, since the EnumCodePages callback
1859 function isn't given a context pointer. */
1860Lisp_Object Vw32_valid_codepages;
1861
1862BOOL CALLBACK enum_codepage_fn (LPTSTR codepageNum)
1863{
1864 DWORD id = atoi (codepageNum);
1865 Vw32_valid_codepages = Fcons (make_number (id), Vw32_valid_codepages);
1866 return TRUE;
1867}
1868
1869DEFUN ("w32-get-valid-codepages", Fw32_get_valid_codepages, Sw32_get_valid_codepages, 0, 0, 0,
1870 "Return list of all valid Windows codepages.")
1871 ()
1872{
1873 Vw32_valid_codepages = Qnil;
1874
1875 EnumSystemCodePages (enum_codepage_fn, CP_SUPPORTED);
1876
1877 Vw32_valid_codepages = Fnreverse (Vw32_valid_codepages);
1878 return Vw32_valid_codepages;
1879}
1880
1881
1882DEFUN ("w32-get-console-codepage", Fw32_get_console_codepage, Sw32_get_console_codepage, 0, 0, 0,
1883 "Return current Windows codepage for console input.")
1884 ()
1885{
1886 return make_number (GetConsoleCP ());
1887}
1888
1889
1890DEFUN ("w32-set-console-codepage", Fw32_set_console_codepage, Sw32_set_console_codepage, 1, 1, 0,
1891 "Make Windows codepage CP be the current codepage setting for Emacs.\n\
1892The codepage setting affects keyboard input and display in tty mode.\n\
1893If successful, the new CP is returned, otherwise nil.")
1894 (cp)
1895 Lisp_Object cp;
1896{
1897 CHECK_NUMBER (cp, 0);
1898
1899 if (!IsValidCodePage (XINT (cp)))
1900 return Qnil;
1901
1902 if (!SetConsoleCP (XINT (cp)))
1903 return Qnil;
1904
1905 return make_number (GetConsoleCP ());
1906}
1907
1908
1909DEFUN ("w32-get-console-output-codepage", Fw32_get_console_output_codepage, Sw32_get_console_output_codepage, 0, 0, 0,
1910 "Return current Windows codepage for console output.")
1911 ()
1912{
1913 return make_number (GetConsoleOutputCP ());
1914}
1915
1916
1917DEFUN ("w32-set-console-output-codepage", Fw32_set_console_output_codepage, Sw32_set_console_output_codepage, 1, 1, 0,
1918 "Make Windows codepage CP be the current codepage setting for Emacs.\n\
1919The codepage setting affects keyboard input and display in tty mode.\n\
1920If successful, the new CP is returned, otherwise nil.")
1921 (cp)
1922 Lisp_Object cp;
1923{
1924 CHECK_NUMBER (cp, 0);
1925
1926 if (!IsValidCodePage (XINT (cp)))
1927 return Qnil;
1928
1929 if (!SetConsoleOutputCP (XINT (cp)))
1930 return Qnil;
1931
1932 return make_number (GetConsoleOutputCP ());
1933}
1934
1935
1936DEFUN ("w32-get-codepage-charset", Fw32_get_codepage_charset, Sw32_get_codepage_charset, 1, 1, 0,
1937 "Return charset of codepage CP.\n\
1938Returns nil if the codepage is not valid.")
1939 (cp)
1940 Lisp_Object cp;
1941{
1942 CHARSETINFO info;
1943
1944 CHECK_NUMBER (cp, 0);
1945
1946 if (!IsValidCodePage (XINT (cp)))
1947 return Qnil;
1948
1949 if (TranslateCharsetInfo ((DWORD *) XINT (cp), &info, TCI_SRCCODEPAGE))
1950 return make_number (info.ciCharset);
1951
1952 return Qnil;
1953}
1954
1955
1956DEFUN ("w32-get-valid-keyboard-layouts", Fw32_get_valid_keyboard_layouts, Sw32_get_valid_keyboard_layouts, 0, 0, 0,
1957 "Return list of Windows keyboard languages and layouts.\n\
1958The return value is a list of pairs of language id and layout id.")
1959 ()
1960{
1961 int num_layouts = GetKeyboardLayoutList (0, NULL);
1962 HKL * layouts = (HKL *) alloca (num_layouts * sizeof (HKL));
1963 Lisp_Object obj = Qnil;
1964
1965 if (GetKeyboardLayoutList (num_layouts, layouts) == num_layouts)
1966 {
1967 while (--num_layouts >= 0)
1968 {
1969 DWORD kl = (DWORD) layouts[num_layouts];
1970
1971 obj = Fcons (Fcons (make_number (kl & 0xffff),
1972 make_number ((kl >> 16) & 0xffff)),
1973 obj);
1974 }
1975 }
1976
1977 return obj;
1978}
1979
1980
1981DEFUN ("w32-get-keyboard-layout", Fw32_get_keyboard_layout, Sw32_get_keyboard_layout, 0, 0, 0,
1982 "Return current Windows keyboard language and layout.\n\
1983The return value is the cons of the language id and the layout id.")
1984 ()
1985{
1986 DWORD kl = (DWORD) GetKeyboardLayout (dwWindowsThreadId);
1987
1988 return Fcons (make_number (kl & 0xffff),
1989 make_number ((kl >> 16) & 0xffff));
1990}
1991
1992
1993DEFUN ("w32-set-keyboard-layout", Fw32_set_keyboard_layout, Sw32_set_keyboard_layout, 1, 1, 0,
1994 "Make LAYOUT be the current keyboard layout for Emacs.\n\
1995The keyboard layout setting affects interpretation of keyboard input.\n\
1996If successful, the new layout id is returned, otherwise nil.")
1997 (layout)
1998 Lisp_Object layout;
1999{
2000 DWORD kl;
2001
2002 CHECK_CONS (layout, 0);
2003 CHECK_NUMBER (XCONS (layout)->car, 0);
2004 CHECK_NUMBER (XCONS (layout)->cdr, 0);
2005
2006 kl = (XINT (XCONS (layout)->car) & 0xffff)
2007 | (XINT (XCONS (layout)->cdr) << 16);
2008
2009 /* Synchronize layout with input thread. */
2010 if (dwWindowsThreadId)
2011 {
2012 if (PostThreadMessage (dwWindowsThreadId, WM_EMACS_SETKEYBOARDLAYOUT,
2013 (WPARAM) kl, 0))
2014 {
2015 MSG msg;
2016 GetMessage (&msg, NULL, WM_EMACS_DONE, WM_EMACS_DONE);
2017
2018 if (msg.wParam == 0)
2019 return Qnil;
2020 }
2021 }
2022 else if (!ActivateKeyboardLayout ((HKL) kl, 0))
2023 return Qnil;
2024
2025 return Fw32_get_keyboard_layout ();
2026}
2027
1843 2028
1844syms_of_ntproc () 2029syms_of_ntproc ()
1845{ 2030{
@@ -1859,6 +2044,17 @@ syms_of_ntproc ()
1859 defsubr (&Sw32_get_valid_locale_ids); 2044 defsubr (&Sw32_get_valid_locale_ids);
1860 defsubr (&Sw32_set_current_locale); 2045 defsubr (&Sw32_set_current_locale);
1861 2046
2047 defsubr (&Sw32_get_console_codepage);
2048 defsubr (&Sw32_set_console_codepage);
2049 defsubr (&Sw32_get_console_output_codepage);
2050 defsubr (&Sw32_set_console_output_codepage);
2051 defsubr (&Sw32_get_valid_codepages);
2052 defsubr (&Sw32_get_codepage_charset);
2053
2054 defsubr (&Sw32_get_valid_keyboard_layouts);
2055 defsubr (&Sw32_get_keyboard_layout);
2056 defsubr (&Sw32_set_keyboard_layout);
2057
1862 DEFVAR_LISP ("w32-quote-process-args", &Vw32_quote_process_args, 2058 DEFVAR_LISP ("w32-quote-process-args", &Vw32_quote_process_args,
1863 "Non-nil enables quoting of process arguments to ensure correct parsing.\n\ 2059 "Non-nil enables quoting of process arguments to ensure correct parsing.\n\
1864Because Windows does not directly pass argv arrays to child processes,\n\ 2060Because Windows does not directly pass argv arrays to child processes,\n\