Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • editwin.c

    rf449096 r21dd391  
    3535  oe_excursion *excursions;
    3636
    37   char *command;
    3837  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);
    47 static int oe_count_glyphs(const char *s);
    4847static int oe_char_width(gunichar c, int column);
    4948static int oe_region_width(owl_editwin *e, int start, int end, int width);
     
    5857static int oe_copy_region(owl_editwin *e);
    5958static char *oe_chunk(owl_editwin *e, int start, int end);
     59static void oe_destroy_cbdata(owl_editwin *e);
    6060
    6161#define INCR 4096
     
    6363#define WHITESPACE " \n\t"
    6464
    65 owl_editwin *owl_editwin_allocate(void)
     65static owl_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);
    7877  /* just in case someone forgot to clean up */
    7978  while (e->excursions) {
    8079    oe_release_excursion(e, e->excursions);
    8180  }
     81  oe_destroy_cbdata(e);
    8282
    8383  owl_free(e);
    84 }
    85 
    86 static 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;
    9684}
    9785
     
    116104}
    117105
    118 /* initialize the editwin e.
    119  * 'win' is an already initialzed curses window that will be used by editwin
    120  */
    121 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist)
     106static void _owl_editwin_init(owl_editwin *e,
     107                              WINDOW *win,
     108                              int winlines,
     109                              int wincols,
     110                              int style,
     111                              owl_history *hist)
    122112{
    123113  e->buff=owl_malloc(INCR);
     
    145135  e->echochar='\0';
    146136
    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   */
    154137  if (win) werase(win);
     138}
     139
     140owl_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;
    155146}
    156147
     
    188179}
    189180
    190 void 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 
    196 const char *owl_editwin_get_command(owl_editwin *e)
    197 {
    198   if(e->command) return e->command;
    199   return "";
    200 }
    201 
    202181void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*))
    203182{
     
    210189}
    211190
    212 void owl_editwin_set_cbdata(owl_editwin *e, void *data)
    213 {
     191static 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
     198void owl_editwin_set_cbdata(owl_editwin *e, void *data, void (*destroy)(void *))
     199{
     200  oe_destroy_cbdata(e);
    214201  e->cbdata = data;
     202  e->destroy_cbdata = destroy;
    215203}
    216204
     
    259247}
    260248
    261 void 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 */
    280 void 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 
    286249/* clear all text except for locktext and put the cursor at the
    287250 * beginning
     
    302265
    303266  owl_free(e->buff);
    304   owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
     267  _owl_editwin_init(e, e->curswin, e->winlines, e->wincols, e->style, e->hist);
    305268
    306269  if (lock > 0) {
Note: See TracChangeset for help on using the changeset viewer.