void capture_filter() { GtkWidget *dialog; GtkWidget *_hbox, *filter_label, *filter_entry, *filter_button; dialog = gnome_dialog_new(_("FilterString"),_("OK"),NULL,NULL); _hbox = gtk_hbox_new(FALSE,0); gtk_container_set_border_width(GTK_CONTAINER(_hbox), 5); filter_label = gtk_label_new("Filter String: "); filter_entry = gtk_entry_new(); filter_button = gtk_button_new_with_label("Save"); gtk_box_pack_start(GTK_BOX(_hbox),filter_label,FALSE,FALSE,5); gtk_box_pack_start(GTK_BOX(_hbox),filter_entry,TRUE,TRUE,6); gtk_box_pack_start(GTK_BOX(_hbox),filter_button,FALSE,FALSE,5); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),_hbox,TRUE,TRUE,0); g_signal_connect(GTK_OBJECT(filter_button),"clicked",GTK_SIGNAL_FUNC(get_filter_str),filter_entry); gtk_signal_connect(GTK_OBJECT(dialog),"clicked",GTK_SIGNAL_FUNC(dialog_ok),&dialog); gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); gtk_widget_show(filter_label); gtk_widget_show(filter_entry); gtk_widget_show(filter_button); gtk_widget_show(_hbox); gtk_widget_show(dialog); gnome_dialog_set_parent(GNOME_DIALOG(dialog),GTK_WINDOW(app)); }
void ifselect(GtkWidget *widget,gpointer data) { gint i = 0; GtkWidget *dialog; GtkWidget *_hbox; GtkWidget *label; GList *glist=NULL; GtkWidget *ifCombo; dialog = gnome_dialog_new(_("Choose a interface to capture"),_("OK"),NULL,NULL); _hbox = gtk_hbox_new(FALSE,0); label = gtk_label_new("Choose an interface: "); ifCombo = gtk_combo_new(); for (i = 0; i < ifnum; i++) { glist = g_list_append(glist, ifitem[i].ifname); } gtk_combo_set_popdown_strings( GTK_COMBO(ifCombo), glist); gtk_box_pack_start(GTK_BOX(_hbox),label,FALSE,FALSE,5); gtk_box_pack_start(GTK_BOX(_hbox),ifCombo,FALSE,FALSE,5); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),_hbox,TRUE,TRUE,0); gtk_signal_connect(GTK_OBJECT(GTK_COMBO(ifCombo)->entry), "activate", GTK_SIGNAL_FUNC (get_ifcard_str),NULL); gtk_widget_show(ifCombo); gtk_widget_show(label); gtk_widget_show(_hbox); gtk_signal_connect(GTK_OBJECT(dialog),"clicked",GTK_SIGNAL_FUNC(dialog_ok),&dialog); gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); gtk_widget_show(dialog); gnome_dialog_set_parent(GNOME_DIALOG(dialog),GTK_WINDOW(app)); }
void about() { GtkWidget *dialog; GtkWidget *contentlabel,*versionlabel,*authorlabel,*copyrightlabel; dialog = gnome_dialog_new(_("About the program"),_("OK"),NULL,NULL); contentlabel = gtk_label_new(_("Linux sniffer")); copyrightlabel = gtk_label_new(_("Copyright 2011-10-06")); authorlabel = gtk_label_new(_("付乔宾")); versionlabel = gtk_label_new(_("Version:1.0")); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),contentlabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),versionlabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),copyrightlabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),authorlabel,TRUE,TRUE,0); gtk_widget_show(contentlabel); gtk_widget_show(versionlabel); gtk_widget_show(copyrightlabel); gtk_widget_show(authorlabel); gtk_signal_connect(GTK_OBJECT(dialog),"clicked",GTK_SIGNAL_FUNC(dialog_ok),&dialog); gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); gtk_widget_show(dialog); gnome_dialog_set_parent(GNOME_DIALOG(dialog),GTK_WINDOW(app)); }
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; }
static void game_preferences_callback (GtkWidget *widget, void *data) { GtkWidget *menu, *omenu, *l, *hb, *cb, *f, *fv; GtkWidget *button; if (pref_dialog) return; pref_dialog = gnome_dialog_new (_("Preferences"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); gnome_dialog_set_parent (GNOME_DIALOG (pref_dialog), GTK_WINDOW (app)); gtk_signal_connect (GTK_OBJECT(pref_dialog), "delete_event", GTK_SIGNAL_FUNC (cancel), NULL); omenu = gtk_option_menu_new (); menu = gtk_menu_new (); fill_menu (menu); gtk_widget_show (omenu); gtk_option_menu_set_menu (GTK_OPTION_MENU(omenu), menu); f = gtk_frame_new (_ ("Scenario")); gtk_container_border_width (GTK_CONTAINER (f), 5); hb = gtk_hbox_new (FALSE, FALSE); gtk_widget_show (hb); l = gtk_label_new (_("Select scenario:")); gtk_widget_show (l); gtk_box_pack_start_defaults (GTK_BOX(hb), l); gtk_box_pack_start_defaults (GTK_BOX(hb), omenu); cb = gtk_check_button_new_with_label ( _("Make it the default scenario") ); gtk_signal_connect (GTK_OBJECT(cb), "clicked", (GtkSignalFunc)set_selection_def, NULL); gtk_widget_show (cb); fv = gtk_vbox_new (0, 5); gtk_container_border_width (GTK_CONTAINER (fv), 5); gtk_widget_show (fv); gtk_box_pack_start_defaults (GTK_BOX(fv), hb); gtk_box_pack_start_defaults (GTK_BOX(fv), cb); gtk_box_pack_start_defaults (GTK_BOX(GNOME_DIALOG(pref_dialog)->vbox), f); gtk_container_add (GTK_CONTAINER (f), fv); gtk_widget_show (f); gnome_dialog_button_connect (GNOME_DIALOG (pref_dialog), 0, GTK_SIGNAL_FUNC (load_scenario_callback), NULL); gnome_dialog_button_connect (GNOME_DIALOG (pref_dialog), 1, GTK_SIGNAL_FUNC (cancel), (gpointer)1); gtk_widget_show (pref_dialog); }
void find_compile_regex(GnomeFindDialog *find_dialog) { int cflags; int regex_result; char errbuf[ERRBUF_SIZE]; char messagebuf[MSGBUF_SIZE]; GtkWidget *message_dialog; if(find_params.regex == TRUE) { /* compile the regular expression */ cflags = REG_EXTENDED; if(find_params.case_sensitive == FALSE) { cflags = cflags | REG_ICASE; } preg = (regex_t *) g_malloc(sizeof(regex_t)); regex_result = regcomp(preg, find_params.find_text, cflags); if(regex_result != 0) { regerror(regex_result, preg, errbuf, ERRBUF_SIZE); g_snprintf(messagebuf, MSGBUF_SIZE, "Error compiling regular expression: %s", errbuf); message_dialog = gnome_message_box_new(messagebuf, GNOME_MESSAGE_BOX_ERROR, GNOME_STOCK_BUTTON_OK, NULL); if (find_dialog != NULL ) { gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog)); } else { gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window)); } gnome_dialog_run_and_close(GNOME_DIALOG(message_dialog)); return; } } }
static GtkWidget * request_dialog (const gchar * request, const gchar * default_text, const guint16 max_length, GnomeStringCallback callback, gpointer data, gboolean password, GtkWindow * parent) { GtkWidget * mbox; callback_info * info; GtkWidget * entry; mbox = gnome_message_box_new ( request, GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_CANCEL, GNOME_STOCK_BUTTON_OK, NULL ); gnome_dialog_set_default ( GNOME_DIALOG(mbox), 1 ); /* set up text entry widget */ entry = gtk_entry_new(); if (password) gtk_entry_set_visibility (GTK_ENTRY(entry), FALSE); if ((default_text != NULL) && (*default_text)) gtk_entry_set_text(GTK_ENTRY(entry), default_text); if (max_length > 0) gtk_entry_set_max_length(GTK_ENTRY(entry), max_length); gtk_box_pack_end ( GTK_BOX(GNOME_DIALOG(mbox)->vbox), entry, FALSE, FALSE, GNOME_PAD_SMALL ); /* If Return is pressed in the text entry, propagate to the buttons */ gnome_dialog_editable_enters(GNOME_DIALOG(mbox), GTK_EDITABLE(entry)); info = g_new(callback_info, 1); info->function = callback; info->data = data; info->entry = GTK_ENTRY(entry); g_signal_connect_data (mbox, "clicked", G_CALLBACK (dialog_string_callback), info, (GClosureNotify) g_free, 0); if (parent != NULL) { gnome_dialog_set_parent(GNOME_DIALOG(mbox),parent); } gtk_widget_grab_focus (entry); gtk_widget_show (entry); gtk_widget_show (mbox); return mbox; }
static GtkWidget * show_ok_box(const gchar * message, const gchar * type, GtkWindow * parent) { GtkWidget * mbox; mbox = gnome_message_box_new (message, type, GNOME_STOCK_BUTTON_OK, NULL); if (parent != NULL) { gnome_dialog_set_parent(GNOME_DIALOG(mbox),parent); } gtk_widget_show (mbox); return mbox; }
void find_process_result(GnomeFindDialog *find_dialog, int find_result) { find_selection *find_select; GtkWidget *message_dialog; if (find_dialog != NULL) g_return_if_fail(GNOME_IS_FIND_DIALOG(find_dialog)); switch (find_result) { case GNOME_FIND_NOMATCH: message_dialog = gnome_message_box_new("Could not find text in console output.", GNOME_MESSAGE_BOX_WARNING, GNOME_STOCK_BUTTON_OK, NULL); if (find_dialog != NULL ) { gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog)); } else { gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window)); } gnome_dialog_run_and_close (GNOME_DIALOG(message_dialog)); if(find_dialog != NULL) gnome_dialog_set_default(GNOME_DIALOG(find_dialog), GNOME_FIND_BUTTON_FIND); break; case GNOME_FIND_MATCH: find_select = (find_selection *) find_current_match->data; gtk_editable_set_position(GTK_EDITABLE(R_gtk_terminal_text), find_select->select_end); gtk_editable_select_region(GTK_EDITABLE(R_gtk_terminal_text), find_select->select_start, find_select->select_end); break; } }
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); }
static int game_quit_callback (GtkWidget *widget, void *data) { GtkWidget *box; box = gnome_message_box_new (_("Do you really want to quit?"), GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_YES, GNOME_STOCK_BUTTON_NO, NULL); gnome_dialog_set_parent (GNOME_DIALOG(box), GTK_WINDOW(app)); gnome_dialog_set_default (GNOME_DIALOG (box), 0); gtk_window_set_modal (GTK_WINDOW (box), TRUE); gtk_signal_connect (GTK_OBJECT (box), "clicked", (GtkSignalFunc)game_maybe_quit, NULL); gtk_widget_show (box); return TRUE; }
void edit_find_cb(GtkWidget *widget, gpointer data) { GtkWidget *find_dialog; find_dialog = gnome_find_dialog_new("Find text", &find_params, TRUE, TRUE, TRUE); gnome_dialog_set_parent(GNOME_DIALOG(find_dialog), GTK_WINDOW(R_gtk_main_window)); gtk_signal_connect(GTK_OBJECT(find_dialog), "find", (GtkSignalFunc) find_dialog_cb, NULL); gtk_signal_connect(GTK_OBJECT(find_dialog), "find_again", (GtkSignalFunc) find_again_dialog_cb, NULL); gtk_widget_show(find_dialog); }
static GtkWidget * reply_dialog (const gchar * question, GnomeReplyCallback callback, gpointer data, gboolean yes_or_ok, gboolean modal, GtkWindow * parent) { GtkWidget * mbox; callback_info * info; if (yes_or_ok) { mbox = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_NO, GNOME_STOCK_BUTTON_YES, NULL); } else { mbox = gnome_message_box_new(question, GNOME_MESSAGE_BOX_QUESTION, GNOME_STOCK_BUTTON_CANCEL, GNOME_STOCK_BUTTON_OK, NULL); } if (callback != NULL) { info = g_new(callback_info, 1); info->function = callback; info->data = data; g_signal_connect_data (mbox, "clicked", G_CALLBACK (dialog_reply_callback), info, (GClosureNotify) g_free, 0); } if (modal) { gtk_window_set_modal(GTK_WINDOW(mbox),TRUE); } if (parent != NULL) { gnome_dialog_set_parent(GNOME_DIALOG(mbox),parent); } gtk_widget_show(mbox); return mbox; }
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; }
static int game_about_callback (GtkWidget *widget, void *data) { GtkWidget *about; const gchar *authors[] = { "Miguel de Icaza.", "Federico Mena.", "Horacio J. Peña.", NULL }; about = gnome_about_new (_("The Same Gnome"), VERSION, "(C) 1997-1998 the Free Software Foundation", (const char **)authors, _("Original idea from KDE's same game program."), /*"gnome-same-gnome.xpm"*/ NULL); gnome_dialog_set_parent(GNOME_DIALOG(about), GTK_WINDOW(app)); gtk_widget_show (about); return TRUE; }
int find_update_line_cache(GnomeFindDialog *find_dialog) { int find_text_len; int eflags; regmatch_t pmatch[1]; int regex_result; char errbuf[ERRBUF_SIZE]; char messagebuf[MSGBUF_SIZE]; int strcmp_result; int tmp_find_pos; gchar *find_line_cache; find_selection *find_select; GtkWidget *message_dialog; /* initialisation */ find_line_cache = NULL; find_text_len = strlen(find_params.find_text); line_cache_update = FALSE; /* free matches list if necessary */ if (find_current_match != NULL) { find_current_match = g_list_first(find_current_match); g_list_foreach(find_current_match, find_free_select, NULL); g_list_free(find_current_match); find_current_match = NULL; } /* Move one line */ switch (find_params.direction) { case GNOME_FIND_FORWARDS: do { if(find_pos > find_pos_max) { if(find_params.wrap_search == TRUE) { find_pos = 0; search_wrapped = TRUE; } else { return GNOME_FIND_NOMATCH; } } else { find_pos++; if((search_wrapped) && (find_pos >= find_pos_init)) { return GNOME_FIND_NOMATCH; } } } while (find_text_cache[find_pos] == '\n'); break; case GNOME_FIND_BACKWARDS: do { if(find_pos < 0) { if(find_params.wrap_search == TRUE) { find_pos = find_pos_max; search_wrapped = TRUE; } else { return GNOME_FIND_NOMATCH; } } else { find_pos--; if((search_wrapped) && (find_pos <= find_pos_init)) { return GNOME_FIND_NOMATCH; } } } while (find_text_cache[find_pos] == '\n'); break; } line_cache_start = line_cache_end = find_pos; while ((line_cache_start > 0) && (find_text_cache[line_cache_start - 1] != '\n')) { line_cache_start--; } while ((line_cache_end < find_pos_max) && (find_text_cache[line_cache_end + 1] != '\n')) { line_cache_end++; } /* Grab the line */ find_line_cache = g_strndup(find_text_cache + line_cache_start, line_cache_end - line_cache_start + 1); /* Search line */ if (find_params.regex == TRUE) { /* Regular expression search */ tmp_find_pos = 0; eflags = 0; do { if (tmp_find_pos != 0) { eflags = REG_NOTBOL; } /* execute the match */ regex_result = regexec(preg, find_line_cache + tmp_find_pos, 1, pmatch, eflags); if(regex_result == 0) { /* construct list item if found */ find_select = g_new(find_selection, 1); find_select->select_start = line_cache_start + tmp_find_pos + pmatch[0].rm_so; find_select->select_end = line_cache_start + tmp_find_pos + pmatch[0].rm_eo; find_current_match = g_list_append(find_current_match, (gpointer) find_select); tmp_find_pos += pmatch[0].rm_so + 1; } else if (regex_result != REG_NOMATCH) { /* report regexec errors and terminate the search */ regerror(regex_result, preg, errbuf, ERRBUF_SIZE); g_snprintf(messagebuf, MSGBUF_SIZE, "Error matching regular expression: %s", errbuf); message_dialog = gnome_message_box_new(messagebuf, GNOME_MESSAGE_BOX_ERROR, GNOME_STOCK_BUTTON_OK, NULL); if (find_dialog != NULL ) { gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(find_dialog)); } else { gnome_dialog_set_parent(GNOME_DIALOG(message_dialog), GTK_WINDOW(R_gtk_main_window)); } gnome_dialog_run_and_close(GNOME_DIALOG(message_dialog)); if (find_line_cache != NULL) { g_free(find_line_cache); } return GNOME_FIND_NOMATCH; } } while ((tmp_find_pos <= (line_cache_end - line_cache_start)) && (regex_result == 0)); } else { /* Literal search */ for (tmp_find_pos = line_cache_start; tmp_find_pos <= line_cache_end; tmp_find_pos++) { if (find_params.case_sensitive == TRUE) { strcmp_result = strncmp(find_params.find_text, find_text_cache + tmp_find_pos, find_text_len); } else { strcmp_result = g_strncasecmp(find_params.find_text, find_text_cache + tmp_find_pos, find_text_len); } /* construct list item if found */ if(strcmp_result == 0) { find_select = g_new(find_selection, 1); find_select->select_start = tmp_find_pos; find_select->select_end = tmp_find_pos + find_text_len; find_current_match = g_list_append(find_current_match, (gpointer) find_select); } } } if (find_line_cache != NULL) { g_free(find_line_cache); } /* Return result */ if (find_current_match != NULL) { if(find_params.direction == GNOME_FIND_BACKWARDS) find_current_match = g_list_last(find_current_match); return GNOME_FIND_MATCH; } return GNOME_FIND_NOTFOUND; }
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; }
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]); }
/* window that shows armies to move in a regroup */ void reagrupe_window( int src, int dst, int cant ) { GtkWidget *label; GtkWidget *table; GtkWidget *frame; GtkWidget *vbox_dia,*vbox; GtkWidget *hbox; GtkAdjustment *adj; char buf[200]; reagrupe_src = src; reagrupe_dst = dst; if( reagrupe_dialog != NULL ) { gdk_window_show( reagrupe_dialog->window); gdk_window_raise( reagrupe_dialog->window); return ; } reagrupe_cant = 0; // reagrupe_dialog = gnome_dialog_new(_("Regrouping armies"),GNOME_STOCK_BUTTON_OK,NULL); reagrupe_dialog = teg_dialog_new(_("Regrouping armies"),_("Regroup your armies")); // Make the dialog modal (=main window is deactivated while the dialog is open) to fix // bug [689687]: Error, unexpected error in reagrupe_click(). gtk_window_set_modal( GTK_WINDOW( reagrupe_dialog ), TRUE ); gnome_dialog_append_button(GNOME_DIALOG(reagrupe_dialog), GNOME_STOCK_BUTTON_OK); gnome_dialog_set_parent (GNOME_DIALOG (reagrupe_dialog), GTK_WINDOW (main_window)); gtk_signal_connect (GTK_OBJECT (reagrupe_dialog), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &reagrupe_dialog); // When ok gets pressed, call reagrupe_ok_cb(). gnome_dialog_button_connect(GNOME_DIALOG(reagrupe_dialog), 0, GTK_SIGNAL_FUNC(reagrupe_ok_cb), NULL); vbox_dia = GNOME_DIALOG(reagrupe_dialog)->vbox; table = gtk_table_new (2, 2, FALSE); gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD); gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD); gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD); gtk_box_pack_start( GTK_BOX( vbox_dia), table, TRUE, TRUE, 0); frame = gtk_frame_new (_("Regrouping")); gtk_container_border_width (GTK_CONTAINER (frame), 0); vbox = gtk_vbox_new (TRUE, 0); gtk_container_border_width (GTK_CONTAINER (vbox), GNOME_PAD); snprintf(buf, sizeof(buf) -1, _("Moving armies from '%s' to '%s'\n"), countries_get_name(src), countries_get_name(dst) ); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); hbox = gtk_hbox_new( FALSE, 0); gtk_container_add( GTK_CONTAINER( vbox ), hbox ); label = gtk_label_new(_("Armies to move")); gtk_box_pack_start( GTK_BOX( hbox), label, TRUE, TRUE, 0); adj = (GtkAdjustment *) gtk_adjustment_new( (gfloat) cant, 0.0, (gfloat) (cant + 1), 1.0, 1.0, 1.0 ); reagrupe_hscale_cant = gtk_hscale_new( adj); gtk_box_pack_start( GTK_BOX( hbox), reagrupe_hscale_cant, TRUE, TRUE, 0); gtk_scale_set_digits(GTK_SCALE(reagrupe_hscale_cant), 0); gtk_scale_set_draw_value(GTK_SCALE(reagrupe_hscale_cant),1); /* gtk_range_draw_trough(GTK_RANGE(reagrupe_hscale_cant)); */ snprintf(buf, sizeof(buf) -1,_("[Note: You can regroup as many times as you want,\nas long as you don't regroup an army that was\nregrouped before in this turn.]")); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); if (!GTK_WIDGET_VISIBLE (reagrupe_dialog)) gtk_widget_show_all (reagrupe_dialog); else gtk_widget_destroy (reagrupe_dialog); }
void display_statistics() { gchar display[50]; GtkWidget *dialog; GtkWidget *totlabel, *iplabel, *tcplabel, *udplabel, *arplabel, *icmplabel, *igmplabel; dialog = gnome_dialog_new(_("Statistics of the packets"),_("OK"),NULL,NULL); pthread_mutex_lock(&packet_stat_mtx); memset(display,0,sizeof(display)); sprintf(display,"Total packets: %d",tot_packet); totlabel = gtk_label_new(display); memset(display,0,sizeof(display)); sprintf(display,"IP packets: %d",ip_packet); iplabel = gtk_label_new(display); memset(display,0,sizeof(display)); sprintf(display,"TCP packets: %d",tcp_packet); tcplabel = gtk_label_new(display); memset(display,0,sizeof(display)); sprintf(display,"UDP packets: %d",udp_packet); udplabel = gtk_label_new(display); memset(display,0,sizeof(display)); sprintf(display,"ARP packets: %d",arp_packet); arplabel = gtk_label_new(display); memset(display,0,sizeof(display)); sprintf(display,"ICMP packets: %d",icmp_packet); icmplabel = gtk_label_new(display); memset(display,0,sizeof(display)); sprintf(display,"IGMP packets: %d",igmp_packet); igmplabel = gtk_label_new(display); pthread_mutex_unlock(&packet_stat_mtx); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),totlabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),iplabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),tcplabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),udplabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),arplabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),icmplabel,TRUE,TRUE,0); gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),igmplabel,TRUE,TRUE,0); gtk_widget_show(totlabel); gtk_widget_show(iplabel); gtk_widget_show(tcplabel); gtk_widget_show(udplabel); gtk_widget_show(arplabel); gtk_widget_show(icmplabel); gtk_widget_show(igmplabel); gtk_signal_connect(GTK_OBJECT(dialog),"clicked",GTK_SIGNAL_FUNC(dialog_ok),&dialog); gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); gtk_widget_show(dialog); gnome_dialog_set_parent(GNOME_DIALOG(dialog),GTK_WINDOW(app)); }
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); }
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"); } }
/* 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); } }
/* shows how many armies you can move after an attack */ void tropas_window( int src, int dst, int cant ) { GtkWidget *label; GtkWidget *table; GtkWidget *frame; GtkWidget *vbox_dia,*vbox; GtkWidget *hbox; GtkAdjustment *adj; char buf[200]; tropas_src = src; tropas_dst = dst; if( tropas_dialog != NULL ) { gdk_window_show( tropas_dialog->window); gdk_window_raise( tropas_dialog->window); return ; } tropas_cant = 0; // tropas_dialog = gnome_dialog_new(_("A country was conquered"),GNOME_STOCK_BUTTON_OK,NULL); tropas_dialog = teg_dialog_new(_("A country was conquered"),_("A country was conquered")); gnome_dialog_append_button( GNOME_DIALOG(tropas_dialog),GNOME_STOCK_BUTTON_OK); gnome_dialog_set_parent (GNOME_DIALOG (tropas_dialog), GTK_WINDOW (main_window)); gtk_signal_connect (GTK_OBJECT (tropas_dialog), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroyed), &tropas_dialog); if( cant > 0 ) gnome_dialog_button_connect(GNOME_DIALOG(tropas_dialog), 0, GTK_SIGNAL_FUNC(tropas_ok_cb), NULL); else gnome_dialog_button_connect(GNOME_DIALOG(tropas_dialog), 0, GTK_SIGNAL_FUNC(tropas_close_cb), NULL); vbox_dia = GNOME_DIALOG(tropas_dialog)->vbox; table = gtk_table_new (2, 2, FALSE); gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD); gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD); gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD); gtk_box_pack_start( GTK_BOX( vbox_dia), table, TRUE, TRUE, 0); frame = gtk_frame_new (_("A new country")); gtk_container_border_width (GTK_CONTAINER (frame), 0); vbox = gtk_vbox_new (TRUE, 0); gtk_container_border_width (GTK_CONTAINER (vbox), GNOME_PAD); snprintf(buf,sizeof(buf)-1,_("You conquered '%s' in your attack from '%s'!!\n"), countries_get_name(dst), countries_get_name(src) ); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); if( cant > 0) { hbox = gtk_hbox_new( FALSE, 0); gtk_container_add( GTK_CONTAINER( vbox ), hbox ); label = gtk_label_new(_("Armies to move")); gtk_box_pack_start( GTK_BOX( hbox), label, TRUE, TRUE, 0); adj = (GtkAdjustment *) gtk_adjustment_new( (gfloat) cant, 0.0, (gfloat) (cant + 1), 1.0, 1.0, 1.0 ); // tropas_spinner_cant = gtk_spin_button_new( adj, 0.0, 0); tropas_hscale_cant = gtk_hscale_new( adj); gtk_box_pack_start( GTK_BOX( hbox), tropas_hscale_cant, TRUE, TRUE, 0); gtk_scale_set_digits(GTK_SCALE(tropas_hscale_cant), 0); gtk_scale_set_draw_value(GTK_SCALE(tropas_hscale_cant),1); /* gtk_range_draw_trough(GTK_RANGE(tropas_hscale_cant)); */ snprintf(buf, sizeof(buf) -1, _("[Note: The server moved 1 army to '%s' for you.\nChoose how many more armies you want to move]"), countries_get_name(dst) ); buf[ sizeof(buf) -1 ] = 0; label = gtk_label_new(buf); gtk_box_pack_start( GTK_BOX( vbox), label, TRUE, TRUE, 0); } gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 0, 1, GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); if (!GTK_WIDGET_VISIBLE (tropas_dialog)) gtk_widget_show_all (tropas_dialog); else gtk_widget_destroy (tropas_dialog); }