Initial revision, simple copy paste works
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,4 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/README Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,5 @@
+A rewrite of the GtkIMHTML widget found in Pidgin. +This is highly experimental right now and might eat babies, we're not sure yet. So proceed with caution :-D --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/meson.build Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,100 @@
+############################################################################### +############################################################################### +project('gtkimhtml', 'c', version : '0.1.0-dev', + meson_version : '>=0.37.0', + default_options : ['c_std=c99']) +parts = meson.project_version().split('-') +parts = parts[0].split('.') +GTKIMHTML_MAJOR_VERSION = parts[0] +version_conf = configuration_data() +version_conf.set('GTKIMHTML_MAJOR_VERSION', GTKIMHTML_MAJOR_VERSION) +version_conf.set('GTKIMHTML_MINOR_VERSION', parts[1]) +version_conf.set('GTKIMHTML_MICRO_VERSION', parts[2]) +version_conf.set('GTKIMHTML_EXTRA_VERSION', extra) +version_conf.set('GTKIMHTML_VERSION', meson.project_version()) +LOCALE_DIR = join_paths(get_option('prefix'), get_option('localedir')) +add_project_arguments('-DLOCALEDIR="@0@"'.format(LOCALE_DIR), language : 'c') +############################################################################### +############################################################################### +pkgconfig = import('pkgconfig') +GLIB = dependency('glib-2.0', version : '>=2.34.0') +GOBJECT = dependency('gobject-2.0') +GTK3 = dependency('gtk+-3.0', version : '>=3.0.0') +GUMBO = dependency('gumbo', version : '>=0.10') +############################################################################### +############################################################################### +GETTEXT_PACKAGE = 'gtkimhtml' +add_project_arguments('-DGETTEXT_PACKAGE="@0@"'.format(GETTEXT_PACKAGE), +############################################################################### +############################################################################### +compiler = meson.get_compiler('c') + '-DPREFIX="@0@"'.format(get_option('prefix')), + '-DLIBDIR="@0@"'.format(get_option('libdir')), +if compiler.has_argument('-Wformat') + add_project_arguments('-Wformat', language : 'c') + if compiler.has_multi_arguments(['-Wformat', '-Werror=format-security']) + add_project_arguments('-Werror=format-security', language : 'c') +# check if we're using gcc +if compiler.get_id() == 'gcc' or host_machine.platform() == 'darwin' + '-DGTKIMHTML_UNUSED=__attribute__((unused))', +toplevel_inc = include_directories('.') +############################################################################### +############################################################################### +############################################################################### +############################################################################### +install_data('ChangeLog', 'INSTALL', 'README', 'HACKING', + install_dir : join_paths(get_option('datadir'), 'doc', 'gtkimhtml'), --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/meson_options.txt Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,15 @@
+############################################################################### +############################################################################### + 'gobject-introspection', + type : 'boolean', value : true, + description : 'Whether or not to build a GObject Introspection type library' + type : 'boolean', value : true, + description : 'Install translation files' --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/po/meson.build Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,3 @@
+# GETTEXTIZE_TRANSLATIONS(UPDATE) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gtkimhtmlbuffer.c Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,168 @@
+ * Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. +#include "gtkimhtmlbuffer.h" +#include "gtkimhtmltagtable.h" +G_DEFINE_TYPE(GtkIMHTMLBuffer, gtk_imhtml_buffer, GTK_TYPE_TEXT_BUFFER) +/****************************************************************************** + *****************************************************************************/ +_gtk_imhtml_buffer_insert_text_parent(GtkTextBuffer *buffer, + GTK_TEXT_BUFFER_CLASS(gtk_imhtml_buffer_parent_class)->insert_text( + g_utf8_strlen(new_text, -1) +_gtk_imhtml_buffer_insert_text_helper(GtkTextBuffer *buffer, + GtkTextTag *tag = NULL; + GumboVector *children = NULL; + const gchar *tag_name = NULL; + gint i = 0, start_pos, length = 0; + start_pos = gtk_text_iter_get_offset(pos); + switch(node->v.element.tag) { + tag_name = gumbo_normalized_tagname(node->v.element.tag); + tag = gtk_text_tag_table_lookup( + gtk_text_buffer_get_tag_table(buffer), + children = &node->v.element.children; + for(i = 0; i < children->length; i++) { + GumboNode *child = (GumboNode *)children->data[i]; + if(child->type == GUMBO_NODE_TEXT || child->type == GUMBO_NODE_WHITESPACE) { + gint text_length = g_utf8_strlen(child->v.text.text, -1); + _gtk_imhtml_buffer_insert_text_parent(buffer, pos, child->v.text.text); + /* now adjust pos to the new insertion point */ + gtk_text_buffer_get_iter_at_offset( + gtk_text_iter_get_offset(pos) + text_length + } else if(child->type == GUMBO_NODE_ELEMENT || child->type == GUMBO_NODE_TEMPLATE) { + length += _gtk_imhtml_buffer_insert_text_helper(buffer, pos, child, str); + GtkTextIter start, end; + gtk_text_buffer_get_iter_at_offset(buffer, &start, start_pos); + gtk_text_buffer_get_iter_at_offset(buffer, &end, start_pos + length); + gtk_text_buffer_apply_tag( +/****************************************************************************** + * GtkTextBuffer Implementation + *****************************************************************************/ +gtk_imthml_buffer_insert_text(GtkTextBuffer *buffer, + GString *str = g_string_new(""); + GumboOutput *output = gumbo_parse(new_text); + _gtk_imhtml_buffer_insert_text_helper(buffer, pos, output->document, str); + GTK_TEXT_BUFFER_CLASS(gtk_imhtml_buffer_parent_class)->insert_text( + g_string_free(str, TRUE); +/****************************************************************************** + *****************************************************************************/ +gtk_imhtml_buffer_init(GtkIMHTMLBuffer *buffer) { +gtk_imhtml_buffer_class_init(GtkIMHTMLBufferClass *klass) { + GtkTextBufferClass *text_buffer_class = GTK_TEXT_BUFFER_CLASS(klass); + text_buffer_class->insert_text = gtk_imthml_buffer_insert_text; +/****************************************************************************** + *****************************************************************************/ +GtkTextBuffer *gtk_imhtml_buffer_new(void) { + GtkTextTagTable *table = gtk_imhtml_tag_table_new(); + GTK_IMHTML_TYPE_BUFFER, --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gtkimhtmlbuffer.h Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,65 @@
+ * Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. +#ifndef GTK_IMHTML_BUFFER_H +#define GTK_IMHTML_BUFFER_H +#define GTK_IMHTML_TYPE_BUFFER (gtk_imhtml_buffer_get_type()) +#define GTK_IMHTML_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_IMHTML_TYPE_BUFFER, GtkIMHTMLBuffer)) +#define GTK_IMHTML_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_IMHTML_TYPE_BUFFER, GtkIMHTMLBufferClass)) +#define GTK_IMHTML_IS_BUFFER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_IMHTML_TYPEBUFFER)) +#define GTK_IMHTML_IS_BUFFER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_IMHTML_TYPE_BUFFER)) +#define GTK_IMHTML_BUFFER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_IMHTML_TYPE_BUFFER, GtkIMHTMLBufferClass)) +typedef struct _GtkIMHTMLBuffer GtkIMHTMLBuffer; +typedef struct _GtkIMHTMLBufferPrivate GtkIMHTMLBufferPrivate; +typedef struct _GtkIMHTMLBufferClass GtkIMHTMLBufferClass; +#include <glib-object.h> +struct _GtkIMHTMLBuffer { + void (*_gplugin_reserved1)(void); + void (*_gplugin_reserved2)(void); + void (*_gplugin_reserved3)(void); + void (*_gplugin_reserved4)(void); +struct _GtkIMHTMLBufferClass { + GtkTextBufferClass parent; + void (*_gplugin_reserved1)(void); + void (*_gplugin_reserved2)(void); + void (*_gplugin_reserved3)(void); + void (*_gplugin_reserved4)(void); +GType gtk_imhtml_buffer_get_type(void); +GtkTextBuffer *gtk_imhtml_buffer_new(void); +#endif /* GTK_IMHTML_BUFFER_H */ --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gtkimhtmldemo.c Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,26 @@
+#include "gtkimhtmlbuffer.h" +gint main(gint argc, gchar **argv) { + GtkWidget *win = NULL, *sw = NULL, *view = NULL; + GtkTextBuffer *buf = NULL; + gtk_init(&argc, &argv); + win = gtk_window_new(GTK_WINDOW_TOPLEVEL); + sw = gtk_scrolled_window_new(NULL, NULL); + gtk_container_add(GTK_CONTAINER(win), sw); + buf = gtk_imhtml_buffer_new(); + view = gtk_text_view_new_with_buffer(buf); + gtk_container_add(GTK_CONTAINER(sw), view); + gtk_widget_show_all(win); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gtkimhtmltagtable.c Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,142 @@
+ * Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. +#include "gtkimhtmltagtable.h" +/****************************************************************************** + *****************************************************************************/ +G_DEFINE_TYPE(GtkIMHTMLTagTable, gtk_imhtml_tag_table, GTK_TYPE_TEXT_TAG_TABLE) +gtk_imhtml_tag_table_init(GtkIMHTMLTagTable *table) { + GtkTextTagTable *text_table = GTK_TEXT_TAG_TABLE(table); + GtkTextTag *tag = NULL; + tag = gtk_text_tag_new("b"); + "weight", PANGO_WEIGHT_BOLD, + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("i"); + "style", PANGO_STYLE_ITALIC, + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("u"); + "underline", PANGO_UNDERLINE_SINGLE, + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("strike"); + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("sub"); + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("sup"); + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("pre"); + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("code"); + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("search"); + "background", "#22ff00", + "weight", PANGO_WEIGHT_BOLD, + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("comment"); + "weight", PANGO_WEIGHT_NORMAL, + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); + tag = gtk_text_tag_new("em"); + "weight", PANGO_WEIGHT_BOLD, + "style", PANGO_STYLE_ITALIC, + gtk_text_tag_table_add(text_table, tag); + g_object_unref(G_OBJECT(tag)); +gtk_imhtml_tag_table_class_init(GtkIMHTMLTagTableClass *klass) { +/****************************************************************************** + *****************************************************************************/ +GtkTextTagTable *gtk_imhtml_tag_table_new(void) { + return g_object_new(GTK_IMHTML_TYPE_TAG_TABLE, NULL); --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/gtkimhtmltagtable.h Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,65 @@
+ * Copyright (C) 2017 Gary Kramlich <grim@reaperworld.com> + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * This library 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 + * Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, see <http://www.gnu.org/licenses/>. +#ifndef GTK_IMHTML_TAG_TABLE_H +#define GTK_IMHTML_TAG_TABLE_H +#define GTK_IMHTML_TYPE_TAG_TABLE (gtk_imhtml_tag_table_get_type()) +#define GTK_IMHTML_TAG_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_IMHTML_TYPE_TAG_TABLE, GtkIMHTMLTAG_TABLE)) +#define GTK_IMHTML_TAG_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GTK_IMHTML_TYPE_TAG_TABLE, GtkIMHTMLTAG_TABLEClass)) +#define GTK_IMHTML_IS_TAG_TABLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_IMHTML_TYPETAG_TABLE)) +#define GTK_IMHTML_IS_TAG_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_IMHTML_TYPE_TAG_TABLE)) +#define GTK_IMHTML_TAG_TABLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_IMHTML_TYPE_TAG_TABLE, GtkIMHTMLTAG_TABLEClass)) +typedef struct _GtkIMHTMLTagTable GtkIMHTMLTagTable; +typedef struct _GtkIMHTMLTagTablePrivate GtkIMHTMLTagTablePrivate; +typedef struct _GtkIMHTMLTagTableClass GtkIMHTMLTagTableClass; +#include <glib-object.h> +struct _GtkIMHTMLTagTable { + GtkTextTagTable parent; + void (*_gplugin_reserved1)(void); + void (*_gplugin_reserved2)(void); + void (*_gplugin_reserved3)(void); + void (*_gplugin_reserved4)(void); +struct _GtkIMHTMLTagTableClass { + GtkTextTagTableClass parent; + void (*_gplugin_reserved1)(void); + void (*_gplugin_reserved2)(void); + void (*_gplugin_reserved3)(void); + void (*_gplugin_reserved4)(void); +GType gtk_imhtml_tag_table_get_type(void); +GtkTextTagTable *gtk_imhtml_tag_table_new(void); +#endif /* GTK_IMHTML_TAG_TABLE_H */ --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/meson.build Thu Nov 30 23:09:22 2017 -0600
@@ -0,0 +1,118 @@
+############################################################################### +############################################################################### +GTKIMHTML_LIBRARY_VERSION = '0.1.0' +GTKIMHTML_PUBLIC_BUILT_HEADERS = [ +GTKIMHTML_PUBLIC_BUILT_SOURCES = [ +GTKIMHTML_PRIVATE_HEADERS = [ +GTKIMHTML_PRIVATE_SOURCES = [ +GTKIMHTML_PRIVATE_BUILT_HEADERS = [ +GTKIMHTML_PRIVATE_BUILT_SOURCES = [ +############################################################################### +############################################################################### +gtkimhtml = shared_library('gtkimhtml', + GTKIMHTML_PUBLIC_BUILT_SOURCES, + GTKIMHTML_PRIVATE_SOURCES, + GTKIMHTML_PRIVATE_BUILT_SOURCES, + GTKIMHTML_PUBLIC_BUILT_HEADERS, + c_args : ['-DGTKIMHTML_COMPILATION', '-DG_LOG_DOMAIN="GtkIMHTML"'], + include_directories : toplevel_inc, + dependencies : [GLIB, GOBJECT, GUMBO, GTK3], + version : GTKIMHTML_LIBRARY_VERSION, +gtkimhtml_dep = declare_dependency( + include_directories : [toplevel_inc, include_directories('.')], + sources : GTKIMHTML_PUBLIC_BUILT_HEADERS, # Ensure they're built before use. + dependencies : [GLIB, GOBJECT] + description : 'A fully featured GModule based plugin library', + version : meson.project_version(), + filebase : 'gtkimhtml', + subdirs : 'gtkimhtml-1.0', + requires : ['glib-2.0', 'gobject-2.0', 'gmodule-2.0', 'gtk+-3.0'], +# SOURCES ${GTKIMHTML_SOURCES} ${GTKIMHTML_NATIVE_SOURCES} gtkimhtml-query.c +# BUILT_SOURCES ${GTKIMHTML_PUBLIC_BUILT_SOURCES} +# FILENAME gtkimhtml.pot +############################################################################### +############################################################################### +if get_option('gobject-introspection') + gtkimhtml_gir = gnome.generate_gir(gtkimhtml, + sources : GTKIMHTML_SOURCES + GTKIMHTML_HEADERS + + GTKIMHTML_PUBLIC_BUILT_SOURCES + + GTKIMHTML_PUBLIC_BUILT_HEADERS, + includes : ['GModule-2.0', 'GObject-2.0', 'Gtk-3.0'], + namespace : 'GtkIMHTML', + symbol_prefix : 'gtkimhtml', + nsversion : '@0@.0'.format(GTKIMHTML_MAJOR_VERSION), +############################################################################### +############################################################################### +driver = executable('gtk-imhtml-demo', + dependencies: [GLIB, GTK3], + link_with: [gtkimhtml], +############################################################################### +############################################################################### +# install the normal includes into the gtkimhtml subdirectory + subdir : 'gtkimhtml-1.0/gtkimhtml'