~ubuntu-branches/ubuntu/lucid/gtkhtml3.14/lucid

« back to all changes in this revision

Viewing changes to components/html-editor/engine.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2009-06-02 11:18:16 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20090602111816-t7rv5r7z58i0lkb4
Tags: 1:3.27.2-0ubuntu1
* New upstream version
* debian/rules:
  - updated library version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*  This file is part of gnome-spell bonobo component
3
 
 
4
 
    Copyright (C) 2000 Helix Code, Inc.
5
 
    Authors:           Radek Doulik <rodo@helixcode.com>
6
 
 
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.
11
 
 
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.
16
 
 
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.
21
 
*/
22
 
 
23
 
#include <config.h>
24
 
#ifdef GNOME_GTKHTML_EDITOR_SHLIB
25
 
#include <glib/gi18n-lib.h>
26
 
#else
27
 
#include <glib/gi18n.h>
28
 
#endif
29
 
#include <string.h>
30
 
#include <bonobo.h>
31
 
 
32
 
#include "gtkhtml.h"
33
 
#include "htmlcursor.h"
34
 
#include "htmlengine.h"
35
 
#include "htmlengine-edit.h"
36
 
#include "htmltext.h"
37
 
#include "htmltype.h"
38
 
#include "htmlundo.h"
39
 
 
40
 
#include "engine.h"
41
 
#include "spellchecker.h"
42
 
 
43
 
static BonoboObjectClass *engine_parent_class;
44
 
 
45
 
inline static EditorEngine *
46
 
html_editor_engine_from_servant (PortableServer_Servant servant)
47
 
{
48
 
        return EDITOR_ENGINE (bonobo_object_from_servant (servant));
49
 
}
50
 
 
51
 
static CORBA_char *
52
 
impl_get_paragraph_data (PortableServer_Servant servant, const CORBA_char * key, CORBA_Environment * ev)
53
 
{
54
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
55
 
        CORBA_char * value = CORBA_OBJECT_NIL;
56
 
 
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);
60
 
 
61
 
        /* printf ("get paragraph data\n"); */
62
 
 
63
 
        return CORBA_string_dup (value ? value : "");
64
 
}
65
 
 
66
 
static void
67
 
impl_set_paragraph_data (PortableServer_Servant servant,
68
 
                         const CORBA_char * key, const CORBA_char * value,
69
 
                         CORBA_Environment * ev)
70
 
{
71
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
72
 
 
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);
76
 
}
77
 
 
78
 
static void
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)
82
 
{
83
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
84
 
 
85
 
        /* printf ("set data by type\n"); */
86
 
 
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);
89
 
}
90
 
 
91
 
static void
92
 
impl_set_listener (PortableServer_Servant servant, const GNOME_GtkHTML_Editor_Listener value, CORBA_Environment * ev)
93
 
{
94
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
95
 
 
96
 
        /* printf ("set listener\n"); */
97
 
 
98
 
        bonobo_object_release_unref (e->listener, NULL);
99
 
        e->listener        = bonobo_object_dup_ref (value, NULL);
100
 
}
101
 
 
102
 
static GNOME_GtkHTML_Editor_Listener
103
 
impl_get_listener (PortableServer_Servant servant, CORBA_Environment * ev)
104
 
{
105
 
        return html_editor_engine_from_servant (servant)->listener;
106
 
}
107
 
 
108
 
static CORBA_boolean
109
 
impl_run_command (PortableServer_Servant servant, const CORBA_char * command, CORBA_Environment * ev)
110
 
{
111
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
112
 
 
113
 
        /* printf ("command: %s\n", command); */
114
 
 
115
 
        return gtk_html_command (e->cd->html, command);
116
 
}
117
 
 
118
 
static CORBA_boolean
119
 
impl_is_paragraph_empty (PortableServer_Servant servant, CORBA_Environment * ev)
120
 
{
121
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
122
 
 
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));
127
 
        }
128
 
        return CORBA_FALSE;
129
 
}
130
 
 
131
 
static CORBA_boolean
132
 
impl_is_previous_paragraph_empty (PortableServer_Servant servant, CORBA_Environment * ev)
133
 
{
134
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
135
 
 
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));
141
 
 
142
 
        return CORBA_FALSE;
143
 
}
144
 
 
145
 
static void
146
 
impl_insert_html (PortableServer_Servant servant, const CORBA_char * html, CORBA_Environment * ev)
147
 
{
148
 
        /* printf ("impl_insert_html\n"); */
149
 
        gtk_html_insert_html (html_editor_engine_from_servant (servant)->cd->html, html);
150
 
}
151
 
 
152
 
static CORBA_boolean
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)
155
 
