From: Arnaud Lacombe <al@sigfpe.info>
[apps/madmutt.git] / mutt_curses.h
1 /*
2  * Copyright notice from original mutt:
3  * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4  * Copyright (C) 2004 g10 Code GmbH
5  *
6  * This file is part of mutt-ng, see http://www.muttng.org/.
7  * It's licensed under the GNU General Public License,
8  * please see the file GPL in the top level source directory.
9  */
10 #ifndef _MUTT_CURSES_H
11 #define _MUTT_CURSES_H
12
13 #ifdef USE_SLANG_CURSES
14
15 #ifndef unix                    /* this symbol is not defined by the hp-ux compiler (sigh) */
16 #define unix
17 #endif /* unix */
18
19 #include "slcurses.h"
20
21 #define KEY_DC SL_KEY_DELETE
22 #define KEY_IC SL_KEY_IC
23
24 /*
25  * ncurses and SLang seem to send different characters when the Enter key is
26  * pressed, so define some macros to properly detect the Enter key.
27  */
28 #define M_ENTER_C '\r'
29 #define M_ENTER_S "\r"
30
31 #else
32
33 #ifdef HAVE_NCURSESW_NCURSES_H
34 #include <ncursesw/ncurses.h>
35 #elif HAVE_NCURSES_NCURSES_H
36 #include <ncurses/ncurses.h>
37 #elif HAVE_NCURSES_H
38 #include <ncurses.h>
39 #else
40 #include <curses.h>
41 #endif
42
43 #define M_ENTER_C '\n'
44 #define M_ENTER_S "\n"
45
46 #endif /* USE_SLANG_CURSES */
47
48 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
49  * various places in Mutt
50  */
51 #ifdef lines
52 #undef lines
53 #endif /* lines */
54
55 #define CLEARLINE_WIN(x) move(x,(option(OPTMBOXPANE)?SidebarWidth:0)), clrtoeol()
56 #define CLEARLINE(x) move(x,0), clrtoeol()
57 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
58 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
59
60 #if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
61 #define curs_set(x)
62 #endif
63
64 #if !defined(USE_SLANG_CURSES) && defined(HAVE_BKGDSET)
65 #define BKGDSET(x) bkgdset (ColorDefs[x] | ' ')
66 #else
67 #define BKGDSET(x)
68 #endif
69
70 #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
71 void mutt_curs_set (int);
72 #else
73 #define mutt_curs_set(x)
74 #endif
75 #define PAGELEN (LINES-3)
76
77 #define ctrl(c) ((c)-'@')
78
79 #ifdef KEY_ENTER
80 #define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
81 #else
82 #define CI_is_return(c) ((c) == '\r' || (c) == '\n')
83 #endif
84
85 event_t mutt_getch (void);
86
87 void mutt_endwin (const char *);
88 void mutt_flushinp (void);
89 void mutt_refresh (void);
90 void mutt_resize_screen (void);
91 void mutt_ungetch (int, int);
92 void mutt_need_hard_redraw (void);
93
94 /* ----------------------------------------------------------------------------
95  * Support for color
96  */
97
98 enum {
99   MT_COLOR_HDEFAULT = 0,
100   MT_COLOR_QUOTED,
101   MT_COLOR_SIGNATURE,
102   MT_COLOR_INDICATOR,
103   MT_COLOR_STATUS,
104   MT_COLOR_TREE,
105   MT_COLOR_NORMAL,
106   MT_COLOR_ERROR,
107   MT_COLOR_TILDE,
108   MT_COLOR_MARKERS,
109   MT_COLOR_BODY,
110   MT_COLOR_HEADER,
111   MT_COLOR_MESSAGE,
112   MT_COLOR_ATTACHMENT,
113   MT_COLOR_SEARCH,
114   MT_COLOR_BOLD,
115   MT_COLOR_SIDEBAR,
116   MT_COLOR_UNDERLINE,
117   MT_COLOR_INDEX,
118   MT_COLOR_NEW,
119   MT_COLOR_FLAGGED,
120   MT_COLOR_MAX
121 };
122
123 typedef struct color_line {
124   regex_t rx;
125   char *pattern;
126   pattern_t *color_pattern;     /* compiled pattern to speed up index color
127                                    calculation */
128   short fg;
129   short bg;
130   int pair;
131   struct color_line *next;
132 } COLOR_LINE;
133
134 typedef struct {
135   const char* msg;
136   long pos;
137   long size;
138   char sizestr[SHORT_STRING];
139 } progress_t;
140
141 void mutt_progress_bar (progress_t* progress, long pos);
142
143 extern int *ColorQuote;
144 extern int ColorQuoteUsed;
145 extern int ColorDefs[];
146 extern COLOR_LINE *ColorHdrList;
147 extern COLOR_LINE *ColorBodyList;
148 extern COLOR_LINE *ColorIndexList;
149
150 void ci_init_color (void);
151 void ci_start_color (void);
152
153 #define SETCOLOR(X) attrset(ColorDefs[X])
154 #define ADDCOLOR(X) attron(ColorDefs[X])
155
156 #define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; }
157
158 /* ----------------------------------------------------------------------------
159  * These are here to avoid compiler warnings with -Wall under SunOS 4.1.x
160  */
161
162 #if !defined(STDC_HEADERS) && !defined(NCURSES_VERSION) && !defined(USE_SLANG_CURSES)
163 extern int endwin ();
164 extern int printw ();
165 extern int beep ();
166 extern int isendwin ();
167 extern int w32addch ();
168 extern int keypad ();
169 extern int wclrtobot ();
170 extern int mvprintw ();
171 extern int getcurx ();
172 extern int getcury ();
173 extern int noecho ();
174 extern int wdelch ();
175 extern int wrefresh ();
176 extern int wmove ();
177 extern int wclear ();
178 extern int waddstr ();
179 extern int wclrtoeol ();
180 #endif
181
182 #endif /* !_MUTT_CURSES_H */