source: mainwin.c @ ea7daa8

release-1.10release-1.7release-1.8release-1.9
Last change on this file since ea7daa8 was e92e2a1, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Don't use a signal to connect rightshift While the signal is cleaner, rightshift should likely be a private property of owl_mainwin anyway. (Or at least a property of owl_view.) This is with the goal of removing the dependence on globalnotifier for the first iteration.
  • Property mode set to 100644
File size: 5.3 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    owl_global_set_needrefresh(&g);
76    return;
77  }
78
79  /* write the messages out */
80  isfull=0;
81  mw->curtruncated=0;
[f2e36b5]82  mw->lasttruncated=0;
[5eeea3b]83
84  for (i=topmsg; i<viewsize; i++) {
[7d4fbcd]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 */
[8fa9562]102    fgcolor=OWL_COLOR_DEFAULT;
103    bgcolor=OWL_COLOR_DEFAULT;
[129e609]104    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
105      f = fl->data;
[c2c5c77]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        }
[7d4fbcd]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;
[f2e36b5]117    if (y+lines > recwinlines) mw->lasttruncated=1;
[7d4fbcd]118    if (y+lines > recwinlines-1) {
119      isfull=1;
[40d1eef]120      owl_message_curs_waddstr(m, recwin,
[7d4fbcd]121                               start,
122                               start+recwinlines-y,
123                               owl_global_get_rightshift(&g),
124                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
[8fa9562]125                               fgcolor, bgcolor);
[7d4fbcd]126    } else {
127      /* otherwise print the whole thing */
[40d1eef]128      owl_message_curs_waddstr(m, recwin,
[7d4fbcd]129                               start,
130                               start+lines,
131                               owl_global_get_rightshift(&g),
132                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
[8fa9562]133                               fgcolor, bgcolor);
[7d4fbcd]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        }
[f63a681]149        if (owl_message_is_delete(m)) {
[7d4fbcd]150          waddstr(recwin, "D");
[f63a681]151        } else if (markedmsgid == owl_message_get_id(m)) {
152          waddstr(recwin, "*");
153        } else {
154          waddstr(recwin, ">");
[7d4fbcd]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);
[f63a681]162      } else if (markedmsgid == owl_message_get_id(m)) {
163        wmove(recwin, savey, 0);
164        waddstr(recwin, " *");
165        wmove(recwin, y, x);
[7d4fbcd]166      }
167    }
168    wattroff(recwin, A_BOLD);
169  }
170  mw->lastdisplayed=i-1;
171}
172
173
[eaa9053]174int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
[37eab7f]175{
[7d4fbcd]176  if (mw->curtruncated) return(1);
177  return(0);
178}
179
[eaa9053]180int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
[37eab7f]181{
[f2e36b5]182  if (mw->lasttruncated) return(1);
183  return(0);
184}
185
[eaa9053]186int owl_mainwin_get_last_msg(const owl_mainwin *mw)
[37eab7f]187{
[7d4fbcd]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.