X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Flablgtkmathview%2Ftest%2Ftest.ml;h=ca9abd84bbab42645173c0b57e0a0347c5874fdf;hb=5a369548a2f04fb59b5cbb94526325aae9bf415a;hp=3e2edeed1b5ef1a05247d096329636154e64e427;hpb=dfb99fda45c1cd87a7c2fedcebb987f3220e0516;p=helm.git diff --git a/helm/DEVEL/lablgtkmathview/test/test.ml b/helm/DEVEL/lablgtkmathview/test/test.ml index 3e2edeed1..ca9abd84b 100644 --- a/helm/DEVEL/lablgtkmathview/test/test.ml +++ b/helm/DEVEL/lablgtkmathview/test/test.ml @@ -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. @@ -29,50 +30,98 @@ (******************************************************************************) (* Callbacks *) -let jump (node : Ominidom.o_mDOMNode) = - let module O = Ominidom in - print_string ("jump: " ^ - (match node#get_attribute (O.o_mDOMString_of_string "href") with - | Some x -> x#get_string - | None -> "NO HREF FOR THIS NODE" - ) ^ "\n"); - 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 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 element_over mathview (element : Gdome.element option) _ = + print_endline ("element_over: " ^ + (match element with + None -> "element_over on nothing" + | Some element -> element#get_tagName#to_string + ) + ) ; + flush stdout +;; + +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 + | None -> assert false (* every element has a parent *) + else + begin + print_endline ("jump: " ^ attr) ; + flush stdout ; + true + end ;; +let rec action mathview (element : Gdome.element) = + let module G = Gdome in + if element#get_tagName#to_string = "m:maction" then + let selection = + if element#hasAttribute ~name:(G.domString "selection") then + int_of_string (element#getAttribute ~name:(G.domString "selection"))#to_string + else + 1 + in + mathview#freeze ; + (* the widget will cast the index back into a reasonable range *) + element#setAttribute ~name:(G.domString "selection") ~value:(G.domString (string_of_int (selection + 1))) ; + mathview#thaw ; + true + else + match element#get_parentNode with + Some p -> + begin + try + action mathview (new Gdome.element_of_node p) + with + GdomeInit.DOMCastException _ -> + print_string "action: NO MACTION FOUND\n" ; + flush stdout ; + false + end + | None -> assert false (* every element has a parent *) -let clicked (node : Ominidom.o_mDOMNode) = - let module O = Ominidom in - print_string ("clicked: " ^ - (match node#get_name with - | Some x -> x#get_string - | None -> "no name" - ) ^ "\n"); - flush stdout +let click mathview (element : Gdome.element option) _ = + let module G = Gdome in + match element with + None -> print_string "CLICKED ON NOTHING\n" ; flush stdout + | Some element -> + if not (jump element) then + if not (mathview#action_toggle element) then + () ;; let activate_t1 mathview () = - mathview#set_font_manager_type `font_manager_t1; + mathview#set_font_manager_type ~fm_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; + mathview#set_font_manager_type ~fm_type:`font_manager_gtk ; print_string "WIDGET SET WITH GTK FONTS\n" ; flush stdout ;; @@ -88,48 +137,79 @@ let get_font_manager_type mathview () = flush stdout ;; -let load mathview () = - mathview#load "test.xml" ; +let get_transparency mathview () = + print_string ("CURRENT TRANSPARENCY: " ^ + (if mathview#get_transparency then "ON" else "OFF") ^ "\n") ; + flush stdout +;; + +let set_transparency mathview () = + mathview#set_transparency (not mathview#get_transparency) ; + print_string "TRANSPARENCY CHANGED\n" ; + flush stdout +;; + + +let load_uri mathview () = + mathview#load_uri ~filename:"test.xml" ; print_string "load: 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 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 - | None -> - mathview#set_selection None; - print_string "no selection\n" - end ; +let load_doc mathview () = + mathview#load_doc ~dom:((Gdome.domImplementation ())#createDocumentFromURI ~uri:"test.xml" ()) ; + print_string "load from DOM: SEEMS TO WORK\n" ; + flush stdout +;; + +let test_get_selection mathview () = + 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 test_set_selection mathview () = + 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 +;; + +let test_add_selection (mathview : GMathViewAux.multi_selection_math_view) () = + match mathview#get_selection with + Some e -> mathview#add_selection e + | None -> + begin + print_string "no selection to add\n" ; + flush stdout + end +;; + +let test_reset_selections (mathview : GMathViewAux.multi_selection_math_view) () = + mathview#set_selection None ; + mathview#remove_selections + let unload mathview () = mathview#unload ; print_string "unload: SEEMS TO WORK\n" ; @@ -221,6 +301,7 @@ let get_anti_aliasing mathview () = flush stdout ;; + (* let set_kerning mathview () = mathview#set_kerning true ; print_string "set_kerning: ON\n" ; @@ -233,6 +314,7 @@ let get_kerning mathview () = "\n") ; flush stdout ;; +*) let set_log_verbosity mathview () = mathview#set_log_verbosity 3 ; @@ -247,23 +329,46 @@ let get_log_verbosity mathview () = flush stdout ;; -let export_to_postscript (mathview : GMathView.math_view) () = +let export_to_postscript (mathview : GMathViewAux.multi_selection_math_view) () = mathview#export_to_postscript ~filename:"test.ps" (); print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n"; flush stdout ;; +let x_coord = ref 0 +;; + +let get_element_at mathview () = + begin + match mathview#get_element_at !x_coord 10 with + None -> print_string ("there is no element at " ^ (string_of_int !x_coord) ^ " 10\n") + | Some e -> print_string ("at " ^ (string_of_int !x_coord) ^ " 10 found element " ^ (e#get_nodeName#to_string) ^ "\n") + end ; + x_coord := !x_coord + 10 ; + flush stdout +;; + +let get_drawing_area mathview () = + begin + let da = mathview#get_drawing_area in + print_string ("don't know what to do with the drawing area\n") + end ; + flush stdout +;; + (* Widget creation *) let main_window = GWindow.window ~title:"GtkMathView test" () in let vbox = GPack.vbox ~packing:main_window#add () in let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in -let mathview= GMathView.math_view ~packing:sw#add ~width:50 ~height:50 () in +let mathview= GMathViewAux.multi_selection_math_view ~packing:sw#add ~width:50 ~height:50 () in let table = GPack.table ~rows:6 ~columns:5 ~packing:vbox#pack () in let button_gtk=GButton.button ~label:"activate Gtk fonts" ~packing:(table#attach ~left:0 ~top:0) () in let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in +let button_add_selection = GButton.button ~label:"add_selection" ~packing:(table#attach ~left:3 ~top:3) () in +let button_reset_selections = GButton.button ~label:"reset_selections" ~packing:(table#attach ~left:4 ~top:3) () in let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in @@ -277,19 +382,24 @@ let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in -let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in -let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in let button_t1 = GButton.button ~label:"activate T1 fonts" ~packing:(table#attach ~left:3 ~top:4) () in let button_get_font_manager_type = GButton.button ~label:"get_font_manager" ~packing:(table#attach ~left:4 ~top:4) () in +let button_get_transparency = GButton.button ~label:"get_transparency" ~packing:(table#attach ~left:0 ~top:5) () in +let button_set_transparency = GButton.button ~label:"set_transparency" ~packing:(table#attach ~left:1 ~top:5) () in +let button_load_dom = GButton.button ~label:"load from DOM" ~packing:(table#attach ~left:2 ~top:5) () in +let button_get_element_at = GButton.button ~label:"get_element_at" ~packing:(table#attach ~left:3 ~top:5) () in +let button_get_drawing_area = GButton.button ~label:"get_drawing_area" ~packing:(table#attach ~left:4 ~top:5) () in (* Signals connection *) ignore(button_gtk#connect#clicked (activate_gtk mathview)) ; -ignore(button_load#connect#clicked (load mathview)) ; +ignore(button_load#connect#clicked (load_uri mathview)) ; ignore(button_unload#connect#clicked (unload mathview)) ; -ignore(button_get_selection#connect#clicked (get_selection mathview)) ; -ignore(button_set_selection#connect#clicked (set_selection mathview)) ; +ignore(button_get_selection#connect#clicked (test_get_selection mathview)) ; +ignore(button_set_selection#connect#clicked (test_set_selection mathview)) ; +ignore(button_add_selection#connect#clicked (test_add_selection mathview)) ; +ignore(button_reset_selections#connect#clicked (test_reset_selections mathview)) ; ignore(button_get_width#connect#clicked (get_width mathview)) ; ignore(button_get_height#connect#clicked (get_height mathview)) ; ignore(button_get_top#connect#clicked (get_top mathview)) ; @@ -303,16 +413,19 @@ ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ; ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ; ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ; ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ; -ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ; -ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ; ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ; ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ; ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ; ignore(button_t1#connect#clicked (activate_t1 mathview)) ; ignore(button_get_font_manager_type#connect#clicked (get_font_manager_type mathview)) ; -ignore(mathview#connect#jump jump) ; -ignore(mathview#connect#clicked clicked) ; -ignore(mathview#connect#selection_changed (selection_changed mathview)) ; +ignore(button_get_transparency#connect#clicked (get_transparency mathview)) ; +ignore(button_set_transparency#connect#clicked (set_transparency mathview)) ; +ignore(mathview#connect#click (click mathview)) ; +ignore(mathview#connect#selection_changed (selection_changed mathview)); +ignore(mathview#connect#element_over (element_over mathview)) ; +ignore(button_load_dom#connect#clicked (load_doc mathview)) ; +ignore(button_get_element_at#connect#clicked (get_element_at mathview)) ; +ignore(button_get_drawing_area#connect#clicked (get_drawing_area mathview)) ; (* Main Loop *) main_window#show () ; GMain.Main.main ()