[gq-commit] gq/src dtutil.c,1.2,1.3
Status: Beta
Brought to you by:
sur5r
From: <sta...@us...> - 2002-07-13 09:13:38
|
Update of /cvsroot/gqclient/gq/src In directory usw-pr-cvs1:/tmp/cvs-serv10442 Modified Files: dtutil.c Log Message: * Fixed yet-another bug: suddenly all empty GtkEditable based attribute data widgets returned zero length data instead of NULL when no data was present. Arghhhhh! Remember: think before checking in... Index: dtutil.c =================================================================== RCS file: /cvsroot/gqclient/gq/src/dtutil.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** dtutil.c 13 Jul 2002 07:01:06 -0000 1.2 --- dtutil.c 13 Jul 2002 09:13:34 -0000 1.3 *************** *** 48,95 **** char nul[] = { 0 }; int pos = 0; ! GByteArray *copy, *encoded; ! gboolean del = FALSE, deldata = FALSE; ! ! if (data == NULL) { ! data = g_byte_array_new(); ! deldata = TRUE; ! } ! ! len = data->len; ! /* encode data */ ! if (encode) { ! encoded = encode(data->data, data->len); ! del = TRUE; ! } else { ! encoded = data; ! del = FALSE; ! } ! /* append a NUL byte, so we can be sure that we have a NUL ! terminated string (though there may be a NUL somewhere in the ! data already) */ ! g_byte_array_append(encoded, nul, 1); ! gtk_editable_delete_text(entry, 0, -1); ! gtk_editable_insert_text(entry, encoded->data, strlen(encoded->data), ! &pos); ! ! gtk_editable_set_position(entry, 0); ! /* strip the extra NUL byte again... */ ! g_byte_array_set_size(encoded, len); ! if (del) g_byte_array_free(encoded, TRUE); ! encoded = NULL; ! /* store a copy of the original data with the entry... */ ! copy = g_byte_array_new(); ! g_byte_array_append(copy, data->data, len); - gtk_object_set_data_full(GTK_OBJECT(entry), - "original_data", copy, - (GtkDestroyNotify) g_byte_array_free); gtk_object_set_data(GTK_OBJECT(entry), "decoder", decode); --- 48,95 ---- char nul[] = { 0 }; int pos = 0; ! GByteArray *copy = NULL, *encoded; ! gboolean del = FALSE; ! gtk_editable_delete_text(entry, 0, -1); ! if (data) { ! len = data->len; ! ! /* encode data */ ! if (encode) { ! encoded = encode(data->data, data->len); ! del = TRUE; ! } else { ! encoded = data; ! del = FALSE; ! } ! /* append a NUL byte, so we can be sure that we have a NUL ! terminated string (though there may be a NUL somewhere in the ! data already) */ ! ! g_byte_array_append(encoded, nul, 1); ! ! gtk_editable_insert_text(entry, encoded->data, ! strlen(encoded->data), &pos); ! ! gtk_editable_set_position(entry, 0); ! /* strip the extra NUL byte again... */ ! g_byte_array_set_size(encoded, len); ! if (del) g_byte_array_free(encoded, TRUE); ! encoded = NULL; ! /* store a copy of the original data with the entry... */ ! copy = g_byte_array_new(); ! g_byte_array_append(copy, data->data, len); ! } ! if (copy) ! gtk_object_set_data_full(GTK_OBJECT(entry), ! "original_data", copy, ! (GtkDestroyNotify) g_byte_array_free); gtk_object_set_data(GTK_OBJECT(entry), "decoder", decode); *************** *** 100,105 **** GTK_SIGNAL_FUNC(editable_changed_cb), (gpointer) NULL); - - if (deldata) g_byte_array_free(data, TRUE); } --- 100,103 ---- *************** *** 108,113 **** int changed = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(entry), "editable_changed_flag")); ! GByteArray *data; char *c; GByteArray* (*decode)(const char *val, int len); --- 106,112 ---- int changed = GPOINTER_TO_INT(gtk_object_get_data(GTK_OBJECT(entry), "editable_changed_flag")); ! GByteArray *data = NULL; char *c; + int l; GByteArray* (*decode)(const char *val, int len); *************** *** 116,119 **** --- 115,127 ---- c = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1); + + if (!c) return NULL; + + l = strlen(c); + if (l == 0) { + g_free(c); + return NULL; + } + if (decode) { data = decode(c, strlen(c)); *************** *** 126,133 **** GByteArray *original = gtk_object_get_data(GTK_OBJECT(entry), "original_data"); - data = g_byte_array_new(); - - /* copy data */ if (original) { g_byte_array_append(data, original->data, original->len); } --- 134,140 ---- GByteArray *original = gtk_object_get_data(GTK_OBJECT(entry), "original_data"); if (original) { + /* copy data, if any */ + data = g_byte_array_new(); g_byte_array_append(data, original->data, original->len); } |