コード例 #1
0
ファイル: gnmenu.c プロジェクト: RandomCore/nethack-de
GtkWidget*
ghack_init_menu_window (void)
{
    GtkWidget *menuWin = NULL;
    GtkWidget *parent = ghack_get_main_window ();

    menuWin = gnome_dialog_new("GnomeHack", GNOME_STOCK_BUTTON_OK, 
		    GNOME_STOCK_BUTTON_CANCEL, NULL);
    
    gnome_dialog_set_default( GNOME_DIALOG(menuWin), 0);
    gtk_signal_connect(GTK_OBJECT(menuWin), "destroy",
		    GTK_SIGNAL_FUNC(ghack_menu_destroy),
		    NULL);

    gtk_signal_connect (GTK_OBJECT (menuWin), "delete_event",
			GTK_SIGNAL_FUNC (ghack_menu_hide),
			NULL);
          
    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_clear",
		    GTK_SIGNAL_FUNC(ghack_menu_window_clear),
		    NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_display",
                       GTK_SIGNAL_FUNC(ghack_menu_window_display),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_start_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_start_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_add_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_add_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_end_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_end_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_select_menu",
                       GTK_SIGNAL_FUNC(ghack_menu_window_select_menu),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "ghack_putstr",
                       GTK_SIGNAL_FUNC(ghack_menu_window_put_string),
                       NULL);

    gtk_signal_connect(GTK_OBJECT(menuWin), "key_press_event",
                       GTK_SIGNAL_FUNC(ghack_menu_window_key),
                       NULL);

    /* Center the dialog over parent */
    g_assert (parent != NULL);
    g_assert (menuWin != NULL);
    g_assert (GTK_IS_WINDOW (parent));
    g_assert (GNOME_IS_DIALOG (menuWin));
    gnome_dialog_set_parent (GNOME_DIALOG (menuWin), GTK_WINDOW (parent));
    
    return menuWin;
}
コード例 #2
0
ファイル: gnbind.c プロジェクト: Agyar/NetHack
/*
char yn_function(const char *ques, const char *choices, char default)
                -- Print a prompt made up of ques, choices and default.
                   Read a single character response that is contained in
                   choices or default.  If choices is NULL, all possible
                   inputs are accepted and returned.  This overrides
                   everything else.  The choices are expected to be in
                   lower case.  Entering ESC always maps to 'q', or 'n',
                   in that order, if present in choices, otherwise it maps
                   to default.  Entering any other quit character (SPACE,
                   RETURN, NEWLINE) maps to default.
                -- If the choices string contains ESC, then anything after
                   it is an acceptable response, but the ESC and whatever
                   follows is not included in the prompt.
                -- If the choices string contains a '#' then accept a count.
                   Place this value in the global "yn_number" and return '#'.
                -- This uses the top line in the tty window-port, other
                   ports might use a popup.
*/
char gnome_yn_function(const char *question, const char *choices,
		CHAR_P def)
{
    int ch;
    int result=-1;
    char message[BUFSZ];
    char yn_esc_map='\033';
    GtkWidget *mainWnd = ghack_get_main_window();
    
    
    if (choices) {
	char *cb, choicebuf[QBUFSZ];
	Strcpy(choicebuf, choices);
	if ((cb = index(choicebuf, '\033')) != 0) {
	    /* anything beyond <esc> is hidden */
	    *cb = '\0';
	}
	sprintf(message, "%s [%s] ", question, choicebuf);
	if (def) sprintf(eos(message), "(%c) ", def);
	/* escape maps to 'q' or 'n' or default, in that order */
	yn_esc_map = (index(choices, 'q') ? 'q' :
		 (index(choices, 'n') ? 'n' : def));
    } else {
	Strcpy(message, question);
    }
    
    
    gnome_putstr(WIN_MESSAGE, ATR_BOLD, message);
    if (mainWnd != NULL && choices && !index(choices,ch)) {
	return(ghack_yes_no_dialog( question, choices, def));
    }

    /* Only here if main window is not present */
    while (result<0) {
	ch=gnome_nhgetch();
	if (ch=='\033') {
	    result=yn_esc_map;
	} else if (choices && !index(choices,ch)) {
	    /* FYI: ch==-115 is for KP_ENTER */
	    if (def && (ch==' ' || ch=='\r' || ch=='\n' || ch==-115)) {
		result=def;
	    } else {
		gnome_nhbell();
		/* and try again... */
	    }
	} else {
	    result=ch;
	}
    }
    return result;
}
コード例 #3
0
ファイル: gnmain.c プロジェクト: chasonr/unnethack-i18n
void ghack_save_game_cb(GtkWidget *widget, gpointer data)
{
    GtkWidget *box;
    box = gnome_message_box_new(_("Quit and save the current game?"),
                                GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES,
                                GNOME_STOCK_BUTTON_NO, NULL);
    gnome_dialog_set_default( GNOME_DIALOG(box), 1);
    gnome_dialog_set_parent (GNOME_DIALOG (box),
                             GTK_WINDOW (ghack_get_main_window ()) );
    gnome_dialog_set_accelerator (GNOME_DIALOG(box), 1, 'n', 0);
    gnome_dialog_set_accelerator (GNOME_DIALOG(box), 0, 'y', 0);

    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
    gtk_signal_connect( GTK_OBJECT(box), "clicked",
                        (GtkSignalFunc)ghack_save_game, NULL);
    gtk_widget_show(box);
}
コード例 #4
0
ファイル: gnaskstr.c プロジェクト: vaLinBSD/nethack
int ghack_ask_string_dialog(const char *szMessageStr,
                            const char *szDefaultStr, const char *szTitleStr,
                            char *buffer)
{
    int i;
    GtkWidget* dialog;
    gchar   *user_text = NULL;

    dialog = gnome_request_dialog(FALSE, szMessageStr,
                                  szDefaultStr, 0,
                                  ghack_ask_string_callback,
                                  &user_text, NULL);
    g_assert(dialog != NULL);

    gtk_window_set_title(GTK_WINDOW(dialog), szTitleStr);

    gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
    gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
    gnome_dialog_set_parent (GNOME_DIALOG (dialog),
                             GTK_WINDOW (ghack_get_main_window ()) );

    i = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));

    /* Quit */
    if ( i != 0 || user_text == NULL ) {
        if (user_text)
            g_free(user_text);
        return -1;
    }

    if ( *user_text == 0 ) {
        g_free(user_text);
        return -1;
    }

    g_assert(strlen(user_text) > 0);
    strcpy (buffer, user_text);
    g_free(user_text);
    return 0;
}
コード例 #5
0
ファイル: gnbind.c プロジェクト: Agyar/NetHack
/* Display the file named str.  Complain about missing files
                   iff complain is TRUE.
*/
void gnome_display_file(const char *filename,BOOLEAN_P must_exist)
{
	/* Strange -- for some reason it makes us create a new text window
	 * instead of reusing any existing ones -- perhaps we can work out
	 * some way to reuse stuff -- but for now just make and destroy new
	 * ones each time */
        
	dlb *f;
       
        f = dlb_fopen(filename, "r");
        if (!f) {
	  if (must_exist) {
	    GtkWidget *box;
            char message[90];
            sprintf(message, "Warning! Could not find file: %s\n",filename);

	    box = gnome_message_box_new (_(message),
		    GNOME_MESSAGE_BOX_ERROR,
		    GNOME_STOCK_BUTTON_OK,
		    NULL);
	    gnome_dialog_set_default( GNOME_DIALOG(box), 0);
	    gnome_dialog_set_parent (GNOME_DIALOG (box), 
		    GTK_WINDOW (ghack_get_main_window ()) );
	    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
	    gtk_widget_show (box);
	  }
        }
	else {
    	  GtkWidget *txtwin, *gless, *frametxt;
#define LLEN 128
	  char line[LLEN], *textlines;
	  int num_lines, charcount;

	  txtwin = gnome_dialog_new("Text Window", GNOME_STOCK_BUTTON_OK,
				    NULL);
          gtk_widget_set_usize(GTK_WIDGET(txtwin), 500, 400);
          gtk_window_set_policy(GTK_WINDOW(txtwin), TRUE, TRUE, FALSE);
          gtk_window_set_title(GTK_WINDOW(txtwin), "Text Window");
	  gnome_dialog_set_default( GNOME_DIALOG(txtwin), 0);
	  gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE);
	  frametxt = gtk_frame_new ("");
	  gtk_widget_show (frametxt);

	  /*
	   * Count the number of lines and characters in the file.
	   */
	  num_lines = 0;
	  charcount = 1;
	  while (dlb_fgets(line, LLEN, f)) {
	    num_lines++;
	    charcount += strlen(line);
	  }
	  (void) dlb_fclose(f);
	  
	  /* Ignore empty files */
	  if (num_lines == 0) return;

	  /*
	   * Re-open the file and read the data into a buffer.  
	   */
	  textlines = (char *) alloc((unsigned int) charcount);
	  textlines[0] = '\0';
	  f = dlb_fopen( filename, RDTMODE);

	  while (dlb_fgets(line, LLEN, f)) {
	    (void) strcat(textlines, line);
	  }
	  (void) dlb_fclose(f);

	  gless = gnome_less_new ();
	  gnome_less_show_string (GNOME_LESS (gless), textlines);
	  gtk_container_add (GTK_CONTAINER (frametxt), gless);
          gtk_box_pack_start(GTK_BOX (GNOME_DIALOG (txtwin)->vbox), frametxt,
                             TRUE, TRUE, 0);
	  gtk_widget_show_all( txtwin);
	  gtk_window_set_modal( GTK_WINDOW(txtwin), TRUE);
	  gnome_dialog_set_parent (GNOME_DIALOG (txtwin), 
		  GTK_WINDOW (ghack_get_main_window ()) );
	  gnome_dialog_run_and_close (GNOME_DIALOG (txtwin));
	  free(textlines);
        }
}
コード例 #6
0
ファイル: gnopts.c プロジェクト: BarclayII/slashem-up
void
ghack_settings_dialog()
{
    int i;
    static GtkWidget* dialog;
    static GtkWidget* swin;
    static GtkWidget* frame1;

    dialog = gnome_dialog_new (_("GnomeHack Settings"),
			    GNOME_STOCK_BUTTON_OK,
			    GNOME_STOCK_BUTTON_CANCEL,
			    NULL);
    gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE);
    gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
		      GTK_SIGNAL_FUNC (opt_sel_key_hit), tilesets );

    frame1 = gtk_frame_new (_("Choose one of the following tilesets:"));
    gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1);
    gtk_widget_show (frame1);
    gtk_container_border_width (GTK_CONTAINER (frame1), 3);

    swin = gtk_scrolled_window_new (NULL, NULL);
    clist = gtk_clist_new (2);
    gtk_clist_column_titles_hide (GTK_CLIST (clist));
    gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180);
    gtk_container_add (GTK_CONTAINER (swin), clist);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
	    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    gtk_signal_connect (GTK_OBJECT (clist), "select_row",
			GTK_SIGNAL_FUNC (opt_sel_row_selected), NULL );

    gtk_container_add (GTK_CONTAINER (frame1), swin);
    gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1);

    /* Add the tilesets into the list here... */
    for (i=0; i < no_tilesets; i++) {
	    gchar accelBuf[BUFSZ];
	    const char *text[3]={accelBuf, tilesets[i].name,NULL};
	    if ((tilesets[i].flags & ~TILESET_TRANSPARENT) != 0)
		continue;		/* Unsupported flag set */
	    sprintf( accelBuf, "%c ", tolower(tilesets[i].name[0]));
	    gtk_clist_insert (GTK_CLIST (clist), i, (char**)text);
    }


    gtk_clist_columns_autosize (GTK_CLIST (clist));
    gtk_widget_show_all (swin);

    /* Center the dialog over over parent */
    gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
    gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
    gnome_dialog_set_parent (GNOME_DIALOG (dialog),
	    GTK_WINDOW (ghack_get_main_window ()) );

    /* Run the dialog -- returning whichever button was pressed */
    i = gnome_dialog_run (GNOME_DIALOG (dialog));
    gnome_dialog_close (GNOME_DIALOG (dialog));

    /* They hit Quit or error */
    if (i != 0 ) {
	return;
    }
    if (gn_tileset < no_tilesets) {
	    if (tilesets[gn_tileset].file[0] != '/') {
		char *path;
		path = (char *)alloc(strlen(TILESETDIR) +
		  strlen(tilesets[gn_tileset].file) + 2);
		sprintf(path, TILESETDIR "/%s", tilesets[gn_tileset].file);
		ghack_free_glyphs();
		if (ghack_init_glyphs(path))
			  g_error ("ERROR:  Could not initialize glyphs.\n");
		free(path);
	    }
	    else {
		ghack_free_glyphs();
		if (ghack_init_glyphs(tilesets[gn_tileset].file))
			  g_error ("ERROR:  Could not initialize glyphs.\n");
	    }
	    ghack_reinit_map_window();
    } else {
	    /* This shouldn't happen */
	    g_warning("This shouldn't happen\n");
    }
}
コード例 #7
0
ファイル: gnplayer.c プロジェクト: Agyar/NetHack
int
ghack_player_sel_dialog(const char** choices,
			const gchar* title,
			const gchar* prompt)
{
    int i;
    static GtkWidget* dialog;
    static GtkWidget* swin;
    static GtkWidget* frame1;

    dialog = gnome_dialog_new(title,
			    GNOME_STOCK_BUTTON_OK,
			    _("Random"),
			    GNOME_STOCK_BUTTON_CANCEL,
			    NULL);
    gnome_dialog_close_hides (GNOME_DIALOG (dialog), FALSE);
    gtk_signal_connect (GTK_OBJECT (dialog), "key_press_event",
                      GTK_SIGNAL_FUNC (player_sel_key_hit), choices );

    frame1 = gtk_frame_new(prompt);
    gtk_object_set_data (GTK_OBJECT (dialog), "frame1", frame1);
    gtk_widget_show (frame1);
    gtk_container_border_width (GTK_CONTAINER (frame1), 3);

    swin = gtk_scrolled_window_new (NULL, NULL);
    clist = gtk_clist_new (2);
    gtk_clist_column_titles_hide (GTK_CLIST (clist));
    gtk_widget_set_usize (GTK_WIDGET (clist), 100, 180);
    gtk_container_add (GTK_CONTAINER (swin), clist);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
	    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    gtk_signal_connect (GTK_OBJECT (clist), "select_row",
			GTK_SIGNAL_FUNC (player_sel_row_selected), NULL );

    gtk_container_add (GTK_CONTAINER (frame1), swin);
    gtk_box_pack_start_defaults (GTK_BOX (GNOME_DIALOG (dialog)->vbox), frame1);

    /* Add the roles into the list here... */
    for (i=0; choices[i]; i++) {
	    gchar accelBuf[BUFSZ];
	    const char *text[3]={accelBuf, choices[i],NULL};
	    sprintf( accelBuf, "%c ", tolower(choices[i][0]));
	    gtk_clist_insert (GTK_CLIST (clist), i, (char**)text);
    }

    gtk_clist_columns_autosize (GTK_CLIST (clist));
    gtk_widget_show_all (swin);

    /* Center the dialog over over parent */
    gnome_dialog_set_default( GNOME_DIALOG(dialog), 0);
    gtk_window_set_modal( GTK_WINDOW(dialog), TRUE);
    gnome_dialog_set_parent (GNOME_DIALOG (dialog),
	    GTK_WINDOW (ghack_get_main_window ()) );

    /* Run the dialog -- returning whichever button was pressed */
    i = gnome_dialog_run_and_close(GNOME_DIALOG(dialog));

    /* Quit on button 2 or error */
    if (i < 0  || i > 1) {
	return(ROLE_NONE);
    }
    /* Random is button 1*/
    if (i == 1 ) {
	return(ROLE_RANDOM);
    }
    return ( role_number);
}
コード例 #8
0
ファイル: gnmenu.c プロジェクト: RandomCore/nethack-de
int
ghack_menu_ext_cmd(void)
{
    int n;
    GtkWidget* dialog;
    GtkWidget* swin;
    GtkWidget* frame1;
    GtkWidget* clist;
    extMenu info;

    dialog = gnome_dialog_new("Extended Commands",
			      GNOME_STOCK_BUTTON_OK,
			      GNOME_STOCK_BUTTON_CANCEL,
			      NULL);
    gnome_dialog_close_hides(GNOME_DIALOG(dialog), FALSE);
    gtk_signal_connect(GTK_OBJECT(dialog), "key_press_event",
		       GTK_SIGNAL_FUNC(ghack_ext_key_hit), &info);

    frame1 = gtk_frame_new("Make your selection");
    gtk_object_set_data(GTK_OBJECT(dialog), "frame1", frame1);
    gtk_widget_show(frame1);
    gtk_container_border_width(GTK_CONTAINER(frame1), 3);

    swin = gtk_scrolled_window_new(NULL, NULL);
    clist = gtk_clist_new(2);
    gtk_object_set_data(GTK_OBJECT(dialog), "clist", clist);
    gtk_widget_set_usize(clist, 500, 400);
    gtk_container_add(GTK_CONTAINER(swin), clist);
    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swin),
				   GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);

    gtk_signal_connect(GTK_OBJECT(clist), "select_row",
		       GTK_SIGNAL_FUNC(ghack_menu_row_selected), NULL);

    gtk_container_add(GTK_CONTAINER(frame1), swin);
    gtk_box_pack_start_defaults(GTK_BOX(GNOME_DIALOG(dialog)->vbox), frame1);

    /* Add the extended commands into the list here... */
    for (n = 0; extcmdlist[n].ef_txt; ++n) {
	const char *text[3]={extcmdlist[n].ef_txt,extcmdlist[n].ef_desc,NULL};
	gtk_clist_insert(GTK_CLIST(clist), n, (char**) text);
    }

    /* fill in starting info fields */
    info.curItem = -1;
    info.numRows = n;
    info.charIdx = 0;
    info.lastTime = 0;

    gtk_clist_columns_autosize(GTK_CLIST(clist));
    gtk_widget_show_all(swin);

    /* Center the dialog over over parent */
    gnome_dialog_set_default(GNOME_DIALOG(dialog), 0);
    gtk_window_set_modal(GTK_WINDOW(dialog), TRUE);
    gnome_dialog_set_parent(GNOME_DIALOG(dialog),
			    GTK_WINDOW(ghack_get_main_window()));

    /* Run the dialog -- returning whichever button was pressed */
    n = gnome_dialog_run_and_close(GNOME_DIALOG(dialog));

    /* Quit on button 2 or error */
    return (n != 0) ? -1 : info.curItem;
}
コード例 #9
0
ファイル: gnyesno.c プロジェクト: Agyar/NetHack
int ghack_yes_no_dialog( const char *question, 
		      const char *choices, int def)
{
    int i=0, ret;
    gchar button_name[BUFSZ];
    GtkWidget *box;
    GtkWidget* mainWnd=NULL;

    box = gnome_message_box_new ( question, GNOME_MESSAGE_BOX_QUESTION, NULL);
    /* add buttons for each choice */
    if (!strcmp(GNOME_STOCK_BUTTON_OK, choices)) {
	gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_OK);
	gnome_dialog_set_default( GNOME_DIALOG(box), 0);
	gnome_dialog_set_accelerator( GNOME_DIALOG(box), 0, 'o', 0);
#if 0
	g_print("Setting accelerator '%c' for button %d\n", 'o', 0);
#endif
    }
    else {
	for( ; choices[i]!='\0'; i++) {
	    if (choices[i]=='y') {
		sprintf( button_name, GNOME_STOCK_BUTTON_YES);
	    }
	    else if (choices[i]=='n') {
		sprintf( button_name, GNOME_STOCK_BUTTON_NO);
	    }
	    else if (choices[i] == 'q') {
	        sprintf( button_name, "Quit");
	    } else {
		sprintf( button_name, "%c", choices[i]);
	    }
	    if (def==choices[i])
		gnome_dialog_set_default( GNOME_DIALOG(box), i);
	    gnome_dialog_append_button ( GNOME_DIALOG(box), button_name);
	    gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
#if 0
	    g_print("Setting accelerator '%c' for button %d\n", choices[i], i);
#endif
	}
    }
#if 0
    /* Perhaps add in a quit game button, like this... */
    gnome_dialog_append_button ( GNOME_DIALOG(box), GNOME_STOCK_BUTTON_CLOSE);
    gnome_dialog_set_accelerator( GNOME_DIALOG(box), i, choices[i], 0);
    g_print("Setting accelerator '%c' for button %d\n", 'Q', i);
#endif

    gnome_dialog_set_close(GNOME_DIALOG (box), TRUE);
    mainWnd = ghack_get_main_window ();
    gtk_window_set_modal( GTK_WINDOW(box), TRUE);
    gtk_window_set_title( GTK_WINDOW(box), "GnomeHack");
    if ( mainWnd != NULL ) {
	gnome_dialog_set_parent (GNOME_DIALOG (box), 
		GTK_WINDOW ( mainWnd) );
    }

    ret=gnome_dialog_run_and_close ( GNOME_DIALOG (box));
    
#if 0
    g_print("You selected button %d\n", ret);
#endif
    
    if (ret==-1)
	return( '\033');
    else
	return( choices[ret]);
}