2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gdk/gdkkeysyms.h>
28 #include <gtk/gtkwidget.h>
29 #include <gtk/gtkwindow.h>
30 #include <gtk/gtkvbox.h>
31 #include <gtk/gtktable.h>
32 #include <gtk/gtklabel.h>
33 #include <gtk/gtkentry.h>
34 #include <gtk/gtkhbox.h>
35 #include <gtk/gtkcheckbutton.h>
36 #include <gtk/gtkhbbox.h>
37 #include <gtk/gtkbutton.h>
38 #include <gtk/gtkctree.h>
45 #include "message_search.h"
46 #include "messageview.h"
49 #include "manage_window.h"
50 #include "alertpanel.h"
52 static GtkWidget
*window
;
53 static GtkWidget
*body_entry
;
54 static GtkWidget
*case_checkbtn
;
55 static GtkWidget
*backward_checkbtn
;
56 static GtkWidget
*search_btn
;
57 static GtkWidget
*clear_btn
;
58 static GtkWidget
*close_btn
;
60 static void message_search_create(MessageView
*summaryview
);
61 static void message_search_execute(GtkButton
*button
, gpointer data
);
62 static void message_search_clear(GtkButton
*button
, gpointer data
);
63 static void body_activated(void);
64 static void key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
);
66 void message_search(MessageView
*messageview
)
69 message_search_create(messageview
);
71 gtk_widget_hide(window
);
73 gtk_widget_grab_focus(search_btn
);
74 gtk_widget_grab_focus(body_entry
);
75 gtk_widget_show(window
);
78 static void message_search_create(MessageView
*messageview
)
82 GtkWidget
*body_label
;
83 GtkWidget
*checkbtn_hbox
;
84 GtkWidget
*confirm_area
;
86 window
= gtk_window_new (GTK_WINDOW_DIALOG
);
87 gtk_window_set_title (GTK_WINDOW (window
),
88 _("Find in current message"));
89 gtk_widget_set_usize (window
, 450, -1);
90 gtk_window_set_policy(GTK_WINDOW(window
), FALSE
, TRUE
, TRUE
);
91 gtk_container_set_border_width (GTK_CONTAINER (window
), 8);
92 gtk_signal_connect(GTK_OBJECT(window
), "delete_event",
93 GTK_SIGNAL_FUNC(gtk_widget_hide_on_delete
), NULL
);
94 gtk_signal_connect(GTK_OBJECT(window
), "key_press_event",
95 GTK_SIGNAL_FUNC(key_pressed
), NULL
);
96 gtk_signal_connect(GTK_OBJECT(window
), "focus_in_event",
97 GTK_SIGNAL_FUNC(manage_window_focus_in
), NULL
);
98 gtk_signal_connect(GTK_OBJECT(window
), "focus_out_event",
99 GTK_SIGNAL_FUNC(manage_window_focus_out
), NULL
);
101 vbox1
= gtk_vbox_new (FALSE
, 0);
102 gtk_widget_show (vbox1
);
103 gtk_container_add (GTK_CONTAINER (window
), vbox1
);
105 hbox1
= gtk_hbox_new (FALSE
, 8);
106 gtk_widget_show (hbox1
);
107 gtk_box_pack_start (GTK_BOX (vbox1
), hbox1
, TRUE
, TRUE
, 0);
109 body_label
= gtk_label_new (_("Find text:"));
110 gtk_widget_show (body_label
);
111 gtk_box_pack_start (GTK_BOX (hbox1
), body_label
, FALSE
, FALSE
, 0);
113 body_entry
= gtk_entry_new ();
114 gtk_widget_show (body_entry
);
115 gtk_box_pack_start (GTK_BOX (hbox1
), body_entry
, TRUE
, TRUE
, 0);
116 gtk_signal_connect(GTK_OBJECT(body_entry
), "activate",
117 GTK_SIGNAL_FUNC(body_activated
), messageview
);
119 checkbtn_hbox
= gtk_hbox_new (FALSE
, 8);
120 gtk_widget_show (checkbtn_hbox
);
121 gtk_box_pack_start (GTK_BOX (vbox1
), checkbtn_hbox
, TRUE
, TRUE
, 0);
122 gtk_container_set_border_width (GTK_CONTAINER (checkbtn_hbox
), 8);
124 case_checkbtn
= gtk_check_button_new_with_label (_("Case sensitive"));
125 gtk_widget_show (case_checkbtn
);
126 gtk_box_pack_start (GTK_BOX (checkbtn_hbox
), case_checkbtn
,
130 gtk_check_button_new_with_label (_("Backward search"));
131 gtk_widget_show (backward_checkbtn
);
132 gtk_box_pack_start (GTK_BOX (checkbtn_hbox
), backward_checkbtn
,
135 gtkut_button_set_create(&confirm_area
,
136 &search_btn
, _("Search"),
137 &clear_btn
, _("Clear"),
138 &close_btn
, _("Close"));
139 gtk_widget_show (confirm_area
);
140 gtk_box_pack_start (GTK_BOX (vbox1
), confirm_area
, FALSE
, FALSE
, 0);
141 gtk_widget_grab_default(search_btn
);
143 gtk_signal_connect(GTK_OBJECT(search_btn
), "clicked",
144 GTK_SIGNAL_FUNC(message_search_execute
),
146 gtk_signal_connect(GTK_OBJECT(clear_btn
), "clicked",
147 GTK_SIGNAL_FUNC(message_search_clear
),
149 gtk_signal_connect_object(GTK_OBJECT(close_btn
), "clicked",
150 GTK_SIGNAL_FUNC(gtk_widget_hide
),
154 static void message_search_execute(GtkButton
*button
, gpointer data
)
156 MessageView
*messageview
= data
;
159 gboolean all_searched
= FALSE
;
162 body_str
= gtk_entry_get_text(GTK_ENTRY(body_entry
));
163 if (*body_str
== '\0') return;
165 case_sens
= gtk_toggle_button_get_active
166 (GTK_TOGGLE_BUTTON(case_checkbtn
));
167 backward
= gtk_toggle_button_get_active
168 (GTK_TOGGLE_BUTTON(backward_checkbtn
));
175 if (messageview_search_string_backward
176 (messageview
, body_str
, case_sens
) == TRUE
)
179 if (messageview_search_string
180 (messageview
, body_str
, case_sens
) == TRUE
)
187 _("Search string not found."));
194 str
= _("Beginning of message reached; "
195 "continue from end?");
197 str
= _("End of message reached; "
198 "continue from beginning?");
200 val
= alertpanel(_("Search finished"), str
,
201 _("Yes"), _("No"), NULL
);
202 if (G_ALERTDEFAULT
== val
) {
203 manage_window_focus_in(window
, NULL
, NULL
);
204 messageview_set_position(messageview
,
211 static void message_search_clear(GtkButton
*button
, gpointer data
)
213 gtk_editable_delete_text(GTK_EDITABLE(body_entry
), 0, -1);
216 static void body_activated(void)
218 gtk_button_clicked(GTK_BUTTON(search_btn
));
221 static void key_pressed(GtkWidget
*widget
, GdkEventKey
*event
, gpointer data
)
223 if (event
&& event
->keyval
== GDK_Escape
)
224 gtk_widget_hide(window
);