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