1 | #include <string.h> |
---|
2 | #include "owl.h" |
---|
3 | |
---|
4 | static const char fileIdent[] = "$Id$"; |
---|
5 | |
---|
6 | #define BOTTOM_OFFSET 1 |
---|
7 | |
---|
8 | void 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 | |
---|
28 | void 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 | |
---|
42 | void 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 | |
---|
48 | void 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 | |
---|
84 | void 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 | |
---|
91 | void 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 | |
---|
98 | void owl_viewwin_pageup(owl_viewwin *v) { |
---|
99 | v->topline-=v->winlines; |
---|
100 | if (v->topline<0) v->topline=0; |
---|
101 | } |
---|
102 | |
---|
103 | void owl_viewwin_lineup(owl_viewwin *v) { |
---|
104 | v->topline--; |
---|
105 | if (v->topline<0) v->topline=0; |
---|
106 | } |
---|
107 | |
---|
108 | void owl_viewwin_right(owl_viewwin *v, int n) { |
---|
109 | v->rightshift+=n; |
---|
110 | } |
---|
111 | |
---|
112 | void owl_viewwin_left(owl_viewwin *v, int n) { |
---|
113 | v->rightshift-=n; |
---|
114 | if (v->rightshift<0) v->rightshift=0; |
---|
115 | } |
---|
116 | |
---|
117 | void owl_viewwin_top(owl_viewwin *v) { |
---|
118 | v->topline=0; |
---|
119 | v->rightshift=0; |
---|
120 | } |
---|
121 | |
---|
122 | void owl_viewwin_bottom(owl_viewwin *v) { |
---|
123 | v->topline = v->textlines - v->winlines + BOTTOM_OFFSET; |
---|
124 | } |
---|
125 | |
---|
126 | void owl_viewwin_free(owl_viewwin *v) { |
---|
127 | owl_fmtext_free(&(v->fmtext)); |
---|
128 | } |
---|