2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU Library General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 #include <devhelp/dh-book-tree.h>
20 #include <devhelp/dh-html.h>
21 #include <devhelp/dh-preferences.h>
22 #include <devhelp/dh-search.h>
23 #include <devhelp/dh-base.h>
25 static void html_view_class_init(HtmlViewClass
*klass
);
26 static void html_view_init(HtmlView
*sp
);
27 static void html_view_finalize(GObject
*object
);
29 struct _HtmlViewPrivate
{
31 AnjutaDevhelp
* devhelp
;
36 G_DEFINE_TYPE(HtmlView
, html_view
, GTK_TYPE_HBOX
)
39 devhelp_html_open_uri_cb (DhHtml
*html
,
41 AnjutaDevhelp
*widget
)
43 #ifdef HAVE_OLD_DEVHELP
44 dh_book_tree_show_uri (DH_BOOK_TREE (widget
->book_tree
), uri
);
46 dh_book_tree_select_uri (DH_BOOK_TREE (widget
->book_tree
), uri
);
52 devhelp_html_location_changed_cb (DhHtml
*html
,
53 const gchar
*location
,
54 AnjutaDevhelp
*widget
)
56 anjuta_devhelp_check_history (widget
);
60 html_view_create_html(HtmlView
* html_view
)
63 HtmlViewPrivate
* priv
= html_view
->priv
;
65 priv
->html
= dh_html_new();
67 if (!priv
->html
|| !DH_IS_HTML(priv
->html
))
68 return TRUE
; /* I think the idea is to wait until we get a widget? */
70 view
= dh_html_get_widget(priv
->html
);
71 gtk_box_pack_start(GTK_BOX(html_view
), dh_html_get_widget(priv
->html
), TRUE
, TRUE
, 1);
73 g_signal_connect (priv
->html
, "open-uri",
74 G_CALLBACK (devhelp_html_open_uri_cb
),
76 g_signal_connect (priv
->html
, "location-changed",
77 G_CALLBACK (devhelp_html_location_changed_cb
),
80 /* Hack to get GtkMozEmbed to work properly. */
81 gtk_widget_realize (view
);
84 dh_html_open_uri(priv
->html
, priv
->uri
);
86 dh_html_clear(priv
->html
);
88 gtk_widget_show (view
);
94 html_view_realize(GtkWidget
* widget
)
96 HtmlView
* html_view
= HTML_VIEW(widget
);
98 if (html_view
->priv
->idle_realize
== 0)
100 html_view
->priv
->idle_realize
=
101 g_idle_add((GSourceFunc
) html_view_create_html
, html_view
);
103 (* GTK_WIDGET_CLASS (html_view_parent_class
)->realize
)(widget
);
107 html_view_unrealize(GtkWidget
* widget
)
109 HtmlView
* html_view
= HTML_VIEW(widget
);
111 if (html_view
->priv
->idle_realize
> 0)
113 g_source_remove (html_view
->priv
->idle_realize
);
114 html_view
->priv
->idle_realize
= 0;
117 if (html_view
->priv
->html
!= NULL
)
119 g_free(html_view
->priv
->uri
);
120 html_view
->priv
->uri
= dh_html_get_location(html_view
->priv
->html
);
123 html_view
->priv
->uri
= NULL
;
125 if (gtk_container_get_children(GTK_CONTAINER(html_view
)))
127 gtk_container_remove(GTK_CONTAINER(widget
), dh_html_get_widget(html_view
->priv
->html
));
128 html_view
->priv
->html
= NULL
;
131 (* GTK_WIDGET_CLASS (html_view_parent_class
)->unrealize
)(widget
);
135 html_view_class_init(HtmlViewClass
*klass
)
137 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
138 GtkWidgetClass
* widget_class
= GTK_WIDGET_CLASS(klass
);
140 object_class
->finalize
= html_view_finalize
;
142 widget_class
->realize
= html_view_realize
;
143 widget_class
->unrealize
= html_view_unrealize
;
147 html_view_init(HtmlView
*obj
)
149 obj
->priv
= g_new0(HtmlViewPrivate
, 1);
150 gtk_widget_show(GTK_WIDGET(obj
));
154 html_view_finalize(GObject
*object
)
157 cobj
= HTML_VIEW(object
);
159 /* Free private members, etc. */
160 if (cobj
->priv
->html
)
161 gtk_widget_destroy(dh_html_get_widget(cobj
->priv
->html
));
162 g_free (cobj
->priv
->uri
);
164 G_OBJECT_CLASS(html_view_parent_class
)->finalize(object
);
168 html_view_new(AnjutaDevhelp
* devhelp
)
172 obj
= HTML_VIEW(g_object_new(HTML_TYPE_VIEW
, NULL
));
174 obj
->priv
->devhelp
= devhelp
;
176 return GTK_WIDGET(obj
);
179 DhHtml
* html_view_get_dh_html(HtmlView
* view
)
181 return view
->priv
->html
;