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