Changes in editwin.c [21dd391:f449096]
Legend:
- Unmodified
- Added
- Removed
-
editwin.c
r21dd391 rf449096 35 35 oe_excursion *excursions; 36 36 37 char *command; 37 38 void (*callback)(struct _owl_editwin*); 38 void (*destroy_cbdata)(void *);39 39 void *cbdata; 40 40 }; … … 45 45 static void oe_restore_excursion(owl_editwin *e, oe_excursion *x); 46 46 static void oe_restore_mark_only(owl_editwin *e, oe_excursion *x); 47 static int oe_count_glyphs(const char *s); 47 48 static int oe_char_width(gunichar c, int column); 48 49 static int oe_region_width(owl_editwin *e, int start, int end, int width); … … 57 58 static int oe_copy_region(owl_editwin *e); 58 59 static char *oe_chunk(owl_editwin *e, int start, int end); 59 static void oe_destroy_cbdata(owl_editwin *e);60 60 61 61 #define INCR 4096 … … 63 63 #define WHITESPACE " \n\t" 64 64 65 staticowl_editwin *owl_editwin_allocate(void)65 owl_editwin *owl_editwin_allocate(void) 66 66 { 67 67 owl_editwin *e; … … 75 75 owl_free(e->buff); 76 76 owl_free(e->killbuf); 77 owl_free(e->command); 77 78 /* just in case someone forgot to clean up */ 78 79 while (e->excursions) { 79 80 oe_release_excursion(e, e->excursions); 80 81 } 81 oe_destroy_cbdata(e);82 82 83 83 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; 84 96 } 85 97 … … 104 116 } 105 117 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 */ 121 void owl_editwin_init(owl_editwin *e, WINDOW *win, int winlines, int wincols, int style, owl_history *hist) 112 122 { 113 123 e->buff=owl_malloc(INCR); … … 135 145 e->echochar='\0'; 136 146 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 */ 137 154 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;146 155 } 147 156 … … 179 188 } 180 189 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 181 202 void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*)) 182 203 { … … 189 210 } 190 211 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); 212 void owl_editwin_set_cbdata(owl_editwin *e, void *data) 213 { 201 214 e->cbdata = data; 202 e->destroy_cbdata = destroy;203 215 } 204 216 … … 247 259 } 248 260 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 249 286 /* clear all text except for locktext and put the cursor at the 250 287 * beginning … … 265 302 266 303 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); 268 305 269 306 if (lock > 0) {
Note: See TracChangeset
for help on using the changeset viewer.