From 8628293739f7f3a1a5152eb1e6036fef5bdfcdf1 Mon Sep 17 00:00:00 2001 From: Dani Carbonell Date: Fri, 10 Jan 2003 18:30:08 +0000 Subject: [PATCH] hide the window only if it really existed (fixes the -c bug). 2003-01-10 Dani Carbonell * src/dialogs.c (connectdialog_connected): hide the window only if it really existed (fixes the -c bug). * src/fields.c (fields_gmsginputadd): this function was useless, removed. (fields_gmsginputback): likewise * src/fields.h: removed those two function's declarations. * src/gtetrinet.c (switch_focus): new function, will handle the notebook's tab switching, sending focus where it should be. (gtetrinet_key): function cleaned. * src/gtetrinet.h: added the function declaration. * src/partyline.c (partyline_entryfocus): now it clears all the text in the partyline's gtk_entry. * src/tetrinet.c (tetrinet_endgame): now it properly closes the field's gtk_entry, if it's open when the game ends. (tetrinet_inmessage): now it properly takes into account that a player has left the game, so no one can attack him after he's gone. * src/winlist.c (winlist_focus): new function that will focus the winlist when the user switches to that tab. * src/winlist.h: added the function declaration. --- ChangeLog | 30 ++++++++++++++++++++++++++++++ src/dialogs.c | 2 +- src/fields.c | 22 ---------------------- src/fields.h | 2 -- src/gtetrinet.c | 34 ++++++++++++++++++++++++++-------- src/gtetrinet.h | 1 + src/partyline.c | 12 ++++++------ src/tetrinet.c | 12 +++++++++--- src/winlist.c | 5 +++++ src/winlist.h | 1 + 10 files changed, 79 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2a4bfcc..16788d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +2003-01-10 Dani Carbonell + + * src/dialogs.c (connectdialog_connected): hide the window only if + it really existed (fixes the -c bug). + + * src/fields.c (fields_gmsginputadd): this function was useless, + removed. + (fields_gmsginputback): likewise + + * src/fields.h: removed those two function's declarations. + + * src/gtetrinet.c (switch_focus): new function, will handle the + notebook's tab switching, sending focus where it should be. + (gtetrinet_key): function cleaned. + + * src/gtetrinet.h: added the function declaration. + + * src/partyline.c (partyline_entryfocus): now it clears all the text + in the partyline's gtk_entry. + + * src/tetrinet.c (tetrinet_endgame): now it properly closes the field's + gtk_entry, if it's open when the game ends. + (tetrinet_inmessage): now it properly takes into account that a + player has left the game, so no one can attack him after he's gone. + + * src/winlist.c (winlist_focus): new function that will focus the + winlist when the user switches to that tab. + + * src/winlist.h: added the function declaration. + 2003-01-08 Jordi Mallach * configure.in (AC_OUTPUT): sigh, I suck. Remove gtetrinet.desktop. diff --git a/src/dialogs.c b/src/dialogs.c index 81fc867..993a9f3 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -275,7 +275,7 @@ void connectdialog_tetrifasttoggle (GtkWidget *widget) void connectdialog_connected (void) { - gtk_widget_destroy (connectdialog); + if (connectdialog != NULL) gtk_widget_destroy (connectdialog); } void connectdialog_destroy (void) diff --git a/src/fields.c b/src/fields.c index 4004296..7f56a35 100644 --- a/src/fields.c +++ b/src/fields.c @@ -596,15 +596,6 @@ void fields_gmsginputactivate (int t) { /* do nothing */; } } -void fields_gmsginputadd (char *c) -{ - gchar *utf8_c = g_locale_to_utf8 (c, -1, NULL, NULL, NULL); - gtk_entry_append_text (GTK_ENTRY(gmsginput), utf8_c); - gtk_entry_set_position (GTK_ENTRY(gmsginput), - strlen(gtk_entry_get_text(GTK_ENTRY(gmsginput)))); - g_free (utf8_c); -} - void gmsginput_activate (GtkEntry *entry, gpointer data) { gchar *locale_s, buf[256]; @@ -638,19 +629,6 @@ void gmsginput_activate (GtkEntry *entry, gpointer data) gmsgstate = 0; } -void fields_gmsginputback (void) -{ - char buf[256]; - gchar *prev; - - GTET_O_STRCPY (buf, gtk_entry_get_text(GTK_ENTRY(gmsginput))); - if (strlen(buf) == 0) return; - prev = g_utf8_prev_char (&buf[strlen(buf)]); - *prev = 0; - gtk_entry_set_text (GTK_ENTRY(gmsginput), buf); - gtk_entry_set_position (GTK_ENTRY(gmsginput), strlen(buf)); -} - const char *fields_gmsginputtext (void) { return gtk_entry_get_text (GTK_ENTRY(gmsginput)); diff --git a/src/fields.h b/src/fields.h index 80f3b56..b565656 100644 --- a/src/fields.h +++ b/src/fields.h @@ -21,6 +21,4 @@ extern void fields_gmsgclear (void); extern void fields_gmsginput (int i); extern void fields_gmsginputclear (void); extern void fields_gmsginputactivate (int i); -extern void fields_gmsginputadd (char *c); -extern void fields_gmsginputback (void); extern const char *fields_gmsginputtext (void); diff --git a/src/gtetrinet.c b/src/gtetrinet.c index 647b27b..2518704 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -49,6 +49,10 @@ static GtkWidget *pixmapdata_label (char **d, char *str); static int gtetrinet_key (int keyval, int mod); gint keypress (GtkWidget *widget, GdkEventKey *key); gint keyrelease (GtkWidget *widget, GdkEventKey *key); +void switch_focus (GtkNotebook *notebook, + GtkNotebookPage *page, + guint page_num, + gpointer user_data); static GtkWidget *app, *pfields, *pparty, *pwinlist; static GtkWidget *winlistwidget, *partywidget, *fieldswidget; @@ -218,8 +222,8 @@ int main (int argc, char *argv[]) gtk_notebook_append_page (GTK_NOTEBOOK(notebook), pwinlist, label); /* add signal to focus the text entry when switching to the partyline page*/ - g_signal_connect_after(G_OBJECT (notebook), "switch_page", - GTK_SIGNAL_FUNC (partyline_switch_entryfocus), + g_signal_connect_after(G_OBJECT (notebook), "switch-page", + GTK_SIGNAL_FUNC (switch_focus), NULL); gtk_widget_show (notebook); @@ -403,12 +407,9 @@ static int gtetrinet_key (int keyval, int mod) switch (keyval) { - case GDK_1: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 0); break; - case GDK_2: - gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 1); - /* partyline_entryfocus(); */ - break; - case GDK_3: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 2); break; + case GDK_1: gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 0); break; + case GDK_2: gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 1); break; + case GDK_3: gtk_notebook_set_current_page (GTK_NOTEBOOK(notebook), 2); break; default: return FALSE; } @@ -517,3 +518,20 @@ void unblock_keyboard_signal (void) { g_signal_handler_unblock (app, keypress_signal); } + +void switch_focus (GtkNotebook *notebook, + GtkNotebookPage *page, + guint page_num, + gpointer user_data) +{ + if (connected) + switch (page_num) + { + case 0: + if (gmsgstate) fields_gmsginputactivate (1); + else partyline_entryfocus (); + break; + case 1: partyline_entryfocus (); break; + case 2: winlist_focus (); break; + } +} diff --git a/src/gtetrinet.h b/src/gtetrinet.h index 8cde9d3..f73f4f2 100644 --- a/src/gtetrinet.h +++ b/src/gtetrinet.h @@ -14,3 +14,4 @@ extern void move_current_page_to_window (void); extern void show_fields_page (void); extern void show_partyline_page (void); void unblock_keyboard_signal (void); +gint get_current_notebook_page (void); diff --git a/src/partyline.c b/src/partyline.c index 79e33d1..e8dae97 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -249,12 +249,12 @@ void partyline_playerlist (int *numbers, char **names, char **teams, int n, char void partyline_entryfocus (void) { - if (connected) gtk_widget_grab_focus (entrybox); -} - -void partyline_switch_entryfocus (void) -{ /* FIXME: should only grab when in right notebook */ - if (connected) gtk_widget_grab_focus (entrybox); + if (connected) + { + gtk_entry_set_text (GTK_ENTRY(entrybox), ""); + gtk_entry_set_position (GTK_ENTRY(entrybox), 0); + gtk_widget_grab_focus (entrybox); + } } void textentry (GtkWidget *widget) diff --git a/src/tetrinet.c b/src/tetrinet.c index ca5198c..919cd63 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -313,6 +313,7 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) /* update playerlist */ playernames[pnum][0] = 0; teamnames[pnum][0] = 0; + playerplaying[pnum] = 0; playerlistupdate (); /* update fields display */ fieldslabelupdate (); @@ -347,6 +348,7 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) message is received (see above) */ playernames[pnum][0] = 0; + playerplaying[pnum] = 0; } break; case IN_TEAM: @@ -1333,9 +1335,13 @@ void tetrinet_endgame (void) fields_setlevel (-1); fields_setactivelevel (-1); fields_setspeciallabel (NULL); - gmsgstate = 0; - fields_gmsginput (FALSE); - fields_gmsginputclear (); + if (gmsgstate) + { + gmsgstate = 0; + fields_gmsginput (FALSE); + fields_gmsginputclear (); + unblock_keyboard_signal (); + } } void tetrinet_updatelevels (void) diff --git a/src/winlist.c b/src/winlist.c index 3e5cd00..a7466b3 100644 --- a/src/winlist.c +++ b/src/winlist.c @@ -87,3 +87,8 @@ void winlist_additem (int team, char *name, int score) -1); g_free (name_utf8); } + +void winlist_focus (void) +{ + gtk_widget_grab_focus (winlist); +} diff --git a/src/winlist.h b/src/winlist.h index 6992ea2..736480d 100644 --- a/src/winlist.h +++ b/src/winlist.h @@ -2,3 +2,4 @@ GtkWidget *winlist_page_new (void); void winlist_clear (void); void winlist_additem (int team, char *name, int score); +void winlist_focus (void); -- 2.50.1