]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.1/ml_gtk_mathview.c
This commit was manufactured by cvs2svn to create branch 'helm'.
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20000829_gtkmathview-0.2.1 / ml_gtk_mathview.c
1 #include <string.h>
2 #include <assert.h>
3 #include <gtk/gtk.h>
4 #include <caml/mlvalues.h>
5 #include <caml/alloc.h>
6 #include <caml/memory.h>
7 #include <caml/callback.h>
8 #include <caml/fail.h>
9
10 #include <gtkmathview/gtkmathview.h>
11 #include <ml_gtk.h>
12
13 #include <wrappers.h>
14 #include <ml_glib.h>
15 #include <ml_gdk.h>
16 #include <ml_gtk.h>
17 #include <gtk_tags.h>
18
19 #include <minidom.h>
20 #include "minidom/ml_minidom.h"
21
22 /* <CSC/>: Next row should be put in a .h of lablgtk. */
23 #define GtkAdjustment_val(val) check_cast(GTK_ADJUSTMENT,val)
24
25 #define GtkMathView_val(val) check_cast(GTK_MATH_VIEW,val)
26
27 #define FontManagerId_val(val) Int_val(val)
28 #define Val_FontManagerId(val) Val_int(val)
29
30 ML_2 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Val_GtkWidget_sink)
31 ML_2 (gtk_math_view_load, GtkMathView_val, String_val, Val_bool)
32 ML_1 (gtk_math_view_unload, GtkMathView_val, Unit)
33 /*ML_1 (gtk_math_view_dump, GtkMathView_val, Unit)*/
34 ML_1 (gtk_math_view_get_selection, GtkMathView_val, Val_mDOMNodeRef)
35 ML_2 (gtk_math_view_set_selection, GtkMathView_val, mDOMNodeRef_val, Unit)
36 ML_1 (gtk_math_view_get_width, GtkMathView_val, Val_int)
37 ML_1 (gtk_math_view_get_height, GtkMathView_val, Val_int)
38 ML_3 (gtk_math_view_set_top, GtkMathView_val, Int_val, Int_val, Unit)
39 ML_3 (gtk_math_view_set_adjustments, GtkMathView_val, GtkAdjustment_val, GtkAdjustment_val, Unit)
40 ML_1 (gtk_math_view_get_hadjustment, GtkMathView_val, Val_GtkWidget)
41 ML_1 (gtk_math_view_get_vadjustment, GtkMathView_val, Val_GtkWidget)
42 ML_1 (gtk_math_view_get_buffer, GtkMathView_val, Val_GdkPixmap)
43 ML_1 (gtk_math_view_get_frame, GtkMathView_val, Val_GtkWidget)
44 ML_2 (gtk_math_view_set_font_size, GtkMathView_val, Int_val, Unit)
45 ML_1 (gtk_math_view_get_font_size, GtkMathView_val, Val_int)
46 ML_2 (gtk_math_view_set_anti_aliasing, GtkMathView_val, Bool_val, Unit)
47 ML_1 (gtk_math_view_get_anti_aliasing, GtkMathView_val, Val_bool)
48 ML_2 (gtk_math_view_set_kerning, GtkMathView_val, Bool_val, Unit)
49 ML_1 (gtk_math_view_get_kerning, GtkMathView_val, Val_bool)
50 ML_2 (gtk_math_view_set_log_verbosity, GtkMathView_val, Int_val, Unit)
51 ML_1 (gtk_math_view_get_log_verbosity, GtkMathView_val, Val_int)
52 ML_2 (gtk_math_view_set_font_manager_type, GtkMathView_val, FontManagerId_val, Unit)
53 ML_1 (gtk_math_view_get_font_manager_type, GtkMathView_val, Val_FontManagerId)
54
55 value
56 ml_gtk_math_view_export_to_postscript_native(value arg1,
57                 value w, value h, value x0, value y0, value disable_colors, value arg2)
58 {
59    CAMLparam5(arg1,w,h,x0,y0);
60    CAMLxparam2(disable_colors, arg2);
61
62    char *filename;
63    FILE *fd;
64    int res;
65    filename = String_val (arg2);
66    if ((fd = fopen(filename, "w"))) {
67       gtk_math_view_export_to_postscript(GtkMathView_val (arg1),
68                       Int_val(w), Int_val(h), Int_val(x0), Int_val(y0), Bool_val(disable_colors), fd);
69       fclose (fd);
70       res = 1;
71    } else {
72       fprintf(stderr, "Error opening file %s for writing\n", filename);
73       res = 0;
74    }
75    CAMLreturn (Val_bool(res));
76 }
77
78 value ml_gtk_math_view_export_to_postscript_bytecode (value* arg, int argn)
79 {
80    return ml_gtk_math_view_export_to_postscript_native(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]);
81 }
82
83 value ml_gtk_math_view_get_top (value arg1)
84 {
85    CAMLparam1(arg1);
86    CAMLlocal1 (result);
87    int x, y;
88    gtk_math_view_get_top(GtkMathView_val (arg1), &x, &y);
89    result = alloc(2, 0);
90    Store_field(result, 0, Val_int(x));
91    Store_field(result, 0, Val_int(y));
92    CAMLreturn (result);
93 }
94
95
96 value ml_gtk_math_view_mDOMNode_of_bodex_option (value arg1)
97 {
98    CAMLparam1(arg1);
99
100    mDOMNodeRef nr;
101    CAMLlocal1 (tmp);
102    CAMLlocal1 (optval);
103    CAMLlocal1 (res);
104
105    if (arg1==Val_int(0)) {
106       assert(0);
107    } else {
108       tmp = Field(arg1, 0);
109       nr = (mDOMNodeRef) Field(tmp, 1);
110    }
111    optval = Val_mDOMNodeRef(nr);
112    if (optval==Val_int(0)) {
113       assert(0);
114    } else {
115       res = Field(optval, 0);
116    }
117
118   CAMLreturn(res);
119 }
120
121 value ml_gtk_math_view_mDOMNode_option_of_bodex_option (value arg1)
122 {
123    CAMLparam1(arg1);
124
125    mDOMNodeRef nr;
126    CAMLlocal1 (tmp);
127
128    if (arg1==Val_int(0)) {
129       nr=NULL;
130    } else {
131       tmp = Field(arg1, 0);
132       nr = (mDOMNodeRef) Field(tmp, 1);
133    }
134
135   CAMLreturn(Val_mDOMNodeRef(nr));
136 }