]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/lablgtkmathview/test/test.ml
First commit towards the 0.2.8 version.
[helm.git] / helm / DEVEL / lablgtkmathview / test / test.ml
index 3e2edeed1b5ef1a05247d096329636154e64e427..855ce95846c80f32697d4dd6d2595cd1da4df84f 100644 (file)
 (******************************************************************************)
 
 (* 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 (node : Ominidom.o_mDOMNode option) =
  let module O = Ominidom in
   print_string ("selection_changed: " ^
@@ -54,14 +44,51 @@ let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
 ;;
 
 
-let clicked (node : Ominidom.o_mDOMNode) =
+let rec jump (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
+  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 ->
+           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
+;;
+
+let clicked mathview (node : Ominidom.o_mDOMNode) =
+ let module O = Ominidom in
+  if not (jump node) then
+   match mathview#get_action with
+      Some n ->
+       mathview#action_toggle ;
+       print_string ("current action selection: " ^
+        string_of_int mathview#action_get_selected ^ "\n") ;
+       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"
+             )
+          | None -> "NO ELEMENT!\n"
+         ) ^ "\n") ;
+       print_string ("clicked: " ^
+        (match node#get_name with
+           Some x -> x#get_string
+         | None   -> "no name"
+        ) ^ "\n") ;
+       flush stdout
 ;;
 
 
@@ -88,12 +115,31 @@ let get_font_manager_type mathview () =
  flush stdout
 ;;
 
+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 mathview () =
  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")) ;
+ print_string "load from DOM: SEEMS TO WORK\n" ;
+ flush stdout
+;;
+
 let get_selection mathview () =
  let module O = Ominidom in
   let selection =
@@ -284,6 +330,9 @@ let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packin
 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
 (* Signals connection *)
 ignore(button_gtk#connect#clicked (activate_gtk mathview)) ;
 ignore(button_load#connect#clicked (load mathview)) ;
@@ -310,9 +359,11 @@ 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(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(button_load_dom#connect#clicked (load_dom mathview)) ;
 (* Main Loop *)
 main_window#show () ;
 GMain.Main.main ()