source: mainwin.c @ afaef6e

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