+2002-12-02 James Antill <james@and.org>
+
+ * 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 <jordi@sindominio.net>
* AUTHORS: added Gerfried.
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)
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)
}
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");
/* 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)
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);
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)