1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
/* This file is part of gnome-spell bonobo component
4
Copyright (C) 2000 Helix Code, Inc.
5
Authors: Radek Doulik <rodo@helixcode.com>
7
This library is free software; you can redistribute it and/or
8
modify it under the terms of the GNU Library General Public
9
License as published by the Free Software Foundation; either
10
version 2 of the License, or (at your option) any later version.
12
This library is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
Library General Public License for more details.
17
You should have received a copy of the GNU Library General Public License
18
along with this library; see the file COPYING.LIB. If not, write to
19
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
Boston, MA 02110-1301, USA.
24
#ifdef GNOME_GTKHTML_EDITOR_SHLIB
25
#include <glib/gi18n-lib.h>
27
#include <glib/gi18n.h>
33
#include "htmlcursor.h"
34
#include "htmlengine.h"
35
#include "htmlengine-edit.h"
41
#include "spellchecker.h"
43
static BonoboObjectClass *engine_parent_class;
45
inline static EditorEngine *
46
html_editor_engine_from_servant (PortableServer_Servant servant)
48
return EDITOR_ENGINE (bonobo_object_from_servant (servant));
52
impl_get_paragraph_data (PortableServer_Servant servant, const CORBA_char * key, CORBA_Environment * ev)
54
EditorEngine *e = html_editor_engine_from_servant (servant);
55
CORBA_char * value = CORBA_OBJECT_NIL;
57
if (e->cd->html->engine->cursor->object && e->cd->html->engine->cursor->object->parent
58
&& HTML_IS_CLUEFLOW (e->cd->html->engine->cursor->object->parent))
59
value = html_object_get_data (e->cd->html->engine->cursor->object->parent, key);
61
/* printf ("get paragraph data\n"); */
63
return CORBA_string_dup (value ? value : "");
67
impl_set_paragraph_data (PortableServer_Servant servant,
68
const CORBA_char * key, const CORBA_char * value,
69
CORBA_Environment * ev)
71
EditorEngine *e = html_editor_engine_from_servant (servant);
73
if (e->cd->html->engine->cursor->object && e->cd->html->engine->cursor->object->parent
74
&& HTML_OBJECT_TYPE (e->cd->html->engine->cursor->object->parent) == HTML_TYPE_CLUEFLOW)
75
html_object_set_data (HTML_OBJECT (e->cd->html->engine->cursor->object->parent), key, value);
79
impl_set_object_data_by_type (PortableServer_Servant servant,
80
const CORBA_char * type_name, const CORBA_char * key, const CORBA_char * value,
81
CORBA_Environment * ev)
83
EditorEngine *e = html_editor_engine_from_servant (servant);
85
/* printf ("set data by type\n"); */
87
/* FIXME should use bonobo_arg_to_gtk, but this seems to be broken */
88
html_engine_set_data_by_type (e->cd->html->engine, html_type_from_name (type_name), key, value);
92
impl_set_listener (PortableServer_Servant servant, const GNOME_GtkHTML_Editor_Listener value, CORBA_Environment * ev)
94
EditorEngine *e = html_editor_engine_from_servant (servant);
96
/* printf ("set listener\n"); */
98
bonobo_object_release_unref (e->listener, NULL);
99
e->listener = bonobo_object_dup_ref (value, NULL);
102
static GNOME_GtkHTML_Editor_Listener
103
impl_get_listener (PortableServer_Servant servant, CORBA_Environment * ev)
105
return html_editor_engine_from_servant (servant)->listener;
109
impl_run_command (PortableServer_Servant servant, const CORBA_char * command, CORBA_Environment * ev)
111
EditorEngine *e = html_editor_engine_from_servant (servant);
113
/* printf ("command: %s\n", command); */
115
return gtk_html_command (e->cd->html, command);
119
impl_is_paragraph_empty (PortableServer_Servant servant, CORBA_Environment * ev)
121
EditorEngine *e = html_editor_engine_from_servant (servant);
123
if (e->cd->html->engine->cursor->object
124
&& e->cd->html->engine->cursor->object->parent
125
&& HTML_OBJECT_TYPE (e->cd->html->engine->cursor->object->parent) == HTML_TYPE_CLUEFLOW) {
126
return html_clueflow_is_empty (HTML_CLUEFLOW (e->cd->html->engine->cursor->object->parent));
132
impl_is_previous_paragraph_empty (PortableServer_Servant servant, CORBA_Environment * ev)
134
EditorEngine *e = html_editor_engine_from_servant (servant);
136
if (e->cd->html->engine->cursor->object
137
&& e->cd->html->engine->cursor->object->parent
138
&& e->cd->html->engine->cursor->object->parent->prev
139
&& HTML_IS_CLUEFLOW (e->cd->html->engine->cursor->object->parent->prev))
140
return html_clueflow_is_empty (HTML_CLUEFLOW (e->cd->html->engine->cursor->object->parent->prev));
146
impl_insert_html (PortableServer_Servant servant, const CORBA_char * html, CORBA_Environment * ev)
148
/* printf ("impl_insert_html\n"); */
149
gtk_html_insert_html (html_editor_engine_from_servant (servant)->cd->html, html);
153
impl_search_by_data (PortableServer_Servant servant, const CORBA_long level, const CORBA_char * klass,
154
const CORBA_char * key, const CORBA_char * value, CORBA_Environment * ev)
156
EditorEngine *e = html_editor_engine_from_servant (servant);
157
HTMLObject *o, *lco = NULL;
161
if (e->cd->html->engine->cursor->object != lco) {
162
o = html_object_nth_parent (e->cd->html->engine->cursor->object, level);
164
o_value = html_object_get_data (o, key);
165
if (o_value && !strcmp (o_value, value))
169
lco = e->cd->html->engine->cursor->object;
170
} while (html_cursor_forward (e->cd->html->engine->cursor, e->cd->html->engine));
175
impl_freeze (PortableServer_Servant servant, CORBA_Environment * ev)
177
html_engine_freeze (html_editor_engine_from_servant (servant)->cd->html->engine);
181
impl_thaw (PortableServer_Servant servant, CORBA_Environment * ev)
183
html_engine_thaw (html_editor_engine_from_servant (servant)->cd->html->engine);
187
impl_undo_begin (PortableServer_Servant servant, const CORBA_char * undo_name, const CORBA_char * redo_name,
188
CORBA_Environment * ev)
190
html_undo_level_begin (html_editor_engine_from_servant (servant)->cd->html->engine->undo, undo_name, redo_name);
194
impl_undo_end (PortableServer_Servant servant, CORBA_Environment * ev)
196
html_undo_level_end (html_editor_engine_from_servant (servant)->cd->html->engine->undo);
200
impl_ignore_word (PortableServer_Servant servant, const CORBA_char * word, CORBA_Environment * ev)
202
EditorEngine *e = html_editor_engine_from_servant (servant);
204
/* printf ("ignoreWord: %s\n", word); */
206
spell_add_to_session (e->cd->html, word, e->cd);
210
impl_has_undo (PortableServer_Servant servant, CORBA_Environment * ev)
212
EditorEngine *e = html_editor_engine_from_servant (servant);
214
/* printf ("hasUndo\n"); */
216
return gtk_html_has_undo (e->cd->html);
220
impl_drop_undo (PortableServer_Servant servant, CORBA_Environment * ev)
222
EditorEngine *e = html_editor_engine_from_servant (servant);
224
/* printf ("dropUndo\n"); */
226
gtk_html_drop_undo (e->cd->html);
230
impl_set_file_path (PortableServer_Servant servant, const CORBA_char * file_path, CORBA_Environment * ev)
232
EditorEngine *e = html_editor_engine_from_servant (servant);
234
g_free (e->cd->file_path);
236
if (file_path && *file_path)
237
e->cd->file_path = g_strdup (file_path);
239
e->cd->file_path = g_strdup (g_get_home_dir ());
243
impl_get_file_path (PortableServer_Servant servant, CORBA_Environment * ev)
245
EditorEngine *e = html_editor_engine_from_servant (servant);
247
return CORBA_string_dup (e->cd->file_path);
251
engine_object_finalize (GObject *object)
253
EditorEngine *e = EDITOR_ENGINE (object);
255
bonobo_object_release_unref (e->listener, NULL);
257
G_OBJECT_CLASS (engine_parent_class)->finalize (object);
261
editor_engine_init (GObject *object)
263
EditorEngine *e = EDITOR_ENGINE (object);
265
e->listener = CORBA_OBJECT_NIL;
269
editor_engine_class_init (EditorEngineClass *klass)
271
GObjectClass *object_class = G_OBJECT_CLASS (klass);
272
POA_GNOME_GtkHTML_Editor_Engine__epv *epv = &klass->epv;
274
engine_parent_class = g_type_class_peek_parent (klass);
275
object_class->finalize = engine_object_finalize;
277
epv->_set_listener = impl_set_listener;
278
epv->_get_listener = impl_get_listener;
279
epv->setParagraphData = impl_set_paragraph_data;
280
epv->getParagraphData = impl_get_paragraph_data;
281
epv->setObjectDataByType = impl_set_object_data_by_type;
282
epv->runCommand = impl_run_command;
283
epv->isParagraphEmpty = impl_is_paragraph_empty;
284
epv->isPreviousParagraphEmpty = impl_is_previous_paragraph_empty;
285
epv->searchByData = impl_search_by_data;
286
epv->insertHTML = impl_insert_html;
287
epv->freeze = impl_freeze;
288
epv->thaw = impl_thaw;
289
epv->undoBegin = impl_undo_begin;
290
epv->undoEnd = impl_undo_end;
291
epv->ignoreWord = impl_ignore_word;
292
epv->hasUndo = impl_has_undo;
293
epv->dropUndo = impl_drop_undo;
294
epv->setFilePath = impl_set_file_path;
295
epv->getFilePath = impl_get_file_path;
298
BONOBO_TYPE_FUNC_FULL (
299
EditorEngine, /* Glib class name */
300
GNOME_GtkHTML_Editor_Engine, /* CORBA interface name */
301
BONOBO_TYPE_OBJECT, /* parent type */
302
editor_engine); /* local prefix ie. 'echo'_class_init */
305
editor_engine_new (GtkHTMLControlData *cd)
309
ee = g_object_new (EDITOR_ENGINE_TYPE, NULL);
313
/* This engine will be returned to the composer window.
314
* The html-widget will be used by the composer to
315
* provide DnD to the composer window's GtkHTML component
318
g_object_set_data ((GObject *)ee, "html-widget", cd->html);