Changeset f6fae8d for editwin.c


Ignore:
Timestamp:
Jun 1, 2010, 12:14:11 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:
e294783
Parents:
84a4aca
Message:
Port the editwin to owl_window

The others are still unmanaged for now. Fortunately, they were set up as
as panels, so we can see through them to the windows we want in the
meantime. :-)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r4e33cb2 rf6fae8d  
    2828  int cursorx;
    2929  int winlines, wincols, fillcol, wrapcol;
    30   WINDOW *curswin;
     30  owl_window *win;
     31  gulong repaint_id;
     32  gulong resized_id;
    3133  int style;
    3234  int lock;
     
    4042};
    4143
     44static void oe_set_curswin(owl_editwin *e, owl_window *w, int winlines, int wincols);
     45static void oe_redisplay(owl_window *win, WINDOW *curswin, void *user_data);
    4246static void oe_reframe(owl_editwin *e);
    4347static void oe_save_excursion(owl_editwin *e, oe_excursion *x);
     
    5862static char *oe_chunk(owl_editwin *e, int start, int end);
    5963static void oe_destroy_cbdata(owl_editwin *e);
     64static void oe_dirty(owl_editwin *e);
     65static void oe_window_resized(owl_window *w, owl_editwin *e);
    6066
    6167#define INCR 4096
     
    7379void owl_editwin_delete(owl_editwin *e)
    7480{
     81  if (e->win) {
     82    g_signal_handler_disconnect(e->win, e->repaint_id);
     83    g_signal_handler_disconnect(e->win, e->resized_id);
     84  }
    7585  owl_free(e->buff);
    7686  owl_free(e->killbuf);
     
    91101  }
    92102  e->index = index;
     103  oe_dirty(e);
    93104}
    94105
     
    105116
    106117static void _owl_editwin_init(owl_editwin *e,
    107                               WINDOW *win,
    108118                              int winlines,
    109119                              int wincols,
     
    130140    e->style=OWL_EDITWIN_STYLE_MULTILINE;
    131141  }
    132   owl_editwin_set_curswin(e, win, winlines, wincols);
    133142  e->lock=0;
    134143  e->dotsend=0;
    135144  e->echochar='\0';
    136 
    137   if (win) werase(win);
    138 }
    139 
    140 owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
     145}
     146
     147owl_editwin *owl_editwin_new(owl_window *win, int winlines, int wincols, int style, owl_history *hist)
    141148{
    142149  owl_editwin *e = owl_editwin_allocate();
    143150
    144   _owl_editwin_init(e, win, winlines, wincols, style, hist);
     151  _owl_editwin_init(e, winlines, wincols, style, hist);
     152  oe_set_curswin(e, win, winlines, wincols);
    145153  return e;
    146154}
    147155
    148 void owl_editwin_set_curswin(owl_editwin *e, WINDOW *w, int winlines, int wincols)
    149 {
    150   e->curswin=w;
     156static void oe_window_resized(owl_window *w, owl_editwin *e)
     157{
     158  /* update the sizes */
     159  owl_window_get_position(w, &e->winlines, &e->wincols, NULL, NULL);
     160}
     161
     162static void oe_set_curswin(owl_editwin *e, owl_window *w, int winlines, int wincols)
     163{
     164  e->win=w;
    151165  e->winlines=winlines;
    152166  e->wincols=wincols;
     
    156170  else
    157171    e->wrapcol = 0;
     172  if (e->win) {
     173    e->repaint_id = g_signal_connect(w, "redraw", G_CALLBACK(oe_redisplay), e);
     174    e->resized_id = g_signal_connect(w, "resized", G_CALLBACK(oe_window_resized), e);
     175    owl_window_dirty(e->win);
     176  }
    158177}
    159178
     
    165184{
    166185  e->echochar=ch;
    167 }
    168 
    169 WINDOW *owl_editwin_get_curswin(owl_editwin *e)
    170 {
    171   return(e->curswin);
     186  oe_dirty(e);
    172187}
    173188
     
    239254  e->lock=e->bufflen;
    240255  oe_set_index(e, e->lock);
    241   owl_editwin_redisplay(e);
     256  oe_dirty(e);
    242257}
    243258
     
    265280
    266281  owl_free(e->buff);
    267   _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
     282  _owl_editwin_init(e, e->winlines, e->wincols, e->style, e->hist);
    268283
    269284  if (lock > 0) {
     
    286301{
    287302  e->topindex = -1;
     303  oe_dirty(e);
    288304}
    289305
     
    467483
    468484  oe_restore_excursion(e, &x);
    469 }
    470 
    471 static void oe_addnec(owl_editwin *e, int count)
     485  oe_dirty(e);
     486}
     487
     488static void oe_addnec(owl_editwin *e, WINDOW *curswin, int count)
    472489{
    473490  int i;
    474491
    475492  for (i = 0; i < count; i++)
    476     waddch(e->curswin, e->echochar);
    477 }
    478 
    479 static void oe_mvaddnec(owl_editwin *e, int y, int x, int count)
    480 {
    481   wmove(e->curswin, y, x);
    482   oe_addnec(e, count);
     493    waddch(curswin, e->echochar);
     494}
     495
     496static void oe_mvaddnec(owl_editwin *e, WINDOW *curswin, int y, int x, int count)
     497{
     498  wmove(curswin, y, x);
     499  oe_addnec(e, curswin, count);
    483500}
    484501
    485502/* regenerate the text on the curses window */
    486 void owl_editwin_redisplay(owl_editwin *e)
     503static void oe_redisplay(owl_window *win, WINDOW *curswin, void *user_data)
    487504{
    488505  int x = -1, y = -1, t, hard;
    489506  int line, index, lineindex, times = 0;
     507  owl_editwin *e = user_data;
    490508
    491509  do {
    492     werase(e->curswin);
     510    werase(curswin);
    493511
    494512    if (e->topindex == -1 || e->index < e->topindex)
     
    505523      if (index - lineindex) {
    506524        if (!e->echochar)
    507           mvwaddnstr(e->curswin, line, 0,
     525          mvwaddnstr(curswin, line, 0,
    508526                     e->buff + lineindex,
    509527                     index - lineindex);
    510528        else {
    511529          if(lineindex < e->lock) {
    512             mvwaddnstr(e->curswin, line, 0,
     530            mvwaddnstr(curswin, line, 0,
    513531                       e->buff + lineindex,
    514532                       MIN(index - lineindex,
    515533                           e->lock - lineindex));
    516534            if (e->lock < index)
    517               oe_addnec(e,
     535              oe_addnec(e, curswin,
    518536                        oe_region_width(e, e->lock, index,
    519537                                        oe_region_width(e, lineindex, e->lock, 0)));
    520538          } else
    521             oe_mvaddnec(e, line, 0, oe_region_width(e, lineindex, index, 0));
     539            oe_mvaddnec(e, curswin, line, 0, oe_region_width(e, lineindex, index, 0));
    522540        }
    523541        if (!hard)
    524           waddch(e->curswin, '\\');
     542          waddch(curswin, '\\');
    525543      }
    526544      line++;
     
    531549  } while(x == -1 && times < 3);
    532550
    533   wmove(e->curswin, y, x);
     551  wmove(curswin, y, x);
    534552  e->cursorx = x;
    535   owl_global_set_needrefresh(&g);
    536553}
    537554
     
    625642  if (start <= e->topindex)
    626643    owl_editwin_recenter(e);
     644
     645  oe_dirty(e);
    627646
    628647  return change;
     
    858877
    859878  e->goal_column = goal_column;
     879  oe_dirty(e);
    860880
    861881  return distance;
     
    12121232    return;
    12131233  }
    1214   owl_editwin_redisplay(e);
    12151234}
    12161235
     
    13471366}
    13481367
     1368static void oe_dirty(owl_editwin *e)
     1369{
     1370  if (e->win) owl_window_dirty(e->win);
     1371}
     1372
    13491373
    13501374
Note: See TracChangeset for help on using the changeset viewer.