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., 51 Franklin Street, Fifth Floor,
19
Boston, MA 02110-1301, 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>
34
#include <libgnome/gnome-util.h>
35
#include <bonobo/bonobo-stream.h>
36
#include <bonobo/bonobo-stream-memory.h>
37
#include <bonobo/bonobo-exception.h>
40
#include "htmlengine.h"
41
#include "gtkhtml-stream.h"
42
#include "htmlsourceview.h"
43
#include "e-html-utils.h"
45
struct _HTMLSourceViewPrivate {
49
gint current_interval;
59
static GtkObject *parent_class;
60
static guint signals [LAST_SIGNAL] = { 0 };
63
html_source_view_real_update (HTMLSourceView *view)
68
html_source_view_load (HTMLSourceView *view)
71
GtkHTMLStream *hstream;
77
CORBA_exception_init (&ev);
79
pstream = view->priv->pstream;
80
smem = bonobo_stream_mem_create (NULL, 1, FALSE, TRUE);
81
Bonobo_PersistStream_save (pstream, BONOBO_OBJREF (smem), view->priv->content_type, &ev);
82
/* Terminate the buffer for e_text_to_html */
83
bonobo_stream_client_write (BONOBO_OBJREF (smem), "", 1, &ev);
85
text = bonobo_stream_mem_get_buffer (BONOBO_STREAM_MEM (smem));
87
if (!view->priv->as_html) {
88
html = e_text_to_html_full (text, E_TEXT_TO_HTML_PRE | E_TEXT_TO_HTML_CONVERT_SPACES, 0);
90
html = g_strdup (text);
93
hstream = gtk_html_begin (view->priv->html);
94
view->priv->html->engine->newPage = FALSE;
96
gtk_html_stream_write (hstream, html, strlen (html));
97
gtk_html_stream_close (hstream, GTK_HTML_STREAM_OK);
99
bonobo_object_unref (BONOBO_OBJECT (smem));
102
CORBA_exception_free (&ev);
106
html_source_view_timeout (gpointer *data)
108
HTMLSourceView *view;
110
g_return_val_if_fail (HTML_IS_SOURCE_VIEW (data), FALSE);
112
view = HTML_SOURCE_VIEW (data);
113
html_source_view_load (view);
119
html_source_view_set_timeout (HTMLSourceView *view, guint timeout)
121
if (view->priv->timer_id)
122
g_source_remove (view->priv->timer_id);
124
view->priv->current_interval = timeout;
125
view->priv->timer_id = g_timeout_add (timeout, (GtkFunction)html_source_view_timeout, view);
129
html_source_view_set_mode (HTMLSourceView *view, gboolean as_html)
131
view->priv->as_html = as_html;
135
html_source_view_set_source (HTMLSourceView *view, BonoboWidget *control, char *content_type)
137
CORBA_Object interface;
138
CORBA_Environment ev;
139
g_return_if_fail (HTML_IS_SOURCE_VIEW (view));
141
CORBA_exception_init (&ev);
142
interface = Bonobo_Unknown_queryInterface (bonobo_widget_get_objref (control),
143
"IDL:Bonobo/PersistStream:1.0", &ev);
144
if (BONOBO_EX (&ev) || interface == CORBA_OBJECT_NIL) {
145
g_warning ("Couldn't find persist stream interface");
149
g_free (view->priv->content_type);
150
view->priv->content_type = g_strdup (content_type);
152
view->priv->pstream = interface;
154
html_source_view_set_timeout (view, view->priv->current_interval);
158
html_source_view_new (void)
162
view = GTK_WIDGET (g_object_new (html_source_view_get_type (), NULL));
168
html_source_view_init (HTMLSourceView *view)
173
view->priv = g_new0 (HTMLSourceViewPrivate, 1);
175
view->priv->content_type = NULL;
176
view->priv->html = GTK_HTML (html = gtk_html_new ());
177
view->priv->current_interval = 500;
178
view->priv->as_html = FALSE;
180
scroll = gtk_scrolled_window_new (NULL, NULL);
181
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll),
182
GTK_POLICY_AUTOMATIC,
183
GTK_POLICY_AUTOMATIC);
185
gtk_container_add (GTK_CONTAINER (scroll), html);
187
gtk_box_pack_start (GTK_BOX (view), scroll,
190
gtk_widget_show_all (scroll);
194
html_source_view_destroy (GtkObject *object)
196
HTMLSourceView *view = HTML_SOURCE_VIEW (object);
197
HTMLSourceViewPrivate *priv = view->priv;
201
g_source_remove (priv->timer_id);
204
if (priv->pstream != CORBA_OBJECT_NIL) {
205
CORBA_Environment ev;
207
CORBA_exception_init (&ev);
208
Bonobo_Unknown_unref (priv->pstream, &ev);
209
CORBA_Object_release (priv->pstream, &ev);
210
CORBA_exception_free (&ev);
217
if (GTK_OBJECT_CLASS (parent_class)->destroy != NULL)
218
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
222
html_source_view_class_init (HTMLSourceViewClass *klass)
224
GtkObjectClass *object_class;
226
object_class = (GtkObjectClass *) klass;
227
parent_class = gtk_type_class (GTK_TYPE_VBOX);
229
signals [UPDATE] = g_signal_new ("update",
230
G_TYPE_FROM_CLASS (object_class),
232
G_STRUCT_OFFSET (HTMLSourceViewClass, update),
234
g_cclosure_marshal_VOID__VOID,
237
object_class->destroy = html_source_view_destroy;
238
klass->update = html_source_view_real_update;
242
html_source_view_get_type (void)
244
static GType view_type = 0;
247
GTypeInfo view_info = {
248
sizeof (HTMLSourceViewClass),
251
(GClassInitFunc) html_source_view_class_init,
254
sizeof (HTMLSourceView),
256
(GInstanceInitFunc) html_source_view_init,
259
view_type = g_type_register_static (GTK_TYPE_VBOX, "HTMLView", &view_info, 0);