]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/cicMathView.ml
43cedcec6b210c18e8c889bfab96f1d5833e9fe1
[helm.git] / matita / matita / cicMathView.ml
1 (* Copyright (C) 2004-2005, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://helm.cs.unibo.it/
24  *)
25
26 open Printf
27
28 open GrafiteTypes
29 open MatitaGtkMisc
30 open MatitaGuiTypes
31 open GtkSourceView2
32
33 type document_element = string
34
35 class type cicMathView =
36 object
37   inherit GObj.widget
38
39   method set_font_size: int -> unit
40   method update_font_size: unit
41
42   method load_root : root:document_element -> unit
43   method remove_selections: unit
44   method set_selection: document_element option -> unit
45   method get_selections: document_element list
46
47     (** @raise Failure "no selection" *)
48   method strings_of_selection: (MatitaGuiTypes.paste_kind * string) list
49
50     (** set hyperlink callback. None disable hyperlink handling *)
51   method set_href_callback: (string -> unit) option -> unit
52
53     (** load a sequent and render it into parent widget *)
54   method nload_sequent:
55    #ApplyTransformation.status -> NCic.metasenv -> NCic.substitution -> int -> unit
56
57   method load_nobject: #ApplyTransformation.status -> NCic.obj -> unit
58 end
59
60 (*
61 let xlink_ns = Gdome.domString "http://www.w3.org/1999/xlink"
62 let helm_ns = Gdome.domString "http://www.cs.unibo.it/helm"
63 let href_ds = Gdome.domString "href"
64 let xref_ds = Gdome.domString "xref"
65 *)
66
67   (** Gdome.element of a MathML document whose rendering should be blank. Used
68   * by cicBrowser to render "about:blank" document *)
69 let empty_mathml = lazy ""
70
71   (** shown for goals closed by side effects *)
72 let closed_goal_mathml = lazy "chiuso per side effect..."
73
74 (*
75 let rec has_maction (elt :Gdome.element) = 
76   (* fix this comparison *)
77   if elt#get_tagName#to_string = "m:maction" ||
78    elt#get_tagName#to_string = "b:action" then
79     true
80   else 
81     match elt#get_parentNode with
82     | Some node when node#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE -> 
83         has_maction (new Gdome.element_of_node node)
84     | _ -> false
85 ;;
86
87 let hrefs_of_elt elt =
88   let localName = href_ds in
89   if elt#hasAttributeNS ~namespaceURI:xlink_ns ~localName then
90     let text =
91       (elt#getAttributeNS ~namespaceURI:xlink_ns ~localName)#to_string in
92     Some (HExtlib.split text)
93   else
94     None
95
96 let id_of_node (node: Gdome.element) =
97   let xref_attr =
98     node#getAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds in
99   try
100     List.hd (HExtlib.split ~sep:' ' xref_attr#to_string)
101   with Failure _ -> assert false
102
103 type selected_term =
104   | SelTerm of NCic.term * string option (* term, parent hypothesis (if any) *)
105   | SelHyp of string * NCic.context (* hypothesis, context *)
106 *)
107
108 let near (x1, y1) (x2, y2) =
109   let distance = sqrt (((x2 -. x1) ** 2.) +. ((y2 -. y1) ** 2.)) in
110   (distance < 4.)
111
112 (*
113 let name_of_hypothesis = function
114   | Some (Cic.Name s, _) -> s
115   | _ -> assert false
116
117 let domImpl = Gdome.domImplementation ()
118
119 (* ids_to_terms should not be passed here, is just for debugging *)
120 let find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types =
121   assert false (* MATITA 1.0
122   let find_parent id ids =
123     let rec aux id =
124 (*       (prerr_endline (sprintf "id %s = %s" id
125         (try
126           CicPp.ppterm (Hashtbl.find ids_to_terms id)
127         with Not_found -> "NONE"))); *)
128       if List.mem id ids then Some id
129       else
130         (match
131           (try Hashtbl.find ids_to_father_ids id with Not_found -> None)
132         with
133         | None -> None
134         | Some id' -> aux id')
135     in
136     aux id
137   in
138   let return_father id ids =
139     match find_parent id ids with
140     | None -> assert false
141     | Some parent_id -> parent_id
142   in
143   let mk_ids terms = List.map CicUtil.id_of_annterm terms in
144   let inner_types =
145    Hashtbl.fold
146     (fun _ types acc ->
147       match types.Cic2acic.annexpected with
148          None -> types.Cic2acic.annsynthesized :: acc
149        | Some ty -> ty :: types.Cic2acic.annsynthesized :: acc
150     ) ids_to_inner_types [] in
151   match annobj with
152   | Cic.AConstant (_, _, _, Some bo, ty, _, _)
153   | Cic.AVariable (_, _, Some bo, ty, _, _)
154   | Cic.ACurrentProof (_, _, _, _, bo, ty, _, _) ->
155       return_father id (mk_ids (ty :: bo :: inner_types))
156   | Cic.AConstant (_, _, _, None, ty, _, _)
157   | Cic.AVariable (_, _, None, ty, _, _) ->
158       return_father id (mk_ids (ty::inner_types))
159   | Cic.AInductiveDefinition _ ->
160       assert false  (* TODO *)
161       *)
162
163   (** @return string content of a dom node having a single text child node, e.g.
164    * <m:mi xlink:href="...">bool</m:mi> *)
165 let string_of_dom_node node =
166   match node#get_firstChild with
167   | None -> ""
168   | Some node ->
169       (try
170         let text = new Gdome.text_of_node node in
171         text#get_data#to_string
172       with GdomeInit.DOMCastException _ -> "")
173 *)
174
175 class clickableMathView obj =
176 let text_width = 80 in
177 object (self)
178   inherit GSourceView2.source_view obj
179
180   method strings_of_selection = (assert false : (paste_kind * string) list)
181   method update_font_size =
182    self#misc#modify_font_by_name
183      (sprintf "%s %d" BuildTimeConf.script_font (MatitaMisc.get_current_font_size ()))
184   method set_href_callback = (function _ -> () : (string -> unit) option -> unit)
185   method private set_cic_info = (function _ -> () : unit (*(Cic.conjecture option * (Cic.id, Cic.term) Hashtbl.t *
186          (Cic.id, Cic.hypothesis) Hashtbl.t *
187          (Cic.id, Cic.id option) Hashtbl.t * ('a, 'b) Hashtbl.t * 'c option)*) option -> unit)
188   (* dal widget di Luca *)
189   method load_root ~root =
190     self#buffer#delete ~start:(self#buffer#get_iter `START)
191     ~stop:(self#buffer#get_iter `END);
192     self#buffer#insert root
193   method action_toggle = (fun _ -> assert false : document_element -> bool)
194   method remove_selections = (() : unit)
195   method set_selection = (fun _ -> () : document_element option -> unit)
196   method get_selections = (assert false : document_element list)
197   method set_font_size font_size =
198    self#misc#modify_font_by_name
199      (sprintf "%s %d" BuildTimeConf.script_font font_size)
200
201   initializer
202     self#set_font_size (MatitaMisc.get_current_font_size ());
203     self#source_buffer#set_language (Some MatitaGtkMisc.matita_lang);
204     self#source_buffer#set_highlight_syntax true;
205     self#set_editable false
206
207 (* MATITA1.0
208   inherit GMathViewAux.multi_selection_math_view obj
209
210   val mutable href_callback: (string -> unit) option = None
211   method set_href_callback f = href_callback <- f
212
213   val mutable _cic_info = None
214   method private set_cic_info info = _cic_info <- info
215   method private cic_info = _cic_info
216
217   val normal_cursor = Gdk.Cursor.create `LEFT_PTR
218   val href_cursor = Gdk.Cursor.create `HAND2
219   val maction_cursor = Gdk.Cursor.create `QUESTION_ARROW
220
221   initializer
222     self#set_font_size (MatitaMisc.get_current_font_size ());
223     ignore (self#connect#selection_changed self#choose_selection_cb);
224     ignore (self#event#connect#button_press self#button_press_cb);
225     ignore (self#event#connect#button_release self#button_release_cb);
226     ignore (self#event#connect#selection_clear self#selection_clear_cb);
227     ignore (self#connect#element_over self#element_over_cb);
228     ignore (self#coerce#misc#connect#selection_get self#selection_get_cb)
229
230   val mutable button_press_x = -1.
231   val mutable button_press_y = -1.
232   val mutable selection_changed = false
233   val mutable href_statusbar_msg:
234     (GMisc.statusbar_context * Gtk.statusbar_message) option = None
235     (* <statusbar ctxt, statusbar msg> *)
236
237   method private selection_get_cb ctxt ~info ~time =
238     let text =
239       match ctxt#target with
240       | "PATTERN" -> self#text_of_selection `Pattern
241       | "TERM" | _ -> self#text_of_selection `Term
242     in
243     match text with
244     | None -> ()
245     | Some s -> ctxt#return s
246
247   method private text_of_selection fmt =
248     match self#get_selections with
249     | [] -> None
250     | node :: _ -> Some (self#string_of_node ~paste_kind:fmt node)
251
252   method private selection_clear_cb sel_event =
253     self#remove_selections;
254     (GData.clipboard Gdk.Atom.clipboard)#clear ();
255     false
256
257   method private button_press_cb gdk_button =
258     let button = GdkEvent.Button.button gdk_button in
259     if  button = MatitaMisc.left_button then begin
260       button_press_x <- GdkEvent.Button.x gdk_button;
261       button_press_y <- GdkEvent.Button.y gdk_button;
262       selection_changed <- false
263     end else if button = MatitaMisc.right_button then
264       self#popup_contextual_menu 
265         (self#get_element_at 
266           (int_of_float (GdkEvent.Button.x gdk_button)) 
267           (int_of_float (GdkEvent.Button.y gdk_button)))  
268         (GdkEvent.Button.time gdk_button);
269     false
270
271   method private element_over_cb (elt_opt, _, _, _) =
272     let win () = self#misc#window in
273     let leave_href () =
274       Gdk.Window.set_cursor (win ()) normal_cursor;
275       HExtlib.iter_option (fun (ctxt, msg) -> ctxt#remove msg)
276         href_statusbar_msg
277     in
278     match elt_opt with
279     | Some elt ->
280         if has_maction elt then
281           Gdk.Window.set_cursor (win ()) maction_cursor
282         else
283         (match hrefs_of_elt elt with
284         | Some ((_ :: _) as hrefs) ->
285             Gdk.Window.set_cursor (win ()) href_cursor;
286             let msg_text = (* now create statusbar msg and store it *)
287               match hrefs with
288               | [ href ] -> sprintf "Hyperlink to %s" href
289               | _ -> sprintf "Hyperlinks to: %s" (String.concat ", " hrefs) in
290             let ctxt = (get_gui ())#main#statusBar#new_context ~name:"href" in
291             let msg = ctxt#push msg_text in
292             href_statusbar_msg <- Some (ctxt, msg)
293         | _ -> leave_href ())
294     | None -> leave_href ()
295
296   method private tactic_text_pattern_of_node node =
297    let id = id_of_node node in
298    let cic_info, unsh_sequent = self#get_cic_info id in
299    match self#get_term_by_id cic_info id with
300    | SelTerm (t, father_hyp) ->
301        let sequent = self#sequent_of_id ~paste_kind:`Pattern id in
302        let text = self#string_of_cic_sequent ~output_type:`Pattern sequent in
303        (match father_hyp with
304        | None -> None, [], Some text
305        | Some hyp_name -> None, [ hyp_name, text ], None)
306    | SelHyp (hyp_name, _ctxt) -> None, [ hyp_name, "%" ], None
307
308   method private tactic_text_of_node node =
309    let id = id_of_node node in
310    let cic_info, unsh_sequent = self#get_cic_info id in
311    match self#get_term_by_id cic_info id with
312    | SelTerm (t, father_hyp) ->
313        let sequent = self#sequent_of_id ~paste_kind:`Term id in
314        let text = self#string_of_cic_sequent ~output_type:`Term sequent in
315        text
316    | SelHyp (hyp_name, _ctxt) -> hyp_name
317
318     (** @return a pattern structure which contains pretty printed terms *)
319   method private tactic_text_pattern_of_selection =
320     match self#get_selections with
321     | [] -> assert false (* this method is invoked only if there's a sel. *)
322     | node :: _ -> self#tactic_text_pattern_of_node node
323
324   method private popup_contextual_menu element time =
325     let menu = GMenu.menu () in
326     let add_menu_item ?(menu = menu) ?stock ?label () =
327       GMenu.image_menu_item ?stock ?label ~packing:menu#append () in
328     let check = add_menu_item ~label:"Check" () in
329     let reductions_menu_item = GMenu.menu_item ~label:"βδιζ-reduce" () in
330     let tactics_menu_item = GMenu.menu_item ~label:"Apply tactic" () in
331     let hyperlinks_menu_item = GMenu.menu_item ~label:"Hyperlinks" () in
332     menu#append reductions_menu_item;
333     menu#append tactics_menu_item;
334     menu#append hyperlinks_menu_item;
335     let reductions = GMenu.menu () in
336     let tactics = GMenu.menu () in
337     let hyperlinks = GMenu.menu () in
338     reductions_menu_item#set_submenu reductions;
339     tactics_menu_item#set_submenu tactics;
340     hyperlinks_menu_item#set_submenu hyperlinks;
341     let normalize = add_menu_item ~menu:reductions ~label:"Normalize" () in
342     let simplify = add_menu_item ~menu:reductions ~label:"Simplify" () in
343     let whd = add_menu_item ~menu:reductions ~label:"Weak head" () in
344     (match element with 
345     | None -> hyperlinks_menu_item#misc#set_sensitive false
346     | Some elt -> 
347         match hrefs_of_elt elt, href_callback with
348         | Some l, Some f ->
349             List.iter 
350               (fun h ->
351                 let item = add_menu_item ~menu:hyperlinks ~label:h () in
352                 connect_menu_item item (fun () -> f h)) l
353         | _ -> hyperlinks_menu_item#misc#set_sensitive false);
354     menu#append (GMenu.separator_item ());
355     let copy = add_menu_item ~stock:`COPY () in
356     let gui = get_gui () in
357     List.iter (fun item -> item#misc#set_sensitive gui#canCopy)
358       [ copy; check; normalize; simplify; whd ];
359     let reduction_action kind () =
360       let pat = self#tactic_text_pattern_of_selection in
361       let statement =
362         let loc = HExtlib.dummy_floc in
363         "\n" ^
364         GrafiteAstPp.pp_executable ~term_pp:(fun s -> s)
365           ~lazy_term_pp:(fun _ -> assert false) ~obj_pp:(fun _ -> assert false)
366           ~map_unicode_to_tex:(Helm_registry.get_bool
367             "matita.paste_unicode_as_tex")
368           (GrafiteAst.Tactic (loc,
369             Some (GrafiteAst.Reduce (loc, kind, pat)),
370             GrafiteAst.Semicolon loc)) in
371       (MatitaScript.current ())#advance ~statement () in
372     connect_menu_item copy gui#copy;
373     connect_menu_item normalize (reduction_action `Normalize);
374     connect_menu_item simplify (reduction_action `Simpl);
375     connect_menu_item whd (reduction_action `Whd);
376     menu#popup ~button:MatitaMisc.right_button ~time
377
378   method private button_release_cb gdk_button =
379     if GdkEvent.Button.button gdk_button = MatitaMisc.left_button then begin
380       let button_release_x = GdkEvent.Button.x gdk_button in
381       let button_release_y = GdkEvent.Button.y gdk_button in
382       if selection_changed then
383         ()
384       else  (* selection _not_ changed *)
385         if near (button_press_x, button_press_y)
386           (button_release_x, button_release_y)
387         then
388           let x = int_of_float button_press_x in
389           let y = int_of_float button_press_y in
390           (match self#get_element_at x y with
391           | None -> ()
392           | Some elt ->
393               if has_maction elt then ignore(self#action_toggle elt) else
394               (match hrefs_of_elt elt with
395               | Some hrefs -> self#invoke_href_callback hrefs gdk_button
396               | None -> ()))
397     end;
398     false
399
400   method private invoke_href_callback hrefs gdk_button =
401     let button = GdkEvent.Button.button gdk_button in
402     if button = MatitaMisc.left_button then
403       let time = GdkEvent.Button.time gdk_button in
404       match href_callback with
405       | None -> ()
406       | Some f ->
407           (match hrefs with
408           | [ uri ] ->  f uri
409           | uris ->
410               let menu = GMenu.menu () in
411               List.iter
412                 (fun uri ->
413                   let menu_item =
414                     GMenu.menu_item ~label:uri ~packing:menu#append () in
415                   connect_menu_item menu_item 
416                   (fun () -> try f uri with Not_found -> assert false))
417                 uris;
418               menu#popup ~button ~time)
419
420   method private choose_selection_cb gdome_elt =
421     let set_selection elt =
422       let misc = self#coerce#misc in
423       self#set_selection (Some elt);
424       misc#add_selection_target ~target:"STRING" Gdk.Atom.primary;
425       ignore (misc#grab_selection Gdk.Atom.primary);
426     in
427     let rec aux elt =
428       if (elt#getAttributeNS ~namespaceURI:helm_ns
429             ~localName:xref_ds)#to_string <> ""
430       then
431         set_selection elt
432       else
433         try
434           (match elt#get_parentNode with
435           | None -> assert false
436           | Some p -> aux (new Gdome.element_of_node p))
437         with GdomeInit.DOMCastException _ -> ()
438     in
439     (match gdome_elt with
440     | Some elt when (elt#getAttributeNS ~namespaceURI:xlink_ns
441         ~localName:href_ds)#to_string <> "" ->
442           set_selection elt
443     | Some elt -> aux elt
444     | None -> self#set_selection None);
445     selection_changed <- true
446
447   method update_font_size = self#set_font_size (MatitaMisc.get_current_font_size ())
448
449     (** find a term by id from stored CIC infos @return either `Hyp if the id
450      * correspond to an hypothesis or `Term (cic, hyp) if the id correspond to a
451      * term. In the latter case hyp is either None (if the term is a subterm of
452      * the sequent conclusion) or Some hyp_name if the term belongs to an
453      * hypothesis *)
454   method private get_term_by_id cic_info id =
455     let unsh_item, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, _, _ =
456       cic_info in
457     let rec find_father_hyp id =
458       if Hashtbl.mem ids_to_hypotheses id
459       then Some (name_of_hypothesis (Hashtbl.find ids_to_hypotheses id))
460       else
461         let father_id =
462           try Hashtbl.find ids_to_father_ids id
463           with Not_found -> assert false in
464         match father_id with
465         | Some id -> find_father_hyp id
466         | None -> None
467     in
468     try
469       let term = Hashtbl.find ids_to_terms id in
470       let father_hyp = find_father_hyp id in
471       SelTerm (term, father_hyp)
472     with Not_found ->
473       try
474         let hyp = Hashtbl.find ids_to_hypotheses id in
475         let _, context, _ =
476           match unsh_item with Some seq -> seq | None -> assert false in
477         let context' = MatitaMisc.list_tl_at hyp context in
478         SelHyp (name_of_hypothesis hyp, context')
479       with Not_found -> assert false
480     
481   method private find_obj_conclusion id =
482     match self#cic_info with
483     | None
484     | Some (_, _, _, _, _, None) -> assert false
485     | Some (_, ids_to_terms, _, ids_to_father_ids, ids_to_inner_types, Some annobj) ->
486         let id =
487          find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types
488         in
489          (try Hashtbl.find ids_to_terms id with Not_found -> assert false)
490
491   method private string_of_node ~(paste_kind:paste_kind) node =
492     if node#hasAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds
493     then
494       match paste_kind with
495       | `Pattern ->
496           let tactic_text_pattern =  self#tactic_text_pattern_of_node node in
497           GrafiteAstPp.pp_tactic_pattern
498             ~term_pp:(fun s -> s) ~lazy_term_pp:(fun _ -> assert false)
499             ~map_unicode_to_tex:(Helm_registry.get_bool
500               "matita.paste_unicode_as_tex")
501             tactic_text_pattern
502       | `Term -> self#tactic_text_of_node node
503     else string_of_dom_node node
504
505   method private string_of_cic_sequent ~output_type cic_sequent =
506     let script = MatitaScript.current () in
507     let metasenv =
508       if script#onGoingProof () then script#proofMetasenv else [] in
509     let map_unicode_to_tex =
510       Helm_registry.get_bool "matita.paste_unicode_as_tex" in
511     ApplyTransformation.txt_of_cic_sequent_conclusion ~map_unicode_to_tex
512      ~output_type text_width metasenv cic_sequent
513
514   method private pattern_of term father_hyp unsh_sequent =
515     let _, unsh_context, conclusion = unsh_sequent in
516     let where =
517      match father_hyp with
518         None -> conclusion
519       | Some name ->
520          let rec aux =
521           function
522              [] -> assert false
523            | Some (Cic.Name name', Cic.Decl ty)::_ when name' = name -> ty
524            | Some (Cic.Name name', Cic.Def (bo,_))::_ when name' = name-> bo
525            | _::tl -> aux tl
526          in
527           aux unsh_context
528     in
529      ProofEngineHelpers.pattern_of ~term:where [term]
530
531   method private get_cic_info id =
532     match self#cic_info with
533     | Some ((Some unsh_sequent, _, _, _, _, _) as info) -> info, unsh_sequent
534     | Some ((None, _, _, _, _, _) as info) ->
535         let t = self#find_obj_conclusion id in
536         info, (~-1, [], t) (* dummy sequent for obj *)
537     | None -> assert false
538
539   method private sequent_of_id ~(paste_kind:paste_kind) id =
540     let cic_info, unsh_sequent = self#get_cic_info id in
541     let cic_sequent =
542       match self#get_term_by_id cic_info id with
543       | SelTerm (t, father_hyp) ->
544 (*
545 IDIOTA: PRIMA SI FA LA LOCATE, POI LA PATTERN_OF. MEGLIO UN'UNICA pattern_of CHE PRENDA IN INPUT UN TERMINE E UN SEQUENTE. PER IL MOMENTO RISOLVO USANDO LA father_hyp PER RITROVARE L'IPOTESI PERDUTA
546 *)
547           let occurrences =
548             ProofEngineHelpers.locate_in_conjecture t unsh_sequent in
549           (match occurrences with
550           | [ context, _t ] ->
551               (match paste_kind with
552               | `Term -> ~-1, context, t
553               | `Pattern -> ~-1, [], self#pattern_of t father_hyp unsh_sequent)
554           | _ ->
555               HLog.error (sprintf "found %d occurrences while 1 was expected"
556                 (List.length occurrences));
557               assert false) (* since it uses physical equality *)
558       | SelHyp (_name, context) -> ~-1, context, Cic.Rel 1 in
559     cic_sequent
560
561   method private string_of_selection ~(paste_kind:paste_kind) =
562     match self#get_selections with
563     | [] -> None
564     | node :: _ -> Some (self#string_of_node ~paste_kind node)
565
566     (** @return an associative list format -> string with all possible selection
567      * formats. Rationale: in order to convert the selection to TERM or PATTERN
568      * format we need the sequent, the metasenv, ... keeping all of them in a
569      * closure would be more expensive than keeping their already converted
570      * forms *)
571   method strings_of_selection =
572     try
573       let misc = self#coerce#misc in
574       List.iter
575         (fun target -> misc#add_selection_target ~target Gdk.Atom.clipboard)
576         [ "TERM"; "PATTERN"; "STRING" ];
577       ignore (misc#grab_selection Gdk.Atom.clipboard);
578       List.map
579         (fun paste_kind ->
580           paste_kind, HExtlib.unopt (self#string_of_selection ~paste_kind))
581         [ `Term; `Pattern ]
582     with Failure _ -> failwith "no selection"
583 *)
584 end
585
586 class _cicMathView obj =
587 object (self)
588   inherit clickableMathView obj
589
590   val mutable current_mathml = None
591
592   method nload_sequent:
593    'status. #ApplyTransformation.status as 'status -> NCic.metasenv ->
594      NCic.substitution -> int -> unit
595    = fun status metasenv subst metano ->
596     let sequent = List.assoc metano metasenv in
597     let txt =
598      ApplyTransformation.ntxt_of_cic_sequent
599       ~map_unicode_to_tex:false 80 status metasenv subst (metano,sequent)
600     in
601     (* MATITA 1.0 if BuildTimeConf.debug then begin
602       let name =
603        "/tmp/sequent_viewer_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
604       HLog.debug ("load_sequent: dumping MathML to ./" ^ name);
605       ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
606     end;*)
607     self#load_root ~root:txt
608
609   method load_nobject :
610    'status. #ApplyTransformation.status as 'status -> NCic.obj -> unit
611    = fun status obj ->
612     let txt = ApplyTransformation.ntxt_of_cic_object ~map_unicode_to_tex:false
613     80 status obj in
614 (*
615     self#set_cic_info
616       (Some (None, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, ids_to_inner_types, Some annobj));
617     (match current_mathml with
618     | Some current_mathml when use_diff ->
619         self#freeze;
620         XmlDiff.update_dom ~from:current_mathml mathml;
621         self#thaw
622     |  _ ->
623 *)
624         (* MATITA1.0 if BuildTimeConf.debug then begin
625           let name =
626            "/tmp/cic_browser_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
627           HLog.debug ("cic_browser: dumping MathML to ./" ^ name);
628           ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
629         end;*)
630         self#load_root ~root:txt;
631         (*current_mathml <- Some mathml*)(*)*);
632 end
633
634  (** constructors *)
635
636 let cicMathView (*?auto_indent ?highlight_current_line ?indent_on_tab ?indent_width ?insert_spaces_instead_of_tabs ?right_margin_position ?show_line_marks ?show_line_numbers ?show_right_margin ?smart_home_end ?tab_width ?editable ?cursor_visible ?justification ?wrap_mode ?accepts_tab ?border_width*) ?width ?height ?packing ?show () =
637  ((*SourceView.make_params [] ~cont:(
638     GtkText.View.make_params ~cont:( *)
639       GContainer.pack_container ~create:(fun pl ->
640         let obj = SourceView.new_ () in
641         Gobject.set_params (Gobject.try_cast obj "GtkSourceView") pl;
642         new _cicMathView obj)(*)) ?auto_indent ?highlight_current_line ?indent_on_tab ?indent_width ?insert_spaces_instead_of_tabs ?right_margin_position ?show_line_marks ?show_line_numbers ?show_right_margin ?smart_home_end ?tab_width ?editable ?cursor_visible ?justification ?wrap_mode ?accepts_tab ?border_width*) [] ?width ?height ?packing ?show () :> cicMathView)