1 /* This file is part of EdiTeX, an editor of mathematical
2 * expressions based on TeX syntax.
4 * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
5 * 2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 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 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * For more information, please visit the project's home page
22 * http://helm.cs.unibo.it/editex/
23 * or send an email to <lpadovan@cs.unibo.it>
28 #include <caml/memory.h>
29 #include <caml/custom.h>
30 #include <caml/callback.h>
32 #include "mlgdomevalue.h"
34 #include "c_mathml_editor.h"
45 ml_Editor* editor = *((ml_Editor**) Data_custom_val(v));
46 assert(editor != NULL);
51 ml_mathml_editor_finalize(value v)
53 ml_Editor* editor = Editor_val(v);
56 remove_global_root(&editor->callback);
57 c_mathml_editor_destroy(editor->c_editor);
62 ml_mathml_editor_log_callback(int level, const char* msg, void* user_data)
64 ml_Editor* ml_editor = (ml_Editor*) user_data;
66 callback2(ml_editor->callback, Val_int(level), copy_string(msg));
70 ml_mathml_editor_get_default_dictionary_path(value unit)
73 CAMLreturn(copy_string(c_mathml_editor_get_default_dictionary_path()));
77 ml_mathml_editor_get_default_mathml_stylesheet_path(value unit)
80 CAMLreturn(copy_string(c_mathml_editor_get_default_mathml_stylesheet_path()));
84 ml_mathml_editor_get_default_tex_stylesheet_path(value unit)
87 CAMLreturn(copy_string(c_mathml_editor_get_default_tex_stylesheet_path()));
91 ml_mathml_editor_new(value dictionary,
96 static struct custom_operations ops =
99 ml_mathml_editor_finalize,
100 custom_compare_default,
102 custom_serialize_default,
103 custom_deserialize_default
106 value v = alloc_custom(&ops, sizeof(ml_Editor*), 0, 1);
107 ml_Editor** ml_editor_ref = (ml_Editor**) Data_custom_val(v);
108 ml_Editor* ml_editor = *ml_editor_ref = malloc(sizeof(ml_Editor));
109 ml_editor->c_editor = c_mathml_editor_new(Document_val(dictionary),
110 Document_val(tml_mml),
111 Document_val(tml_tex),
112 ml_mathml_editor_log_callback,
114 ml_editor->callback = log_message_cb;
115 register_global_root(&ml_editor->callback);
121 ml_mathml_editor_freeze(value v)
124 ml_Editor* editor = Editor_val(v);
125 CAMLreturn(Val_bool(c_mathml_editor_freeze(editor->c_editor)));
129 ml_mathml_editor_thaw(value v)
132 ml_Editor* editor = Editor_val(v);
133 CAMLreturn(Val_bool(c_mathml_editor_thaw(editor->c_editor)));
137 ml_mathml_editor_push(value v, value ch)
140 ml_Editor* editor = Editor_val(v);
141 c_mathml_editor_push(editor->c_editor, Int_val(ch));
142 CAMLreturn(Val_unit);
146 ml_mathml_editor_drop(value v, value alt)
149 ml_Editor* editor = Editor_val(v);
150 c_mathml_editor_drop(editor->c_editor, Bool_val(alt));
151 CAMLreturn(Val_unit);
155 ml_mathml_editor_cursor_hide(value v)
158 ml_Editor* editor = Editor_val(v);
159 CAMLreturn(Val_bool(c_mathml_editor_cursor_hide(editor->c_editor)));
163 ml_mathml_editor_cursor_show(value v)
166 ml_Editor* editor = Editor_val(v);
167 CAMLreturn(Val_bool(c_mathml_editor_cursor_show(editor->c_editor)));
171 ml_mathml_editor_get_tex(value v)
174 ml_Editor* editor = Editor_val(v);
175 char* res = c_mathml_editor_get_tex(editor->c_editor);
177 ml_res = copy_string(res);
183 ml_mathml_editor_reset(value v, value s)
186 ml_Editor* editor = Editor_val(v);
187 c_mathml_editor_reset(editor->c_editor);
188 CAMLreturn(Val_unit);
192 ml_mathml_editor_get_tml(value v)
195 ml_Editor* editor = Editor_val(v);
196 GdomeDocument* doc = c_mathml_editor_get_tml(editor->c_editor);
197 CAMLreturn(Val_Document(doc));
201 ml_mathml_editor_get_mml(value v)
204 ml_Editor* editor = Editor_val(v);
205 GdomeDocument* doc = c_mathml_editor_get_mml(editor->c_editor);
206 CAMLreturn(Val_Document(doc));