Nico Golde:
[apps/madmutt.git] / mutt_curses.h
1 /*
2  * Copyright (C) 1996-2000 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., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
18  */ 
19
20 #ifdef USE_SLANG_CURSES
21
22 #ifndef unix /* this symbol is not defined by the hp-ux compiler (sigh) */
23 #define unix
24 #endif /* unix */
25
26 #include "slcurses.h"
27
28 #define KEY_DC SL_KEY_DELETE
29 #define KEY_IC SL_KEY_IC
30
31 /*
32  * ncurses and SLang seem to send different characters when the Enter key is
33  * pressed, so define some macros to properly detect the Enter key.
34  */
35 #define M_ENTER_C '\r'
36 #define M_ENTER_S "\r"
37
38 #else
39
40 #ifdef HAVE_NCURSESW_NCURSES_H
41 #include <ncursesw/ncurses.h>
42 #else
43 #ifdef HAVE_NCURSES_H
44 #include <ncurses.h>
45 #else
46 #include <curses.h>
47 #endif
48 #endif
49
50 #define M_ENTER_C '\n'
51 #define M_ENTER_S "\n"
52
53 #endif /* USE_SLANG_CURSES */
54
55 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
56  * various places in Mutt
57  */
58 #ifdef lines
59 #undef lines
60 #endif /* lines */
61
62 #define CLEARLINE_WIN(x) move(x,SidebarWidth), clrtoeol()
63 #define CLEARLINE(x) move(x,0), clrtoeol()
64 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
65 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
66
67 #if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
68 #define curs_set(x)
69 #endif
70
71 #if !defined(USE_SLANG_CURSES) && defined(HAVE_BKGDSET)
72 #define BKGDSET(x) bkgdset (ColorDefs[x] | ' ')
73 #else
74 #define BKGDSET(x)
75 #endif
76
77 #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
78 void mutt_curs_set (int);
79 #else
80 #define mutt_curs_set(x)
81 #endif
82 #define PAGELEN (LINES-3)
83
84 #define ctrl(c) ((c)-'@')
85
86 #ifdef KEY_ENTER
87 #define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
88 #else
89 #define CI_is_return(c) ((c) == '\r' || (c) == '\n')
90 #endif
91
92 event_t mutt_getch (void);
93
94 void mutt_endwin (const char *);
95 void mutt_flushinp (void);
96 void mutt_refresh (void);
97 void mutt_resize_screen (void);
98 void mutt_ungetch (int, int);
99 void mutt_need_hard_redraw (void);
100
101 /* ----------------------------------------------------------------------------
102  * Support for color
103  */
104
105 enum
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_SIDEBAR,
124   MT_COLOR_UNDERLINE,
125   MT_COLOR_INDEX,
126   MT_COLOR_NEW,
127   MT_COLOR_FLAGGED,
128   MT_COLOR_MAX
129 };
130
131 typedef struct color_line
132 {
133   regex_t rx;
134   char *pattern;
135   pattern_t *color_pattern; /* compiled pattern to speed up index color
136                                calculation */
137   short fg;
138   short bg;
139   int pair;
140   struct color_line *next;
141 } COLOR_LINE;
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