142660Smarkm/* window.h -- Structure and flags used in manipulating Info windows.
2146515Sru   $Id: window.h,v 1.3 2004/04/11 17:56:46 karl Exp $
321495Sjmacd
442660Smarkm   This file is part of GNU Info, a program for reading online documentation
521495Sjmacd   stored in Info format.
621495Sjmacd
7146515Sru   Copyright (C) 1993, 1997, 2004 Free Software Foundation, Inc.
821495Sjmacd
921495Sjmacd   This program is free software; you can redistribute it and/or modify
1021495Sjmacd   it under the terms of the GNU General Public License as published by
1121495Sjmacd   the Free Software Foundation; either version 2, or (at your option)
1221495Sjmacd   any later version.
1321495Sjmacd
1421495Sjmacd   This program is distributed in the hope that it will be useful,
1521495Sjmacd   but WITHOUT ANY WARRANTY; without even the implied warranty of
1621495Sjmacd   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1721495Sjmacd   GNU General Public License for more details.
1821495Sjmacd
1921495Sjmacd   You should have received a copy of the GNU General Public License
2021495Sjmacd   along with this program; if not, write to the Free Software
2121495Sjmacd   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2221495Sjmacd
2321495Sjmacd   Written by Brian Fox (bfox@ai.mit.edu). */
2421495Sjmacd
2542660Smarkm#ifndef INFO_WINDOW_H
2642660Smarkm#define INFO_WINDOW_H
2721495Sjmacd
28146515Sru#include "infomap.h"
2921495Sjmacd#include "nodes.h"
3021495Sjmacd
3121495Sjmacd/* Smallest number of visible lines in a window.  The actual height is
3221495Sjmacd   always one more than this number because each window has a modeline. */
3321495Sjmacd#define WINDOW_MIN_HEIGHT 2
3421495Sjmacd
3521495Sjmacd/* Smallest number of screen lines that can be used to fully present a
3621495Sjmacd   window.  This number includes the modeline of the window. */
3721495Sjmacd#define WINDOW_MIN_SIZE (WINDOW_MIN_HEIGHT + 1)
3821495Sjmacd
3921495Sjmacd/* The exact same elements are used within the WINDOW_STATE structure and a
4021495Sjmacd   subsection of the WINDOW structure.  We could define a structure which
4121495Sjmacd   contains this elements, and include that structure in each of WINDOW_STATE
4221495Sjmacd   and WINDOW.  But that would lead references in the code such as
4321495Sjmacd   window->state->node which we would like to avoid.  Instead, we #define the
4421495Sjmacd   elements here, and simply include the define in both data structures. Thus,
4521495Sjmacd   if you need to change window state information, here is where you would
4621495Sjmacd   do it.  NB> The last element does NOT end with a semi-colon. */
4721495Sjmacd#define WINDOW_STATE_DECL \
4842660Smarkm   NODE *node;          /* The node displayed in this window. */ \
4942660Smarkm   int pagetop;         /* LINE_STARTS[PAGETOP] is first line in WINDOW. */ \
5042660Smarkm   long point           /* Offset within NODE of the cursor position. */
5121495Sjmacd
5221495Sjmacd/* Structure which defines a window.  Windows are doubly linked, next
5321495Sjmacd   and prev. The list of windows is kept on WINDOWS.  The structure member
5421495Sjmacd   window->height is the total height of the window.  The position location
5521495Sjmacd   (0, window->height + window->first_row) is the first character of this
5621495Sjmacd   windows modeline.  The number of lines that can be displayed in a window
5721495Sjmacd   is equal to window->height - 1. */
5842660Smarkmtypedef struct window_struct
5942660Smarkm{
6042660Smarkm  struct window_struct *next;      /* Next window in this chain. */
6142660Smarkm  struct window_struct *prev;      /* Previous window in this chain. */
6242660Smarkm  int width;            /* Width of this window. */
6342660Smarkm  int height;           /* Height of this window. */
6442660Smarkm  int first_row;        /* Offset of the first line in the_screen. */
6542660Smarkm  int goal_column;      /* The column we would like the cursor to appear in. */
6642660Smarkm  Keymap keymap;        /* Keymap used to read commands in this window. */
6742660Smarkm  WINDOW_STATE_DECL;    /* Node, pagetop and point. */
6842660Smarkm  char *modeline;       /* Calculated text of the modeline for this window. */
6942660Smarkm  char **line_starts;   /* Array of printed line starts for this node. */
7042660Smarkm  int line_count;       /* Number of lines appearing in LINE_STARTS. */
7142660Smarkm  int flags;            /* See below for details. */
7221495Sjmacd} WINDOW;
7321495Sjmacd
7421495Sjmacdtypedef struct {
7542660Smarkm  WINDOW_STATE_DECL;            /* What gets saved. */
7621495Sjmacd} WINDOW_STATE;
7721495Sjmacd
78146515Sru/* Structure defining the current state of an incremental search. */
79146515Srutypedef struct {
80146515Sru  WINDOW_STATE_DECL;    /* The node, pagetop and point. */
81146515Sru  int search_index;     /* Offset of the last char in the search string. */
82146515Sru  int direction;        /* The direction that this search is heading in. */
83146515Sru  int failing;          /* Whether or not this search failed. */
84146515Sru} SEARCH_STATE;
85146515Sru
8642660Smarkm#define W_UpdateWindow  0x01    /* WINDOW needs updating. */
8742660Smarkm#define W_WindowIsPerm  0x02    /* This WINDOW is a permanent object. */
8842660Smarkm#define W_WindowVisible 0x04    /* This WINDOW is currently visible. */
8942660Smarkm#define W_InhibitMode   0x08    /* This WINDOW has no modeline. */
9042660Smarkm#define W_NoWrap        0x10    /* Lines do not wrap in this window. */
9142660Smarkm#define W_InputWindow   0x20    /* Window accepts input. */
9242660Smarkm#define W_TempWindow    0x40    /* Window is less important. */
9321495Sjmacd
9442660Smarkmextern WINDOW *windows;         /* List of visible Info windows. */
9542660Smarkmextern WINDOW *active_window;   /* The currently active window. */
9642660Smarkmextern WINDOW *the_screen;      /* The Info screen is just another window. */
9742660Smarkmextern WINDOW *the_echo_area;   /* THE_ECHO_AREA is a window in THE_SCREEN. */
9821495Sjmacd
9921495Sjmacd/* Global variable control redisplay of scrolled windows.  If non-zero, it
10021495Sjmacd   is the desired number of lines to scroll the window in order to make
10121495Sjmacd   point visible.  A user might set this to 1 for smooth scrolling.  If
10221495Sjmacd   set to zero, the line containing point is centered within the window. */
10321495Sjmacdextern int window_scroll_step;
10421495Sjmacd
10521495Sjmacd /* Make the modeline member for WINDOW. */
106146515Sruextern void window_make_modeline (WINDOW *window);
10721495Sjmacd
10821495Sjmacd/* Initalize the window system by creating THE_SCREEN and THE_ECHO_AREA.
10921495Sjmacd   Create the first window ever, and make it permanent.
11021495Sjmacd   You pass WIDTH and HEIGHT; the dimensions of the total screen size. */
111146515Sruextern void window_initialize_windows (int width, int height);
11221495Sjmacd
11321495Sjmacd/* Make a new window showing NODE, and return that window structure.
11421495Sjmacd   The new window is made to be the active window.  If NODE is passed
11521495Sjmacd   as NULL, then show the node showing in the active window.  If the
11621495Sjmacd   window could not be made return a NULL pointer.  The active window
11721495Sjmacd   is not changed.*/
118146515Sruextern WINDOW *window_make_window (NODE *node);
11921495Sjmacd
12021495Sjmacd/* Delete WINDOW from the list of known windows.  If this window was the
12121495Sjmacd   active window, make the next window in the chain be the active window,
12221495Sjmacd   or the previous window in the chain if there is no next window. */
123146515Sruextern void window_delete_window (WINDOW *window);
12421495Sjmacd
12521495Sjmacd/* A function to call when the screen changes size, and some windows have
12621495Sjmacd   to get deleted.  The function is called with the window to be deleted
12721495Sjmacd   as an argument, and it can't do anything about the window getting deleted;
12821495Sjmacd   it can only clean up dangling references to that window. */
12921495Sjmacdextern VFunction *window_deletion_notifier;
13021495Sjmacd
13121495Sjmacd/* Set WINDOW to display NODE. */
132146515Sruextern void window_set_node_of_window (WINDOW *window, NODE *node);
13321495Sjmacd
13421495Sjmacd/* Tell the window system that the size of the screen has changed.  This
13521495Sjmacd   causes lots of interesting things to happen.  The permanent windows
13621495Sjmacd   are resized, as well as every visible window.  You pass WIDTH and HEIGHT;
13721495Sjmacd   the dimensions of the total screen size. */
138146515Sruextern void window_new_screen_size (int width, int height);
13921495Sjmacd
14021495Sjmacd/* Change the height of WINDOW by AMOUNT.  This also automagically adjusts
14121495Sjmacd   the previous and next windows in the chain.  If there is only one user
14221495Sjmacd   window, then no change takes place. */
143146515Sruextern void window_change_window_height (WINDOW *window, int amount);
14421495Sjmacd
14521495Sjmacd/* Adjust the pagetop of WINDOW such that the cursor point will be visible. */
146146515Sruextern void window_adjust_pagetop (WINDOW *window);
14721495Sjmacd
14821495Sjmacd/* Tile all of the windows currently displayed in the global variable
14921495Sjmacd   WINDOWS.  If argument DO_INTERNALS is non-zero, tile windows displaying
15021495Sjmacd   internal nodes as well. */
15121495Sjmacd#define DONT_TILE_INTERNALS 0
15221495Sjmacd#define TILE_INTERNALS      1
153146515Sruextern void window_tile_windows (int style);
15421495Sjmacd
15521495Sjmacd/* Toggle the state of line wrapping in WINDOW.  This can do a bit of fancy
15621495Sjmacd   redisplay. */
157146515Sruextern void window_toggle_wrap (WINDOW *window);
15821495Sjmacd
15921495Sjmacd/* For every window in CHAIN, set the flags member to have FLAG set. */
160146515Sruextern void window_mark_chain (WINDOW *chain, int flag);
16121495Sjmacd
16221495Sjmacd/* For every window in CHAIN, clear the flags member of FLAG. */
163146515Sruextern void window_unmark_chain (WINDOW *chain, int flag);
16421495Sjmacd
16521495Sjmacd/* Make WINDOW start displaying at PERCENT percentage of its node. */
166146515Sruextern void window_goto_percentage (WINDOW *window, int percent);
16721495Sjmacd
16821495Sjmacd/* Build a new node which has FORMAT printed with ARG1 and ARG2 as the
16921495Sjmacd   contents. */
170146515Sruextern NODE *build_message_node (char *format, void *arg1, void *arg2);
17121495Sjmacd
17221495Sjmacd/* Useful functions can be called from outside of window.c. */
173146515Sruextern void initialize_message_buffer (void);
17421495Sjmacd
17521495Sjmacd/* Print FORMAT with ARG1,2 to the end of the current message buffer. */
176146515Sruextern void printf_to_message_buffer (char *format, void *arg1, void *arg2,
177146515Sru    void *arg3);
17821495Sjmacd
17921495Sjmacd/* Convert the contents of the message buffer to a node. */
180146515Sruextern NODE *message_buffer_to_node (void);
18121495Sjmacd
18221495Sjmacd/* Return the length of the most recently printed line in message buffer. */
183146515Sruextern int message_buffer_length_this_line (void);
18421495Sjmacd
18521495Sjmacd/* Pad STRING to COUNT characters by inserting blanks. */
186146515Sruextern int pad_to (int count, char *string);
18721495Sjmacd
18821495Sjmacd/* Make a message appear in the echo area, built from FORMAT, ARG1 and ARG2.
18921495Sjmacd   The arguments are treated similar to printf () arguments, but not all of
19021495Sjmacd   printf () hair is present.  The message appears immediately.  If there was
19121495Sjmacd   already a message appearing in the echo area, it is removed. */
192146515Sruextern void window_message_in_echo_area (char *format, void *arg1, void *arg2);
19321495Sjmacd
19421495Sjmacd/* Place a temporary message in the echo area built from FORMAT, ARG1
19521495Sjmacd   and ARG2.  The message appears immediately, but does not destroy
19621495Sjmacd   any existing message.  A future call to unmessage_in_echo_area ()
19721495Sjmacd   restores the old contents. */
198146515Sruextern void message_in_echo_area (char *format, void *arg1, void *arg2);
199146515Sruextern void unmessage_in_echo_area (void);
20021495Sjmacd
20121495Sjmacd/* Clear the echo area, removing any message that is already present.
20221495Sjmacd   The echo area is cleared immediately. */
203146515Sruextern void window_clear_echo_area (void);
20421495Sjmacd
20521495Sjmacd/* Quickly guess the approximate number of lines to that NODE would
20621495Sjmacd   take to display.  This really only counts carriage returns. */
207146515Sruextern int window_physical_lines (NODE *node);
20821495Sjmacd
20921495Sjmacd/* Calculate a list of line starts for the node belonging to WINDOW.  The line
21021495Sjmacd   starts are pointers to the actual text within WINDOW->NODE. */
211146515Sruextern void calculate_line_starts (WINDOW *window);
21221495Sjmacd
21321495Sjmacd/* Given WINDOW, recalculate the line starts for the node it displays. */
214146515Sruextern void recalculate_line_starts (WINDOW *window);
21521495Sjmacd
21621495Sjmacd/* Return the number of characters it takes to display CHARACTER on the
21721495Sjmacd   screen at HPOS. */
218146515Sruextern int character_width (int character, int hpos);
21921495Sjmacd
22021495Sjmacd/* Return the number of characters it takes to display STRING on the
22121495Sjmacd   screen at HPOS. */
222146515Sruextern int string_width (char *string, int hpos);
22321495Sjmacd
22421495Sjmacd/* Return the index of the line containing point. */
225146515Sruextern int window_line_of_point (WINDOW *window);
22621495Sjmacd
22721495Sjmacd/* Get and return the goal column for this window. */
228146515Sruextern int window_get_goal_column (WINDOW *window);
22921495Sjmacd
23021495Sjmacd/* Get and return the printed column offset of the cursor in this window. */
231146515Sruextern int window_get_cursor_column (WINDOW *window);
23221495Sjmacd
23321495Sjmacd/* Get and Set the node, pagetop, and point of WINDOW. */
234146515Sruextern void window_get_state (WINDOW *window, SEARCH_STATE *state);
235146515Sruextern void window_set_state (WINDOW *window, SEARCH_STATE *state);
23621495Sjmacd
23721495Sjmacd/* Count the number of characters in LINE that precede the printed column
23821495Sjmacd   offset of GOAL. */
239146515Sruextern int window_chars_to_goal (char *line, int goal);
24021495Sjmacd
24142660Smarkm#endif /* not INFO_WINDOW_H */
242