Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 628 lines (549 sloc) 16.214 kb
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
1 /* window.c */
2 /* Copyright 1995 by Steve Kirkendall */
3
4
5 #include "elvis.h"
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
6 #ifdef FEATURE_RCSID
2fe6e17 Martin Dietze Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
7 char id_window[] = "$Id: window.c,v 2.74 2004/03/19 16:43:08 steve Exp $";
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
8 #endif
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
9
10 #if USE_PROTOTYPES
11 static int setwm(OPTDESC *desc, OPTVAL *val, CHAR *newval);
12 static CHAR *getwm(OPTDESC *desc, OPTVAL *val);
13 #endif
14
15
16 WINDOW windows; /* list of all windows */
17 WINDOW windefault; /* the window whose options are current */
18 WINDOWBUF windefopts; /* fake window, stores the default window options */
19
20 /* Set the wrapmargin value. This actually sets the buffer's textwidth
21 * option instead of the window's wrapmargin option.
22 */
23 static int setwm(desc, val, newval)
24 OPTDESC *desc; /* description of the option */
25 OPTVAL *val; /* value of the option */
26 CHAR *newval;/* value the option should have (as a string) */
27 {
28 WINDOW win = (WINDOW)val->value.pointer;
29 BUFFER buf;
30 long l;
31
32 assert(win == windefault || win == &windefopts);
33
34 /* choose a buffer */
35 buf = (win->cursor ? markbuffer(win->cursor) : bufdefopts);
36
37 /* check for bad value */
38 if (!calcnumber(newval))
39 {
40 msg(MSG_ERROR, "[s]$1 must be number", desc->longname);
41 return -1;
42 }
43 l = CHAR2long(newval);
44 if (l < 0 || l >= o_columns(win))
45 {
46 msg(MSG_ERROR, "[sd]$1 must be between 0 and $2", desc->longname, o_columns(win));
47 return -1;
48 }
49
50 /* compute the new value of textwidth */
51 if (l != 0)
52 {
53 l = o_columns(win) - l;
54 }
55
56 /* store the value, if changed */
57 if (l != o_textwidth(buf))
58 {
59 o_textwidth(buf) = l;
60 optflags(o_textwidth(buf)) |= OPT_SET;
61 }
62
63 /* wrapmargin itself never changes */
64 return 0;
65 }
66
67 /* This value computes a value for wrapmargin, based on the window's "columns"
68 * option and the buffer's "textwidth" option. If the window's "columns" is
69 * less than or equal to the buffer's "textwidth", this function will return
70 * "wide" instead of a number because the "wrapmargin" option doesn't allow
71 * setting textwidth to a value wider than the window.
72 */
73 static CHAR *getwm(desc, val)
74 OPTDESC *desc; /* description of the option */
75 OPTVAL *val; /* value of the option */
76 {
77 static CHAR str[12];
78 WINDOW win = (WINDOW)val->value.pointer;
3a9bb55 Martin Dietze Import Elvis 2.1_3 (written by Steve Kirkendall)
authored
79 BUFFER buf;
80
81 /* special case: during initialization, always return "0" because
82 * that's always the default value for wrapmargin. Any other value
83 * would be dependent on the screen width.
84 */
85 if (!win || !win->cursor)
86 return toCHAR("0");
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
87
88 assert(win == windefault);
89
3a9bb55 Martin Dietze Import Elvis 2.1_3 (written by Steve Kirkendall)
authored
90 buf = markbuffer(win->cursor);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
91 if (o_textwidth(buf) >= o_columns(win))
92 {
93 CHARcpy(str, toCHAR("wide"));
94 }
95 else if (o_textwidth(buf) == 0)
96 {
97 CHARcpy(str, toCHAR("0"));
98 }
99 else
100 {
101 long2CHAR(str, o_columns(win) - o_textwidth(buf));
102 }
103 return str;
104 }
105
106
107 static OPTDESC wdesc[] =
108 {
109 {"windowid", "id", optnstring, optisnumber },
110 #if defined (GUI_WIN32)
111 {"columns", "cols", optnstring, optiswinsize },
112 {"lines", "rows", optnstring, optiswinsize },
113 #else
114 {"columns", "cols", optnstring, optisnumber },
115 {"lines", "rows", optnstring, optisnumber },
116 #endif
117 {"list", "li", NULL, NULL },
118 {"display", "mode", optsstring, optisstring },
119 {"number", "nu", NULL, NULL },
120 {"ruler", "ru", NULL, NULL },
121 {"scroll", "scr", optnstring, optisnumber },
122 {"showmatch", "sm", NULL, NULL },
123 {"showmode", "smd", NULL, NULL },
124 {"wrap", "wr", NULL, NULL },
125 {"sidescroll", "ss", optnstring, optisnumber, "1:30" },
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
126 {"wrapmargin", "wm", getwm, setwm },
127 {"hasfocus", "hf", NULL, NULL },
128 {"folding", "fold", NULL, NULL },
129 {"hllayers", "hll", optnstring, optisnumber, "0:30" },
130 {"eventcounter", "evct",optnstring, optisnumber },
131 {"ww", "ww", optsstring, optisstring }
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
132 };
133
134 /* Initialize the window module. Mostly this makes the windefopts variable
135 * act as the current window, so that window options can be set during
136 * initialization, before any real windows have been created.
137 */
138 void wininit()
139 {
140 /* initialize the options */
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
141 optpreset(o_display(&windefopts), toCHAR("normal"), OPT_HIDE|OPT_LOCK);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
142 optflags(o_windowid(&windefopts)) = OPT_LOCK|OPT_HIDE;
143 #if defined (GUI_WIN32)
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
144 optpreset(o_columns(&windefopts), 80, OPT_SET|OPT_NODFLT);
145 optpreset(o_lines(&windefopts), 25, OPT_SET|OPT_NODFLT);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
146 #else
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
147 optpreset(o_columns(&windefopts), 80, OPT_SET|OPT_LOCK|OPT_NODFLT);
148 optpreset(o_lines(&windefopts), 24, OPT_SET|OPT_LOCK|OPT_NODFLT);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
149 #endif
150 o_scroll(&windefopts) = 12;
151 windefopts.wrapmargin.value.pointer = (void *)&windefopts;
152 windefopts.wrapmargin.flags = OPT_REDRAW|OPT_HIDE;
153 optflags(o_list(&windefopts)) = OPT_REDRAW;
154 optflags(o_number(&windefopts)) = OPT_REDRAW;
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
155 optpreset(o_wrap(&windefopts), ElvTrue, OPT_REDRAW);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
156 o_sidescroll(&windefopts) = 8;
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
157 optpreset(o_folding(&windefopts), ElvTrue, OPT_REDRAW|OPT_HIDE);
158 optpreset(o_hllayers(&windefopts), 0L, OPT_REDRAW|OPT_HIDE);
159 optflags(o_ww(&windefopts)) = OPT_NODFLT|OPT_HIDE;
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
160
161 /* make the options accessible to :set */
162 optinsert("defwin", QTY(wdesc), wdesc, &windefopts.windowid);
163 }
164
165
166 /* Allocate a new window. This function should only be called by the
167 * EVENT module; other modules are expected to call the GUI's creategw()
168 * function, which will ultimately cause EVENT to call this function.
169 */
170 WINDOW winalloc(gw, gvals, buf, rows, columns)
171 GUIWIN *gw; /* GUI's handle for the new window */
172 OPTVAL *gvals; /* values of the GUI's window-dependent options */
173 BUFFER buf; /* buffer to use in the new window */
174 long rows; /* height of the new window */
175 long columns;/* width of the new window */
176 {
177 static long nextwindowid; /* counter used for assigning windowid */
178 WINDOW newp; /* pointer to the new window */
179
180 /* allocate a window, and initialize it */
181 newp = (WINDOW)safealloc(1, sizeof *newp);
182 *newp = windefopts;
183 newp->next = windows;
184 windows = newp;
185 newp->gw = gw;
186 newp->guivals = gvals;
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
187 newp->cursor = markalloc(buf, buf->docursor);
2fe6e17 Martin Dietze Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
188 if (buf->docursor != buf->changepos)
189 newp->prevcursor = markalloc(buf, buf->changepos);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
190 newp->wantcol = 0;
191 newp->cursx = newp->cursy = -1;
192
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
193 /* Initialize any options that aren't inherited from windefopts */
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
194 o_windowid(newp) = ++nextwindowid;
195 o_lines(newp) = rows;
196 o_columns(newp) = columns;
197 newp->wrapmargin.value.pointer = (void *)newp;
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
198 o_hasfocus(newp) = ElvFalse;
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
199
200 /* allocate storage space for the screen images */
97d8998 Martin Dietze Import Elvis 2.1_4 (written by Steve Kirkendall)
authored
201 newp->di = (DRAWINFO *)drawalloc((int)rows, (int)columns, newp->cursor);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
202
203 /* choose the default display mode */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
204 if (!dispset(newp, o_initialsyntax(buf) ? "syntax" : tochar8(o_bufdisplay(buf))))
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
205 (void)dispset(newp, NULL);
206
207 /* no text is selected, initially */
208 newp->seltop = newp->selbottom = NULL;
209
210 /* there is initially no matching parenthesis */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
211 #ifdef FEATURE_TEXTOBJ
212 newp->matchend =
213 #endif
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
214 newp->match = -4;
215
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
216 /* by default, don't tweak the "normal" font. */
217 newp->defaultfont = 0;
218 newp->fgcolor = colorinfo[COLOR_FONT_NORMAL].fg;
219 newp->bgcolor = colorinfo[COLOR_FONT_NORMAL].bg;
220
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
221 /* push the initial state */
222 if (gui->moveto)
223 {
224 vipush(newp, 0, newp->cursor);
225 newp->di->drawstate = DRAW_VISUAL;
226 }
227 else
228 {
229 vipush(newp, ELVIS_BOTTOM, newp->cursor);
230 newp->di->drawstate = DRAW_OPENOUTPUT;
231 }
232
233 /* push an extra state or two, if we're supposed to */
234 switch (o_initialstate)
235 {
236 case 'i':
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
237 if (!o_locked(markbuffer(newp->cursor)))
238 {
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
239 bufwilldo(newp->cursor, ElvTrue);
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
240 if (o_bufchars(markbuffer(newp->cursor)) == 0L)
241 {
242 assert(markoffset(newp->cursor) == 0L);
243 bufreplace(newp->cursor, newp->cursor, toCHAR("\n"), 1);
244 marksetoffset(newp->cursor, 0L);
245 }
246 inputpush(newp, newp->state->flags, 'i');
247 }
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
248 break;
249
250 case 'r':
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
251 if (!o_locked(markbuffer(newp->cursor)))
252 {
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
253 bufwilldo(newp->cursor, ElvTrue);
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
254 if (o_bufchars(markbuffer(newp->cursor)) == 0L)
255 {
256 assert(markoffset(newp->cursor) == 0L);
257 bufreplace(newp->cursor, newp->cursor, toCHAR("\n"), 1);
258 marksetoffset(newp->cursor, 0L);
259 }
260 inputpush(newp, newp->state->flags, 'R');
261 }
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
262 break;
263
264 case 'e':
265 /* push a whole new stratum! */
266 statestratum(newp, toCHAR(EX_BUF), ':', exenter);
267 newp->state->flags &= ~(ELVIS_POP|ELVIS_ONCE|ELVIS_1LINE);
268 break;
269 }
270
271 /* if no other window is the default already, then make this the
272 * default and flush any accumulated messages.
273 */
274 if (!windefault)
275 {
276 winoptions(newp);
277 msgflush();
278 }
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
279 else if (mapbusy())
280 {
281 /* just make it the default */
282 winoptions(newp);
283 assert(newp && windefault);
284 }
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
285
286 return newp;
287 }
288
289 /* Free a window. This function should only be called by the EVENT module;
290 * other modules are expected to call the GUI's destroygw() function, which
291 * will ultimately cause EVENT to call this function.
292 */
293 void winfree(win, force)
294 WINDOW win; /* the window to be freed */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
295 ELVBOOL force; /* If ElvTrue, try harder */
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
296 {
297 WINDOW scan, lag;
298 int i;
299
300 /* remove this window from the list of windows */
301 assert(windows);
302 for (scan = windows, lag = NULL; scan != win; lag = scan, scan = scan->next)
303 {
304 assert(scan->next);
305 }
306 if (lag)
307 {
308 lag->next = scan->next;
309 }
310 else
311 {
312 windows = scan->next;
313 }
314
315 /* if this was the default, it isn't now! */
316 if (windefault == win)
317 {
318 winoptions((WINDOW)0);
319 }
320
321 /* free the whole state stack */
322 while (win->state)
323 {
324 statepop(win);
325 }
326
327 /* free the marks in the tagstack */
328 for (i = 0; i < TAGSTK && win->tagstack[i].origin; i++)
329 {
330 markfree(win->tagstack[i].origin);
331 if (win->tagstack[i].prevtag)
332 safefree(win->tagstack[i].prevtag);
333 }
334
335 /* Unload the buffer. This will make it disappear if that's safe.
336 * If it succeeds, it will also free the cursor; if it doesn't
337 * succeed, then we want to free the cursor marks anyway.
338 */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
339 if (!bufunload(markbuffer(win->cursor), force, ElvFalse))
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
340 {
341 markfree(win->cursor);
342 if (win->prevcursor)
343 {
344 markfree(win->prevcursor);
345 }
346 if (win->seltop)
347 {
348 markfree(win->seltop);
349 markfree(win->selbottom);
350 }
351 }
352
353 /* free the options' value strings */
354 optfree(QTY(wdesc), &win->windowid);
355
356 /* free the storage space for the window's image */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
357 if (win->di)
358 {
359 drawfree(win->di);
360 win->di = NULL;
361 }
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
362
363 /* free any resources allocated for the display mode */
364 if (win->md)
365 {
366 (*win->md->term)(win->mi);
367 }
368
369 /* free the window struct itself */
370 safefree(win);
371 }
372
373 /* Change the size of the window. This function should only be called by
374 * the EVENT module; other modules aren't expected to worry about window size
375 * changes.
376 */
377 void winresize(win, rows, columns)
378 WINDOW win; /* the window to be resized */
379 long rows; /* new height of the window */
380 long columns;/* new width of the window */
381 {
97d8998 Martin Dietze Import Elvis 2.1_4 (written by Steve Kirkendall)
authored
382 MARKBUF oldtop;
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
383 CHAR *changed;
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
384
385 /* update the options */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
386 changed = NULL;
387 if (o_lines(win) != rows)
388 changed = toCHAR("lines");
389 else if (o_columns(win) != columns)
390 changed = toCHAR("columns");
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
391 o_lines(win) = rows;
392 o_columns(win) = columns;
393 if (!(optflags(o_scroll(win)) & OPT_SET))
394 {
395 o_scroll(win) = rows / 2;
396 }
397
398 /* free the old screen image, and allocate a new one */
97d8998 Martin Dietze Import Elvis 2.1_4 (written by Steve Kirkendall)
authored
399 oldtop = *win->di->topmark;
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
400 if (win->di)
401 drawfree(win->di);
97d8998 Martin Dietze Import Elvis 2.1_4 (written by Steve Kirkendall)
authored
402 win->di = drawalloc((int)rows, (int)columns, &oldtop);
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
403
404 #ifdef FEATURE_AUTOCMD
405 /* handle OptChanged event for lines or columns now */
406 if (changed);
407 auperform(win, ElvFalse, NULL, AU_OPTCHANGED, changed);
408 #endif
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
409 }
410
411 /* Cause a different buffer to be associated with this window. This function
412 * will call the GUI's retitle() function to change the window title to match
413 * the new buffer's name.
414 */
415 void winchgbuf(win, buf, force)
416 WINDOW win; /* window that will use the new buffer */
417 BUFFER buf; /* the new buffer */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
418 ELVBOOL force; /* if ElvTrue, try harder */
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
419 {
420 /* if same buffer, do nothing */
421 if (buf == markbuffer(win->cursor))
422 {
423 return;
424 }
425
426 /* remember the old filename and line number */
427 optprevfile(o_filename(markbuffer(win->cursor)), markline(win->cursor));
428
429 /* free the prevcursor mark */
430 if (win->prevcursor)
431 {
432 markfree(win->prevcursor);
433 win->prevcursor = NULL;
434 }
435
436 /* cancel any selection */
437 if (win->seltop)
438 {
439 markfree(win->seltop);
440 markfree(win->selbottom);
441 win->seltop = win->selbottom = NULL;
442 }
443
444 /* release the old buffer, and discard it if that's okay */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
445 if (bufunload(markbuffer(win->cursor), ElvFalse, ElvFalse) || force)
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
446 {
447 /* good! now switch buffers */
448 marksetbuffer(win->cursor, buf);
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
449 marksetoffset(win->cursor, buf->docursor);
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
450 if (windefault == win)
451 {
452 bufoptions(buf);
453 }
454
2fe6e17 Martin Dietze Import Elvis 2.2_1 (written by Steve Kirkendall)
authored
455 /* if the change location is different from docursor, then
456 * use it as the previous location for this window.
457 */
458 if (buf->changepos != buf->docursor)
459 win->prevcursor = markalloc(buf, buf->changepos);
460
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
461 /* switch to the new buffer's preferred display mode */
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
462 dispset(win, o_initialsyntax(buf) ? "syntax" : tochar8(o_bufdisplay(buf)));
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
463
464 /* retitle the GUI window */
465 if (gui->retitle)
466 {
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
467 (*gui->retitle)(win->gw, tochar8(o_filename(buf) ? o_filename(buf) : o_bufname(buf)));
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
468 }
469 }
470 }
471
472 /* Make this window be the default window, and its associated buffer be the
473 * default buffer. If win is NULL, no window will be the default.
474 */
475 void winoptions(win)
476 WINDOW win; /* the new default window */
477 {
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
478 #ifdef FEATURE_AUTOCMD
479 ELVBOOL changed = ElvFalse;
480 #endif
481
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
482 /* Delete the default options from the list of settable options.
483 * It is too late to change them via :set anymore.
484 */
485 optdelete(&windefopts.windowid);
486
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
487 /* if this window isn't already the default... */
488 if (windefault != win)
489 {
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
490 #ifdef FEATURE_AUTOCMD
491 if (windefault)
492 (void)auperform(windefault, ElvFalse, NULL, AU_WINLEAVE, NULL);
493 #endif
494
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
495 /* delete the old default window's options */
496 if (windefault)
497 {
498 optdelete(&windefault->windowid);
499 if (gui->nopts > 0 && windefault->guivals)
500 {
501 optdelete(windefault->guivals);
502 }
503 }
504 else if (windefopts.modename)
505 {
506 optdelete(&windefopts.windowid);
507 windefopts.modename = (char *)1;
508 }
509
510 /* make this window's options the defaults */
511 if (win)
512 {
513 optinsert("win", QTY(wdesc), wdesc, &win->windowid);
514 if (gui->nopts > 0)
515 {
516 optinsert("guiwin", gui->nopts, gui->optdescs, win->guivals);
517 }
518 }
519
520 windefault = win;
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
521 #ifdef FEATURE_AUTOCMD
522 changed = ElvTrue;
523 #endif
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
524 }
525
526 if (win)
527 {
528 /* make this window's buffer be the default buffer */
529 bufoptions(markbuffer(win->cursor));
530
531 /* make this window's mode be the default mode */
532 dispoptions(win->md, win->mi);
533 }
534 else
535 {
536 /* no defaults for buffer or mode */
537 bufoptions(NULL);
538 dispoptions(NULL, NULL);
539 }
9f1c6f0 Martin Dietze Import Elvis 2.2_0 (written by Steve Kirkendall)
authored
540
541 #ifdef FEATURE_AUTOCMD
542 if (changed && windefault)
543 (void)auperform(windefault, ElvFalse, NULL, AU_WINENTER, NULL);
544 #endif
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
545 }
546
547
548 /* Count the windows. If buf is NULL, then count all windows; else only
549 * count windows which contain buf in the state stack or tag stack.
550 */
551 int wincount(buf)
552 BUFFER buf; /* buffer of interest, or NULL for any buffer */
553 {
554 int i, j;
555 WINDOW scan;
556 STATE *s;
557
558 for (scan = windows, i = 0; scan; scan = scan->next)
559 {
560 /* if no specific buf is requested, then count every window */
561 if (!buf)
562 {
563 i++;
564 continue;
565 }
566
567 /* else look for it in state stack or tag stack */
568 for (s = scan->state; s; s = s->pop)
569 if (markbuffer(s->cursor) == buf)
570 goto Found;
571 for (j = 0; j < TAGSTK && scan->tagstack[j].origin; j++)
572 if (markbuffer(scan->tagstack[j].origin) == buf)
573 goto Found;
574
575 /* if we get here, then this window doesn't use the requested
576 * buffer and should therefore not be included in the count.
577 */
578 continue;
579
580 Found:
581 i++;
582 }
583 return i;
584 }
585
586
587 /* locate the WINDOW associated with GUIWIN "gw" */
588 WINDOW winofgw(gw)
589 GUIWIN *gw; /* GUI's handle for the window */
590 {
591 WINDOW win;
592
593 assert(windows);
8d1ac0c Martin Dietze Import Elvis 2.1 (written by Steve Kirkendall)
authored
594 for (win = windows; win && win->gw != gw; win = win->next)
cf92e3b Martin Dietze Import Elvis 2.0 (written by Steve Kirkendall)
authored
595 {
596 }
597 return win;
598 }
599
600
601 /* Locate a WINDOW associated with BUFFER "buf". If "win" is NULL, then
602 * searching begins at the start of the window list; else it begins after
603 * the given window. If "buf" is NULL, then any window matches regardless
604 * of its buffer. Returns the WINDOW if a match is found, or NULL of no
605 * matches are found.
606 */
607 WINDOW winofbuf(win, buf)
608 WINDOW win; /* where to start searching; NULL for first search */
609 BUFFER buf; /* the buffer of interest */
610 {
611 /* if "win" is NULL, then start searching at first window */
612 if (!win)
613 {
614 win = windows;
615 }
616 else
617 {
618 win = win->next;
619 }
620
621 /* search for "buf", or NULL */
622 while (win && buf && markbuffer(win->cursor) != buf)
623 {
624 win = win->next;
625 }
626 return win;
627 }
Something went wrong with that request. Please try again.