-(* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
+(* Copyright (C) 2000-2003, Luca Padovani <luca.padovani@cs.unibo.it>,
+ * Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>.
*
* This file is part of lablgtkmathview, the Ocaml binding
* for the GtkMathView widget.
(* MathView widget *)
(******************************************************************************)
+let helmns = Gdome.domString "http://www.cs.unibo.it/helm";;
+
+(*
+let choose_selection mmlwidget (element : Gdome.element option) =
+ let module G = Gdome in
+ let rec aux element =
+ if element#hasAttributeNS
+ ~namespaceURI:Misc.helmns
+ ~localName:(G.domString "xref")
+ then
+ mmlwidget#set_selection (Some element)
+ else
+ try
+ match element#get_parentNode with
+ None -> assert false
+ (*CSC: OCAML DIVERGES!
+ | Some p -> aux (new G.element_of_node p)
+ *)
+ | Some p -> aux (new Gdome.element_of_node p)
+ with
+ GdomeInit.DOMCastException _ ->
+ prerr_endline
+ "******* trying to select above the document root ********"
+ in
+ match element with
+ Some x -> aux x
+ | None -> mmlwidget#set_selection None
+;;
+*)
+
(* Callbacks *)
let selection_changed mathview (element : Gdome.element option) =
+ let rec aux element =
+ if element#hasAttributeNS
+ ~namespaceURI:helmns
+ ~localName:(Gdome.domString "xref")
+ then
+ mathview#set_selection (Some element)
+ else
+ try
+ match element#get_parentNode with
+ None -> mathview#set_selection None
+ | Some p -> aux (new Gdome.element_of_node p)
+ with
+ GdomeInit.DOMCastException _ ->
+ prerr_endline "******* trying to select above the document root ********"
+ in
print_endline ("selection_changed: " ^
(match element with
None -> "selection_changed on nothing"
| Some element -> element#get_tagName#to_string
)
) ;
- mathview#set_selection element;
+ match element with
+ None -> ()
+ | Some el -> aux el;
flush stdout
;;
-let element_changed mathview (element : Gdome.element option) =
- print_endline ("element_changed: " ^
+let element_over mathview (element : Gdome.element option) _ =
+ print_endline ("element_over: " ^
(match element with
- None -> "element_changed on nothing"
+ None -> "element_over on nothing"
| Some element -> element#get_tagName#to_string
)
) ;
end
| None -> assert false (* every element has a parent *)
-let clicked mathview (element : Gdome.element) =
+let click mathview (element : Gdome.element option) _ =
let module G = Gdome in
- if not (jump element) then
- if not (action mathview 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
- *)
- ()
+ 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
+ ()
;;
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 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_uri mathview)) ;
ignore(button_get_font_manager_type#connect#clicked (get_font_manager_type mathview)) ;
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#click (click mathview)) ;
ignore(mathview#connect#selection_changed (selection_changed mathview));
-ignore(mathview#connect#element_changed (element_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 ()