]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c
ocaml 3.09 transition
[helm.git] / helm / DEVEL / lablgtkmathview / ml_gtk_mathview.c
1 /* Copyright (C) 2000-2005,
2  *    Luca Padovani           <lpadovan@cs.unibo.it>
3  *    Claudio Sacerdoti Coen  <sacerdot@cs.unibo.it>
4  *    Stefano Zacchiroli      <zacchiro@cs.unibo.it>
5  *
6  * This file is part of lablgtkmathview, the Ocaml binding for the
7  * GtkMathView widget.
8  * 
9  * lablgtkmathview is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of the
12  * License, or (at your option) any later version.
13  *
14  * lablgtkmathview is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with lablgtkmathview; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22  * 02111-1307, USA.
23  * 
24  * For details, send a mail to the authors.
25  */
26
27 #include <assert.h>
28
29 #include <gtk/gtkmathview_gmetadom.h>
30 #include <gtk/gtk.h>
31
32 #include <caml/mlvalues.h>
33 #include <caml/alloc.h>
34 #include <caml/memory.h>
35 #include <caml/callback.h>
36 #include <caml/fail.h>
37 #include <caml/custom.h>
38 #include <caml/callback.h>
39
40 #include <wrappers.h>
41 #include <ml_glib.h>
42 #include <ml_gdk.h>
43 #include <ml_gtk.h>
44 #include <ml_gobject.h>
45 #include <ml_gdkpixbuf.h>
46 #include <ml_pango.h>
47 #include <gtk_tags.h>
48 #include <gdk_tags.h>
49
50 #include <mlgdomevalue.h>
51
52 /* Init all */
53
54 CAMLprim value ml_gtk_mathview_init(value unit)
55 {
56     /* Since these are declared const, must force gcc to call them! */
57     GType t = gtk_math_view_get_type();
58     return Val_GType(t);
59 }
60
61 #define GtkMathView_val(val) check_cast(GTK_MATH_VIEW,val)
62
63 //#####################################
64 //
65 //#define FontManagerId_val(val) Int_val(val)
66 //#define Val_FontManagerId(val) Val_int(val)
67 //
68 ///* As ML_1, but the result is optional */
69 //#define OML_1(cname, conv1, conv) \
70 //value ml_##cname (value arg1) { return Val_option_ptr((cname (conv1 (arg1))),conv); }
71 ///* As ML_3, but the result is optional */
72 #define OML_3(cname, conv1, conv2, conv3, conv) \
73 value ml_##cname (value arg1, value arg2, value arg3) { return Val_option_ptr((cname (conv1 (arg1), conv2 (arg2), conv3 (arg3))),conv); }
74 ///* As ML_2, but the second argument is optional */
75 //#define ML_2O(cname, conv1, conv2, conv) \
76 //value ml_##cname (value arg1, value arg2) \
77 //{ return conv (cname (conv1(arg1), ptr_val_option(arg2,conv2))); }
78
79 value Val_Element_ref(GdomeElement* elem)
80 {
81   if (elem != NULL)
82     {
83       GdomeException exc = 0;
84       gdome_el_ref(elem, &exc);
85       g_assert(exc == 0);
86     }
87   return Val_Element(elem);
88 }
89
90 ML_2 (gtk_math_view_structure_changed, GtkMathView_val, Element_val, Unit)
91 ML_3 (gtk_math_view_attribute_changed, GtkMathView_val, Element_val, DOMString_val, Unit)
92 /* OML_3 (gtk_math_view_get_element_at, GtkMathView_val, Int_val, Int_val, Val_Element) */
93 ML_1 (gtk_math_view_freeze, GtkMathView_val, Unit)
94 ML_1 (gtk_math_view_thaw, GtkMathView_val, Unit)
95 ML_2 (gtk_math_view_load_uri, GtkMathView_val, String_val, Val_bool)
96 ML_2 (gtk_math_view_load_root, GtkMathView_val, Element_val, Val_bool)
97 ML_1 (gtk_math_view_unload, GtkMathView_val, Unit)
98 ML_2 (gtk_math_view_select, GtkMathView_val, Element_val, Unit)
99 ML_2 (gtk_math_view_unselect, GtkMathView_val, Element_val, Unit)
100 ML_2 (gtk_math_view_is_selected, GtkMathView_val, Element_val, Val_bool)
101 /*
102 ML_2 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Val_GtkWidget_sink)
103 ML_1 (gtk_math_view_get_width, GtkMathView_val, Val_int)
104 ML_1 (gtk_math_view_get_height, GtkMathView_val, Val_int)
105 */
106 ML_3 (gtk_math_view_set_top, GtkMathView_val, Int_val, Int_val, Unit)
107 ML_3 (gtk_math_view_set_adjustments, GtkMathView_val, GtkAdjustment_val, GtkAdjustment_val, Unit)
108 /*
109 ML_1 (gtk_math_view_get_hadjustment, GtkMathView_val, Val_GtkWidget)
110 ML_1 (gtk_math_view_get_vadjustment, GtkMathView_val, Val_GtkWidget)
111 */
112 ML_1 (gtk_math_view_get_buffer, GtkMathView_val, Val_GdkPixmap)
113 ML_2 (gtk_math_view_set_font_size, GtkMathView_val, Int_val, Unit)
114 ML_1 (gtk_math_view_get_font_size, GtkMathView_val, Val_int)
115 ML_2 (gtk_math_view_set_log_verbosity, GtkMathView_val, Int_val, Unit)
116 ML_1 (gtk_math_view_get_log_verbosity, GtkMathView_val, Val_int)
117 ML_2 (gtk_math_view_set_t1_opaque_mode, GtkMathView_val, Bool_val, Unit)
118 ML_1 (gtk_math_view_get_t1_opaque_mode, GtkMathView_val, Val_bool)
119 ML_2 (gtk_math_view_set_t1_anti_aliased_mode, GtkMathView_val, Bool_val, Unit)
120 ML_1 (gtk_math_view_get_t1_anti_aliased_mode, GtkMathView_val, Val_bool)
121 ML_1 (gtk_math_view_add_configuration_path, String_val, Unit)
122
123 value ml_gtk_math_view_get_element_at (value arg1, value arg2, value arg3)
124 {
125    CAMLparam3(arg1, arg2, arg3);
126    CAMLlocal1 (result);
127    GdomeElement* el;
128    if (gtk_math_view_get_element_at(GtkMathView_val (arg1), Int_val(arg2), Int_val(arg3), &el, NULL, NULL))
129      result = Val_option_ptr(el, Val_Element);
130    else
131      result = Val_unit;
132    CAMLreturn (result);
133 }
134
135 value ml_gtk_math_view_get_document (value arg1)
136 {
137    CAMLparam1(arg1);
138    CAMLlocal1(result);
139    GdomeDocument* doc = gtk_math_view_get_document(GtkMathView_val (arg1));
140    if (doc == NULL)
141            result = Val_unit;
142    else
143            result = Val_option_ptr(doc, Val_Document);
144    CAMLreturn (result);
145 }
146
147 value ml_gtk_math_view_get_adjustments(value arg1)
148 {
149    CAMLparam1(arg1);
150    CAMLlocal1(result);
151    GtkAdjustment* hadj;
152    GtkAdjustment* vadj;
153    gtk_math_view_get_adjustments(GtkMathView_val (arg1), &hadj, &vadj);
154    result = alloc(2, 0);
155    Store_field(result, 0, Val_GtkWidget(hadj));
156    Store_field(result, 1, Val_GtkWidget(vadj));
157    CAMLreturn(result);
158 }
159
160 value ml_gtk_math_view_get_size (value arg1)
161 {
162    CAMLparam1(arg1);
163    CAMLlocal1(result);
164    int width, height;
165    gtk_math_view_get_size(GtkMathView_val (arg1), &width, &height);
166    result = alloc(1, 0);
167    Store_field(result, 0, Val_int(width));
168    Store_field(result, 1, Val_int(height));
169    CAMLreturn (result);
170 }
171
172 value ml_gtk_math_view_get_bounding_box (value arg1)
173 {
174    CAMLparam1(arg1);
175    CAMLlocal1(result);
176    int width, height, depth;
177    GtkMathViewBoundingBox gbox;
178    gtk_math_view_get_bounding_box(GtkMathView_val (arg1), &gbox);
179    result = alloc(3, 0);
180    Store_field(result, 0, Val_int(gbox.width));
181    Store_field(result, 1, Val_int(gbox.height));
182    Store_field(result, 2, Val_int(gbox.depth));
183    CAMLreturn (result);
184 }
185
186 value ml_gtk_math_view_get_top (value arg1)
187 {
188    CAMLparam1(arg1);
189    CAMLlocal1(result);
190    int x, y;
191    gtk_math_view_get_top(GtkMathView_val (arg1), &x, &y);
192    result = alloc(2, 0);
193    Store_field(result, 0, Val_int(x));
194    Store_field(result, 1, Val_int(y));
195    CAMLreturn (result);
196 }
197
198 /*
199 value ml_gtk_math_view_get_element_coords (value arg1, value arg2)
200 {
201   CAMLparam2(arg1, arg2);
202   CAMLlocal1 (result);
203   int x, y;
204   gtk_math_view_get_element_coords(GtkMathView_val (arg1), Element_val(arg2), &x, &y);
205   result = alloc(2, 0);
206   Store_field(result, 0, Val_int(x));
207   Store_field(result, 1, Val_int(y));
208   CAMLreturn (result);
209 }
210 */
211
212 value ml_gtk_math_view_gdome_element_of_boxed_option (value arg1)
213 {
214    CAMLparam1(arg1);
215
216    GdomeException exc = 0;
217    GdomeElement* nr = NULL;
218    CAMLlocal1 (res);
219
220    if (arg1==Val_int(0)) {
221       assert(0);
222    } else {
223       nr = (GdomeElement*) Field(Field(arg1,0),1);
224    }
225
226    res = Val_Element_ref(nr);
227    if (res==Val_int(0)) {
228       assert(0);
229    }
230
231    CAMLreturn(res);
232 }
233
234 value ml_gtk_math_view_gdome_element_option_of_boxed_option (value arg1)
235 {
236    CAMLparam1(arg1);
237
238    GdomeElement* nr;
239    CAMLlocal1 (valnr);
240    CAMLlocal1 (res);
241
242    if (arg1==Val_int(0)) {
243       res=Val_unit;
244    } else {
245       GdomeException exc = 0;
246       GdomeElement* elem = (GdomeElement*) Field(Field(arg1,0),1);
247       assert(elem != NULL);
248       res = Val_option_ptr(elem, Val_Element_ref);
249    }
250
251    CAMLreturn(res);
252 }
253
254 value ml_gtk_math_view_model_event_of_boxed_option (value arg1)
255 {
256    CAMLparam1(arg1);
257    GdomeElement* nr;
258    CAMLlocal1 (valnr);
259    CAMLlocal1 (res);
260
261    assert(arg1 != Val_int(0));
262    GtkMathViewModelEvent* event = (GtkMathViewModelEvent*) Field(Field(arg1,0),1);
263    res = alloc(4, 0);
264    Store_field(res, 0, Val_option_ptr(event->id, Val_Element_ref));
265    Store_field(res, 1, Val_int(event->x));
266    Store_field(res, 2, Val_int(event->y));
267    Store_field(res, 3, Val_int(event->state));
268
269    CAMLreturn(res);
270 }
271