source: viewwin.c @ 7c8060d0

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7c8060d0 was 3a2daac, checked in by James M. Kretchmar <kretch@mit.edu>, 22 years ago
viewwin will now say "End" instead of "More" when at the end Added a debugging message indicating the result of topmsg calculations
  • 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
8void owl_viewwin_init_text(owl_viewwin *v, WINDOW *win, int winlines, int wincols, char *text) {
9  /* initialize the viewwin e.
10   * 'win' is an already initialzed curses window that will be used by viewwin
11   */
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
28void owl_viewwin_init_fmtext(owl_viewwin *v, WINDOW *win, int winlines, int wincols, owl_fmtext *fmtext) {
29  /* initialize the viewwin e.
30   * 'win' is an already initialzed curses window that will be used by viewwin
31   */
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  v->curswin=w;
44  v->winlines=winlines;
45  v->wincols=wincols;
46}
47
48void owl_viewwin_redisplay(owl_viewwin *v, int update) {
49  /* regenerate text on the curses window. */
50  /* if update == 1 then do a doupdate() */
51
52  owl_fmtext fm1, fm2;
53 
54  werase(v->curswin);
55  wmove(v->curswin, 0, 0);
56
57  owl_fmtext_init_null(&fm1);
58  owl_fmtext_init_null(&fm2);
59 
60  owl_fmtext_truncate_lines(&(v->fmtext), v->topline, v->winlines-BOTTOM_OFFSET, &fm1);
61  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
62
63  owl_fmtext_curs_waddstr(&fm2, v->curswin);
64
65  /* print the message at the bottom */
66  wmove(v->curswin, v->winlines-1, 0);
67  wattrset(v->curswin, A_REVERSE);
68  if (v->textlines - v->topline > v->winlines-BOTTOM_OFFSET) {
69    waddstr(v->curswin, "--More-- (Space to see more, 'q' to quit)");
70  } else {
71    waddstr(v->curswin, "--End-- (Press 'q' to quit)");
72  }
73  wattroff(v->curswin, A_REVERSE);
74  wnoutrefresh(v->curswin);
75
76  if (update==1) {
77    doupdate();
78  }
79
80  owl_fmtext_free(&fm1);
81  owl_fmtext_free(&fm2);
82}
83
84void owl_viewwin_pagedown(owl_viewwin *v) {
85  v->topline+=v->winlines - BOTTOM_OFFSET;
86  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
87    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
88  }
89}
90
91void owl_viewwin_linedown(owl_viewwin *v) {
92  v->topline++;
93  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
94    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
95  }
96}
97
98void owl_viewwin_pageup(owl_viewwin *v) {
99  v->topline-=v->winlines;
100  if (v->topline<0) v->topline=0;
101}
102
103void owl_viewwin_lineup(owl_viewwin *v) {
104  v->topline--;
105  if (v->topline<0) v->topline=0;
106}
107
108void owl_viewwin_right(owl_viewwin *v, int n) {
109  v->rightshift+=n;
110}
111
112void owl_viewwin_left(owl_viewwin *v, int n) {
113  v->rightshift-=n;
114  if (v->rightshift<0) v->rightshift=0;
115}
116
117void owl_viewwin_top(owl_viewwin *v) {
118  v->topline=0;
119  v->rightshift=0;
120}
121
122void owl_viewwin_bottom(owl_viewwin *v) {
123  v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
124}
125
126void owl_viewwin_free(owl_viewwin *v) {
127  owl_fmtext_free(&(v->fmtext));
128}
Note: See TracBrowser for help on using the repository browser.