diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-10-12 13:21:07 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-10-12 13:21:07 (EDT) |
commit | eab9e3a4e753a96c3d4c279d127c3d562beb4934 (patch) | |
tree | 3b3aabb5e37a562a982fd1b91cfbc00719fa8f29 /src | |
parent | a8ec2a404a8fdec019b72b46445fbc119432de15 (diff) | |
download | marquee-eab9e3a4e753a96c3d4c279d127c3d562beb4934.zip marquee-eab9e3a4e753a96c3d4c279d127c3d562beb4934.tar.gz marquee-eab9e3a4e753a96c3d4c279d127c3d562beb4934.tar.bz2 |
MqFindToolbar: New class
Diffstat (limited to 'src')
-rw-r--r-- | src/find-toolbar.c | 189 | ||||
-rw-r--r-- | src/find-toolbar.h | 60 | ||||
-rw-r--r-- | src/local.mk | 1 |
3 files changed, 250 insertions, 0 deletions
diff --git a/src/find-toolbar.c b/src/find-toolbar.c new file mode 100644 index 0000000..2e6e4ab --- /dev/null +++ b/src/find-toolbar.c @@ -0,0 +1,189 @@ +/* + * Revealable find toolbar + * + * Copyright (C) 2017 Patrick McDermott + * + * This file is part of Marquee. + * + * Marquee 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 3 of the License, or + * (at your option) any later version. + * + * Marquee 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 Marquee. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <glib.h> +#include <gtk/gtk.h> +#include <webkit2/webkit2.h> + +#include "find-toolbar.h" +#include "web-view.h" + +struct _MqFindToolbar { + GtkRevealer parent_instance; + MqWebView *web_view; + GtkWidget *search_entry; + GtkWidget *matches_label; + gboolean match_case; + gboolean searching; + WebKitFindController *find_controller; +}; + +enum { + PROP_WEB_VIEW = 1, + N_PROPERTIES +}; + +static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,}; + +struct _MqFindToolbarClass { + GtkRevealerClass parent_class; +}; + +G_DEFINE_TYPE(MqFindToolbar, mq_find_toolbar, GTK_TYPE_REVEALER) + +static void +get_property(GObject *object, guint property_id, GValue *value, + GParamSpec *pspec) +{ + MqFindToolbar *find_toolbar; + + find_toolbar = MQ_FIND_TOOLBAR(object); + + switch (property_id) { + case PROP_WEB_VIEW: + g_value_set_object(value, find_toolbar->web_view); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, + pspec); + break; + } +} + +static void +set_property(GObject *object, guint property_id, const GValue *value, + GParamSpec *pspec) +{ + MqFindToolbar *find_toolbar; + + find_toolbar = MQ_FIND_TOOLBAR(object); + + switch (property_id) { + case PROP_WEB_VIEW: + find_toolbar->web_view = g_value_get_object(value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, + pspec); + break; + } +} + +static void +mq_find_toolbar_class_init(MqFindToolbarClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->get_property = get_property; + object_class->set_property = set_property; + + obj_properties[PROP_WEB_VIEW] = g_param_spec_object( + "web-view", + "MqWebView", + "The associated MqWebView instance", + MQ_TYPE_WEB_VIEW, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB); + g_object_class_install_properties(object_class, N_PROPERTIES, + obj_properties); +} + +static void +mq_find_toolbar_init(MqFindToolbar *find_toolbar) +{ + GtkWidget *close_button; + GtkWidget *prev_button; + GtkWidget *next_button; + GtkWidget *match_case_button; + GtkWidget *box; + + /* Search entry */ + find_toolbar->search_entry = gtk_search_entry_new(); +// g_signal_connect(find_toolbar->search_entry, "search-changed", +// G_CALLBACK(find_search_changed_cb), find_toolbar); +// g_signal_connect(find_toolbar->search_entry, "key-press-event", +// G_CALLBACK(find_search_key_press_event_cb), find_toolbar); + + /* Previous button */ + prev_button = gtk_button_new_from_icon_name("go-up", + GTK_ICON_SIZE_BUTTON); + gtk_widget_set_tooltip_text(prev_button, "Find previous occurrence"); + gtk_widget_set_can_focus(prev_button, FALSE); +// g_signal_connect(prev_button, "clicked", +// G_CALLBACK(find_prev_clicked_cb), find_toolbar); + + /* Next button */ + next_button = gtk_button_new_from_icon_name("go-down", + GTK_ICON_SIZE_BUTTON); + gtk_widget_set_tooltip_text(next_button, "Find next occurrence"); + gtk_widget_set_can_focus(next_button, FALSE); +// g_signal_connect(next_button, "clicked", +// G_CALLBACK(find_next_clicked_cb), find_toolbar); + + /* Case sensitivity button */ + match_case_button = gtk_toggle_button_new_with_label("Match case"); + gtk_widget_set_tooltip_text(match_case_button, + "Search with case sensitivity"); + gtk_widget_set_can_focus(match_case_button, FALSE); +// g_signal_connect(match_case_button, "toggled", +// G_CALLBACK(find_match_case_toggled_cb), find_toolbar); + + /* Matches label */ + find_toolbar->matches_label = gtk_label_new(NULL); + + /* Close button */ + close_button = gtk_button_new_from_icon_name("window-close", + GTK_ICON_SIZE_BUTTON); + gtk_button_set_relief(GTK_BUTTON(close_button), GTK_RELIEF_NONE); + gtk_widget_set_tooltip_text(close_button, "Close find bar"); + gtk_widget_set_can_focus(close_button, FALSE); +// g_signal_connect(close_button, "clicked", +// G_CALLBACK(find_close_clicked_cb), find_toolbar); + + /* Box */ + box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); + gtk_box_pack_start(GTK_BOX(box), find_toolbar->search_entry, + FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), prev_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), next_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), match_case_button, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(box), find_toolbar->matches_label, + FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX(box), close_button, FALSE, FALSE, 0); + + /* Revealer */ + gtk_revealer_set_transition_type(GTK_REVEALER(find_toolbar), + GTK_REVEALER_TRANSITION_TYPE_SLIDE_DOWN); + gtk_container_add(GTK_CONTAINER(find_toolbar), box); + + find_toolbar->match_case = FALSE; + find_toolbar->searching = FALSE; + find_toolbar->find_controller = webkit_web_view_get_find_controller( + WEBKIT_WEB_VIEW(find_toolbar->web_view)); +} + +GtkWidget * +mq_find_toolbar_new(MqWebView *web_view) +{ + return GTK_WIDGET(g_object_new(MQ_TYPE_FIND_TOOLBAR, + "web-view", web_view, + NULL)); +} diff --git a/src/find-toolbar.h b/src/find-toolbar.h new file mode 100644 index 0000000..3ea3d82 --- /dev/null +++ b/src/find-toolbar.h @@ -0,0 +1,60 @@ +/* + * Revealable find toolbar + * + * Copyright (C) 2017 Patrick McDermott + * + * This file is part of Marquee. + * + * Marquee 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 3 of the License, or + * (at your option) any later version. + * + * Marquee 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 Marquee. If not, see <http://www.gnu.org/licenses/>. + */ + +typedef struct _MqFindToolbar MqFindToolbar; +typedef struct _MqFindToolbarClass MqFindToolbarClass; + +#ifndef MQ_FIND_TOOLBAR_H +#define MQ_FIND_TOOLBAR_H + +#include <gtk/gtk.h> +#include <webkit2/webkit2.h> + +#include "tab.h" + +G_BEGIN_DECLS + +#define MQ_TYPE_FIND_TOOLBAR (mq_find_toolbar_get_type()) +#define MQ_FIND_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + MQ_TYPE_FIND_TOOLBAR, MqFindToolbar)) +#define MQ_IS_FIND_TOOLBAR(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + MQ_TYPE_FIND_TOOLBAR)) +#define MQ_FIND_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + MQ_TYPE_FIND_TOOLBAR, \ + MqFindToolbarClass)) +#define MQ_IS_FIND_TOOLBAR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + MQ_TYPE_FIND_TOOLBAR)) +#define MQ_FIND_TOOLBAR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + MQ_TYPE_FIND_TOOLBAR, \ + MqFindToolbarClass)) + +GType +mq_find_toolbar_get_type(void); + +GtkWidget * +mq_find_toolbar_new(MqWebView *web_view); + +void +mq_find_toolbar_reveal(MqFindToolbar *find_toolbar); + +G_END_DECLS + +#endif /* MQ_FIND_TOOLBAR_H */ diff --git a/src/local.mk b/src/local.mk index 279748d..b3efd88 100644 --- a/src/local.mk +++ b/src/local.mk @@ -6,6 +6,7 @@ marquee_SOURCES += \ %reldir%/window.c \ %reldir%/tab.c \ %reldir%/tab-chrome.c \ + %reldir%/find-toolbar.c \ %reldir%/web-view.c \ %reldir%/html.c \ %reldir%/gpl-3-0.c \ |