]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.1/test/test.ml
Initial revision
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20000829_gtkmathview-0.2.1 / test / test.ml
index a8e184bc43e084888349e072253d73f981fb346b..dd66d3885d66d0ec2ab3f49e2a6979c4993b67a5 100644 (file)
 let jump (node : Ominidom.o_mDOMNode) =
  let module O = Ominidom in
   print_string ("jump: " ^
-   (try 
-      let href = node#get_attribute (O.o_mDOMString_of_string "href") in
-      href#get_string
-    with
-      O.Minidom_exception s -> "EXCEPTION: " ^ s
+   (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
 ;;
@@ -23,17 +21,13 @@ let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
  let module O = Ominidom in
   print_string ("selection_changed: " ^
    (match node with
-       None ->
-         mathview#reset_selection;
-         "selection_changed on nothing"
+       None -> "selection_changed on nothing"
      | Some node ->
-        try
-         mathview#set_selection node ;
-         let node_name = node#get_name in
-         node_name#get_string
-       with
-         O.Minidom_exception s -> "EXCEPTION: " ^ s
+       match node#get_name with
+       | Some x -> x#get_string
+       | None   -> "on element without name"
    ) ^ "\n");
+  mathview#set_selection node;
   flush stdout
 ;;
 
@@ -41,24 +35,22 @@ let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
 let clicked (node : Ominidom.o_mDOMNode) =
  let module O = Ominidom in
   print_string ("clicked: " ^
-   (try
-      let node_name = node#get_name in
-      node_name#get_string
-    with
-      O.Minidom_exception s -> "EXCEPTION: " ^ s
+   (match node#get_name with
+    | Some x -> x#get_string
+    | None   -> "no name"
    ) ^ "\n");
   flush stdout
 ;;
 
 
 let activate_t1 mathview () =
- mathview#set_font_manager_type GtkMathView.MathView.FontManagerT1;
+ 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 GtkMathView.MathView.FontManagerGtk;
+ mathview#set_font_manager_type `font_manager_gtk;
  print_string "WIDGET SET WITH GTK FONTS\n" ;
  flush stdout
 ;;
@@ -67,8 +59,8 @@ let get_font_manager_type mathview () =
  print_string "CURRENT FONT MANAGER TYPE: ";
  begin
   match mathview#get_font_manager_type with
-  | GtkMathView.MathView.FontManagerT1 -> print_string "T1"
-  | GtkMathView.MathView.FontManagerGtk -> print_string "GTK"
+  | `font_manager_t1 -> print_string "T1"
+  | `font_manager_gtk -> print_string "GTK"
  end;
  print_newline();
  flush stdout
@@ -83,13 +75,14 @@ let load mathview () =
 let get_selection mathview () =
  let module O = Ominidom in
   let selection =
-   if not mathview#has_selection then "nothing"
-   else
-     let node = mathview#get_selection in
-     (try node#get_name#get_string
-      with
-        O.Minidom_exception s -> "EXCEPTION: " ^ s
-     ) 
+    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
@@ -98,28 +91,23 @@ let get_selection mathview () =
 let set_selection mathview () =
  let module O = Ominidom in
   begin
-   try
-    let selected_node = mathview#get_selection in
-    try
-      let parent_node = selected_node#get_parent in
-      mathview#set_selection parent_node;
-      print_string "set selection: SEEMS TO WORK\n"
-    with
-      O.Minidom_exception s ->
-        print_string ("EXCEPTION: " ^ s ^ "\n")
-   with
-    GtkMathView.MathView.NoSelection ->
-     print_string "set_selection: YOU MUST PREVIOUSLY SELECT A NON-ROOT NODE\n" 
+    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 ;
   flush stdout
 ;;
 
-let reset_selection mathview () =
- mathview#reset_selection ;
- print_string "reset_selection: SEEMS TO WORK\n" ;
- flush stdout
-;;
-
 let unload mathview () =
  mathview#unload ;
  print_string "unload: SEEMS TO WORK\n" ;
@@ -237,8 +225,8 @@ let get_log_verbosity mathview () =
  flush stdout
 ;;
 
-let export_to_postscript mathview () =
- mathview#export_to_postscript 595 822 72 72 false "test.ps" ;
+let export_to_postscript (mathview : GMathView.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
 ;;
@@ -274,14 +262,12 @@ 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_reset_selection = GButton.button ~label:"reset_selection" ~packing:(table#attach ~left:0 ~top:5) () in
 (* Signals connection *)
 ignore(button_gtk#connect#clicked (activate_gtk mathview)) ;
 ignore(button_load#connect#clicked (load 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_reset_selection#connect#clicked (reset_selection 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)) ;