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