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