source: viewwin.c @ 27c3a93

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 27c3a93 was b2b0773, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Changes to help build on OSX
  • Property mode set to 100644
File size: 3.2 KB
Line 
1#include <string.h>
2#include "owl.h"
3
4static const char fileIdent[] = "$Id$";
5
6#define BOTTOM_OFFSET 1
7
8/* initialize the viewwin e.  'win' is an already initialzed curses
9 * window that will be used by viewwin
10 */
11void owl_viewwin_init_text(owl_viewwin *v, WINDOW *win, int winlines, int wincols, char *text)
12{
13  owl_fmtext_init_null(&(v->fmtext));
14  if (text) {
15    owl_fmtext_append_normal(&(v->fmtext), text);
16    if (text[strlen(text)-1]!='\n') {
17      owl_fmtext_append_normal(&(v->fmtext), "\n");
18    }
19    v->textlines=owl_fmtext_num_lines(&(v->fmtext));
20  }
21  v->topline=0;
22  v->rightshift=0;
23  v->winlines=winlines;
24  v->wincols=wincols;
25  v->curswin=win;
26}
27
28/* initialize the viewwin e.  'win' is an already initialzed curses
29 * window that will be used by viewwin
30 */
31void owl_viewwin_init_fmtext(owl_viewwin *v, WINDOW *win, int winlines, int wincols, owl_fmtext *fmtext)
32{
33  owl_fmtext_copy(&(v->fmtext), fmtext);
34  v->textlines=owl_fmtext_num_lines(&(v->fmtext));
35  v->topline=0;
36  v->rightshift=0;
37  v->winlines=winlines;
38  v->wincols=wincols;
39  v->curswin=win;
40}
41
42void owl_viewwin_set_curswin(owl_viewwin *v, WINDOW *w, int winlines, int wincols)
43{
44  v->curswin=w;
45  v->winlines=winlines;
46  v->wincols=wincols;
47}
48
49/* regenerate text on the curses window. */
50/* if update == 1 then do a doupdate() */
51void owl_viewwin_redisplay(owl_viewwin *v, int update)
52{
53  owl_fmtext fm1, fm2;
54 
55  werase(v->curswin);
56  wmove(v->curswin, 0, 0);
57
58  owl_fmtext_init_null(&fm1);
59  owl_fmtext_init_null(&fm2);
60 
61  owl_fmtext_truncate_lines(&(v->fmtext), v->topline, v->winlines-BOTTOM_OFFSET, &fm1);
62  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
63
64  owl_fmtext_curs_waddstr(&fm2, v->curswin);
65
66  /* print the message at the bottom */
67  wmove(v->curswin, v->winlines-1, 0);
68  wattrset(v->curswin, A_REVERSE);
69  if (v->textlines - v->topline > v->winlines-BOTTOM_OFFSET) {
70    waddstr(v->curswin, "--More-- (Space to see more, 'q' to quit)");
71  } else {
72    waddstr(v->curswin, "--End-- (Press 'q' to quit)");
73  }
74  wattroff(v->curswin, A_REVERSE);
75  wnoutrefresh(v->curswin);
76
77  if (update==1) {
78    doupdate();
79  }
80
81  owl_fmtext_free(&fm1);
82  owl_fmtext_free(&fm2);
83}
84
85void owl_viewwin_pagedown(owl_viewwin *v)
86{
87  v->topline+=v->winlines - BOTTOM_OFFSET;
88  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
89    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
90  }
91}
92
93void owl_viewwin_linedown(owl_viewwin *v)
94{
95  v->topline++;
96  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
97    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
98  }
99}
100
101void owl_viewwin_pageup(owl_viewwin *v)
102{
103  v->topline-=v->winlines;
104  if (v->topline<0) v->topline=0;
105}
106
107void owl_viewwin_lineup(owl_viewwin *v)
108{
109  v->topline--;
110  if (v->topline<0) v->topline=0;
111}
112
113void owl_viewwin_right(owl_viewwin *v, int n)
114{
115  v->rightshift+=n;
116}
117
118void owl_viewwin_left(owl_viewwin *v, int n)
119{
120  v->rightshift-=n;
121  if (v->rightshift<0) v->rightshift=0;
122}
123
124void owl_viewwin_top(owl_viewwin *v)
125{
126  v->topline=0;
127  v->rightshift=0;
128}
129
130void owl_viewwin_bottom(owl_viewwin *v)
131{
132  v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
133}
134
135void owl_viewwin_free(owl_viewwin *v)
136{
137  owl_fmtext_free(&(v->fmtext));
138}
Note: See TracBrowser for help on using the repository browser.