diff --git a/linux/gtknewgame.c b/linux/gtknewgame.c index e2344c09a..deffe03b8 100644 --- a/linux/gtknewgame.c +++ b/linux/gtknewgame.c @@ -38,11 +38,11 @@ countBeforeSame( GtkWidget *widget, gpointer data ) { ItemNumPair* pair = (ItemNumPair*)data; if ( !pair->found ) { - if ( pair->item == widget ) { - pair->found = TRUE; - } else { - ++pair->index; - } + if ( pair->item == widget ) { + pair->found = TRUE; + } else { + ++pair->index; + } } } /* countBeforeSame */ @@ -77,8 +77,8 @@ nplayers_menu_select( GtkWidget* item, GtkNewGameState* state ) /* now loop through all the hboxes */ while ( low < high ) { - setChildrenSensitivity( state->playerEntries[low], enabling ); - ++low; + setChildrenSensitivity( state->playerEntries[low], enabling ); + ++low; } state->nPlayers = newNPlayers; } /* nplayers_menu_select */ @@ -95,7 +95,7 @@ size_menu_select( GtkWidget* item, GtkNewGameState* state ) gtk_container_foreach( GTK_CONTAINER(item->parent), countBeforeSame, &pair ); XP_DEBUGF( "changing nCols from %d to %d\n", state->nCols, - MAX_COLS - pair.index ); + MAX_COLS - pair.index ); state->nCols = MAX_COLS - pair.index; } /* size_menu_select */ @@ -110,34 +110,34 @@ loadCopyValues( GtkWidget* item, gpointer data ) { LoadPair* lp = (LoadPair*)data; LocalPlayer* player = lp->info; - char* entryText; + const char* entryText; switch( lp->counter ) { case 0: /* labels */ case 2: - break; + break; case 1: /* name field */ - entryText = gtk_entry_get_text( GTK_ENTRY(item) ); - player->name = copyString( MPPARM(lp->mpool) entryText ); - break; + entryText = gtk_entry_get_text( GTK_ENTRY(item) ); + player->name = copyString( MPPARM(lp->mpool) entryText ); + break; case 3: /* passwd field */ - entryText = gtk_entry_get_text( GTK_ENTRY(item) ); - player->password = copyString( MPPARM(lp->mpool) entryText ); - break; + entryText = gtk_entry_get_text( GTK_ENTRY(item) ); + player->password = copyString( MPPARM(lp->mpool) entryText ); + break; case 4: /* is Robot */ - player->isRobot = GTK_WIDGET_STATE( item ) == GTK_STATE_ACTIVE; - break; + player->isRobot = GTK_WIDGET_STATE( item ) == GTK_STATE_ACTIVE; + break; case 5: /* is local */ - player->isLocal = GTK_WIDGET_STATE( item ) == GTK_STATE_ACTIVE; - break; + player->isLocal = GTK_WIDGET_STATE( item ) == GTK_STATE_ACTIVE; + break; default: - XP_ASSERT( 0 ); + XP_ASSERT( 0 ); } ++lp->counter; } /* loadCopyValues */ static void -handle_ok( GtkWidget* widget, void* closure ) +handle_ok( GtkWidget* widget, gpointer closure ) { GtkNewGameState* state = (GtkNewGameState*)closure; CurGameInfo* gi = &state->globals->cGlobals.params->gi; @@ -150,15 +150,15 @@ handle_ok( GtkWidget* widget, void* closure ) gi->boardSize = state->nCols; /* they're the same for now */ for ( i = 0; i < state->nPlayers; ++i ) { - LocalPlayer* player = &gi->players[i]; - GtkWidget* hbox = state->playerEntries[i]; + LocalPlayer* player = &gi->players[i]; + GtkWidget* hbox = state->playerEntries[i]; - lp.info = player; - lp.counter = 0; + lp.info = player; + lp.counter = 0; - /* Read values out of the items in the hbox, which are, in order, the - name entry, passwd entry, isLocal box and isRobot box */ - gtk_container_foreach( GTK_CONTAINER(hbox), loadCopyValues, &lp ); + /* Read values out of the items in the hbox, which are, in order, the + name entry, passwd entry, isLocal box and isRobot box */ + gtk_container_foreach( GTK_CONTAINER(hbox), loadCopyValues, &lp ); } state->cancelled = XP_FALSE; @@ -223,7 +223,7 @@ makeNewGameDialog( GtkNewGameState* state ) hbox = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), gtk_label_new("Number of players"), - FALSE, TRUE, 0 ); + FALSE, TRUE, 0 ); opt = gtk_option_menu_new(); nPlayersMenu = gtk_menu_new(); @@ -232,14 +232,14 @@ makeNewGameDialog( GtkNewGameState* state ) state->nPlayers = gi->nPlayers; for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) { - char buf[2]; - snprintf( buf, 2, "%d", i+1 ); - item = make_menu_item( buf, GTK_SIGNAL_FUNC(nplayers_menu_select), - state ); - gtk_menu_append( GTK_MENU(nPlayersMenu), item ); - if ( i+1 == state->nPlayers ) { - gtk_menu_set_active( GTK_MENU(nPlayersMenu), i ); - } + char buf[2]; + snprintf( buf, 2, "%d", i+1 ); + item = make_menu_item( buf, GTK_SIGNAL_FUNC(nplayers_menu_select), + state ); + gtk_menu_append( GTK_MENU(nPlayersMenu), item ); + if ( i+1 == state->nPlayers ) { + gtk_menu_set_active( GTK_MENU(nPlayersMenu), i ); + } } gtk_option_menu_set_menu( GTK_OPTION_MENU(opt), nPlayersMenu ); @@ -250,80 +250,80 @@ makeNewGameDialog( GtkNewGameState* state ) gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) { - GtkWidget* label; - GtkWidget* nameField = gtk_entry_new(); - GtkWidget* passwdField = gtk_entry_new_with_max_length( 6 ); - GtkWidget* robotCheck = gtk_check_button_new_with_label( "robot" ); - GtkWidget* localCheck = gtk_check_button_new_with_label( "is local" ); - hbox = gtk_hbox_new( FALSE, 0 ); - state->playerEntries[i] = hbox; + GtkWidget* label; + GtkWidget* nameField = gtk_entry_new(); + GtkWidget* passwdField = gtk_entry_new_with_max_length( 6 ); + GtkWidget* robotCheck = gtk_check_button_new_with_label( "robot" ); + GtkWidget* localCheck = gtk_check_button_new_with_label( "is local" ); + hbox = gtk_hbox_new( FALSE, 0 ); + state->playerEntries[i] = hbox; - label = gtk_label_new("name:"); - gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 ); - gtk_widget_show( label ); + label = gtk_label_new("name:"); + gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 ); + gtk_widget_show( label ); - gtk_box_pack_start( GTK_BOX(hbox), nameField, FALSE, TRUE, 0 ); - gtk_widget_show( nameField ); + gtk_box_pack_start( GTK_BOX(hbox), nameField, FALSE, TRUE, 0 ); + gtk_widget_show( nameField ); - label = gtk_label_new("passwd:"); - gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 ); - gtk_widget_show( label ); + label = gtk_label_new("passwd:"); + gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 ); + gtk_widget_show( label ); - gtk_box_pack_start( GTK_BOX(hbox), passwdField, FALSE, TRUE, 0 ); - gtk_widget_show( passwdField ); + gtk_box_pack_start( GTK_BOX(hbox), passwdField, FALSE, TRUE, 0 ); + gtk_widget_show( passwdField ); - gtk_box_pack_start( GTK_BOX(hbox), robotCheck, FALSE, TRUE, 0 ); - gtk_widget_show( robotCheck ); + gtk_box_pack_start( GTK_BOX(hbox), robotCheck, FALSE, TRUE, 0 ); + gtk_widget_show( robotCheck ); - gtk_box_pack_start( GTK_BOX(hbox), localCheck, FALSE, TRUE, 0 ); - gtk_widget_show( localCheck ); + gtk_box_pack_start( GTK_BOX(hbox), localCheck, FALSE, TRUE, 0 ); + gtk_widget_show( localCheck ); - if ( i < state->nPlayers ) { - XP_Bool isSet; - gtk_entry_set_text( - GTK_ENTRY(nameField), - gi->players[i].name ); + if ( i < state->nPlayers ) { + XP_Bool isSet; + gtk_entry_set_text( + GTK_ENTRY(nameField), + gi->players[i].name ); - isSet = gi->players[i].isRobot; - gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(robotCheck), - isSet ); - XP_DEBUGF( "isRobot set to %d\n", isSet ); - isSet = gi->players[i].isLocal; - gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(localCheck), - isSet ); - XP_DEBUGF( "isLocal set to %d\n", isSet ); - } else { - char buf[10]; - snprintf( buf, sizeof(buf), "Player %d", i+1 ); - gtk_entry_set_text( GTK_ENTRY(nameField), buf ); + isSet = gi->players[i].isRobot; + gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(robotCheck), + isSet ); + XP_DEBUGF( "isRobot set to %d\n", isSet ); + isSet = gi->players[i].isLocal; + gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(localCheck), + isSet ); + XP_DEBUGF( "isLocal set to %d\n", isSet ); + } else { + char buf[10]; + snprintf( buf, sizeof(buf), "Player %d", i+1 ); + gtk_entry_set_text( GTK_ENTRY(nameField), buf ); - gtk_widget_set_sensitive( hbox, FALSE ); - gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(localCheck), - XP_TRUE ); - } - gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); - gtk_widget_show( hbox ); + gtk_widget_set_sensitive( hbox, FALSE ); + gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(localCheck), + XP_TRUE ); + } + gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); + gtk_widget_show( hbox ); } /* board size choices */ hbox = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), gtk_label_new("Board size"), - FALSE, TRUE, 0 ); + FALSE, TRUE, 0 ); opt = gtk_option_menu_new(); boardSizeMenu = gtk_menu_new(); state->nCols = gi->boardSize; for ( i = 0; i < MAX_SIZE_CHOICES; ++i ) { - char buf[10]; - XP_U16 siz = MAX_COLS - i; - snprintf( buf, sizeof(buf), "%dx%d", siz, siz ); - item = make_menu_item( buf, GTK_SIGNAL_FUNC(size_menu_select), - state ); - gtk_menu_append( GTK_MENU(boardSizeMenu), item ); - if ( siz == state->nCols ) { - gtk_menu_set_active( GTK_MENU(boardSizeMenu), i ); - } + char buf[10]; + XP_U16 siz = MAX_COLS - i; + snprintf( buf, sizeof(buf), "%dx%d", siz, siz ); + item = make_menu_item( buf, GTK_SIGNAL_FUNC(size_menu_select), + state ); + gtk_menu_append( GTK_MENU(boardSizeMenu), item ); + if ( siz == state->nCols ) { + gtk_menu_set_active( GTK_MENU(boardSizeMenu), i ); + } } gtk_option_menu_set_menu( GTK_OPTION_MENU(opt), boardSizeMenu ); @@ -331,12 +331,12 @@ makeNewGameDialog( GtkNewGameState* state ) gtk_box_pack_start( GTK_BOX(hbox), opt, FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), gtk_label_new("Dictionary: "), - FALSE, TRUE, 0 ); + FALSE, TRUE, 0 ); XP_ASSERT( gi->dictName ); gtk_box_pack_start( GTK_BOX(hbox), - gtk_label_new(gi->dictName), - FALSE, TRUE, 0 ); + gtk_label_new(gi->dictName), + FALSE, TRUE, 0 ); gtk_widget_show( hbox ); @@ -345,14 +345,16 @@ makeNewGameDialog( GtkNewGameState* state ) /* buttons at the bottom */ hbox = gtk_hbox_new( FALSE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), - makeButton( "Ok", handle_ok, state ), - FALSE, TRUE, 0 ); + makeButton( "Ok", GTK_SIGNAL_FUNC(handle_ok) , state ), + FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), - makeButton( "Revert", handle_revert, state ), - FALSE, TRUE, 0 ); + makeButton( "Revert", GTK_SIGNAL_FUNC(handle_revert), + state ), + FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), - makeButton( "Cancel", handle_cancel, state ), - FALSE, TRUE, 0 ); + makeButton( "Cancel", GTK_SIGNAL_FUNC(handle_cancel), + state ), + FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); @@ -372,65 +374,13 @@ newGameDialog( GtkAppGlobals* globals/* , GtkGameInfo* gameInfo */ ) /* returns when button handler calls gtk_main_quit */ do { - GtkWidget* dialog = makeNewGameDialog( &state ); - state.revert = FALSE; - gtk_main(); - gtk_widget_destroy( dialog ); + GtkWidget* dialog = makeNewGameDialog( &state ); + state.revert = FALSE; + gtk_main(); + gtk_widget_destroy( dialog ); } while ( state.revert ); return !state.cancelled; } /* newGameDialog */ -#if 0 -gint -gtkask( GtkAppGlobals* globals, gchar *message, gint numButtons, - char* button1, ... ) -{ - GtkWidget* dialog; - GtkWidget* label; - GtkWidget* button; - short i; - gboolean* results = g_malloc( numButtons * sizeof(results[0]) ); - char** butList = &button1; - - /* Create the widgets */ - dialog = gtk_dialog_new(); - gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE ); - - label = gtk_label_new( message ); - - for ( i = 0; i < numButtons; ++i ) { - button = gtk_button_new_with_label( *butList ); - - results[i] = 0; - gtk_signal_connect( GTK_OBJECT( button ), "clicked", - GTK_SIGNAL_FUNC(button_event), &results[i] ); - - gtk_container_add( GTK_CONTAINER( GTK_DIALOG(dialog)->action_area), - button ); - - ++butList; - } - - /* Add the label, and show everything we've added to the dialog. */ - gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox), - label); - gtk_widget_show_all (dialog); - - /* returns when button handler calls gtk_main_quit */ - gtk_main(); - - gtk_widget_destroy( dialog ); - - for ( i = 0; i < numButtons; ++i ) { - if ( results[i] ) { - break; - } - } - g_free( results ); - return i; - } /* gtkask */ - -#endif - #endif /* PLATFORM_GTK */ diff --git a/linux/gtkntilesask.c b/linux/gtkntilesask.c index 30d01d666..ff04d453e 100644 --- a/linux/gtkntilesask.c +++ b/linux/gtkntilesask.c @@ -57,7 +57,8 @@ askNTiles( GtkAppGlobals* globals, XP_U16 max, XP_U16 deflt ) button = gtk_button_new_with_label( buf ); gtk_box_pack_start( GTK_BOX(hbox), button, FALSE, TRUE, 0 ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", button_event, + gtk_signal_connect( GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(button_event), &results[i] ); gtk_widget_show( button ); } @@ -67,8 +68,10 @@ askNTiles( GtkAppGlobals* globals, XP_U16 max, XP_U16 deflt ) sprintf( defbuf, "Default (%d)", deflt ); button = gtk_button_new_with_label( defbuf ); - gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->vbox), button, FALSE, TRUE, 0 ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", button_event, + gtk_box_pack_start( GTK_BOX(GTK_DIALOG(dialog)->vbox), button, FALSE, + TRUE, 0 ); + gtk_signal_connect( GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(button_event), &results[deflt-1] ); gtk_widget_show( button ); diff --git a/linux/gtkpasswdask.c b/linux/gtkpasswdask.c index 89e939fbf..a15017932 100644 --- a/linux/gtkpasswdask.c +++ b/linux/gtkpasswdask.c @@ -65,11 +65,12 @@ gtkpasswdask( const char* name, char* outbuf, XP_U16* buflen ) hbox = gtk_hbox_new(FALSE, 0); for ( i = 0; i < 2; ++i ) { - GtkWidget* button = gtk_button_new_with_label( labels[i] ); - gtk_signal_connect( GTK_OBJECT(button), "clicked", button_event, - boolps[i] ); - gtk_box_pack_start( GTK_BOX(hbox), button, FALSE, TRUE, 0 ); - gtk_widget_show( button ); + GtkWidget* button = gtk_button_new_with_label( labels[i] ); + gtk_signal_connect( GTK_OBJECT(button), "clicked", + GTK_SIGNAL_FUNC(button_event), + boolps[i] ); + gtk_box_pack_start( GTK_BOX(hbox), button, FALSE, TRUE, 0 ); + gtk_widget_show( button ); } gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); @@ -81,9 +82,9 @@ gtkpasswdask( const char* name, char* outbuf, XP_U16* buflen ) gtk_main(); if ( ok ) { - char* text = gtk_entry_get_text( GTK_ENTRY(entry) ); - strncpy( outbuf, text, *buflen ); - *buflen = strlen(outbuf); + const char* text = gtk_entry_get_text( GTK_ENTRY(entry) ); + strncpy( outbuf, text, *buflen ); + *buflen = strlen(outbuf); } gtk_widget_destroy( dialog );