/* gotowin.c go to word or number index * Copyright (c) 2004 by SmartLu All Rights Reserved * Distributed under the terms of the GNU General Public License (GPL) * See the GNU Library General Public License for more details. */ #include "srecite.h" //goto word or number index static void goto_index(); static GtkWidget *goto_win,*input_entry; static GtkWidget *result_label; //static GtkWidget *pad_label; static GtkWidget *quit_button,*goto_button; static void goto_quit() { gtk_grab_remove(goto_win); gtk_widget_destroy(goto_win); //gtk_widget_show(window); } /* window of goto */ void goto_window() { GtkWidget *vbox,*hbox,*h_line; GtkWidget *xpm_label; gchar str[255]; gchar temp[255]; /* goto window */ goto_win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(goto_win),"Goto word or number index"); gtk_widget_set_usize(goto_win,600,150); gtk_widget_set_uposition(goto_win,300,200); gtk_container_border_width(GTK_CONTAINER(goto_win),0); gtk_signal_connect (GTK_OBJECT (goto_win), "delete_event", GTK_SIGNAL_FUNC(goto_quit), goto_win); /* vbox */ vbox = gtk_vbox_new(TRUE,0); gtk_container_add(GTK_CONTAINER(goto_win),vbox); gtk_widget_show(vbox); /* hbox */ hbox = gtk_hbox_new(TRUE,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); gtk_widget_show(hbox); /* goto label */ sprintf(temp,"%d",word_count); strcpy(str,""); strcat(str,"Wordbook: "); strcat(str,S_conf.filename); strcat(str," Total words: "); strcat(str,temp); xpm_label = create_img_box(PRE_DIR"icon/about.png",str); gtk_box_pack_start(GTK_BOX(hbox),xpm_label,FALSE,FALSE,0); gtk_widget_show(xpm_label); /* result label */ result_label=gtk_label_new("Go to word or number index which you input!"); gtk_box_pack_start(GTK_BOX(vbox),result_label,FALSE,FALSE,0); // left gtk_widget_show(result_label); /* input word editor */ input_entry = gtk_entry_new(); gtk_entry_set_max_length (GTK_ENTRY(input_entry), 100); g_signal_connect (G_OBJECT(input_entry), "activate", G_CALLBACK (goto_index),input_entry); gtk_box_pack_start(GTK_BOX(vbox),input_entry,FALSE,FALSE,0); gtk_widget_show(input_entry); // font gtk_widget_modify_font((GtkWidget *) input_entry, font); /* h_line */ h_line = gtk_hseparator_new(); gtk_box_pack_start(GTK_BOX(vbox),h_line,FALSE,FALSE,0); gtk_widget_show(h_line); /* button */ hbox = gtk_hbox_new(TRUE,0); gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0); gtk_widget_show(hbox); /* goto button */ goto_button = create_img_button(PRE_DIR"icon/goto.png", "Goto", "Goto", goto_index, goto_button); gtk_box_pack_start(GTK_BOX(hbox),goto_button,FALSE,FALSE,0); gtk_widget_show(goto_button); /* quit button */ quit_button = create_img_button(PRE_DIR"icon/exit.png", "Quit", "Quit", goto_quit, quit_button); gtk_box_pack_start(GTK_BOX(hbox),quit_button,FALSE,FALSE,0); gtk_widget_show(quit_button); /* show all!over! */ gtk_widget_set_sensitive(input_entry,1); //gtk_widget_hide(window); gtk_widget_show(goto_win); } //goto word or number index static void goto_index() { //g_print("goto read!!\n"); gchar word[256]; gchar result_str[256]; int flag=0; int input_index=0; strcpy(word,gtk_entry_get_text(GTK_ENTRY(input_entry))); if(isalpha(word[0])) //word { flag = do_EN_search(word,0,word_count-1);//search whole wordbook if(flag) //found { //S_state.word_index --; goto_quit(); } else // not found { strcpy(result_str,"Not found word: "); strcat(result_str,word); strcat(result_str," ! Please input again"); gtk_label_set(GTK_LABEL(result_label),result_str); gtk_editable_select_region(GTK_EDITABLE (input_entry), 0,GTK_ENTRY(input_entry)->text_length); } } else if(isdigit(word[0])) // number { sscanf(word,"%d\n",& input_index); g_print("input number: %d\n",input_index); if(input_index < word_count && input_index > -1) { S_state.word_index = input_index; goto_quit(); } else { strcpy(result_str,"Your input number beyonds the range of current word book!!"); strcat(result_str," Please input again"); gtk_label_set(GTK_LABEL(result_label),result_str); //select input entry gtk_editable_select_region(GTK_EDITABLE (input_entry), 0,GTK_ENTRY(input_entry)->text_length); } } else { strcpy(result_str,"Your input can't be accepted!!"); strcat(result_str," Please input again"); gtk_label_set(GTK_LABEL(result_label),result_str); //select input entry gtk_editable_select_region(GTK_EDITABLE (input_entry), 0,GTK_ENTRY(input_entry)->text_length); } }