summaryrefslogtreecommitdiff
path: root/info/window.h
blob: 8cb755f4d795d516961dce70b924cee7cc647b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/* window.h -- Structure and flags used in manipulating Info windows.
   $Id: window.h 5337 2013-08-22 17:54:06Z karl $

   Copyright 1993, 1997, 2004, 2007, 2011 2013
   Free Software Foundation, Inc.

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.

   Originally written by Brian Fox. */

#ifndef INFO_WINDOW_H
#define INFO_WINDOW_H

#include "infomap.h"
#include "nodes.h"

/* Smallest number of visible lines in a window.  The actual height is
   always one more than this number because each window has a modeline. */
#define WINDOW_MIN_HEIGHT 2

/* Smallest number of screen lines that can be used to fully present a
   window.  This number includes the modeline of the window. */
#define WINDOW_MIN_SIZE (WINDOW_MIN_HEIGHT + 1)

/* A line map structure keeps a table of point values corresponding to
   column offsets within the current line.  It is used to convert
   point values into columns on screen and vice versa. */
typedef struct line_map_struct
{
  NODE *node;      /* Node to which this line pertains */
  size_t nline;    /* Line number for which the map is computed. */
  size_t size;     /* Number of elements map can accomodate */
  size_t used;     /* Number of used map slots */
  long *map;       /* The map itself */
} LINE_MAP;

/* The exact same elements are used within the WINDOW_STATE structure and a
   subsection of the WINDOW structure.  We could define a structure which
   contains this elements, and include that structure in each of WINDOW_STATE
   and WINDOW.  But that would lead references in the code such as
   window->state->node which we would like to avoid.  Instead, we #define the
   elements here, and simply include the define in both data structures. Thus,
   if you need to change window state information, here is where you would
   do it.  NB> The last element does NOT end with a semi-colon. */
#define WINDOW_STATE_DECL \
   NODE *node;          /* The node displayed in this window. */ \
   int pagetop;         /* LINE_STARTS[PAGETOP] is first line in WINDOW. */ \
   long point           /* Offset within NODE of the cursor position. */

/* Structure which defines a window.  Windows are doubly linked, next
   and prev. The list of windows is kept on WINDOWS.  The structure member
   window->height is the total height of the window.  The position location
   (0, window->height + window->first_row) is the first character of this
   windows modeline.  The number of lines that can be displayed in a window
   is equal to window->height - 1. */
typedef struct window_struct
{
  struct window_struct *next;      /* Next window in this chain. */
  struct window_struct *prev;      /* Previous window in this chain. */
  size_t width;         /* Width of this window. */
  size_t height;        /* Height of this window. */
  size_t first_row;     /* Offset of the first line in the_screen. */
  size_t goal_column;   /* The column we would like the cursor to appear in. */
  Keymap keymap;        /* Keymap used to read commands in this window. */
  WINDOW_STATE_DECL;    /* Node, pagetop and point. */
  LINE_MAP line_map;    /* Current line map */
  char *modeline;       /* Calculated text of the modeline for this window. */
  char **line_starts;   /* Array of printed line starts for this node. */
  size_t line_count;    /* Number of lines appearing in LINE_STARTS. */
  size_t *log_line_no;  /* Number of logical line corresponding to each
			   physical one. */
  int flags;            /* See below for details. */
} WINDOW;

typedef struct {
  WINDOW_STATE_DECL;            /* What gets saved. */
} WINDOW_STATE;

/* Structure defining the current state of an incremental search. */
typedef struct {
  WINDOW_STATE_DECL;    /* The node, pagetop and point. */
  int search_index;     /* Offset of the last char in the search string. */
  int direction;        /* The direction that this search is heading in. */
  int failing;          /* Whether or not this search failed. */
} SEARCH_STATE;

#define W_UpdateWindow  0x01    /* WINDOW needs updating. */
#define W_WindowIsPerm  0x02    /* This WINDOW is a permanent object. */
#define W_WindowVisible 0x04    /* This WINDOW is currently visible. */
#define W_InhibitMode   0x08    /* This WINDOW has no modeline. */
#define W_NoWrap        0x10    /* Lines do not wrap in this window. */
#define W_InputWindow   0x20    /* Window accepts input. */
#define W_TempWindow    0x40    /* Window is less important. */

extern WINDOW *windows;         /* List of visible Info windows. */
extern WINDOW *active_window;   /* The currently active window. */
extern WINDOW *the_screen;      /* The Info screen is just another window. */
extern WINDOW *the_echo_area;   /* THE_ECHO_AREA is a window in THE_SCREEN. */

extern int show_malformed_multibyte_p; /* Show malformed multibyte sequences */

/* Global variable control redisplay of scrolled windows.  If non-zero, it
   is the desired number of lines to scroll the window in order to make
   point visible.  A user might set this to 1 for smooth scrolling.  If
   set to zero, the line containing point is centered within the window. */
extern int window_scroll_step;

 /* Make the modeline member for WINDOW. */
extern void window_make_modeline (WINDOW *window);

/* Initalize the window system by creating THE_SCREEN and THE_ECHO_AREA.
   Create the first window ever, and make it permanent.
   You pass WIDTH and HEIGHT; the dimensions of the total screen size. */
extern void window_initialize_windows (int width, int height);

/* Make a new window showing NODE, and return that window structure.
   The new window is made to be the active window.  If NODE is passed
   as NULL, then show the node showing in the active window.  If the
   window could not be made return a NULL pointer.  The active window
   is not changed.*/
extern WINDOW *window_make_window (NODE *node);

/* Delete WINDOW from the list of known windows.  If this window was the
   active window, make the next window in the chain be the active window,
   or the previous window in the chain if there is no next window. */
