annotate src/clipboard.c @ 28925:46fa2d54e389 v8.2.4985

patch 8.2.4985: PVS warns for possible array underrun Commit: https://github.com/vim/vim/commit/875339b22a989d0782097036169e8fb9e2100d7e Author: Bram Moolenaar <Bram@vim.org> Date: Fri May 20 14:10:50 2022 +0100 patch 8.2.4985: PVS warns for possible array underrun Problem: PVS warns for possible array underrun. Solution: Add a check for a positive value. (closes https://github.com/vim/vim/issues/10451)
author Bram Moolenaar <Bram@vim.org>
date Fri, 20 May 2022 15:15:04 +0200
parents d770568e6c98
children 89e1d67814a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * clipboard.c: Functions to handle the clipboard
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #include "vim.h"
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16 #ifdef FEAT_CYGWIN_WIN32_CLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 # define WIN32_LEAN_AND_MEAN
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 # include <windows.h>
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 # include "winclip.pro"
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 // Functions for copying and pasting text between applications.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 // This is always included in a GUI version, but may also be included when the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 // clipboard and mouse is available to a terminal version such as xterm.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 // Note: there are some more functions in ops.c that handle selection stuff.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 //
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 // Also note that the majority of functions here deal with the X 'primary'
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 // (visible - for Visual mode use) selection, and only that. There are no
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 // versions of these for the 'clipboard' selection, as Visual mode has no use
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 // for them.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 #if defined(FEAT_CLIPBOARD) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 * Selection stuff using Visual mode, for cutting and pasting text to other
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 * windows.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 * Call this to initialise the clipboard. Pass it FALSE if the clipboard code
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 * is included, but the clipboard can not be used, or TRUE if the clipboard can
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 * be used. Eg unix may call this with FALSE, then call it again with TRUE if
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43 * the GUI starts.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 clip_init(int can_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 Clipboard_T *cb;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 cb = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 for (;;)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 cb->available = can_use;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 cb->owned = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 cb->start.lnum = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 cb->start.col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 cb->end.lnum = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 cb->end.col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 cb->state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 if (cb == &clip_plus)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 cb = &clip_plus;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68 * Check whether the VIsual area has changed, and if so try to become the owner
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 * of the selection, and free any old converted selection we may still have
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 * lying around. If the VIsual mode has ended, make a copy of what was
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 * selected so we can still give it to others. Will probably have to make sure
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 * this is called whenever VIsual mode is ended.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 clip_update_selection(Clipboard_T *clip)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 pos_T start, end;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 // If visual mode is only due to a redo command ("."), then ignore it
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28303
diff changeset
80 if (!redo_VIsual_busy && VIsual_active && (State & MODE_NORMAL))
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
82 if (LT_POS(VIsual, curwin->w_cursor))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
83 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
84 start = VIsual;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
85 end = curwin->w_cursor;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
86 if (has_mbyte)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
87 end.col += (*mb_ptr2len)(ml_get_cursor()) - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
88 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
90 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
91 start = curwin->w_cursor;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
92 end = VIsual;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
93 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
94 if (!EQUAL_POS(clip->start, start)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 || !EQUAL_POS(clip->end, end)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
96 || clip->vmode != VIsual_mode)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
98 clip_clear_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
99 clip->start = start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
100 clip->end = end;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
101 clip->vmode = VIsual_mode;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
102 clip_free_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
103 clip_own_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 clip_gen_set_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
105 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 clip_gen_own_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
114 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
115 return clip_mch_own_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
116 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
117 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
118 return clip_xterm_own_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
119 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
120 return clip_mch_own_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
121 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
122 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
123
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
124 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
125 clip_own_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
126 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
127 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
128 * Also want to check somehow that we are reading from the keyboard rather
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
129 * than a mapping etc.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
130 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
131 #ifdef FEAT_X11
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
132 // Always own the selection, we might have lost it without being
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
133 // notified, e.g. during a ":sh" command.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
134 if (cbd->available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
135 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
136 int was_owned = cbd->owned;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
137
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
138 cbd->owned = (clip_gen_own_selection(cbd) == OK);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
139 if (!was_owned && (cbd == &clip_star || cbd == &clip_plus))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
140 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
141 // May have to show a different kind of highlighting for the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
142 // selected area. There is no specific redraw command for this,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 // just redraw all windows on the current buffer.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
144 if (cbd->owned
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28303
diff changeset
145 && (get_real_state() == MODE_VISUAL
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28303
diff changeset
146 || get_real_state() == MODE_SELECT)
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 && (cbd == &clip_star ? clip_isautosel_star()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 : clip_isautosel_plus())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 redraw_curbuf_later(INVERTED_ALL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 // Only own the clipboard when we didn't own it yet.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 if (!cbd->owned && cbd->available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 cbd->owned = (clip_gen_own_selection(cbd) == OK);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
158 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
159
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
160 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
161 clip_gen_lose_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
162 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
164 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
165 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
166 clip_mch_lose_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
167 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
168 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
169 clip_xterm_lose_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
170 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
171 clip_mch_lose_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
172 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
176 clip_lose_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
177 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
178 #ifdef FEAT_X11
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 int was_owned = cbd->owned;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181 int visual_selection = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
182
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
183 if (cbd == &clip_star || cbd == &clip_plus)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
184 visual_selection = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
185
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
186 clip_free_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
187 cbd->owned = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
188 if (visual_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
189 clip_clear_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
190 clip_gen_lose_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
191 #ifdef FEAT_X11
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
192 if (visual_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
193 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
194 // May have to show a different kind of highlighting for the selected
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
195 // area. There is no specific redraw command for this, just redraw all
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
196 // windows on the current buffer.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
197 if (was_owned
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28303
diff changeset
198 && (get_real_state() == MODE_VISUAL
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28303
diff changeset
199 || get_real_state() == MODE_SELECT)
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
200 && (cbd == &clip_star ?
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
201 clip_isautosel_star() : clip_isautosel_plus())
25901
f48c435bd1df patch 8.2.3484: crash when going through spell suggestions
Bram Moolenaar <Bram@vim.org>
parents: 24790
diff changeset
202 && HL_ATTR(HLF_V) != HL_ATTR(HLF_VNC)
f48c435bd1df patch 8.2.3484: crash when going through spell suggestions
Bram Moolenaar <Bram@vim.org>
parents: 24790
diff changeset
203 && !exiting)
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 update_curbuf(INVERTED_ALL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 setcursor();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 cursor_on();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 out_flush_cursor(TRUE, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
209 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
210 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
212 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
213
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 clip_copy_selection(Clipboard_T *clip)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 {
28773
d770568e6c98 patch 8.2.4911: the mode #defines are not clearly named
Bram Moolenaar <Bram@vim.org>
parents: 28303
diff changeset
217 if (VIsual_active && (State & MODE_NORMAL) && clip->available)
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 clip_update_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 clip_free_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 clip_own_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 if (clip->owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 clip_get_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 clip_gen_set_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
225 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
226 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
227
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
228 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
229 * Save and restore clip_unnamed before doing possibly many changes. This
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
230 * prevents accessing the clipboard very often which might slow down Vim
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 * considerably.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
233 static int global_change_count = 0; // if set, inside a start_global_changes
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
234 static int clipboard_needs_update = FALSE; // clipboard needs to be updated
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
235 static int clip_did_set_selection = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
236
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
237 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 * Save clip_unnamed and reset it.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 start_global_changes(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 if (++global_change_count > 1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 clip_unnamed_saved = clip_unnamed;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246 clipboard_needs_update = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 if (clip_did_set_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 clip_unnamed = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 clip_did_set_selection = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
252 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
253 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
256 * Return TRUE if setting the clipboard was postponed, it already contains the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 * right text.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 is_clipboard_needs_update()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 return clipboard_needs_update;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
263 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
264
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
265 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
266 * Restore clip_unnamed and set the selection when needed.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 end_global_changes(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 if (--global_change_count > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 // recursive
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 if (!clip_did_set_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 clip_did_set_selection = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 clip_unnamed = clip_unnamed_saved;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 clip_unnamed_saved = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 if (clipboard_needs_update)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 // only store something in the clipboard,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
282 // if we have yanked anything to it
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 if (clip_unnamed & CLIP_UNNAMED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 clip_own_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 clip_gen_set_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 if (clip_unnamed & CLIP_UNNAMED_PLUS)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 clip_own_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 clip_gen_set_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
292 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
293 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
294 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 clipboard_needs_update = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
296 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
297
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
298 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299 * Called when Visual mode is ended: update the selection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 clip_auto_select(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 if (clip_isautosel_star())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 clip_copy_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 if (clip_isautosel_plus())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 clip_copy_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
308 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
309
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
310 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
311 * Return TRUE if automatic selection of Visual area is desired for the *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 * register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 clip_isautosel_star(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 return (
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
319 gui.in_use ? (vim_strchr(p_go, GO_ASEL) != NULL) :
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 clip_autoselect_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
322 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
323
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
324 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
325 * Return TRUE if automatic selection of Visual area is desired for the +
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 * register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 clip_isautosel_plus(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 return (
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
333 gui.in_use ? (vim_strchr(p_go, GO_ASELPLUS) != NULL) :
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 clip_autoselect_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
336 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
337
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
338
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
339 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
340 * Stuff for general mouse selection, without using Visual mode.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
341 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
342
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
343 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 * Compare two screen positions ala strcmp()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 clip_compare_pos(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 int row1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 int col1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 int row2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 int col2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
353 if (row1 > row2) return(1);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
354 if (row1 < row2) return(-1);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
355 if (col1 > col2) return(1);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
356 if (col1 < col2) return(-1);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 return(0);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
358 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
359
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 // "how" flags for clip_invert_area()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 #define CLIP_CLEAR 1
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 #define CLIP_SET 2
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363 #define CLIP_TOGGLE 3
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
364
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
365 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
366 * Invert or un-invert a rectangle of the screen.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
367 * "invert" is true if the result is inverted.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 clip_invert_rectangle(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 Clipboard_T *cbd UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 int row_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 int col_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 int height_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 int width_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 int invert)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 int row = row_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 int col = col_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 int height = height_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381 int width = width_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
384 // this goes on top of all popup windows
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385 screen_zindex = CLIP_ZINDEX;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 if (col < cbd->min_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 width -= cbd->min_col - col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 col = cbd->min_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 if (width > cbd->max_col - col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 width = cbd->max_col - col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 if (row < cbd->min_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 height -= cbd->min_row - row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 row = cbd->min_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
399 if (height > cbd->max_row - row + 1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
400 height = cbd->max_row - row + 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
404 gui_mch_invert_rectangle(row, col, height, width);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
407 screen_draw_rectangle(row, col, height, width, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 screen_zindex = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
411 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
412
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
413 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
414 * Invert a region of the display between a starting and ending row and column
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 * Values for "how":
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 * CLIP_CLEAR: undo inversion
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 * CLIP_SET: set inversion
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
418 * CLIP_TOGGLE: set inversion if pos1 < pos2, undo inversion otherwise.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 * 0: invert (GUI only).
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 clip_invert_area(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 Clipboard_T *cbd,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 int row1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 int col1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 int row2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 int col2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 int how)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 int invert = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431 int max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 max_col = cbd->max_col - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 max_col = Columns - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 if (how == CLIP_SET)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440 invert = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
442 // Swap the from and to positions so the from is always before
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
443 if (clip_compare_pos(row1, col1, row2, col2) > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445 int tmp_row, tmp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 tmp_row = row1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 tmp_col = col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 row1 = row2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 col1 = col2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 row2 = tmp_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 col2 = tmp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 else if (how == CLIP_TOGGLE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455 invert = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
457 // If all on the same line, do it the easy way
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 if (row1 == row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
460 clip_invert_rectangle(cbd, row1, col1, 1, col2 - col1, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
464 // Handle a piece of the first line
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 if (col1 > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
467 clip_invert_rectangle(cbd, row1, col1, 1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 (int)Columns - col1, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 row1++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
470 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
471
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
472 // Handle a piece of the last line
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 if (col2 < max_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
475 clip_invert_rectangle(cbd, row2, 0, 1, col2, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 row2--;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
477 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
478
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 // Handle the rectangle that's left
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 if (row2 >= row1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
481 clip_invert_rectangle(cbd, row1, 0, row2 - row1 + 1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 (int)Columns, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
483 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
484 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
485
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
486 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
487 * Start, continue or end a modeless selection. Used when editing the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
488 * command-line, in the cmdline window and when the mouse is in a popup window.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
491 clip_modeless(int button, int is_click, int is_drag)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493 int repeat;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
495 repeat = ((clip_star.mode == SELECT_MODE_CHAR
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 || clip_star.mode == SELECT_MODE_LINE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 && (mod_mask & MOD_MASK_2CLICK))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 || (clip_star.mode == SELECT_MODE_WORD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 && (mod_mask & MOD_MASK_3CLICK));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 if (is_click && button == MOUSE_RIGHT)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
502 // Right mouse button: If there was no selection, start one.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 // Otherwise extend the existing selection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 if (clip_star.state == SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
505 clip_start_selection(mouse_col, mouse_row, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
506 clip_process_selection(button, mouse_col, mouse_row, repeat);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 else if (is_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
509 clip_start_selection(mouse_col, mouse_row, repeat);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 else if (is_drag)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
512 // Don't try extending a selection if there isn't one. Happens when
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
513 // button-down is in the cmdline and them moving mouse upwards.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 if (clip_star.state != SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
515 clip_process_selection(button, mouse_col, mouse_row, repeat);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 else // release
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
518 clip_process_selection(MOUSE_RELEASE, mouse_col, mouse_row, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
519 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
520
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
521 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
522 * Update the currently selected region by adding and/or subtracting from the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
523 * beginning or end and inverting the changed area(s).
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 clip_update_modeless_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 Clipboard_T *cb,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 int row1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 int col1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 int row2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 int col2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 // See if we changed at the beginning of the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
534 if (row1 != cb->start.lnum || col1 != (int)cb->start.col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 clip_invert_area(cb, row1, col1, (int)cb->start.lnum, cb->start.col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 CLIP_TOGGLE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 cb->start.lnum = row1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 cb->start.col = col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
540 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
541
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
542 // See if we changed at the end of the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
543 if (row2 != cb->end.lnum || col2 != (int)cb->end.col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
545 clip_invert_area(cb, (int)cb->end.lnum, cb->end.col, row2, col2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 CLIP_TOGGLE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 cb->end.lnum = row2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 cb->end.col = col2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
549 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
550 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
551
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
552 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
553 * Find the starting and ending positions of the word at the given row and
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
554 * column. Only white-separated words are recognized here.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
556 #define CHAR_CLASS(c) (c <= ' ' ? ' ' : vim_iswordc(c))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
559 clip_get_word_boundaries(Clipboard_T *cb, int row, int col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 int start_class;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 int temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564 int mboff;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
566 if (row >= screen_Rows || col >= screen_Columns || ScreenLines == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 p = ScreenLines + LineOffset[row];
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 25901
diff changeset
570 // Correct for starting in the right half of a double-wide char
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
572 col -= dbcs_screen_head_off(p, p + col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
573 else if (enc_utf8 && p[col] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 --col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575 start_class = CHAR_CLASS(p[col]);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 temp_col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 for ( ; temp_col > 0; temp_col--)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 if (enc_dbcs != 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
580 && (mboff = dbcs_screen_head_off(p, p + temp_col - 1)) > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 temp_col -= mboff;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 else if (CHAR_CLASS(p[temp_col - 1]) != start_class
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
583 && !(enc_utf8 && p[temp_col - 1] == 0))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585 cb->word_start_col = temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 temp_col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
588 for ( ; temp_col < screen_Columns; temp_col++)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
589 if (enc_dbcs != 0 && dbcs_ptr2cells(p + temp_col) == 2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 ++temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
591 else if (CHAR_CLASS(p[temp_col]) != start_class
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 && !(enc_utf8 && p[temp_col] == 0))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 cb->word_end_col = temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
595 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
596
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
597 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
598 * Find the column position for the last non-whitespace character on the given
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 * line at or before start_col.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
602 clip_get_line_end(Clipboard_T *cbd UNUSED, int row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 if (row >= screen_Rows || ScreenLines == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 return 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 for (i =
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 cbd->max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 screen_Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 i > 0; i--)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 if (ScreenLines[LineOffset[row] + i - 1] != ' ')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 return i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
618 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
619
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
620 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 * Start the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
624 clip_start_selection(int col, int row, int repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 Clipboard_T *cb = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 win_T *wp;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 int row_cp = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630 int col_cp = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 wp = mouse_find_win(&row_cp, &col_cp, FIND_POPUP);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 if (wp != NULL && WIN_IS_POPUP(wp)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 && popup_is_in_scrollbar(wp, row_cp, col_cp))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 // click or double click in scrollbar does not start a selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 if (cb->state == SELECT_DONE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 clip_clear_selection(cb);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 row = check_row(row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 col = check_col(col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644 col = mb_fix_col(col, row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 cb->start.lnum = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 cb->start.col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 cb->end = cb->start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 cb->origin_row = (short_u)cb->start.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 cb->state = SELECT_IN_PROGRESS;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652 if (wp != NULL && WIN_IS_POPUP(wp))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 // Click in a popup window restricts selection to that window,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 // excluding the border.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 cb->min_col = wp->w_wincol + wp->w_popup_border[3];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657 cb->max_col = wp->w_wincol + popup_width(wp)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 - wp->w_popup_border[1] - wp->w_has_scrollbar;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 if (cb->max_col > screen_Columns)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660 cb->max_col = screen_Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
661 cb->min_row = wp->w_winrow + wp->w_popup_border[0];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
662 cb->max_row = wp->w_winrow + popup_height(wp) - 1
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 - wp->w_popup_border[2];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 cb->min_col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 cb->max_col = screen_Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 cb->min_row = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 cb->max_row = screen_Rows;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 if (repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 if (++cb->mode > SELECT_MODE_LINE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
683 // clear the cursor until the selection is made
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 gui_undraw_cursor();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 switch (cb->mode)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 case SELECT_MODE_CHAR:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 cb->origin_start_col = cb->start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 cb->word_end_col = clip_get_line_end(cb, (int)cb->start.lnum);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 case SELECT_MODE_WORD:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
696 clip_get_word_boundaries(cb, (int)cb->start.lnum, cb->start.col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
697 cb->origin_start_col = cb->word_start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
698 cb->origin_end_col = cb->word_end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
700 clip_invert_area(cb, (int)cb->start.lnum, cb->word_start_col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 (int)cb->end.lnum, cb->word_end_col, CLIP_SET);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 cb->start.col = cb->word_start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
703 cb->end.col = cb->word_end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 case SELECT_MODE_LINE:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
707 clip_invert_area(cb, (int)cb->start.lnum, 0, (int)cb->start.lnum,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 (int)Columns, CLIP_SET);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 cb->start.col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 cb->end.col = Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714 cb->prev = cb->start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
717 printf("Selection started at (%ld,%d)\n", cb->start.lnum, cb->start.col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
719 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
720
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
721 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 * Continue processing the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 clip_process_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 int button,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 int col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 int row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 int_u repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 Clipboard_T *cb = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 int diff;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733 int slen = 1; // cursor shape width
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 if (button == MOUSE_RELEASE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 if (cb->state != SELECT_IN_PROGRESS)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
740 // Check to make sure we have something selected
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
741 if (cb->start.lnum == cb->end.lnum && cb->start.col == cb->end.col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 gui_update_cursor(FALSE, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 cb->state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 printf("Selection ended: (%ld,%d) to (%ld,%d)\n", cb->start.lnum,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753 cb->start.col, cb->end.lnum, cb->end.col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 if (clip_isautosel_star()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 || (
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758 gui.in_use ? (vim_strchr(p_go, GO_ASELML) != NULL) :
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 clip_autoselectml))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 clip_copy_modeless_selection(FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 gui_update_cursor(FALSE, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 cb->state = SELECT_DONE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
769 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
770
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 row = check_row(row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 col = check_col(col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773 col = mb_fix_col(col, row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
775 if (col == (int)cb->prev.col && row == cb->prev.lnum && !repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
777
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
778 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
779 * When extending the selection with the right mouse button, swap the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
780 * start and end if the position is before half the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
782 if (cb->state == SELECT_DONE && button == MOUSE_RIGHT)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
783 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
784 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
785 * If the click is before the start, or the click is inside the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
786 * selection and the start is the closest side, set the origin to the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 * end of the selection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
789 if (clip_compare_pos(row, col, (int)cb->start.lnum, cb->start.col) < 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 || (clip_compare_pos(row, col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
791 (int)cb->end.lnum, cb->end.col) < 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 && (((cb->start.lnum == cb->end.lnum
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
793 && cb->end.col - col > col - cb->start.col))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 || ((diff = (cb->end.lnum - row) -
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 (row - cb->start.lnum)) > 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
796 || (diff == 0 && col < (int)(cb->start.col +
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 cb->end.col) / 2)))))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 cb->origin_row = (short_u)cb->end.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 cb->origin_start_col = cb->end.col - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
801 cb->origin_end_col = cb->end.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
805 cb->origin_row = (short_u)cb->start.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
806 cb->origin_start_col = cb->start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
807 cb->origin_end_col = cb->start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
809 if (cb->mode == SELECT_MODE_WORD && !repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 // set state, for when using the right mouse button
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 cb->state = SELECT_IN_PROGRESS;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 printf("Selection extending to (%d,%d)\n", row, col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 if (repeated_click && ++cb->mode > SELECT_MODE_LINE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 switch (cb->mode)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 case SELECT_MODE_CHAR:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
826 // If we're on a different line, find where the line ends
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 if (row != cb->prev.lnum)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
828 cb->word_end_col = clip_get_line_end(cb, row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
830 // See if we are before or after the origin of the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
831 if (clip_compare_pos(row, col, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 cb->origin_start_col) >= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
834 if (col >= (int)cb->word_end_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
835 clip_update_modeless_selection(cb, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
836 cb->origin_start_col, row, (int)Columns);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
839 if (has_mbyte && mb_lefthalve(row, col))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 slen = 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
841 clip_update_modeless_selection(cb, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
842 cb->origin_start_col, row, col + slen);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
843 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
844 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 if (has_mbyte
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
848 && mb_lefthalve(cb->origin_row, cb->origin_start_col))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 slen = 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
850 if (col >= (int)cb->word_end_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
851 clip_update_modeless_selection(cb, row, cb->word_end_col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
852 cb->origin_row, cb->origin_start_col + slen);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
854 clip_update_modeless_selection(cb, row, col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
855 cb->origin_row, cb->origin_start_col + slen);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 case SELECT_MODE_WORD:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
860 // If we are still within the same word, do nothing
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
861 if (row == cb->prev.lnum && col >= (int)cb->word_start_col
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862 && col < (int)cb->word_end_col && !repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 // Get new word boundaries
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 clip_get_word_boundaries(cb, row, col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
868 // Handle being after the origin point of selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
869 if (clip_compare_pos(row, col, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 cb->origin_start_col) >= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 clip_update_modeless_selection(cb, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
872 cb->origin_start_col, row, cb->word_end_col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 clip_update_modeless_selection(cb, row, cb->word_start_col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
875 cb->origin_row, cb->origin_end_col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 case SELECT_MODE_LINE:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
879 if (row == cb->prev.lnum && !repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
882 if (clip_compare_pos(row, col, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 cb->origin_start_col) >= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
884 clip_update_modeless_selection(cb, cb->origin_row, 0, row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 (int)Columns);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
887 clip_update_modeless_selection(cb, row, 0, cb->origin_row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 (int)Columns);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
890 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
891
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 cb->prev.lnum = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893 cb->prev.col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
896 printf("Selection is: (%ld,%d) to (%ld,%d)\n", cb->start.lnum,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897 cb->start.col, cb->end.lnum, cb->end.col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
899 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
900
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 # if defined(FEAT_GUI) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
903 * Redraw part of the selection if character at "row,col" is inside of it.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 * Only used for the GUI.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
907 clip_may_redraw_selection(int row, int col, int len)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 int start = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910 int end = col + len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 if (clip_star.state != SELECT_CLEARED
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 && row >= clip_star.start.lnum
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 && row <= clip_star.end.lnum)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
916 if (row == clip_star.start.lnum && start < (int)clip_star.start.col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 start = clip_star.start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
918 if (row == clip_star.end.lnum && end > (int)clip_star.end.col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 end = clip_star.end.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 if (end > start)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
921 clip_invert_area(&clip_star, row, start, row, end, 0);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
925
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 * Called from outside to clear selected region from the display
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 clip_clear_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
932
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 if (cbd->state == SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
936 clip_invert_area(cbd, (int)cbd->start.lnum, cbd->start.col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
937 (int)cbd->end.lnum, cbd->end.col, CLIP_CLEAR);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 cbd->state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
939 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
940
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
941 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
942 * Clear the selection if any lines from "row1" to "row2" are inside of it.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
945 clip_may_clear_selection(int row1, int row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 if (clip_star.state == SELECT_DONE
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 && row2 >= clip_star.start.lnum
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 && row1 <= clip_star.end.lnum)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 clip_clear_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
951 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
952
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
953 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
954 * Called before the screen is scrolled up or down. Adjusts the line numbers
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
955 * of the selection. Call with big number when clearing the screen.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 clip_scroll_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 int rows) // negative for scroll down
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961 int lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 if (clip_star.state == SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 lnum = clip_star.start.lnum - rows;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 if (lnum <= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 clip_star.start.lnum = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
969 else if (lnum >= screen_Rows) // scrolled off of the screen
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 clip_star.state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972 clip_star.start.lnum = lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 lnum = clip_star.end.lnum - rows;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
975 if (lnum < 0) // scrolled off of the screen
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 clip_star.state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 else if (lnum >= screen_Rows)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
978 clip_star.end.lnum = screen_Rows - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 clip_star.end.lnum = lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
981 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
982
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
983 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
984 * Copy the currently selected area into the '*' register so it will be
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 * available for pasting.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
986 * When "both" is TRUE also copy to the '+' register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
989 clip_copy_modeless_selection(int both UNUSED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 char_u *buffer;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 char_u *bufp;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 int row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 int start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 int end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 int line_end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 int add_newline_flag = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 int len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 int row1 = clip_star.start.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 int col1 = clip_star.start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 int row2 = clip_star.end.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003 int col2 = clip_star.end.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 // Can't use ScreenLines unless initialized
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 if (ScreenLines == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1008
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1009 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1010 * Make sure row1 <= row2, and if row1 == row2 that col1 <= col2.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 if (row1 > row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 row = row1; row1 = row2; row2 = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 row = col1; col1 = col2; col2 = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 else if (row1 == row2 && col1 > col2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 row = col1; col1 = col2; col2 = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 if (col1 < clip_star.min_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 col1 = clip_star.min_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 if (col2 > clip_star.max_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 col2 = clip_star.max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1026 if (row1 > clip_star.max_row || row2 < clip_star.min_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 if (row1 < clip_star.min_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 row1 = clip_star.min_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 if (row2 > clip_star.max_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 row2 = clip_star.max_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 #endif
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 25901
diff changeset
1033 // correct starting point for being on right half of double-wide char
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 p = ScreenLines + LineOffset[row1];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1036 col1 -= (*mb_head_off)(p, p + col1);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1037 else if (enc_utf8 && p[col1] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038 --col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1040 // Create a temporary buffer for storing the text
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 len = (row2 - row1 + 1) * Columns + 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1043 len *= 2; // max. 2 bytes per display cell
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 else if (enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 len *= MB_MAXBYTES;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 buffer = alloc(len);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 if (buffer == NULL) // out of memory
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 // Process each row in the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1051 for (bufp = buffer, row = row1; row <= row2; row++)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 if (row == row1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 start_col = col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 start_col = clip_star.min_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 start_col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 if (row == row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 end_col = col2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 end_col = clip_star.max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 end_col = Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1071 line_end_col = clip_get_line_end(&clip_star, row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1073 // See if we need to nuke some trailing whitespace
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 if (end_col >=
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 clip_star.max_col
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 Columns
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1080 && (row < row2 || end_col > line_end_col))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 // Get rid of trailing whitespace
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 end_col = line_end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 if (end_col < start_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085 end_col = start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1087 // If the last line extended to the end, add an extra newline
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 if (row == row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 add_newline_flag = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1090 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1091
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1092 // If after the first row, we need to always add a newline
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 if (row > row1 && !LineWraps[row - 1])
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094 *bufp++ = NL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1096 // Safetey check for in case resizing went wrong
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1097 if (row < screen_Rows && end_col <= screen_Columns)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 p = ScreenLines + LineOffset[row];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1104 for (i = start_col; i < end_col; ++i)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1105 if (enc_dbcs == DBCS_JPNU && p[i] == 0x8e)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 // single-width double-byte char
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 *bufp++ = 0x8e;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 *bufp++ = ScreenLines2[LineOffset[row] + i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 *bufp++ = p[i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 if (MB_BYTE2LEN(p[i]) == 2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 *bufp++ = p[++i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1116 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1117 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 else if (enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 int off;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122 int ci;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 off = LineOffset[row];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1125 for (i = start_col; i < end_col; ++i)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1127 // The base character is either in ScreenLinesUC[] or
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 // ScreenLines[].
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 if (ScreenLinesUC[off + i] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 *bufp++ = ScreenLines[off + i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1133 bufp += utf_char2bytes(ScreenLinesUC[off + i], bufp);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1134 for (ci = 0; ci < Screen_mco; ++ci)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 // Add a composing character.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 if (ScreenLinesC[ci][off + i] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1139 bufp += utf_char2bytes(ScreenLinesC[ci][off + i],
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 bufp);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1141 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1142 }
26771
fc859aea8cec patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents: 25901
diff changeset
1143 // Skip right half of double-wide character.
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 if (ScreenLines[off + i + 1] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 ++i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1146 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1147 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1150 STRNCPY(bufp, ScreenLines + LineOffset[row] + start_col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 end_col - start_col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 bufp += end_col - start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1153 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1154 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1155 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1156
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1157 // Add a newline at the end if the selection ended there
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 if (add_newline_flag)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159 *bufp++ = NL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1161 // First cleanup any old selection and become the owner.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 clip_free_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163 clip_own_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 // Yank the text into the '*' register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1166 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1168 // Make the register contents available to the outside world.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169 clip_gen_set_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 #ifdef FEAT_X11
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 if (both)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 // Do the same for the '+' register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 clip_free_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 clip_own_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1177 clip_yank_selection(MCHAR, buffer, (long)(bufp - buffer), &clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 clip_gen_set_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 vim_free(buffer);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 clip_gen_set_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 if (!clip_did_set_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1189 // Updating postponed, so that accessing the system clipboard won't
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1190 // hang Vim when accessing it many times (e.g. on a :g command).
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1191 if ((cbd == &clip_plus && (clip_unnamed_saved & CLIP_UNNAMED_PLUS))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 || (cbd == &clip_star && (clip_unnamed_saved & CLIP_UNNAMED)))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 clipboard_needs_update = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1196 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1197 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 clip_mch_set_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 clip_xterm_set_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 clip_mch_set_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1208 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1209
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1211 clip_gen_request_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 clip_mch_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 clip_xterm_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 clip_mch_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1223 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1224
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1225 #if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD) && defined(USE_SYSTEM)) \
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1228 clip_x11_owner_exists(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1230 return XGetSelectionOwner(X_DISPLAY, cbd->sel_atom) != None;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1234 #if (defined(FEAT_X11) && defined(USE_SYSTEM)) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1236 clip_gen_owner_exists(Clipboard_T *cbd UNUSED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 # ifdef FEAT_GUI_GTK
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 return clip_gtk_owner_exists(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 return clip_x11_owner_exists(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 return TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1250
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1251 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1252 * Extract the items in the 'clipboard' option and set global values.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1253 * Return an error message or NULL for success.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 char *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 check_clipboard_option(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 int new_unnamed = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 int new_autoselect_star = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 int new_autoselect_plus = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 int new_autoselectml = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 int new_html = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 regprog_T *new_exclude_prog = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 char *errmsg = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 for (p = p_cb; *p != NUL; )
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1269 if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 new_unnamed |= CLIP_UNNAMED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 p += 7;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274 else if (STRNCMP(p, "unnamedplus", 11) == 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 && (p[11] == ',' || p[11] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 new_unnamed |= CLIP_UNNAMED_PLUS;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 p += 11;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1280 else if (STRNCMP(p, "autoselect", 10) == 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 && (p[10] == ',' || p[10] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 new_autoselect_star = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 p += 10;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1286 else if (STRNCMP(p, "autoselectplus", 14) == 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 && (p[14] == ',' || p[14] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 new_autoselect_plus = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 p += 14;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1292 else if (STRNCMP(p, "autoselectml", 12) == 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 && (p[12] == ',' || p[12] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 new_autoselectml = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 p += 12;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 else if (STRNCMP(p, "html", 4) == 0 && (p[4] == ',' || p[4] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 new_html = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 p += 4;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1303 else if (STRNCMP(p, "exclude:", 8) == 0 && new_exclude_prog == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 p += 8;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1306 new_exclude_prog = vim_regcomp(p, RE_MAGIC);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 if (new_exclude_prog == NULL)
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
1308 errmsg = e_invalid_argument;
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 {
26865
bce848ec8b1b patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 26771
diff changeset
1313 errmsg = e_invalid_argument;
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 if (*p == ',')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 ++p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 if (errmsg == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 {
20707
ec89debe5037 patch 8.2.0907: when using :global clipboard isn't set correctly
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
1321 if (global_busy)
ec89debe5037 patch 8.2.0907: when using :global clipboard isn't set correctly
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
1322 // clip_unnamed will be reset to clip_unnamed_saved
ec89debe5037 patch 8.2.0907: when using :global clipboard isn't set correctly
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
1323 // at end_global_changes
ec89debe5037 patch 8.2.0907: when using :global clipboard isn't set correctly
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
1324 clip_unnamed_saved = new_unnamed;
ec89debe5037 patch 8.2.0907: when using :global clipboard isn't set correctly
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
1325 else
ec89debe5037 patch 8.2.0907: when using :global clipboard isn't set correctly
Bram Moolenaar <Bram@vim.org>
parents: 20007
diff changeset
1326 clip_unnamed = new_unnamed;
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 clip_autoselect_star = new_autoselect_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 clip_autoselect_plus = new_autoselect_plus;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 clip_autoselectml = new_autoselectml;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 clip_html = new_html;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 vim_regfree(clip_exclude_prog);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 clip_exclude_prog = new_exclude_prog;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 #ifdef FEAT_GUI_GTK
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 gui_gtk_set_selection_targets();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 gui_gtk_set_dnd_targets();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 vim_regfree(new_exclude_prog);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1343
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344 return errmsg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1346
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348 * Stuff for the X clipboard. Shared between VMS and Unix.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1349 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1350
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 # include <X11/Xatom.h>
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 # include <X11/Intrinsic.h>
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1355 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1356 * Open the application context (if it hasn't been opened yet).
28303
9849df834f1d patch 8.2.4677: the Athena GUI support is outdated
Bram Moolenaar <Bram@vim.org>
parents: 27426
diff changeset
1357 * Used for Motif GUI and the xterm clipboard.
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 open_app_context(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1361 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 if (app_context == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 XtToolkitInitialize();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365 app_context = XtCreateApplicationContext();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 static Atom vim_atom; // Vim's own special selection format
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 static Atom vimenc_atom; // Vim's extended selection format
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 static Atom utf8_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 static Atom compound_text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 static Atom text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 static Atom targets_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1375 static Atom timestamp_atom; // Used to get a timestamp
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1376
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1377 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1378 x11_setup_atoms(Display *dpy)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 vim_atom = XInternAtom(dpy, VIM_ATOM_NAME, False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 vimenc_atom = XInternAtom(dpy, VIMENC_ATOM_NAME,False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1382 utf8_atom = XInternAtom(dpy, "UTF8_STRING", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 compound_text_atom = XInternAtom(dpy, "COMPOUND_TEXT", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384 text_atom = XInternAtom(dpy, "TEXT", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 targets_atom = XInternAtom(dpy, "TARGETS", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 clip_star.sel_atom = XA_PRIMARY;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387 clip_plus.sel_atom = XInternAtom(dpy, "CLIPBOARD", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388 timestamp_atom = XInternAtom(dpy, "TIMESTAMP", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 * X Selection stuff, for cutting and pasting text to other windows.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 static Boolean
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 clip_x11_convert_selection_cb(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 Widget w UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 Atom *sel_atom,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 Atom *target,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 Atom *type,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 XtPointer *value,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 long_u *length,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 int *format)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405 static char_u *save_result = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 static long_u save_length = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1407 char_u *string;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 int motion_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 Clipboard_T *cbd;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 if (*sel_atom == clip_plus.sel_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413 cbd = &clip_plus;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1415 cbd = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1416
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1417 if (!cbd->owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418 return False; // Shouldn't ever happen
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 // requestor wants to know what target types we support
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 if (*target == targets_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 static Atom array[7];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 *value = (XtPointer)array;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 i = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 array[i++] = targets_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 array[i++] = vimenc_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429 array[i++] = vim_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 if (enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 array[i++] = utf8_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1432 array[i++] = XA_STRING;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1433 array[i++] = text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 array[i++] = compound_text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 *type = XA_ATOM;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437 // This used to be: *format = sizeof(Atom) * 8; but that caused
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 // crashes on 64 bit machines. (Peter Derr)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 *format = 32;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 *length = i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 return True;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 if ( *target != XA_STRING
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445 && *target != vimenc_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 && (*target != utf8_atom || !enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 && *target != vim_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1448 && *target != text_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 && *target != compound_text_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1452 clip_get_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 motion_type = clip_convert_selection(&string, length, cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454 if (motion_type < 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1456
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 // For our own format, the first byte contains the motion type
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458 if (*target == vim_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 (*length)++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1460
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1461 // Our own format with encoding: motion 'encoding' NUL text
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 if (*target == vimenc_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 *length += STRLEN(p_enc) + 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1464
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1465 if (save_length < *length || save_length / 2 >= *length)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 *value = XtRealloc((char *)save_result, (Cardinal)*length + 1);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 *value = save_result;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 if (*value == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1470 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1471 vim_free(string);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1472 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1474 save_result = (char_u *)*value;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 save_length = *length;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1477 if (*target == XA_STRING || (*target == utf8_atom && enc_utf8))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 mch_memmove(save_result, string, (size_t)(*length));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 *type = *target;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1481 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1482 else if (*target == compound_text_atom || *target == text_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1483 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1484 XTextProperty text_prop;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 char *string_nt = (char *)save_result;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 int conv_result;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 // create NUL terminated string which XmbTextListToTextProperty wants
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 mch_memmove(string_nt, string, (size_t)*length);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 string_nt[*length] = NUL;
27426
41e0dcf38521 patch 8.2.4241: some type casts are redundant
Bram Moolenaar <Bram@vim.org>
parents: 27018
diff changeset
1491 conv_result = XmbTextListToTextProperty(X_DISPLAY, &string_nt,
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 1, XCompoundTextStyle, &text_prop);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1493 if (conv_result != Success)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 vim_free(string);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 *value = (XtPointer)(text_prop.value); // from plain text
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 *length = text_prop.nitems;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 *type = compound_text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 XtFree((char *)save_result);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502 save_result = (char_u *)*value;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 save_length = *length;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 else if (*target == vimenc_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1506 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 int l = STRLEN(p_enc);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 save_result[0] = motion_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 STRCPY(save_result + 1, p_enc);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 mch_memmove(save_result + l + 2, string, (size_t)(*length - l - 2));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1512 *type = vimenc_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1513 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1514 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 save_result[0] = motion_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 mch_memmove(save_result + 1, string, (size_t)(*length - 1));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518 *type = vim_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 *format = 8; // 8 bits per char
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1521 vim_free(string);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 return True;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1523 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 clip_x11_lose_ownership_cb(Widget w UNUSED, Atom *sel_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1527 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1528 if (*sel_atom == clip_plus.sel_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 clip_lose_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1530 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 clip_lose_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1532 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1533
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1534 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 clip_x11_notify_cb(Widget w UNUSED, Atom *sel_atom UNUSED, Atom *target UNUSED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 // To prevent automatically freeing the selection value.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 * Property callback to get a timestamp for XtOwnSelection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 */
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1543 # if (defined(FEAT_X11) && defined(FEAT_XCLIPBOARD)) || defined(PROTO)
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 clip_x11_timestamp_cb(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 Widget w,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 XtPointer n UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 XEvent *event,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 Boolean *cont UNUSED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1551 Atom actual_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 int format;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 unsigned long nitems, bytes_after;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 unsigned char *prop=NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 XPropertyEvent *xproperty=&event->xproperty;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1556
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1557 // Must be a property notify, state can't be Delete (True), has to be
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 // one of the supported selection types.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1559 if (event->type != PropertyNotify || xproperty->state
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 || (xproperty->atom != clip_star.sel_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561 && xproperty->atom != clip_plus.sel_atom))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564 if (XGetWindowProperty(xproperty->display, xproperty->window,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 xproperty->atom, 0, 0, False, timestamp_atom, &actual_type, &format,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1566 &nitems, &bytes_after, &prop))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1567 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1568
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1569 if (prop)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1570 XFree(prop);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1571
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1572 // Make sure the property type is "TIMESTAMP" and it's 32 bits.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 if (actual_type != timestamp_atom || format != 32)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1575
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 // Get the selection, using the event timestamp.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1577 if (XtOwnSelection(w, xproperty->atom, xproperty->time,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 clip_x11_notify_cb) == OK)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1580 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1581 // Set the "owned" flag now, there may have been a call to
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582 // lose_ownership_cb in between.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 if (xproperty->atom == clip_plus.sel_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 clip_plus.owned = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 clip_star.owned = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1588 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1589
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1590 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 x11_setup_selection(Widget w)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 XtAddEventHandler(w, PropertyChangeMask, False,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 /*(XtEventHandler)*/clip_x11_timestamp_cb, (XtPointer)NULL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 }
27018
268f6a3511df patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents: 26865
diff changeset
1596 # endif
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 clip_x11_request_selection_cb(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 Widget w UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 XtPointer success,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 Atom *sel_atom,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1603 Atom *type,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1604 XtPointer value,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1605 long_u *length,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1606 int *format)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1607 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1608 int motion_type = MAUTO;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1609 long_u len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1610 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1611 char **text_list = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1612 Clipboard_T *cbd;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1613 char_u *tmpbuf = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1614
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1615 if (*sel_atom == clip_plus.sel_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1616 cbd = &clip_plus;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1617 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1618 cbd = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1619
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1620 if (value == NULL || *length == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1621 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1622 clip_free_selection(cbd); // nothing received, clear register
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1623 *(int *)success = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1624 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1625 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1626 p = (char_u *)value;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1627 len = *length;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1628 if (*type == vim_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1629 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1630 motion_type = *p++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1631 len--;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1632 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1633
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1634 else if (*type == vimenc_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1635 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1636 char_u *enc;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1637 vimconv_T conv;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1638 int convlen;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1639
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1640 motion_type = *p++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 --len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1643 enc = p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1644 p += STRLEN(p) + 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 len -= p - enc;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1646
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 // If the encoding of the text is different from 'encoding', attempt
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648 // converting it.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 conv.vc_type = CONV_NONE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 convert_setup(&conv, enc, p_enc);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1651 if (conv.vc_type != CONV_NONE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1652 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 convlen = len; // Need to use an int here.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1654 tmpbuf = string_convert(&conv, p, &convlen);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 len = convlen;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656 if (tmpbuf != NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1657 p = tmpbuf;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 convert_setup(&conv, NULL, NULL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1660 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662 else if (*type == compound_text_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1663 || *type == utf8_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1664 || (enc_dbcs != 0 && *type == text_atom))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1665 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1666 XTextProperty text_prop;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1667 int n_text = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1668 int status;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1670 text_prop.value = (unsigned char *)value;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 text_prop.encoding = *type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 text_prop.format = *format;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673 text_prop.nitems = len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 #if defined(X_HAVE_UTF8_STRING)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 if (*type == utf8_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 status = Xutf8TextPropertyToTextList(X_DISPLAY, &text_prop,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1677 &text_list, &n_text);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1678 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1679 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 status = XmbTextPropertyToTextList(X_DISPLAY, &text_prop,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1681 &text_list, &n_text);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 if (status != Success || n_text < 1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1684 *(int *)success = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1685 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1686 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 p = (char_u *)text_list[0];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 len = STRLEN(p);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1690 clip_yank_selection(motion_type, p, (long)len, cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1691
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 if (text_list != NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1693 XFreeStringList(text_list);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 vim_free(tmpbuf);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 XtFree((char *)value);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 *(int *)success = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1698
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1700 clip_x11_request_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1701 Widget myShell,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1702 Display *dpy,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1704 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1705 XEvent event;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1706 Atom type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1707 static int success;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1708 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1709 time_t start_time;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1710 int timed_out = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1711
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1712 for (i = 0; i < 6; i++)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1713 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1714 switch (i)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1715 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1716 case 0: type = vimenc_atom; break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1717 case 1: type = vim_atom; break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1718 case 2: type = utf8_atom; break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1719 case 3: type = compound_text_atom; break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1720 case 4: type = text_atom; break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1721 default: type = XA_STRING;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1722 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1723 if (type == utf8_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1724 # if defined(X_HAVE_UTF8_STRING)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1725 && !enc_utf8
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1726 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1727 )
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1728 // Only request utf-8 when 'encoding' is utf8 and
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1729 // Xutf8TextPropertyToTextList is available.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730 continue;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 success = MAYBE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 XtGetSelectionValue(myShell, cbd->sel_atom, type,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1733 clip_x11_request_selection_cb, (XtPointer)&success, CurrentTime);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1734
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1735 // Make sure the request for the selection goes out before waiting for
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1736 // a response.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 XFlush(dpy);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1740 * Wait for result of selection request, otherwise if we type more
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1741 * characters, then they will appear before the one that requested the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 * paste! Don't worry, we will catch up with any other events later.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1743 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 start_time = time(NULL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 while (success == MAYBE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747 if (XCheckTypedEvent(dpy, PropertyNotify, &event)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1748 || XCheckTypedEvent(dpy, SelectionNotify, &event)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1749 || XCheckTypedEvent(dpy, SelectionRequest, &event))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1750 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1751 // This is where clip_x11_request_selection_cb() should be
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1752 // called. It may actually happen a bit later, so we loop
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1753 // until "success" changes.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1754 // We may get a SelectionRequest here and if we don't handle
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1755 // it we hang. KDE klipper does this, for example.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1756 // We need to handle a PropertyNotify for large selections.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1757 XtDispatchEvent(&event);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1758 continue;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1759 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1760
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1761 // Time out after 2 to 3 seconds to avoid that we hang when the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1762 // other process doesn't respond. Note that the SelectionNotify
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1763 // event may still come later when the selection owner comes back
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1764 // to life and the text gets inserted unexpectedly. Don't know
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1765 // why that happens or how to avoid that :-(.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1766 if (time(NULL) > start_time + 2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1767 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1768 timed_out = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1769 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1770 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1771
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1772 // Do we need this? Probably not.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1773 XSync(dpy, False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1775 // Wait for 1 msec to avoid that we eat up all CPU time.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1776 ui_delay(1L, TRUE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1777 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1778
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1779 if (success == TRUE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1780 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1781
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1782 // don't do a retry with another type after timing out, otherwise we
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1783 // hang for 15 seconds.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1784 if (timed_out)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1785 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1786 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1787
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1788 // Final fallback position - use the X CUT_BUFFER0 store
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1789 yank_cut_buffer0(dpy, cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1790 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 clip_x11_lose_selection(Widget myShell, Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 XtDisownSelection(myShell, cbd->sel_atom,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796 XtLastTimestampProcessed(XtDisplay(myShell)));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1797 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1798
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1799 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1800 clip_x11_own_selection(Widget myShell, Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1801 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1802 // When using the GUI we have proper timestamps, use the one of the last
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 // event. When in the console we don't get events (the terminal gets
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1804 // them), Get the time by a zero-length append, clip_x11_timestamp_cb will
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 // be called with the current timestamp.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 if (XtOwnSelection(myShell, cbd->sel_atom,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 XtLastTimestampProcessed(XtDisplay(myShell)),
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 clip_x11_convert_selection_cb, clip_x11_lose_ownership_cb,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 clip_x11_notify_cb) == False)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813 return FAIL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1814 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1815 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1816 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1817 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 if (!XChangeProperty(XtDisplay(myShell), XtWindow(myShell),
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1819 cbd->sel_atom, timestamp_atom, 32, PropModeAppend, NULL, 0))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 return FAIL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822 // Flush is required in a terminal as nothing else is doing it.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 XFlush(XtDisplay(myShell));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 return OK;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1825 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1826
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 * Send the current selection to the clipboard. Do nothing for X because we
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1829 * will fill in the selection only when requested by another app.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1830 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1831 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 clip_x11_set_selection(Clipboard_T *cbd UNUSED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1834 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 #if defined(FEAT_XCLIPBOARD) || defined(FEAT_GUI_X11) \
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1839 || defined(FEAT_GUI_GTK) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 * Get the contents of the X CUT_BUFFER0 and put it in "cbd".
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844 yank_cut_buffer0(Display *dpy, Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1845 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1846 int nbytes = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1847 char_u *buffer = (char_u *)XFetchBuffer(dpy, &nbytes, 0);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1848
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1849 if (nbytes > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1850 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1851 int done = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1852
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1853 // CUT_BUFFER0 is supposed to be always latin1. Convert to 'enc' when
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1854 // using a multi-byte encoding. Conversion between two 8-bit
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1855 // character sets usually fails and the text might actually be in
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1856 // 'enc' anyway.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1857 if (has_mbyte)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1858 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1859 char_u *conv_buf;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1860 vimconv_T vc;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1861
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1862 vc.vc_type = CONV_NONE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1863 if (convert_setup(&vc, (char_u *)"latin1", p_enc) == OK)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1864 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1865 conv_buf = string_convert(&vc, buffer, &nbytes);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1866 if (conv_buf != NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1867 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1868 clip_yank_selection(MCHAR, conv_buf, (long)nbytes, cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1869 vim_free(conv_buf);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1870 done = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 convert_setup(&vc, NULL, NULL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1873 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1874 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1875 if (!done) // use the text without conversion
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1876 clip_yank_selection(MCHAR, buffer, (long)nbytes, cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1877 XFree((void *)buffer);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1878 if (p_verbose > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1879 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1880 verbose_enter();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1881 verb_msg(_("Used CUT_BUFFER0 instead of empty selection"));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1882 verbose_leave();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1883 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1884 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1885 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1886 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1887
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1888 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1889 * SELECTION / PRIMARY ('*')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 * Text selection stuff that uses the GUI selection register '*'. When using a
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 * GUI this may be text from another window, otherwise it is the last text we
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 * had highlighted with VIsual mode. With mouse support, clicking the middle
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894 * button performs the paste, otherwise you will need to do <"*p>. "
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 * If not under X, it is synonymous with the clipboard register '+'.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 * X CLIPBOARD ('+')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 * Text selection stuff that uses the GUI clipboard register '+'.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 * Under X, this matches the standard cut/paste buffer CLIPBOARD selection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901 * It will be used for unnamed cut/pasting is 'clipboard' contains "unnamed",
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1902 * otherwise you will need to do <"+p>. "
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 * If not under X, it is synonymous with the selection register '*'.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1905
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1907 * Routine to export any final X selection we had to the environment
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1908 * so that the text is still available after Vim has exited. X selections
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1909 * only exist while the owning application exists, so we write to the
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1910 * permanent (while X runs) store CUT_BUFFER0.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1911 * Dump the CLIPBOARD selection if we own it (it's logically the more
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 * 'permanent' of the two), otherwise the PRIMARY one.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 * For now, use a hard-coded sanity limit of 1Mb of data.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1915 #if (defined(FEAT_X11) && defined(FEAT_CLIPBOARD)) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 x11_export_final_selection(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1918 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 Display *dpy;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1920 char_u *str = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 long_u len = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 int motion_type = -1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1925 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1926 dpy = X_DISPLAY;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1927 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1928 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1929 # ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1930 dpy = xterm_dpy;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1931 # else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1932 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1933 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1934
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1935 // Get selection to export
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1936 if (clip_plus.owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1937 motion_type = clip_convert_selection(&str, &len, &clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1938 else if (clip_star.owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1939 motion_type = clip_convert_selection(&str, &len, &clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1940
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1941 // Check it's OK
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1942 if (dpy != NULL && str != NULL && motion_type >= 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1943 && len < 1024*1024 && len > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1944 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1945 int ok = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1946
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1947 // The CUT_BUFFER0 is supposed to always contain latin1. Convert from
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1948 // 'enc' when it is a multi-byte encoding. When 'enc' is an 8-bit
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1949 // encoding conversion usually doesn't work, so keep the text as-is.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1950 if (has_mbyte)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1951 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1952 vimconv_T vc;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1953
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1954 vc.vc_type = CONV_NONE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1955 if (convert_setup(&vc, p_enc, (char_u *)"latin1") == OK)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1957 int intlen = len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1958 char_u *conv_str;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1959
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 vc.vc_fail = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1961 conv_str = string_convert(&vc, str, &intlen);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1962 len = intlen;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1963 if (conv_str != NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1964 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1965 vim_free(str);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1966 str = conv_str;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1967 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1968 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1969 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1970 ok = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1971 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1972 convert_setup(&vc, NULL, NULL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1973 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1974 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1975 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1976 ok = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1977 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1978 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1979
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1980 // Do not store the string if conversion failed. Better to use any
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1981 // other selection than garbled text.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982 if (ok)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1983 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1984 XStoreBuffer(dpy, (char *)str, (int)len, 0);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 XFlush(dpy);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1986 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1989 vim_free(str);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1990 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1991 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 clip_free_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 yankreg_T *y_ptr = get_y_current();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1998 if (cbd == &clip_plus)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1999 set_y_current(get_y_register(PLUS_REGISTER));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2000 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2001 set_y_current(get_y_register(STAR_REGISTER));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2002 free_yank_all();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2003 get_y_current()->y_size = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2004 set_y_current(y_ptr);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2005 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2008 * Get the selected text and put it in register '*' or '+'.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2011 clip_get_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013 yankreg_T *old_y_previous, *old_y_current;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2014 pos_T old_cursor;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2015 pos_T old_visual;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2016 int old_visual_mode;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2017 colnr_T old_curswant;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2018 int old_set_curswant;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2019 pos_T old_op_start, old_op_end;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2020 oparg_T oa;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2021 cmdarg_T ca;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2022
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2023 if (cbd->owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2024 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2025 if ((cbd == &clip_plus
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2026 && get_y_register(PLUS_REGISTER)->y_array != NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2027 || (cbd == &clip_star
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2028 && get_y_register(STAR_REGISTER)->y_array != NULL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2029 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2030
23021
d10a37eb91ee patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents: 20707
diff changeset
2031 // Avoid triggering autocmds such as TextYankPost.
d10a37eb91ee patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents: 20707
diff changeset
2032 block_autocmds();
d10a37eb91ee patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents: 20707
diff changeset
2033
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2034 // Get the text between clip_star.start & clip_star.end
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2035 old_y_previous = get_y_previous();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2036 old_y_current = get_y_current();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2037 old_cursor = curwin->w_cursor;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2038 old_curswant = curwin->w_curswant;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2039 old_set_curswant = curwin->w_set_curswant;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2040 old_op_start = curbuf->b_op_start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2041 old_op_end = curbuf->b_op_end;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2042 old_visual = VIsual;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2043 old_visual_mode = VIsual_mode;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2044 clear_oparg(&oa);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2045 oa.regname = (cbd == &clip_plus ? '+' : '*');
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2046 oa.op_type = OP_YANK;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19774
diff changeset
2047 CLEAR_FIELD(ca);
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2048 ca.oap = &oa;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2049 ca.cmdchar = 'y';
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2050 ca.count1 = 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2051 ca.retval = CA_NO_ADJ_OP_END;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2052 do_pending_operator(&ca, 0, TRUE);
23467
826a6406ea7b patch 8.2.2276: list of distributed files is outdated
Bram Moolenaar <Bram@vim.org>
parents: 23021
diff changeset
2053
826a6406ea7b patch 8.2.2276: list of distributed files is outdated
Bram Moolenaar <Bram@vim.org>
parents: 23021
diff changeset
2054 // restore things
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2055 set_y_previous(old_y_previous);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2056 set_y_current(old_y_current);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2057 curwin->w_cursor = old_cursor;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2058 changed_cline_bef_curs(); // need to update w_virtcol et al
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2059 curwin->w_curswant = old_curswant;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2060 curwin->w_set_curswant = old_set_curswant;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2061 curbuf->b_op_start = old_op_start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2062 curbuf->b_op_end = old_op_end;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2063 VIsual = old_visual;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2064 VIsual_mode = old_visual_mode;
23021
d10a37eb91ee patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents: 20707
diff changeset
2065
d10a37eb91ee patch 8.2.2057: getting the selection may trigger TextYankPost autocmd
Bram Moolenaar <Bram@vim.org>
parents: 20707
diff changeset
2066 unblock_autocmds();
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2067 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2068 else if (!is_clipboard_needs_update())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2069 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2070 clip_free_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2071
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2072 // Try to get selected text from another window
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2073 clip_gen_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2074 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2075 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2076
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2077 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2078 * Convert from the GUI selection string into the '*'/'+' register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2079 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2080 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2081 clip_yank_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2082 int type,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2083 char_u *str,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2084 long len,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2085 Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2086 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2087 yankreg_T *y_ptr;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2088
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2089 if (cbd == &clip_plus)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2090 y_ptr = get_y_register(PLUS_REGISTER);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2091 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2092 y_ptr = get_y_register(STAR_REGISTER);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2093
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2094 clip_free_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2095
24790
14b86681e6e6 patch 8.2.2933: when 'clipboard' is "unnamed" zp does not work correctly
Bram Moolenaar <Bram@vim.org>
parents: 23467
diff changeset
2096 str_to_reg(y_ptr, type, str, len, -1, FALSE);
19774
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2097 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2098
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2099 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2100 * Convert the '*'/'+' register into a GUI selection string returned in *str
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2101 * with length *len.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2102 * Returns the motion type, or -1 for failure.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2103 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2104 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2105 clip_convert_selection(char_u **str, long_u *len, Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2106 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2107 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2108 int lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2109 int i, j;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2110 int_u eolsize;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2111 yankreg_T *y_ptr;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2112
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2113 if (cbd == &clip_plus)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2114 y_ptr = get_y_register(PLUS_REGISTER);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2115 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2116 y_ptr = get_y_register(STAR_REGISTER);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2117
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2118 # ifdef USE_CRNL
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2119 eolsize = 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2120 # else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2121 eolsize = 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2122 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2123
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2124 *str = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2125 *len = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2126 if (y_ptr->y_array == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2127 return -1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2128
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2129 for (i = 0; i < y_ptr->y_size; i++)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2130 *len += (long_u)STRLEN(y_ptr->y_array[i]) + eolsize;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2131
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2132 // Don't want newline character at end of last line if we're in MCHAR mode.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2133 if (y_ptr->y_type == MCHAR && *len >= eolsize)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2134 *len -= eolsize;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2135
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2136 p = *str = alloc(*len + 1); // add one to avoid zero
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2137 if (p == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2138 return -1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2139 lnum = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2140 for (i = 0, j = 0; i < (int)*len; i++, j++)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2141 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2142 if (y_ptr->y_array[lnum][j] == '\n')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2143 p[i] = NUL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2144 else if (y_ptr->y_array[lnum][j] == NUL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2145 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2146 # ifdef USE_CRNL
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2147 p[i++] = '\r';
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2148 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2149 p[i] = '\n';
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2150 lnum++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2151 j = -1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2152 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2153 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2154 p[i] = y_ptr->y_array[lnum][j];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2155 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2156 return y_ptr->y_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2157 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2158
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2159 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2160 * When "regname" is a clipboard register, obtain the selection. If it's not
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2161 * available return zero, otherwise return "regname".
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2162 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2163 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2164 may_get_selection(int regname)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2165 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2166 if (regname == '*')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2167 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2168 if (!clip_star.available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2169 regname = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2170 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2171 clip_get_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2172 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2173 else if (regname == '+')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2174 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2175 if (!clip_plus.available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2176 regname = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2177 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2178 clip_get_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2179 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2180 return regname;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2181 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2182
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2183 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2184 * If we have written to a clipboard register, send the text to the clipboard.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2185 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2186 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2187 may_set_selection(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2188 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2189 if ((get_y_current() == get_y_register(STAR_REGISTER))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2190 && clip_star.available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2191 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2192 clip_own_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2193 clip_gen_set_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2194 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2195 else if ((get_y_current() == get_y_register(PLUS_REGISTER))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2196 && clip_plus.available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2197 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2198 clip_own_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2199 clip_gen_set_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2200 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2201 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2202
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2203 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2204 * Adjust the register name pointed to with "rp" for the clipboard being
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2205 * used always and the clipboard being available.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2206 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2207 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2208 adjust_clip_reg(int *rp)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2209 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2210 // If no reg. specified, and "unnamed" or "unnamedplus" is in 'clipboard',
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2211 // use '*' or '+' reg, respectively. "unnamedplus" prevails.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2212 if (*rp == 0 && (clip_unnamed != 0 || clip_unnamed_saved != 0))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2213 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2214 if (clip_unnamed != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2215 *rp = ((clip_unnamed & CLIP_UNNAMED_PLUS) && clip_plus.available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2216 ? '+' : '*';
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2217 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2218 *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2219 && clip_plus.available) ? '+' : '*';
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2220 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2221 if (!clip_star.available && *rp == '*')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2222 *rp = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2223 if (!clip_plus.available && *rp == '+')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2224 *rp = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2225 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2226
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2227 #endif // FEAT_CLIPBOARD