1 | #include "owl.h" |
---|
2 | |
---|
3 | static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data); |
---|
4 | static void owl_mainwin_resized(owl_window *w, void *user_data); |
---|
5 | |
---|
6 | void owl_mainwin_init(owl_mainwin *mw, owl_window *window) |
---|
7 | { |
---|
8 | mw->curtruncated=0; |
---|
9 | mw->lastdisplayed=-1; |
---|
10 | mw->window = g_object_ref(window); |
---|
11 | /* for now, just assume this object lasts forever */ |
---|
12 | g_signal_connect(window, "redraw", G_CALLBACK(owl_mainwin_redraw), mw); |
---|
13 | g_signal_connect(window, "resized", G_CALLBACK(owl_mainwin_resized), mw); |
---|
14 | owl_window_dirty(window); |
---|
15 | |
---|
16 | /* For now, we do not bother with connecting up dependencies; that'll be a |
---|
17 | * future refactor of the mainwin */ |
---|
18 | } |
---|
19 | |
---|
20 | static void owl_mainwin_resized(owl_window *w, void *user_data) |
---|
21 | { |
---|
22 | owl_mainwin *mw = user_data; |
---|
23 | |
---|
24 | /* in case any styles rely on the current width */ |
---|
25 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
26 | |
---|
27 | /* recalculate the topmsg to make sure the current message is on |
---|
28 | * screen */ |
---|
29 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
30 | |
---|
31 | /* Schedule a redraw */ |
---|
32 | owl_window_dirty(mw->window); |
---|
33 | } |
---|
34 | |
---|
35 | void owl_mainwin_redisplay(owl_mainwin *mw) |
---|
36 | { |
---|
37 | owl_window_dirty(mw->window); |
---|
38 | } |
---|
39 | |
---|
40 | static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data) |
---|
41 | { |
---|
42 | owl_message *m; |
---|
43 | int i, lines, isfull, viewsize; |
---|
44 | int x, y, savey, recwinlines, start; |
---|
45 | int topmsg, curmsg, markedmsgid, fgcolor, bgcolor; |
---|
46 | const owl_view *v; |
---|
47 | GList *fl; |
---|
48 | const owl_filter *f; |
---|
49 | owl_mainwin *mw = user_data; |
---|
50 | |
---|
51 | topmsg = owl_global_get_topmsg(&g); |
---|
52 | curmsg = owl_global_get_curmsg(&g); |
---|
53 | markedmsgid = owl_global_get_markedmsgid(&g); |
---|
54 | v = owl_global_get_current_view(&g); |
---|
55 | owl_fmtext_reset_colorpairs(); |
---|
56 | |
---|
57 | if (v==NULL) { |
---|
58 | owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay."); |
---|
59 | return; |
---|
60 | } |
---|
61 | |
---|
62 | werase(recwin); |
---|
63 | |
---|
64 | recwinlines=owl_global_get_recwin_lines(&g); |
---|
65 | viewsize=owl_view_get_size(v); |
---|
66 | |
---|
67 | /* if there are no messages or if topmsg is past the end of the messages, |
---|
68 | * just draw a blank screen */ |
---|
69 | if (viewsize==0 || topmsg>=viewsize) { |
---|
70 | if (viewsize==0) { |
---|
71 | owl_global_set_topmsg(&g, 0); |
---|
72 | } |
---|
73 | mw->curtruncated=0; |
---|
74 | mw->lastdisplayed=-1; |
---|
75 | return; |
---|
76 | } |
---|
77 | |
---|
78 | /* write the messages out */ |
---|
79 | isfull=0; |
---|
80 | mw->curtruncated=0; |
---|
81 | mw->lasttruncated=0; |
---|
82 | |
---|
83 | for (i=topmsg; i<viewsize; i++) { |
---|
84 | if (isfull) break; |
---|
85 | m=owl_view_get_element(v, i); |
---|
86 | |
---|
87 | /* hold on to y in case this is the current message or deleted */ |
---|
88 | getyx(recwin, y, x); |
---|
89 | savey=y; |
---|
90 | |
---|
91 | /* if it's the current message, account for a vert_offset */ |
---|
92 | if (i==owl_global_get_curmsg(&g)) { |
---|
93 | start=owl_global_get_curmsg_vert_offset(&g); |
---|
94 | lines=owl_message_get_numlines(m)-start; |
---|
95 | } else { |
---|
96 | start=0; |
---|
97 | lines=owl_message_get_numlines(m); |
---|
98 | } |
---|
99 | |
---|
100 | /* if we match filters set the color */ |
---|
101 | fgcolor=OWL_COLOR_DEFAULT; |
---|
102 | bgcolor=OWL_COLOR_DEFAULT; |
---|
103 | for (fl = g.filterlist; fl; fl = g_list_next(fl)) { |
---|
104 | f = fl->data; |
---|
105 | if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) || |
---|
106 | (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) { |
---|
107 | if (owl_filter_message_match(f, m)) { |
---|
108 | if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f); |
---|
109 | if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f); |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | /* if we'll fill the screen print a partial message */ |
---|
115 | if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1; |
---|
116 | if (y+lines > recwinlines) mw->lasttruncated=1; |
---|
117 | if (y+lines > recwinlines-1) { |
---|
118 | isfull=1; |
---|
119 | owl_message_curs_waddstr(m, recwin, |
---|
120 | start, |
---|
121 | start+recwinlines-y, |
---|
122 | owl_global_get_rightshift(&g), |
---|
123 | owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1, |
---|
124 | fgcolor, bgcolor); |
---|
125 | } else { |
---|
126 | /* otherwise print the whole thing */ |
---|
127 | owl_message_curs_waddstr(m, recwin, |
---|
128 | start, |
---|
129 | start+lines, |
---|
130 | owl_global_get_rightshift(&g), |
---|
131 | owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1, |
---|
132 | fgcolor, bgcolor); |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | /* is it the current message and/or deleted? */ |
---|
137 | getyx(recwin, y, x); |
---|
138 | wattrset(recwin, A_NORMAL); |
---|
139 | if (owl_global_get_rightshift(&g)==0) { /* this lame and should be fixed */ |
---|
140 | if (m==owl_view_get_element(v, curmsg)) { |
---|
141 | wmove(recwin, savey, 0); |
---|
142 | wattron(recwin, A_BOLD); |
---|
143 | if (owl_global_get_curmsg_vert_offset(&g)>0) { |
---|
144 | waddstr(recwin, "+"); |
---|
145 | } else { |
---|
146 | waddstr(recwin, "-"); |
---|
147 | } |
---|
148 | if (owl_message_is_delete(m)) { |
---|
149 | waddstr(recwin, "D"); |
---|
150 | } else if (markedmsgid == owl_message_get_id(m)) { |
---|
151 | waddstr(recwin, "*"); |
---|
152 | } else { |
---|
153 | waddstr(recwin, ">"); |
---|
154 | } |
---|
155 | wmove(recwin, y, x); |
---|
156 | wattroff(recwin, A_BOLD); |
---|
157 | } else if (owl_message_is_delete(m)) { |
---|
158 | wmove(recwin, savey, 0); |
---|
159 | waddstr(recwin, " D"); |
---|
160 | wmove(recwin, y, x); |
---|
161 | } else if (markedmsgid == owl_message_get_id(m)) { |
---|
162 | wmove(recwin, savey, 0); |
---|
163 | waddstr(recwin, " *"); |
---|
164 | wmove(recwin, y, x); |
---|
165 | } |
---|
166 | } |
---|
167 | wattroff(recwin, A_BOLD); |
---|
168 | } |
---|
169 | mw->lastdisplayed=i-1; |
---|
170 | } |
---|
171 | |
---|
172 | |
---|
173 | int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw) |
---|
174 | { |
---|
175 | if (mw->curtruncated) return(1); |
---|
176 | return(0); |
---|
177 | } |
---|
178 | |
---|
179 | int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw) |
---|
180 | { |
---|
181 | if (mw->lasttruncated) return(1); |
---|
182 | return(0); |
---|
183 | } |
---|
184 | |
---|
185 | int owl_mainwin_get_last_msg(const owl_mainwin *mw) |
---|
186 | { |
---|
187 | /* return the number of the last message displayed. -1 if none */ |
---|
188 | return(mw->lastdisplayed); |
---|
189 | } |
---|