[7d4fbcd] | 1 | #include "owl.h" |
---|
| 2 | |
---|
[1aee7d9] | 3 | static const char fileIdent[] = "$Id$"; |
---|
| 4 | |
---|
[7d4fbcd] | 5 | void owl_mainwin_init(owl_mainwin *mw) { |
---|
| 6 | mw->curtruncated=0; |
---|
| 7 | mw->lastdisplayed=-1; |
---|
| 8 | } |
---|
| 9 | |
---|
| 10 | void owl_mainwin_redisplay(owl_mainwin *mw) { |
---|
| 11 | owl_message *m; |
---|
[5eeea3b] | 12 | int i, p, q, lines, isfull, viewsize; |
---|
[7d4fbcd] | 13 | int x, y, savey, recwinlines, start; |
---|
| 14 | int topmsg, curmsg, color; |
---|
| 15 | WINDOW *recwin; |
---|
| 16 | owl_view *v; |
---|
| 17 | owl_list *filtlist; |
---|
| 18 | owl_filter *f; |
---|
| 19 | |
---|
| 20 | recwin=owl_global_get_curs_recwin(&g); |
---|
| 21 | topmsg=owl_global_get_topmsg(&g); |
---|
| 22 | curmsg=owl_global_get_curmsg(&g); |
---|
| 23 | v=owl_global_get_current_view(&g); |
---|
| 24 | |
---|
[f2f9314] | 25 | if (v==NULL) { |
---|
| 26 | owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay."); |
---|
| 27 | return; |
---|
| 28 | } |
---|
| 29 | |
---|
[7d4fbcd] | 30 | werase(recwin); |
---|
| 31 | |
---|
| 32 | recwinlines=owl_global_get_recwin_lines(&g); |
---|
| 33 | topmsg=owl_global_get_topmsg(&g); |
---|
[5eeea3b] | 34 | viewsize=owl_view_get_size(v); |
---|
[7d4fbcd] | 35 | |
---|
[5eeea3b] | 36 | /* if there are no messages or if topmsg is past the end of the messages, |
---|
| 37 | * just draw a blank screen */ |
---|
| 38 | if (viewsize==0 || topmsg>=viewsize) { |
---|
| 39 | if (viewsize==0) { |
---|
| 40 | owl_global_set_topmsg(&g, 0); |
---|
| 41 | } |
---|
[7d4fbcd] | 42 | mw->curtruncated=0; |
---|
| 43 | mw->lastdisplayed=-1; |
---|
| 44 | wnoutrefresh(recwin); |
---|
| 45 | owl_global_set_needrefresh(&g); |
---|
| 46 | return; |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | /* write the messages out */ |
---|
| 50 | isfull=0; |
---|
| 51 | mw->curtruncated=0; |
---|
[f2e36b5] | 52 | mw->lasttruncated=0; |
---|
[5eeea3b] | 53 | |
---|
| 54 | for (i=topmsg; i<viewsize; i++) { |
---|
[7d4fbcd] | 55 | if (isfull) break; |
---|
| 56 | m=owl_view_get_element(v, i); |
---|
| 57 | |
---|
| 58 | /* hold on to y in case this is the current message or deleted */ |
---|
| 59 | getyx(recwin, y, x); |
---|
| 60 | savey=y; |
---|
| 61 | |
---|
| 62 | /* if it's the current message, account for a vert_offset */ |
---|
| 63 | if (i==owl_global_get_curmsg(&g)) { |
---|
| 64 | start=owl_global_get_curmsg_vert_offset(&g); |
---|
| 65 | lines=owl_message_get_numlines(m)-start; |
---|
| 66 | } else { |
---|
| 67 | start=0; |
---|
| 68 | lines=owl_message_get_numlines(m); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | /* if we match filters set the color */ |
---|
| 72 | color=OWL_COLOR_DEFAULT; |
---|
| 73 | filtlist=owl_global_get_filterlist(&g); |
---|
| 74 | q=owl_list_get_size(filtlist); |
---|
| 75 | for (p=0; p<q; p++) { |
---|
| 76 | f=owl_list_get_element(filtlist, p); |
---|
| 77 | if (owl_filter_message_match(f, m)) { |
---|
| 78 | if (owl_filter_get_color(f)!=OWL_COLOR_DEFAULT) color=owl_filter_get_color(f); |
---|
| 79 | } |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | /* if we'll fill the screen print a partial message */ |
---|
| 83 | if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1; |
---|
[f2e36b5] | 84 | if (y+lines > recwinlines) mw->lasttruncated=1; |
---|
[7d4fbcd] | 85 | if (y+lines > recwinlines-1) { |
---|
| 86 | isfull=1; |
---|
| 87 | owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g), |
---|
| 88 | start, |
---|
| 89 | start+recwinlines-y, |
---|
| 90 | owl_global_get_rightshift(&g), |
---|
| 91 | owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1, |
---|
| 92 | color); |
---|
| 93 | } else { |
---|
| 94 | /* otherwise print the whole thing */ |
---|
| 95 | owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g), |
---|
| 96 | start, |
---|
| 97 | start+lines, |
---|
| 98 | owl_global_get_rightshift(&g), |
---|
| 99 | owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1, |
---|
| 100 | color); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | /* is it the current message and/or deleted? */ |
---|
| 105 | getyx(recwin, y, x); |
---|
| 106 | wattrset(recwin, A_NORMAL); |
---|
| 107 | if (owl_global_get_rightshift(&g)==0) { /* this lame and should be fixed */ |
---|
| 108 | if (m==owl_view_get_element(v, curmsg)) { |
---|
| 109 | wmove(recwin, savey, 0); |
---|
| 110 | wattron(recwin, A_BOLD); |
---|
| 111 | if (owl_global_get_curmsg_vert_offset(&g)>0) { |
---|
| 112 | waddstr(recwin, "+"); |
---|
| 113 | } else { |
---|
| 114 | waddstr(recwin, "-"); |
---|
| 115 | } |
---|
| 116 | if (!owl_message_is_delete(m)) { |
---|
| 117 | waddstr(recwin, ">"); |
---|
| 118 | } else { |
---|
| 119 | waddstr(recwin, "D"); |
---|
| 120 | } |
---|
| 121 | wmove(recwin, y, x); |
---|
| 122 | wattroff(recwin, A_BOLD); |
---|
| 123 | } else if (owl_message_is_delete(m)) { |
---|
| 124 | wmove(recwin, savey, 0); |
---|
| 125 | waddstr(recwin, " D"); |
---|
| 126 | wmove(recwin, y, x); |
---|
| 127 | } |
---|
| 128 | } |
---|
| 129 | wattroff(recwin, A_BOLD); |
---|
| 130 | } |
---|
| 131 | mw->lastdisplayed=i-1; |
---|
| 132 | |
---|
| 133 | wnoutrefresh(recwin); |
---|
| 134 | owl_global_set_needrefresh(&g); |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | |
---|
| 138 | int owl_mainwin_is_curmsg_truncated(owl_mainwin *mw) { |
---|
| 139 | if (mw->curtruncated) return(1); |
---|
| 140 | return(0); |
---|
| 141 | } |
---|
| 142 | |
---|
[f2e36b5] | 143 | int owl_mainwin_is_last_msg_truncated(owl_mainwin *mw) { |
---|
| 144 | if (mw->lasttruncated) return(1); |
---|
| 145 | return(0); |
---|
| 146 | } |
---|
| 147 | |
---|
[7d4fbcd] | 148 | int owl_mainwin_get_last_msg(owl_mainwin *mw) { |
---|
| 149 | /* return the number of the last message displayed. -1 if none */ |
---|
| 150 | return(mw->lastdisplayed); |
---|
| 151 | } |
---|