2 #include <caml/memory.h>
3 #include <caml/custom.h>
4 #include <caml/callback.h>
6 #include "mlgdomevalue.h"
8 #include "c_mathml_editor.h"
19 ml_Editor* editor = (ml_Editor*) Data_custom_val(v);
20 assert(editor != NULL);
25 ml_mathml_editor_finalize(value v)
27 ml_Editor* editor = Editor_val(v);
30 remove_global_root(&editor->callback);
31 c_mathml_editor_destroy(editor->c_editor);
35 ml_mathml_editor_log_callback(int level, const char* msg, void* user_data)
37 ml_Editor* ml_editor = (ml_Editor*) user_data;
39 callback2(ml_editor->callback, Val_int(level), copy_string(msg));
43 ml_mathml_editor_new(value dictionary,
48 static struct custom_operations ops =
51 ml_mathml_editor_finalize,
52 custom_compare_default,
54 custom_serialize_default,
55 custom_deserialize_default
58 value v = alloc_custom(&ops, sizeof(ml_Editor), 0, 1);
59 ml_Editor* ml_editor = (ml_Editor*) Data_custom_val(v);
60 ml_editor->c_editor = c_mathml_editor_new(Document_val(dictionary),
61 Document_val(tml_mml),
62 Document_val(tml_tex),
63 ml_mathml_editor_log_callback,
65 ml_editor->callback = log_message_cb;
66 register_global_root(&ml_editor->callback);
72 ml_mathml_editor_freeze(value v)
75 ml_Editor* editor = Editor_val(v);
76 CAMLreturn(Val_bool(c_mathml_editor_freeze(editor->c_editor)));
80 ml_mathml_editor_thaw(value v)
83 ml_Editor* editor = Editor_val(v);
84 CAMLreturn(Val_bool(c_mathml_editor_thaw(editor->c_editor)));
88 ml_mathml_editor_push(value v, value ch)
91 ml_Editor* editor = Editor_val(v);
92 c_mathml_editor_push(editor->c_editor, Int_val(ch));
97 ml_mathml_editor_drop(value v, value alt)
100 ml_Editor* editor = Editor_val(v);
101 c_mathml_editor_drop(editor->c_editor, Bool_val(alt));
102 CAMLreturn(Val_unit);
106 ml_mathml_editor_cursor_hide(value v)
109 ml_Editor* editor = Editor_val(v);
110 CAMLreturn(Val_bool(c_mathml_editor_cursor_hide(editor->c_editor)));
114 ml_mathml_editor_cursor_show(value v)
117 ml_Editor* editor = Editor_val(v);
118 CAMLreturn(Val_bool(c_mathml_editor_cursor_show(editor->c_editor)));
122 ml_mathml_editor_get_tex(value v)
125 ml_Editor* editor = Editor_val(v);
126 char* res = c_mathml_editor_get_tex(editor->c_editor);
128 ml_res = copy_string(res);
134 ml_mathml_editor_reset(value v, value s)
137 ml_Editor* editor = Editor_val(v);
138 c_mathml_editor_reset(editor->c_editor);
139 CAMLreturn(Val_unit);
143 ml_mathml_editor_get_tml(value v)
146 ml_Editor* editor = Editor_val(v);
147 GdomeDocument* doc = c_mathml_editor_get_tml(editor->c_editor);
148 CAMLreturn(Val_Document(doc));
152 ml_mathml_editor_get_mml(value v)
155 ml_Editor* editor = Editor_val(v);
156 GdomeDocument* doc = c_mathml_editor_get_mml(editor->c_editor);
157 CAMLreturn(Val_Document(doc));