1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
/* This file is part of the GtkHTML library.
4
Copyright (C) 2000 Helix Code, Inc.
6
This library is free software; you can redistribute it and/or
7
modify it under the terms of the GNU Library General Public
8
License as published by the Free Software Foundation; either
9
version 2 of the License, or (at your option) any later version.
11
This library is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
Library General Public License for more details.
16
You should have received a copy of the GNU Library General Public License
17
along with this library; see the file COPYING.LIB. If not, write to
18
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
21
Author: Larry Ewing <lewing@ximian.com>
26
#ifdef GNOME_GTKHTML_EDITOR_SHLIB
27
#include <glib/gi18n-lib.h>
29
#include <glib/gi18n.h>
35
#include <libgnome/gnome-util.h>
36
#include <bonobo/bonobo-stream.h>
37
#include <bonobo/bonobo-stream-memory.h>
38
#include <bonobo/bonobo-exception.h>
41
#include "htmlengine.h"
42
#include "gtkhtml-stream.h"
43
#include "htmlsourceview.h"
44
#include "e-html-utils.h"
46
struct _HTMLSourceViewPrivate {
50
gint current_interval;
60
static GtkObject *parent_class;
61
static guint signals [LAST_SIGNAL] = { 0 };
64
html_source_view_real_update (HTMLSourceView *view)
69
html_source_view_load (HTMLSourceView *view)
72
GtkHTMLStream *hstream;
78
CORBA_exception_init (&ev);
80
pstream = view->priv->pstream;
81
smem = bonobo_stream_mem_create (NULL, 1, FALSE, TRUE);
82
Bonobo_PersistStream_save (pstream, BONOBO_OBJREF (smem), view->priv->content_type, &ev);
83
/* Terminate the buffer for e_text_to_html */
84
bonobo_stream_client_write (BONOBO_OBJREF (smem), "", 1, &ev);
86
text = bonobo_stream_mem_get_buffer (BONOBO_STREAM_MEM (smem));
88
if (!view->priv->as_html) {
89
html = e_text_to_html_full (text, E_TEXT_TO_HTML_PRE | E_TEXT_TO_HTML_CONVERT_SPACES, 0);
91
html = g_strdup (text);
94
hstream = gtk_html_begin (view->priv->html);
95
view->priv->html->engine->newPage = FALSE;
97
gtk_html_stream_write (hstream, html, strlen (html));
98
gtk_html_stream_close (hstream, GTK_HTML_STREAM_OK);
100
bonobo_object_unref (BONOBO_OBJECT (smem));
103
CORBA_exception_free (&ev);
107
html_source_view_timeout (gpointer *data)
109
HTMLSourceView *view;
111
g_return_val_if_fail (HTML_IS_SOURCE_VIEW (data), FALSE);
113
view = HTML_SOURCE_VIEW (data);
114
html_source_view_load (view);
120
html_source_view_set_timeout (HTMLSourceView *view, guint timeout)
122
if (view->priv->timer_id)
123
g_source_remove (view->priv->timer_id);
125
view->priv->current_interval = timeout;
126
view->priv->timer_id = g_timeout_add (timeout, (GtkFunction)html_source_view_timeout, view);
130
html_source_view_set_mode (HTMLSourceView *view, gboolean as_html)
132
view->priv->as_html = as_html;
136
html_source_view_set_source (HTMLSourceView *view, BonoboWidget *control, char *content_type)
138
CORBA_Object interface;
139
CORBA_Environment ev;
140
g_return_if_fail (HTML_IS_SOURCE_VIEW (view));
142
CORBA_exception_init (&ev);
143
interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (control),
144
"IDL:Bonobo/PersistStream:1.0", &ev);
145
if (BONOBO_EX (&ev) || interface == CORBA_OBJECT_NIL) {
146
g_warning ("Couldn't find persist stream interface");
150
g_free (view->priv->content_type);
151
view->priv->content_type = g_strdup (content_type);
153
view->priv->pstream = interface;
155
html_source_view_set_timeout (view, view->priv->current_interval);
159
html_source_view_new (void)
163
view = GTK_WIDGET (g_object_new (html_source_view_get_type (), NULL));
169
html_source_view_init (HTMLSourceView *view)
174
view->priv = g_new0 (HTMLSourceViewPrivate, 1);
176
view->priv->content_type = NULL;
177
view->priv->html = GTK_HTML (html = gtk_html_new ());
178
view->priv->current_interval = 500;
179
view->priv->as_html = FALSE;
181
scroll = gtk_scrolled_window_new (NULL, NULL);
182
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
183
GTK_POLICY_AUTOMATIC,
184
GTK_POLICY_AUTOMATIC);
186
gtk_container_add (GTK_CONTAINER (scroll), html);
188
gtk_box_pack_start (GTK_BOX (view), scroll,
191
gtk_widget_show_all (scroll);
195
html_source_view_destroy (GtkObject *object)
197
HTMLSourceView *view = HTML_SOURCE_VIEW (object);
198
HTMLSourceViewPrivate *priv = view->priv;
202
g_source_remove (priv->timer_id);
205
if (priv->pstream != CORBA_OBJECT_NIL) {
206
CORBA_Environment ev;
208
CORBA_exception_init (&ev);
209
Bonobo_Unknown_unref (priv->pstream, &ev);
210
CORBA_Object_release (priv->pstream, &ev);
211
CORBA_exception_free (&ev);
218
if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
219
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
223
html_source_view_class_init (HTMLSourceViewClass *klass)
225
GtkObjectClass *object_class;
227
object_class = (GtkObjectClass *) klass;
228
parent_class = gtk_type_class (GTK_TYPE_VBOX);
230
signals [UPDATE] = g_signal_new ("update",
231
G_TYPE_FROM_CLASS (object_class),
233
G_STRUCT_OFFSET (HTMLSourceViewClass, update),
235
g_cclosure_marshal_VOID__VOID,
238
object_class->destroy = html_source_view_destroy;
239
klass->update = html_source_view_real_update;
243
html_source_view_get_type (void)
245
static GType view_type = 0;
248
GTypeInfo view_info = {
249
sizeof (HTMLSourceViewClass),
252
(GClassInitFunc) html_source_view_class_init,
255
sizeof (HTMLSourceView),
257
(GInstanceInitFunc) html_source_view_init,
260
view_type = g_type_register_static (GTK_TYPE_VBOX, "HTMLView", &view_info, 0);