begin to move ui code into the lib-ui
[apps/madmutt.git] / lib-ui / 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 #include "mutt.h"
14
15 #ifdef USE_SLANG_CURSES
16
17 #ifndef unix                    /* this symbol is not defined by the hp-ux compiler (sigh) */
18 #define unix
19 #endif /* unix */
20
21 #include "slcurses.h"
22
23 #define KEY_DC SL_KEY_DELETE
24 #define KEY_IC SL_KEY_IC
25
26 /*
27  * ncurses and SLang seem to send different characters when the Enter key is
28  * pressed, so define some macros to properly detect the Enter key.
29  */
30 #define M_ENTER_C '\r'
31 #define M_ENTER_S "\r"
32
33 #else
34
35 #ifdef HAVE_NCURSESW_NCURSES_H
36 #include <ncursesw/ncurses.h>
37 #else
38 #ifdef HAVE_NCURSES_NCURSES_H
39 #include <ncurses/ncurses.h>
40 #else
41 #ifdef HAVE_NCURSES_H
42 #include <ncurses.h>
43 #else
44 #include <curses.h>
45 #endif
46 #endif
47 #endif
48
49 #define M_ENTER_C '\n'
50 #define M_ENTER_S "\n"
51
52 #endif /* USE_SLANG_CURSES */
53
54 /* AIX defines ``lines'' in <term.h>, but it's used as a var name in
55  * various places in Mutt
56  */
57 #ifdef lines
58 #undef lines
59 #endif /* lines */
60
61 #define CLEARLINE_WIN(x) move(x,(option(OPTMBOXPANE)?SidebarWidth:0)), clrtoeol()
62 #define CLEARLINE(x) move(x,0), clrtoeol()
63 #define CENTERLINE(x,y) move(y, (COLS-strlen(x))/2), addstr(x)
64 #define BEEP() do { if (option (OPTBEEP)) beep(); } while (0)
65
66 #if ! (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
67 #define curs_set(x)
68 #endif
69
70 #if !defined(USE_SLANG_CURSES) && defined(HAVE_BKGDSET)
71 #define BKGDSET(x) bkgdset (ColorDefs[x] | ' ')
72 #else
73 #define BKGDSET(x)
74 #endif
75
76 #if (defined(USE_SLANG_CURSES) || defined(HAVE_CURS_SET))
77 void mutt_curs_set (int);
78 #else
79 #define mutt_curs_set(x)
80 #endif
81 #define PAGELEN (LINES-3)
82
83 #define ctrl(c) ((c)-'@')
84
85 #ifdef KEY_ENTER
86 #define CI_is_return(c) ((c) == '\r' || (c) == '\n' || (c) == KEY_ENTER)
87 #else
88 #define CI_is_return(c) ((c) == '\r' || (c) == '\n')
89 #endif
90
91 event_t mutt_getch (void);
92
93 void mutt_endwin (const char *);
94 void mutt_flushinp (void);
95 void mutt_refresh (void);
96 void mutt_resize_screen (void);
97 void mutt_ungetch (int, int);
98 void mutt_need_hard_redraw (void);
99
100 /* ----------------------------------------------------------------------------
101  * Support for color
102  */
103
104 enum {
105   MT_COLOR_HDEFAULT = 0,
106   MT_COLOR_QUOTED,
107   MT_COLOR_SIGNATURE,
108   MT_COLOR_INDICATOR,
109   MT_COLOR_STATUS,
110   MT_COLOR_TREE,
111   MT_COLOR_NORMAL,
112   MT_COLOR_ERROR,
113   MT_COLOR_TILDE,
114   MT_COLOR_MARKERS,
115   MT_COLOR_BODY,
116   MT_COLOR_HEADER,
117   MT_COLOR_MESSAGE,
118   MT_COLOR_ATTACHMENT,
119   MT_COLOR_SEARCH,
120   MT_COLOR_BOLD,
121   MT_COLOR_SIDEBAR,
122   MT_COLOR_UNDERLINE,
123   MT_COLOR_INDEX,
124   MT_COLOR_NEW,
125   MT_COLOR_FLAGGED,
126   MT_COLOR_MAX
127 };
128
129 typedef struct color_line {
130   regex_t rx;
131   char *pattern;
132   pattern_t *color_pattern;     /* compiled pattern to speed up index color
133                                    calculation */
134   short fg;
135   short bg;
136   int pair;
137   struct color_line *next;
138 } COLOR_LINE;
139
140 typedef struct {
141   const char* msg;
142   long pos;
143   long size;
144   char sizestr[SHORT_STRING];
145 } progress_t;
146
147 void mutt_progress_bar (progress_t* progress, long pos);
148
149 extern int *ColorQuote;
150 extern int ColorQuoteUsed;
151 extern int ColorDefs[];
152 extern COLOR_LINE *ColorHdrList;
153 extern COLOR_LINE *ColorBodyList;
154 extern COLOR_LINE *ColorIndexList;
155
156 void ci_init_color (void);
157 void ci_start_color (void);
158
159 #define SETCOLOR(X) attrset(ColorDefs[X])
160 #define ADDCOLOR(X) attron(ColorDefs[X])
161
162 #define MAYBE_REDRAW(x) if (option (OPTNEEDREDRAW)) { unset_option (OPTNEEDREDRAW); x = REDRAW_FULL; }
163
164 #endif /* !_MUTT_CURSES_H */