more coding rules, simplifications.
[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 #else
36 #ifdef HAVE_NCURSES_NCURSES_H
37 #include <ncurses/ncurses.h>
38 #else
39 #ifdef HAVE_NCURSES_H
40 #include <ncurses.h>
41 #else
42 #include <curses.h>
43 #endif
44 #endif
45 #endif
46
47 #define M_ENTER_C '\n'
48 #define M_ENTER_S "\n"
49
50 #endif /* USE_SLANG_CURSES */
51
52 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
53  * various places in Mutt
54  */
55 #ifdef lines
56 #undef lines
57 #endif /* lines */
58
59 #define CLEARLINE_WIN(x) move(x,(option(OPTMBOXPANE)?SidebarWidth:0)), clrtoeol()
60 #define CLEARLINE(x) move(x,0), clrtoeol()
61 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
62 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
63
64 #if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
65 #define curs_set(x)
66 #endif
67
68 #if !defined(USE_SLANG_CURSES) && defined(HAVE_BKGDSET)
69 #define BKGDSET(x) bkgdset (ColorDefs[x] | ' ')
70 #else
71 #define BKGDSET(x)
72 #endif
73
74 #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
75 void mutt_curs_set (int);
76 #else
77 #define mutt_curs_set(x)
78 #endif
79 #define PAGELEN (LINES-3)
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
89 event_t mutt_getch (void);
90
91 void mutt_endwin (const char *);
92 void mutt_flushinp (void);
93 void mutt_refresh (void);
94 void mutt_resize_screen (void);
95 void mutt_ungetch (int, int);
96 void mutt_need_hard_redraw (void);
97
98 /* ----------------------------------------------------------------------------
99  * Support for color
100  */
101
102 enum {
103   MT_COLOR_HDEFAULT = 0,
104   MT_COLOR_QUOTED,
105   MT_COLOR_SIGNATURE,
106   MT_COLOR_INDICATOR,
107   MT_COLOR_STATUS,
108   MT_COLOR_TREE,
109   MT_COLOR_NORMAL,
110   MT_COLOR_ERROR,
111   MT_COLOR_TILDE,
112   MT_COLOR_MARKERS,
113   MT_COLOR_BODY,
114   MT_COLOR_HEADER,
115   MT_COLOR_MESSAGE,
116   MT_COLOR_ATTACHMENT,
117   MT_COLOR_SEARCH,
118   MT_COLOR_BOLD,
119   MT_COLOR_SIDEBAR,
120   MT_COLOR_UNDERLINE,
121   MT_COLOR_INDEX,
122   MT_COLOR_NEW,
123   MT_COLOR_FLAGGED,
124   MT_COLOR_MAX
125 };
126
127 typedef struct color_line {
128   regex_t rx;
129   char *pattern;
130   pattern_t *color_pattern;     /* compiled pattern to speed up index color
131                                    calculation */
132   short fg;
133   short bg;
134   int pair;
135   struct color_line *next;
136 } COLOR_LINE;
137
138 typedef struct {
139   const char* msg;
140   long pos;
141   long size;
142   char sizestr[SHORT_STRING];
143 } progress_t;
144
145 void mutt_progress_bar (progress_t* progress, long pos);
146
147 extern int *ColorQuote;
148 extern int ColorQuoteUsed;
149 extern int ColorDefs[];
150 extern COLOR_LINE *ColorHdrList;
151 extern COLOR_LINE *ColorBodyList;
152 extern COLOR_LINE *ColorIndexList;
153
154 void ci_init_color (void);
155 void ci_start_color (void);
156
157 #define SETCOLOR(X) attrset(ColorDefs[X])
158 #define ADDCOLOR(X) attron(ColorDefs[X])
159
160 #define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; }
161
162 /* ----------------------------------------------------------------------------
163  * These are here to avoid compiler warnings with -Wall under SunOS 4.1.x
164  */
165
166 #if !defined(STDC_HEADERS) && !defined(NCURSES_VERSION) && !defined(USE_SLANG_CURSES)
167 extern int endwin ();
168 extern int printw ();
169 extern int beep ();
170 extern int isendwin ();
171 extern int w32addch ();
172 extern int keypad ();
173 extern int wclrtobot ();
174 extern int mvprintw ();
175 extern int getcurx ();
176 extern int getcury ();
177 extern int noecho ();
178 extern int wdelch ();
179 extern int wrefresh ();
180 extern int wmove ();
181 extern int wclear ();
182 extern int waddstr ();
183 extern int wclrtoeol ();
184 #endif
185
186 #endif /* !_MUTT_CURSES_H */