source: mainwin.c @ 8a2815b

release-1.10release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8a2815b was 129e609, checked in by Nelson Elhage <nelhage@mit.edu>, 15 years ago
Use a owl_dict to store the list of filters. Cathy Zhang reported that narrowing to filters that reference other filters is significantly slower than narrowing to filters that don't. The culprit is almost certainly the linear lookup of filters by name, which we currently do on each filter evaluation. Switch to using an owl_dict, which will now do a binary search over the filter list. We could potentially get this even faster by caching the owl_filter itself inside the owl_filterelement, and invalidating it somehow on filter redefinition, but we can save that sort of cleverness for later, if necessary. We also store the filters in a linked list, in order to preserve the ability to traverse them in order, for ":show filters" and for coloring.
  • Property mode set to 100644
File size: 4.4 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, lines, isfull, viewsize;
13  int x, y, savey, recwinlines, start;
14  int topmsg, curmsg, markedmsgid, fgcolor, bgcolor;
15  WINDOW *recwin;
16  const owl_view *v;
17  GList *fl;
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  markedmsgid = owl_global_get_markedmsgid(&g);
24  v = owl_global_get_current_view(&g);
25  owl_fmtext_reset_colorpairs();
26
27  if (v==NULL) {
28    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
29    return;
30  }
31
32  werase(recwin);
33
34  recwinlines=owl_global_get_recwin_lines(&g);
35  viewsize=owl_view_get_size(v);
36
37  /* if there are no messages or if topmsg is past the end of the messages,
38   * just draw a blank screen */
39  if (viewsize==0 || topmsg>=viewsize) {
40    if (viewsize==0) {
41      owl_global_set_topmsg(&g, 0);
42    }
43    mw->curtruncated=0;
44    mw->lastdisplayed=-1;
45    wnoutrefresh(recwin);
46    owl_global_set_needrefresh(&g);
47    return;
48  }
49
50  /* write the messages out */
51  isfull=0;
52  mw->curtruncated=0;
53  mw->lasttruncated=0;
54
55  for (i=topmsg; i<viewsize; i++) {
56    if (isfull) break;
57    m=owl_view_get_element(v, i);
58
59    /* hold on to y in case this is the current message or deleted */
60    getyx(recwin, y, x);
61    savey=y;
62
63    /* if it's the current message, account for a vert_offset */
64    if (i==owl_global_get_curmsg(&g)) {
65      start=owl_global_get_curmsg_vert_offset(&g);
66      lines=owl_message_get_numlines(m)-start;
67    } else {
68      start=0;
69      lines=owl_message_get_numlines(m);
70    }
71
72    /* if we match filters set the color */
73    fgcolor=OWL_COLOR_DEFAULT;
74    bgcolor=OWL_COLOR_DEFAULT;
75    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
76      f = fl->data;
77      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
78          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
79        if (owl_filter_message_match(f, m)) {
80          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
81          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
82        }
83      }
84    }
85
86    /* if we'll fill the screen print a partial message */
87    if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
88    if (y+lines > recwinlines) mw->lasttruncated=1;
89    if (y+lines > recwinlines-1) {
90      isfull=1;
91      owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g),
92                               start,
93                               start+recwinlines-y,
94                               owl_global_get_rightshift(&g),
95                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
96                               fgcolor, bgcolor);
97    } else {
98      /* otherwise print the whole thing */
99      owl_message_curs_waddstr(m, owl_global_get_curs_recwin(&g),
100                               start,
101                               start+lines,
102                               owl_global_get_rightshift(&g),
103                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
104                               fgcolor, bgcolor);
105    }
106
107
108    /* is it the current message and/or deleted? */
109    getyx(recwin, y, x);
110    wattrset(recwin, A_NORMAL);
111    if (owl_global_get_rightshift(&g)==0) {   /* this lame and should be fixed */
112      if (m==owl_view_get_element(v, curmsg)) {
113        wmove(recwin, savey, 0);
114        wattron(recwin, A_BOLD);       
115        if (owl_global_get_curmsg_vert_offset(&g)>0) {
116          waddstr(recwin, "+");
117        } else {
118          waddstr(recwin, "-");
119        }
120        if (owl_message_is_delete(m)) {
121          waddstr(recwin, "D");
122        } else if (markedmsgid == owl_message_get_id(m)) {
123          waddstr(recwin, "*");
124        } else {
125          waddstr(recwin, ">");
126        }
127        wmove(recwin, y, x);
128        wattroff(recwin, A_BOLD);
129      } else if (owl_message_is_delete(m)) {
130        wmove(recwin, savey, 0);
131        waddstr(recwin, " D");
132        wmove(recwin, y, x);
133      } else if (markedmsgid == owl_message_get_id(m)) {
134        wmove(recwin, savey, 0);
135        waddstr(recwin, " *");
136        wmove(recwin, y, x);
137      }
138    }
139    wattroff(recwin, A_BOLD);
140  }
141  mw->lastdisplayed=i-1;
142
143  wnoutrefresh(recwin);
144  owl_global_set_needrefresh(&g);
145}
146
147
148int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
149{
150  if (mw->curtruncated) return(1);
151  return(0);
152}
153
154int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
155{
156  if (mw->lasttruncated) return(1);
157  return(0);
158}
159
160int owl_mainwin_get_last_msg(const owl_mainwin *mw)
161{
162  /* return the number of the last message displayed. -1 if none */
163  return(mw->lastdisplayed);
164}
Note: See TracBrowser for help on using the repository browser.