Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    r21dd391 rf449096  
    3535  oe_excursion *excursions;
    3636
     37  char *command;
    3738  void (*callback)(struct _owl_editwin*);
    38   void (*destroy_cbdata)(void *);
    3939  void *cbdata;
    4040};
     
    4545static void oe_restore_excursion(owl_editwin *e, oe_excursion *x);
    4646static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x);
     47static int oe_count_glyphs(const char *s);
    4748static int oe_char_width(gunichar c, int column);
    4849static int oe_region_width(owl_editwin *e, int start, int end, int width);
     
    5758static int oe_copy_region(owl_editwin *e);
    5859static char *oe_chunk(owl_editwin *e, int start, int end);
    59 static void oe_destroy_cbdata(owl_editwin *e);
    6060
    6161#define INCR 4096
     
    6363#define WHITESPACE " \n\t"
    6464
    65 static owl_editwin *owl_editwin_allocate(void)
     65owl_editwin *owl_editwin_allocate(void)
    6666{
    6767  owl_editwin *e;
     
    7575  owl_free(e->buff);
    7676  owl_free(e->killbuf);
     77  owl_free(e->command);
    7778  /* just in case someone forgot to clean up */
    7879  while (e->excursions) {
    7980    oe_release_excursion(e, e->excursions);
    8081  }
    81   oe_destroy_cbdata(e);
    8282
    8383  owl_free(e);
     84}
     85
     86static int oe_count_glyphs(const char *s)
     87{
     88  int count = 0;
     89  const char *p;
     90
     91  for(p = s; *p != 0; p = g_utf8_find_next_char(p, NULL))
     92    if (!g_unichar_ismark(g_utf8_get_char(p)))
     93      count++;
     94
     95  return count;
    8496}
    8597
     
    104116}
    105117
    106 static void _owl_editwin_init(owl_editwin *e,
    107                               WINDOW *win,
    108                               int winlines,
    109                               int wincols,
    110                               int style,
    111                               owl_history *hist)
     118/* initialize the editwin e.
     119 * 'win' is an already initialzed curses window that will be used by editwin
     120 */
     121void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
    112122{
    113123  e->buff=owl_malloc(INCR);
     
    135145  e->echochar='\0';
    136146
     147  /* We get initialized multiple times, but we need to hold on to
     148     the callbacks, so we can't NULL them here. */
     149  /*
     150    e->command = NULL;
     151    e->callback = NULL;
     152    e->cbdata = NULL;
     153  */
    137154  if (win) werase(win);
    138 }
    139 
    140 owl_editwin *owl_editwin_new(WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
    141 {
    142   owl_editwin *e = owl_editwin_allocate();
    143 
    144   _owl_editwin_init(e, win, winlines, wincols, style, hist);
    145   return e;
    146155}
    147156
     
    179188}
    180189
     190void owl_editwin_set_command(owl_editwin *e, const char *command)
     191{
     192  if(e->command) owl_free(e->command);
     193  e->command = owl_strdup(command);
     194}
     195
     196const char *owl_editwin_get_command(owl_editwin *e)
     197{
     198  if(e->command) return e->command;
     199  return "";
     200}
     201
    181202void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*))
    182203{
     
    189210}
    190211
    191 static void oe_destroy_cbdata(owl_editwin *e) {
    192   if (e->destroy_cbdata)
    193     e->destroy_cbdata(e->cbdata);
    194   e->cbdata = NULL;
    195   e->destroy_cbdata = NULL;
    196 }
    197 
    198 void owl_editwin_set_cbdata(owl_editwin *e, void *data, void (*destroy)(void *))
    199 {
    200   oe_destroy_cbdata(e);
     212void owl_editwin_set_cbdata(owl_editwin *e, void *data)
     213{
    201214  e->cbdata = data;
    202   e->destroy_cbdata = destroy;
    203215}
    204216
     
    247259}
    248260
     261void owl_editwin_new_style(owl_editwin *e, int newstyle, owl_history *h)
     262{
     263  e->hist = h;
     264
     265  if (e->style==newstyle) return;
     266
     267  if (newstyle==OWL_EDITWIN_STYLE_MULTILINE) {
     268    e->style=newstyle;
     269  } else if (newstyle==OWL_EDITWIN_STYLE_ONELINE) {
     270    e->style=newstyle;
     271
     272    /* nuke everything after the first line */
     273    owl_editwin_move_to_top(e);
     274    owl_editwin_move_to_end_of_line(e);
     275    owl_editwin_replace(e, oe_count_glyphs(e->buff + e->index),  "");
     276  }
     277}
     278
     279/* completly reinitialize the buffer */
     280void owl_editwin_fullclear(owl_editwin *e)
     281{
     282  owl_free(e->buff);
     283  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
     284}
     285
    249286/* clear all text except for locktext and put the cursor at the
    250287 * beginning
     
    265302
    266303  owl_free(e->buff);
    267   _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
     304  owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    268305
    269306  if (lock > 0) {
Note: See TracChangeset for help on using the changeset viewer.