1 /*--------------------------------*-C-*---------------------------------*
2  * File:    screen.h
3  *
4  * This module is all new by Robert Nation
5  * <nation@rocket.sanders.lockheed.com>
6  *
7  * Additional modifications by mj olesen <olesen@me.QueensU.CA>
8  * No additional restrictions are applied.
9  *
10  * As usual, the author accepts no responsibility for anything, nor does
11  * he guarantee anything whatsoever.
12  *----------------------------------------------------------------------*/
13 #ifndef _SCREEN_H
14 #define _SCREEN_H
15 
16 #include <X11/Xfuncproto.h>
17 #include "startup.h"
18 
19 /************ Macros and Definitions ************/
20 #define WRAP_CHAR       (0xff)
21 #define PROP_SIZE           4096
22 #define TABSIZE             8   /* default tab size */
23 
24 #define IS_SELECTION(a)         (((a) == XA_PRIMARY) || ((a) == XA_SECONDARY) || ((a) == props[PROP_CLIPBOARD]))
25 #define IS_CUT_BUFFER(a)        (((a) >= XA_CUT_BUFFER0) && ((a) <= XA_CUT_BUFFER7))
26 
27 #define ZERO_SCROLLBACK do { \
28                           if (BITFIELD_IS_SET(vt_options, VT_OPTIONS_HOME_ON_OUTPUT)) TermWin.view_start = 0; \
29                         } while (0)
30 #define REFRESH_ZERO_SCROLLBACK do { \
31                                   if (BITFIELD_IS_SET(vt_options, VT_OPTIONS_HOME_ON_OUTPUT)) TermWin.view_start = 0; \
32                                 } while (0)
33 #define CHECK_SELECTION do { \
34                           if (selection.op) selection_check(); \
35                         } while (0)
36 #define CLEAR_SELECTION (selection.beg.row = selection.beg.col = selection.end.row = selection.end.col = 0)
37 #define CLEAR_ALL_SELECTION (selection.beg.row = selection.beg.col = selection.mark.row = selection.mark.col = selection.end.row = selection.end.col = 0)
38 
39 #define scr_touch()  (refresh_all = 1)
40 
41 /*
42  * CLEAR_ROWS : clear <num> rows starting from row <row>
43  * CLEAR_CHARS: clear <num> chars starting from pixel position <x,y>
44  * ERASE_ROWS : set <num> rows starting from row <row> to the foreground color
45  */
46 #define CLEAR_ROWS(row, num)  do {if (buffer_pixmap) {XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, Col2Pixel(0), Row2Pixel(row), TERM_WINDOW_GET_WIDTH(), Height2Pixel(num), \
47                                   Col2Pixel(0), Row2Pixel(row));} XClearArea(Xdisplay, TermWin.vt, Col2Pixel(0), Row2Pixel(row), TERM_WINDOW_GET_WIDTH(), Height2Pixel(num), 0);} while (0)
48 #define CLEAR_CHARS(x, y, num) ((buffer_pixmap) \
49                                ? (XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, x, y, Width2Pixel(num), Height2Pixel(1), x, y)) \
50                                : (XClearArea(Xdisplay, TermWin.vt, x, y, Width2Pixel(num), Height2Pixel(1), 0)))
51 #define CLEAR_RECT(x, y, w, h) ((buffer_pixmap) \
52                                ? (XCopyArea(Xdisplay, pmap, buffer_pixmap, TermWin.gc, x, y, w, h, x, y)) \
53                                : (XClearArea(Xdisplay, TermWin.vt, x, y, w, h, 0)))
54 #define UPDATE_BOX(x1, y1, x2, y2)  do {if (buffer_pixmap) {if (x1 < low_x) low_x = x1; if (x2 > high_x) high_x = x2; \
55                                                             if (y1 < low_y) low_y = y1; if (y2 > high_y) high_y = y2;}} while (0)
56 #define ERASE_ROWS(row, num)  do {XFillRectangle(Xdisplay, draw_buffer, TermWin.gc, Col2Pixel(0), Row2Pixel(row), TERM_WINDOW_GET_WIDTH(), Height2Pixel(num)); \
57                                   if (buffer_pixmap) {XClearArea(Xdisplay, TermWin.vt, Col2Pixel(0), Row2Pixel(row), TERM_WINDOW_GET_WIDTH(), Height2Pixel(num), 0);}} while (0)
58 #if FIXME_BLOCK
59 # define DRAW_STRING(Func, x, y, str, len)  Func(Xdisplay, draw_buffer, TermWin.fontset, TermWin.gc, x, y, str, len)
60 #else
61 # define DRAW_STRING(Func, x, y, str, len)  Func(Xdisplay, draw_buffer, TermWin.gc, x, y, str, len)
62 #endif
63 
64 /* Make bold if bold flag is set and either we're drawing the foreground color or we're not suppressing bold.
65    In other words, the foreground color can always be bolded, but other colors can't if bold is suppressed. */
66 #define MONO_BOLD(x) (((x) & RS_Bold) && (!BITFIELD_IS_SET(vt_options, VT_OPTIONS_COLORS_SUPPRESS_BOLD) || fore == fgColor))
67 
68 /* Screen refresh methods */
69 #define NO_REFRESH              0       /* Window not visible at all!        */
70 #define FAST_REFRESH            (1<<1)  /* Fully exposed window              */
71 #define SLOW_REFRESH            (1<<2)  /* Partially exposed window          */
72 #define SMOOTH_REFRESH          (1<<3)  /* Do sync'ing to make it smooth     */
73 
74 #define IGNORE  0
75 #define SAVE    's'
76 #define RESTORE 'r'
77 #define REVERT IGNORE
78 #define INVOKE RESTORE
79 
80 /* flags for scr_gotorc() */
81 #define C_RELATIVE      1   /* col movement is relative */
82 #define R_RELATIVE      2   /* row movement is relative */
83 #define RELATIVE        (R_RELATIVE|C_RELATIVE)
84 
85 /* modes for scr_insdel_chars(), scr_insdel_lines() */
86 #define INSERT          -1  /* don't change these values */
87 #define DELETE          +1
88 #define ERASE           +2
89 
90 /* modes for scr_page() - scroll page. used by scrollbar window */
91 enum {
92     UP,
93     DN,
94     NO_DIR
95 };
96 
97 /* arguments for scr_change_screen() */
98 enum {
99     PRIMARY,
100     SECONDARY
101 };
102 
103 #ifdef MULTI_CHARSET
104 #define RS_multi1       0x80000000u /* multibyte 1st byte */
105 #define RS_multi0       0x40000000u /* only multibyte characters */
106 #define RS_multi2       (RS_multi0|RS_multi1)   /* multibyte 2nd byte */
107 #define RS_multiMask    (RS_multi0|RS_multi1)   /* multibyte mask */
108 #endif
109 #define RS_ukFont       0x20000000u /* UK character set */
110 #define RS_acsFont      0x10000000u /* ACS graphics character set */
111 #define RS_fontMask     (RS_acsFont|RS_ukFont)
112 #define RS_Uline        0x08000000u /* underline */
113 #define RS_RVid         0x04000000u /* reverse video */
114 #define RS_Select       0x02000000u /* selected text */
115 #define RS_Cursor       0x01000000u /* cursor location */
116 #define RS_Blink        0x00800000u /* blink */
117 #define RS_Conceal      0x00400000u /* conceal */
118 #define RS_Dim          0x00200000u /* dim (apply alpha) */
119 #define RS_Bold         0x00100000u /* bold */
120 #define RS_Italic       0x00080000u /* italic */
121 #define RS_Overscore    0x00040000u /* overscore */
122 #define RS_fgMask       0x0003FE00u /* 512 colors */
123 #define RS_bgMask       0x000001FFu /* 512 colors */
124 #define RS_None         0x00000000u /* Normal */
125 
126 #define RS_attrMask     (0xFF000000u|RS_Overscore|RS_Italic|RS_Bold|RS_Dim|RS_Conceal|RS_Blink)
127 
128 /* how to build & extract colors and attributes */
129 #define GET_FGCOLOR(r)        (((r) & RS_fgMask)>>9)
130 #define GET_BGCOLOR(r)        (((r) & RS_bgMask))
131 #define GET_ATTR(r)           (((r) & RS_attrMask))
132 #define GET_BGATTR(r)         (((r) & (RS_attrMask | RS_bgMask)))
133 
134 #define SET_FGCOLOR(r,fg)     (((r) & ~RS_fgMask)  | ((fg)<<9))
135 #define SET_BGCOLOR(r,bg)     (((r) & ~RS_bgMask)  | (bg))
136 #define SET_ATTR(r,a)         (((r) & ~RS_attrMask)| (a))
137 #define DEFAULT_RSTYLE        (RS_None | (fgColor<<9) | (bgColor))
138 
139 /* screen_t flags */
140 #define Screen_Relative       (1<<0)    /* relative origin mode flag         */
141 #define Screen_VisibleCursor  (1<<1)    /* cursor visible?                   */
142 #define Screen_Autowrap       (1<<2)    /* auto-wrap flag                    */
143 #define Screen_Insert         (1<<3)    /* insert mode (vs. overstrike)      */
144 #define Screen_WrapNext       (1<<4)    /* need to wrap for next char?       */
145 #define Screen_DefaultFlags   (Screen_VisibleCursor|Screen_Autowrap)
146 
147 /************ Structures ************/
148 /* General overview of the screen stuff:
149 
150    TermWin.saveLines tells us how many lines are in the scrollback buffer.
151    There are a total of TermWin.saveLines + TermWin.nrow rows in the
152    screen buffer, with the scrollback coming before the on-screen data.
153    TermWin.nscrolled tells us how many lines of the scrollback buffer have
154    actually been used (i.e., allocated).  TermWin.view_start tells us how
155    many lines back into the scrollback buffer the currently-visible data
156    is.  (0 means we're at the bottom and not in scrollback.)
157 */
158 typedef unsigned char text_t;
159 typedef unsigned int rend_t;
160 typedef enum {
161     SELECTION_CLEAR = 0,
162     SELECTION_INIT,
163     SELECTION_BEGIN,
164     SELECTION_CONT,
165     SELECTION_DONE
166 } selection_op_t;
167 typedef enum {
168     LATIN1 = 0, UCS2, EUCJ, EUCKR = EUCJ, GB = EUCJ, SJIS, BIG5
169 } encoding_t;
170 typedef struct {
171     short row, col;
172 } row_col_t;
173 /* screen_t:
174 
175    screen.text contains a 2-D array of the screen data.  screen.rend contains
176    a matching 2-D array of rendering information (as 32-bit masks).  They are
177    allocated together, so you can always be sure that screen.rend[r] will be
178    allocated if screen.text[r] is.  You are also guaranteed that each row of
179    screen.text is TermWin.ncol + 1 columns long, and each row of screen.rend
180    is TermWin.ncol columns long.  They both have (TermWin.nrow +
181    TermWin.saveLines) rows, but only TermWin.nrow + TermWin.nscrolled lines
182    are actually allocated.  The extra column in the text array is for storing
183    line wrap information.  It will either be the length of the line, or
184    WRAP_CHAR if the line wraps into the next line.
185 
186    screen.row and screen.col contain the current cursor position.  It is always
187    somewhere on the visible screen.  screen.tscroll and screen.bscroll are the
188    top and bottom rows of the current scroll region.  screen.charset is the
189    character set currently being used (0-3).
190 */
191 typedef struct {
192     text_t **text;
193     rend_t **rend;
194     short row, col;
195     short tscroll, bscroll;
196     unsigned char charset:2;
197     unsigned char flags:5;
198 } screen_t;
199 /* A save_t object is used to save/restore the cursor position and other
200    relevant data when requested to do so by the application. */
201 typedef struct {
202     short row, col;
203     short charset;
204     char charset_char;
205     rend_t rstyle;
206 } save_t;
207 /* selection_t:
208 
209    selection.text is a string containing the current selection text.  It is
210    duplicated from the screen data.  selection.len is the length of that string.
211    selection.op represents the current state, selection-wise.  selection.screen
212    gives the number (0 or 1) of the current screen.  selection.clicks tells how
213    many clicks created the current selection (0-3, or 4 if nothing is selected).
214    beg, mark, and end represent the row and column of the beginning of the
215    selection, the click that created the selection, and the end of the selection,
216    respectively.
217 
218    -TermWin.nscrolled <= beg.row <= mark.row <= end.row < TermWin.nrow
219 */
220 typedef struct {
221     text_t  *text;
222     int len;
223     selection_op_t op;
224     unsigned short screen:1;
225     unsigned char clicks:3;
226     row_col_t beg, mark, end;
227 } selection_t;
228 
229 /************ Variables ************/
230 extern unsigned int colorfgbg;
231 extern unsigned char refresh_all;
232 #ifdef MULTI_CHARSET
233 extern encoding_t encoding_method;
234 #endif
235 #ifdef ESCREEN
236 extern screen_t screen;
237 #endif
238 
239 /************ Function Prototypes ************/
240 _XFUNCPROTOBEGIN
241 
242 extern void blank_dline(text_t *, rend_t *, int, rend_t);
243 extern void blank_sline(text_t *, rend_t *, int);
244 extern void make_screen_mem(text_t **, rend_t **, int);
245 extern void scr_reset(void);
246 extern void scr_release(void);
247 extern void scr_poweron(void);
248 extern void scr_cursor(int);
249 extern int scr_change_screen(int);
250 extern void scr_color(unsigned int, unsigned int);
251 extern void scr_rendition(int, int);
252 extern int scroll_text(int, int, int, int);
253 extern void scr_add_lines(const unsigned char *, int, int);
254 extern void scr_backspace(void);
255 extern void scr_tab(int);
256 extern void scr_gotorc(int, int, int);
257 extern void scr_index(int);
258 extern void scr_erase_line(int);
259 extern void scr_erase_screen(int);
260 extern void scr_E(void);
261 extern void scr_insdel_lines(int, int);
262 extern void scr_insdel_chars(int, int);
263 extern void scr_scroll_region(int, int);
264 extern void scr_cursor_visible(int);
265 extern void scr_autowrap(int);
266 extern void scr_relative_origin(int);
267 extern void scr_insert_mode(int);
268 extern void scr_set_tab(int);
269 extern void scr_rvideo_mode(int);
270 extern void scr_report_position(void);
271 extern void set_font_style(void);
272 extern void scr_charset_choose(int);
273 extern void scr_charset_set(int, unsigned int);
274 extern void set_multichar_encoding(const char *);
275 extern int scr_get_fgcolor(void);
276 extern int scr_get_bgcolor(void);
277 extern void scr_expose(int, int, int, int);
278 extern int scr_move_to(int, int);
279 extern int scr_page(int, int);
280 extern void scr_bell(void);
281 extern void scr_printscreen(int);
282 extern void scr_refresh(int);
283 extern int scr_strmatch(unsigned long, unsigned long, const char *);
284 extern void scr_search_scrollback(char *);
285 extern void scr_dump(void);
286 extern void scr_dump_to_file(const char *);
287 extern void selection_check(void);
288 extern void selection_write(unsigned char *, size_t);
289 extern void selection_fetch(Window, unsigned, int);
290 extern void selection_copy_string(Atom, char *, size_t);
291 extern void selection_copy(Atom);
292 extern void selection_paste(Atom);
293 extern void selection_reset(void);
294 extern void selection_clear(void);
295 extern void selection_setclr(int, int, int, int, int);
296 extern void selection_start(int, int);
297 extern void selection_start_colrow(int, int);
298 extern void selection_make(Time);
299 extern void selection_click(int, int, int);
300 extern void selection_delimit_word(int, int, row_col_t *, row_col_t *);
301 extern void selection_extend(int, int, int);
302 extern void selection_extend_colrow(int, int, int, int);
303 extern void selection_rotate(int, int);
304 extern void selection_send(XSelectionRequestEvent *);
305 extern void mouse_report(XButtonEvent *);
306 extern void twin_mouse_drag_report(XButtonEvent *);
307 extern void mouse_tracking(int, int, int, int, int);
308 extern void debug_colors(void);
309 #ifdef MULTI_CHARSET
310 extern int scr_multi2(void);
311 extern int scr_multi1(void);
312 #endif /* MULTI_CHARSET */
313 #ifdef ESCREEN
314 extern void parse_screen_status_if_necessary(void);
315 #endif
316 
317 _XFUNCPROTOEND
318 
319 #endif
320