From 6e4fb2c28e34b4b89c9e2199c09f22edf5060f7d Mon Sep 17 00:00:00 2001 From: Jordi Albornoz Date: Tue, 3 Dec 2002 17:10:35 +0000 Subject: [PATCH] Patch from James Antill: * src/misc.c (adjust_bottom_text_view): Change function API to work on TextViews nativley ... use idle handler to stop syncronous updates. (nocolor): Change static buffer with no bounds checking to dynamicly sized buffer. * src/gtetrinet.c (keypress): Search for notebook keys before game keys (as 1, 2 and 3 are attack commands). --- ChangeLog | 10 ++++++++ src/fields.c | 4 +-- src/gtetrinet.c | 12 ++++----- src/misc.c | 68 ++++++++++++++++++++++++++++++++++++++++++------- src/misc.h | 2 +- src/partyline.c | 2 +- 6 files changed, 79 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index 15d9f11..8abfecf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2002-12-02 James Antill + + * src/misc.c (adjust_bottom_text_view): Change function API to work on + TextViews nativley ... use idle handler to stop syncronous updates. + (nocolor): Change static buffer with no bounds checking to dynamicly + sized buffer. + + * src/gtetrinet.c (keypress): Search for notebook keys before game + keys (as 1, 2 and 3 are attack commands). + 2002-11-18 Jordi Mallach * AUTHORS: added Gerfried. diff --git a/src/fields.c b/src/fields.c index f5de3e1..21a1dd5 100644 --- a/src/fields.c +++ b/src/fields.c @@ -499,7 +499,7 @@ void fields_drawnextblock (TETRISBLOCK block) void fields_attdefmsg (char *text) { textbox_addtext (GTK_TEXT_VIEW(attdefwidget), text); - adjust_bottom (GTK_TEXT_VIEW(attdefwidget)->vadjustment); + adjust_bottom_text_view (GTK_TEXT_VIEW(attdefwidget)); } void fields_attdefclear (void) @@ -541,7 +541,7 @@ void fields_setactivelevel (int l) void fields_gmsgadd (char *str) { textbox_addtext (GTK_TEXT_VIEW(gmsgtext), str); - adjust_bottom (GTK_TEXT_VIEW(gmsgtext)->vadjustment); + adjust_bottom_text_view (GTK_TEXT_VIEW(gmsgtext)); } void fields_gmsgclear (void) diff --git a/src/gtetrinet.c b/src/gtetrinet.c index 915dc0e..265b7bf 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -320,16 +320,16 @@ gint keypress (GtkWidget *widget, GdkEventKey *key) } if (game_area) - { - /* keys for the playing field - key releases needed - install timeout */ - if (keytimeoutid && key->time == k.time) - gtk_timeout_remove (keytimeoutid); - if (tetrinet_key (key->keyval, key->string)) goto keyprocessed; + { /* keys for the playing field - key releases needed - install timeout */ + if (keytimeoutid && key->time == k.time) + gtk_timeout_remove (keytimeoutid); } if (gtetrinet_key(key->keyval, key->state & (GDK_MOD1_MASK | GDK_CONTROL_MASK | GDK_SHIFT_MASK))) - goto keyprocessed; + goto keyprocessed; + if (game_area && tetrinet_key (key->keyval, key->string)) goto keyprocessed; + return FALSE; keyprocessed: gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event"); diff --git a/src/misc.c b/src/misc.c index bbcddce..d4513da 100644 --- a/src/misc.c +++ b/src/misc.c @@ -239,19 +239,69 @@ void textbox_addtext (GtkTextView *textbox, unsigned char *text) /* if (bottom) adjust_bottom (textboxadj); */ } -void adjust_bottom (GtkAdjustment *adj) -{ /* FIXME: GtkTextView craps itself */ - gtk_adjustment_set_value (adj, adj->upper); +/* have to use an idle handler for the adjustment ... or the TextView goes + * syncronous ... and has bugs. + * There might be a better way to do a one shot idle handler. + * This works though */ +static GList *adj_list = NULL; + +static gboolean cb_adjust_bottom(gpointer data) +{ + GList *scan = adj_list; + + while (scan) + { + GtkTextView *tv = scan->data; + GtkTextIter iter; + + gtk_text_buffer_get_end_iter(tv->buffer, &iter); + /* Maybe want... scroll_to_iter(tv, &iter, 0.0, TRUE, 0.0, 1.0); ???? */ + gtk_text_view_scroll_to_iter(tv, &iter, 0.0, FALSE, 0.0, 0.0); + + scan = scan->next; + } + + g_list_free(adj_list); + adj_list = NULL; + return FALSE; +} + +void adjust_bottom_text_view (GtkTextView *tv) +{ + if (!g_list_find(adj_list, tv)) + { + if (!adj_list) + gtk_idle_add(cb_adjust_bottom, adj_list); + + adj_list = g_list_append(adj_list, tv); + } } char *nocolor (char *str) { - static char buf[1024], *p; - for (p = buf; *str; str ++) { - if (*str > 0x1F) *p++ = *str; - } - *p = 0; - return buf; + static GString *ret = NULL; + size_t len = strlen(str); + char *scan = NULL; + char *p = NULL; + + if (!ret) + ret = g_string_new(""); + + g_string_assign(ret, str); + + p = scan = ret->str; + while (*scan) + { + if ((signed char)*scan > 0x1F) /* high characters are ok, + * but only if it's UTF-8 -- + * just kill them for now */ + *p++ = *scan; + ++scan; + } + if (scan != p) + g_string_truncate(ret, len - (scan - p)); + + return ret->str; } GtkWidget *pixmap_label (GdkPixmap *pm, GdkBitmap *mask, char *str) diff --git a/src/misc.h b/src/misc.h index aae953a..2ded9e2 100644 --- a/src/misc.h +++ b/src/misc.h @@ -8,7 +8,7 @@ extern int randomnum (int n); extern void fdreadline (int fd, char *buf); extern void textbox_setup (void); extern void textbox_addtext (GtkTextView *textbox, unsigned char *text); -extern void adjust_bottom (GtkAdjustment *adj); +extern void adjust_bottom_text_view (GtkTextView *); extern char *nocolor (char *str); extern GtkWidget *pixmap_label (GdkPixmap *pm, GdkBitmap *mask, char *str); diff --git a/src/partyline.c b/src/partyline.c index 58511b2..5d7a5d3 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -170,7 +170,7 @@ void partyline_status (char *status) void partyline_text (char *text) { textbox_addtext (GTK_TEXT_VIEW(textbox), text); - adjust_bottom (GTK_TEXT_VIEW(textbox)->vadjustment); + adjust_bottom_text_view(GTK_TEXT_VIEW(textbox)); } void partyline_playerlist (int *numbers, char **names, char **teams, int n, char **specs, int sn) -- 2.50.1