]> matita.cs.unibo.it Git - helm.git/commitdiff
Fixing the selections
authorClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Wed, 8 Nov 2000 14:29:55 +0000 (14:29 +0000)
committerClaudio Sacerdoti Coen <claudio.sacerdoticoen@unibo.it>
Wed, 8 Nov 2000 14:29:55 +0000 (14:29 +0000)
helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.0/gtkMathView.ml
helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.0/minidom/ml_minidom.h
helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.0/ml_gtk_mathview.c
helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.0/test/test.ml

index 62cd5409dc436b9b019c69658576e0beb35bab53..97ae38e32979b9aa48ec61b2c5d78f19c9153b4f 100644 (file)
@@ -4,8 +4,13 @@ open Tags
 open GtkBase
 open Gpointer
 
-external mDOMNode_of_boxed_option : Gpointer.boxed option -> Minidom.mDOMNode =
- "ml_gtk_math_view_mDOMNode_of_bodex_option"
+external mDOMNode_of_boxed_option :
+ Gpointer.boxed option -> Minidom.mDOMNode =
+  "ml_gtk_math_view_mDOMNode_of_bodex_option"
+
+external mDOMNode_option_of_boxed_option :
+ Gpointer.boxed option -> Minidom.mDOMNode option =
+  "ml_gtk_math_view_mDOMNode_option_of_bodex_option"
 
 module MathView = struct
   let cast w : math_view obj = Object.try_cast w "GtkMathView"
@@ -17,11 +22,9 @@ module MathView = struct
    "ml_gtk_math_view_load"
   external unload : [>`math_view] obj -> unit =
    "ml_gtk_math_view_unload"
-  (*external dump : [>`math_view] obj -> unit =
-   "ml_gtk_math_view_dump"*)
-  external get_selection : [>`math_view] obj -> Minidom.mDOMNode =
+  external get_selection : [>`math_view] obj -> Minidom.mDOMNode option =
    "ml_gtk_math_view_get_selection"
-  external set_selection : [>`math_view] obj -> Minidom.mDOMNode -> unit =
+  external set_selection : [>`math_view] obj -> Minidom.mDOMNode option -> unit=
    "ml_gtk_math_view_set_selection"
   external get_width : [>`math_view] obj -> int =
    "ml_gtk_math_view_get_width"
@@ -82,7 +85,7 @@ module MathView = struct
     let selection_changed : ([>`math_view],_) t =
      let marshal_selection_changed f _ =
       function
-         [GtkArgv.POINTER node] -> f (mDOMNode_of_boxed_option node)
+         [GtkArgv.POINTER node] -> f (mDOMNode_option_of_boxed_option node)
        | _ -> invalid_arg "GtkMathView.MathView.Signals.marshal_selection_changed"
      in
       { name = "selection_changed"; marshaller = marshal_selection_changed }
index 318b7f0675d48d07287e4443e151f5cd1ef0e677..2a812ae0f9aac2f1a13a6ab28fc1ba8d8e2549e5 100644 (file)
@@ -3,3 +3,4 @@
 #define Val_mDOMString(s) (copy_string((char*) (s)))
 #define mDOMString_val(v) ((mDOMStringRef) String_val(v))
 #define mDOMNode_val(v) ((mDOMNodeRef) v)
+#define Val_mDOMNode_option(p)   ((p != NULL) ? ml_some((value) p) : Val_unit)
index 184977e5e15018d1ba39f82af35eff74f6b9939c..84e21a6c84e0490b4c370e42b0d887025b96e4a6 100644 (file)
@@ -1,4 +1,5 @@
 #include <string.h>
+#include <assert.h>
 #include <gtk/gtk.h>
 #include <caml/mlvalues.h>
 #include <caml/alloc.h>
@@ -25,8 +26,8 @@ ML_3 (gtk_math_view_new,GtkAdjustment_val, GtkAdjustment_val, Bool_val, Val_GtkW
 ML_2 (gtk_math_view_load, GtkMathView_val, String_val, Val_bool)
 ML_1 (gtk_math_view_unload, GtkMathView_val, Unit)
 /*ML_1 (gtk_math_view_dump, GtkMathView_val, Unit)*/
-ML_1 (gtk_math_view_get_selection, GtkMathView_val, Val_ptr)
-ML_2 (gtk_math_view_set_selection, GtkMathView_val, mDOMNode_val, Unit)
+ML_1 (gtk_math_view_get_selection, GtkMathView_val, Val_mDOMNode_option)
+ML_2 (gtk_math_view_set_selection, GtkMathView_val, mDOMNode_option_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)
@@ -84,7 +85,7 @@ value ml_gtk_math_view_mDOMNode_of_bodex_option (value arg1)
    CAMLlocal1 (tmp);
 
    if (arg1==Val_int(0)) {
-      nr = NULL;
+      assert(0);
    } else {
       tmp = Field(arg1, 0);
       nr = (mDOMNodeRef) Field(tmp, 1);
@@ -92,3 +93,20 @@ value ml_gtk_math_view_mDOMNode_of_bodex_option (value arg1)
 
   CAMLreturn((value) nr);
 }
+
+value ml_gtk_math_view_mDOMNode_option_of_bodex_option (value arg1)
+{
+   CAMLparam1(arg1);
+
+   mDOMNodeRef nr;
+   CAMLlocal1 (tmp);
+
+   if (arg1==Val_int(0)) {
+      nr = NULL;
+   } else {
+      tmp = Field(arg1, 0);
+      nr = (mDOMNodeRef) Field(tmp, 1);
+   }
+
+  CAMLreturn(Val_option(nr, Val_ptr));
+}
index 4f9af18e55a346b4599efa879e4b1f6ba311248d..1550a06421584f08217cc983b059d8c87bd509f9 100644 (file)
@@ -32,9 +32,12 @@ let jump node =
 let selection_changed node =
  let module M = Minidom in
   print_string ("selection_changed: " ^
-   (match M.node_get_name node with
-       None   -> "selection_changed on nothing" 
-     | Some s -> "selection changed on " ^ M.string_of_mDOMString s
+   (match node with
+       None -> "selection_changed on nothing"
+     | Some node ->
+        match M.node_get_name node with
+           None   -> "selection_changed on a node without name" 
+         | Some s -> "selection changed on " ^ M.string_of_mDOMString s
    ) ^ "\n");
   flush stdout
 ;;
@@ -70,10 +73,9 @@ let load mathview () =
 
 let get_selection mathview () =
  let selection =
-(*  match !mathview#get_selection with
+  match !mathview#get_selection with
      None -> "NO SELECTION"
    | Some node ->
-*) let node = !mathview#get_selection in
       match Minidom.node_get_name node with
         None   -> "selection is on nothing" 
       | Some s -> "selection is on " ^ Minidom.string_of_mDOMString s
@@ -85,14 +87,13 @@ let get_selection mathview () =
 let set_selection mathview () =
  begin
   try
-(*   match !mathview#get_selection with
+   match !mathview#get_selection with
       None -> raise Not_found
     | Some node ->
-*) let node = !mathview#get_selection in
        match Minidom.node_get_parent node with
           None -> raise Not_found
         | Some node ->
-           !mathview#set_selection node ;
+           !mathview#set_selection (Some node) ;
            print_string "set_selection: SEEMS TO WORK\n"
   with
    Not_found ->