From 5a7485a8f24e457fd4cc091f24c48f3cb8d11fca Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Wed, 6 Feb 2002 15:06:33 +0000 Subject: [PATCH] First commit toward 0.3.0. Instead of minidom, gdome and gmetadom are now used. --- helm/DEVEL/lablgtkmathview/META.in | 2 +- helm/DEVEL/lablgtkmathview/Makefile.in | 8 +- helm/DEVEL/lablgtkmathview/configure.in | 10 +- helm/DEVEL/lablgtkmathview/debian/control | 2 +- helm/DEVEL/lablgtkmathview/gMathView.ml | 57 ++++++- helm/DEVEL/lablgtkmathview/gtkMathView.ml | 51 ++---- helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c | 53 ++++--- helm/DEVEL/lablgtkmathview/test/test.ml | 157 ++++++++++--------- 8 files changed, 181 insertions(+), 159 deletions(-) diff --git a/helm/DEVEL/lablgtkmathview/META.in b/helm/DEVEL/lablgtkmathview/META.in index ef5298f15..c38ad22dc 100644 --- a/helm/DEVEL/lablgtkmathview/META.in +++ b/helm/DEVEL/lablgtkmathview/META.in @@ -1,4 +1,4 @@ -requires="mlminidom lablgtk" +requires="gdome lablgtk" version="@VERSION@" archive(byte)="lablgtkmathview.cma ml_gtk_mathview.o" archive(native)="lablgtkmathview.cmxa ml_gtk_mathview.o" diff --git a/helm/DEVEL/lablgtkmathview/Makefile.in b/helm/DEVEL/lablgtkmathview/Makefile.in index e7d9c0d50..9bfde70c1 100644 --- a/helm/DEVEL/lablgtkmathview/Makefile.in +++ b/helm/DEVEL/lablgtkmathview/Makefile.in @@ -11,7 +11,7 @@ DIST_FILES = \ configure.in gMathView.ml gtkMathView.ml gtk_mathview.ml \ ml_gtk_mathview.c META.in DOC_FILES = AUTHORS COPYING ChangeLog NEWS README -REQUIRES = mlminidom lablgtk +REQUIRES = gdome lablgtk PREDICATES = MLFLAGS = -labels @@ -39,7 +39,7 @@ dist: rm -rf $(PACKAGE)-$(VERSION) ml_gtk_mathview.o: ml_gtk_mathview.c - gcc -c -I$(INCLUDEDIR) `ocamlfind query -i-format lablgtk` `glib-config --cflags` `minidom-config --cflags` `gtk-config --cflags` `gtkmathview-config --cflags` `ocamlfind query -i-format mlminidom` $< + gcc -c -I$(INCLUDEDIR) `ocamlfind query -i-format lablgtk` `glib-config --cflags` `gtk-config --cflags` `gtkmathview-config --cflags` `gdome-config --cflags` `ocamlfind query -i-format gdome` $< .SUFFIXES: .cmo .cmi .cmx .ml .mli @@ -60,12 +60,12 @@ include .depend $(ARCHIVE): $(OBJECTS) $(OCAMLC) -a -custom -package "$(REQUIRES)" \ -predicates "$(PREDICATES)" -o $@ $^ \ - -cclib "`glib-config --libs` `minidom-config --libs` `gtkmathview-config --libs`" + -cclib "`glib-config --libs` `gdome-config --libs` `gtkmathview-config --libs`" $(ARCHIVE_OPT): $(OBJECTS_OPT) $(OCAMLOPT) -a -package "$(REQUIRES)" \ -predicates "$(PREDICATES)" -o $@ $^ \ - -cclib "`glib-config --libs` `minidom-config --libs` `gtkmathview-config --libs`" + -cclib "`glib-config --libs` `gdome-config --libs` `gtkmathview-config --libs`" $(TESTDIR)/test: $(OBJECTS_C) $(ARCHIVE) $(TESTDIR)/test.ml mkdir -p $(TMPPKGDIR) diff --git a/helm/DEVEL/lablgtkmathview/configure.in b/helm/DEVEL/lablgtkmathview/configure.in index b01be7d64..d9bb91ac2 100644 --- a/helm/DEVEL/lablgtkmathview/configure.in +++ b/helm/DEVEL/lablgtkmathview/configure.in @@ -3,8 +3,8 @@ AC_INIT(gMathView.ml) PACKAGE=lablgtkmathview LABLGTKMATHVIEW_MAJOR_VERSION=0 -LABLGTKMATHVIEW_MINOR_VERSION=2 -LABLGTKMATHVIEW_MICRO_VERSION=8 +LABLGTKMATHVIEW_MINOR_VERSION=3 +LABLGTKMATHVIEW_MICRO_VERSION=0 LABLGTKMATHVIEW_VERSION=$LABLGTKMATHVIEW_MAJOR_VERSION.$LABLGTKMATHVIEW_MINOR_VERSION.$LABLGTKMATHVIEW_MICRO_VERSION VERSION=$LABLGTKMATHVIEW_VERSION @@ -23,9 +23,9 @@ if test $HAVE_OCAMLFIND = "no"; then AC_MSG_ERROR(could not find ocamlfind in PATH, please make sure findlib is installed) fi -AC_MSG_CHECKING("for mlminidom") -ocamlfind query mlminidom || - AC_MSG_ERROR(mlminidom not installed (according to findlib)) +AC_MSG_CHECKING("for gdome") +ocamlfind query gdome || + AC_MSG_ERROR(gdome not installed (according to findlib)) AC_MSG_CHECKING("for lablgtk") ocamlfind query lablgtk || diff --git a/helm/DEVEL/lablgtkmathview/debian/control b/helm/DEVEL/lablgtkmathview/debian/control index 71d2dfb0c..645634cb4 100644 --- a/helm/DEVEL/lablgtkmathview/debian/control +++ b/helm/DEVEL/lablgtkmathview/debian/control @@ -2,7 +2,7 @@ Source: lablgtkmathview Section: devel Priority: optional Maintainer: Stefano Zacchiroli -Build-Depends: debhelper (>> 2.0.0), ocaml (>= 3.02), lablgtk (= 1.2.1helm-1), mlminidom (>= 0.2.1), libgtk1.2-dev, libgtkmathview-dev (>= 0.2.8), libminidom-dev (>= 0.1.3), libxml2-dev, ocaml-findlib +Build-Depends: debhelper (>> 2.0.0), ocaml (>= 3.02), lablgtk (= 1.2.1helm-1), libgtk1.2-dev, libgtkmathview-dev (>= 0.3.0), libxml2-dev, ocaml-findlib Standards-Version: 3.5.2 Package: lablgtkmathview diff --git a/helm/DEVEL/lablgtkmathview/gMathView.ml b/helm/DEVEL/lablgtkmathview/gMathView.ml index 00c239afc..63a3c234a 100644 --- a/helm/DEVEL/lablgtkmathview/gMathView.ml +++ b/helm/DEVEL/lablgtkmathview/gMathView.ml @@ -34,11 +34,36 @@ exception NoSelection;; class math_view_signals obj = object inherit GContainer.container_signals obj - method clicked = GtkSignal.connect ~sgn:MathView.Signals.clicked obj ~after + method clicked = + let module S = GtkSignal in + let new_clicked = + let new_marshaller f x y = + MathView.Signals.clicked.S.marshaller + (fun e -> f (new Gdome.element e)) x y + in + { S.name = "clicked"; S.marshaller = new_marshaller } + in + GtkSignal.connect ~sgn:new_clicked obj ~after method selection_changed = - GtkSignal.connect ~sgn:MathView.Signals.selection_changed obj ~after + let module S = GtkSignal in + let new_selection_changed = + let new_marshaller f x y = + MathView.Signals.selection_changed.S.marshaller + (function None -> f None | Some e -> f (Some (new Gdome.element e))) x y + in + { S.name = "selection_changed"; S.marshaller = new_marshaller } + in + GtkSignal.connect ~sgn:new_selection_changed obj ~after method element_changed = - GtkSignal.connect ~sgn:MathView.Signals.element_changed obj ~after + let module S = GtkSignal in + let new_element_changed = + let new_marshaller f x y = + MathView.Signals.element_changed.S.marshaller + (function None -> f None | Some e -> f (Some (new Gdome.element e))) x y + in + { S.name = "element_changed"; S.marshaller = new_marshaller } + in + GtkSignal.connect ~sgn:new_element_changed obj ~after end class math_view obj = object @@ -47,10 +72,20 @@ class math_view obj = object method load ~filename = if not (MathView.load obj ~filename) then raise (ErrorLoadingFile filename) method load_tree ~dom = - if not (MathView.load_tree obj ~dom) then raise ErrorLoadingDOM + if not (MathView.load_tree obj ~dom:((dom : Gdome.document)#as_Document)) then + raise ErrorLoadingDOM method unload = MathView.unload obj - method get_selection = MathView.get_selection obj - method set_selection (node : Ominidom.o_mDOMNode option) = MathView.set_selection obj node + method get_selection = + match MathView.get_selection obj with + None -> None + | Some element -> Some (new Gdome.element element) + method set_selection element = + let element = + match element with + None -> None + | Some element -> Some ((element : Gdome.element)#as_Element) + in + MathView.set_selection obj element method get_width = MathView.get_width obj method get_height = MathView.get_height obj method get_top = MathView.get_top obj @@ -82,10 +117,16 @@ class math_view obj = object if not result then raise (ErrorWritingFile filename) method get_font_manager_type = MathView.get_font_manager_type obj method set_font_manager_type ~fm_type = MathView.set_font_manager_type obj ~fm_type - method get_element = MathView.get_element obj + method get_element = + match MathView.get_element obj with + None -> None + | Some element -> Some (new Gdome.element element) method action_get_selected = MathView.action_get_selected obj method action_set_selected = MathView.action_set_selected obj - method get_action = MathView.get_action obj + method get_action = + match MathView.get_action obj with + None -> None + | Some ac -> Some (new Gdome.element ac) method action_toggle = MathView.action_toggle obj end diff --git a/helm/DEVEL/lablgtkmathview/gtkMathView.ml b/helm/DEVEL/lablgtkmathview/gtkMathView.ml index eed812d9e..fb2cfc4e0 100644 --- a/helm/DEVEL/lablgtkmathview/gtkMathView.ml +++ b/helm/DEVEL/lablgtkmathview/gtkMathView.ml @@ -26,25 +26,13 @@ open Tags open GtkBase open Gpointer -external mDOMNode_of_boxed_option : - Gpointer.boxed option -> Minidom.mDOMNode = - "ml_gtk_math_view_mDOMNode_of_boxed_option" +external gdome_element_of_boxed_option : + Gpointer.boxed option -> TElement.t = + "ml_gtk_math_view_gdome_element_of_boxed_option" -external mDOMNode_option_of_boxed_option : - Gpointer.boxed option -> Minidom.mDOMNode option = - "ml_gtk_math_view_mDOMNode_option_of_boxed_option" - -let o_mDOMNode_of_mDOMNode node = new Ominidom.o_mDOMNode node - -let o_mDOMNode_option_of_mDOMNode_option = - function - | Some x -> Some (o_mDOMNode_of_mDOMNode x) - | None -> None - -let mDOMNode_option_of_o_mDOMNode_option = - function - | Some x -> Some (x#get_dom_node) - | None -> None +external gdome_element_option_of_boxed_option : + Gpointer.boxed option -> TElement.t option = + "ml_gtk_math_view_gdome_element_option_of_boxed_option" module MathView = struct exception NoSelection @@ -56,20 +44,15 @@ module MathView = struct create (optboxed adjustmenth) (optboxed adjustmentv) external load : [>`math_view] obj -> filename:string -> bool = "ml_gtk_math_view_load" - external raw_load_tree : [>`math_view] obj -> Minidom.mDOMDoc -> bool = + external load_tree : [>`math_view] obj -> dom:[> `Document] GdomeT.t -> bool = "ml_gtk_math_view_load_tree" - let load_tree obj ~(dom:Ominidom.o_mDOMDoc) = - raw_load_tree obj dom#get_dom_doc external unload : [>`math_view] obj -> unit = "ml_gtk_math_view_unload" - external raw_get_selection : [>`math_view] obj -> Minidom.mDOMNode option = + external get_selection : [>`math_view] obj -> TElement.t option = "ml_gtk_math_view_get_selection" - let get_selection obj = - o_mDOMNode_option_of_mDOMNode_option (raw_get_selection obj) - external raw_set_selection : [>`math_view] obj -> Minidom.mDOMNode option -> unit= + external set_selection : + [>`math_view] obj -> [> `Element] GdomeT.t option -> unit= "ml_gtk_math_view_set_selection" - let set_selection obj node = - raw_set_selection obj (mDOMNode_option_of_o_mDOMNode_option node) external get_width : [>`math_view] obj -> int = "ml_gtk_math_view_get_width" external get_height : [>`math_view] obj -> int = @@ -117,18 +100,14 @@ module MathView = struct external set_font_manager_type : [>`math_view] obj -> fm_type:[`font_manager_gtk | `font_manager_t1] -> unit = "ml_gtk_math_view_set_font_manager_type" - external raw_get_element : [>`math_view] obj -> Minidom.mDOMNode option = + external get_element : [>`math_view] obj -> TElement.t option = "ml_gtk_math_view_get_element" - let get_element obj = - o_mDOMNode_option_of_mDOMNode_option (raw_get_element obj) external action_get_selected : [>`math_view] obj -> int = "ml_gtk_math_view_action_get_selected" external action_set_selected : [>`math_view] obj -> int -> unit = "ml_gtk_math_view_action_set_selected" - external raw_get_action : [>`math_view] obj -> Minidom.mDOMNode option = + external get_action : [>`math_view] obj -> TElement.t option = "ml_gtk_math_view_get_action" - let get_action obj = - o_mDOMNode_option_of_mDOMNode_option (raw_get_action obj) external action_toggle : [>`math_view] obj -> unit = "ml_gtk_math_view_action_toggle" @@ -138,7 +117,7 @@ module MathView = struct let clicked : ([>`math_view],_) t = let marshal_clicked f _ = function - [GtkArgv.POINTER node] -> f (o_mDOMNode_of_mDOMNode (mDOMNode_of_boxed_option node)) + [GtkArgv.POINTER element] -> f (gdome_element_of_boxed_option element) | _ -> invalid_arg "GtkMathView.MathView.Signals.marshal_clicked" in { name = "clicked"; marshaller = marshal_clicked } @@ -146,7 +125,7 @@ module MathView = struct let selection_changed : ([>`math_view],_) t = let marshal_selection_changed f _ = function - [GtkArgv.POINTER node] -> f (o_mDOMNode_option_of_mDOMNode_option (mDOMNode_option_of_boxed_option node)) + [GtkArgv.POINTER element] -> f (gdome_element_option_of_boxed_option element) | _ -> invalid_arg "GtkMathView.MathView.Signals.marshal_selection_changed" in { name = "selection_changed"; marshaller = marshal_selection_changed } @@ -154,7 +133,7 @@ module MathView = struct let element_changed : ([>`math_view],_) t = let marshal_element_changed f _ = function - [GtkArgv.POINTER node] -> f (o_mDOMNode_option_of_mDOMNode_option (mDOMNode_option_of_boxed_option node)) + [GtkArgv.POINTER element] -> f (gdome_element_option_of_boxed_option element) | _ -> invalid_arg "GtkMathView.MathView.Signals.marshal_element_changed" in { name = "element_changed"; marshaller = marshal_element_changed } diff --git a/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c b/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c index 5038e8b86..df4719b61 100644 --- a/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c +++ b/helm/DEVEL/lablgtkmathview/ml_gtk_mathview.c @@ -39,14 +39,21 @@ #include #include -#include -#include "ml_minidom.h" +#include #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_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))); } + FontManagerId font_manager_id_of_value(value v) { @@ -71,10 +78,10 @@ value_of_font_manager_id(FontManagerId id) 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) -ML_2 (gtk_math_view_load_tree, GtkMathView_val, mDOMDocRef_val, Val_bool) +ML_2 (gtk_math_view_load_tree, GtkMathView_val, Document_val, Val_bool) ML_1 (gtk_math_view_unload, 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) +OML_1 (gtk_math_view_get_selection, GtkMathView_val, Val_Element) +ML_2O (gtk_math_view_set_selection, GtkMathView_val, Element_val, Unit) 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) @@ -95,8 +102,8 @@ 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) -ML_1 (gtk_math_view_get_element, GtkMathView_val, Val_mDOMNodeRef) -ML_1 (gtk_math_view_get_action, GtkMathView_val, Val_mDOMNodeRef) +OML_1 (gtk_math_view_get_element, GtkMathView_val, Val_Element) +OML_1 (gtk_math_view_get_action, GtkMathView_val, Val_Element) ML_1 (gtk_math_view_action_get_selected, GtkMathView_val, Val_int) ML_2 (gtk_math_view_action_set_selected, GtkMathView_val, Int_val, Unit) ML_1 (gtk_math_view_action_toggle, GtkMathView_val, Unit) @@ -141,45 +148,39 @@ value ml_gtk_math_view_get_top (value arg1) CAMLreturn (result); } - -value ml_gtk_math_view_mDOMNode_of_boxed_option (value arg1) +value ml_gtk_math_view_gdome_element_of_boxed_option (value arg1) { CAMLparam1(arg1); - mDOMNodeRef nr; - CAMLlocal1 (tmp); - CAMLlocal1 (optval); + GdomeElement* nr; CAMLlocal1 (res); if (arg1==Val_int(0)) { assert(0); } else { - tmp = Field(arg1, 0); - nr = (mDOMNodeRef) Field(tmp, 1); + nr = (GdomeElement*) Field(Field(arg1,0), 1); } - optval = Val_mDOMNodeRef(nr); - if (optval==Val_int(0)) { + res = Val_Element(nr); + if (res==Val_int(0)) { assert(0); - } else { - res = Field(optval, 0); } - CAMLreturn(res); + CAMLreturn(res); } -value ml_gtk_math_view_mDOMNode_option_of_boxed_option (value arg1) +value ml_gtk_math_view_gdome_element_option_of_boxed_option (value arg1) { CAMLparam1(arg1); - mDOMNodeRef nr; - CAMLlocal1 (tmp); + GdomeElement* nr; + CAMLlocal1 (valnr); + CAMLlocal1 (res); if (arg1==Val_int(0)) { - nr=NULL; + res=Val_unit; } else { - tmp = Field(arg1, 0); - nr = (mDOMNodeRef) Field(tmp, 1); + res = Val_option_ptr((GdomeElement*) Field(Field(arg1,0),1),Val_Element); } - CAMLreturn(Val_mDOMNodeRef(nr)); + CAMLreturn(res); } diff --git a/helm/DEVEL/lablgtkmathview/test/test.ml b/helm/DEVEL/lablgtkmathview/test/test.ml index 855ce9584..61dd0370c 100644 --- a/helm/DEVEL/lablgtkmathview/test/test.ml +++ b/helm/DEVEL/lablgtkmathview/test/test.ml @@ -29,44 +29,54 @@ (******************************************************************************) (* Callbacks *) -let selection_changed mathview (node : Ominidom.o_mDOMNode option) = - let module O = Ominidom in - print_string ("selection_changed: " ^ - (match node with - None -> "selection_changed on nothing" - | Some node -> - match node#get_name with - | Some x -> x#get_string - | None -> "on element without name" - ) ^ "\n"); - mathview#set_selection node; - flush stdout +let selection_changed mathview (element : Gdome.element option) = + print_endline ("selection_changed: " ^ + (match element with + None -> "selection_changed on nothing" + | Some element -> element#get_tagName#to_string + ) + ) ; + mathview#set_selection element; + flush stdout ;; +let element_changed mathview (element : Gdome.element option) = + print_endline ("element_changed: " ^ + (match element with + None -> "element_changed on nothing" + | Some element -> element#get_tagName#to_string + ) + ) ; + flush stdout +;; -let rec jump (node : Ominidom.o_mDOMNode) = - let module O = Ominidom in - match node#get_attribute (O.o_mDOMString_of_string "href") with - None -> - begin - try - let p = node#get_parent in - jump p - with - O.Node_has_no_parent -> +let rec jump (element : Gdome.element) = + let module G = Gdome in + let attr = (element#getAttribute ~name:(G.domString "href"))#to_string in + if attr = "" then + match element#get_parentNode with + Some p -> + begin + try + jump (new Gdome.element_of_node p) + with + GdomeInit.DOMCastException _ -> print_string "jump: NO HREF FOR THIS NODE\n" ; flush stdout ; false - end - | Some x -> - print_string ("jump: " ^ x#get_string ^ "\n") ; - flush stdout ; - true + end + | None -> assert false (* every element has a parent *) + else + begin + print_endline ("jump: " ^ attr) ; + flush stdout ; + true + end ;; -let clicked mathview (node : Ominidom.o_mDOMNode) = - let module O = Ominidom in - if not (jump node) then +let clicked (mathview : GMathView.math_view) (element : Gdome.element) = + let module G = Gdome in + if not (jump element) then match mathview#get_action with Some n -> mathview#action_toggle ; @@ -75,31 +85,23 @@ let clicked mathview (node : Ominidom.o_mDOMNode) = flush stdout ; | None -> print_string ("mouse is on: " ^ - (match (mathview#get_element : Ominidom.o_mDOMNode option) with - Some e -> - (match e#get_name with - Some x -> x#get_string - | None -> "no name" - ) + (match (mathview#get_element : Gdome.element option) with + Some e -> e#get_tagName#to_string | None -> "NO ELEMENT!\n" ) ^ "\n") ; - print_string ("clicked: " ^ - (match node#get_name with - Some x -> x#get_string - | None -> "no name" - ) ^ "\n") ; + print_endline ("clicked: " ^ element#get_tagName#to_string) ; flush stdout ;; -let activate_t1 mathview () = +let activate_t1 (mathview : GMathView.math_view) () = mathview#set_font_manager_type `font_manager_t1; print_string "WIDGET SET WITH T1 FONTS\n" ; flush stdout ;; -let activate_gtk mathview () = - mathview#set_font_manager_type `font_manager_gtk; +let activate_gtk (mathview : GMathView.math_view) () = + mathview#set_font_manager_type `font_manager_gtk ; print_string "WIDGET SET WITH GTK FONTS\n" ; flush stdout ;; @@ -128,52 +130,50 @@ let set_transparency mathview () = ;; -let load mathview () = +let load (mathview : GMathView.math_view) () = mathview#load "test.xml" ; print_string "load: SEEMS TO WORK\n" ; flush stdout ;; -let load_dom mathview () = - mathview#load_tree (new Ominidom.o_mDOMDoc (Minidom.doc_load "test.xml")) ; +let load_dom (mathview : GMathView.math_view) () = + mathview#load_tree ((Gdome.domImplementation ())#createDocumentFromURI ~uri:"test.xml" ~mode:0) ; print_string "load from DOM: SEEMS TO WORK\n" ; flush stdout ;; -let get_selection mathview () = - let module O = Ominidom in - let selection = - match mathview#get_selection with - | Some node -> - begin - match node#get_name with - | Some name -> name#get_string - | None -> "element with no name!" - end - | None -> "no selection!" - in - print_string ("get_selection: " ^ selection ^ "\n") ; - flush stdout +let get_selection (mathview : GMathView.math_view) () = + let selection = + match mathview#get_selection with + Some element -> element#get_tagName#to_string + | None -> "no selection!" + in + print_string ("get_selection: " ^ selection ^ "\n") ; + flush stdout ;; -let set_selection mathview () = - let module O = Ominidom in - begin - match mathview#get_selection with - | Some node -> - begin - try - let parent_node = node#get_parent in - mathview#set_selection (Some parent_node); - print_string "set selection: SEEMS TO WORK\n" - with - _ -> print_string "EXCEPTION: no parent\n" - end +let set_selection (mathview : GMathView.math_view) () = + begin + match mathview#get_selection with + Some element -> + begin + match element#get_parentNode with + Some p -> + begin + try + mathview#set_selection (Some (new Gdome.element_of_node p)); + print_string "set selection: SEEMS TO WORK\n" + with + GdomeInit.DOMCastException _ -> + print_string "EXCEPTION: no parent\n" + end + | None -> assert false (* every element has a parent *) + end | None -> - mathview#set_selection None; - print_string "no selection\n" - end ; - flush stdout + mathview#set_selection None; + print_string "no selection\n" + end ; + flush stdout ;; let unload mathview () = @@ -363,6 +363,7 @@ ignore(button_get_transparency#connect#clicked (get_transparency mathview)) ; ignore(button_set_transparency#connect#clicked (set_transparency mathview)) ; ignore(mathview#connect#clicked (clicked mathview)) ; ignore(mathview#connect#selection_changed (selection_changed mathview)) ; +ignore(mathview#connect#element_changed (element_changed mathview)) ; ignore(button_load_dom#connect#clicked (load_dom mathview)) ; (* Main Loop *) main_window#show () ; -- 2.39.2