X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Flablgtkmathview%2Fml_gtk_mathview.c;h=51fded25e0bdd28567432a5368541a83292270f5;hb=5325734bc2e4927ed7ec146e35a6f0f2b49f50c1;hp=5f86ff03c4bc35a057f16159b340b0ac014542ee;hpb=4a97b3700b140024e1783ac12501ad5dfa4be9b5;p=helm.git diff --git a/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c b/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c index 5f86ff03c..51fded25e 100644 --- a/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c +++ b/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c @@ -1,4 +1,5 @@ -/* Copyright (C) 2000, Luca Padovani . +/* Copyright (C) 2000-2003, Luca Padovani , + * Claudio Sacerdoti Coen . * * This file is part of lablgtkmathview, the Ocaml binding * for the GtkMathView widget. @@ -21,71 +22,80 @@ */ #include -#include -#include + +#include #include + #include #include #include #include #include - -#include -#include +#include +#include #include #include #include #include +#include +#include +#include #include +#include -#include -#include "mlminidom/ml_minidom.h" - -/* : Next row should be put in a .h of lablgtk. */ -#define GtkAdjustment_val(val) check_cast(GTK_ADJUSTMENT,val) -/* : Next rows too */ +#include -extern value Val_GtkObject_sink(); +/* Init all */ -#define Val_GtkAny(w) Val_GtkObject((GtkObject*)w) -#define Val_GtkAny_sink(w) Val_GtkObject_sink((GtkObject*)w) -#define Val_GtkWidget Val_GtkAny -#define Val_GtkWidget_sink Val_GtkAny_sink - -#define GtkMathView_val(val) check_cast(GTK_MATH_VIEW,val) - -#define FontManagerId_val(val) Int_val(val) -#define Val_FontManagerId(val) Val_int(val) - -FontManagerId -font_manager_id_of_value(value v) +CAMLprim value ml_gtk_mathview_init(value unit) { - if (v == hash_variant("font_manager_gtk")) return FONT_MANAGER_GTK; - else if (v == hash_variant("font_manager_t1")) return FONT_MANAGER_T1; - else assert(0); + /* Since these are declared const, must force gcc to call them! */ + GType t = gtk_math_view_get_type(); + return Val_GType(t); } -value -value_of_font_manager_id(FontManagerId id) +#define GtkMathView_val(val) check_cast(GTK_MATH_VIEW,val) + +//##################################### +// +//#define FontManagerId_val(val) Int_val(val) +//#define Val_FontManagerId(val) Val_int(val) +// +///* As ML_1, but the result is optional */ +//#define OML_1(cname, conv1, conv) \ +//value ml_##cname (value arg1) { return Val_option_ptr((cname (conv1 (arg1))),conv); } +///* As ML_3, but the result is optional */ +#define OML_3(cname, conv1, conv2, conv3, conv) \ +value ml_##cname (value arg1, value arg2, value arg3) { return Val_option_ptr((cname (conv1 (arg1), conv2 (arg2), conv3 (arg3))),conv); } +///* As ML_2, but the second argument is optional */ +//#define ML_2O(cname, conv1, conv2, conv) \ +//value ml_##cname (value arg1, value arg2) \ +//{ return conv (cname (conv1(arg1), ptr_val_option(arg2,conv2))); } + +value Val_Element_ref(GdomeElement* elem) { - switch (id) { - case FONT_MANAGER_GTK: - return hash_variant("font_manager_gtk"); - case FONT_MANAGER_T1: - return hash_variant("font_manager_t1"); - default: - assert(0); - break; - } + if (elem != NULL) + { + GdomeException exc = 0; + gdome_el_ref(elem, &exc); + g_assert(exc == 0); + } + return Val_Element(elem); } -ML_2 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Val_GtkWidget_sink) -ML_2 (gtk_math_view_load, GtkMathView_val, String_val, Val_bool) +OML_3 (gtk_math_view_get_element_at, GtkMathView_val, Int_val, Int_val, Val_Element) +ML_1 (gtk_math_view_freeze, GtkMathView_val, Unit) +ML_1 (gtk_math_view_thaw, GtkMathView_val, Unit) +ML_2 (gtk_math_view_load_uri, GtkMathView_val, String_val, Val_bool) +ML_2 (gtk_math_view_load_doc, GtkMathView_val, Document_val, Val_bool) ML_1 (gtk_math_view_unload, GtkMathView_val, Unit) -/*ML_1 (gtk_math_view_dump, GtkMathView_val, Unit)*/ -ML_1 (gtk_math_view_get_selection, GtkMathView_val, Val_mDOMNodeRef) -ML_2 (gtk_math_view_set_selection, GtkMathView_val, mDOMNodeRef_val, Unit) +ML_2 (gtk_math_view_select, GtkMathView_val, Element_val, Unit) +ML_2 (gtk_math_view_unselect, GtkMathView_val, Element_val, Unit) +ML_2 (gtk_math_view_is_selected, GtkMathView_val, Element_val, Val_bool) +/* +ML_2 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Val_GtkWidget_sink) +*/ ML_1 (gtk_math_view_get_width, GtkMathView_val, Val_int) ML_1 (gtk_math_view_get_height, GtkMathView_val, Val_int) ML_3 (gtk_math_view_set_top, GtkMathView_val, Int_val, Int_val, Unit) @@ -93,45 +103,11 @@ ML_3 (gtk_math_view_set_adjustments, GtkMathView_val, GtkAdjustment_val, GtkAdju ML_1 (gtk_math_view_get_hadjustment, GtkMathView_val, Val_GtkWidget) ML_1 (gtk_math_view_get_vadjustment, GtkMathView_val, Val_GtkWidget) ML_1 (gtk_math_view_get_buffer, GtkMathView_val, Val_GdkPixmap) -ML_1 (gtk_math_view_get_frame, GtkMathView_val, Val_GtkWidget) +ML_1 (gtk_math_view_get_drawing_area, GtkMathView_val, Val_GtkWidget) ML_2 (gtk_math_view_set_font_size, GtkMathView_val, Int_val, Unit) ML_1 (gtk_math_view_get_font_size, GtkMathView_val, Val_int) -ML_2 (gtk_math_view_set_anti_aliasing, GtkMathView_val, Bool_val, Unit) -ML_1 (gtk_math_view_get_anti_aliasing, GtkMathView_val, Val_bool) -ML_2 (gtk_math_view_set_kerning, GtkMathView_val, Bool_val, Unit) -ML_1 (gtk_math_view_get_kerning, GtkMathView_val, Val_bool) ML_2 (gtk_math_view_set_log_verbosity, GtkMathView_val, Int_val, Unit) ML_1 (gtk_math_view_get_log_verbosity, GtkMathView_val, Val_int) -ML_2 (gtk_math_view_set_font_manager_type, GtkMathView_val, font_manager_id_of_value, Unit) -ML_1 (gtk_math_view_get_font_manager_type, GtkMathView_val, value_of_font_manager_id) - -value -ml_gtk_math_view_export_to_postscript_native(value arg1, - value w, value h, value x0, value y0, value disable_colors, value arg2) -{ - CAMLparam5(arg1,w,h,x0,y0); - CAMLxparam2(disable_colors, arg2); - - char *filename; - FILE *fd; - int res; - filename = String_val (arg2); - if ((fd = fopen(filename, "w"))) { - gtk_math_view_export_to_postscript(GtkMathView_val (arg1), - Int_val(w), Int_val(h), Int_val(x0), Int_val(y0), Bool_val(disable_colors), fd); - fclose (fd); - res = 1; - } else { - fprintf(stderr, "Error opening file %s for writing\n", filename); - res = 0; - } - CAMLreturn (Val_bool(res)); -} - -value ml_gtk_math_view_export_to_postscript_bytecode (value* arg, int argn) -{ - return ml_gtk_math_view_export_to_postscript_native(arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]); -} value ml_gtk_math_view_get_top (value arg1) { @@ -141,36 +117,62 @@ value ml_gtk_math_view_get_top (value arg1) gtk_math_view_get_top(GtkMathView_val (arg1), &x, &y); result = alloc(2, 0); Store_field(result, 0, Val_int(x)); - Store_field(result, 0, Val_int(y)); + Store_field(result, 1, Val_int(y)); CAMLreturn (result); } -value ml_gtk_math_view_mDOMNode_of_boxed (value arg1) +/* +value ml_gtk_math_view_get_element_coords (value arg1, value arg2) +{ + CAMLparam2(arg1, arg2); + CAMLlocal1 (result); + int x, y; + gtk_math_view_get_element_coords(GtkMathView_val (arg1), Element_val(arg2), &x, &y); + result = alloc(2, 0); + Store_field(result, 0, Val_int(x)); + Store_field(result, 1, Val_int(y)); + CAMLreturn (result); +} +*/ + +value ml_gtk_math_view_gdome_element_of_boxed_option (value arg1) { CAMLparam1(arg1); - mDOMNodeRef nr; - CAMLlocal1 (optval); + GdomeException exc = 0; + GdomeElement* nr = NULL; CAMLlocal1 (res); - nr = (mDOMNodeRef) Field(arg1, 1); - optval = Val_mDOMNodeRef(nr); - if (optval==Val_int(0)) { + if (arg1==Val_int(0)) { assert(0); } else { - res = Field(optval, 0); + nr = (GdomeElement*) Field(Field(arg1,0),1); + } + + res = Val_Element_ref(nr); + if (res==Val_int(0)) { + assert(0); } - CAMLreturn(res); + CAMLreturn(res); } -value ml_gtk_math_view_mDOMNode_option_of_boxed (value arg1) +value ml_gtk_math_view_gdome_element_option_of_boxed_option (value arg1) { CAMLparam1(arg1); - mDOMNodeRef nr; + GdomeElement* nr; + CAMLlocal1 (valnr); + CAMLlocal1 (res); - nr = (mDOMNodeRef) Field(arg1, 1); + if (arg1==Val_int(0)) { + res=Val_unit; + } else { + GdomeException exc = 0; + GdomeElement* elem = (GdomeElement*) Field(Field(arg1,0),1); + assert(elem != NULL); + res = Val_option_ptr(elem, Val_Element_ref); + } - CAMLreturn(Val_mDOMNodeRef(nr)); + CAMLreturn(res); }