static void search_selected(gchar *str) { gchar *euc_str; gint method; glong len; LOG(LOG_DEBUG, "IN : search_selected(%s)", str); if(selection_mode <= SELECTION_DO_NOTHING) { LOG(LOG_DEBUG, "OUT : search_selected() = NOP1"); return; } if(strcmp(previous, str) == 0){ // Do nothing if the word is the save as before. LOG(LOG_DEBUG, "same as before"); ; } else { euc_str = iconv_convert("utf-8", "euc-jp", str); if(validate_euc_str(euc_str) == FALSE) { g_free(euc_str); LOG(LOG_DEBUG, "OUT : search_selected() = INVALID"); return; } remove_space(euc_str); len = g_utf8_strlen(str, -1); if((auto_minchar <= len) && (len <= auto_maxchar)) { gtk_entry_set_text(GTK_ENTRY(word_entry), str); method = ebook_search_method(); if((method == SEARCH_METHOD_INTERNET) || (method == SEARCH_METHOD_MULTI) || (method == SEARCH_METHOD_FULL_TEXT)){ LOG(LOG_DEBUG, "OUT : search_selected() = NOP2"); return; } if(selection_mode <= SELECTION_COPY_ONLY) { LOG(LOG_DEBUG, "OUT : search_selected() = COPY"); return; } clear_message(); clear_search_result(); if(method == SEARCH_METHOD_GREP){ grep_search(euc_str); show_result_tree(); select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); save_word_history(str); } else { ebook_search_auto(euc_str, method); show_result_tree(); if(search_result){ if(selection_mode == SELECTION_POPUP) { show_result_in_popup(); } else { select_first_item(); if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); } save_word_history(str); } else { current_in_result = NULL; set_current_result(NULL); if(selection_mode == SELECTION_POPUP) { beep(); } else { if(selection_mode == SELECTION_SEARCH_TOP) bring_to_top(main_window); push_message(_("No hit.")); } } } sprintf(previous, "%s", str); } else { LOG(LOG_DEBUG, "OUT : search_selected() = LENGTH"); } g_free(euc_str); } LOG(LOG_DEBUG, "OUT : search_selected()"); }
void show_popup(RESULT *result) { gchar *text=NULL; GtkTextIter iter; CANVAS canvas; DRAW_TEXT l_text; gint length; gchar *euc_str; g_assert(result->type == RESULT_TYPE_EB); LOG(LOG_DEBUG, "IN : show_popup()"); text = ebook_get_text(result->data.eb.book_info, result->data.eb.pos_text.page, result->data.eb.pos_text.offset); if(text == NULL) return; // Prevent the window from growing. //if(text[strlen(text)-1] == '\n') //text[strlen(text)-1] = '\0'; if(popup == NULL){ create_popup_window(); } // Program aborts if you enable this line. //gtk_text_view_set_buffer(GTK_TEXT_VIEW(main_view), NULL); clear_text_buffer(); gtk_text_buffer_get_start_iter (text_buffer, &iter); length = strlen(text); if(text[length-1] == '\n'){ text[length-1] = '\0'; length --; } l_text.text = text; l_text.length = length; canvas.buffer = text_buffer; canvas.iter = &iter; canvas.indent = 0; if(result->word != NULL){ euc_str = iconv_convert("utf-8", "euc-jp", result->word); draw_content(&canvas, &l_text, result->data.eb.book_info, NULL, euc_str); g_free(euc_str); } else { draw_content(&canvas, &l_text, result->data.eb.book_info, NULL, NULL); } gtk_text_buffer_get_start_iter (text_buffer, &iter); gtk_text_buffer_place_cursor(text_buffer, &iter); if(bshow_popup_title){ gchar title[256]; sprintf(title, "%d of %d", g_list_index(search_result, current_in_result->data) + 1, g_list_length(search_result)); gtk_label_set_text(GTK_LABEL(title_label), title); } gtk_adjustment_set_value( gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(popup_scroll)), 0); gtk_adjustment_set_value( gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(popup_scroll)), 0); gtk_window_present(GTK_WINDOW(popup)); g_free(text); set_current_result(result); gtk_timeout_add(10, scroll_to_top, NULL); LOG(LOG_DEBUG, "OUT : show_popup()"); }