source: mainwin.c @ bf21c4e

release-1.10
Last change on this file since bf21c4e was 7dcef03, checked in by Anders Kaseorg <andersk@mit.edu>, 11 years ago
Use the Glib slice allocator for fixed-size objects The slice allocator, available since GLib 2.10, is more space-efficient than [g_]malloc. Since BarnOwl is obviously at the leading edge of space-efficient technology, this seems like a natural fit. Use it for every fixed-size object except owl_viewwin_search_data (which would need an extra destroy_cbdata function to g_slice_free it). Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • 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
[ab88b05]6CALLER_OWN owl_mainwin *owl_mainwin_new(owl_window *window)
[37eab7f]7{
[7dcef03]8  owl_mainwin *mw = g_slice_new(owl_mainwin);
[7d4fbcd]9  mw->curtruncated=0;
10  mw->lastdisplayed=-1;
[40d1eef]11  mw->window = g_object_ref(window);
[fa65671]12  /* for now, just assume this object lasts forever */
[40d1eef]13  g_signal_connect(window, "redraw", G_CALLBACK(owl_mainwin_redraw), mw);
[fa65671]14  g_signal_connect(window, "resized", G_CALLBACK(owl_mainwin_resized), mw);
[521e600]15  owl_window_dirty(window);
[9bd51b8]16
[e92e2a1]17  /* For now, we do not bother with connecting up dependencies; that'll be a
18   * future refactor of the mainwin */
[ab88b05]19
20  return mw;
[fa65671]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);
[7d4fbcd]36}
37
[37eab7f]38void owl_mainwin_redisplay(owl_mainwin *mw)
39{
[40d1eef]40  owl_window_dirty(mw->window);
41}
42
43static void owl_mainwin_redraw(owl_window *w, WINDOW *recwin, void *user_data)
44{
[7d4fbcd]45  owl_message *m;
[129e609]46  int i, lines, isfull, viewsize;
[7d4fbcd]47  int x, y, savey, recwinlines, start;
[f63a681]48  int topmsg, curmsg, markedmsgid, fgcolor, bgcolor;
[9e5c9f3]49  const owl_view *v;
[129e609]50  GList *fl;
[4542047]51  const owl_filter *f;
[40d1eef]52  owl_mainwin *mw = user_data;
[7d4fbcd]53
[f63a681]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);
[7d4fbcd]58
[f2f9314]59  if (v==NULL) {
60    owl_function_debugmsg("Hit a null window in owl_mainwin_redisplay.");
61    return;
62  }
63
[7d4fbcd]64  werase(recwin);
65
66  recwinlines=owl_global_get_recwin_lines(&g);
[5eeea3b]67  viewsize=owl_view_get_size(v);
[7d4fbcd]68
[5eeea3b]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    }
[7d4fbcd]75    mw->curtruncated=0;
76    mw->lastdisplayed=-1;
77    return;
78  }
79
80  /* write the messages out */
81  isfull=0;
82  mw->curtruncated=0;
[f2e36b5]83  mw->lasttruncated=0;
[5eeea3b]84
85  for (i=topmsg; i<viewsize; i++) {
[7d4fbcd]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 */
[8fa9562]103    fgcolor=OWL_COLOR_DEFAULT;
104    bgcolor=OWL_COLOR_DEFAULT;
[129e609]105    for (fl = g.filterlist; fl; fl = g_list_next(fl)) {
106      f = fl->data;
[c2c5c77]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        }
[7d4fbcd]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;
[f2e36b5]118    if (y+lines > recwinlines) mw->lasttruncated=1;
[7d4fbcd]119    if (y+lines > recwinlines-1) {
120      isfull=1;
[40d1eef]121      owl_message_curs_waddstr(m, recwin,
[7d4fbcd]122                               start,
123                               start+recwinlines-y,
124                               owl_global_get_rightshift(&g),
125                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
[8fa9562]126                               fgcolor, bgcolor);
[7d4fbcd]127    } else {
128      /* otherwise print the whole thing */
[40d1eef]129      owl_message_curs_waddstr(m, recwin,
[7d4fbcd]130                               start,
131                               start+lines,
132                               owl_global_get_rightshift(&g),
133                               owl_global_get_cols(&g)+owl_global_get_rightshift(&g)-1,
[8fa9562]134                               fgcolor, bgcolor);
[7d4fbcd]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        }
[f63a681]150        if (owl_message_is_delete(m)) {
[7d4fbcd]151          waddstr(recwin, "D");
[f63a681]152        } else if (markedmsgid == owl_message_get_id(m)) {
153          waddstr(recwin, "*");
154        } else {
155          waddstr(recwin, ">");
[7d4fbcd]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);
[f63a681]163      } else if (markedmsgid == owl_message_get_id(m)) {
164        wmove(recwin, savey, 0);
165        waddstr(recwin, " *");
166        wmove(recwin, y, x);
[7d4fbcd]167      }
168    }
169    wattroff(recwin, A_BOLD);
170  }
171  mw->lastdisplayed=i-1;
172}
173
174
[eaa9053]175int owl_mainwin_is_curmsg_truncated(const owl_mainwin *mw)
[37eab7f]176{
[7d4fbcd]177  if (mw->curtruncated) return(1);
178  return(0);
179}
180
[eaa9053]181int owl_mainwin_is_last_msg_truncated(const owl_mainwin *mw)
[37eab7f]182{
[f2e36b5]183  if (mw->lasttruncated) return(1);
184  return(0);
185}
186
[eaa9053]187int owl_mainwin_get_last_msg(const owl_mainwin *mw)
[37eab7f]188{
[7d4fbcd]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.