source: viewwin.c @ 2febcae

barnowl_perlaimdebianrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 2febcae was 9866c3a, checked in by Alejandro R. Sedeño <asedeno@mit.edu>, 13 years ago
Reworked the fmtext format to use in-line formatting. Characters used for formatting are part of Unicode Supplemental Private Area-B, or Plane 16. fmtext no longer need 5x the text space to store formatting information, though they are harder to change at arbitrary points. This was something we hardly ever did anyhow, and we can still do everything we need to do. fmtext keeps a pair of colors and a char for default attributes to be applied when necessary. Searching is now done inline at owl_fmtext_waddstr() rather than specifying a section of the string to be reversed. This probably still needs some cleanup and more comments, but it works.
  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[7d4fbcd]1#include <string.h>
2#include "owl.h"
3
[1aee7d9]4static 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 */
11void 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);
[afbf668]16    if (text[strlen(text)-1]!='\n' && text[0]!='\0') {
[7d4fbcd]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;
[afbf668]26  v->onclose_hook = NULL;
27}
28
29void owl_viewwin_append_text(owl_viewwin *v, char *text) {
30    owl_fmtext_append_normal(&(v->fmtext), text);
31    v->textlines=owl_fmtext_num_lines(&(v->fmtext)); 
[7d4fbcd]32}
33
[b2b0773]34/* initialize the viewwin e.  'win' is an already initialzed curses
35 * window that will be used by viewwin
36 */
37void owl_viewwin_init_fmtext(owl_viewwin *v, WINDOW *win, int winlines, int wincols, owl_fmtext *fmtext)
38{
[7d4fbcd]39  owl_fmtext_copy(&(v->fmtext), fmtext);
40  v->textlines=owl_fmtext_num_lines(&(v->fmtext));
41  v->topline=0;
42  v->rightshift=0;
43  v->winlines=winlines;
44  v->wincols=wincols;
45  v->curswin=win;
46}
47
[b2b0773]48void owl_viewwin_set_curswin(owl_viewwin *v, WINDOW *w, int winlines, int wincols)
49{
[7d4fbcd]50  v->curswin=w;
51  v->winlines=winlines;
52  v->wincols=wincols;
53}
54
[afbf668]55void owl_viewwin_set_onclose_hook(owl_viewwin *v, void (*onclose_hook) (owl_viewwin *vwin, void *data), void *onclose_hook_data) {
56  v->onclose_hook = onclose_hook;
57  v->onclose_hook_data = onclose_hook_data;
58}
59
[b2b0773]60/* regenerate text on the curses window. */
61/* if update == 1 then do a doupdate() */
62void owl_viewwin_redisplay(owl_viewwin *v, int update)
63{
[7d4fbcd]64  owl_fmtext fm1, fm2;
65 
66  werase(v->curswin);
67  wmove(v->curswin, 0, 0);
68
[af2ca19]69  owl_fmtext_init_null(&fm1);
70  owl_fmtext_init_null(&fm2);
71 
[7d4fbcd]72  owl_fmtext_truncate_lines(&(v->fmtext), v->topline, v->winlines-BOTTOM_OFFSET, &fm1);
73  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
74
[9866c3a]75  owl_fmtext_curs_waddstr(&fm2, v->curswin, 0);
[7d4fbcd]76
77  /* print the message at the bottom */
78  wmove(v->curswin, v->winlines-1, 0);
79  wattrset(v->curswin, A_REVERSE);
[3a2daac]80  if (v->textlines - v->topline > v->winlines-BOTTOM_OFFSET) {
[7d4fbcd]81    waddstr(v->curswin, "--More-- (Space to see more, 'q' to quit)");
82  } else {
83    waddstr(v->curswin, "--End-- (Press 'q' to quit)");
84  }
85  wattroff(v->curswin, A_REVERSE);
86  wnoutrefresh(v->curswin);
87
88  if (update==1) {
89    doupdate();
90  }
[af2ca19]91
92  owl_fmtext_free(&fm1);
93  owl_fmtext_free(&fm2);
[7d4fbcd]94}
95
[b2b0773]96void owl_viewwin_pagedown(owl_viewwin *v)
97{
[7d4fbcd]98  v->topline+=v->winlines - BOTTOM_OFFSET;
99  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
100    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
101  }
102}
103
[b2b0773]104void owl_viewwin_linedown(owl_viewwin *v)
105{
[7d4fbcd]106  v->topline++;
107  if ( (v->topline+v->winlines-BOTTOM_OFFSET) > v->textlines) {
108    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
109  }
110}
111
[b2b0773]112void owl_viewwin_pageup(owl_viewwin *v)
113{
[7d4fbcd]114  v->topline-=v->winlines;
115  if (v->topline<0) v->topline=0;
116}
117
[b2b0773]118void owl_viewwin_lineup(owl_viewwin *v)
119{
[7d4fbcd]120  v->topline--;
121  if (v->topline<0) v->topline=0;
122}
123
[b2b0773]124void owl_viewwin_right(owl_viewwin *v, int n)
125{
[7d4fbcd]126  v->rightshift+=n;
127}
128
[b2b0773]129void owl_viewwin_left(owl_viewwin *v, int n)
130{
[7d4fbcd]131  v->rightshift-=n;
132  if (v->rightshift<0) v->rightshift=0;
133}
134
[b2b0773]135void owl_viewwin_top(owl_viewwin *v)
136{
[7d4fbcd]137  v->topline=0;
138  v->rightshift=0;
139}
140
[b2b0773]141void owl_viewwin_bottom(owl_viewwin *v)
142{
[7d4fbcd]143  v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
144}
145
[b2b0773]146void owl_viewwin_free(owl_viewwin *v)
147{
[afbf668]148  if (v->onclose_hook) {
149    v->onclose_hook(v, v->onclose_hook_data);
[8721756]150    v->onclose_hook = NULL;
151    v->onclose_hook_data = NULL;
[afbf668]152  }
[7d4fbcd]153  owl_fmtext_free(&(v->fmtext));
154}
Note: See TracBrowser for help on using the repository browser.