comparison gtk/dw.c @ 608:e49524bc2f07

Fix trailing junk on dw_mle_export()
author mhessling@81767d24-ef19-dc11-ae90-00e081727c95
date Sun, 01 Oct 2006 04:40:02 +0000
parents 840b43f3976b
children 2bff0dbae0e5
comparison
equal deleted inserted replaced
607:b4cb30f47a97 608:e49524bc2f07
4209 4209
4210 /* 4210 /*
4211 * Grabs text from an MLE box. 4211 * Grabs text from an MLE box.
4212 * Parameters: 4212 * Parameters:
4213 * handle: Handle to the MLE to be queried. 4213 * handle: Handle to the MLE to be queried.
4214 * buffer: Text buffer to be exported. 4214 * buffer: Text buffer to be exported. MUST allow for trailing nul character.
4215 * startpoint: Point to start grabbing text. 4215 * startpoint: Point to start grabbing text.
4216 * length: Amount of text to be grabbed. 4216 * length: Amount of text to be grabbed.
4217 */ 4217 */
4218 void dw_mle_export(HWND handle, char *buffer, int startpoint, int length) 4218 void dw_mle_export(HWND handle, char *buffer, int startpoint, int length)
4219 { 4219 {
4221 gchar *text; 4221 gchar *text;
4222 4222
4223 DW_MUTEX_LOCK; 4223 DW_MUTEX_LOCK;
4224 /* force the return value to nul in case the following tests fail */ 4224 /* force the return value to nul in case the following tests fail */
4225 if(buffer) 4225 if(buffer)
4226 strcpy(buffer,""); 4226 buffer[0] = '\0';
4227 #if GTK_MAJOR_VERSION > 1 4227 #if GTK_MAJOR_VERSION > 1
4228 if(GTK_IS_SCROLLED_WINDOW(handle)) 4228 if(GTK_IS_SCROLLED_WINDOW(handle))
4229 #else 4229 #else
4230 if(GTK_IS_BOX(handle)) 4230 if(GTK_IS_BOX(handle))
4231 #endif 4231 #endif
4243 gtk_text_buffer_get_iter_at_offset(tbuffer, &end, startpoint + length); 4243 gtk_text_buffer_get_iter_at_offset(tbuffer, &end, startpoint + length);
4244 text = gtk_text_iter_get_text(&start, &end); 4244 text = gtk_text_iter_get_text(&start, &end);
4245 if(text) /* Should this get freed? */ 4245 if(text) /* Should this get freed? */
4246 { 4246 {
4247 if(buffer) 4247 if(buffer)
4248 strcpy(buffer, text); 4248 memcpy(buffer, text);
4249 } 4249 }
4250 } 4250 }
4251 #else 4251 #else
4252 if(tmp && GTK_IS_TEXT(tmp)) 4252 if(tmp && GTK_IS_TEXT(tmp))
4253 { 4253 {
4254 text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), startpoint, startpoint + length - 1); 4254 text = gtk_editable_get_chars(GTK_EDITABLE(&(GTK_TEXT(tmp)->editable)), 0, -1); /* get the complete contents */
4255 if(text) 4255 if(text)
4256 { 4256 {
4257 if(buffer) 4257 if(buffer)
4258 strcpy(buffer, text); 4258 {
4259 len = strlen(text);
4260 if(startpoint < len)
4261 {
4262 max = min(length, len - startpoint);
4263 memcpy(buffer, &text[startpoint], max);
4264 buffer[max] = '\0';
4265 }
4266 }
4259 g_free(text); 4267 g_free(text);
4260 } 4268 }
4261 } 4269 }
4262 #endif 4270 #endif
4263 } 4271 }