Changeset 68f63a2 for viewwin.c


Ignore:
Timestamp:
May 29, 2010, 1:14:57 PM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
1383b58
Parents:
7c8811c
git-author:
David Benjamin <davidben@mit.edu> (05/27/10 02:49:57)
git-committer:
David Benjamin <davidben@mit.edu> (05/29/10 13:14:57)
Message:
Port owl_viewwin to owl_window

A number of hacks. This is just a test run of the API.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • viewwin.c

    rfe4c786 r68f63a2  
    77 * window that will be used by viewwin
    88 */
    9 void owl_viewwin_init_text(owl_viewwin *v, WINDOW *win, int winlines, int wincols, const char *text)
     9void owl_viewwin_init_text(owl_viewwin *v, owl_window *win, const char *text)
    1010{
    1111  owl_fmtext_init_null(&(v->fmtext));
     
    1919  v->topline=0;
    2020  v->rightshift=0;
    21   v->winlines=winlines;
    22   v->wincols=wincols;
    23   v->curswin=win;
    2421  v->onclose_hook = NULL;
     22
     23  owl_viewwin_set_window(v, win);
    2524}
    2625
     
    2827    owl_fmtext_append_normal(&(v->fmtext), text);
    2928    v->textlines=owl_fmtext_num_lines(&(v->fmtext)); 
     29    owl_window_dirty(v->window);
    3030}
    3131
     
    3333 * window that will be used by viewwin
    3434 */
    35 void owl_viewwin_init_fmtext(owl_viewwin *v, WINDOW *win, int winlines, int wincols, const owl_fmtext *fmtext)
     35void owl_viewwin_init_fmtext(owl_viewwin *v, owl_window *win, const owl_fmtext *fmtext)
    3636{
    3737  char *text;
     
    4646  v->topline=0;
    4747  v->rightshift=0;
    48   v->winlines=winlines;
    49   v->wincols=wincols;
    50   v->curswin=win;
     48
     49  owl_viewwin_set_window(v, win);
    5150}
    5251
    53 void owl_viewwin_set_curswin(owl_viewwin *v, WINDOW *w, int winlines, int wincols)
     52void owl_viewwin_set_window(owl_viewwin *v, owl_window *w)
    5453{
    55   v->curswin=w;
    56   v->winlines=winlines;
    57   v->wincols=wincols;
     54  if (v->window) {
     55    owl_window_set_redraw_cb(v->window, 0, 0, 0);
     56    owl_window_set_resize_cb(v->window, 0, 0, 0);
     57  }
     58  v->window = w;
     59  if (w) {
     60    owl_window_get_position(w, &v->winlines, &v->wincols, 0, 0);
     61    owl_window_set_redraw_cb(w, owl_viewwin_redisplay, v, 0);
     62    owl_window_set_resize_cb(w, owl_viewwin_resize_hook, v, 0);
     63  }
    5864}
    5965
     
    6369}
    6470
     71void owl_viewwin_resize_hook(owl_window *w, void *user_data)
     72{
     73  owl_viewwin *v = user_data;
     74  owl_window_get_position(w, &v->winlines, &v->wincols, 0, 0);
     75}
     76
    6577/* regenerate text on the curses window. */
    66 void owl_viewwin_redisplay(owl_viewwin *v)
     78void owl_viewwin_redisplay(owl_window *w, WINDOW *curswin, void *user_data)
    6779{
    6880  owl_fmtext fm1, fm2;
    69 
    70   /* avoid segfault when screen too small to create curswin */
    71   if (v->curswin == NULL)
    72     return;
     81  owl_viewwin *v = user_data;
    7382 
    74   werase(v->curswin);
    75   wmove(v->curswin, 0, 0);
     83  werase(curswin);
     84  wmove(curswin, 0, 0);
    7685
    7786  owl_fmtext_init_null(&fm1);
     
    8190  owl_fmtext_truncate_cols(&fm1, v->rightshift, v->wincols-1+v->rightshift, &fm2);
    8291
    83   owl_fmtext_curs_waddstr_without_search(&fm2, v->curswin);
     92  owl_fmtext_curs_waddstr_without_search(&fm2, curswin);
    8493
    8594  /* print the message at the bottom */
    86   wmove(v->curswin, v->winlines-1, 0);
    87   wattrset(v->curswin, A_REVERSE);
     95  wmove(curswin, v->winlines-1, 0);
     96  wattrset(curswin, A_REVERSE);
    8897  if (v->textlines - v->topline > v->winlines-BOTTOM_OFFSET) {
    89     waddstr(v->curswin, "--More-- (Space to see more, 'q' to quit)");
     98    waddstr(curswin, "--More-- (Space to see more, 'q' to quit)");
    9099  } else {
    91     waddstr(v->curswin, "--End-- (Press 'q' to quit)");
     100    waddstr(curswin, "--End-- (Press 'q' to quit)");
    92101  }
    93   wattroff(v->curswin, A_REVERSE);
     102  wattroff(curswin, A_REVERSE);
    94103
    95104  owl_fmtext_cleanup(&fm1);
     
    103112    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
    104113  }
     114  owl_window_dirty(v->window);
    105115}
    106116
     
    111121    v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
    112122  }
     123  owl_window_dirty(v->window);
    113124}
    114125
     
    117128  v->topline-=v->winlines;
    118129  if (v->topline<0) v->topline=0;
     130  owl_window_dirty(v->window);
    119131}
    120132
     
    123135  v->topline--;
    124136  if (v->topline<0) v->topline=0;
     137  owl_window_dirty(v->window);
    125138}
    126139
     
    128141{
    129142  v->rightshift+=n;
     143  owl_window_dirty(v->window);
    130144}
    131145
     
    134148  v->rightshift-=n;
    135149  if (v->rightshift<0) v->rightshift=0;
     150  owl_window_dirty(v->window);
    136151}
    137152
     
    140155  v->topline=0;
    141156  v->rightshift=0;
     157  owl_window_dirty(v->window);
    142158}
    143159
     
    145161{
    146162  v->topline = v->textlines - v->winlines + BOTTOM_OFFSET;
     163  owl_window_dirty(v->window);
    147164}
    148165
Note: See TracChangeset for help on using the changeset viewer.