mutt stable branch with some hacks
1/*
2 * Copyright (C) 1996-2000,2012 Michael R. Elkins <me@mutt.org>
3 * Copyright (C) 2004 g10 Code GmbH
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20#ifndef _MUTT_CURSES_H_
21#define _MUTT_CURSES_H_ 1
22
23#ifdef USE_SLANG_CURSES
24
25#ifndef unix /* this symbol is not defined by the hp-ux compiler (sigh) */
26#define unix
27#endif /* unix */
28
29#include <slang.h> /* in addition to slcurses.h, we need slang.h for the version
30 number to test for 2.x having UTF-8 support in main.c */
31#include <slcurses.h>
32
33#define KEY_DC SL_KEY_DELETE
34#define KEY_IC SL_KEY_IC
35
36/*
37 * ncurses and SLang seem to send different characters when the Enter key is
38 * pressed, so define some macros to properly detect the Enter key.
39 */
40#define MUTT_ENTER_C '\r'
41#define MUTT_ENTER_S "\r"
42
43#else /* USE_SLANG_CURSES */
44
45#if HAVE_NCURSESW_NCURSES_H
46# include <ncursesw/ncurses.h>
47#elif HAVE_NCURSES_NCURSES_H
48# include <ncurses/ncurses.h>
49#elif HAVE_NCURSES_H
50# include <ncurses.h>
51#else
52# include <curses.h>
53#endif
54
55#define MUTT_ENTER_C '\n'
56#define MUTT_ENTER_S "\n"
57
58#endif /* USE_SLANG_CURSES */
59
60/* AIX defines ``lines'' in <term.h>, but it's used as a var name in
61 * various places in Mutt
62 */
63#ifdef lines
64#undef lines
65#endif /* lines */
66
67#define CLEARLINE(win,x) mutt_window_clearline(win, x)
68#define CENTERLINE(win,x,y) mutt_window_move(win, y, (win->cols-strlen(x))/2), addstr(x)
69#define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
70
71#if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
72#define curs_set(x)
73#endif
74
75#if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
76void mutt_curs_set (int);
77#else
78#define mutt_curs_set(x)
79#endif
80
81#define ctrl(c) ((c)-'@')
82
83#ifdef KEY_ENTER
84#define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
85#else
86#define CI_is_return(c) ((c) == '\r' || (c) == '\n')
87#endif
88
89extern int MuttGetchTimeout;
90
91event_t mutt_getch (void);
92
93void mutt_getch_timeout (int);
94void mutt_endwin (const char *);
95void mutt_flushinp (void);
96void mutt_refresh (void);
97void mutt_resize_screen (void);
98void mutt_unget_event (int, int);
99void mutt_unget_string (char *);
100void mutt_push_macro_event (int, int);
101void mutt_flush_macro_to_endcond (void);
102void mutt_flush_unget_to_endcond (void);
103void mutt_need_hard_redraw (void);
104
105/* ----------------------------------------------------------------------------
106 * Support for color
107 */
108
109enum
110{
111 MT_COLOR_HDEFAULT = 0,
112 MT_COLOR_QUOTED,
113 MT_COLOR_SIGNATURE,
114 MT_COLOR_INDICATOR,
115 MT_COLOR_STATUS,
116 MT_COLOR_TREE,
117 MT_COLOR_NORMAL,
118 MT_COLOR_ERROR,
119 MT_COLOR_TILDE,
120 MT_COLOR_MARKERS,
121 MT_COLOR_BODY,
122 MT_COLOR_HEADER,
123 MT_COLOR_MESSAGE,
124 MT_COLOR_ATTACHMENT,
125 MT_COLOR_SEARCH,
126 MT_COLOR_BOLD,
127 MT_COLOR_UNDERLINE,
128 MT_COLOR_INDEX,
129 MT_COLOR_PROMPT,
130#ifdef USE_SIDEBAR
131 MT_COLOR_DIVIDER,
132 MT_COLOR_FLAGGED,
133 MT_COLOR_HIGHLIGHT,
134 MT_COLOR_NEW,
135 MT_COLOR_SB_INDICATOR,
136 MT_COLOR_SB_SPOOLFILE,
137#endif
138 MT_COLOR_COMPOSE_HEADER,
139 MT_COLOR_COMPOSE_SECURITY_ENCRYPT,
140 MT_COLOR_COMPOSE_SECURITY_SIGN,
141 MT_COLOR_COMPOSE_SECURITY_BOTH,
142 MT_COLOR_COMPOSE_SECURITY_NONE,
143 MT_COLOR_MAX
144};
145
146typedef struct color_line
147{
148 regex_t rx;
149 char *pattern;
150 pattern_t *color_pattern; /* compiled pattern to speed up index color
151 calculation */
152 short fg;
153 short bg;
154 int pair;
155 struct color_line *next;
156
157 unsigned int stop_matching : 1; /* used by the pager for body patterns,
158 to prevent the color from being retried
159 once it fails. */
160} COLOR_LINE;
161
162#define MUTT_PROGRESS_SIZE (1<<0) /* traffic-based progress */
163#define MUTT_PROGRESS_MSG (1<<1) /* message-based progress */
164
165typedef struct
166{
167 unsigned short inc;
168 unsigned short flags;
169 const char* msg;
170 long pos;
171 long size;
172 unsigned int timestamp;
173 char sizestr[SHORT_STRING];
174} progress_t;
175
176void mutt_progress_init (progress_t* progress, const char *msg,
177 unsigned short flags, unsigned short inc,
178 long size);
179/* If percent is positive, it is displayed as percentage, otherwise
180 * percentage is calculated from progress->size and pos if progress
181 * was initialized with positive size, otherwise no percentage is shown */
182void mutt_progress_update (progress_t* progress, long pos, int percent);
183
184/* Windows for different parts of the screen */
185typedef struct
186{
187 int rows;
188 int cols;
189 int row_offset;
190 int col_offset;
191} mutt_window_t;
192
193extern mutt_window_t *MuttHelpWindow;
194extern mutt_window_t *MuttIndexWindow;
195extern mutt_window_t *MuttStatusWindow;
196extern mutt_window_t *MuttMessageWindow;
197#ifdef USE_SIDEBAR
198extern mutt_window_t *MuttSidebarWindow;
199#endif
200
201void mutt_init_windows (void);
202void mutt_free_windows (void);
203void mutt_reflow_windows (void);
204int mutt_window_move (mutt_window_t *, int row, int col);
205int mutt_window_mvaddch (mutt_window_t *, int row, int col, const chtype ch);
206int mutt_window_mvaddstr (mutt_window_t *, int row, int col, const char *str);
207int mutt_window_mvprintw (mutt_window_t *, int row, int col, const char *fmt, ...);
208void mutt_window_clrtoeol (mutt_window_t *);
209void mutt_window_clearline (mutt_window_t *, int row);
210void mutt_window_getyx (mutt_window_t *, int *y, int *x);
211
212
213static inline int mutt_window_wrap_cols(mutt_window_t *win, short wrap)
214{
215 if (wrap < 0)
216 return win->cols > -wrap ? win->cols + wrap : win->cols;
217 else if (wrap)
218 return wrap < win->cols ? wrap : win->cols;
219 else
220 return win->cols;
221}
222
223extern int *ColorQuote;
224extern int ColorQuoteUsed;
225extern int ColorDefs[];
226extern COLOR_LINE *ColorHdrList;
227extern COLOR_LINE *ColorBodyList;
228extern COLOR_LINE *ColorIndexList;
229
230void ci_init_color (void);
231void ci_start_color (void);
232
233/* If the system has bkgdset() use it rather than attrset() so that the clr*()
234 * functions will properly set the background attributes all the way to the
235 * right column.
236 */
237#if defined(HAVE_BKGDSET)
238#define SETCOLOR(X) bkgdset(ColorDefs[X] | ' ')
239#define ATTRSET(X) bkgdset(X | ' ')
240#else
241#define SETCOLOR(X) attrset(ColorDefs[X])
242#define ATTRSET attrset
243#endif
244
245/* reset the color to the normal terminal color as defined by 'color normal ...' */
246#define NORMAL_COLOR SETCOLOR(MT_COLOR_NORMAL)
247
248/* ----------------------------------------------------------------------------
249 * These are here to avoid compiler warnings with -Wall under SunOS 4.1.x
250 */
251
252#if !defined(STDC_HEADERS) && !defined(NCURSES_VERSION) && !defined(USE_SLANG_CURSES)
253extern int endwin();
254extern int printw();
255extern int beep();
256extern int isendwin();
257extern int w32addch();
258extern int keypad();
259extern int wclrtobot();
260extern int mvprintw();
261extern int getcurx();
262extern int getcury();
263extern int noecho();
264extern int wdelch();
265extern int wrefresh();
266extern int wmove();
267extern int wclear();
268extern int waddstr();
269extern int wclrtoeol();
270#endif
271
272#endif /* _MUTT_CURSES_H_ */