Changes in editwin.c [f449096:21dd391]
Legend:
- Unmodified
- Added
- Removed
-
editwin.c
rf449096 r21dd391 35 35 oe_excursion *excursions; 36 36 37 char *command;38 37 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);48 47 static int oe_char_width(gunichar c, int column); 49 48 static int oe_region_width(owl_editwin *e, int start, int end, int width); … … 58 57 static int oe_copy_region(owl_editwin *e); 59 58 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 owl_editwin *owl_editwin_allocate(void)65 static 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);78 77 /* just in case someone forgot to clean up */ 79 78 while (e->excursions) { 80 79 oe_release_excursion(e, e->excursions); 81 80 } 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;96 84 } 97 85 … … 116 104 } 117 105 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) 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) 122 112 { 123 113 e->buff=owl_malloc(INCR); … … 145 135 e->echochar='\0'; 146 136 147 /* We get initialized multiple times, but we need to hold on to148 the callbacks, so we can't NULL them here. */149 /*150 e->command = NULL;151 e->callback = NULL;152 e->cbdata = NULL;153 */154 137 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; 155 146 } 156 147 … … 188 179 } 189 180 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 202 181 void owl_editwin_set_callback(owl_editwin *e, void (*cb)(owl_editwin*)) 203 182 { … … 210 189 } 211 190 212 void owl_editwin_set_cbdata(owl_editwin *e, void *data) 213 { 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); 214 201 e->cbdata = data; 202 e->destroy_cbdata = destroy; 215 203 } 216 204 … … 259 247 } 260 248 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 286 249 /* clear all text except for locktext and put the cursor at the 287 250 * beginning … … 302 265 303 266 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); 305 268 306 269 if (lock > 0) {
Note: See TracChangeset
for help on using the changeset viewer.