annotate src/popupmenu.c @ 716:8ae24f338cab v7.0217

updated for version 7.0217
author vimboss
date Tue, 07 Mar 2006 22:38:47 +0000
parents d6a69271cb9a
children 44348703ab1b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4:
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
2 *
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
4 *
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
8 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
9
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
10 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
11 * popupmenu.c: Popup menu (PUM)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
12 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
13 #include "vim.h"
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
14
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
15 #if defined(FEAT_INS_EXPAND) || defined(PROTO)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
16
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
17 static pumitem_T *pum_array = NULL; /* items of displayed pum */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
18 static int pum_size; /* nr of items in "pum_array" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
19 static int pum_selected; /* index of selected item or -1 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
20 static int pum_first = 0; /* index of top item */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
21
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
22 static int pum_height; /* nr of displayed pum items */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
23 static int pum_width; /* width of displayed pum items */
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
24 static int pum_base_width; /* width of pum items base */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
25 static int pum_scrollbar; /* TRUE when scrollbar present */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
26
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
27 static int pum_row; /* top row of pum */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
28 static int pum_col; /* left column of pum */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
29
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
30 #define PUM_DEF_HEIGHT 10
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
31 #define PUM_DEF_WIDTH 15
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
32
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
33 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
34 * Show the popup menu with items "array[size]".
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
35 * "array" must remain valid until pum_undisplay() is called!
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
36 * When possible the leftmost character is aligned with screen column "col".
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
37 * The menu appears above the screen line "row" or at "row" + "height" - 1.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
38 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
39 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
40 pum_display(array, size, selected, row, height, col)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
41 pumitem_T *array;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
42 int size;
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
43 int selected; /* index of initially selected item, none if
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
44 out of range */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
45 int row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
46 int height;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
47 int col;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
48 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
49 int w;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
50 int def_width = PUM_DEF_WIDTH;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
51 int max_width = 0;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
52 int extra_width = 0;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
53 int i;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
54
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
55 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
56 * Figure out the size and position of the pum.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
57 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
58 if (size < PUM_DEF_HEIGHT)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
59 pum_height = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
60 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
61 pum_height = PUM_DEF_HEIGHT;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
62
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
63 /* Put the pum below "row" if possible. If there are few lines decide on
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
64 * where there is more room. */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
65 if (row >= cmdline_row - pum_height && row > (cmdline_row - height) / 2)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
66 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
67 /* pum above "row" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
68 if (row >= size)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
69 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
70 pum_row = row - size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
71 pum_height = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
72 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
73 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
74 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
75 pum_row = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
76 pum_height = row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
77 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
78 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
79 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
80 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
81 /* pum below "row" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
82 pum_row = row + height;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
83 if (size > cmdline_row - pum_row)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
84 pum_height = cmdline_row - pum_row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
85 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
86 pum_height = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
87 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
88
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
89 /* don't display when we only have room for one line */
657
b112ec5c73f0 updated for version 7.0193
vimboss
parents: 642
diff changeset
90 if (pum_height < 1 || (pum_height == 1 && size > 1))
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
91 return;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
92
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
93 /* Compute the width of the widest match and the widest extra. */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
94 for (i = 0; i < size; ++i)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
95 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
96 w = vim_strsize(array[i].pum_text);
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
97 if (max_width < w)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
98 max_width = w;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
99 if (array[i].pum_extra != NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
100 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
101 w = vim_strsize(array[i].pum_extra);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
102 if (extra_width < w)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
103 extra_width = w;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
104 }
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
105 }
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
106 pum_base_width = max_width;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
107
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
108 /* if there are more items than room we need a scrollbar */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
109 if (pum_height < size)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
110 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
111 pum_scrollbar = 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
112 ++max_width;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
113 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
114 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
115 pum_scrollbar = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
116
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
117 if (def_width < max_width)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
118 def_width = max_width;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
119
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
120 if (col < Columns - PUM_DEF_WIDTH || col < Columns - max_width)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
121 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
122 /* align pum column with "col" */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
123 pum_col = col;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
124 pum_width = Columns - pum_col - pum_scrollbar;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
125 if (pum_width > max_width + extra_width + 1
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
126 && pum_width > PUM_DEF_WIDTH)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
127 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
128 pum_width = max_width + extra_width + 1;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
129 if (pum_width < PUM_DEF_WIDTH)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
130 pum_width = PUM_DEF_WIDTH;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
131 }
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
132 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
133 else if (Columns < def_width)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
134 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
135 /* not enough room, will use what we have */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
136 pum_col = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
137 pum_width = Columns - 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
138 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
139 else
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
140 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
141 if (max_width > PUM_DEF_WIDTH)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
142 max_width = PUM_DEF_WIDTH; /* truncate */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
143 pum_col = Columns - max_width;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
144 pum_width = max_width - pum_scrollbar;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
145 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
146
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
147 pum_array = array;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
148 pum_size = size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
149
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
150 /* Set selected item and redraw. */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
151 pum_set_selected(selected);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
152 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
153
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
154 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
155 * Redraw the popup menu, using "pum_first" and "pum_selected".
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
156 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
157 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
158 pum_redraw()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
159 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
160 int row = pum_row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
161 int col;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
162 int attr_norm = highlight_attr[HLF_PNI];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
163 int attr_select = highlight_attr[HLF_PSI];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
164 int attr_scroll = highlight_attr[HLF_PSB];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
165 int attr_thumb = highlight_attr[HLF_PST];
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
166 int attr;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
167 int i;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
168 int idx;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
169 char_u *s;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
170 char_u *p;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
171 int totwidth, width, w;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
172 int thumb_pos = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
173 int thumb_heigth = 1;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
174 int round;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
175
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
176 if (pum_scrollbar)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
177 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
178 thumb_heigth = pum_height * pum_height / pum_size;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
179 if (thumb_heigth == 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
180 thumb_heigth = 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
181 thumb_pos = (pum_first * (pum_height - thumb_heigth)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
182 + (pum_size - pum_height) / 2)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
183 / (pum_size - pum_height);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
184 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
185
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
186 for (i = 0; i < pum_height; ++i)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
187 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
188 idx = i + pum_first;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
189 attr = (idx == pum_selected) ? attr_select : attr_norm;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
190
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
191 /* prepend a space if there is room */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
192 if (pum_col > 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
193 screen_putchar(' ', row, pum_col - 1, attr);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
194
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
195 /* Display each entry, use two spaces for a Tab.
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
196 * Do this twice: For the main text and for the extra info */
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
197 col = pum_col;
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
198 totwidth = 0;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
199 for (round = 1; round <= 2; ++round)
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
200 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
201 width = 0;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
202 s = NULL;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
203 for (p = round == 1 ? pum_array[idx].pum_text
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
204 : pum_array[idx].pum_extra; ; mb_ptr_adv(p))
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
205 {
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
206 if (s == NULL)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
207 s = p;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
208 w = ptr2cells(p);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
209 if (*p == NUL || *p == TAB || totwidth + w > pum_width)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
210 {
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
211 /* Display the text that fits or comes before a Tab. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
212 screen_puts_len(s, p - s, row, col, attr);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
213 col += width;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
214
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
215 if (*p != TAB)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
216 break;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
217
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
218 /* Display two spaces for a Tab. */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
219 screen_puts_len((char_u *)" ", 2, row, col, attr);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
220 col += 2;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
221 totwidth += 2;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
222 s = NULL; /* start text at next char */
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
223 width = 0;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
224 }
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
225 else
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
226 width += w;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
227 }
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
228 if (round == 2 || pum_array[idx].pum_extra == NULL
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
229 || pum_base_width + 1 >= pum_width)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
230 break;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
231 screen_fill(row, row + 1, col, pum_col + pum_base_width + 1,
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
232 ' ', ' ', attr);
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
233 col = pum_col + pum_base_width + 1;
d6a69271cb9a updated for version 7.0194
vimboss
parents: 657
diff changeset
234 totwidth = pum_base_width + 1;
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
235 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
236
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
237 screen_fill(row, row + 1, col, pum_col + pum_width, ' ', ' ', attr);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
238 if (pum_scrollbar > 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
239 screen_putchar(' ', row, pum_col + pum_width,
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
240 i >= thumb_pos && i < thumb_pos + thumb_heigth
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
241 ? attr_thumb : attr_scroll);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
242
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
243 ++row;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
244 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
245 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
246
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
247 #if 0 /* not used yet */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
248 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
249 * Return the index of the currently selected item.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
250 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
251 int
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
252 pum_get_selected()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
253 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
254 return pum_selected;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
255 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
256 #endif
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
257
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
258 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
259 * Set the index of the currently selected item. The menu will scroll when
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
260 * necessary. When "n" is out of range don't scroll.
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
261 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
262 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
263 pum_set_selected(n)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
264 int n;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
265 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
266 pum_selected = n;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
267
716
8ae24f338cab updated for version 7.0217
vimboss
parents: 659
diff changeset
268 if (pum_selected >= 0 && pum_selected < pum_size)
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
269 {
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
270 if (pum_first > pum_selected - 4)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
271 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
272 /* scroll down; when we did a jump it's probably a PageUp then
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
273 * scroll a whole page */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
274 if (pum_first > pum_selected - 2)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
275 {
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
276 pum_first -= pum_height - 2;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
277 if (pum_first < 0)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
278 pum_first = 0;
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
279 else if (pum_first > pum_selected)
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
280 pum_first = pum_selected;
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
281 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
282 else
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
283 pum_first = pum_selected;
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
284 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
285 else if (pum_first < pum_selected - pum_height + 5)
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
286 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
287 /* scroll up; when we did a jump it's probably a PageDown then
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
288 * scroll a whole page */
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
289 if (pum_first < pum_selected - pum_height + 1 + 2)
642
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
290 {
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
291 pum_first += pum_height - 2;
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
292 if (pum_first < pum_selected - pum_height + 1)
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
293 pum_first = pum_selected - pum_height + 1;
2392a6da4aa4 updated for version 7.0186
vimboss
parents: 610
diff changeset
294 }
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
295 else
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
296 pum_first = pum_selected - pum_height + 1;
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
297 }
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
298
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
299 if (pum_height > 6)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
300 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
301 /* Give three lines of context when possible. */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
302 if (pum_first > pum_selected - 3)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
303 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
304 /* scroll down */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
305 pum_first = pum_selected - 3;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
306 if (pum_first < 0)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
307 pum_first = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
308 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
309 else if (pum_first < pum_selected + 3 - pum_height + 1)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
310 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
311 /* scroll up */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
312 pum_first = pum_selected + 3 - pum_height + 1;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
313 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
314 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
315 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
316
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
317 /* Never display more than we have */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
318 if (pum_first > pum_size - pum_height)
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
319 pum_first = pum_size - pum_height;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
320
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
321 pum_redraw();
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
322 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
323
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
324 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
325 * Undisplay the popup menu (later).
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
326 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
327 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
328 pum_undisplay()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
329 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
330 pum_array = NULL;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
331 redraw_all_later(NOT_VALID);
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
332 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
333
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
334 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
335 * Clear the popup menu. Currently only resets the offset to the first
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
336 * displayed item.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
337 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
338 void
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
339 pum_clear()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
340 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
341 pum_first = 0;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
342 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
343
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
344 /*
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
345 * Return TRUE if the popup menu is displayed.
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
346 */
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
347 int
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
348 pum_visible()
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
349 {
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
350 return pum_array != NULL;
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
351 }
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
352
610
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
353 /*
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
354 * Return the height of the popup menu, the number of entries visible.
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
355 * Only valid when pum_visible() returns TRUE!
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
356 */
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
357 int
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
358 pum_get_height()
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
359 {
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
360 return pum_height;
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
361 }
cd3689efd90a updated for version 7.0173
vimboss
parents: 545
diff changeset
362
545
7a10f094c6bb updated for version 7.0154
vimboss
parents:
diff changeset
363 #endif