source: mainwin.c @ 65d3ef16

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 65d3ef16 was 8fa9562, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 18 years ago
Added background color support to owl. If we run out of color pairs during a painting of the screen, further background colors will be silently dropped. I'm hoping this doesn't happen often. The used pair list is reset with each draw, so only what's actually on screen matters.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1#include "owl.h"
2
3static const char fileIdent[] = "$Id$";
4
5void owl_mainwin_init(owl_mainwin *mw)
6{
7  mw->curtruncated=0;
8  mw->lastdisplayed=-1;
9}
10
11void owl_mainwin_redisplay(owl_mainwin *mw)
12{
13  owl_message *m;
14  int i, p, q, lines, isfull, viewsize;
15  int x, y, savey, recwinlines, start;
16  int topmsg, curmsg, fgcolor, bgcolor;
17  WINDOW *recwin;
18  owl_view *v;
19  owl_list *filtlist;
20  owl_filter *f;
21
22  recwin=owl_global_get_curs_recwin(&g);
23  topmsg=owl_global_get_topmsg(&g);
24  curmsg=owl_global_get_curmsg(&g);
25  v=owl_global_get_current_view(&g);
26  owl_fmtext_reset_colorpairs();
27
28  if (v==NULL) {
29    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
30    return;
31  }
32
33  werase(recwin);
34
35  recwinlines=owl_global_get_recwin_lines(&g);
36  topmsg=owl_global_get_topmsg(&g);
37  viewsize=owl_view_get_size(v);
38
39  /* if there are no messages or if topmsg is past the end of the messages,
40   * just draw a blank screen */
41  if (viewsize==0 || topmsg>=viewsize) {
42    if (viewsize==0) {
43      owl_global_set_topmsg(&g, 0);
44    }
45    mw->curtruncated=0;
46    mw->lastdisplayed=-1;
47    wnoutrefresh(recwin);
48    owl_global_set_needrefresh(&g);
49    return;
50  }
51
52  /* write the messages out */
53  isfull=0;
54  mw->curtruncated=0;
55  mw->lasttruncated=0;
56
57  for (i=topmsg; i<viewsize; i++) {
58    if (isfull) break;
59    m=owl_view_get_element(v, i);
60
61    /* hold on to y in case this is the current message or deleted */
62    getyx(recwin, y, x);
63    savey=y;
64
65    /* if it's the current message, account for a vert_offset */
66    if (i==owl_global_get_curmsg(&g)) {
67      start=owl_global_get_curmsg_vert_offset(&g);
68      lines=owl_message_get_numlines(m)-start;
69    } else {
70      start=0;
71      lines=owl_message_get_numlines(m);
72    }
73
74    /* if we match filters set the color */
75    fgcolor=OWL_COLOR_DEFAULT;
76    bgcolor=OWL_COLOR_DEFAULT;
77    filtlist=owl_global_get_filterlist(&g);
78    q=owl_list_get_size(filtlist);
79    for (p=0; p<q; p++) {
80      f=owl_list_get_element(filtlist, p);
81      if (owl_filter_message_match(f, m)) {
82        if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
83        if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
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(owl_mainwin *mw)
144{
145  if (mw->curtruncated) return(1);
146  return(0);
147}
148
149int owl_mainwin_is_last_msg_truncated(owl_mainwin *mw)
150{
151  if (mw->lasttruncated) return(1);
152  return(0);
153}
154
155int owl_mainwin_get_last_msg(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.