]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c
First commit towards the 0.2.8 version.
[helm.git] / helm / DEVEL / lablgtkmathview / ml_gtk_mathview.c
1 /* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
2  *
3  * This file is part of lablgtkmathview, the Ocaml binding
4  * for the GtkMathView widget.
5  * 
6  * lablgtkmathview is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * lablgtkmathview is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with lablgtkmathview; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  * 
20  * For details, send a mail to the author.
21  */
22
23 #include <assert.h>
24 #include <string.h>
25 #include <assert.h>
26 #include <gtk/gtk.h>
27 #include <caml/mlvalues.h>
28 #include <caml/alloc.h>
29 #include <caml/memory.h>
30 #include <caml/callback.h>
31 #include <caml/fail.h>
32
33 #include <gtkmathview.h>
34 #include <ml_gtk.h>
35
36 #include <wrappers.h>
37 #include <ml_glib.h>
38 #include <ml_gdk.h>
39 #include <ml_gtk.h>
40 #include <gtk_tags.h>
41
42 #include <minidom.h>
43 #include "ml_minidom.h"
44
45 #define GtkMathView_val(val) check_cast(GTK_MATH_VIEW,val)
46
47 #define FontManagerId_val(val) Int_val(val)
48 #define Val_FontManagerId(val) Val_int(val)
49
50 FontManagerId
51 font_manager_id_of_value(value v)
52 {
53   if (v == hash_variant("font_manager_gtk")) return FONT_MANAGER_GTK;
54   else if (v == hash_variant("font_manager_t1")) return FONT_MANAGER_T1;
55   else assert(0);
56 }
57
58 value
59 value_of_font_manager_id(FontManagerId id)
60 {
61   switch (id) {
62   case FONT_MANAGER_GTK:
63     return hash_variant("font_manager_gtk");
64   case FONT_MANAGER_T1:
65     return hash_variant("font_manager_t1");
66   default:
67     assert(0);
68     break;
69   }
70 }
71
72 ML_2 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Val_GtkWidget_sink)
73 ML_2 (gtk_math_view_load, GtkMathView_val, String_val, Val_bool)
74 ML_2 (gtk_math_view_load_tree, GtkMathView_val, mDOMDocRef_val, Val_bool)
75 ML_1 (gtk_math_view_unload, GtkMathView_val, Unit)
76 ML_1 (gtk_math_view_get_selection, GtkMathView_val, Val_mDOMNodeRef)
77 ML_2 (gtk_math_view_set_selection, GtkMathView_val, mDOMNodeRef_val, Unit)
78 ML_1 (gtk_math_view_get_width, GtkMathView_val, Val_int)
79 ML_1 (gtk_math_view_get_height, GtkMathView_val, Val_int)
80 ML_3 (gtk_math_view_set_top, GtkMathView_val, Int_val, Int_val, Unit)
81 ML_3 (gtk_math_view_set_adjustments, GtkMathView_val, GtkAdjustment_val, GtkAdjustment_val, Unit)
82 ML_1 (gtk_math_view_get_hadjustment, GtkMathView_val, Val_GtkWidget)
83 ML_1 (gtk_math_view_get_vadjustment, GtkMathView_val, Val_GtkWidget)
84 ML_1 (gtk_math_view_get_buffer, GtkMathView_val, Val_GdkPixmap)
85 ML_1 (gtk_math_view_get_frame, GtkMathView_val, Val_GtkWidget)
86 ML_2 (gtk_math_view_set_font_size, GtkMathView_val, Int_val, Unit)
87 ML_1 (gtk_math_view_get_font_size, GtkMathView_val, Val_int)
88 ML_2 (gtk_math_view_set_anti_aliasing, GtkMathView_val, Bool_val, Unit)
89 ML_1 (gtk_math_view_get_anti_aliasing, GtkMathView_val, Val_bool)
90 ML_2 (gtk_math_view_set_kerning, GtkMathView_val, Bool_val, Unit)
91 ML_1 (gtk_math_view_get_kerning, GtkMathView_val, Val_bool)
92 ML_2 (gtk_math_view_set_transparency, GtkMathView_val, Bool_val, Unit)
93 ML_1 (gtk_math_view_get_transparency, GtkMathView_val, Val_bool)
94 ML_2 (gtk_math_view_set_log_verbosity, GtkMathView_val, Int_val, Unit)
95 ML_1 (gtk_math_view_get_log_verbosity, GtkMathView_val, Val_int)
96 ML_2 (gtk_math_view_set_font_manager_type, GtkMathView_val, font_manager_id_of_value, Unit)
97 ML_1 (gtk_math_view_get_font_manager_type, GtkMathView_val, value_of_font_manager_id)
98 ML_1 (gtk_math_view_get_element, GtkMathView_val, Val_mDOMNodeRef)
99 ML_1 (gtk_math_view_get_action, GtkMathView_val, Val_mDOMNodeRef)
100 ML_1 (gtk_math_view_action_get_selected, GtkMathView_val, Val_int)
101 ML_2 (gtk_math_view_action_set_selected, GtkMathView_val, Int_val, Unit)
102 ML_1 (gtk_math_view_action_toggle, GtkMathView_val, Unit)
103
104 value
105 ml_gtk_math_view_export_to_postscript_native(value arg1,
106                 value w, value h, value x0, value y0, value disable_colors, value arg2)
107 {
108    CAMLparam5(arg1,w,h,x0,y0);
109    CAMLxparam2(disable_colors, arg2);
110
111    char *filename;
112    FILE *fd;
113    int res;
114    filename = String_val (arg2);
115    if ((fd = fopen(filename, "w"))) {
116       gtk_math_view_export_to_postscript(GtkMathView_val (arg1),
117                       Int_val(w), Int_val(h), Int_val(x0), Int_val(y0), Bool_val(disable_colors), fd);
118       fclose (fd);
119       res = 1;
120    } else {
121       fprintf(stderr, "Error opening file %s for writing\n", filename);
122       res = 0;
123    }
124    CAMLreturn (Val_bool(res));
125 }
126
127 value ml_gtk_math_view_export_to_postscript_bytecode (value* arg, int argn)
128 {
129    return ml_gtk_math_view_export_to_postscript_native(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]);
130 }
131
132 value ml_gtk_math_view_get_top (value arg1)
133 {
134    CAMLparam1(arg1);
135    CAMLlocal1 (result);
136    int x, y;
137    gtk_math_view_get_top(GtkMathView_val (arg1), &x, &y);
138    result = alloc(2, 0);
139    Store_field(result, 0, Val_int(x));
140    Store_field(result, 0, Val_int(y));
141    CAMLreturn (result);
142 }
143
144
145 value ml_gtk_math_view_mDOMNode_of_boxed_option (value arg1)
146 {
147    CAMLparam1(arg1);
148
149    mDOMNodeRef nr;
150    CAMLlocal1 (tmp);
151    CAMLlocal1 (optval);
152    CAMLlocal1 (res);
153
154    if (arg1==Val_int(0)) {
155       assert(0);
156    } else {
157       tmp = Field(arg1, 0);
158       nr = (mDOMNodeRef) Field(tmp, 1);
159    }
160    optval = Val_mDOMNodeRef(nr);
161    if (optval==Val_int(0)) {
162       assert(0);
163    } else {
164       res = Field(optval, 0);
165    }
166
167   CAMLreturn(res);
168 }
169
170 value ml_gtk_math_view_mDOMNode_option_of_boxed_option (value arg1)
171 {
172    CAMLparam1(arg1);
173
174    mDOMNodeRef nr;
175    CAMLlocal1 (tmp);
176
177    if (arg1==Val_int(0)) {
178       nr=NULL;
179    } else {
180       tmp = Field(arg1, 0);
181       nr = (mDOMNodeRef) Field(tmp, 1);
182    }
183
184   CAMLreturn(Val_mDOMNodeRef(nr));
185 }