source: viewwin.c @ 7d4fbcd

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