Changeset 68f63a2


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.
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r13ebf92 r68f63a2  
    12851285  owl_popwin_up(pw);
    12861286  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
    1287   owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
    1288                         owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
    1289                         text);
    1290   owl_viewwin_redisplay(v);
    1291   owl_global_set_needrefresh(&g);
     1287  owl_viewwin_init_text(v, owl_popwin_get_content(pw), text);
    12921288}
    12931289
     
    13021298  owl_popwin_up(pw);
    13031299  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
    1304   owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw),
    1305                    owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
    1306                    fm);
    1307   owl_viewwin_redisplay(v);
    1308   owl_global_set_needrefresh(&g);
     1300  owl_viewwin_init_fmtext(v, owl_popwin_get_content(pw), fm);
    13091301}
    13101302
  • global.c

    r449af72 r68f63a2  
    511511
    512512void owl_global_relayout(owl_global *g) {
    513   owl_popwin *pw;
    514   owl_viewwin *vw;
    515 
    516513  if (!g->relayoutpending) return;
    517514  g->relayoutpending = 0;
     
    528525   * screen */
    529526  owl_function_calculate_topmsg(OWL_DIRECTION_NONE);
    530 
    531   /* recreate the popwin */
    532   pw = owl_global_get_popwin(g);
    533   if (owl_popwin_is_active(pw)) {
    534     /*
    535      * This is somewhat hacky; we probably want a proper windowing layer. We
    536      * destroy the popwin and recreate it. Then the viewwin is redirected to
    537      * the new window.
    538      */
    539     vw = owl_global_get_viewwin(g);
    540     owl_popwin_close(pw);
    541     owl_popwin_up(pw);
    542     owl_viewwin_set_curswin(vw, owl_popwin_get_curswin(pw),
    543         owl_popwin_get_lines(pw), owl_popwin_get_cols(pw));
    544     owl_viewwin_redisplay(vw);
    545   }
    546527
    547528  /* refresh stuff */
  • keys.c

    r44cc9ab r68f63a2  
    342342
    343343void owl_keys_popless_postalways(owl_input j) {
    344   owl_viewwin *v = owl_global_get_viewwin(&g);
    345   const owl_popwin *pw = owl_global_get_popwin(&g);
    346 
    347   if (pw && owl_popwin_is_active(pw) && v) {
    348     owl_viewwin_redisplay(v);
    349     owl_global_set_needrefresh(&g);
    350   } 
    351344}
    352345
  • owl.h

    r449af72 r68f63a2  
    404404  int rightshift;
    405405  int winlines, wincols;
    406   WINDOW *curswin;
     406  owl_window *window;
    407407  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
    408408  void *onclose_hook_data;
     
    410410 
    411411typedef struct _owl_popwin {
    412   PANEL *borderpanel;
    413   PANEL *poppanel;
     412  owl_window *border;
     413  owl_window *content;
    414414  int lines;
    415415  int cols;
  • popexec.c

    r125fd21 r68f63a2  
    2828  owl_popwin_up(pw);
    2929  owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless");
    30   owl_viewwin_init_text(v, owl_popwin_get_curswin(pw),
    31                         owl_popwin_get_lines(pw), owl_popwin_get_cols(pw),
    32                         "");
    33   owl_viewwin_redisplay(v);
    34   owl_global_set_needrefresh(&g);
     30  owl_viewwin_init_text(v, owl_popwin_get_content(pw), "");
    3531  owl_viewwin_set_onclose_hook(v, owl_popexec_viewwin_onclose, pe);
    3632  pe->refcount++;
     
    111107    if (pe->winactive) {
    112108      owl_viewwin_append_text(pe->vwin, "\n");
    113       owl_viewwin_redisplay(pe->vwin);
    114       owl_global_set_needrefresh(&g);
    115109    }
    116110    owl_select_remove_io_dispatch(d);
     
    139133  if (pe->winactive) {
    140134    owl_viewwin_append_text(pe->vwin, buf);
    141     owl_viewwin_redisplay(pe->vwin);
    142     owl_global_set_needrefresh(&g);
    143135  }
    144136  owl_free(buf);
  • popwin.c

    r0881cdd r68f63a2  
    1111int owl_popwin_up(owl_popwin *pw)
    1212{
    13   int glines, gcols, startcol, startline;
    14   WINDOW *popwin, *borderwin;
     13  /* make them zero-size for now */
     14  pw->border = owl_window_new(0, 0, 0, 0, 0);
     15  pw->content = owl_window_new(pw->border, 0, 0, 0, 0);
    1516
    16   /* calculate the size of the popwin */
    17   glines=owl_global_get_lines(&g);
    18   gcols=owl_global_get_cols(&g);
     17  owl_window_set_redraw_cb(pw->border, owl_popwin_draw_border, pw, 0);
     18  owl_window_set_resize_cb(pw->border, owl_popwin_resize_content, pw, 0);
     19  /* HACK */
     20  owl_window_set_resize_cb(owl_window_get_screen(), owl_popwin_reposition, pw, 0);
    1921
    20   pw->lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
    21   startline = (glines-pw->lines)/2;
     22  /* calculate position, THEN map the windows maybe setting a resize hook
     23   * should just cause it to get called? */
     24  owl_popwin_reposition(owl_window_get_screen(), pw);
     25  owl_window_map(pw->border, 1);
    2226
    23   pw->cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
    24   startcol = (gcols-pw->cols)/2;
     27  pw->active=1;
     28  return(0);
     29}
    2530
    26   borderwin = newwin(pw->lines, pw->cols, startline, startcol);
    27   pw->borderpanel = new_panel(borderwin);
    28   popwin = newwin(pw->lines-2, pw->cols-2, startline+1, startcol+1);
    29   pw->poppanel = new_panel(popwin);
     31void owl_popwin_reposition(owl_window *screen, void *user_data)
     32{
     33  owl_popwin *pw = user_data;
     34  int lines, cols, startline, startcol;
     35  int glines, gcols;
    3036
    31   werase(popwin);
    32   werase(borderwin);
     37  owl_window_get_position(screen, &glines, &gcols, 0, 0);
     38
     39  lines = owl_util_min(glines,24)*3/4 + owl_util_max(glines-24,0)/2;
     40  startline = (glines-lines)/2;
     41  cols = owl_util_min(gcols,90)*15/16 + owl_util_max(gcols-90,0)/2;
     42  startcol = (gcols-cols)/2;
     43
     44  owl_window_set_position(pw->border, lines, cols, startline, startcol);
     45}
     46
     47void owl_popwin_resize_content(owl_window *w, void *user_data)
     48{
     49  owl_popwin *pw = user_data;
     50  owl_window_get_position(w, &pw->lines, &pw->cols, 0, 0);
     51  owl_window_set_position(pw->content, pw->lines-2, pw->cols-2, 1, 1);
     52}
     53
     54void owl_popwin_draw_border(owl_window *w, WINDOW *borderwin, void *user_data)
     55{
     56  owl_popwin *pw = user_data;
    3357  if (owl_global_is_fancylines(&g)) {
    3458    box(borderwin, 0, 0);
     
    4468    waddch(borderwin, '+');
    4569  }
    46    
    47   owl_global_set_needrefresh(&g);
    48   pw->active=1;
    49   return(0);
    5070}
    5171
    5272int owl_popwin_close(owl_popwin *pw)
    5373{
    54   WINDOW *popwin, *borderwin;
    55 
    56   popwin = panel_window(pw->poppanel);
    57   borderwin = panel_window(pw->borderpanel);
    58 
    59   del_panel(pw->poppanel);
    60   del_panel(pw->borderpanel);
    61   delwin(popwin);
    62   delwin(borderwin);
    63 
     74  owl_window_delete(pw->border);
     75  pw->border = 0;
     76  pw->content = 0;
    6477  pw->active=0;
    65   owl_global_set_needrefresh(&g);
     78  owl_window_set_resize_cb(owl_window_get_screen(), 0, 0, 0);
    6679  return(0);
    6780}
     
    7285}
    7386
    74 WINDOW *owl_popwin_get_curswin(const owl_popwin *pw)
     87owl_window *owl_popwin_get_content(const owl_popwin *pw)
    7588{
    76   return panel_window(pw->poppanel);
     89  return pw->content;
    7790}
    7891
  • 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.