From d1dce1a55df4d1e772a09e734435cced16679c9f Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 13 Oct 2017 03:56:08 -0400 Subject: MqNavigationToolbar: New class Replaces MqTabChrome. --- (limited to 'src') diff --git a/src/local.mk b/src/local.mk index 6573473..fcfeba7 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%/navigation-toolbar.c \ %reldir%/back-forward-button-box.c \ %reldir%/stop-reload-button.c \ %reldir%/uri-entry.c \ diff --git a/src/navigation-toolbar.c b/src/navigation-toolbar.c new file mode 100644 index 0000000..4d6cc0b --- /dev/null +++ b/src/navigation-toolbar.c @@ -0,0 +1,253 @@ +/* + * Navigation 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 . + */ + +#include +#include +#include + +#include "navigation-toolbar.h" +#include "config.h" +#include "tab.h" +#include "find-toolbar.h" +#include "web-view.h" +#include "back-forward-button-box.h" +#include "stop-reload-button.h" +#include "uri-entry.h" +#include "home-button.h" +#include "main-menu.h" + +struct _MqNavigationToolbar { + GtkToolbar parent_instance; + MqConfig *config; + MqTab *tab; + MqFindToolbar *find_toolbar; + MqWebView *web_view; + gchar *uri; +}; + +enum { + PROP_CONFIG = 1, + PROP_TAB, + PROP_FIND_TOOLBAR, + PROP_WEB_VIEW, + PROP_URI, + N_PROPERTIES +}; + +static GParamSpec *obj_properties[N_PROPERTIES] = {NULL,}; + +struct _MqNavigationToolbarClass { + GtkToolbarClass parent_class; +}; + +G_DEFINE_TYPE(MqNavigationToolbar, mq_navigation_toolbar, GTK_TYPE_TOOLBAR) + +static void +constructed(GObject *object) +{ + MqNavigationToolbar *navigation_toolbar; + GtkToolItem *back_forward_button_box; + GtkToolItem *stop_reload_button; + GtkToolItem *uri_entry; + GtkToolItem *home_button; + GtkToolItem *menu_button; + + if (G_OBJECT_CLASS(mq_navigation_toolbar_parent_class)->constructed) { + G_OBJECT_CLASS(mq_navigation_toolbar_parent_class)->constructed( + object); + } + + navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object); + + /* Back/forward button box */ + back_forward_button_box = mq_back_forward_button_box_new( + navigation_toolbar->web_view); + + /* Stop/reload button */ + stop_reload_button = mq_stop_reload_button_new( + navigation_toolbar->web_view); + + /* URI entry */ + uri_entry = mq_uri_entry_new(navigation_toolbar->web_view, + navigation_toolbar->uri); + + /* Home button */ + home_button = mq_home_button_new(navigation_toolbar->config, + navigation_toolbar->web_view); + + /* Menu button */ + menu_button = mq_main_menu_new(navigation_toolbar->tab, + navigation_toolbar->find_toolbar, navigation_toolbar->web_view); + + /* Navigation toolbar */ + gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), + back_forward_button_box, -1); + gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), + stop_reload_button, -1); + gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), uri_entry, -1); + gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), home_button, -1); + gtk_toolbar_insert(GTK_TOOLBAR(navigation_toolbar), menu_button, -1); + + gtk_widget_set_hexpand(GTK_WIDGET(navigation_toolbar), TRUE); +} + +static void +finalize(GObject *object) +{ + MqNavigationToolbar *navigation_toolbar; + + navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object); + + if (navigation_toolbar->uri) { + g_free(navigation_toolbar->uri); + } +} + +static void +get_property(GObject *object, guint property_id, GValue *value, + GParamSpec *pspec) +{ + MqNavigationToolbar *navigation_toolbar; + + navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object); + + switch (property_id) { + case PROP_CONFIG: + g_value_set_pointer(value, navigation_toolbar->config); + break; + case PROP_TAB: + g_value_set_pointer(value, navigation_toolbar->tab); + break; + case PROP_FIND_TOOLBAR: + g_value_set_object(value, + navigation_toolbar->find_toolbar); + case PROP_WEB_VIEW: + g_value_set_object(value, navigation_toolbar->web_view); + break; + case PROP_URI: + g_value_set_string(value, navigation_toolbar->uri); + 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) +{ + MqNavigationToolbar *navigation_toolbar; + + navigation_toolbar = MQ_NAVIGATION_TOOLBAR(object); + + switch (property_id) { + case PROP_CONFIG: + navigation_toolbar->config = g_value_get_pointer(value); + break; + case PROP_TAB: + navigation_toolbar->tab = g_value_get_pointer(value); + break; + case PROP_FIND_TOOLBAR: + navigation_toolbar->find_toolbar = + g_value_get_object(value); + break; + case PROP_WEB_VIEW: + navigation_toolbar->web_view = + g_value_get_object(value); + break; + case PROP_URI: + navigation_toolbar->uri = g_strdup(g_value_get_string( + value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, + pspec); + break; + } +} + +static void +mq_navigation_toolbar_class_init(MqNavigationToolbarClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->constructed = constructed; + object_class->finalize = finalize; + object_class->get_property = get_property; + object_class->set_property = set_property; + + obj_properties[PROP_CONFIG] = g_param_spec_pointer( + "config", + "MqConfig", + "The application's MqConfig instance", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB); + obj_properties[PROP_TAB] = g_param_spec_pointer( + "tab", + "MqTab", + "The ancestral MqTab instance", + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB); + obj_properties[PROP_FIND_TOOLBAR] = g_param_spec_object( + "find-toolbar", + "MqFindToolbar", + "The associated MqFindToolbar instance", + MQ_TYPE_FIND_TOOLBAR, + G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB); + 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); + obj_properties[PROP_URI] = g_param_spec_string( + "uri", + "URI", + "The URI to load", + "", + 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_navigation_toolbar_init( + MqNavigationToolbar G_GNUC_UNUSED *navigation_toolbar) +{ +} + +GtkWidget * +mq_navigation_toolbar_new(MqConfig *config, MqTab *tab, + MqFindToolbar *find_toolbar, MqWebView *web_view, const gchar *uri) +{ + return g_object_new(MQ_TYPE_NAVIGATION_TOOLBAR, + "config", config, + "tab", tab, + "find-toolbar", find_toolbar, + "web-view", web_view, + "uri", uri, + NULL); +} diff --git a/src/navigation-toolbar.h b/src/navigation-toolbar.h new file mode 100644 index 0000000..47ecc7d --- /dev/null +++ b/src/navigation-toolbar.h @@ -0,0 +1,61 @@ +/* + * Navigation 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 . + */ + +typedef struct _MqNavigationToolbar MqNavigationToolbar; +typedef struct _MqNavigationToolbarClass MqNavigationToolbarClass; + +#ifndef MQ_NAVIGATION_TOOLBAR_H +#define MQ_NAVIGATION_TOOLBAR_H + +#include + +#include "tab.h" +#include "find-toolbar.h" +#include "web-view.h" + +G_BEGIN_DECLS + +#define MQ_TYPE_NAVIGATION_TOOLBAR \ + (mq_navigation_toolbar_get_type()) +#define MQ_NAVIGATION_TOOLBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST((obj), MQ_TYPE_NAVIGATION_TOOLBAR, \ + MqNavigationToolbar)) +#define MQ_IS_NAVIGATION_TOOLBAR(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE((obj), MQ_TYPE_NAVIGATION_TOOLBAR)) +#define MQ_NAVIGATION_TOOLBAR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST((klass), MQ_TYPE_NAVIGATION_TOOLBAR, \ + MqNavigationToolbarClass)) +#define MQ_IS_NAVIGATION_TOOLBAR_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE( (klass), MQ_TYPE_NAVIGATION_TOOLBAR)) +#define MQ_NAVIGATION_TOOLBAR_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS((obj), MQ_TYPE_NAVIGATION_TOOLBAR, \ + MqNavigationToolbarClass)) + +GType +mq_navigation_toolbar_get_type(void); + +GtkWidget * +mq_navigation_toolbar_new(MqConfig *config, MqTab *tab, + MqFindToolbar *find_toolbar, MqWebView *web_view, const gchar *uri); + +G_END_DECLS + +#endif /* MQ_NAVIGATION_TOOLBAR_H */ -- cgit v0.9.1