Started help thing
This commit is contained in:
parent
b417c578f0
commit
70f306252f
@ -21,10 +21,20 @@ mooapp_sources = \
|
||||
$(mooapp)/mooappinput.c \
|
||||
$(mooapp)/mooappinput.h \
|
||||
$(mooapp)/mooappoutput.c \
|
||||
$(mooapp)/mooappoutput.h
|
||||
$(mooapp)/mooappoutput.h \
|
||||
$(mooapp)/moohelp.c \
|
||||
$(mooapp)/moohelp.h
|
||||
|
||||
if MOO_USE_XML
|
||||
mooapp_sources += \
|
||||
$(mooapp)/moohtml.c \
|
||||
$(mooapp)/moohtml.h
|
||||
endif
|
||||
|
||||
mooapp_extra_dist = \
|
||||
$(mooapp)/gpl
|
||||
$(mooapp)/gpl \
|
||||
$(mooapp)/moohtml.c \
|
||||
$(mooapp)/moohtml.h
|
||||
|
||||
$(mooapp)/mooappabout-glade.h: $(mooapp_srcdir)/glade/mooappabout.glade $(XML2H)
|
||||
mkdir -p $(mooapp)
|
||||
|
16
moo/mooapp/moohelp.c
Normal file
16
moo/mooapp/moohelp.c
Normal file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* moohelp.c
|
||||
*
|
||||
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#include "mooapp/moohelp.h"
|
||||
|
||||
|
27
moo/mooapp/moohelp.h
Normal file
27
moo/mooapp/moohelp.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* moohelp.h
|
||||
*
|
||||
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifndef __MOO_HELP_H__
|
||||
#define __MOO_HELP_H__
|
||||
|
||||
#include "mooapp/moohtml.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MOO_HELP_H__ */
|
2261
moo/mooapp/moohtml.c
Normal file
2261
moo/mooapp/moohtml.c
Normal file
File diff suppressed because it is too large
Load Diff
97
moo/mooapp/moohtml.h
Normal file
97
moo/mooapp/moohtml.h
Normal file
@ -0,0 +1,97 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4; coding: utf-8 -*-
|
||||
*
|
||||
* moohtml.h
|
||||
*
|
||||
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
|
||||
*
|
||||
* This program 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* See COPYING file that comes with this distribution.
|
||||
*/
|
||||
|
||||
#ifndef __MOO_HTML_H__
|
||||
#define __MOO_HTML_H__
|
||||
|
||||
#include <gtk/gtktextview.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define MOO_TYPE_HTML (moo_html_get_type ())
|
||||
#define MOO_HTML(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_HTML, MooHtml))
|
||||
#define MOO_HTML_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_HTML, MooHtmlClass))
|
||||
#define MOO_IS_HTML(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_HTML))
|
||||
#define MOO_IS_HTML_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_HTML))
|
||||
#define MOO_HTML_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_HTML, MooHtmlClass))
|
||||
|
||||
#define MOO_TYPE_HTML_TAG (moo_html_tag_get_type ())
|
||||
#define MOO_HTML_TAG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), MOO_TYPE_HTML_TAG, MooHtmlTag))
|
||||
#define MOO_HTML_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOO_TYPE_HTML_TAG, MooHtmlTagClass))
|
||||
#define MOO_IS_HTML_TAG(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), MOO_TYPE_HTML_TAG))
|
||||
#define MOO_IS_HTML_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOO_TYPE_HTML_TAG))
|
||||
#define MOO_HTML_TAG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOO_TYPE_HTML_TAG, MooHtmlTagClass))
|
||||
|
||||
typedef struct _MooHtml MooHtml;
|
||||
typedef struct _MooHtmlPrivate MooHtmlPrivate;
|
||||
typedef struct _MooHtmlClass MooHtmlClass;
|
||||
typedef struct _MooHtmlTag MooHtmlTag;
|
||||
typedef struct _MooHtmlTagClass MooHtmlTagClass;
|
||||
typedef struct _MooHtmlAttr MooHtmlAttr;
|
||||
|
||||
struct _MooHtml
|
||||
{
|
||||
GtkTextView parent;
|
||||
MooHtmlPrivate *priv;
|
||||
};
|
||||
|
||||
struct _MooHtmlClass
|
||||
{
|
||||
GtkTextViewClass parent_class;
|
||||
|
||||
gboolean (*load_url) (MooHtml *html,
|
||||
const char *url);
|
||||
void (*hover_link) (MooHtml *html,
|
||||
const char *link);
|
||||
};
|
||||
|
||||
struct _MooHtmlTag
|
||||
{
|
||||
GtkTextTag base;
|
||||
|
||||
MooHtmlTag *parent;
|
||||
GHashTable *child_tags; /* char* -> MooHtmlTag* */
|
||||
|
||||
MooHtmlAttr *attr;
|
||||
char *href;
|
||||
};
|
||||
|
||||
struct _MooHtmlTagClass
|
||||
{
|
||||
GtkTextTagClass base_class;
|
||||
};
|
||||
|
||||
|
||||
GType moo_html_get_type (void) G_GNUC_CONST;
|
||||
GType moo_html_tag_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget *moo_html_new (void);
|
||||
|
||||
gboolean moo_html_load_memory (MooHtml *html,
|
||||
const char *buffer,
|
||||
int size,
|
||||
const char *url,
|
||||
const char *encoding);
|
||||
gboolean moo_html_load_file (MooHtml *html,
|
||||
const char *file,
|
||||
const char *encoding);
|
||||
|
||||
void moo_html_set_font (MooHtml *html,
|
||||
const char *font);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __MOO_HTML_H__ */
|
70
tests/testhtml.c
Normal file
70
tests/testhtml.c
Normal file
@ -0,0 +1,70 @@
|
||||
#include "moohtml.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
|
||||
static void
|
||||
set_title (MooHtml *html,
|
||||
G_GNUC_UNUSED GParamSpec *pspec,
|
||||
GtkWindow *window)
|
||||
{
|
||||
char *title;
|
||||
g_object_get (html, "title", &title, NULL);
|
||||
gtk_window_set_title (window, title);
|
||||
g_free (title);
|
||||
}
|
||||
|
||||
static void
|
||||
hover_link (GtkStatusbar *statusbar,
|
||||
const char *link)
|
||||
{
|
||||
gtk_statusbar_pop (statusbar, 0);
|
||||
|
||||
if (link)
|
||||
gtk_statusbar_push (statusbar, 0, link);
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
GtkWidget *window, *swin, *html, *statusbar, *vbox;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 400, 300);
|
||||
g_signal_connect (window, "destroy",
|
||||
G_CALLBACK (gtk_main_quit), NULL);
|
||||
|
||||
vbox = gtk_vbox_new (FALSE, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), vbox);
|
||||
|
||||
swin = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin),
|
||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), swin, TRUE, TRUE, 0);
|
||||
|
||||
html = moo_html_new ();
|
||||
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (html), 6);
|
||||
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (html), 6);
|
||||
gtk_container_add (GTK_CONTAINER (swin), html);
|
||||
// moo_html_set_font (MOO_HTML (html), "Tahoma 12");
|
||||
|
||||
statusbar = gtk_statusbar_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 0);
|
||||
|
||||
g_signal_connect (html, "notify::title",
|
||||
G_CALLBACK (set_title), window);
|
||||
g_signal_connect_swapped (html, "hover-link",
|
||||
G_CALLBACK (hover_link), statusbar);
|
||||
|
||||
if (!argv[1])
|
||||
g_error ("usage: %s <file.html>", argv[0]);
|
||||
|
||||
if (!moo_html_load_file (MOO_HTML (html), argv[1], NULL))
|
||||
g_error ("ERROR");
|
||||
|
||||
gtk_widget_show_all (window);
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user