source: viewwin.c @ 1aee7d9

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 1aee7d9 was 1aee7d9, checked in by Erik Nygren <nygren@mit.edu>, 18 years ago
* Added RCS Id strings to all files. * 'show keymaps' shows details of all keymaps after summary list.
  • Property mode set to 100644
File size: 3.1 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_truncate_lines(&(v->fmtext), v->topline, v->winlines-BOTTOM_OFFSET, &fm1);
58  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
59
60  owl_fmtext_curs_waddstr(&fm2, v->curswin);
61
62  /* print the message at the bottom */
63  wmove(v->curswin, v->winlines-1, 0);
64  wattrset(v->curswin, A_REVERSE);
65  if (v->textlines - v->topline > v->winlines-BOTTOM_OFFSET - 1) {
66    waddstr(v->curswin, "--More-- (Space to see more, 'q' to quit)");
67  } else {
68    waddstr(v->curswin, "--End-- (Press 'q' to quit)");
69  }
70  wattroff(v->curswin, A_REVERSE);
71  wnoutrefresh(v->curswin);
72
73  if (update==1) {
74    doupdate();
75  }
76}
77
78void owl_viewwin_pagedown(owl_viewwin *v) {
79  v->topline+=v->winlines - BOTTOM_OFFSET;
80  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
81    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
82  }
83}
84
85void owl_viewwin_linedown(owl_viewwin *v) {
86  v->topline++;
87  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
88    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
89  }
90}
91
92void owl_viewwin_pageup(owl_viewwin *v) {
93  v->topline-=v->winlines;
94  if (v->topline<0) v->topline=0;
95}
96
97void owl_viewwin_lineup(owl_viewwin *v) {
98  v->topline--;
99  if (v->topline<0) v->topline=0;
100}
101
102void owl_viewwin_right(owl_viewwin *v, int n) {
103  v->rightshift+=n;
104}
105
106void owl_viewwin_left(owl_viewwin *v, int n) {
107  v->rightshift-=n;
108  if (v->rightshift<0) v->rightshift=0;
109}
110
111void owl_viewwin_top(owl_viewwin *v) {
112  v->topline=0;
113  v->rightshift=0;
114}
115
116void owl_viewwin_bottom(owl_viewwin *v) {
117  v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
118}
119
120void owl_viewwin_free(owl_viewwin *v) {
121  owl_fmtext_free(&(v->fmtext));
122}
Note: See TracBrowser for help on using the repository browser.