more openssl 1.1 support stuff
[rofl0r-ixchat.git] / src / fe-gtk / search.c
blobd62e79c71e25401b586c799e1f689f4858ff8967
1 /* X-Chat
2 * Copyright (C) 1998 Peter Zelezny.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19 #include <stdio.h>
20 #include <string.h>
21 #include <stdlib.h>
23 #include "fe-gtk.h"
25 #include <gtk/gtkentry.h>
26 #include <gtk/gtkhbox.h>
27 #include <gtk/gtkvbox.h>
28 #include <gtk/gtklabel.h>
29 #include <gtk/gtkstock.h>
30 #include <gtk/gtkhbbox.h>
31 #include <gtk/gtkhseparator.h>
32 #include <gtk/gtkvseparator.h>
33 #include <gtk/gtkradiobutton.h>
34 #include <gtk/gtktogglebutton.h>
35 #include <gdk/gdkkeysyms.h>
37 #include "../common/xchat.h"
38 #include "../common/fe.h"
39 #include "../common/util.h"
40 #include "../common/xchatc.h"
41 #include "gtkutil.h"
42 #include "xtext.h"
43 #include "maingui.h"
46 static textentry *last; /* our last search pos */
47 static int case_match = 0;
48 static int search_backward = 0;
51 static void
52 search_search (session * sess, const gchar *text)
54 if (!is_session (sess))
56 fe_message (_("The window you opened this Search "
57 "for doesn't exist anymore."), FE_MSG_ERROR);
58 return;
61 last = gtk_xtext_search (GTK_XTEXT (sess->gui->xtext), text,
62 last, case_match, search_backward);
63 if (!last)
64 fe_message (_("Search hit end, not found."), FE_MSG_ERROR);
67 static void
68 search_find_cb (GtkWidget * button, session * sess)
70 GtkEntry *entry;
71 const gchar *text;
73 entry = g_object_get_data (G_OBJECT (button), "e");
74 text = gtk_entry_get_text (entry);
75 search_search (sess, text);
78 static void
79 search_close_cb (GtkWidget * button, GtkWidget * win)
81 gtk_widget_destroy (win);
84 static void
85 search_entry_cb (GtkWidget * entry, session * sess)
87 search_search (sess, gtk_entry_get_text (GTK_ENTRY (entry)));
90 static gboolean
91 search_key_cb (GtkWidget * window, GdkEventKey * key, gpointer userdata)
93 if (key->keyval == GDK_Escape)
94 gtk_widget_destroy (window);
95 return FALSE;
98 static void
99 search_caseign_cb (GtkToggleButton * but, session * sess)
101 case_match = (but->active)? 1: 0;
104 static void
105 search_dirbwd_cb (GtkToggleButton * but, session * sess)
107 search_backward = (but->active)? 1: 0;
110 void
111 search_open (session * sess)
113 GtkWidget *win, *hbox, *vbox, *entry, *wid;
115 last = NULL;
116 win = mg_create_generic_tab ("search", _("XChat: Search"), TRUE, FALSE,
117 NULL, NULL, 0, 0, &vbox, 0);
118 gtk_container_set_border_width (GTK_CONTAINER (win), 12);
119 gtk_box_set_spacing (GTK_BOX (vbox), 4);
121 hbox = gtk_hbox_new (0, 10);
122 gtk_container_add (GTK_CONTAINER (vbox), hbox);
123 gtk_widget_show (hbox);
125 gtkutil_label_new (_("Find:"), hbox);
127 entry = gtk_entry_new ();
128 g_signal_connect (G_OBJECT (entry), "activate",
129 G_CALLBACK (search_entry_cb), sess);
130 gtk_container_add (GTK_CONTAINER (hbox), entry);
131 gtk_widget_show (entry);
132 gtk_widget_grab_focus (entry);
134 wid = gtk_check_button_new_with_mnemonic (_("_Match case"));
135 GTK_TOGGLE_BUTTON (wid)->active = case_match;
136 g_signal_connect (G_OBJECT (wid), "toggled", G_CALLBACK (search_caseign_cb), sess);
137 gtk_container_add (GTK_CONTAINER (vbox), wid);
138 gtk_widget_show (wid);
140 wid = gtk_check_button_new_with_mnemonic (_("Search _backwards"));
141 GTK_TOGGLE_BUTTON (wid)->active = search_backward;
142 g_signal_connect (G_OBJECT (wid), "toggled", G_CALLBACK (search_dirbwd_cb), sess);
143 gtk_container_add (GTK_CONTAINER (vbox), wid);
144 gtk_widget_show (wid);
146 hbox = gtk_hbutton_box_new ();
147 gtk_box_pack_start (GTK_BOX (vbox), hbox, 0, 0, 4);
148 gtk_widget_show (hbox);
150 gtkutil_button (hbox, GTK_STOCK_CLOSE, 0, search_close_cb, win,
151 _("_Close"));
152 wid = gtkutil_button (hbox, GTK_STOCK_FIND, 0, search_find_cb, sess,
153 _("_Find"));
154 g_object_set_data (G_OBJECT (wid), "e", entry);
156 g_signal_connect (G_OBJECT (win), "key-press-event", G_CALLBACK (search_key_cb), win);
158 gtk_widget_show (win);