home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
- * "Epsilon", "EEL" and "Lugaru" are trademarks of Lugaru Software, Ltd. *
- * *
- * Copyright (C) 1989-1990 Lugaru Software Ltd. All rights reserved. *
- * *
- * Limited permission is hereby granted to reproduce and modify this *
- * copyrighted material provided that the resulting code is used only in *
- * conjunction with Lugaru products and that this notice is retained in *
- * any such reproduction or modification. *
- ************************************************************************/
-
- #include "eel.h"
-
- /* This file demonstrates how to save & restore a particular window
- configuration. It provides two subroutines: do_save_window() saves, and
- do_restore_windows() restores, a particular arrangement of windows.
- The subroutines don't restore any buffer-to-window mappings, or deal with
- the possibility that the screen size may be different now.
-
- For testing purposes, it provides two commands save-window and
- restore-window, on A-F-1 and A-F-2 respectively.
- */
-
- #define WINFO_SIZE 200 /* size of char array with window info */
-
- #define DEMO
- #ifdef DEMO
- char window_info[WINFO_SIZE];
-
- command save_windows() on reg_tab[FALT(1)] /* demo commands */
- {
- do_save_windows(window_info);
- say("Save as %s", window_info);
- }
-
- command restore_windows() on reg_tab[FALT(2)]
- {
- say("Restore %s", window_info);
- do_restore_windows(window_info);
- }
- #endif
-
- /*
- Window configurations are stored in a string as a series of commands,
- each consisting of a letter H, V, or G, and a number n. H or V means
- split the current window horizontally or vertically, and make the
- size of the child window be n. G means go to window n.
- */
-
- do_restore_windows(p) /* restore window pattern from p */
- char *p;
- {
- int n, old;
-
- window_one();
- for (; *p; p++) {
- n = strtoi(p + 1, 10);
- switch (*p) {
- case 'V': old = window_width;
- window_split(VERTICAL);
- window_width = old - n;
- break;
- case 'H': old = window_height;
- window_split(HORIZONTAL);
- window_height = old - n;
- break;
- case 'G': window_number = n;
- break;
- }
- }
- }
-
- do_save_windows(p) /* save window configuration in p */
- char *p;
- {
- int orig = window_number;
-
- *p = 0;
- get_win_info(p, 0, number_of_windows(), 0, screen_cols - 1,
- 0, screen_lines - 2);
- p += strlen(p);
- sprintf(p, "G%d", orig);
- window_number = orig;
- }
-
- /*
- Scan range of windows, looking for first that stretches to final column
- or line. That tells whether the first split in the range was horiz or vert.
- Next, move forward until past that whole rectangle, then record the first
- split in p, and recurse for both subwindows.
- */
- get_win_info(p, from, to, fcol, lcol, fline, lline)
- char *p;
- {
- int col, line, hitbot, hitright, w;
-
- if (from >= to)
- return;
- for (w = from; w < to; w++) {
- window_number = w;
- hitright = (lcol == window_edge(HORIZONTAL, BOTTOMRIGHT));
- hitbot = (lline == window_edge(VERTICAL, BOTTOMRIGHT));
- if (hitbot || hitright)
- break; /* look for top-right or bottom-left corner */
- } /* of some full-size rectangle */
- if (hitbot && hitright) /* easy, found bottom-right corner */
- return;
- p += strlen(p); /* now get past other windows in rect */
- for (w++; w < to; w++) {
- window_number = w;
- col = window_edge(HORIZONTAL, TOPLEFT);
- line = window_edge(VERTICAL, TOPLEFT);
- if (hitbot && fline == line) {
- sprintf(p, "G%dV%d", from, col - fcol);
- get_win_info(p, from, w, fcol, col - 1, fline, lline);
- get_win_info(p, w, to, col, lcol, fline, lline);
- return;
- }
- if (hitright && fcol == col) {
- sprintf(p, "G%dH%d", from, line - fline);
- get_win_info(p, from, w, fcol, lcol, fline, line - 1);
- get_win_info(p, w, to, fcol, lcol, line, lline);
- return;
- }
- }
- }
-