source: mainwin.c @ 40597e7

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 40597e7 was 521e600, checked in by David Benjamin <davidben@mit.edu>, 15 years ago
Dirty windows when we init them
  • Property mode set to 100644
File size: 5.3 KB
Line 
1#include "owl.h"
2
3static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data);
4static void owl_mainwin_resized(owl_window *w, void *user_data);
5
6void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
7{
8  mw->curtruncated=0;
9  mw->lastdisplayed=-1;
10  mw->window = g_object_ref(window);
11  /* for now, just assume this object lasts forever */
12  g_signal_connect(window, "redraw", G_CALLBACK(owl_mainwin_redraw), mw);
13  g_signal_connect(window, "resized", G_CALLBACK(owl_mainwin_resized), mw);
14  owl_window_dirty(window);
15
16  /* connect a ton of dependencies */
17  owl_dirty_window_on_signal(window, g.gn, "notify::rightshift");
18}
19
20static 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);
33}
34
35void owl_mainwin_redisplay(owl_mainwin *mw)
36{
37  owl_window_dirty(mw->window);
38}
39
40static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
41{
42  owl_message *m;
43  int i, lines, isfull, viewsize;
44  int x, y, savey, recwinlines, start;
45  int topmsg, curmsg, markedmsgid, fgcolor, bgcolor;
46  const owl_view *v;
47  GList *fl;
48  const owl_filter *f;
49  owl_mainwin *mw = user_data;
50
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);
55  owl_fmtext_reset_colorpairs();
56
57  if (v==NULL) {
58    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
59    return;
60  }
61
62  werase(recwin);
63
64  recwinlines=owl_global_get_recwin_lines(&g);
65  viewsize=owl_view_get_size(v);
66
67  /* if there are no messages or if topmsg is past the end of the messages,
68   * just draw a blank screen */
69  if (viewsize==0 || topmsg>=viewsize) {
70    if (viewsize==0) {
71      owl_global_set_topmsg(&g, 0);
72    }
73    mw->curtruncated=0;
74    mw->lastdisplayed=-1;
75    owl_global_set_needrefresh(&g);
76    return;
77  }
78
79  /* write the messages out */
80  isfull=0;
81  mw->curtruncated=0;
82  mw->lasttruncated=0;
83
84  for (i=topmsg; i<viewsize; i++) {
85    if (isfull) break;
86    m=owl_view_get_element(v, i);
87
88    /* hold on to y in case this is the current message or deleted */
89    getyx(recwin, y, x);
90    savey=y;
91
92    /* if it's the current message, account for a vert_offset */
93    if (i==owl_global_get_curmsg(&g)) {
94      start=owl_global_get_curmsg_vert_offset(&g);
95      lines=owl_message_get_numlines(m)-start;
96    } else {
97      start=0;
98      lines=owl_message_get_numlines(m);
99    }
100
101    /* if we match filters set the color */
102    fgcolor=OWL_COLOR_DEFAULT;
103    bgcolor=OWL_COLOR_DEFAULT;
104    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
105      f = fl->data;
106      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
107          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
108        if (owl_filter_message_match(f, m)) {
109          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
110          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
111        }
112      }
113    }
114
115    /* if we'll fill the screen print a partial message */
116    if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
117    if (y+lines > recwinlines) mw->lasttruncated=1;
118    if (y+lines > recwinlines-1) {
119      isfull=1;
120      owl_message_curs_waddstr(m, recwin,
121                               start,
122                               start+recwinlines-y,
123                               owl_global_get_rightshift(&g),
124                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
125                               fgcolor, bgcolor);
126    } else {
127      /* otherwise print the whole thing */
128      owl_message_curs_waddstr(m, recwin,
129                               start,
130                               start+lines,
131                               owl_global_get_rightshift(&g),
132                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
133                               fgcolor, bgcolor);
134    }
135
136
137    /* is it the current message and/or deleted? */
138    getyx(recwin, y, x);
139    wattrset(recwin, A_NORMAL);
140    if (owl_global_get_rightshift(&g)==0) {   /* this lame and should be fixed */
141      if (m==owl_view_get_element(v, curmsg)) {
142        wmove(recwin, savey, 0);
143        wattron(recwin, A_BOLD);       
144        if (owl_global_get_curmsg_vert_offset(&g)>0) {
145          waddstr(recwin, "+");
146        } else {
147          waddstr(recwin, "-");
148        }
149        if (owl_message_is_delete(m)) {
150          waddstr(recwin, "D");
151        } else if (markedmsgid == owl_message_get_id(m)) {
152          waddstr(recwin, "*");
153        } else {
154          waddstr(recwin, ">");
155        }
156        wmove(recwin, y, x);
157        wattroff(recwin, A_BOLD);
158      } else if (owl_message_is_delete(m)) {
159        wmove(recwin, savey, 0);
160        waddstr(recwin, " D");
161        wmove(recwin, y, x);
162      } else if (markedmsgid == owl_message_get_id(m)) {
163        wmove(recwin, savey, 0);
164        waddstr(recwin, " *");
165        wmove(recwin, y, x);
166      }
167    }
168    wattroff(recwin, A_BOLD);
169  }
170  mw->lastdisplayed=i-1;
171}
172
173
174int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
175{
176  if (mw->curtruncated) return(1);
177  return(0);
178}
179
180int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
181{
182  if (mw->lasttruncated) return(1);
183  return(0);
184}
185
186int owl_mainwin_get_last_msg(const owl_mainwin *mw)
187{
188  /* return the number of the last message displayed. -1 if none */
189  return(mw->lastdisplayed);
190}
Note: See TracBrowser for help on using the repository browser.