source: mainwin.c @ e9b4a2c

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