source: mainwin.c @ 40d1eef

release-1.10release-1.7release-1.8release-1.9
Last change on this file since 40d1eef was 40d1eef, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
And a hacky port of the mainwin too Some of the old relayout code should still be reorganized, but it's a start.
  • Property mode set to 100644
File size: 4.5 KB
RevLine 
[7d4fbcd]1#include "owl.h"
2
[40d1eef]3static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data);
4
5void owl_mainwin_init(owl_mainwin *mw, owl_window *window)
[37eab7f]6{
[7d4fbcd]7  mw->curtruncated=0;
8  mw->lastdisplayed=-1;
[40d1eef]9  mw->window = g_object_ref(window);
10  g_signal_connect(window, "redraw", G_CALLBACK(owl_mainwin_redraw), mw);
[7d4fbcd]11}
12
[37eab7f]13void owl_mainwin_redisplay(owl_mainwin *mw)
14{
[40d1eef]15  owl_window_dirty(mw->window);
16}
17
18static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
19{
[7d4fbcd]20  owl_message *m;
[129e609]21  int i, lines, isfull, viewsize;
[7d4fbcd]22  int x, y, savey, recwinlines, start;
[f63a681]23  int topmsg, curmsg, markedmsgid, fgcolor, bgcolor;
[9e5c9f3]24  const owl_view *v;
[129e609]25  GList *fl;
[4542047]26  const owl_filter *f;
[40d1eef]27  owl_mainwin *mw = user_data;
[7d4fbcd]28
[f63a681]29  topmsg = owl_global_get_topmsg(&g);
30  curmsg = owl_global_get_curmsg(&g);
31  markedmsgid = owl_global_get_markedmsgid(&g);
32  v = owl_global_get_current_view(&g);
[8fa9562]33  owl_fmtext_reset_colorpairs();
[7d4fbcd]34
[f2f9314]35  if (v==NULL) {
36    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
37    return;
38  }
39
[7d4fbcd]40  werase(recwin);
41
42  recwinlines=owl_global_get_recwin_lines(&g);
[5eeea3b]43  viewsize=owl_view_get_size(v);
[7d4fbcd]44
[5eeea3b]45  /* if there are no messages or if topmsg is past the end of the messages,
46   * just draw a blank screen */
47  if (viewsize==0 || topmsg>=viewsize) {
48    if (viewsize==0) {
49      owl_global_set_topmsg(&g, 0);
50    }
[7d4fbcd]51    mw->curtruncated=0;
52    mw->lastdisplayed=-1;
53    owl_global_set_needrefresh(&g);
54    return;
55  }
56
57  /* write the messages out */
58  isfull=0;
59  mw->curtruncated=0;
[f2e36b5]60  mw->lasttruncated=0;
[5eeea3b]61
62  for (i=topmsg; i<viewsize; i++) {
[7d4fbcd]63    if (isfull) break;
64    m=owl_view_get_element(v, i);
65
66    /* hold on to y in case this is the current message or deleted */
67    getyx(recwin, y, x);
68    savey=y;
69
70    /* if it's the current message, account for a vert_offset */
71    if (i==owl_global_get_curmsg(&g)) {
72      start=owl_global_get_curmsg_vert_offset(&g);
73      lines=owl_message_get_numlines(m)-start;
74    } else {
75      start=0;
76      lines=owl_message_get_numlines(m);
77    }
78
79    /* if we match filters set the color */
[8fa9562]80    fgcolor=OWL_COLOR_DEFAULT;
81    bgcolor=OWL_COLOR_DEFAULT;
[129e609]82    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
83      f = fl->data;
[c2c5c77]84      if ((owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) ||
85          (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT)) {
86        if (owl_filter_message_match(f, m)) {
87          if (owl_filter_get_fgcolor(f)!=OWL_COLOR_DEFAULT) fgcolor=owl_filter_get_fgcolor(f);
88          if (owl_filter_get_bgcolor(f)!=OWL_COLOR_DEFAULT) bgcolor=owl_filter_get_bgcolor(f);
89        }
[7d4fbcd]90      }
91    }
92
93    /* if we'll fill the screen print a partial message */
94    if ((y+lines > recwinlines) && (i==owl_global_get_curmsg(&g))) mw->curtruncated=1;
[f2e36b5]95    if (y+lines > recwinlines) mw->lasttruncated=1;
[7d4fbcd]96    if (y+lines > recwinlines-1) {
97      isfull=1;
[40d1eef]98      owl_message_curs_waddstr(m, recwin,
[7d4fbcd]99                               start,
100                               start+recwinlines-y,
101                               owl_global_get_rightshift(&g),
102                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
[8fa9562]103                               fgcolor, bgcolor);
[7d4fbcd]104    } else {
105      /* otherwise print the whole thing */
[40d1eef]106      owl_message_curs_waddstr(m, recwin,
[7d4fbcd]107                               start,
108                               start+lines,
109                               owl_global_get_rightshift(&g),
110                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
[8fa9562]111                               fgcolor, bgcolor);
[7d4fbcd]112    }
113
114
115    /* is it the current message and/or deleted? */
116    getyx(recwin, y, x);
117    wattrset(recwin, A_NORMAL);
118    if (owl_global_get_rightshift(&g)==0) {   /* this lame and should be fixed */
119      if (m==owl_view_get_element(v, curmsg)) {
120        wmove(recwin, savey, 0);
121        wattron(recwin, A_BOLD);       
122        if (owl_global_get_curmsg_vert_offset(&g)>0) {
123          waddstr(recwin, "+");
124        } else {
125          waddstr(recwin, "-");
126        }
[f63a681]127        if (owl_message_is_delete(m)) {
[7d4fbcd]128          waddstr(recwin, "D");
[f63a681]129        } else if (markedmsgid == owl_message_get_id(m)) {
130          waddstr(recwin, "*");
131        } else {
132          waddstr(recwin, ">");
[7d4fbcd]133        }
134        wmove(recwin, y, x);
135        wattroff(recwin, A_BOLD);
136      } else if (owl_message_is_delete(m)) {
137        wmove(recwin, savey, 0);
138        waddstr(recwin, " D");
139        wmove(recwin, y, x);
[f63a681]140      } else if (markedmsgid == owl_message_get_id(m)) {
141        wmove(recwin, savey, 0);
142        waddstr(recwin, " *");
143        wmove(recwin, y, x);
[7d4fbcd]144      }
145    }
146    wattroff(recwin, A_BOLD);
147  }
148  mw->lastdisplayed=i-1;
149}
150
151
[eaa9053]152int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
[37eab7f]153{
[7d4fbcd]154  if (mw->curtruncated) return(1);
155  return(0);
156}
157
[eaa9053]158int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
[37eab7f]159{
[f2e36b5]160  if (mw->lasttruncated) return(1);
161  return(0);
162}
163
[eaa9053]164int owl_mainwin_get_last_msg(const owl_mainwin *mw)
[37eab7f]165{
[7d4fbcd]166  /* return the number of the last message displayed. -1 if none */
167  return(mw->lastdisplayed);
168}
Note: See TracBrowser for help on using the repository browser.