source: mainwin.c @ 7cfb1df

release-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7cfb1df was 9bda818, checked in by Anders Kaseorg <andersk@mit.edu>, 15 years ago
owl_mainwin_redisplay: Remove redundant call to owl_global_get_topmsg. Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Property mode set to 100644
File size: 4.2 KB
Line 
1#include "owl.h"
2
3void owl_mainwin_init(owl_mainwin *mw)
4{
5  mw->curtruncated=0;
6  mw->lastdisplayed=-1;
7}
8
9void owl_mainwin_redisplay(owl_mainwin *mw)
10{
11  owl_message *m;
12  int i, p, q, lines, isfull, viewsize;
13  int x, y, savey, recwinlines, start;
14  int topmsg, curmsg, fgcolor, bgcolor;
15  WINDOW *recwin;
16  const owl_view *v;
17  const owl_list *filtlist;
18  const 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  owl_fmtext_reset_colorpairs();
25
26  if (v==NULL) {
27    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
28    return;
29  }
30
31  werase(recwin);
32
33  recwinlines=owl_global_get_recwin_lines(&g);
34  viewsize=owl_view_get_size(v);
35
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    }
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;
52  mw->lasttruncated=0;
53
54  for (i=topmsg; i<viewsize; i++) {
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    fgcolor=OWL_COLOR_DEFAULT;
73    bgcolor=OWL_COLOR_DEFAULT;
74    filtlist=owl_global_get_filterlist(&g);
75    q=owl_list_get_size(filtlist);
76    for (p=0; p<q; p++) {
77      f=owl_list_get_element(filtlist, p);
78      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
79          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
80        if (owl_filter_message_match(f, m)) {
81          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
82          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
83        }
84      }
85    }
86
87    /* if we'll fill the screen print a partial message */
88    if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
89    if (y+lines > recwinlines) mw->lasttruncated=1;
90    if (y+lines > recwinlines-1) {
91      isfull=1;
92      owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g),
93                               start,
94                               start+recwinlines-y,
95                               owl_global_get_rightshift(&g),
96                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
97                               fgcolor, bgcolor);
98    } else {
99      /* otherwise print the whole thing */
100      owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g),
101                               start,
102                               start+lines,
103                               owl_global_get_rightshift(&g),
104                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
105                               fgcolor, bgcolor);
106    }
107
108
109    /* is it the current message and/or deleted? */
110    getyx(recwin, y, x);
111    wattrset(recwin, A_NORMAL);
112    if (owl_global_get_rightshift(&g)==0) {   /* this lame and should be fixed */
113      if (m==owl_view_get_element(v, curmsg)) {
114        wmove(recwin, savey, 0);
115        wattron(recwin, A_BOLD);       
116        if (owl_global_get_curmsg_vert_offset(&g)>0) {
117          waddstr(recwin, "+");
118        } else {
119          waddstr(recwin, "-");
120        }
121        if (!owl_message_is_delete(m)) {
122          waddstr(recwin, ">");
123        } else {
124          waddstr(recwin, "D");
125        }
126        wmove(recwin, y, x);
127        wattroff(recwin, A_BOLD);
128      } else if (owl_message_is_delete(m)) {
129        wmove(recwin, savey, 0);
130        waddstr(recwin, " D");
131        wmove(recwin, y, x);
132      }
133    }
134    wattroff(recwin, A_BOLD);
135  }
136  mw->lastdisplayed=i-1;
137
138  wnoutrefresh(recwin);
139  owl_global_set_needrefresh(&g);
140}
141
142
143int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
144{
145  if (mw->curtruncated) return(1);
146  return(0);
147}
148
149int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
150{
151  if (mw->lasttruncated) return(1);
152  return(0);
153}
154
155int owl_mainwin_get_last_msg(const owl_mainwin *mw)
156{
157  /* return the number of the last message displayed. -1 if none */
158  return(mw->lastdisplayed);
159}
Note: See TracBrowser for help on using the repository browser.