source: mainwin.c @ bf7aa1d

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