-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 rec action mathview (element : Gdome.element) =
+ let module G = Gdome in
+ if element#get_tagName#to_string = "m:maction" then
+ let selection =
+ if element#hasAttribute ~name:(G.domString "selection") then
+ int_of_string (element#getAttribute ~name:(G.domString "selection"))#to_string
+ else
+ 1
+ in
+ mathview#freeze ;
+ (* the widget will cast the index back into a reasonable range *)
+ element#setAttribute ~name:(G.domString "selection") ~value:(G.domString (string_of_int (selection + 1))) ;
+ mathview#thaw ;
+ true
+ else
+ match element#get_parentNode with
+ Some p ->
+ begin
+ try
+ action mathview (new Gdome.element_of_node p)
+ with
+ GdomeInit.DOMCastException _ ->
+ print_string "action: NO MACTION FOUND\n" ;
+ flush stdout ;
+ false
+ end
+ | None -> assert false (* every element has a parent *)
+
+let click mathview (element : Gdome.element option) _ =
+ let module G = Gdome in
+ 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
+ ()