2009-12-18 02:55:02 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2009 Mark Benjamin <netsurf-browser.org.MarkBenjamin@dfgh.net>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf 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; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Free text search (front component)
|
|
|
|
*/
|
2012-05-16 23:57:43 +04:00
|
|
|
#include <stdint.h>
|
2009-12-18 02:55:02 +03:00
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
2011-01-30 02:40:22 +03:00
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
#include "utils/config.h"
|
2014-10-16 12:53:55 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
2009-12-18 02:55:02 +03:00
|
|
|
#include "content/content.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/hlcache.h"
|
2014-02-08 23:21:22 +04:00
|
|
|
#include "desktop/browser.h"
|
2009-12-18 02:55:02 +03:00
|
|
|
#include "desktop/search.h"
|
|
|
|
#include "desktop/searchweb.h"
|
2014-10-16 12:53:55 +04:00
|
|
|
#include "desktop/gui_search.h"
|
2009-12-18 02:55:02 +03:00
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
#include "gtk/compat.h"
|
|
|
|
#include "gtk/search.h"
|
|
|
|
#include "gtk/scaffolding.h"
|
|
|
|
#include "gtk/window.h"
|
2014-03-18 20:02:21 +04:00
|
|
|
|
|
|
|
/**
|
2014-03-19 02:32:52 +04:00
|
|
|
* activate search forwards button in gui.
|
|
|
|
*
|
|
|
|
* \param active activate/inactivate
|
2014-11-08 15:35:11 +03:00
|
|
|
* \param gw The gui window in which to activite the search button in.
|
2014-03-19 02:32:52 +04:00
|
|
|
*/
|
|
|
|
static void nsgtk_search_set_forward_state(bool active, struct gui_window *gw)
|
2014-03-18 20:02:21 +04:00
|
|
|
{
|
|
|
|
if (gw != NULL && nsgtk_get_browser_window(gw) != NULL) {
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = nsgtk_get_scaffold(gw);
|
2014-03-18 20:02:21 +04:00
|
|
|
gtk_widget_set_sensitive(
|
|
|
|
GTK_WIDGET(nsgtk_scaffolding_search(g)->buttons[1]),
|
|
|
|
active);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
/**
|
|
|
|
* activate search back button in gui.
|
|
|
|
*
|
|
|
|
* \param active activate/inactivate
|
2014-11-08 15:35:11 +03:00
|
|
|
* \param gw The gui window in which to activite the search button in.
|
2014-03-19 02:32:52 +04:00
|
|
|
*/
|
|
|
|
static void nsgtk_search_set_back_state(bool active, struct gui_window *gw)
|
2014-03-18 20:02:21 +04:00
|
|
|
{
|
|
|
|
if (gw != NULL && nsgtk_get_browser_window(gw) != NULL) {
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = nsgtk_get_scaffold(gw);
|
2014-03-18 20:02:21 +04:00
|
|
|
gtk_widget_set_sensitive(GTK_WIDGET(nsgtk_scaffolding_search(
|
|
|
|
g)->buttons[0]), active);
|
|
|
|
}
|
|
|
|
}
|
2009-12-18 02:55:02 +03:00
|
|
|
|
|
|
|
/** connected to the search forward button */
|
|
|
|
|
|
|
|
gboolean nsgtk_search_forward_button_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2014-02-08 23:21:22 +04:00
|
|
|
struct gui_window *gw = nsgtk_scaffolding_top_level(g);
|
|
|
|
struct browser_window *bw = nsgtk_get_browser_window(gw);
|
2012-01-07 03:42:22 +04:00
|
|
|
|
|
|
|
assert(bw);
|
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
search_flags_t flags = SEARCH_FLAG_FORWARDS |
|
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
|
|
nsgtk_scaffolding_search(g)->caseSens)) ?
|
|
|
|
SEARCH_FLAG_CASE_SENSITIVE : 0) |
|
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
|
|
nsgtk_scaffolding_search(g)->checkAll)) ?
|
|
|
|
SEARCH_FLAG_SHOWALL : 0);
|
2013-05-07 17:41:40 +04:00
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
browser_window_search(bw, gw, flags,
|
2013-05-07 17:41:40 +04:00
|
|
|
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
|
2009-12-18 02:55:02 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** connected to the search back button */
|
|
|
|
|
|
|
|
gboolean nsgtk_search_back_button_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2014-02-08 23:21:22 +04:00
|
|
|
struct gui_window *gw = nsgtk_scaffolding_top_level(g);
|
|
|
|
struct browser_window *bw = nsgtk_get_browser_window(gw);
|
2012-01-07 03:42:22 +04:00
|
|
|
|
|
|
|
assert(bw);
|
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
search_flags_t flags = 0 |(gtk_toggle_button_get_active(
|
|
|
|
GTK_TOGGLE_BUTTON(
|
|
|
|
nsgtk_scaffolding_search(g)->caseSens)) ?
|
|
|
|
SEARCH_FLAG_CASE_SENSITIVE : 0) |
|
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
|
|
|
nsgtk_scaffolding_search(g)->checkAll)) ?
|
|
|
|
SEARCH_FLAG_SHOWALL : 0);
|
2013-05-07 17:41:40 +04:00
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
browser_window_search(bw, gw, flags,
|
2013-05-07 17:41:40 +04:00
|
|
|
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
|
2009-12-18 02:55:02 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** connected to the search close button */
|
|
|
|
|
|
|
|
gboolean nsgtk_search_close_button_clicked(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_scaffolding_toggle_search_bar_visibility(g);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** connected to the search entry [typing] */
|
|
|
|
|
|
|
|
gboolean nsgtk_search_entry_changed(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2014-02-08 23:21:22 +04:00
|
|
|
struct gui_window *gw = nsgtk_scaffolding_top_level(g);
|
|
|
|
struct browser_window *bw = nsgtk_get_browser_window(gw);
|
2014-07-27 21:06:07 +04:00
|
|
|
search_flags_t flags;
|
2011-08-24 16:31:27 +04:00
|
|
|
|
2012-01-07 03:10:04 +04:00
|
|
|
assert(bw != NULL);
|
|
|
|
|
2014-03-18 20:02:21 +04:00
|
|
|
nsgtk_search_set_forward_state(true, gw);
|
|
|
|
nsgtk_search_set_back_state(true, gw);
|
2012-01-07 03:10:04 +04:00
|
|
|
|
2014-07-27 21:06:07 +04:00
|
|
|
flags = SEARCH_FLAG_FORWARDS |
|
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
2012-01-07 03:10:04 +04:00
|
|
|
nsgtk_scaffolding_search(g)->caseSens)) ?
|
|
|
|
SEARCH_FLAG_CASE_SENSITIVE : 0) |
|
2014-07-27 21:06:07 +04:00
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
2012-01-07 03:10:04 +04:00
|
|
|
nsgtk_scaffolding_search(g)->checkAll)) ?
|
|
|
|
SEARCH_FLAG_SHOWALL : 0);
|
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
browser_window_search(bw, gw, flags,
|
2013-05-07 17:41:40 +04:00
|
|
|
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
|
2009-12-18 02:55:02 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** connected to the search entry [return key] */
|
|
|
|
|
|
|
|
gboolean nsgtk_search_entry_activate(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2014-02-08 23:21:22 +04:00
|
|
|
struct gui_window *gw = nsgtk_scaffolding_top_level(g);
|
|
|
|
struct browser_window *bw = nsgtk_get_browser_window(gw);
|
2014-07-27 21:06:07 +04:00
|
|
|
search_flags_t flags;
|
2012-01-07 03:42:22 +04:00
|
|
|
|
|
|
|
assert(bw);
|
|
|
|
|
2014-07-27 21:06:07 +04:00
|
|
|
flags = SEARCH_FLAG_FORWARDS |
|
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_scaffolding_search(g)->caseSens)) ?
|
|
|
|
SEARCH_FLAG_CASE_SENSITIVE : 0) |
|
2014-07-27 21:06:07 +04:00
|
|
|
(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_scaffolding_search(g)->checkAll)) ?
|
|
|
|
SEARCH_FLAG_SHOWALL : 0);
|
2011-08-24 16:31:27 +04:00
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
browser_window_search(bw, gw, flags,
|
2013-05-07 17:41:40 +04:00
|
|
|
gtk_entry_get_text(nsgtk_scaffolding_search(g)->entry));
|
2009-12-18 02:55:02 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** allows escape key to close search bar too */
|
|
|
|
|
2014-07-27 21:06:07 +04:00
|
|
|
gboolean
|
|
|
|
nsgtk_search_entry_key(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
2009-12-18 02:55:02 +03:00
|
|
|
{
|
2012-05-16 23:57:43 +04:00
|
|
|
if (event->keyval == GDK_KEY(Escape)) {
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2009-12-18 02:55:02 +03:00
|
|
|
nsgtk_scaffolding_toggle_search_bar_visibility(g);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** connected to the websearch entry [return key] */
|
|
|
|
|
|
|
|
gboolean nsgtk_websearch_activate(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = data;
|
2014-05-25 03:57:48 +04:00
|
|
|
nserror ret;
|
|
|
|
nsurl *url;
|
|
|
|
|
|
|
|
ret = search_web_omni(
|
|
|
|
gtk_entry_get_text(GTK_ENTRY(nsgtk_scaffolding_websearch(g))),
|
|
|
|
SEARCH_WEB_OMNI_SEARCHONLY,
|
|
|
|
&url);
|
|
|
|
if (ret == NSERROR_OK) {
|
|
|
|
temp_open_background = 0;
|
|
|
|
ret = browser_window_create(
|
|
|
|
BW_CREATE_HISTORY | BW_CREATE_TAB,
|
|
|
|
url,
|
|
|
|
NULL,
|
|
|
|
nsgtk_get_browser_window(nsgtk_scaffolding_top_level(g)),
|
|
|
|
NULL);
|
|
|
|
temp_open_background = -1;
|
|
|
|
nsurl_unref(url);
|
|
|
|
}
|
|
|
|
if (ret != NSERROR_OK) {
|
|
|
|
warn_user(messages_get_errorcode(ret), 0);
|
|
|
|
}
|
|
|
|
|
2009-12-18 02:55:02 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* allows a click in the websearch entry field to clear the name of the
|
|
|
|
* provider
|
|
|
|
*/
|
|
|
|
|
|
|
|
gboolean nsgtk_websearch_clear(GtkWidget *widget, GdkEventFocus *f,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2014-07-27 21:06:07 +04:00
|
|
|
struct nsgtk_scaffolding *g = (struct nsgtk_scaffolding *)data;
|
2009-12-18 02:55:02 +03:00
|
|
|
gtk_editable_select_region(GTK_EDITABLE(
|
|
|
|
nsgtk_scaffolding_websearch(g)), 0, -1);
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(nsgtk_scaffolding_websearch(g)));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-19 02:32:52 +04:00
|
|
|
static struct gui_search_table search_table = {
|
|
|
|
.forward_state = (void *)nsgtk_search_set_forward_state,
|
|
|
|
.back_state = (void *)nsgtk_search_set_back_state,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gui_search_table *nsgtk_search_table = &search_table;
|