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
89event_t mutt_getch (void);
90
91void mutt_endwin (const char *);
92void mutt_flushinp (void);
93void mutt_refresh (void);
94void mutt_resize_screen (void);
95void mutt_unget_event (int, int);
96void mutt_unget_string (char *);
97void mutt_push_macro_event (int, int);
98void mutt_flush_macro_to_endcond (void);
99void mutt_need_hard_redraw (void);
100
101/* ----------------------------------------------------------------------------
102 * Support for color
103 */
104
105enum
106{
107 MT_COLOR_HDEFAULT = 0,
108 MT_COLOR_QUOTED,
109 MT_COLOR_SIGNATURE,
110 MT_COLOR_INDICATOR,
111 MT_COLOR_STATUS,
112 MT_COLOR_TREE,
113 MT_COLOR_NORMAL,
114 MT_COLOR_ERROR,
115 MT_COLOR_TILDE,
116 MT_COLOR_MARKERS,
117 MT_COLOR_BODY,
118 MT_COLOR_HEADER,
119 MT_COLOR_MESSAGE,
120 MT_COLOR_ATTACHMENT,
121 MT_COLOR_SEARCH,
122 MT_COLOR_BOLD,
123 MT_COLOR_UNDERLINE,
124 MT_COLOR_INDEX,
125 MT_COLOR_PROMPT,
126#ifdef USE_SIDEBAR
127 MT_COLOR_DIVIDER,
128 MT_COLOR_FLAGGED,
129 MT_COLOR_HIGHLIGHT,
130 MT_COLOR_NEW,
131 MT_COLOR_SB_INDICATOR,
132 MT_COLOR_SB_SPOOLFILE,
133#endif
134 MT_COLOR_MAX
135};
136
137typedef struct color_line
138{
139 regex_t rx;
140 char *pattern;
141 pattern_t *color_pattern; /* compiled pattern to speed up index color
142 calculation */
143 short fg;
144 short bg;
145 int pair;
146 struct color_line *next;
147} COLOR_LINE;
148
149#define MUTT_PROGRESS_SIZE (1<<0) /* traffic-based progress */
150#define MUTT_PROGRESS_MSG (1<<1) /* message-based progress */
151
152typedef struct
153{
154 unsigned short inc;
155 unsigned short flags;
156 const char* msg;
157 long pos;
158 long size;
159 unsigned int timestamp;
160 char sizestr[SHORT_STRING];
161} progress_t;
162
163void mutt_progress_init (progress_t* progress, const char *msg,
164 unsigned short flags, unsigned short inc,
165 long size);
166/* If percent is positive, it is displayed as percentage, otherwise
167 * percentage is calculated from progress->size and pos if progress
168 * was initialized with positive size, otherwise no percentage is shown */
169void mutt_progress_update (progress_t* progress, long pos, int percent);
170
171/* Windows for different parts of the screen */
172typedef struct
173{
174 int rows;
175 int cols;
176 int row_offset;
177 int col_offset;
178} mutt_window_t;
179
180extern mutt_window_t *MuttHelpWindow;
181extern mutt_window_t *MuttIndexWindow;
182extern mutt_window_t *MuttStatusWindow;
183extern mutt_window_t *MuttMessageWindow;
184#ifdef USE_SIDEBAR
185extern mutt_window_t *MuttSidebarWindow;
186#endif
187
188void mutt_init_windows (void);
189void mutt_free_windows (void);
190void mutt_reflow_windows (void);
191int mutt_window_move (mutt_window_t *, int row, int col);
192int mutt_window_mvaddch (mutt_window_t *, int row, int col, const chtype ch);
193int mutt_window_mvaddstr (mutt_window_t *, int row, int col, const char *str);
194int mutt_window_mvprintw (mutt_window_t *, int row, int col, const char *fmt, ...);
195void mutt_window_clrtoeol (mutt_window_t *);
196void mutt_window_clearline (mutt_window_t *, int row);
197void mutt_window_getyx (mutt_window_t *, int *y, int *x);
198
199
200static inline int mutt_window_wrap_cols(mutt_window_t *win, short wrap)
201{
202 if (wrap < 0)
203 return win->cols > -wrap ? win->cols + wrap : win->cols;
204 else if (wrap)
205 return wrap < win->cols ? wrap : win->cols;
206 else
207 return win->cols;
208}
209
210extern int *ColorQuote;
211extern int ColorQuoteUsed;
212extern int ColorDefs[];
213extern COLOR_LINE *ColorHdrList;
214extern COLOR_LINE *ColorBodyList;
215extern COLOR_LINE *ColorIndexList;
216
217void ci_init_color (void);
218void ci_start_color (void);
219
220/* If the system has bkgdset() use it rather than attrset() so that the clr*()
221 * functions will properly set the background attributes all the way to the
222 * right column.
223 */
224#if defined(HAVE_BKGDSET)
225#define SETCOLOR(X) bkgdset(ColorDefs[X] | ' ')
226#define ATTRSET(X) bkgdset(X | ' ')
227#else
228#define SETCOLOR(X) attrset(ColorDefs[X])
229#define ATTRSET attrset
230#endif
231
232/* reset the color to the normal terminal color as defined by 'color normal ...' */
233#define NORMAL_COLOR SETCOLOR(MT_COLOR_NORMAL)
234
235#define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; }
236
237/* ----------------------------------------------------------------------------
238 * These are here to avoid compiler warnings with -Wall under SunOS 4.1.x
239 */
240
241#if !defined(STDC_HEADERS) && !defined(NCURSES_VERSION) && !defined(USE_SLANG_CURSES)
242extern int endwin();
243extern int printw();
244extern int beep();
245extern int isendwin();
246extern int w32addch();
247extern int keypad();
248extern int wclrtobot();
249extern int mvprintw();
250extern int getcurx();
251extern int getcury();
252extern int noecho();
253extern int wdelch();
254extern int wrefresh();
255extern int wmove();
256extern int wclear();
257extern int waddstr();
258extern int wclrtoeol();
259#endif
260
261#endif /* _MUTT_CURSES_H_ */