annotate src/clipboard.c @ 19774:00a1b89256ea v8.2.0443

patch 8.2.0443: clipboard code is spread out Commit: https://github.com/vim/vim/commit/45fffdf10b7cb6e59794e76e9b8a2930fcb4b192 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Mar 24 21:42:01 2020 +0100 patch 8.2.0443: clipboard code is spread out Problem: Clipboard code is spread out. Solution: Move clipboard code to its own file. (Yegappan Lakshmanan, closes #5827)
author Bram Moolenaar <Bram@vim.org>
date Tue, 24 Mar 2020 21:45:04 +0100
parents
children aadd1cae2ff5
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
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 if (!redo_VIsual_busy && VIsual_active && (State & NORMAL))
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
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
145 && (get_real_state() == VISUAL
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
146 || get_real_state() == SELECTMODE)
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
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
198 && (get_real_state() == VISUAL
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
199 || get_real_state() == SELECTMODE)
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())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
202 && 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
203 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
204 update_curbuf(INVERTED_ALL);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
205 setcursor();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
206 cursor_on();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
207 out_flush_cursor(TRUE, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
208 }
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 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
211 }
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 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
214 clip_copy_selection(Clipboard_T *clip)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
215 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
216 if (VIsual_active && (State & NORMAL) && clip->available)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
217 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
218 clip_update_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
219 clip_free_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
220 clip_own_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
221 if (clip->owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
222 clip_get_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
223 clip_gen_set_selection(clip);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
224 }
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 * 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
229 * 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
230 * considerably.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
231 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
232 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
233 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
234 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
235
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 * Save clip_unnamed and reset it.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
238 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
239 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
240 start_global_changes(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
241 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
242 if (++global_change_count > 1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
243 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
244 clip_unnamed_saved = clip_unnamed;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
245 clipboard_needs_update = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
246
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
247 if (clip_did_set_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
248 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
249 clip_unnamed = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
250 clip_did_set_selection = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
251 }
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 * 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
256 * right text.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
257 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
258 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
259 is_clipboard_needs_update()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
260 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
261 return clipboard_needs_update;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
262 }
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 * 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
266 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
267 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
268 end_global_changes(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
269 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
270 if (--global_change_count > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
271 // recursive
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
272 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
273 if (!clip_did_set_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
274 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
275 clip_did_set_selection = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
276 clip_unnamed = clip_unnamed_saved;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
277 clip_unnamed_saved = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278 if (clipboard_needs_update)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
280 // only store something in the clipboard,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
281 // 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
282 if (clip_unnamed & CLIP_UNNAMED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
283 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
284 clip_own_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
285 clip_gen_set_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
286 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287 if (clip_unnamed & CLIP_UNNAMED_PLUS)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
289 clip_own_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 clip_gen_set_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
291 }
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 clipboard_needs_update = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
295 }
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 * 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
299 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
300 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
301 clip_auto_select(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
302 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
303 if (clip_isautosel_star())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
304 clip_copy_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
305 if (clip_isautosel_plus())
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
306 clip_copy_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
307 }
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 * 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
311 * register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
312 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
313 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
314 clip_isautosel_star(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
315 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
316 return (
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
317 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
318 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
319 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
320 clip_autoselect_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
321 }
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 * 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
325 * register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
326 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
327 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
328 clip_isautosel_plus(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
329 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 return (
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
332 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
333 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
334 clip_autoselect_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
335 }
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 * 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
340 */
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 * Compare two screen positions ala strcmp()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 clip_compare_pos(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347 int row1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 int col1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 int row2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350 int col2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
352 if (row1 > row2) return(1);
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 (col1 > col2) 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 return(0);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
357 }
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 // "how" flags for clip_invert_area()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
360 #define CLIP_CLEAR 1
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
361 #define CLIP_SET 2
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
362 #define CLIP_TOGGLE 3
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
363
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 * 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
366 * "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
367 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
368 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
369 clip_invert_rectangle(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
370 Clipboard_T *cbd UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
371 int row_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
372 int col_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
373 int height_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
374 int width_arg,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
375 int invert)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
376 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
377 int row = row_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
378 int col = col_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
379 int height = height_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
380 int width = width_arg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
381
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
382 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
383 // 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
384 screen_zindex = CLIP_ZINDEX;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
385
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
386 if (col < cbd->min_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
387 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
388 width -= cbd->min_col - col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
389 col = cbd->min_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
390 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
391 if (width > cbd->max_col - col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
392 width = cbd->max_col - col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
393 if (row < cbd->min_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
394 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
395 height -= cbd->min_row - row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
396 row = cbd->min_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
397 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
398 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
399 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 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
401 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
402 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
403 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
404 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
405 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
406 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
407 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
408 screen_zindex = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
409 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
410 }
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 * 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
414 * Values for "how":
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
415 * CLIP_CLEAR: undo inversion
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
416 * CLIP_SET: set inversion
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
417 * 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
418 * 0: invert (GUI only).
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
419 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
420 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
421 clip_invert_area(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
422 Clipboard_T *cbd,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
423 int row1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
424 int col1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
425 int row2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
426 int col2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
427 int how)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
428 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
429 int invert = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
430 int max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
431
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
432 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
433 max_col = cbd->max_col - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
434 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
435 max_col = Columns - 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
436 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
437
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
438 if (how == CLIP_SET)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
439 invert = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
440
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
441 // 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
442 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
443 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
444 int tmp_row, tmp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
445
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
446 tmp_row = row1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
447 tmp_col = col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
448 row1 = row2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
449 col1 = col2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
450 row2 = tmp_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
451 col2 = tmp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
452 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
453 else if (how == CLIP_TOGGLE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
454 invert = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
455
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
456 // 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
457 if (row1 == row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
458 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
459 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
460 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
461 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
462 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
463 // 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
464 if (col1 > 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
465 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
466 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
467 (int)Columns - col1, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
468 row1++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
469 }
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 // 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
472 if (col2 < max_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
473 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
474 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
475 row2--;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
476 }
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 // Handle the rectangle that's left
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
479 if (row2 >= row1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
480 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
481 (int)Columns, invert);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
482 }
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 * 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
487 * 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
488 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
489 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
490 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
491 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
492 int repeat;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
493
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
494 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
495 || clip_star.mode == SELECT_MODE_LINE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
496 && (mod_mask & MOD_MASK_2CLICK))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
497 || (clip_star.mode == SELECT_MODE_WORD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
498 && (mod_mask & MOD_MASK_3CLICK));
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
499 if (is_click && button == MOUSE_RIGHT)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
500 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
501 // 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
502 // Otherwise extend the existing selection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
503 if (clip_star.state == SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
504 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
505 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
506 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
507 else if (is_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
508 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
509 else if (is_drag)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
510 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
511 // 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
512 // 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
513 if (clip_star.state != SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
514 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
515 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
516 else // release
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
517 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
518 }
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 * 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
522 * 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
523 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
524 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
525 clip_update_modeless_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
526 Clipboard_T *cb,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
527 int row1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
528 int col1,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
529 int row2,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
530 int col2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
531 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 // 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
533 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
534 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
535 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
536 CLIP_TOGGLE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 cb->start.lnum = row1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
538 cb->start.col = col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
539 }
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 // 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
542 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
543 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
544 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
545 CLIP_TOGGLE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
546 cb->end.lnum = row2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
547 cb->end.col = col2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
548 }
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 * 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
553 * 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
554 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
555 #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
556
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
557 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
558 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
559 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
560 int start_class;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
561 int temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
562 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
563 int mboff;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
564
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
565 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
566 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
568 p = ScreenLines + LineOffset[row];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
569 // Correct for starting in the right halve of a double-wide char
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
570 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571 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
572 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
573 --col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
574 start_class = CHAR_CLASS(p[col]);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
575
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
576 temp_col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
577 for ( ; temp_col > 0; temp_col--)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
578 if (enc_dbcs != 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
579 && (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
580 temp_col -= mboff;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
581 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
582 && !(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
583 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
584 cb->word_start_col = temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
585
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
586 temp_col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
587 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
588 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
589 ++temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
590 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
591 && !(enc_utf8 && p[temp_col] == 0))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
592 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
593 cb->word_end_col = temp_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
594 }
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 * 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
598 * line at or before start_col.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
599 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
600 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
601 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
602 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
603 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
604
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
605 if (row >= screen_Rows || ScreenLines == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
606 return 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
607 for (i =
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
608 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
609 cbd->max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
610 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
611 screen_Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
612 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
613 i > 0; i--)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
614 if (ScreenLines[LineOffset[row] + i - 1] != ' ')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
615 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
616 return i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
617 }
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 * Start the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
621 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
622 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
623 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
624 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
625 Clipboard_T *cb = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
626 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 win_T *wp;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628 int row_cp = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 int col_cp = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 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
632 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
633 && 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
634 // 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
635 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 if (cb->state == SELECT_DONE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639 clip_clear_selection(cb);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 row = check_row(row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 col = check_col(col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 col = mb_fix_col(col, row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 cb->start.lnum = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 cb->start.col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 cb->end = cb->start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
648 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
649 cb->state = SELECT_IN_PROGRESS;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 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
652 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 // 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
654 // excluding the border.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 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
656 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
657 - 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
658 if (cb->max_col > screen_Columns)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 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->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
661 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
662 - wp->w_popup_border[2];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
663 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
664 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 cb->min_col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 cb->max_col = screen_Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 cb->min_row = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 cb->max_row = screen_Rows;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
673 if (repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
674 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675 if (++cb->mode > SELECT_MODE_LINE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
679 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
680
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
681 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 // 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
683 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684 gui_undraw_cursor();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 switch (cb->mode)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
688 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
689 case SELECT_MODE_CHAR:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
690 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
691 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
692 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 case SELECT_MODE_WORD:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 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
696 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
697 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
698
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
699 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
700 (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
701 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
702 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
703 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
704
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
705 case SELECT_MODE_LINE:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
706 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
707 (int)Columns, CLIP_SET);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
708 cb->start.col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 cb->end.col = Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 }
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 cb->prev = cb->start;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
714
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
715 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
716 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
717 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
718 }
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 * Continue processing the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
722 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
723 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
724 clip_process_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
725 int button,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
726 int col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
727 int row,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
728 int_u repeated_click)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
729 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
730 Clipboard_T *cb = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
731 int diff;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
732 int slen = 1; // cursor shape width
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
733
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
734 if (button == MOUSE_RELEASE)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
735 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
736 if (cb->state != SELECT_IN_PROGRESS)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
737 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
738
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
739 // 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
740 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
741 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
742 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
743 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
744 gui_update_cursor(FALSE, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
745 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
746 cb->state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
747 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748 }
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 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
751 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
752 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
753 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 if (clip_isautosel_star()
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 || (
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 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
758 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 clip_autoselectml))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 clip_copy_modeless_selection(FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 #ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 gui_update_cursor(FALSE, FALSE);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 cb->state = SELECT_DONE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
768 }
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 row = check_row(row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 col = check_col(col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 col = mb_fix_col(col, row);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 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
775 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
776
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 * 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
779 * 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
780 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
781 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
782 {
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 * 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
785 * 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
786 * end of the selection.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
787 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
788 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
789 || (clip_compare_pos(row, col,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
790 (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
791 && (((cb->start.lnum == cb->end.lnum
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
792 && 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
793 || ((diff = (cb->end.lnum - row) -
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
794 (row - cb->start.lnum)) > 0
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
795 || (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
796 cb->end.col) / 2)))))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
797 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
798 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
799 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
800 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
801 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 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
805 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
806 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
807 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
808 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
809 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 }
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 // 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
813 cb->state = SELECT_IN_PROGRESS;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816 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
817 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
819 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
820 cb->mode = SELECT_MODE_CHAR;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 switch (cb->mode)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
824 case SELECT_MODE_CHAR:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
825 // 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
826 if (row != cb->prev.lnum)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
827 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
828
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
829 // 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
830 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
831 cb->origin_start_col) >= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
832 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
833 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
834 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
835 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
836 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
838 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
839 slen = 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
840 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
841 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
842 }
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 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
845 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
846 if (has_mbyte
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
847 && 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
848 slen = 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
849 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
850 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
851 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
852 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
853 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
854 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
855 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
856 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
857
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
858 case SELECT_MODE_WORD:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
859 // 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
860 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
861 && 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
862 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 // Get new word boundaries
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865 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
866
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
867 // 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
868 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
869 cb->origin_start_col) >= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
870 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
871 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
872 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
873 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
874 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
875 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 case SELECT_MODE_LINE:
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 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
879 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
880
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
881 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
882 cb->origin_start_col) >= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
883 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
884 (int)Columns);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
885 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
886 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
887 (int)Columns);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
888 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
889 }
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 cb->prev.lnum = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
892 cb->prev.col = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
893
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
894 #ifdef DEBUG_SELECTION
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
895 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
896 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
897 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 }
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 # if defined(FEAT_GUI) || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 * 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
903 * Only used for the GUI.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
905 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
906 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
907 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
908 int start = col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
909 int end = col + len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
910
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
911 if (clip_star.state != SELECT_CLEARED
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
912 && row >= clip_star.start.lnum
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
913 && row <= clip_star.end.lnum)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
914 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
915 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
916 start = clip_star.start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
917 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
918 end = clip_star.end.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
919 if (end > start)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
920 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
921 }
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 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
924
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 * 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
927 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 clip_clear_selection(Clipboard_T *cbd)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930 {
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 if (cbd->state == SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
933 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
934
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
935 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
936 (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
937 cbd->state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
938 }
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 * 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
942 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
943 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
944 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
945 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
946 if (clip_star.state == SELECT_DONE
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
947 && row2 >= clip_star.start.lnum
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
948 && row1 <= clip_star.end.lnum)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
949 clip_clear_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
950 }
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 * 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
954 * 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
955 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
956 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
957 clip_scroll_selection(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
958 int rows) // negative for scroll down
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
959 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
960 int lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
961
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
962 if (clip_star.state == SELECT_CLEARED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
963 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
964
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
965 lnum = clip_star.start.lnum - rows;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
966 if (lnum <= 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
967 clip_star.start.lnum = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
968 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
969 clip_star.state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
970 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
971 clip_star.start.lnum = lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
972
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
973 lnum = clip_star.end.lnum - rows;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
974 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
975 clip_star.state = SELECT_CLEARED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
976 else if (lnum >= screen_Rows)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
977 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
978 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
979 clip_star.end.lnum = lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
980 }
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 * 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
984 * available for pasting.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
985 * 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
986 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
987 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
988 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
989 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
990 char_u *buffer;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
991 char_u *bufp;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
992 int row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
993 int start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
994 int end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
995 int line_end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
996 int add_newline_flag = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
997 int len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
998 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
999 int row1 = clip_star.start.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1000 int col1 = clip_star.start.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1001 int row2 = clip_star.end.lnum;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1002 int col2 = clip_star.end.col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1003
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1004 // Can't use ScreenLines unless initialized
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1005 if (ScreenLines == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1006 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1007
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 * 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
1010 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1011 if (row1 > row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1012 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1013 row = row1; row1 = row2; row2 = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1014 row = col1; col1 = col2; col2 = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1015 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1016 else if (row1 == row2 && col1 > col2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1017 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1018 row = col1; col1 = col2; col2 = row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1019 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1020 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1021 if (col1 < clip_star.min_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1022 col1 = clip_star.min_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1023 if (col2 > clip_star.max_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1024 col2 = clip_star.max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1025 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
1026 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1027 if (row1 < clip_star.min_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1028 row1 = clip_star.min_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1029 if (row2 > clip_star.max_row)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1030 row2 = clip_star.max_row;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1031 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1032 // correct starting point for being on right halve of double-wide char
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1033 p = ScreenLines + LineOffset[row1];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1034 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1035 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
1036 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
1037 --col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1038
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1039 // 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
1040 len = (row2 - row1 + 1) * Columns + 1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1041 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1042 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
1043 else if (enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1044 len *= MB_MAXBYTES;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1045 buffer = alloc(len);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1046 if (buffer == NULL) // out of memory
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1047 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1048
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1049 // Process each row in the selection
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1050 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
1051 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1052 if (row == row1)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1053 start_col = col1;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1054 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1055 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1056 start_col = clip_star.min_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1057 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1058 start_col = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1059 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1060
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1061 if (row == row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1062 end_col = col2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1063 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1064 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1065 end_col = clip_star.max_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1066 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1067 end_col = Columns;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1068 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1069
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1070 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
1071
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1072 // 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
1073 if (end_col >=
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1074 #ifdef FEAT_PROP_POPUP
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1075 clip_star.max_col
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1076 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1077 Columns
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1078 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1079 && (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
1080 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1081 // Get rid of trailing whitespace
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1082 end_col = line_end_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1083 if (end_col < start_col)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1084 end_col = start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1085
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1086 // 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
1087 if (row == row2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1088 add_newline_flag = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1089 }
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 // 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
1092 if (row > row1 && !LineWraps[row - 1])
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1093 *bufp++ = NL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1094
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1095 // 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
1096 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
1097 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1098 if (enc_dbcs != 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1099 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1100 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1101
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1102 p = ScreenLines + LineOffset[row];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1103 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
1104 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
1105 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1106 // single-width double-byte char
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1107 *bufp++ = 0x8e;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1108 *bufp++ = ScreenLines2[LineOffset[row] + i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1109 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1110 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1111 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1112 *bufp++ = p[i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1113 if (MB_BYTE2LEN(p[i]) == 2)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1114 *bufp++ = p[++i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1115 }
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 else if (enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1118 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1119 int off;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1120 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1121 int ci;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1122
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1123 off = LineOffset[row];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1124 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
1125 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1126 // 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
1127 // ScreenLines[].
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1128 if (ScreenLinesUC[off + i] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1129 *bufp++ = ScreenLines[off + i];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1130 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1131 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1132 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
1133 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
1134 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1135 // Add a composing character.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1136 if (ScreenLinesC[ci][off + i] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1137 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1138 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
1139 bufp);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1140 }
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 // Skip right halve of double-wide character.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1143 if (ScreenLines[off + i + 1] == 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1144 ++i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1145 }
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 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1148 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1149 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
1150 end_col - start_col);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1151 bufp += end_col - start_col;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1152 }
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 // 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
1157 if (add_newline_flag)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1158 *bufp++ = NL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1159
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1160 // 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
1161 clip_free_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1162 clip_own_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1163
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1164 // Yank the text into the '*' register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1165 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
1166
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1167 // 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
1168 clip_gen_set_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1169
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1170 #ifdef FEAT_X11
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1171 if (both)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1172 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1173 // Do the same for the '+' register.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1174 clip_free_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1175 clip_own_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1176 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
1177 clip_gen_set_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1178 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1179 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1180 vim_free(buffer);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1181 }
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 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1184 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
1185 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 if (!clip_did_set_selection)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1187 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1188 // 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
1189 // 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
1190 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
1191 || (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
1192 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1193 clipboard_needs_update = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1194 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1195 }
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 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1199 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1200 clip_mch_set_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1201 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1202 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1203 clip_xterm_set_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1204 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1205 clip_mch_set_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1206 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1207 }
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 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1210 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
1211 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1212 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 # ifdef FEAT_GUI
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1214 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 clip_mch_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1218 clip_xterm_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1219 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1220 clip_mch_request_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1221 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1222 }
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 #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
1225 || defined(PROTO)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1226 static int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1227 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
1228 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1229 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
1230 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1231 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1232
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1233 #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
1234 int
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1235 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
1236 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1237 #ifdef FEAT_XCLIPBOARD
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1238 # ifdef FEAT_GUI_GTK
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1239 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1240 return clip_gtk_owner_exists(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1241 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1242 # endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1243 return clip_x11_owner_exists(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1244 #else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1245 return TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1246 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1247 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1248 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1249
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 * 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
1252 * 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
1253 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1254 char *
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1255 check_clipboard_option(void)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1256 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1257 int new_unnamed = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1258 int new_autoselect_star = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1259 int new_autoselect_plus = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1260 int new_autoselectml = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1261 int new_html = FALSE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1262 regprog_T *new_exclude_prog = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1263 char *errmsg = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1264 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1265
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1266 for (p = p_cb; *p != NUL; )
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1267 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1268 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
1269 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1270 new_unnamed |= CLIP_UNNAMED;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1271 p += 7;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1272 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1273 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
1274 && (p[11] == ',' || p[11] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1276 new_unnamed |= CLIP_UNNAMED_PLUS;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277 p += 11;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 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
1280 && (p[10] == ',' || p[10] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1282 new_autoselect_star = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1283 p += 10;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1284 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1285 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
1286 && (p[14] == ',' || p[14] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1287 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1288 new_autoselect_plus = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1289 p += 14;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1290 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1291 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
1292 && (p[12] == ',' || p[12] == NUL))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1293 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1294 new_autoselectml = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1295 p += 12;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1296 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1297 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
1298 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 new_html = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 p += 4;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1301 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1302 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
1303 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1304 p += 8;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1305 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
1306 if (new_exclude_prog == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1307 errmsg = e_invarg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1308 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1309 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1310 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1311 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1312 errmsg = e_invarg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1313 break;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1314 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315 if (*p == ',')
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1316 ++p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1317 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1318 if (errmsg == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1319 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1320 clip_unnamed = new_unnamed;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1321 clip_autoselect_star = new_autoselect_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1322 clip_autoselect_plus = new_autoselect_plus;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1323 clip_autoselectml = new_autoselectml;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1324 clip_html = new_html;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1325 vim_regfree(clip_exclude_prog);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1326 clip_exclude_prog = new_exclude_prog;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 #ifdef FEAT_GUI_GTK
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1328 if (gui.in_use)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1329 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330 gui_gtk_set_selection_targets();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 gui_gtk_set_dnd_targets();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 #endif
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1335 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 vim_regfree(new_exclude_prog);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1338 return errmsg;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1339 }
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 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 * 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
1343 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1344
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1345 #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
1346 # include <X11/Xatom.h>
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1347 # include <X11/Intrinsic.h>
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1348
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 * Open the application context (if it hasn't been opened yet).
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1351 * Used for Motif and Athena GUI and the xterm clipboard.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1353 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1354 open_app_context(void)
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 if (app_context == NULL)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 XtToolkitInitialize();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359 app_context = XtCreateApplicationContext();
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1360 }
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
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 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
1364 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
1365 static Atom utf8_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1366 static Atom compound_text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 static Atom text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 static Atom targets_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 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
1370
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1371 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1372 x11_setup_atoms(Display *dpy)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1373 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1374 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
1375 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
1376 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
1377 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
1378 text_atom = XInternAtom(dpy, "TEXT", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1379 targets_atom = XInternAtom(dpy, "TARGETS", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1380 clip_star.sel_atom = XA_PRIMARY;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1381 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
1382 timestamp_atom = XInternAtom(dpy, "TIMESTAMP", False);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1383 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1384
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1385 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 * 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
1387 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1388
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1389 static Boolean
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1390 clip_x11_convert_selection_cb(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1391 Widget w UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1392 Atom *sel_atom,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1393 Atom *target,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1394 Atom *type,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1395 XtPointer *value,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1396 long_u *length,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1397 int *format)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1398 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1399 static char_u *save_result = NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1400 static long_u save_length = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1401 char_u *string;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1402 int motion_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1403 Clipboard_T *cbd;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1404 int i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1405
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1406 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
1407 cbd = &clip_plus;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1408 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1409 cbd = &clip_star;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1410
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1411 if (!cbd->owned)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1412 return False; // Shouldn't ever happen
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1413
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1414 // 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
1415 if (*target == targets_atom)
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 static Atom array[7];
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1418
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1419 *value = (XtPointer)array;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1420 i = 0;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1421 array[i++] = targets_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1422 array[i++] = vimenc_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1423 array[i++] = vim_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1424 if (enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1425 array[i++] = utf8_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1426 array[i++] = XA_STRING;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1427 array[i++] = text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1428 array[i++] = compound_text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1429
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1430 *type = XA_ATOM;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1431 // 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
1432 // 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
1433 *format = 32;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1434 *length = i;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1435 return True;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1436 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1437
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1438 if ( *target != XA_STRING
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1439 && *target != vimenc_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1440 && (*target != utf8_atom || !enc_utf8)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1441 && *target != vim_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1442 && *target != text_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1443 && *target != compound_text_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1444 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1445
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1446 clip_get_selection(cbd);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1447 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
1448 if (motion_type < 0)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1449 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1450
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1451 // 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
1452 if (*target == vim_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1453 (*length)++;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1454
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1455 // 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
1456 if (*target == vimenc_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1457 *length += STRLEN(p_enc) + 2;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1458
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1459 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
1460 *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
1461 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1462 *value = save_result;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1463 if (*value == NULL)
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 vim_free(string);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1466 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1467 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1468 save_result = (char_u *)*value;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1469 save_length = *length;
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 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
1472 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1473 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
1474 *type = *target;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1475 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1476 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
1477 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1478 XTextProperty text_prop;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1479 char *string_nt = (char *)save_result;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1480 int conv_result;
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 // 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
1483 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
1484 string_nt[*length] = NUL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1485 conv_result = XmbTextListToTextProperty(X_DISPLAY, (char **)&string_nt,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1486 1, XCompoundTextStyle, &text_prop);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1487 if (conv_result != Success)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1488 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1489 vim_free(string);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1490 return False;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1491 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1492 *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
1493 *length = text_prop.nitems;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1494 *type = compound_text_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1495 XtFree((char *)save_result);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1496 save_result = (char_u *)*value;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1497 save_length = *length;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1498 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1499 else if (*target == vimenc_atom)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1500 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1501 int l = STRLEN(p_enc);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1502
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1503 save_result[0] = motion_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1504 STRCPY(save_result + 1, p_enc);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1505 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
1506 *type = vimenc_atom;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1507 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1508 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1509 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1510 save_result[0] = motion_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1511 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
1512 *type = vim_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 *format = 8; // 8 bits per char
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1515 vim_free(string);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1516 return True;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1517 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1518
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1519 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1520 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
1521 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1522 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
1523 clip_lose_selection(&clip_plus);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1524 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1525 clip_lose_selection(&clip_star);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1526 }
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 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1529 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
1530 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1531 // 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
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 /*
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 * 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
1536 */
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 clip_x11_timestamp_cb(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 Widget w,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 XtPointer n UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1541 XEvent *event,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542 Boolean *cont UNUSED)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 Atom actual_type;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 int format;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 unsigned long nitems, bytes_after;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 unsigned char *prop=NULL;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 XPropertyEvent *xproperty=&event->xproperty;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1550 // 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
1551 // one of the supported selection types.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1552 if (event->type != PropertyNotify || xproperty->state
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 || (xproperty->atom != clip_star.sel_atom
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 && xproperty->atom != clip_plus.sel_atom))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555 return;
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 if (XGetWindowProperty(xproperty->display, xproperty->window,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1558 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
1559 &nitems, &bytes_after, &prop))
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1560 return;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1561
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1562 if (prop)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1563 XFree(prop);
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1564
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1565 // 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
1566 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
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 // 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
1570 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
1571 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
1572 clip_x11_notify_cb) == OK)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1573 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1574 // 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
1575 // lose_ownership_cb in between.
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1576 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
1577 clip_plus.owned = TRUE;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1578 else
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1579 clip_star.owned = TRUE;
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 }
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1582
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1583 void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1584 x11_setup_selection(Widget w)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1585 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1586 XtAddEventHandler(w, PropertyChangeMask, False,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1587 /*(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
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 static void
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1591 clip_x11_request_selection_cb(
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1592 Widget w UNUSED,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1593 XtPointer success,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1594 Atom *sel_atom,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1595 Atom *type,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1596 XtPointer value,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1597 long_u *length,
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1598 int *format)
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1599 {
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1600 int motion_type = MAUTO;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1601 long_u len;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1602 char_u *p;
00a1b89256ea patch 8.2.0443: clipboard code is spread out
Bram Moolenaar <Bram@vim.org><