diff options
author | Miles Bader <miles@gnu.org> | 2005-02-18 00:41:50 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 2005-02-18 00:41:50 +0000 |
commit | 8d46efcc0f2045a1e5a2739c55ba6a88fbf4bcfc (patch) | |
tree | bc968a02587d51199537bb335d5494e756e35fdf /src | |
parent | 8589dc17f80450f5773a2d449fa6d94c9bb04fe3 (diff) | |
parent | 9b516537a9899900647d4eae5ec8778e6837ad3c (diff) | |
download | emacs-8d46efcc0f2045a1e5a2739c55ba6a88fbf4bcfc.tar.gz emacs-8d46efcc0f2045a1e5a2739c55ba6a88fbf4bcfc.tar.bz2 emacs-8d46efcc0f2045a1e5a2739c55ba6a88fbf4bcfc.zip |
Revision: miles@gnu.org--gnu-2005/emacs--unicode--0--patch-15
Merge from emacs--cvs-trunk--0
Patches applied:
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-95
Merge from gnus--rel--5.10
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-96
Move Gnus images into etc/images
* miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-97
- miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-105
Update from CVS
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-14
Merge from emacs--cvs-trunk--0
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-15
Update from CVS: lisp/imap.el (imap-log): Doc fix.
* miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-16
Merge from emacs--cvs-trunk--0
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 113 | ||||
-rw-r--r-- | src/data.c | 4 | ||||
-rw-r--r-- | src/dispextern.h | 15 | ||||
-rw-r--r-- | src/doc.c | 11 | ||||
-rw-r--r-- | src/emacs.c | 3 | ||||
-rw-r--r-- | src/keyboard.c | 2 | ||||
-rw-r--r-- | src/keymap.c | 77 | ||||
-rw-r--r-- | src/keymap.h | 2 | ||||
-rw-r--r-- | src/lread.c | 4 | ||||
-rw-r--r-- | src/s/ms-w32.h | 2 | ||||
-rw-r--r-- | src/w32.c | 2 | ||||
-rw-r--r-- | src/w32.h | 22 | ||||
-rw-r--r-- | src/w32select.c | 1079 | ||||
-rw-r--r-- | src/xdisp.c | 149 | ||||
-rw-r--r-- | src/xfns.c | 44 | ||||
-rw-r--r-- | src/xselect.c | 20 | ||||
-rw-r--r-- | src/xterm.c | 111 |
17 files changed, 1243 insertions, 417 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index d2afed264eb..089a3f3a694 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,116 @@ +2005-02-17 Andreas Schwab <schwab@suse.de> + + * xfns.c (hack_wm_protocols): Use correct type for last parameter + of XGetWindowProperty to avoid aliasing issues. + (Fx_window_property): Likewise. + + * xselect.c (Fx_disown_selection_internal): Use union of struct + input_event and struct selection_input_event to avoid aliasing + issues. + + * xterm.c (handle_one_xevent): Use union of struct input_event and + struct selection_input_event to avoid aliasing issues. + (SET_SAVED_MENU_EVENT): Adapt reference to inev. + +2005-02-17 Kim F. Storm <storm@cua.dk> + + * dispextern.h (enum it_method): New enum. + (GET_FROM_*): Its members. + (struct it): Change member method from function pointer to enum. + + * xdisp.c (check_it, init_from_display_pos, handle_stop) + (setup_for_ellipsis, handle_single_display_spec) + (handle_composition_prop, next_overlay_string) + (get_overlay_strings, reseat_1, reseat_to_string) + (next_element_from_ellipsis, BUFFER_POS_REACHED_P) + (in_display_vector_p, display_line, get_next_display_element): + Change it->method from function pointer to enum. + (get_next_element): New array to map it->method to function. + (get_next_display_element): Use it. + (set_iterator_to_next): Use switch instead of if/else chain. + +2005-02-15 Benjamin Riefenstahl <Benjamin.Riefenstahl@epost.de> + + * w32select.c: Summary: Thorough rework to implement Unicode + clipboard operations and delayed rendering. + + Drop last_clipboard_text and related code, keep track of + ownership via clipboard_owner instead. Drop old #if0 + sections. + + (DEFAULT_LCID, ANSICP, OEMCP, QUNICODE, QANSICP, QOEMCP) + (clipboard_owner, modifying_clipboard, cfg_coding_system) + (cfg_codepage, cfg_lcid, cfg_clipboard_type, current_text) + (current_coding_system, current_requires_encoding) + (current_num_nls, current_clipboard_type, current_lcid): New + static variables. + + (convert_to_handle_as_ascii, convert_to_handle_as_coded) + (render, render_all, run_protected, lisp_error_handler) + (owner_callback, create_owner, setup_config) + (enum_locale_callback, cp_from_locale, coding_from_cp): New + local functions. + + (term_w32select, globals_of_w32select): New global functions. + + (Fw32_set_clipboard_data): Ignore parameter FRAME, use + clipboard_owner instead. Use delayed rendering and provide + all text formats. Provide CF_LOCALE if necessary. + + (Fw32_get_clipboard_data): Handle CF_UNICODETEXT and + CF_LOCALE. Fall back to CF_TEXT, if CF_UNICODETEXT is not + available. Force DOS line-ends for decoding. + + (Fx_selection_exists_p): Handle CF_UNICODETEXT. + + (syms_of_w32select): Init and register new variables. + + * w32.h: Add prototypes for globals_of_w32select and + term_w32select. Make the neighboring K&R declarations into + prototypes, too. + + * emacs.c: Include w32.h to get function prototypes. + (main): Call globals_of_w32select. + + * w32.c (term_ntproc): Call term_w32select. + + * s/ms-w32.h: Guard MSC-specific #pragmas with an #ifdef. + +2005-02-16 Kim F. Storm <storm@cua.dk> + + * xdisp.c (BUFFER_POS_REACHED_P): Return true if pos reached and + at end of display vector. + +2005-02-15 Richard M. Stallman <rms@gnu.org> + + * xdisp.c (get_next_display_element): Fix escape-glyph criterion + for mode and header lines. + + * lread.c (syms_of_lread) <user-init-file>: Doc fix. + + * keymap.h (describe_map_tree): Change decl. + + * keyboard.c (command_loop_1): Always use safe_run_hooks + to run Qdeferred_action_function. + + * keymap.c (describe_map_tree): New arg MENTION_SHADOW. Calls changed. + (describe_map, describe_vector): Likewise. When it's 1, + don't omit shadowed bindings, instead mark them as shadowed. + + * doc.c (Fsubstitute_command_keys): Compute list of shadowing maps + for describe_map_tree. Pass 1 for MENTION_SHADOW. + + * data.c (Fsetq_default): Allow no arg case. + +2005-02-14 Kenichi Handa <handa@m17n.org> + + * coding.c (encode_coding_string): Always return a unibyte string. + If NOCOPY is nonzero and there's no need of encoding, make STR + unibyte directly. + + * xselect.c (lisp_data_to_selection_data): If OBJ is a non-ASCII + multibyte string, signal an error instead of aborting. + 2005-02-12 Dan Nicolaescu <dann@ics.uci.edu> * keyboard.c: If HAVE_FCNTL_H include fcntl.h. diff --git a/src/data.c b/src/data.c index c8b540cc4cc..a78ff68c7e4 100644 --- a/src/data.c +++ b/src/data.c @@ -1458,7 +1458,7 @@ for this variable. */) return value; } -DEFUN ("setq-default", Fsetq_default, Ssetq_default, 2, UNEVALLED, 0, +DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0, doc: /* Set the default value of variable VAR to VALUE. VAR, the variable name, is literal (not evaluated); VALUE is an expression: it is evaluated and its value returned. @@ -1470,7 +1470,7 @@ More generally, you can use multiple variables and values, as in This sets each VAR's default value to the corresponding VALUE. The VALUE for the Nth VAR can refer to the new default values of previous VARs. -usage: (setq-default VAR VALUE [VAR VALUE...]) */) +usage: (setq-default [VAR VALUE...]) */) (args) Lisp_Object args; { diff --git a/src/dispextern.h b/src/dispextern.h index a438b305c35..19f35a744e8 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -1780,6 +1780,16 @@ struct it_slice Lisp_Object height; }; +enum it_method { + GET_FROM_BUFFER = 0, + GET_FROM_DISPLAY_VECTOR, + GET_FROM_COMPOSITION, + GET_FROM_STRING, + GET_FROM_C_STRING, + GET_FROM_IMAGE, + GET_FROM_STRETCH, + NUM_IT_METHODS +}; struct it { @@ -1790,9 +1800,8 @@ struct it /* The window's frame. */ struct frame *f; - /* Function to call to load this structure with the next display - element. */ - int (* method) P_ ((struct it *it)); + /* Method to use to load this structure with the next display element. */ + enum it_method method; /* The next position at which to check for face changes, invisible text, overlay strings, end of text etc., which see. */ diff --git a/src/doc.c b/src/doc.c index 1bb78c0c376..e1012b97198 100644 --- a/src/doc.c +++ b/src/doc.c @@ -882,6 +882,9 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int { struct buffer *oldbuf; int start_idx; + /* This is for computing the SHADOWS arg for describe_map_tree. */ + Lisp_Object active_maps = Fcurrent_active_maps (Qnil); + Lisp_Object earlier_maps; changed = 1; strp += 2; /* skip \{ or \< */ @@ -932,7 +935,13 @@ thus, \\=\\=\\=\\= puts \\=\\= into the output, and \\=\\=\\=\\[ puts \\=\\[ int else if (start[-1] == '<') keymap = tem; else - describe_map_tree (tem, 1, Qnil, Qnil, (char *)0, 1, 0, 0); + { + /* Get the list of active keymaps that precede this one. + If this one's not active, get nil. */ + earlier_maps = Fcdr (Fmemq (tem, Freverse (active_maps))); + describe_map_tree (tem, 1, Fnreverse (earlier_maps), + Qnil, (char *)0, 1, 0, 0, 1); + } tem = Fbuffer_string (); Ferase_buffer (); set_buffer_internal (oldbuf); diff --git a/src/emacs.c b/src/emacs.c index becab72ccdd..300f8ef6858 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -42,6 +42,8 @@ Boston, MA 02111-1307, USA. */ #ifdef WINDOWSNT #include <fcntl.h> +#include <windows.h> /* just for w32.h */ +#include "w32.h" #endif #include "lisp.h" @@ -1660,6 +1662,7 @@ main (argc, argv #ifdef HAVE_NTGUI globals_of_w32fns (); globals_of_w32menu (); + globals_of_w32select (); #endif /* HAVE_NTGUI */ } diff --git a/src/keyboard.c b/src/keyboard.c index e10b111d12d..32d8a34216b 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -1442,7 +1442,7 @@ command_loop_1 () resize_echo_area_exactly (); if (!NILP (Vdeferred_action_list)) - call0 (Vdeferred_action_function); + safe_run_hooks (Qdeferred_action_function); if (!NILP (Vpost_command_idle_hook) && !NILP (Vrun_hooks)) { diff --git a/src/keymap.c b/src/keymap.c index 2977b4dec09..3aaecf1a5d7 100644 --- a/src/keymap.c +++ b/src/keymap.c @@ -121,10 +121,11 @@ static void describe_command P_ ((Lisp_Object, Lisp_Object)); static void describe_translation P_ ((Lisp_Object, Lisp_Object)); static void describe_map P_ ((Lisp_Object, Lisp_Object, void (*) P_ ((Lisp_Object, Lisp_Object)), - int, Lisp_Object, Lisp_Object*, int)); + int, Lisp_Object, Lisp_Object*, int, int)); static void describe_vector P_ ((Lisp_Object, Lisp_Object, Lisp_Object, void (*) (Lisp_Object, Lisp_Object), int, - Lisp_Object, Lisp_Object, int *, int, int)); + Lisp_Object, Lisp_Object, int *, + int, int, int)); static void silly_event_symbol_error P_ ((Lisp_Object)); /* Keymap object support - constructors and predicates. */ @@ -2853,7 +2854,7 @@ You type Translation\n\ if (!NILP (Vkey_translation_map)) describe_map_tree (Vkey_translation_map, 0, Qnil, prefix, - "Key translations", nomenu, 1, 0); + "Key translations", nomenu, 1, 0, 0); /* Print the (major mode) local map. */ @@ -2866,7 +2867,7 @@ You type Translation\n\ if (!NILP (start1)) { describe_map_tree (start1, 1, shadow, prefix, - "\f\nOverriding Bindings", nomenu, 0, 0); + "\f\nOverriding Bindings", nomenu, 0, 0, 0); shadow = Fcons (start1, shadow); } else @@ -2887,7 +2888,8 @@ You type Translation\n\ if (!NILP (start1)) { describe_map_tree (start1, 1, shadow, prefix, - "\f\n`keymap' Property Bindings", nomenu, 0, 0); + "\f\n`keymap' Property Bindings", nomenu, + 0, 0, 0); shadow = Fcons (start1, shadow); } @@ -2915,7 +2917,8 @@ You type Translation\n\ p += sizeof (" Minor Mode Bindings") - 1; *p = 0; - describe_map_tree (maps[i], 1, shadow, prefix, title, nomenu, 0, 0); + describe_map_tree (maps[i], 1, shadow, prefix, + title, nomenu, 0, 0, 0); shadow = Fcons (maps[i], shadow); } @@ -2925,23 +2928,23 @@ You type Translation\n\ { if (EQ (start1, XBUFFER (buffer)->keymap)) describe_map_tree (start1, 1, shadow, prefix, - "\f\nMajor Mode Bindings", nomenu, 0, 0); + "\f\nMajor Mode Bindings", nomenu, 0, 0, 0); else describe_map_tree (start1, 1, shadow, prefix, "\f\n`local-map' Property Bindings", - nomenu, 0, 0); + nomenu, 0, 0, 0); shadow = Fcons (start1, shadow); } } describe_map_tree (current_global_map, 1, shadow, prefix, - "\f\nGlobal Bindings", nomenu, 0, 1); + "\f\nGlobal Bindings", nomenu, 0, 1, 0); /* Print the function-key-map translations under this prefix. */ if (!NILP (Vfunction_key_map)) describe_map_tree (Vfunction_key_map, 0, Qnil, prefix, - "\f\nFunction key map translations", nomenu, 1, 0); + "\f\nFunction key map translations", nomenu, 1, 0, 0); UNGCPRO; return Qnil; @@ -2962,17 +2965,21 @@ You type Translation\n\ so print strings and vectors differently. If ALWAYS_TITLE is nonzero, print the title even if there are no maps - to look through. */ + to look through. + + If MENTION_SHADOW is nonzero, then when something is shadowed by SHADOW, + don't omit it; instead, mention it but say it is shadowed. */ void describe_map_tree (startmap, partial, shadow, prefix, title, nomenu, transl, - always_title) + always_title, mention_shadow) Lisp_Object startmap, shadow, prefix; int partial; char *title; int nomenu; int transl; int always_title; + int mention_shadow; { Lisp_Object maps, orig_maps, seen, sub_shadows; struct gcpro gcpro1, gcpro2, gcpro3; @@ -3074,7 +3081,7 @@ key binding\n\ describe_map (Fcdr (elt), prefix, transl ? describe_translation : describe_command, - partial, sub_shadows, &seen, nomenu); + partial, sub_shadows, &seen, nomenu, mention_shadow); skip: ; } @@ -3154,7 +3161,8 @@ describe_translation (definition, args) PARTIAL, SHADOW, NOMENU are as in `describe_map_tree' above. */ static void -describe_map (map, prefix, elt_describer, partial, shadow, seen, nomenu) +describe_map (map, prefix, elt_describer, partial, shadow, + seen, nomenu, mention_shadow) register Lisp_Object map; Lisp_Object prefix; void (*elt_describer) P_ ((Lisp_Object, Lisp_Object)); @@ -3162,6 +3170,7 @@ describe_map (map, prefix, elt_describer, partial, shadow, seen, nomenu) Lisp_Object shadow; Lisp_Object *seen; int nomenu; + int mention_shadow; { Lisp_Object tail, definition, event; Lisp_Object tem; @@ -3191,9 +3200,10 @@ describe_map (map, prefix, elt_describer, partial, shadow, seen, nomenu) || CHAR_TABLE_P (XCAR (tail))) describe_vector (XCAR (tail), prefix, Qnil, elt_describer, partial, shadow, map, - (int *)0, 0, 1); + (int *)0, 0, 1, mention_shadow); else if (CONSP (XCAR (tail))) { + int this_shadowed = 0; event = XCAR (XCAR (tail)); /* Ignore bindings whose "prefix" are not really valid events. @@ -3222,7 +3232,13 @@ describe_map (map, prefix, elt_describer, partial, shadow, seen, nomenu) if (!NILP (shadow)) { tem = shadow_lookup (shadow, kludge, Qt); - if (!NILP (tem)) continue; + if (!NILP (tem)) + { + if (mention_shadow) + this_shadowed = 1; + else + continue; + } } tem = Flookup_key (map, kludge, Qt); @@ -3242,6 +3258,13 @@ describe_map (map, prefix, elt_describer, partial, shadow, seen, nomenu) elt_describer will take care of spacing out far enough for alignment purposes. */ (*elt_describer) (definition, Qnil); + + if (this_shadowed) + { + SET_PT (PT - 1); + insert_string (" (binding currently shadowed)"); + SET_PT (PT + 1); + } } else if (EQ (XCAR (tail), Qkeymap)) { @@ -3280,7 +3303,7 @@ DESCRIBER is the output function used; nil means use `princ'. */) specbind (Qstandard_output, Fcurrent_buffer ()); CHECK_VECTOR_OR_CHAR_TABLE (vector); describe_vector (vector, Qnil, describer, describe_vector_princ, 0, - Qnil, Qnil, (int *)0, 0, 0); + Qnil, Qnil, (int *)0, 0, 0, 0); return unbind_to (count, Qnil); } @@ -3323,7 +3346,8 @@ DESCRIBER is the output function used; nil means use `princ'. */) static void describe_vector (vector, prefix, args, elt_describer, partial, shadow, entire_map, - indices, char_table_depth, keymap_p) + indices, char_table_depth, keymap_p, + mention_shadow) register Lisp_Object vector; Lisp_Object prefix, args; void (*elt_describer) P_ ((Lisp_Object, Lisp_Object)); @@ -3333,6 +3357,7 @@ describe_vector (vector, prefix, args, elt_describer, int *indices; int char_table_depth; int keymap_p; + int mention_shadow; { Lisp_Object definition; Lisp_Object tem2; @@ -3377,6 +3402,7 @@ describe_vector (vector, prefix, args, elt_describer, for (i = from; i < to; i++) { + int this_shadowed = 0; int range_beg, range_end; Lisp_Object val; @@ -3412,7 +3438,13 @@ describe_vector (vector, prefix, args, elt_describer, tem = shadow_lookup (shadow, kludge, Qt); - if (!NILP (tem)) continue; + if (!NILP (tem)) + { + if (mention_shadow) + this_shadowed = 1; + else + continue; + } } /* Ignore this definition if it is shadowed by an earlier @@ -3477,6 +3509,13 @@ describe_vector (vector, prefix, args, elt_describer, elt_describer will take care of spacing out far enough for alignment purposes. */ (*elt_describer) (definition, args); + + if (this_shadowed) + { + SET_PT (PT - 1); + insert_string (" (binding currently shadowed)"); + SET_PT (PT + 1); + } } if (CHAR_TABLE_P (vector) && ! NILP (XCHAR_TABLE (vector)->defalt)) diff --git a/src/keymap.h b/src/keymap.h index 214ba605c76..e50a62c8aa5 100644 --- a/src/keymap.h +++ b/src/keymap.h @@ -37,7 +37,7 @@ extern Lisp_Object access_keymap P_ ((Lisp_Object, Lisp_Object, int, int, int)); extern Lisp_Object get_keyelt P_ ((Lisp_Object, int)); extern Lisp_Object get_keymap P_ ((Lisp_Object, int, int)); extern void describe_map_tree P_ ((Lisp_Object, int, Lisp_Object, Lisp_Object, - char *, int, int, int)); + char *, int, int, int, int)); extern int current_minor_maps P_ ((Lisp_Object **, Lisp_Object **)); extern void initial_define_key P_ ((Lisp_Object, int, char *)); extern void initial_define_lispy_key P_ ((Lisp_Object, char *, char *)); diff --git a/src/lread.c b/src/lread.c index ccd8909b971..709db3bf29e 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3998,8 +3998,8 @@ as a function. */); DEFVAR_LISP ("user-init-file", &Vuser_init_file, doc: /* File name, including directory, of user's initialization file. -If the file loaded had extension `.elc' and there was a corresponding `.el' -file, this variable contains the name of the .el file, suitable for use +If the file loaded had extension `.elc', and the corresponding source file +exists, this variable contains the name of source file, suitable for use by functions like `custom-save-all' which edit the init file. */); Vuser_init_file = Qnil; diff --git a/src/s/ms-w32.h b/src/s/ms-w32.h index 09d31ed2e04..503c8547c69 100644 --- a/src/s/ms-w32.h +++ b/src/s/ms-w32.h @@ -477,8 +477,10 @@ extern char *get_emacs_configuration_options (void); must include config.h to pick up this pragma. */ /* Names must be < 8 bytes */ +#ifdef _MSC_VER #pragma data_seg("EMDATA") #pragma bss_seg("EMBSS") +#endif /* #define FULL_DEBUG */ /* #define EMACSDEBUG */ diff --git a/src/w32.c b/src/w32.c index 7b54924d736..cdc41a8c772 100644 --- a/src/w32.c +++ b/src/w32.c @@ -3884,6 +3884,8 @@ term_ntproc () /* shutdown the socket interface if necessary */ term_winsock (); #endif + + term_w32select (); } void diff --git a/src/w32.h b/src/w32.h index cce1f094363..79a78a5a544 100644 --- a/src/w32.h +++ b/src/w32.h @@ -122,16 +122,18 @@ extern void reset_standard_handles (int in, int out, /* Return the string resource associated with KEY of type TYPE. */ extern LPBYTE w32_get_resource (char * key, LPDWORD type); -extern void init_ntproc (); -extern void term_ntproc (); -extern void globals_of_w32 (); -extern void syms_of_w32term (); -extern void syms_of_w32fns (); -extern void globals_of_w32fns (); -extern void syms_of_w32select (); -extern void syms_of_w32menu (); -extern void globals_of_w32menu (); -extern void syms_of_fontset (); +extern void init_ntproc (void); +extern void term_ntproc (void); +extern void globals_of_w32 (void); +extern void syms_of_w32term (void); +extern void syms_of_w32fns (void); +extern void globals_of_w32fns (void); +extern void syms_of_w32select (void); +extern void globals_of_w32select (void); +extern void term_w32select (void); +extern void syms_of_w32menu (void); +extern void globals_of_w32menu (void); +extern void syms_of_fontset (void); #endif /* EMACS_W32_H */ diff --git a/src/w32select.c b/src/w32select.c index af3d477f876..478774663c8 100644 --- a/src/w32select.c +++ b/src/w32select.c @@ -1,5 +1,5 @@ /* Selection processing for Emacs on the Microsoft W32 API. - Copyright (C) 1993, 1994 Free Software Foundation. + Copyright (C) 1993, 1994, 2004 Free Software Foundation. This file is part of GNU Emacs. @@ -18,261 +18,744 @@ along with GNU Emacs; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* Written by Kevin Gallo */ - +/* Written by Kevin Gallo, Benjamin Riefenstahl */ + + +/* + * Notes on usage of selection-coding-system and + * next-selection-coding-system on MS Windows: + * + * The selection coding system variables apply only to the version of + * the clipboard data that is closest in type, i.e. when a 16-bit + * Unicode coding system is given, they apply to he Unicode clipboard + * (CF_UNICODETEXT), when a well-known console codepage is given, they + * apply to the console version of the clipboard data (CF_OEMTEXT), + * else they apply to the normal 8-bit text clipboard (CF_TEXT). + * + * When pasting (getting data from the OS), the clipboard format that + * matches the {next-}selection-coding-system is retrieved. If + * Unicode is requested, but not available, 8-bit text (CF_TEXT) is + * used. In all other cases the OS will transparently convert + * formats, so no other fallback is needed. + * + * When copying or cutting (sending data to the OS), the data is + * announced and stored internally, but only actually rendered on + * request. The requester determines the format provided. The + * {next-}selection-coding-system is only used, when its corresponding + * clipboard type matches the type requested. + * + * Scenarios to use the facilities for customizing the selection + * coding system are: + * + * ;; Generally use KOI8-R instead of the russian MS codepage for + * ;; the 8-bit clipboard. + * (set-selection-coding-system 'koi8-r-dos) + * + * Or + * + * ;; Create a special clipboard copy function that uses codepage + * ;; 1253 (Greek) to copy Greek text to a specific non-Unicode + * ;; application. + * (defun greek-copy (beg end) + * (interactive "r") + * (set-next-selection-coding-system 'cp1253-dos) + * (copy-region-as-kill beg end)) + * (global-set-key "\C-c\C-c" 'greek-copy) + */ + +/* + * Ideas for further directions: + * + * The encoding and decoding routines could be moved to Lisp code + * similar to how xselect.c does it (using well-known routine names + * for the delayed rendering). If the definition of which clipboard + * types should be supported is also moved to Lisp, functionality + * could be expanded to CF_HTML, CF_RTF and maybe other types. + */ + #include <config.h> #include "lisp.h" #include "w32term.h" /* for all of the w32 includes */ -#include "dispextern.h" /* frame.h seems to want this */ -#include "keyboard.h" -#include "frame.h" /* Need this to get the X window of selected_frame */ +#include "w32heap.h" /* os_subtype */ #include "blockinput.h" -#include "buffer.h" +#include "keyboard.h" /* cmd_error_internal() */ #include "charset.h" #include "coding.h" #include "composite.h" + +static HGLOBAL convert_to_handle_as_ascii (void); +static HGLOBAL convert_to_handle_as_coded (Lisp_Object coding_system); +static Lisp_Object render (Lisp_Object oformat); +static Lisp_Object render_locale (void); +static Lisp_Object render_all (void); +static void run_protected (Lisp_Object (*code) (), Lisp_Object arg); +static Lisp_Object lisp_error_handler (Lisp_Object error); +static LRESULT CALLBACK owner_callback (HWND win, UINT msg, + WPARAM wp, LPARAM lp); +static HWND create_owner (void); + +static void setup_config (void); +static BOOL WINAPI enum_locale_callback (/*const*/ char* loc_string); +static UINT cp_from_locale (LCID lcid, UINT format); +static Lisp_Object coding_from_cp (UINT codepage); + + +/* A remnant from X11: Symbol for the CLIPBORD selection type. Other + selections are not used on Windows, so we don't need symbols for + PRIMARY and SECONDARY. */ Lisp_Object QCLIPBOARD; -/* Coding system for communicating with other Windows programs via the +/* Coding system for communicating with other programs via the clipboard. */ static Lisp_Object Vselection_coding_system; -/* Coding system for the next communicating with other Windows programs. */ +/* Coding system for the next communication with other programs. */ static Lisp_Object Vnext_selection_coding_system; -/* Sequence number, used where possible to detect when we are pasting - our own text. */ -static DWORD last_clipboard_sequence_number; -extern ClipboardSequence_Proc clipboard_sequence_fn; - -/* The last text we put into the clipboard. This is used when the OS - does not support sequence numbers (NT4, 95). It is undesirable to - use data put on the clipboard by Emacs because the clipboard data - could be MULEtilated by inappropriately chosen - (next-)selection-coding-system. For this reason, we must store the - text *after* it was encoded/Unix-to-DOS-converted. */ -static unsigned char *last_clipboard_text = NULL; -static size_t clipboard_storage_size = 0; - -#if 0 -DEFUN ("w32-open-clipboard", Fw32_open_clipboard, Sw32_open_clipboard, 0, 1, 0, - doc: /* This opens the clipboard with the given frame pointer. */) - (frame) - Lisp_Object frame; +/* Internal pseudo-constants, initialized in globals_of_w32select() + based on current system parameters. */ +static LCID DEFAULT_LCID; +static UINT ANSICP, OEMCP; +static Lisp_Object QUNICODE, QANSICP, QOEMCP; + +/* A hidden window just for the clipboard management. */ +static HWND clipboard_owner; +/* A flag to tell WM_DESTROYCLIPBOARD who is to blame this time (just + checking GetClipboardOwner() doesn't work, sadly). */ +static int modifying_clipboard = 0; + +/* Configured transfer parameters, based on the last inspection of + selection-coding-system. */ +static Lisp_Object cfg_coding_system; +static UINT cfg_codepage; +static LCID cfg_lcid; +static UINT cfg_clipboard_type; + +/* The current state for delayed rendering. */ +static Lisp_Object current_text; +static Lisp_Object current_coding_system; +static int current_requires_encoding, current_num_nls; +static UINT current_clipboard_type; +static LCID current_lcid; + +#if TRACE +#define ONTRACE(stmt) stmt +#else +#define ONTRACE(stmt) /*stmt*/ +#endif + + +/* This function assumes that there is no multibyte character in + current_text, so we can short-cut encoding. */ + +static HGLOBAL +convert_to_handle_as_ascii (void) { - BOOL ok = FALSE; + HGLOBAL htext = NULL; + int nbytes; + int truelen; + unsigned char *src; + unsigned char *dst; - if (!NILP (frame)) - CHECK_LIVE_FRAME (frame); + ONTRACE (fprintf (stderr, "convert_to_handle_as_ascii\n")); - BLOCK_INPUT; + nbytes = SBYTES (current_text) + 1; + src = SDATA (current_text); - ok = OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL); + /* We need to add to the size the number of LF chars where we have + to insert CR chars (the standard CF_TEXT clipboard format uses + CRLF line endings, while Emacs uses just LF internally). */ - UNBLOCK_INPUT; + truelen = nbytes + current_num_nls; + + if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) + return NULL; - return (ok ? frame : Qnil); + if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) + { + GlobalFree (htext); + return NULL; + } + + /* convert to CRLF line endings expected by clipboard */ + while (1) + { + unsigned char *next; + /* copy next line or remaining bytes including '\0' */ + next = _memccpy (dst, src, '\n', nbytes); + if (next) + { + /* copied one line ending with '\n' */ + int copied = next - dst; + nbytes -= copied; + src += copied; + /* insert '\r' before '\n' */ + next[-1] = '\r'; + next[0] = '\n'; + dst = next + 1; + } + else + /* copied remaining partial line -> now finished */ + break; + } + + GlobalUnlock (htext); + + return htext; } -DEFUN ("w32-empty-clipboard", Fw32_empty_clipboard, - Sw32_empty_clipboard, 0, 0, 0, - doc: /* Empty the clipboard. -Assigns ownership of the clipboard to the window which opened it. */) - () +/* This function assumes that there are multibyte or NUL characters in + current_text, or that we need to construct Unicode. It runs the + text through the encoding machinery. */ + +static HGLOBAL +convert_to_handle_as_coded (Lisp_Object coding_system) { - BOOL ok = FALSE; + HGLOBAL htext = NULL, htext2; + int nbytes; + unsigned char *src; + unsigned char *dst = NULL; + int bufsize; + struct coding_system coding; + Lisp_Object string = Qnil; + + ONTRACE (fprintf (stderr, "convert_to_handle_as_coded: %s\n", + SDATA (SYMBOL_NAME (coding_system)))); + + setup_coding_system (Fcheck_coding_system (coding_system), &coding); + coding.src_multibyte = 1; + coding.dst_multibyte = 0; + /* Need to set COMPOSITION_DISABLED, otherwise Emacs crashes in + encode_coding_iso2022 trying to dereference a null pointer. */ + coding.composing = COMPOSITION_DISABLED; + if (coding.type == coding_type_iso2022) + coding.flags |= CODING_FLAG_ISO_SAFE; + coding.mode |= CODING_MODE_LAST_BLOCK; + /* Force DOS line-ends. */ + coding.eol_type = CODING_EOL_CRLF; + + if (SYMBOLP (coding.pre_write_conversion) + && !NILP (Ffboundp (coding.pre_write_conversion))) + string = run_pre_post_conversion_on_str (current_text, &coding, 1); + else + string = current_text; + + nbytes = SBYTES (string); + src = SDATA (string); - BLOCK_INPUT; + bufsize = encoding_buffer_size (&coding, nbytes) +2; + htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, bufsize); - ok = EmptyClipboard (); + if (htext != NULL) + dst = (unsigned char *) GlobalLock (htext); - UNBLOCK_INPUT; + if (dst != NULL) + { + encode_coding (&coding, src, dst, nbytes, bufsize-2); + /* Add the string terminator. Add two NULs in case we are + producing Unicode here. */ + dst[coding.produced] = dst[coding.produced+1] = '\0'; + } - return (ok ? Qt : Qnil); + if (dst != NULL) + GlobalUnlock (htext); + + if (htext != NULL) + { + /* Shrink data block to actual size. */ + htext2 = GlobalReAlloc (htext, coding.produced+2, + GMEM_MOVEABLE | GMEM_DDESHARE); + if (htext2 != NULL) htext = htext2; + } + + return htext; +} + +static Lisp_Object +render (Lisp_Object oformat) +{ + HGLOBAL htext = NULL; + UINT format = XFASTINT (oformat); + + ONTRACE (fprintf (stderr, "render\n")); + + if (NILP (current_text)) + return Qnil; + + if (current_requires_encoding || format == CF_UNICODETEXT) + { + if (format == current_clipboard_type) + htext = convert_to_handle_as_coded (current_coding_system); + else + switch (format) + { + case CF_UNICODETEXT: + htext = convert_to_handle_as_coded (QUNICODE); + break; + case CF_TEXT: + case CF_OEMTEXT: + { + Lisp_Object cs; + cs = coding_from_cp (cp_from_locale (current_lcid, format)); + htext = convert_to_handle_as_coded (cs); + break; + } + } + } + else + htext = convert_to_handle_as_ascii (); + + ONTRACE (fprintf (stderr, "render: htext = 0x%08X\n", (unsigned) htext)); + + if (htext == NULL) + return Qnil; + + if (SetClipboardData (format, htext) == NULL) + { + GlobalFree(htext); + return Qnil; + } + + return Qt; } -DEFUN ("w32-close-clipboard", Fw32_close_clipboard, - Sw32_close_clipboard, 0, 0, 0, - doc: /* Close the clipboard. */) - () +static Lisp_Object +render_locale (void) { - BOOL ok = FALSE; + HANDLE hlocale = NULL; + LCID * lcid_ptr; + + ONTRACE (fprintf (stderr, "render_locale\n")); + + if (current_lcid == LOCALE_NEUTRAL || current_lcid == DEFAULT_LCID) + return Qt; + + hlocale = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, sizeof (current_lcid)); + if (hlocale == NULL) + return Qnil; + + if ((lcid_ptr = (LCID *) GlobalLock (hlocale)) == NULL) + { + GlobalFree(hlocale); + return Qnil; + } + + *lcid_ptr = current_lcid; + GlobalUnlock (hlocale); + + if (SetClipboardData (CF_LOCALE, hlocale) == NULL) + { + GlobalFree(hlocale); + return Qnil; + } + + return Qt; +} + +/* At the end of the program, we want to ensure that our clipboard + data survives us. This code will do that. */ + +static Lisp_Object +render_all (void) +{ + ONTRACE (fprintf (stderr, "render_all\n")); + + /* According to the docs we should not call OpenClipboard() here, + but testing on W2K and working code in other projects shows that + it is actually necessary. */ + + OpenClipboard (NULL); + + /* There is no usefull means to report errors here, there are none + expected anyway, and even if there were errors, they wouldn't do + any harm. So we just go ahead and do what has to be done without + bothering with error handling. */ + + ++modifying_clipboard; + EmptyClipboard (); + --modifying_clipboard; + + /* For text formats that we don't render here, the OS can use its + own translation rules instead, so we don't really need to offer + everything. To minimize memory consumption we cover three + possible situations based on our primary format as detected from + selection-coding-system (see setup_config()): + + - Post CF_TEXT only. Let the OS convert to CF_OEMTEXT and the OS + (on NT) or the application (on 9x/Me) convert to + CF_UNICODETEXT. + + - Post CF_OEMTEXT only. Similar automatic conversions happen as + for CF_TEXT. + + - Post CF_UNICODETEXT + CF_TEXT. 9x itself ignores + CF_UNICODETEXT, even though some applications can still handle + it. + + Note 1: We render the less capable CF_TEXT *before* the more + capable CF_UNICODETEXT, to prevent clobbering through automatic + conversions, just in case. + + Note 2: We could check os_subtype here and only render the + additional CF_TEXT on 9x/Me. But OTOH with + current_clipboard_type == CF_UNICODETEXT we don't involve the + automatic conversions anywhere else, so to get consistent + results, we probably don't want to rely on it here either. */ + + render_locale(); + + if (current_clipboard_type == CF_UNICODETEXT) + render (make_number (CF_TEXT)); + render (make_number (current_clipboard_type)); + + CloseClipboard (); + + return Qnil; +} + +static void +run_protected (Lisp_Object (*code) (), Lisp_Object arg) +{ + /* FIXME: This works but it doesn't feel right. Too much fiddling + with global variables and calling strange looking functions. Is + this really the right way to run Lisp callbacks? */ + + extern int waiting_for_input; + int owfi; BLOCK_INPUT; - ok = CloseClipboard (); + /* Fsignal calls abort() if it sees that waiting_for_input is + set. */ + owfi = waiting_for_input; + waiting_for_input = 0; + + internal_condition_case_1 (code, arg, Qt, lisp_error_handler); + + waiting_for_input = owfi; UNBLOCK_INPUT; +} - return (ok ? Qt : Qnil); +static Lisp_Object +lisp_error_handler (Lisp_Object error) +{ + Vsignaling_function = Qnil; + cmd_error_internal (error, "Error in delayed clipboard rendering: "); + Vinhibit_quit = Qt; + return Qt; } -#endif -DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, - Sw32_set_clipboard_data, 1, 2, 0, - doc: /* This sets the clipboard data to the given text. */) - (string, frame) - Lisp_Object string, frame; +static LRESULT CALLBACK +owner_callback (HWND win, UINT msg, WPARAM wp, LPARAM lp) { - BOOL ok = TRUE; - HANDLE htext; - int nbytes; - int truelen, nlines = 0; - unsigned char *src; - unsigned char *dst; + switch (msg) + { + case WM_RENDERFORMAT: + ONTRACE (fprintf (stderr, "WM_RENDERFORMAT\n")); + run_protected (render, make_number (wp)); + return 0; + + case WM_RENDERALLFORMATS: + ONTRACE (fprintf (stderr, "WM_RENDERALLFORMATS\n")); + run_protected (render_all, Qnil); + return 0; + + case WM_DESTROYCLIPBOARD: + if (!modifying_clipboard) + { + ONTRACE (fprintf (stderr, "WM_DESTROYCLIPBOARD (other)\n")); + current_text = Qnil; + current_coding_system = Qnil; + } + else + { + ONTRACE (fprintf (stderr, "WM_DESTROYCLIPBOARD (self)\n")); + } + return 0; - CHECK_STRING (string); + case WM_DESTROY: + if (win == clipboard_owner) + clipboard_owner = NULL; + break; + } - if (!NILP (frame)) - CHECK_LIVE_FRAME (frame); + return DefWindowProc (win, msg, wp, lp); +} - BLOCK_INPUT; +static HWND +create_owner (void) +{ + static const char CLASSNAME[] = "Emacs Clipboard"; + WNDCLASS wc; - /* Include the terminating NULL character in the source of - conversion. */ - nbytes = SBYTES (string) + 1; - src = SDATA (string); - dst = src; + memset (&wc, 0, sizeof (wc)); + wc.lpszClassName = CLASSNAME; + wc.lpfnWndProc = owner_callback; + RegisterClass (&wc); + + return CreateWindow (CLASSNAME, CLASSNAME, 0, 0, 0, 0, 0, NULL, NULL, + NULL, NULL); +} + +/* Called on exit by term_ntproc() in w32.c */ + +void +term_w32select (void) +{ + /* This is needed to trigger WM_RENDERALLFORMATS. */ + if (clipboard_owner != NULL) + DestroyWindow (clipboard_owner); +} - /* We need to know how many lines there are, since we need CRLF line - termination for compatibility with other Windows Programs. - avoid using strchr because it recomputes the length every time */ - while ((dst = memchr (dst, '\n', nbytes - (dst - src))) != NULL) +static void +setup_config (void) +{ + const char *coding_name; + const char *cp; + char *end; + int slen; + Lisp_Object new_coding_system; + + CHECK_SYMBOL (Vselection_coding_system); + + /* Check if we have it cached */ + new_coding_system = NILP (Vnext_selection_coding_system) ? + Vselection_coding_system : Vnext_selection_coding_system; + if (!NILP (cfg_coding_system) + && EQ (cfg_coding_system, new_coding_system)) + return; + cfg_coding_system = new_coding_system; + + /* Set some sensible fallbacks */ + cfg_codepage = ANSICP; + cfg_lcid = LOCALE_NEUTRAL; + cfg_clipboard_type = CF_TEXT; + + /* Interpret the coding system symbol name */ + coding_name = SDATA (SYMBOL_NAME (cfg_coding_system)); + + /* "(.*-)?utf-16.*" -> CF_UNICODETEXT */ + cp = strstr (coding_name, "utf-16"); + if (cp != NULL && (cp == coding_name || cp[-1] == '-')) { - nlines++; - dst++; + cfg_clipboard_type = CF_UNICODETEXT; + return; } - { - /* Since we are now handling multilingual text, we must consider - encoding text for the clipboard. */ - int result = string_xstring_p (string); + /* "cp[0-9]+.*" or "windows-[0-9]+.*" -> CF_TEXT or CF_OEMTEXT */ + slen = strlen (coding_name); + if (slen >= 4 && coding_name[0] == 'c' && coding_name[1] == 'p') + cp = coding_name + 2; + else if (slen >= 10 && memcmp (coding_name, "windows-", 8) == 0) + cp = coding_name + 8; + else + return; + + end = (char*)cp; + cfg_codepage = strtol (cp, &end, 10); + + /* Error return from strtol() or number of digits < 2 -> Restore the + default and drop it. */ + if (cfg_codepage == 0 || (end-cp) < 2 ) + { + cfg_codepage = ANSICP; + return; + } - if (result == 0) - { - /* No multibyte character in OBJ. We need not encode it. */ + /* Is it the currently active system default? */ + if (cfg_codepage == ANSICP) + { + /* cfg_clipboard_type = CF_TEXT; */ + return; + } + if (cfg_codepage == OEMCP) + { + cfg_clipboard_type = CF_OEMTEXT; + return; + } - /* Need to know final size after CR chars are inserted (the - standard CF_TEXT clipboard format uses CRLF line endings, - while Emacs uses just LF internally). */ + /* Else determine a suitable locale the hard way. */ + EnumSystemLocales (enum_locale_callback, LCID_INSTALLED); +} - truelen = nbytes + nlines; +static BOOL WINAPI +enum_locale_callback (/*const*/ char* loc_string) +{ + LCID lcid; + UINT codepage; - if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, truelen)) == NULL) - goto error; + lcid = strtoul (loc_string, NULL, 16); - if ((dst = (unsigned char *) GlobalLock (htext)) == NULL) - goto error; + /* Is the wanted codepage the "ANSI" codepage for this locale? */ + codepage = cp_from_locale (lcid, CF_TEXT); + if (codepage == cfg_codepage) + { + cfg_lcid = lcid; + cfg_clipboard_type = CF_TEXT; + return FALSE; /* Stop enumeration */ + } + + /* Is the wanted codepage the OEM codepage for this locale? */ + codepage = cp_from_locale (lcid, CF_OEMTEXT); + if (codepage == cfg_codepage) + { + cfg_lcid = lcid; + cfg_clipboard_type = CF_OEMTEXT; + return FALSE; /* Stop enumeration */ + } - /* convert to CRLF line endings expected by clipboard */ - while (1) - { - unsigned char *next; - /* copy next line or remaining bytes including '\0' */ - next = _memccpy (dst, src, '\n', nbytes); - if (next) - { - /* copied one line ending with '\n' */ - int copied = next - dst; - nbytes -= copied; - src += copied; - /* insert '\r' before '\n' */ - next[-1] = '\r'; - next[0] = '\n'; - dst = next + 1; - } - else - /* copied remaining partial line -> now finished */ - break; - } + return TRUE; /* Continue enumeration */ +} - GlobalUnlock (htext); +static UINT +cp_from_locale (LCID lcid, UINT format) +{ + char buffer[20] = ""; + UINT variant, cp; - Vlast_coding_system_used = Qraw_text; - } - else - { - /* We must encode contents of OBJ to the selection coding - system. */ - struct coding_system coding; - HANDLE htext2; + variant = + format == CF_TEXT ? LOCALE_IDEFAULTANSICODEPAGE : LOCALE_IDEFAULTCODEPAGE; - if (NILP (Vnext_selection_coding_system)) - Vnext_selection_coding_system = Vselection_coding_system; - setup_coding_system - (Fcheck_coding_system (Vnext_selection_coding_system), &coding); - coding.mode |= (CODING_MODE_SAFE_ENCODING | CODING_MODE_LAST_BLOCK); + GetLocaleInfo (lcid, variant, buffer, sizeof (buffer)); + cp = strtoul (buffer, NULL, 10); - Vnext_selection_coding_system = Qnil; + if (cp == CP_ACP) + return ANSICP; + else if (cp == CP_OEMCP) + return OEMCP; + else + return cp; +} - /* We suppress producing escape sequences for composition. */ - coding.common_flags &= ~CODING_ANNOTATION_MASK; - coding.dst_bytes = SCHARS (string) * 2; - if ((htext = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, coding.dst_bytes)) == NULL) - goto error; - if ((coding.destination = (unsigned char *) GlobalLock (htext)) == NULL) - goto error; - encode_coding_object (&coding, string, 0, 0, - SCHARS (string), SBYTES (string), Qnil); - Vlast_coding_system_used = CODING_ID_NAME (coding.id); +static Lisp_Object +coding_from_cp (UINT codepage) +{ + char buffer[30]; + sprintf (buffer, "cp%d-dos", (int) codepage); + return intern (buffer); + /* We don't need to check that this coding system exists right here, + because that is done when the coding system is actually + instantiated, i.e. it is passed through Fcheck_coding_system() + there. */ +} - /* If clipboard sequence numbers are not supported, keep a copy for - later comparison. */ - if (!clipboard_sequence_fn) - { - /* Stash away the data we are about to put into the - clipboard, so we could later check inside - Fw32_get_clipboard_data whether the clipboard still - holds our data. */ - if (clipboard_storage_size < coding.produced) - { - clipboard_storage_size = coding.produced + 100; - last_clipboard_text = (char *) xrealloc (last_clipboard_text, - clipboard_storage_size); - } - if (last_clipboard_text) - memcpy (last_clipboard_text, coding.destination, - coding.produced); - } - GlobalUnlock (htext); +DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, + Sw32_set_clipboard_data, 1, 2, 0, + doc: /* This sets the clipboard data to the given text. */) + (string, ignored) + Lisp_Object string, ignored; +{ + BOOL ok = TRUE; + int nbytes; + unsigned char *src; + unsigned char *dst; + unsigned char *end; - /* Shrink data block to actual size. */ - htext2 = GlobalReAlloc (htext, coding.produced, - GMEM_MOVEABLE | GMEM_DDESHARE); - if (htext2 != NULL) htext = htext2; - } - } + /* This parameter used to be the current frame, but we don't use + that any more. */ + (void) ignored; - if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) + CHECK_STRING (string); + + setup_config (); + + current_text = string; + current_coding_system = cfg_coding_system; + current_clipboard_type = cfg_clipboard_type; + current_lcid = cfg_lcid; + current_num_nls = 0; + current_requires_encoding = 0; + + BLOCK_INPUT; + + /* Check for non-ASCII characters. While we are at it, count the + number of LFs, so we know how many CRs we will have to add later + (just in the case where we can use our internal ASCII rendering, + see code and comment in convert_to_handle_as_ascii() above). */ + nbytes = SBYTES (string); + src = SDATA (string); + + for (dst = src, end = src+nbytes; dst < end; dst++) + { + if (*dst == '\n') + current_num_nls++; + else if (*dst >= 0x80 || *dst == 0) + { + current_requires_encoding = 1; + break; + } + } + + if (!current_requires_encoding) + { + /* If all we have is ASCII we don't need to pretend we offer + anything fancy. */ + current_coding_system = Qraw_text; + current_clipboard_type = CF_TEXT; + current_lcid = LOCALE_NEUTRAL; + } + + if (!OpenClipboard (clipboard_owner)) goto error; - ok = EmptyClipboard () && SetClipboardData (CF_TEXT, htext); + ++modifying_clipboard; + ok = EmptyClipboard (); + --modifying_clipboard; + + /* If we have something non-ASCII we may want to set a locale. We + do that directly (non-delayed), as it's just a small bit. */ + if (ok) + ok = !NILP(render_locale()); + + if (ok) + { + if (clipboard_owner == NULL) + { + /* If for some reason we don't have a clipboard_owner, we + just set the text format as chosen by the configuration + and than forget about the whole thing. */ + ok = !NILP(render (make_number (current_clipboard_type))); + current_text = Qnil; + current_coding_system = Qnil; + } + else + { + /* Advertise all supported formats so that whatever the + requester chooses, only one encoding step needs to be + made. This is intentionally different from what we do in + the handler for WM_RENDERALLFORMATS. */ + SetClipboardData (CF_UNICODETEXT, NULL); + SetClipboardData (CF_TEXT, NULL); + SetClipboardData (CF_OEMTEXT, NULL); + } + } CloseClipboard (); - /* Common sense says to read the sequence number inside the - OpenClipboard/ CloseClipboard block to avoid race conditions - where another app puts something on the clipboard straight after - us. But experience suggests that the sequence number from the - SetClipboardData is not allocated until we close the clipboard! - Since clipboard operations are normally user-driven, the race - condition is probably not going to really happen. */ - if (clipboard_sequence_fn) - last_clipboard_sequence_number = clipboard_sequence_fn (); + /* With delayed rendering we haven't really "used" this coding + system yet, and it's even unclear if we ever will. But this is a + way to tell the upper level what we *would* use under ideal + circumstances. + + We don't signal the actually used coding-system later when we + finally render, because that can happen at any time and we don't + want to disturb the "foreground" action. */ + if (ok) + Vlast_coding_system_used = current_coding_system; + + Vnext_selection_coding_system = Qnil; if (ok) goto done; error: ok = FALSE; - if (htext) GlobalFree (htext); - if (last_clipboard_text) - *last_clipboard_text = '\0'; - - last_clipboard_sequence_number = 0; + current_text = Qnil; + current_coding_system = Qnil; done: UNBLOCK_INPUT; @@ -280,24 +763,52 @@ DEFUN ("w32-set-clipboard-data", Fw32_set_clipboard_data, return (ok ? string : Qnil); } + DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, Sw32_get_clipboard_data, 0, 1, 0, doc: /* This gets the clipboard data in text format. */) - (frame) - Lisp_Object frame; + (ignored) + Lisp_Object ignored; { - HANDLE htext; + HGLOBAL htext; Lisp_Object ret = Qnil; + UINT actual_clipboard_type; + int use_configured_coding_system = 1; + + /* This parameter used to be the current frame, but we don't use + that any more. */ + (void) ignored; - if (!NILP (frame)) - CHECK_LIVE_FRAME (frame); + /* Don't pass our own text from the clipboard (which might be + troublesome if the killed text includes null characters). */ + if (!NILP (current_text)) + return ret; + + setup_config (); + actual_clipboard_type = cfg_clipboard_type; BLOCK_INPUT; - if (!OpenClipboard ((!NILP (frame) && FRAME_W32_P (XFRAME (frame))) ? FRAME_W32_WINDOW (XFRAME (frame)) : NULL)) + if (!OpenClipboard (clipboard_owner)) goto done; - if ((htext = GetClipboardData (CF_TEXT)) == NULL) + if ((htext = GetClipboardData (actual_clipboard_type)) == NULL) + { + /* If we want CF_UNICODETEXT but can't get it, the current + coding system is useless. OTOH we can still try and decode + CF_TEXT based on the locale that the system gives us and that + we get down below. */ + if (actual_clipboard_type == CF_UNICODETEXT) + { + htext = GetClipboardData (CF_TEXT); + if (htext != NULL) + { + actual_clipboard_type = CF_TEXT; + use_configured_coding_system = 0; + } + } + } + if (htext == NULL) goto closeclip; { @@ -310,51 +821,105 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, if ((src = (unsigned char *) GlobalLock (htext)) == NULL) goto closeclip; - nbytes = strlen (src); - - /* If the text in clipboard is identical to what we put there - last time w32_set_clipboard_data was called, pretend there's no - data in the clipboard. This is so we don't pass our own text - from the clipboard (which might be troublesome if the killed - text includes null characters). */ - if ((clipboard_sequence_fn - && clipboard_sequence_fn () == last_clipboard_sequence_number) - || (last_clipboard_text - && clipboard_storage_size >= nbytes - && memcmp(last_clipboard_text, src, nbytes) == 0)) - goto closeclip; + /* If the clipboard data contains any non-ascii code, we need to + decode it with a coding system. */ + if (actual_clipboard_type == CF_UNICODETEXT) + { + nbytes = lstrlenW ((WCHAR *)src) * 2; + require_decoding = 1; + } + else + { + int i; - { - /* If the clipboard data contains any non-ascii code, we - need to decode it. */ - int i; + nbytes = strlen (src); - for (i = 0; i < nbytes; i++) - { - if (src[i] >= 0x80) - { - require_decoding = 1; - break; - } - } - } + for (i = 0; i < nbytes; i++) + { + if (src[i] >= 0x80) + { + require_decoding = 1; + break; + } + } + } if (require_decoding) { struct coding_system coding; + Lisp_Object coding_system = Qnil; + + /* `next-selection-coding-system' should override everything, + even when the locale passed by the system disagrees. The + only exception is when `next-selection-coding-system' + requested CF_UNICODETEXT and we couldn't get that. */ + if (use_configured_coding_system + && !NILP (Vnext_selection_coding_system)) + coding_system = Vnext_selection_coding_system; + + /* If we have CF_TEXT or CF_OEMTEXT, we want to check out + CF_LOCALE, too. */ + else if (actual_clipboard_type != CF_UNICODETEXT) + { + HGLOBAL hlocale; + LCID lcid = DEFAULT_LCID; + UINT cp; + + /* Documentation says that the OS always generates + CF_LOCALE info automatically, so the locale handle + should always be present. Fact is that this is not + always true on 9x ;-(. */ + hlocale = GetClipboardData (CF_LOCALE); + if (hlocale != NULL) + { + const LCID * lcid_ptr; + lcid_ptr = (const LCID *) GlobalLock (hlocale); + if (lcid_ptr != NULL) + { + lcid = *lcid_ptr; + GlobalUnlock (hlocale); + } + + /* 9x has garbage as the sort order (to be exact there + is another instance of the language id in the upper + word). We don't care about sort order anyway, so + we just filter out the unneeded mis-information to + avoid irritations. */ + lcid = MAKELCID (LANGIDFROMLCID (lcid), SORT_DEFAULT); + } + + /* If we are using fallback from CF_UNICODETEXT, we can't + use the configured coding system. Also we don't want + to use it, if the system has supplied us with a locale + and it is not just the system default. */ + if (!use_configured_coding_system || lcid != DEFAULT_LCID) + { + cp = cp_from_locale (lcid, actual_clipboard_type); + /* If it's just our current standard setting anyway, + use the coding system that the user has selected. + Otherwise create a new spec to match the locale + that was specified by the other side or the + system. */ + if (!use_configured_coding_system || cp != cfg_codepage) + coding_system = coding_from_cp (cp); + } + } + + if (NILP (coding_system)) + coding_system = Vselection_coding_system; + Vnext_selection_coding_system = Qnil; - if (NILP (Vnext_selection_coding_system)) - Vnext_selection_coding_system = Vselection_coding_system; - setup_coding_system - (Fcheck_coding_system (Vnext_selection_coding_system), &coding); + setup_coding_system (Fcheck_coding_system (coding_system), &coding); coding.src_multibyte = 0; coding.dst_multibyte = 1; - Vnext_selection_coding_system = Qnil; coding.mode |= CODING_MODE_LAST_BLOCK; /* We explicitly disable composition handling because selection data should not contain any composition sequence. */ coding.common_flags &= ~CODING_ANNOTATION_MASK; + /* Force DOS line-ends. */ + coding.eol_type = CODING_EOL_CRLF; + coding.dst_bytes = nbytes * 2; coding.destination = (unsigned char *) xmalloc (coding.dst_bytes); decode_coding_c_string (&coding, src, nbytes, Qnil); @@ -365,10 +930,13 @@ DEFUN ("w32-get-clipboard-data", Fw32_get_clipboard_data, } else { - /* Need to know final size after CR chars are removed because we - can't change the string size manually, and doing an extra - copy is silly. Note that we only remove CR when it appears - as part of CRLF. */ + /* FIXME: We may want to repeat the code in this branch for + the Unicode case. */ + + /* Need to know final size after CR chars are removed because + we can't change the string size manually, and doing an + extra copy is silly. We only remove CR when it appears as + part of CRLF. */ truelen = nbytes; dst = src; @@ -445,9 +1013,14 @@ and t is the same as `SECONDARY'. */) if (OpenClipboard (NULL)) { - int format = 0; - while (format = EnumClipboardFormats (format)) - if (format == CF_TEXT) + UINT format = 0; + setup_config (); + while ((format = EnumClipboardFormats (format))) + /* Check CF_TEXT in addition to cfg_clipboard_type, + because we can fall back on that if CF_UNICODETEXT is + not available. Actually a check for CF_TEXT only + should be enough. */ + if (format == cfg_clipboard_type || format == CF_TEXT) { val = Qt; break; @@ -459,24 +1032,25 @@ and t is the same as `SECONDARY'. */) return Qnil; } +/* One-time init. Called in the un-dumped Emacs, but not in the + dumped version. */ + void syms_of_w32select () { -#if 0 - defsubr (&Sw32_open_clipboard); - defsubr (&Sw32_empty_clipboard); - defsubr (&Sw32_close_clipboard); -#endif defsubr (&Sw32_set_clipboard_data); defsubr (&Sw32_get_clipboard_data); defsubr (&Sx_selection_exists_p); DEFVAR_LISP ("selection-coding-system", &Vselection_coding_system, doc: /* Coding system for communicating with other programs. -When sending or receiving text via cut_buffer, selection, and clipboard, -the text is encoded or decoded by this coding system. -The default value is `iso-latin-1-dos'. */); - Vselection_coding_system = intern ("iso-latin-1-dos"); +When sending or receiving text via cut_buffer, selection, and +clipboard, the text is encoded or decoded by this coding system. +The default value is the current system default encoding on 9x/Me and +`utf-16le-dos' (Unicode) on NT/W2K/XP. */); + /* The actual value is set dynamically in the dumped Emacs, see + below. */ + Vselection_coding_system = Qnil; DEFVAR_LISP ("next-selection-coding-system", &Vnext_selection_coding_system, doc: /* Coding system for the next communication with other programs. @@ -487,6 +1061,41 @@ set to nil. */); Vnext_selection_coding_system = Qnil; QCLIPBOARD = intern ("CLIPBOARD"); staticpro (&QCLIPBOARD); + + cfg_coding_system = Qnil; staticpro (&cfg_coding_system); + current_text = Qnil; staticpro (¤t_text); + current_coding_system = Qnil; staticpro (¤t_coding_system); + + QUNICODE = intern ("utf-16le-dos"); staticpro (&QUNICODE); + QANSICP = Qnil; staticpro (&QANSICP); + QOEMCP = Qnil; staticpro (&QOEMCP); +} + +/* One-time init. Called in the dumped Emacs, but not in the + un-dumped version. */ + +void +globals_of_w32select () +{ + DEFAULT_LCID = GetUserDefaultLCID (); + /* Drop the sort order from the LCID, so we can compare this with + CF_LOCALE objects that have the same fix on 9x. */ + DEFAULT_LCID = MAKELCID (LANGIDFROMLCID (DEFAULT_LCID), SORT_DEFAULT); + + ANSICP = GetACP (); + OEMCP = GetOEMCP (); + + QANSICP = coding_from_cp (ANSICP); + QOEMCP = coding_from_cp (OEMCP); + + if (os_subtype == OS_NT) + Vselection_coding_system = QUNICODE; + else if (inhibit_window_system) + Vselection_coding_system = QOEMCP; + else + Vselection_coding_system = QANSICP; + + clipboard_owner = create_owner (); } /* arch-tag: c96e9724-5eb1-4dad-be07-289f092fd2af diff --git a/src/xdisp.c b/src/xdisp.c index a90483aae1e..9aefcf5c9a5 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -830,7 +830,6 @@ static char *decode_mode_spec_coding P_ ((Lisp_Object, char *, int)); static int invisible_text_between_p P_ ((struct it *, int, int)); #endif -static int next_element_from_ellipsis P_ ((struct it *)); static void pint2str P_ ((char *, int, int)); static void pint2hrstr P_ ((char *, int, int)); static struct text_pos run_window_scroll_functions P_ ((Lisp_Object, @@ -905,6 +904,7 @@ static void reseat_1 P_ ((struct it *, struct text_pos, int)); static void back_to_previous_visible_line_start P_ ((struct it *)); void reseat_at_previous_visible_line_start P_ ((struct it *)); static void reseat_at_next_visible_line_start P_ ((struct it *, int)); +static int next_element_from_ellipsis P_ ((struct it *)); static int next_element_from_display_vector P_ ((struct it *)); static int next_element_from_string P_ ((struct it *)); static int next_element_from_c_string P_ ((struct it *)); @@ -2046,7 +2046,7 @@ static void check_it (it) struct it *it; { - if (it->method == next_element_from_string) + if (it->method == GET_FROM_STRING) { xassert (STRINGP (it->string)); xassert (IT_STRING_CHARPOS (*it) >= 0); @@ -2054,7 +2054,7 @@ check_it (it) else { xassert (IT_STRING_CHARPOS (*it) < 0); - if (it->method == next_element_from_buffer) + if (it->method == GET_FROM_BUFFER) { /* Check that character and byte positions agree. */ xassert (IT_CHARPOS (*it) == BYTE_TO_CHAR (IT_BYTEPOS (*it))); @@ -2564,7 +2564,7 @@ init_from_display_pos (it, w, pos) property for an image, the iterator will be set up for that image, and we have to undo that setup first before we can correct the overlay string index. */ - if (it->method == next_element_from_image) + if (it->method == GET_FROM_IMAGE) pop_it (it); /* We already have the first chunk of overlay strings in @@ -2587,7 +2587,7 @@ init_from_display_pos (it, w, pos) it->string = it->overlay_strings[relative_index]; xassert (STRINGP (it->string)); it->current.string_pos = pos->string_pos; - it->method = next_element_from_string; + it->method = GET_FROM_STRING; } #if 0 /* This is bogus because POS not having an overlay string @@ -2603,7 +2603,7 @@ init_from_display_pos (it, w, pos) while (it->sp) pop_it (it); it->current.overlay_string_index = -1; - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; if (CHARPOS (pos->pos) == ZV) it->overlay_strings_at_end_processed_p = 1; } @@ -2717,7 +2717,7 @@ handle_stop (it) { /* Don't check for overlay strings below when set to deliver characters from a display vector. */ - if (it->method == next_element_from_display_vector) + if (it->method == GET_FROM_DISPLAY_VECTOR) handle_overlay_change_p = 0; /* Handle overlay changes. */ @@ -3375,7 +3375,7 @@ setup_for_ellipsis (it, len) /* Remember the current face id in case glyphs specify faces. IT's face is restored in set_iterator_to_next. */ it->saved_face_id = it->face_id; - it->method = next_element_from_display_vector; + it->method = GET_FROM_DISPLAY_VECTOR; it->ellipsis_p = 1; } @@ -3740,7 +3740,7 @@ handle_single_display_spec (it, spec, object, position, it->image_id = -1; /* no image */ it->position = start_pos; it->object = NILP (object) ? it->w->buffer : object; - it->method = next_element_from_image; + it->method = GET_FROM_IMAGE; it->face_id = face_id; /* Say that we haven't consumed the characters with @@ -3823,7 +3823,7 @@ handle_single_display_spec (it, spec, object, position, it->current.overlay_string_index = -1; IT_STRING_CHARPOS (*it) = IT_STRING_BYTEPOS (*it) = 0; it->end_charpos = it->string_nchars = SCHARS (it->string); - it->method = next_element_from_string; + it->method = GET_FROM_STRING; it->stop_charpos = 0; it->string_from_display_prop_p = 1; /* Say that we haven't consumed the characters with @@ -3833,7 +3833,7 @@ handle_single_display_spec (it, spec, object, position, } else if (CONSP (value) && EQ (XCAR (value), Qspace)) { - it->method = next_element_from_stretch; + it->method = GET_FROM_STRETCH; it->object = value; it->current.pos = it->position = start_pos; } @@ -3844,7 +3844,7 @@ handle_single_display_spec (it, spec, object, position, it->image_id = lookup_image (it->f, value); it->position = start_pos; it->object = NILP (object) ? it->w->buffer : object; - it->method = next_element_from_image; + it->method = GET_FROM_IMAGE; /* Say that we haven't consumed the characters with `display' property yet. The call to pop_it in @@ -4193,7 +4193,7 @@ handle_composition_prop (it) if (id >= 0) { - it->method = next_element_from_composition; + it->method = GET_FROM_COMPOSITION; it->cmp_id = id; it->cmp_len = COMPOSITION_LENGTH (prop); /* For a terminal, draw only the first character of the @@ -4268,7 +4268,7 @@ next_overlay_string (it) it->current.overlay_string_index = -1; SET_TEXT_POS (it->current.string_pos, -1, -1); it->n_overlay_strings = 0; - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; /* If we're at the end of the buffer, record that we have processed the overlay strings there already, so that @@ -4297,7 +4297,7 @@ next_overlay_string (it) it->string = it->overlay_strings[i]; it->multibyte_p = STRING_MULTIBYTE (it->string); SET_TEXT_POS (it->current.string_pos, 0, 0); - it->method = next_element_from_string; + it->method = GET_FROM_STRING; it->stop_charpos = 0; } @@ -4562,13 +4562,13 @@ get_overlay_strings (it, charpos) xassert (STRINGP (it->string)); it->end_charpos = SCHARS (it->string); it->multibyte_p = STRING_MULTIBYTE (it->string); - it->method = next_element_from_string; + it->method = GET_FROM_STRING; } else { it->string = Qnil; it->current.overlay_string_index = -1; - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; } CHECK_IT (it); @@ -4946,7 +4946,7 @@ reseat_1 (it, pos, set_stop_p) IT_STRING_CHARPOS (*it) = -1; IT_STRING_BYTEPOS (*it) = -1; it->string = Qnil; - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; /* RMS: I added this to fix a bug in move_it_vertically_backward where it->area continued to relate to the starting point for the backward motion. Bug report from @@ -5012,7 +5012,7 @@ reseat_to_string (it, s, string, charpos, precision, field_width, multibyte) it->string = string; it->s = NULL; it->end_charpos = it->string_nchars = SCHARS (string); - it->method = next_element_from_string; + it->method = GET_FROM_STRING; it->current.string_pos = string_pos (charpos, string); } else @@ -5034,7 +5034,7 @@ reseat_to_string (it, s, string, charpos, precision, field_width, multibyte) it->end_charpos = it->string_nchars = strlen (s); } - it->method = next_element_from_c_string; + it->method = GET_FROM_C_STRING; } /* PRECISION > 0 means don't return more than PRECISION characters @@ -5065,6 +5065,20 @@ reseat_to_string (it, s, string, charpos, precision, field_width, multibyte) Iteration ***********************************************************************/ +/* Map enum it_method value to corresponding next_element_from_* function. */ + +static int (* get_next_element[NUM_IT_METHODS]) P_ ((struct it *it)) = +{ + next_element_from_buffer, + next_element_from_display_vector, + next_element_from_composition, + next_element_from_string, + next_element_from_c_string, + next_element_from_image, + next_element_from_stretch +}; + + /* Load IT's display element fields with information about the next display element from the current position of IT. Value is zero if end of buffer (or C string) is reached. */ @@ -5080,7 +5094,7 @@ get_next_display_element (it) int success_p; get_next: - success_p = (*it->method) (it); + success_p = (*get_next_element[it->method]) (it); if (it->what == IT_CHARACTER) { @@ -5114,7 +5128,7 @@ get_next_display_element (it) it->current.dpvec_index = 0; it->dpvec_face_id = -1; it->saved_face_id = it->face_id; - it->method = next_element_from_display_vector; + it->method = GET_FROM_DISPLAY_VECTOR; it->ellipsis_p = 0; } else @@ -5139,7 +5153,7 @@ get_next_display_element (it) else if ((it->c < ' ' ? (it->area != TEXT_AREA /* In mode line, treat \n, \t like other crl chars. */ - || (it->c != '\n' + || (it->c != '\t' && it->glyph_row && it->glyph_row->mode_line_p) || (it->c != '\n' && it->c != '\t')) : (it->multibyte_p @@ -5274,7 +5288,7 @@ get_next_display_element (it) it->current.dpvec_index = 0; it->dpvec_face_id = face_id; it->saved_face_id = it->face_id; - it->method = next_element_from_display_vector; + it->method = GET_FROM_DISPLAY_VECTOR; it->ellipsis_p = 0; goto get_next; } @@ -5340,8 +5354,9 @@ set_iterator_to_next (it, reseat_p) moving the iterator to a new position might set them. */ it->start_of_box_run_p = it->end_of_box_run_p = 0; - if (it->method == next_element_from_buffer) + switch (it->method) { + case GET_FROM_BUFFER: /* The current display element of IT is a character from current_buffer. Advance in the buffer, and maybe skip over invisible lines that are so because of selective display. */ @@ -5354,32 +5369,32 @@ set_iterator_to_next (it, reseat_p) IT_CHARPOS (*it) += 1; xassert (IT_BYTEPOS (*it) == CHAR_TO_BYTE (IT_CHARPOS (*it))); } - } - else if (it->method == next_element_from_composition) - { - xassert (it->cmp_id >= 0 && it ->cmp_id < n_compositions); + break; + + case GET_FROM_COMPOSITION: + xassert (it->cmp_id >= 0 && it->cmp_id < n_compositions); if (STRINGP (it->string)) { IT_STRING_BYTEPOS (*it) += it->len; IT_STRING_CHARPOS (*it) += it->cmp_len; - it->method = next_element_from_string; + it->method = GET_FROM_STRING; goto consider_string_end; } else { IT_BYTEPOS (*it) += it->len; IT_CHARPOS (*it) += it->cmp_len; - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; } - } - else if (it->method == next_element_from_c_string) - { + break; + + case GET_FROM_C_STRING: /* Current display element of IT is from a C string. */ IT_BYTEPOS (*it) += it->len; IT_CHARPOS (*it) += 1; - } - else if (it->method == next_element_from_display_vector) - { + break; + + case GET_FROM_DISPLAY_VECTOR: /* Current display element of IT is from a display table entry. Advance in the display table definition. Reset it to null if end reached, and continue with characters from buffers/ @@ -5393,11 +5408,11 @@ set_iterator_to_next (it, reseat_p) if (it->dpvec + it->current.dpvec_index == it->dpend) { if (it->s) - it->method = next_element_from_c_string; + it->method = GET_FROM_C_STRING; else if (STRINGP (it->string)) - it->method = next_element_from_string; + it->method = GET_FROM_STRING; else - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; it->dpvec = NULL; it->current.dpvec_index = -1; @@ -5414,9 +5429,9 @@ set_iterator_to_next (it, reseat_p) /* Recheck faces after display vector */ it->stop_charpos = IT_CHARPOS (*it); } - } - else if (it->method == next_element_from_string) - { + break; + + case GET_FROM_STRING: /* Current display element is a character from a Lisp string. */ xassert (it->s == NULL && STRINGP (it->string)); IT_STRING_BYTEPOS (*it) += it->len; @@ -5441,34 +5456,35 @@ set_iterator_to_next (it, reseat_p) && it->sp > 0) { pop_it (it); - if (!STRINGP (it->string)) - it->method = next_element_from_buffer; - else + if (STRINGP (it->string)) goto consider_string_end; + it->method = GET_FROM_BUFFER; } } - } - else if (it->method == next_element_from_image - || it->method == next_element_from_stretch) - { + break; + + case GET_FROM_IMAGE: + case GET_FROM_STRETCH: /* The position etc with which we have to proceed are on the stack. The position may be at the end of a string, if the `display' property takes up the whole string. */ + xassert (it->sp > 0); pop_it (it); it->image_id = 0; if (STRINGP (it->string)) { - it->method = next_element_from_string; + it->method = GET_FROM_STRING; goto consider_string_end; } - else - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; + break; + + default: + /* There are no other methods defined, so this should be a bug. */ + abort (); } - else - /* There are no other methods defined, so this should be a bug. */ - abort (); - xassert (it->method != next_element_from_string + xassert (it->method != GET_FROM_STRING || (STRINGP (it->string) && IT_STRING_CHARPOS (*it) >= 0)); } @@ -5680,7 +5696,7 @@ next_element_from_ellipsis (it) was in IT->saved_face_id, and signal that it's there by setting face_before_selective_p. */ it->saved_face_id = it->face_id; - it->method = next_element_from_buffer; + it->method = GET_FROM_BUFFER; reseat_at_next_visible_line_start (it, 1); it->face_before_selective_p = 1; } @@ -5921,11 +5937,14 @@ move_it_in_display_line_to (it, to_charpos, to_x, op) saved_glyph_row = it->glyph_row; it->glyph_row = NULL; -#define BUFFER_POS_REACHED_P() \ - ((op & MOVE_TO_POS) != 0 \ - && BUFFERP (it->object) \ - && IT_CHARPOS (*it) >= to_charpos \ - && it->method == next_element_from_buffer) +#define BUFFER_POS_REACHED_P() \ + ((op & MOVE_TO_POS) != 0 \ + && BUFFERP (it->object) \ + && IT_CHARPOS (*it) >= to_charpos \ + && (it->method == GET_FROM_BUFFER || \ + (it->method == GET_FROM_DISPLAY_VECTOR && \ + it->dpvec + it->current.dpvec_index + 1 >= it->dpend))) + while (1) { @@ -6616,7 +6635,7 @@ int in_display_vector_p (it) struct it *it; { - return (it->method == next_element_from_display_vector + return (it->method == GET_FROM_DISPLAY_VECTOR && it->current.dpvec_index > 0 && it->dpvec + it->current.dpvec_index != it->dpend); } @@ -15348,7 +15367,7 @@ display_line (it) /* Record whether this row ends inside an ellipsis. */ row->ends_in_ellipsis_p - = (it->method == next_element_from_display_vector + = (it->method == GET_FROM_DISPLAY_VECTOR && it->ellipsis_p); /* Save fringe bitmaps in this row. */ diff --git a/src/xfns.c b/src/xfns.c index d1edf554feb..8267709767f 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -1860,7 +1860,8 @@ hack_wm_protocols (f, widget) BLOCK_INPUT; { - Atom type, *atoms = 0; + Atom type; + unsigned char *catoms; int format = 0; unsigned long nitems = 0; unsigned long bytes_after; @@ -1869,20 +1870,27 @@ hack_wm_protocols (f, widget) FRAME_X_DISPLAY_INFO (f)->Xatom_wm_protocols, (long)0, (long)100, False, XA_ATOM, &type, &format, &nitems, &bytes_after, - (unsigned char **) &atoms) + &catoms) == Success) && format == 32 && type == XA_ATOM) - while (nitems > 0) - { - nitems--; - if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window) - need_delete = 0; - else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus) - need_focus = 0; - else if (atoms[nitems] == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself) - need_save = 0; - } - if (atoms) XFree ((char *) atoms); + { + Atom *atoms = (Atom *) catoms; + while (nitems > 0) + { + nitems--; + if (atoms[nitems] + == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_delete_window) + need_delete = 0; + else if (atoms[nitems] + == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_take_focus) + need_focus = 0; + else if (atoms[nitems] + == FRAME_X_DISPLAY_INFO (f)->Xatom_wm_save_yourself) + need_save = 0; + } + } + if (catoms) + XFree (catoms); } { Atom props [10]; @@ -4140,7 +4148,7 @@ no value of TYPE. */) Atom prop_atom; int rc; Lisp_Object prop_value = Qnil; - char *tmp_data = NULL; + unsigned char *tmp_data = NULL; Atom actual_type; Atom target_type = XA_STRING; int actual_format; @@ -4180,7 +4188,7 @@ no value of TYPE. */) rc = XGetWindowProperty (FRAME_X_DISPLAY (f), target_window, prop_atom, 0, 0, False, target_type, &actual_type, &actual_format, &actual_size, - &bytes_remaining, (unsigned char **) &tmp_data); + &bytes_remaining, &tmp_data); if (rc == Success) { int size = bytes_remaining; @@ -4193,7 +4201,7 @@ no value of TYPE. */) ! NILP (delete_p), target_type, &actual_type, &actual_format, &actual_size, &bytes_remaining, - (unsigned char **) &tmp_data); + &tmp_data); if (rc == Success && tmp_data) { /* The man page for XGetWindowProperty says: @@ -4217,14 +4225,14 @@ no value of TYPE. */) long *ldata = (long *) tmp_data; for (i = 0; i < actual_size; ++i) - idata[i]= (int) ldata[i]; + idata[i] = (int) ldata[i]; } if (NILP (vector_ret_p)) prop_value = make_string (tmp_data, size); else prop_value = x_property_data_to_lisp (f, - (unsigned char *) tmp_data, + tmp_data, actual_type, actual_format, actual_size); diff --git a/src/xselect.c b/src/xselect.c index bf37cde4d0b..a49b6b89ee4 100644 --- a/src/xselect.c +++ b/src/xselect.c @@ -1908,7 +1908,12 @@ lisp_data_to_selection_data (display, obj, } else if (STRINGP (obj)) { - xassert (! STRING_MULTIBYTE (obj)); + if (SCHARS (obj) < SBYTES (obj)) + /* OBJ is a multibyte string containing a non-ASCII char. */ + Fsignal (Qerror, /* Qselection_error */ + Fcons (build_string + ("Non-ASCII string must be encoded in advance"), + Fcons (obj, Qnil))); if (NILP (type)) type = QSTRING; *format_ret = 8; @@ -2184,7 +2189,10 @@ Disowning it means there is no such selection. */) { Time timestamp; Atom selection_atom; - struct selection_input_event event; + union { + struct selection_input_event sie; + struct input_event ie; + } event; Display *display; struct x_display_info *dpyinfo; struct frame *sf = SELECTED_FRAME (); @@ -2212,10 +2220,10 @@ Disowning it means there is no such selection. */) the selection owner to None. The NCD server does, the MIT Sun4 server doesn't. So we synthesize one; this means we might get two, but that's ok, because the second one won't have any effect. */ - SELECTION_EVENT_DISPLAY (&event) = display; - SELECTION_EVENT_SELECTION (&event) = selection_atom; - SELECTION_EVENT_TIME (&event) = timestamp; - x_handle_selection_clear ((struct input_event *) &event); + SELECTION_EVENT_DISPLAY (&event.sie) = display; + SELECTION_EVENT_SELECTION (&event.sie) = selection_atom; + SELECTION_EVENT_TIME (&event.sie) = timestamp; + x_handle_selection_clear (&event.ie); return Qt; } diff --git a/src/xterm.c b/src/xterm.c index 137e0d2ae9e..3b6d2e18ac6 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -5625,8 +5625,8 @@ static struct x_display_info *next_noop_dpyinfo; f->output_data.x->saved_menu_event \ = (XEvent *) xmalloc (sizeof (XEvent)); \ bcopy (&event, f->output_data.x->saved_menu_event, size); \ - inev.kind = MENU_BAR_ACTIVATE_EVENT; \ - XSETFRAME (inev.frame_or_window, f); \ + inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \ + XSETFRAME (inev.ie.frame_or_window, f); \ } \ while (0) @@ -5733,7 +5733,10 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) int *finish; struct input_event *hold_quit; { - struct input_event inev; + union { + struct input_event ie; + struct selection_input_event sie; + } inev; int count = 0; int do_help = 0; int nbytes = 0; @@ -5743,9 +5746,9 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) *finish = X_EVENT_NORMAL; - EVENT_INIT (inev); - inev.kind = NO_EVENT; - inev.arg = Qnil; + EVENT_INIT (inev.ie); + inev.ie.kind = NO_EVENT; + inev.ie.arg = Qnil; switch (event.type) { @@ -5843,8 +5846,8 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) if (!f) goto OTHER; /* May be a dialog that is to be removed */ - inev.kind = DELETE_WINDOW_EVENT; - XSETFRAME (inev.frame_or_window, f); + inev.ie.kind = DELETE_WINDOW_EVENT; + XSETFRAME (inev.ie.frame_or_window, f); goto done; } @@ -5907,7 +5910,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) if (event.xclient.message_type == dpyinfo->Xatom_Scrollbar) { - x_scroll_bar_to_input_event (&event, &inev); + x_scroll_bar_to_input_event (&event, &inev.ie); *finish = X_EVENT_GOTO_OUT; goto done; } @@ -5918,7 +5921,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) if (!f) goto OTHER; - if (x_handle_dnd_message (f, &event.xclient, dpyinfo, &inev)) + if (x_handle_dnd_message (f, &event.xclient, dpyinfo, &inev.ie)) *finish = X_EVENT_DROP; } break; @@ -5939,11 +5942,11 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) { XSelectionClearEvent *eventp = (XSelectionClearEvent *) &event; - inev.kind = SELECTION_CLEAR_EVENT; - SELECTION_EVENT_DISPLAY (&inev) = eventp->display; - SELECTION_EVENT_SELECTION (&inev) = eventp->selection; - SELECTION_EVENT_TIME (&inev) = eventp->time; - inev.frame_or_window = Qnil; + inev.ie.kind = SELECTION_CLEAR_EVENT; + SELECTION_EVENT_DISPLAY (&inev.sie) = eventp->display; + SELECTION_EVENT_SELECTION (&inev.sie) = eventp->selection; + SELECTION_EVENT_TIME (&inev.sie) = eventp->time; + inev.ie.frame_or_window = Qnil; } break; @@ -5956,14 +5959,14 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) XSelectionRequestEvent *eventp = (XSelectionRequestEvent *) &event; - inev.kind = SELECTION_REQUEST_EVENT; - SELECTION_EVENT_DISPLAY (&inev) = eventp->display; - SELECTION_EVENT_REQUESTOR (&inev) = eventp->requestor; - SELECTION_EVENT_SELECTION (&inev) = eventp->selection; - SELECTION_EVENT_TARGET (&inev) = eventp->target; - SELECTION_EVENT_PROPERTY (&inev) = eventp->property; - SELECTION_EVENT_TIME (&inev) = eventp->time; - inev.frame_or_window = Qnil; + inev.ie.kind = SELECTION_REQUEST_EVENT; + SELECTION_EVENT_DISPLAY (&inev.sie) = eventp->display; + SELECTION_EVENT_REQUESTOR (&inev.sie) = eventp->requestor; + SELECTION_EVENT_SELECTION (&inev.sie) = eventp->selection; + SELECTION_EVENT_TARGET (&inev.sie) = eventp->target; + SELECTION_EVENT_PROPERTY (&inev.sie) = eventp->property; + SELECTION_EVENT_TIME (&inev.sie) = eventp->time; + inev.ie.frame_or_window = Qnil; } break; @@ -6102,8 +6105,8 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) { f->async_iconified = 1; - inev.kind = ICONIFY_EVENT; - XSETFRAME (inev.frame_or_window, f); + inev.ie.kind = ICONIFY_EVENT; + XSETFRAME (inev.ie.frame_or_window, f); } } goto OTHER; @@ -6135,8 +6138,8 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) if (f->iconified) { - inev.kind = DEICONIFY_EVENT; - XSETFRAME (inev.frame_or_window, f); + inev.ie.kind = DEICONIFY_EVENT; + XSETFRAME (inev.ie.frame_or_window, f); } else if (! NILP (Vframe_list) && ! NILP (XCDR (Vframe_list))) @@ -6302,18 +6305,18 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) orig_keysym = keysym; /* Common for all keysym input events. */ - XSETFRAME (inev.frame_or_window, f); - inev.modifiers + XSETFRAME (inev.ie.frame_or_window, f); + inev.ie.modifiers = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), modifiers); - inev.timestamp = event.xkey.time; + inev.ie.timestamp = event.xkey.time; /* First deal with keysyms which have defined translations to characters. */ if (keysym >= 32 && keysym < 128) /* Avoid explicitly decoding each ASCII character. */ { - inev.kind = ASCII_KEYSTROKE_EVENT; - inev.code = keysym; + inev.ie.kind = ASCII_KEYSTROKE_EVENT; + inev.ie.code = keysym; goto done_keysym; } @@ -6323,10 +6326,10 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) Vx_keysym_table, Qnil)))) { - inev.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) - ? ASCII_KEYSTROKE_EVENT - : MULTIBYTE_CHAR_KEYSTROKE_EVENT); - inev.code = XFASTINT (c); + inev.ie.kind = (SINGLE_BYTE_CHAR_P (XFASTINT (c)) + ? ASCII_KEYSTROKE_EVENT + : MULTIBYTE_CHAR_KEYSTROKE_EVENT); + inev.ie.code = XFASTINT (c); goto done_keysym; } @@ -6416,8 +6419,8 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) STORE_KEYSYM_FOR_DEBUG (keysym); /* make_lispy_event will convert this to a symbolic key. */ - inev.kind = NON_ASCII_KEYSTROKE_EVENT; - inev.code = keysym; + inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT; + inev.ie.code = keysym; goto done_keysym; } @@ -6469,18 +6472,18 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) else c = STRING_CHAR_AND_LENGTH (copy_bufptr + i, nbytes - i, len); - inev.kind = (SINGLE_BYTE_CHAR_P (c) + inev.ie.kind = (SINGLE_BYTE_CHAR_P (c) ? ASCII_KEYSTROKE_EVENT : MULTIBYTE_CHAR_KEYSTROKE_EVENT); - inev.code = c; - kbd_buffer_store_event_hold (&inev, hold_quit); + inev.ie.code = c; + kbd_buffer_store_event_hold (&inev.ie, hold_quit); } /* Previous code updated count by nchars rather than nbytes, but that seems bogus to me. ++kfs */ count += nbytes; - inev.kind = NO_EVENT; /* Already stored above. */ + inev.ie.kind = NO_EVENT; /* Already stored above. */ if (keysym == NoSymbol) break; @@ -6507,7 +6510,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) #endif case EnterNotify: - x_detect_focus_change (dpyinfo, &event, &inev); + x_detect_focus_change (dpyinfo, &event, &inev.ie); f = x_any_window_to_frame (dpyinfo, event.xcrossing.window); @@ -6537,11 +6540,11 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) goto OTHER; case FocusIn: - x_detect_focus_change (dpyinfo, &event, &inev); + x_detect_focus_change (dpyinfo, &event, &inev.ie); goto OTHER; case LeaveNotify: - x_detect_focus_change (dpyinfo, &event, &inev); + x_detect_focus_change (dpyinfo, &event, &inev.ie); f = x_top_window_to_frame (dpyinfo, event.xcrossing.window); if (f) @@ -6564,7 +6567,7 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) goto OTHER; case FocusOut: - x_detect_focus_change (dpyinfo, &event, &inev); + x_detect_focus_change (dpyinfo, &event, &inev.ie); goto OTHER; case MotionNotify: @@ -6604,8 +6607,8 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) && !EQ (window, last_window) && !EQ (window, selected_window)) { - inev.kind = SELECT_WINDOW_EVENT; - inev.frame_or_window = window; + inev.ie.kind = SELECT_WINDOW_EVENT; + inev.ie.frame_or_window = window; } last_window=window; @@ -6764,13 +6767,13 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) && (int)(event.xbutton.time - ignore_next_mouse_click_timeout) > 0) { ignore_next_mouse_click_timeout = 0; - construct_mouse_click (&inev, &event, f); + construct_mouse_click (&inev.ie, &event, f); } if (event.type == ButtonRelease) ignore_next_mouse_click_timeout = 0; } else - construct_mouse_click (&inev, &event, f); + construct_mouse_click (&inev.ie, &event, f); } } } @@ -6785,12 +6788,12 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) scroll bars. */ if (bar && event.xbutton.state & ControlMask) { - x_scroll_bar_handle_click (bar, &event, &inev); + x_scroll_bar_handle_click (bar, &event, &inev.ie); *finish = X_EVENT_DROP; } #else /* not USE_TOOLKIT_SCROLL_BARS */ if (bar) - x_scroll_bar_handle_click (bar, &event, &inev); + x_scroll_bar_handle_click (bar, &event, &inev.ie); #endif /* not USE_TOOLKIT_SCROLL_BARS */ } @@ -6898,9 +6901,9 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) } done: - if (inev.kind != NO_EVENT) + if (inev.ie.kind != NO_EVENT) { - kbd_buffer_store_event_hold (&inev, hold_quit); + kbd_buffer_store_event_hold (&inev.ie, hold_quit); count++; } |