]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/lablgtkmathview/test/test.ml
...
[helm.git] / helm / DEVEL / lablgtkmathview / test / test.ml
index 3e2edeed1b5ef1a05247d096329636154e64e427..655970cca5a1974e7c6aa0db5cb3c19106839123 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 (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_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 (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 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 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 ;
+       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 : Gdome.element option) with
+            Some e -> e#get_tagName#to_string
+          | None -> "NO ELEMENT!\n"
+         ) ^ "\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
 ;;
@@ -88,48 +117,65 @@ let get_font_manager_type mathview () =
  flush stdout
 ;;
 
-let load mathview () =
+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 : GMathView.math_view) () =
  mathview#load "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 load_dom (mathview : GMathView.math_view) () =
+ mathview#load_tree ((Gdome.domImplementation ())#createDocumentFromURI ~uri:"test.xml" ()) ;
+ print_string "load from DOM: SEEMS TO WORK\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 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 : 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
+;;
+
 let unload mathview () =
  mathview#unload ;
  print_string "unload: SEEMS TO WORK\n" ;
@@ -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,12 @@ 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(mathview#connect#element_changed (element_changed mathview)) ;
+ignore(button_load_dom#connect#clicked (load_dom mathview)) ;
 (* Main Loop *)
 main_window#show () ;
 GMain.Main.main ()