Changeset 60c1386


Ignore:
Timestamp:
Sep 18, 2010, 5:07:39 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
a8186dc
Parents:
2640b63
git-author:
David Benjamin <davidben@mit.edu> (08/01/10 16:29:45)
git-committer:
David Benjamin <davidben@mit.edu> (09/18/10 17:07:39)
Message:
Split the viewwin's status bar into its own window
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • owl.h

    r9eb38bb r60c1386  
    394394} owl_mainwin;
    395395
     396typedef struct _owl_editwin owl_editwin;
     397typedef struct _owl_editwin_excursion owl_editwin_excursion;
     398
    396399typedef struct _owl_viewwin {
    397400  owl_fmtext fmtext;
     
    400403  int rightshift;
    401404  owl_window *window;
    402   gulong sig_redraw_id;
    403405  void (*onclose_hook) (struct _owl_viewwin *vwin, void *data);
    404406  void *onclose_hook_data;
     407
     408  gulong sig_resize_id;
     409  owl_window *content;
     410  gulong sig_content_redraw_id;
     411  owl_window *status;
     412  gulong sig_status_redraw_id;
    405413} owl_viewwin;
    406414 
     
    462470  int repeats;
    463471} owl_history;
    464 
    465 typedef struct _owl_editwin owl_editwin;
    466 typedef struct _owl_editwin_excursion owl_editwin_excursion;
    467472
    468473typedef struct _owl_mainpanel {
  • viewwin.c

    r2640b63 r60c1386  
    55#define EMPTY_INDICATOR "~"
    66
    7 static void owl_viewwin_redraw(owl_window *w, WINDOW *curswin, void *user_data);
     7static void owl_viewwin_redraw_content(owl_window *w, WINDOW *curswin, void *user_data);
     8static void owl_viewwin_redraw_status(owl_window *w, WINDOW *curswin, void *user_data);
     9static void owl_viewwin_layout(owl_viewwin *v);
    810static void owl_viewwin_set_window(owl_viewwin *v, owl_window *w);
    911
     
    5658static void owl_viewwin_set_window(owl_viewwin *v, owl_window *w)
    5759{
    58   v->window = w;
    59   if (w) {
    60     g_object_ref(v->window);
    61     v->sig_redraw_id = g_signal_connect(w, "redraw", G_CALLBACK(owl_viewwin_redraw), v);
    62   }
     60  v->window = g_object_ref(w);
     61  v->content = owl_window_new(v->window);
     62  v->status = owl_window_new(v->window);
     63
     64  v->sig_content_redraw_id =
     65    g_signal_connect(v->content, "redraw", G_CALLBACK(owl_viewwin_redraw_content), v);
     66  v->sig_status_redraw_id =
     67    g_signal_connect(v->status, "redraw", G_CALLBACK(owl_viewwin_redraw_status), v);
     68  v->sig_resize_id =
     69    g_signal_connect_swapped(v->window, "resized", G_CALLBACK(owl_viewwin_layout), v);
     70  owl_viewwin_layout(v);
     71
     72  owl_window_show(v->content);
     73  owl_window_show(v->status);
    6374}
    6475
     
    6879}
    6980
     81static void owl_viewwin_layout(owl_viewwin *v)
     82{
     83  int lines, cols;
     84  owl_window_get_position(v->window, &lines, &cols, NULL, NULL);
     85  owl_window_set_position(v->content, lines - BOTTOM_OFFSET, cols, 0, 0);
     86  owl_window_set_position(v->status, BOTTOM_OFFSET, cols, lines - BOTTOM_OFFSET, 0);
     87}
     88
    7089/* regenerate text on the curses window. */
    71 static void owl_viewwin_redraw(owl_window *w, WINDOW *curswin, void *user_data)
     90static void owl_viewwin_redraw_content(owl_window *w, WINDOW *curswin, void *user_data)
    7291{
    7392  owl_fmtext fm1, fm2;
     
    7796
    7897  owl_window_get_position(w, &winlines, &wincols, 0, 0);
    79  
     98
    8099  werase(curswin);
    81100  wmove(curswin, 0, 0);
     
    83102  owl_fmtext_init_null(&fm1);
    84103  owl_fmtext_init_null(&fm2);
    85  
    86   owl_fmtext_truncate_lines(&(v->fmtext), v->topline, winlines-BOTTOM_OFFSET, &fm1);
     104
     105  owl_fmtext_truncate_lines(&(v->fmtext), v->topline, winlines, &fm1);
    87106  owl_fmtext_truncate_cols(&fm1, v->rightshift, wincols-1+v->rightshift, &fm2);
    88107
     
    92111  y = v->textlines - v->topline;
    93112  wmove(curswin, y, 0);
    94   for (; y < winlines-BOTTOM_OFFSET; y++) {
     113  for (; y < winlines; y++) {
    95114    waddstr(curswin, EMPTY_INDICATOR);
    96115    waddstr(curswin, "\n");
    97116  }
    98117
    99   /* print the message at the bottom */
    100   wmove(curswin, winlines-1, 0);
     118  owl_fmtext_cleanup(&fm1);
     119  owl_fmtext_cleanup(&fm2);
     120}
     121
     122static void owl_viewwin_redraw_status(owl_window *w, WINDOW *curswin, void *user_data)
     123{
     124  owl_viewwin *v = user_data;
     125  int winlines, wincols;
     126
     127  owl_window_get_position(v->content, &winlines, &wincols, 0, 0);
     128
     129  werase(curswin);
     130  wmove(curswin, 0, 0);
    101131  wattrset(curswin, A_REVERSE);
    102   if (v->textlines - v->topline > winlines-BOTTOM_OFFSET) {
     132  if (v->textlines - v->topline > winlines) {
    103133    waddstr(curswin, "--More-- (Space to see more, 'q' to quit)");
    104134  } else {
     
    106136  }
    107137  wattroff(curswin, A_REVERSE);
    108 
    109   owl_fmtext_cleanup(&fm1);
    110   owl_fmtext_cleanup(&fm2);
    111138}
    112139
     
    122149void owl_viewwin_dirty(owl_viewwin *v)
    123150{
    124   if (v->window)
    125     owl_window_dirty(v->window);
     151  owl_window_dirty(v->content);
     152  owl_window_dirty(v->status);
    126153}
    127154
    128155void owl_viewwin_down(owl_viewwin *v, int amount) {
    129156  int winlines;
    130   owl_window_get_position(v->window, &winlines, 0, 0, 0);
     157  owl_window_get_position(v->content, &winlines, 0, 0, 0);
    131158  /* Don't scroll past the bottom. */
    132   amount = MIN(amount, v->textlines - (v->topline + winlines - BOTTOM_OFFSET));
     159  amount = MIN(amount, v->textlines - (v->topline + winlines));
    133160  /* But if we're already past the bottom, don't back up either. */
    134161  if (amount > 0) {
     
    148175{
    149176  int winlines;
    150   owl_window_get_position(v->window, &winlines, 0, 0, 0);
    151   owl_viewwin_down(v, winlines - BOTTOM_OFFSET);
     177  owl_window_get_position(v->content, &winlines, 0, 0, 0);
     178  owl_viewwin_down(v, winlines);
    152179}
    153180
     
    160187{
    161188  int winlines;
    162   owl_window_get_position(v->window, &winlines, 0, 0, 0);
    163   owl_viewwin_up(v, winlines - BOTTOM_OFFSET);
     189  owl_window_get_position(v->content, &winlines, 0, 0, 0);
     190  owl_viewwin_up(v, winlines);
    164191}
    165192
     
    192219{
    193220  int winlines;
    194   owl_window_get_position(v->window, &winlines, 0, 0, 0);
    195   v->topline = v->textlines - winlines + BOTTOM_OFFSET;
     221  owl_window_get_position(v->content, &winlines, 0, 0, 0);
     222  v->topline = v->textlines - winlines;
    196223  owl_viewwin_dirty(v);
    197224}
     
    228255    v->onclose_hook_data = NULL;
    229256  }
    230   if (v->window) {
    231     g_signal_handler_disconnect(v->window, v->sig_redraw_id);
    232     g_object_unref(v->window);
    233     v->window = NULL;
    234   }
     257  /* TODO: This is far too tedious. owl_viewwin should own v->window
     258   * and just unlink it in one go. Signals should also go away for
     259   * free. */
     260  g_signal_handler_disconnect(v->window, v->sig_resize_id);
     261  g_signal_handler_disconnect(v->content, v->sig_content_redraw_id);
     262  g_signal_handler_disconnect(v->status, v->sig_status_redraw_id);
     263  owl_window_unlink(v->content);
     264  owl_window_unlink(v->status);
     265  g_object_unref(v->window);
     266  g_object_unref(v->content);
     267  g_object_unref(v->status);
    235268  owl_fmtext_cleanup(&(v->fmtext));
    236269  owl_free(v);
Note: See TracChangeset for help on using the changeset viewer.