[7d4fbcd] | 1 | #include <string.h> |
---|
| 2 | #include "owl.h" |
---|
| 3 | |
---|
[1aee7d9] | 4 | static const char fileIdent[] = "$Id$"; |
---|
| 5 | |
---|
[7d4fbcd] | 6 | #define BOTTOM_OFFSET 1 |
---|
| 7 | |
---|
[b2b0773] | 8 | /* initialize the viewwin e. 'win' is an already initialzed curses |
---|
| 9 | * window that will be used by viewwin |
---|
| 10 | */ |
---|
| 11 | void owl_viewwin_init_text(owl_viewwin *v, WINDOW *win, int winlines, int wincols, char *text) |
---|
| 12 | { |
---|
[7d4fbcd] | 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 | |
---|
[b2b0773] | 28 | /* initialize the viewwin e. 'win' is an already initialzed curses |
---|
| 29 | * window that will be used by viewwin |
---|
| 30 | */ |
---|
| 31 | void owl_viewwin_init_fmtext(owl_viewwin *v, WINDOW *win, int winlines, int wincols, owl_fmtext *fmtext) |
---|
| 32 | { |
---|
[7d4fbcd] | 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 | |
---|
[b2b0773] | 42 | void owl_viewwin_set_curswin(owl_viewwin *v, WINDOW *w, int winlines, int wincols) |
---|
| 43 | { |
---|
[7d4fbcd] | 44 | v->curswin=w; |
---|
| 45 | v->winlines=winlines; |
---|
| 46 | v->wincols=wincols; |
---|
| 47 | } |
---|
| 48 | |
---|
[b2b0773] | 49 | /* regenerate text on the curses window. */ |
---|
| 50 | /* if update == 1 then do a doupdate() */ |
---|
| 51 | void owl_viewwin_redisplay(owl_viewwin *v, int update) |
---|
| 52 | { |
---|
[7d4fbcd] | 53 | owl_fmtext fm1, fm2; |
---|
| 54 | |
---|
| 55 | werase(v->curswin); |
---|
| 56 | wmove(v->curswin, 0, 0); |
---|
| 57 | |
---|
[af2ca19] | 58 | owl_fmtext_init_null(&fm1); |
---|
| 59 | owl_fmtext_init_null(&fm2); |
---|
| 60 | |
---|
[7d4fbcd] | 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); |
---|
[3a2daac] | 69 | if (v->textlines - v->topline > v->winlines-BOTTOM_OFFSET) { |
---|
[7d4fbcd] | 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 | } |
---|
[af2ca19] | 80 | |
---|
| 81 | owl_fmtext_free(&fm1); |
---|
| 82 | owl_fmtext_free(&fm2); |
---|
[7d4fbcd] | 83 | } |
---|
| 84 | |
---|
[b2b0773] | 85 | void owl_viewwin_pagedown(owl_viewwin *v) |
---|
| 86 | { |
---|
[7d4fbcd] | 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 | |
---|
[b2b0773] | 93 | void owl_viewwin_linedown(owl_viewwin *v) |
---|
| 94 | { |
---|
[7d4fbcd] | 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 | |
---|
[b2b0773] | 101 | void owl_viewwin_pageup(owl_viewwin *v) |
---|
| 102 | { |
---|
[7d4fbcd] | 103 | v->topline-=v->winlines; |
---|
| 104 | if (v->topline<0) v->topline=0; |
---|
| 105 | } |
---|
| 106 | |
---|
[b2b0773] | 107 | void owl_viewwin_lineup(owl_viewwin *v) |
---|
| 108 | { |
---|
[7d4fbcd] | 109 | v->topline--; |
---|
| 110 | if (v->topline<0) v->topline=0; |
---|
| 111 | } |
---|
| 112 | |
---|
[b2b0773] | 113 | void owl_viewwin_right(owl_viewwin *v, int n) |
---|
| 114 | { |
---|
[7d4fbcd] | 115 | v->rightshift+=n; |
---|
| 116 | } |
---|
| 117 | |
---|
[b2b0773] | 118 | void owl_viewwin_left(owl_viewwin *v, int n) |
---|
| 119 | { |
---|
[7d4fbcd] | 120 | v->rightshift-=n; |
---|
| 121 | if (v->rightshift<0) v->rightshift=0; |
---|
| 122 | } |
---|
| 123 | |
---|
[b2b0773] | 124 | void owl_viewwin_top(owl_viewwin *v) |
---|
| 125 | { |
---|
[7d4fbcd] | 126 | v->topline=0; |
---|
| 127 | v->rightshift=0; |
---|
| 128 | } |
---|
| 129 | |
---|
[b2b0773] | 130 | void owl_viewwin_bottom(owl_viewwin *v) |
---|
| 131 | { |
---|
[7d4fbcd] | 132 | v->topline = v->textlines - v->winlines + BOTTOM_OFFSET; |
---|
| 133 | } |
---|
| 134 | |
---|
[b2b0773] | 135 | void owl_viewwin_free(owl_viewwin *v) |
---|
| 136 | { |
---|
[7d4fbcd] | 137 | owl_fmtext_free(&(v->fmtext)); |
---|
| 138 | } |
---|