/* showword.c function for show word * 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" /* get next index */ static void get_next_index(); /* stop show word when menuitem stop is click*/ void show_stop() { // g_print("click stop \n"); timer_uninstall(); //inacitve stop_button gtk_widget_set_sensitive(stop_button,0); //active play button gtk_widget_set_sensitive(play_button,1); } /* play show word when menuitem play is click*/ void show_play() { // g_print("click play \n"); //install timer timer_install(); //inacitve play_button gtk_widget_set_sensitive(play_button,0); //active stop button gtk_widget_set_sensitive(stop_button,1); } /* back show word when menuitem back is click*/ void show_back() { //no random //S_conf.random = 0; //no timer! timer_uninstall(); // g_print("click back \n"); //because show_word will ++; if(S_conf.style == 0) { S_state.word_index -= 2; while(word_tag[S_state.word_index] == 1) S_state.word_index --; show_word(); } if(S_conf.style == 1) { if(S_state.style_step == 0) { S_state.word_index -= 2; while(word_tag[S_state.word_index] == 1) S_state.word_index --; } if(S_state.style_step == 1) S_state.word_index --; show_word(); } //inacitve stop_button gtk_widget_set_sensitive(stop_button,0); //active play button gtk_widget_set_sensitive(play_button,1); } /* next show word when menuitem next is click*/ void show_next() { //no random //S_conf.random = 0; // g_print("click next \n"); // no timer! timer_uninstall(); //show next word! if(S_conf.style == 0) { show_word(); } if(S_conf.style == 1) { if(S_state.style_step == 1) S_state.word_index --; show_word(); } //inacitve stop_button gtk_widget_set_sensitive(stop_button,0); //active play button if(S_state.word_index < word_count ) gtk_widget_set_sensitive(play_button,1); } /* random show word when menuitem random is click*/ void show_random() { // g_print("click random \n"); if(GTK_CHECK_MENU_ITEM(random_menu_item)->active) { S_conf.random = 1; g_print("random switch ON! S_conf.random = %d\n",S_conf.random); } else { S_conf.random = 0; g_print("random switch OFF! S_conf.random = %d\n",S_conf.random); } } /* get next index */ static void get_next_index() { int randnum; if(S_conf.random == 1) { // 0< random num < (word_count-1) randnum = rand() % (word_count-1); S_state.word_index = randnum; } while(word_tag[S_state.word_index] == 1) { if(S_conf.random == 1) { randnum = rand() % (word_count-1); S_state.word_index = randnum; } S_state.word_index ++; } } //show S_line in label,fist step gint show_word() { gchar text[256]; get_next_index(); if(S_conf.style == 0) { // read line!!!!! read_line();//change S_line; strcpy(text,""); if(S_conf.EN_word) { strcat(text,S_line.EN_word); } //not show TK_word //show_photetic(); if(S_conf.TK_word) { if(S_conf.show_format == 0) strcat(text,"\n"); else strcat(text," "); strcat(text,S_line.TK_word); } if(S_conf.CH_word) { if(S_conf.show_format == 2) strcat(text," "); else strcat(text,"\n"); strcat(text,S_line.CH_word); } // strcpy(wordname,""); // strcpy(wordname,S_line.EN_word); // read aloudly read_word(S_line.EN_word); } else { if(S_state.style_step == 0) { //step 1,show EN read_line();//change S_line; strcpy(text,""); strcat(text,S_line.EN_word); if(S_conf.show_format == 1) strcat(text,"\n"); if(S_conf.show_format == 0) strcat(text,"\n\n"); S_state.style_step = 1; } else { //step 2,show EN and CH strcpy(text,""); //if(S_conf.EN_word) { strcat(text,S_line.EN_word); } //not show TK_word //show_photetic(); //if(S_conf.TK_word) { if(S_conf.show_format == 0) strcat(text,"\n"); else strcat(text," "); strcat(text,S_line.TK_word); } //if(S_conf.CH_word) { if(S_conf.show_format == 2) strcat(text," "); else strcat(text,"\n"); strcat(text,S_line.CH_word); } S_state.style_step = 0; // read aloudly read_word(S_line.EN_word); } } // fix window size fix_window_usize(); //g_print("get a text = %s \n\n",text); if(S_state.word_index >= word_count) // end of word book { show_stop(); gtk_widget_set_sensitive(next_button,0); gtk_widget_set_sensitive(play_button,0); gtk_label_set(GTK_LABEL(label),"End of word book :)\nGood Good Study, Day Day Up!");//show word in label } else if(S_state.word_index < 0) // start of word book { show_stop(); gtk_widget_set_sensitive(back_button,0); gtk_label_set(GTK_LABEL(label),"Head of word book :)\nSome Dance to Remember\nSome Dance to Forget");//show word in label } else // normal { gtk_widget_set_sensitive(next_button,1); gtk_label_set(GTK_LABEL(label),text);//show word in label } // word_index ++ for next word S_state.word_index ++; return 1; } /* show banner */ void show_banner(gchar * banner) { gtk_label_set(GTK_LABEL(label),banner);//show word in label } /* void show_go() { } */