{
156
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
157
 
        HTMLObject *o, *lco = NULL;
158
 
        gchar *o_value;
159
 
 
160
 
        do {
161
 
                if (e->cd->html->engine->cursor->object != lco) {
162
 
                        o = html_object_nth_parent (e->cd->html->engine->cursor->object, level);
163
 
                        if (o) {
164
 
                                o_value = html_object_get_data (o, key);
165
 
                                if (o_value && !strcmp (o_value, value))
166
 
                                        return TRUE;
167
 
                        }
168
 
                }
169
 
                lco = e->cd->html->engine->cursor->object;
170
 
        } while (html_cursor_forward (e->cd->html->engine->cursor, e->cd->html->engine));
171
 
        return FALSE;
172
 
}
173
 
 
174
 
static void
175
 
impl_freeze (PortableServer_Servant servant, CORBA_Environment * ev)
176
 
{
177
 
        html_engine_freeze (html_editor_engine_from_servant (servant)->cd->html->engine);
178
 
}
179
 
 
180
 
static void
181
 
impl_thaw (PortableServer_Servant servant, CORBA_Environment * ev)
182
 
{
183
 
        html_engine_thaw (html_editor_engine_from_servant (servant)->cd->html->engine);
184
 
}
185
 
 
186
 
static void
187
 
impl_undo_begin (PortableServer_Servant servant, const CORBA_char * undo_name, const CORBA_char * redo_name,
188
 
                 CORBA_Environment * ev)
189
 
{
190
 
        html_undo_level_begin (html_editor_engine_from_servant (servant)->cd->html->engine->undo, undo_name, redo_name);
191
 
}
192
 
 
193
 
static void
194
 
impl_undo_end (PortableServer_Servant servant, CORBA_Environment * ev)
195
 
{
196
 
        html_undo_level_end (html_editor_engine_from_servant (servant)->cd->html->engine->undo);
197
 
}
198
 
 
199
 
static void
200
 
impl_ignore_word (PortableServer_Servant servant, const CORBA_char * word, CORBA_Environment * ev)
201
 
{
202
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
203
 
 
204
 
        /* printf ("ignoreWord: %s\n", word); */
205
 
 
206
 
        spell_add_to_session (e->cd->html, word, e->cd);
207
 
}
208
 
 
209
 
static CORBA_boolean
210
 
impl_has_undo (PortableServer_Servant servant, CORBA_Environment * ev)
211
 
{
212
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
213
 
 
214
 
        /* printf ("hasUndo\n"); */
215
 
 
216
 
        return gtk_html_has_undo (e->cd->html);
217
 
}
218
 
 
219
 
static void
220
 
impl_drop_undo (PortableServer_Servant servant, CORBA_Environment * ev)
221
 
{
222
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
223
 
 
224
 
        /* printf ("dropUndo\n"); */
225
 
 
226
 
        gtk_html_drop_undo (e->cd->html);
227
 
}
228
 
 
229
 
static void
230
 
impl_set_file_path (PortableServer_Servant servant, const CORBA_char * file_path, CORBA_Environment * ev)
231
 
{
232
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
233
 
 
234
 
        g_free (e->cd->file_path);
235
 
 
236
 
        if (file_path && *file_path)
237
 
                e->cd->file_path = g_strdup (file_path);
238
 
        else
239
 
                e->cd->file_path = g_strdup (g_get_home_dir ());
240
 
}
241
 
 
242
 
static CORBA_char *
243
 
impl_get_file_path (PortableServer_Servant servant, CORBA_Environment * ev)
244
 
{
245
 
        EditorEngine *e = html_editor_engine_from_servant (servant);
246
 
 
247
 
        return CORBA_string_dup (e->cd->file_path);
248
 
}
249
 
 
250
 
static void
251
 
engine_object_finalize (GObject *object)
252
 
{
253
 
        EditorEngine *e = EDITOR_ENGINE (object);
254
 
 
255
 
        bonobo_object_release_unref (e->listener, NULL);
256
 
 
257
 
        G_OBJECT_CLASS (engine_parent_class)->finalize (object);
258
 
}
259
 
 
260
 
static void
261
 
editor_engine_init (GObject *object)
262
 
{
263
 
        EditorEngine *e = EDITOR_ENGINE (object);
264
 
 
265
 
        e->listener = CORBA_OBJECT_NIL;
266
 
}
267
 
 
268
 
static void
269
 
editor_engine_class_init (EditorEngineClass *klass)
270
 
{
271
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
272
 
        POA_GNOME_GtkHTML_Editor_Engine__epv *epv = &klass->epv;
273
 
 
274
 
        engine_parent_class = g_type_class_peek_parent (klass);
275
 
        object_class->finalize = engine_object_finalize;
276
 
 
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;
296
 
}
297
 
 
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 */
303
 
 
304
 
EditorEngine *
305
 
editor_engine_new (GtkHTMLControlData *cd)
306
 
{
307
 
        EditorEngine *ee;
308
 
 
309
 
        ee = g_object_new (EDITOR_ENGINE_TYPE, NULL);
310
 
 
311
 
        ee->cd = cd;
312
 
 
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
316
 
         */
317
 
 
318
 
        g_object_set_data ((GObject *)ee, "html-widget", cd->html);
319
 
 
320
 
        return ee;
321
 
}