📄 search.c
字号:
/*************************************************************************** * Copyright (C) 2003 by zhong * * zhongz@163.com * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * ***************************************************************************/#include <string.h>#include <gtk/gtk.h>#include <gtkhtml/gtkhtml-search.h>#include "interface.h"// 搜索当前页面代码typedef struct _ChmSee_Search ChmSee_Search; struct _ChmSee_Search { GtkWidget *search_chm_html; GtkWidget *search_entry; GtkWidget *search_checkbutton; GtkWidget *button2; GtkWidget *button3;};static GtkWidget *button_next_new(void) { GtkWidget *button2; GtkWidget *alignment2; GtkWidget *hbox3; GtkWidget *image2; GtkWidget *label2; button2 = gtk_button_new (); gtk_widget_show (button2); alignment2 = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_widget_show (alignment2); gtk_container_add (GTK_CONTAINER (button2), alignment2); hbox3 = gtk_hbox_new (FALSE, 2); gtk_widget_show (hbox3); gtk_container_add (GTK_CONTAINER (alignment2), hbox3); image2 = gtk_image_new_from_stock ("gtk-go-forward", GTK_ICON_SIZE_BUTTON); gtk_widget_show (image2); gtk_box_pack_start (GTK_BOX (hbox3), image2, FALSE, FALSE, 0); label2 = gtk_label_new_with_mnemonic ("下一个"); gtk_widget_show (label2); gtk_box_pack_start (GTK_BOX (hbox3), label2, FALSE, FALSE, 0); return button2; }static void chmsee_html_search(GtkWidget *widget, ChmSee_Search *sh_window) { gchar *text; gchar *text_utf; gboolean toggle_button; text = g_strdup_printf("%s", gtk_entry_get_text(GTK_ENTRY(sh_window->search_entry))); text_utf = g_locale_from_utf8(text, -1, NULL, NULL, NULL); toggle_button = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (sh_window->search_checkbutton)); gtk_html_engine_search (GTK_HTML( sh_window->search_chm_html ), (const gchar *)text_utf, toggle_button, TRUE, FALSE);}static void chmsee_html_search_next(GtkWidget *widget, ChmSee_Search *sh_window) { gtk_html_engine_search_next (GTK_HTML( sh_window->search_chm_html ));}static void search_entry_changed (GtkEntry *entry, ChmSee_Search *sh_window) { const gchar *text; gint text_length; text = gtk_entry_get_text (GTK_ENTRY (entry)); text_length = strlen(text); if (text_length >= 2) { gtk_widget_set_sensitive (sh_window->button2, TRUE); gtk_widget_set_sensitive (sh_window->button3, TRUE); } else { gtk_widget_set_sensitive (sh_window->button2, FALSE); gtk_widget_set_sensitive (sh_window->button3, FALSE); }}void create_search_window (GtkWidget *widget, ChmSee *window){ ChmSee_Search *sh_window; sh_window = g_new0(ChmSee_Search, 1); GtkWidget *search_window; GtkWidget *vbox1; GtkWidget *hseparator1; GtkWidget *hbuttonbox1; GtkWidget *button1; sh_window->search_chm_html = window->chm_html; search_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_container_set_border_width (GTK_CONTAINER (search_window), 10); gtk_window_set_title (GTK_WINDOW (search_window), "搜索当前页面"); gtk_window_set_resizable (GTK_WINDOW (search_window), FALSE); vbox1 = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox1); gtk_container_add (GTK_CONTAINER (search_window), vbox1); sh_window->search_entry = gtk_entry_new (); gtk_widget_show (sh_window->search_entry); gtk_box_pack_start (GTK_BOX (vbox1), sh_window->search_entry, FALSE, FALSE, 0); g_signal_connect (sh_window->search_entry, "changed", G_CALLBACK (search_entry_changed), sh_window); sh_window->search_checkbutton = gtk_check_button_new_with_mnemonic ("区分大小写"); gtk_widget_show (sh_window->search_checkbutton); gtk_box_pack_start (GTK_BOX (vbox1), sh_window->search_checkbutton, FALSE, FALSE, 4); hseparator1 = gtk_hseparator_new (); gtk_widget_show (hseparator1); gtk_box_pack_start (GTK_BOX (vbox1), hseparator1, FALSE, FALSE, 5); hbuttonbox1 = gtk_hbutton_box_new (); gtk_widget_show (hbuttonbox1); gtk_box_pack_start (GTK_BOX (vbox1), hbuttonbox1, FALSE, FALSE, 0); gtk_box_set_spacing (GTK_BOX (hbuttonbox1), 5); button1 = gtk_button_new_from_stock ("gtk-close"); gtk_widget_show (button1); gtk_container_add (GTK_CONTAINER (hbuttonbox1), button1); GTK_WIDGET_SET_FLAGS (button1, GTK_CAN_DEFAULT); sh_window->button2 = gtk_button_new_from_stock ("gtk-find"); gtk_widget_show (sh_window->button2); gtk_container_add (GTK_CONTAINER (hbuttonbox1), sh_window->button2); GTK_WIDGET_SET_FLAGS (sh_window->button2, GTK_CAN_DEFAULT); gtk_widget_set_sensitive (sh_window->button2, FALSE); sh_window->button3 = button_next_new(); gtk_widget_show (sh_window->button3); gtk_container_add (GTK_CONTAINER (hbuttonbox1), sh_window->button3); GTK_WIDGET_SET_FLAGS (sh_window->button3, GTK_CAN_DEFAULT); gtk_widget_set_sensitive (sh_window->button3, FALSE); g_signal_connect_swapped ((gpointer) search_window, "destroy", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (search_window)); g_signal_connect_swapped ((gpointer) button1, "clicked", G_CALLBACK (gtk_widget_destroy), GTK_OBJECT (search_window)); g_signal_connect ((gpointer) sh_window->button2, "clicked", G_CALLBACK (chmsee_html_search), sh_window); g_signal_connect ((gpointer) sh_window->button3, "clicked", G_CALLBACK (chmsee_html_search_next), sh_window); gtk_widget_show( search_window );}// End// 搜索目录代码
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -