source: mainwin.c @ fa65671

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