extern void window_delete_window (WINDOW *window);

/* A function to call when the screen changes size, and some windows have
   to get deleted.  The function is called with the window to be deleted
   as an argument, and it can't do anything about the window getting deleted;
   it can only clean up dangling references to that window. */
extern VFunction *window_deletion_notifier;

/* Set WINDOW to display NODE. */
extern void window_set_node_of_window (WINDOW *window, NODE *node);

/* Tell the window system that the size of the screen has changed.  This
   causes lots of interesting things to happen.  The permanent windows
   are resized, as well as every visible window.  You pass WIDTH and HEIGHT;
   the dimensions of the total screen size. */
extern void window_new_screen_size (int width, int height);

/* Change the height of WINDOW by AMOUNT.  This also automagically adjusts
   the previous and next windows in the chain.  If there is only one user
   window, then no change takes place. */
extern void window_change_window_height (WINDOW *window, int amount);

/* Adjust the pagetop of WINDOW such that the cursor point will be visible. */
extern void window_adjust_pagetop (WINDOW *window);

/* Tile all of the windows currently displayed in the global variable
   WINDOWS.  If argument DO_INTERNALS is non-zero, tile windows displaying
   internal nodes as well. */
#define DONT_TILE_INTERNALS 0
#define TILE_INTERNALS      1
extern void window_tile_windows (int style);

/* Toggle the state of line wrapping in WINDOW.  This can do a bit of fancy
   redisplay. */
extern void window_toggle_wrap (WINDOW *window);

/* For every window in CHAIN, set the flags member to have FLAG set. */
extern void window_mark_chain (WINDOW *chain, int flag);

/* For every window in CHAIN, clear the flags member of FLAG. */
extern void window_unmark_chain (WINDOW *chain, int flag);

/* Make WINDOW start displaying at PERCENT percentage of its node. */
extern void window_goto_percentage (WINDOW *window, int percent);

/* Build a new node which has AP printed according to FORMAT as the
   contents. */
extern NODE *build_message_node (const char *format, va_list ap);

extern NODE *format_message_node (const char *format, ...)
  TEXINFO_PRINTFLIKE(1,2);

/* Build a new node with the given CONTENTS.
   Note: CONTENTS is "stolen", i.e. the pointer to it is saved in the
   new node. */
extern NODE *string_to_node (char *contents);

/* Useful functions can be called from outside of window.c. */
extern void initialize_message_buffer (void);

/* Print arguments according to FORMAT to the end of the current message
   buffer. */
extern void printf_to_message_buffer (const char *format, ...)
  TEXINFO_PRINTFLIKE(1,2);

/* Convert the contents of the message buffer to a node. */
extern NODE *message_buffer_to_node (void);

/* Return the length of the most recently printed line in message buffer. */
extern int message_buffer_length_this_line (void);

/* Pad STRING to COUNT characters by inserting blanks. */
extern int pad_to (int count, char *string);

/* Make a message appear in the echo area, built from arguments formatted
   according to FORMAT.

   The message appears immediately.  If there was
   already a message appearing in the echo area, it is removed. */
extern void window_message_in_echo_area (const char *format, ...)
  TEXINFO_PRINTFLIKE(1,2);

extern void vwindow_message_in_echo_area (const char *format, va_list ap);

extern void free_echo_area (void);

/* Place a temporary message in the echo area built from arguments
   formatted as per FORMAT.

   The message appears immediately, but does not destroy
   any existing message.  A future call to unmessage_in_echo_area ()
   restores the old contents. */
extern void message_in_echo_area (const char *format, ...)
  TEXINFO_PRINTFLIKE(1,2);

extern void unmessage_in_echo_area (void);

/* Clear the echo area, removing any message that is already present.
   The echo area is cleared immediately. */
extern void window_clear_echo_area (void);

/* Quickly guess the approximate number of lines to that NODE would
   take to display.  This really only counts carriage returns. */
extern int window_physical_lines (NODE *node);

/* Calculate a list of line starts for the node belonging to WINDOW.  The line
   starts are pointers to the actual text within WINDOW->NODE. */
extern void calculate_line_starts (WINDOW *window);

/* Given WINDOW, recalculate the line starts for the node it displays. */
extern void recalculate_line_starts (WINDOW *window);

/* Return the number of characters it takes to display CHARACTER on the
   screen at HPOS. */
extern int character_width (int character, int hpos);

/* Return the number of characters it takes to display STRING on the
   screen at HPOS. */
extern int string_width (char *string, int hpos);

/* Return the index of the line containing point. */
extern int window_line_of_point (WINDOW *window);

/* Get and return the goal column for this window. */
extern int window_get_goal_column (WINDOW *window);

/* Get and return the printed column offset of the cursor in this window. */
extern int window_get_cursor_column (WINDOW *window);

/* Get and Set the node, pagetop, and point of WINDOW. */
extern void window_get_state (WINDOW *window, SEARCH_STATE *state);
extern void window_set_state (WINDOW *window, SEARCH_STATE *state);

/* Count the number of characters in current line of WIN that precede
   the printed column offset of GOAL. */
extern int window_chars_to_goal (WINDOW *win, int goal);

extern size_t process_node_text
        (WINDOW *win, char *start, int do_tags,
         int (*fun) (void *, size_t, size_t, const char *, char *,
		     size_t, size_t),
	 void *closure);

extern void clean_manpage (char *manpage);

extern void window_compute_line_map (WINDOW *win);

extern int window_point_to_column (WINDOW *win, long point, long *np);

extern void window_line_map_init (WINDOW *win);

extern long window_end_of_line (WINDOW *win);

extern size_t window_log_to_phys_line (WINDOW *window, size_t ln);

#endif /* not INFO_WINDOW_H */