1 (* Copyright (C) 2004-2005, HELM Team.
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.
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.
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.
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,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
33 let matita_script_current = ref (fun _ -> (assert false : < advance: ?statement:string -> unit -> unit; status: GrafiteTypes.status >));;
34 let register_matita_script_current f = matita_script_current := f;;
35 let get_matita_script_current () = !matita_script_current ();;
37 type document_element = (int * int * string) list * string (* hyperlinks,text *)
39 class type cicMathView =
43 method load_root : root:document_element -> unit
44 method remove_selections: unit
45 method set_selection: document_element option -> unit
46 method get_selections: document_element list
48 (** @raise Failure "no selection" *)
49 method strings_of_selection: (MatitaGuiTypes.paste_kind * string) list
51 (** set hyperlink callback. None disable hyperlink handling *)
52 method set_href_callback: (string -> unit) option -> unit
54 (** load a sequent and render it into parent widget *)
56 #ApplyTransformation.status -> NCic.metasenv -> NCic.substitution -> int -> unit
58 method load_nobject: #ApplyTransformation.status -> NCic.obj -> unit
62 let xlink_ns = Gdome.domString "http://www.w3.org/1999/xlink"
63 let helm_ns = Gdome.domString "http://www.cs.unibo.it/helm"
64 let href_ds = Gdome.domString "href"
65 let xref_ds = Gdome.domString "xref"
68 (** Gdome.element of a MathML document whose rendering should be blank. Used
69 * by cicBrowser to render "about:blank" document *)
70 let empty_mathml = lazy ([],"")
72 (** shown for goals closed by side effects *)
73 let closed_goal_mathml = lazy ([],"chiuso per side effect...")
76 let rec has_maction (elt :Gdome.element) =
77 (* fix this comparison *)
78 if elt#get_tagName#to_string = "m:maction" ||
79 elt#get_tagName#to_string = "b:action" then
82 match elt#get_parentNode with
83 | Some node when node#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE ->
84 has_maction (new Gdome.element_of_node node)
88 let hrefs_of_elt elt =
89 let localName = href_ds in
90 if elt#hasAttributeNS ~namespaceURI:xlink_ns ~localName then
92 (elt#getAttributeNS ~namespaceURI:xlink_ns ~localName)#to_string in
93 Some (HExtlib.split text)
97 let id_of_node (node: Gdome.element) =
99 node#getAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds in
101 List.hd (HExtlib.split ~sep:' ' xref_attr#to_string)
102 with Failure _ -> assert false
105 | SelTerm of NCic.term * string option (* term, parent hypothesis (if any) *)
106 | SelHyp of string * NCic.context (* hypothesis, context *)
109 let near (x1, y1) (x2, y2) =
110 let distance = sqrt (((x2 -. x1) ** 2.) +. ((y2 -. y1) ** 2.)) in
114 let name_of_hypothesis = function
115 | Some (Cic.Name s, _) -> s
118 let domImpl = Gdome.domImplementation ()
120 (* ids_to_terms should not be passed here, is just for debugging *)
121 let find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types =
122 assert false (* MATITA 1.0
123 let find_parent id ids =
125 (* (prerr_endline (sprintf "id %s = %s" id
127 CicPp.ppterm (Hashtbl.find ids_to_terms id)
128 with Not_found -> "NONE"))); *)
129 if List.mem id ids then Some id
132 (try Hashtbl.find ids_to_father_ids id with Not_found -> None)
135 | Some id' -> aux id')
139 let return_father id ids =
140 match find_parent id ids with
141 | None -> assert false
142 | Some parent_id -> parent_id
144 let mk_ids terms = List.map CicUtil.id_of_annterm terms in
148 match types.Cic2acic.annexpected with
149 None -> types.Cic2acic.annsynthesized :: acc
150 | Some ty -> ty :: types.Cic2acic.annsynthesized :: acc
151 ) ids_to_inner_types [] in
153 | Cic.AConstant (_, _, _, Some bo, ty, _, _)
154 | Cic.AVariable (_, _, Some bo, ty, _, _)
155 | Cic.ACurrentProof (_, _, _, _, bo, ty, _, _) ->
156 return_father id (mk_ids (ty :: bo :: inner_types))
157 | Cic.AConstant (_, _, _, None, ty, _, _)
158 | Cic.AVariable (_, _, None, ty, _, _) ->
159 return_father id (mk_ids (ty::inner_types))
160 | Cic.AInductiveDefinition _ ->
161 assert false (* TODO *)
164 (** @return string content of a dom node having a single text child node, e.g.
165 * <m:mi xlink:href="...">bool</m:mi> *)
166 let string_of_dom_node node =
167 match node#get_firstChild with
171 let text = new Gdome.text_of_node node in
172 text#get_data#to_string
173 with GdomeInit.DOMCastException _ -> "")
176 class clickableMathView obj =
177 let text_width = 80 in
179 inherit GSourceView2.source_view obj
181 method strings_of_selection = (assert false : (paste_kind * string) list)
183 val mutable href_callback: (string -> unit) option = None
184 method set_href_callback f = href_callback <- f
186 val mutable href_statusbar_msg:
187 (GMisc.statusbar_context * Gtk.statusbar_message) option = None
188 (* <statusbar ctxt, statusbar msg> *)
190 method private set_cic_info = (function _ -> () : unit (*(Cic.conjecture option * (Cic.id, Cic.term) Hashtbl.t *
191 (Cic.id, Cic.hypothesis) Hashtbl.t *
192 (Cic.id, Cic.id option) Hashtbl.t * ('a, 'b) Hashtbl.t * 'c option)*) option -> unit)
193 (* dal widget di Luca *)
194 method load_root ~root:(hyperlinks,text) =
195 self#buffer#delete ~start:(self#buffer#get_iter `START)
196 ~stop:(self#buffer#get_iter `END);
197 self#buffer#insert text;
198 let all_tag = self#buffer#create_tag [] in
199 self#buffer#apply_tag all_tag ~start:(self#buffer#get_iter `START)
200 ~stop:(self#buffer#get_iter `END);
201 ignore(all_tag#connect#event
202 ~callback:(fun ~origin event pos ->
203 match GdkEvent.get_type event with
205 Gdk.Window.set_cursor
206 (match self#get_window `TEXT with None -> assert false | Some x -> x)
207 (Gdk.Cursor.create `ARROW);
208 HExtlib.iter_option (fun (ctxt, msg) -> ctxt#remove msg)
212 let hyperlink_tag = self#buffer#create_tag [] in
213 ignore(hyperlink_tag#connect#event
214 ~callback:(fun ~origin event pos ->
215 let offset = (new GText.iter pos)#offset in
219 (fun (start,stop,href) -> start <= offset && offset <= stop
222 Not_found -> assert false
224 match GdkEvent.get_type event with
226 (match href_callback with
231 Gdk.Window.set_cursor
232 (match self#get_window `TEXT with None -> assert false | Some x -> x)
233 (Gdk.Cursor.create `HAND1);
234 let ctxt = (MatitaMisc.get_gui ())#main#statusBar#new_context ~name:"href" in
235 let msg = ctxt#push href in
236 href_statusbar_msg <- Some (ctxt, msg);
240 ( fun (start,stop,(href : string)) ->
241 self#buffer#apply_tag hyperlink_tag
242 ~start:(self#buffer#get_iter_at_char start)
243 ~stop:(self#buffer#get_iter_at_char (stop+1));
247 method action_toggle = (fun _ -> assert false : document_element -> bool)
248 method remove_selections = (() : unit)
249 method set_selection = (fun _ -> () : document_element option -> unit)
250 method get_selections = (assert false : document_element list)
253 self#source_buffer#set_language (Some MatitaGtkMisc.matita_lang);
254 self#source_buffer#set_highlight_syntax true;
255 self#set_editable false;
256 MatitaMisc.observe_font_size
258 self#misc#modify_font_by_name
259 (sprintf "%s %d" BuildTimeConf.script_font size))
262 inherit GMathViewAux.multi_selection_math_view obj
264 val mutable href_callback: (string -> unit) option = None
265 method set_href_callback f = href_callback <- f
267 val mutable _cic_info = None
268 method private set_cic_info info = _cic_info <- info
269 method private cic_info = _cic_info
271 val normal_cursor = Gdk.Cursor.create `LEFT_PTR
272 val href_cursor = Gdk.Cursor.create `HAND2
273 val maction_cursor = Gdk.Cursor.create `QUESTION_ARROW
276 ignore (self#connect#selection_changed self#choose_selection_cb);
277 ignore (self#event#connect#button_press self#button_press_cb);
278 ignore (self#event#connect#button_release self#button_release_cb);
279 ignore (self#event#connect#selection_clear self#selection_clear_cb);
280 ignore (self#connect#element_over self#element_over_cb);
281 ignore (self#coerce#misc#connect#selection_get self#selection_get_cb)
283 val mutable button_press_x = -1.
284 val mutable button_press_y = -1.
285 val mutable selection_changed = false
286 val mutable href_statusbar_msg:
287 (GMisc.statusbar_context * Gtk.statusbar_message) option = None
288 (* <statusbar ctxt, statusbar msg> *)
290 method private selection_get_cb ctxt ~info ~time =
292 match ctxt#target with
293 | "PATTERN" -> self#text_of_selection `Pattern
294 | "TERM" | _ -> self#text_of_selection `Term
298 | Some s -> ctxt#return s
300 method private text_of_selection fmt =
301 match self#get_selections with
303 | node :: _ -> Some (self#string_of_node ~paste_kind:fmt node)
305 method private selection_clear_cb sel_event =
306 self#remove_selections;
307 (GData.clipboard Gdk.Atom.clipboard)#clear ();
310 method private button_press_cb gdk_button =
311 let button = GdkEvent.Button.button gdk_button in
312 if button = MatitaMisc.left_button then begin
313 button_press_x <- GdkEvent.Button.x gdk_button;
314 button_press_y <- GdkEvent.Button.y gdk_button;
315 selection_changed <- false
316 end else if button = MatitaMisc.right_button then
317 self#popup_contextual_menu
319 (int_of_float (GdkEvent.Button.x gdk_button))
320 (int_of_float (GdkEvent.Button.y gdk_button)))
321 (GdkEvent.Button.time gdk_button);
324 method private element_over_cb (elt_opt, _, _, _) =
325 let win () = self#misc#window in
327 Gdk.Window.set_cursor (win ()) normal_cursor;
328 HExtlib.iter_option (fun (ctxt, msg) -> ctxt#remove msg)
333 if has_maction elt then
334 Gdk.Window.set_cursor (win ()) maction_cursor
336 (match hrefs_of_elt elt with
337 | Some ((_ :: _) as hrefs) ->
338 Gdk.Window.set_cursor (win ()) href_cursor;
339 let msg_text = (* now create statusbar msg and store it *)
341 | [ href ] -> sprintf "Hyperlink to %s" href
342 | _ -> sprintf "Hyperlinks to: %s" (String.concat ", " hrefs) in
343 let ctxt = (get_gui ())#main#statusBar#new_context ~name:"href" in
344 let msg = ctxt#push msg_text in
345 href_statusbar_msg <- Some (ctxt, msg)
346 | _ -> leave_href ())
347 | None -> leave_href ()
349 method private tactic_text_pattern_of_node node =
350 let id = id_of_node node in
351 let cic_info, unsh_sequent = self#get_cic_info id in
352 match self#get_term_by_id cic_info id with
353 | SelTerm (t, father_hyp) ->
354 let sequent = self#sequent_of_id ~paste_kind:`Pattern id in
355 let text = self#string_of_cic_sequent ~output_type:`Pattern sequent in
356 (match father_hyp with
357 | None -> None, [], Some text
358 | Some hyp_name -> None, [ hyp_name, text ], None)
359 | SelHyp (hyp_name, _ctxt) -> None, [ hyp_name, "%" ], None
361 method private tactic_text_of_node node =
362 let id = id_of_node node in
363 let cic_info, unsh_sequent = self#get_cic_info id in
364 match self#get_term_by_id cic_info id with
365 | SelTerm (t, father_hyp) ->
366 let sequent = self#sequent_of_id ~paste_kind:`Term id in
367 let text = self#string_of_cic_sequent ~output_type:`Term sequent in
369 | SelHyp (hyp_name, _ctxt) -> hyp_name
371 (** @return a pattern structure which contains pretty printed terms *)
372 method private tactic_text_pattern_of_selection =
373 match self#get_selections with
374 | [] -> assert false (* this method is invoked only if there's a sel. *)
375 | node :: _ -> self#tactic_text_pattern_of_node node
377 method private popup_contextual_menu element time =
378 let menu = GMenu.menu () in
379 let add_menu_item ?(menu = menu) ?stock ?label () =
380 GMenu.image_menu_item ?stock ?label ~packing:menu#append () in
381 let check = add_menu_item ~label:"Check" () in
382 let reductions_menu_item = GMenu.menu_item ~label:"βδιζ-reduce" () in
383 let tactics_menu_item = GMenu.menu_item ~label:"Apply tactic" () in
384 let hyperlinks_menu_item = GMenu.menu_item ~label:"Hyperlinks" () in
385 menu#append reductions_menu_item;
386 menu#append tactics_menu_item;
387 menu#append hyperlinks_menu_item;
388 let reductions = GMenu.menu () in
389 let tactics = GMenu.menu () in
390 let hyperlinks = GMenu.menu () in
391 reductions_menu_item#set_submenu reductions;
392 tactics_menu_item#set_submenu tactics;
393 hyperlinks_menu_item#set_submenu hyperlinks;
394 let normalize = add_menu_item ~menu:reductions ~label:"Normalize" () in
395 let simplify = add_menu_item ~menu:reductions ~label:"Simplify" () in
396 let whd = add_menu_item ~menu:reductions ~label:"Weak head" () in
398 | None -> hyperlinks_menu_item#misc#set_sensitive false
400 match hrefs_of_elt elt, href_callback with
404 let item = add_menu_item ~menu:hyperlinks ~label:h () in
405 connect_menu_item item (fun () -> f h)) l
406 | _ -> hyperlinks_menu_item#misc#set_sensitive false);
407 menu#append (GMenu.separator_item ());
408 let copy = add_menu_item ~stock:`COPY () in
409 let gui = get_gui () in
410 List.iter (fun item -> item#misc#set_sensitive gui#canCopy)
411 [ copy; check; normalize; simplify; whd ];
412 let reduction_action kind () =
413 let pat = self#tactic_text_pattern_of_selection in
415 let loc = HExtlib.dummy_floc in
417 GrafiteAstPp.pp_executable ~term_pp:(fun s -> s)
418 ~lazy_term_pp:(fun _ -> assert false) ~obj_pp:(fun _ -> assert false)
419 ~map_unicode_to_tex:(Helm_registry.get_bool
420 "matita.paste_unicode_as_tex")
421 (GrafiteAst.Tactic (loc,
422 Some (GrafiteAst.Reduce (loc, kind, pat)),
423 GrafiteAst.Semicolon loc)) in
424 (get_matita_script_current ())#advance ~statement () in
425 connect_menu_item copy gui#copy;
426 connect_menu_item normalize (reduction_action `Normalize);
427 connect_menu_item simplify (reduction_action `Simpl);
428 connect_menu_item whd (reduction_action `Whd);
429 menu#popup ~button:MatitaMisc.right_button ~time
431 method private button_release_cb gdk_button =
432 if GdkEvent.Button.button gdk_button = MatitaMisc.left_button then begin
433 let button_release_x = GdkEvent.Button.x gdk_button in
434 let button_release_y = GdkEvent.Button.y gdk_button in
435 if selection_changed then
437 else (* selection _not_ changed *)
438 if near (button_press_x, button_press_y)
439 (button_release_x, button_release_y)
441 let x = int_of_float button_press_x in
442 let y = int_of_float button_press_y in
443 (match self#get_element_at x y with
446 if has_maction elt then ignore(self#action_toggle elt) else
447 (match hrefs_of_elt elt with
448 | Some hrefs -> self#invoke_href_callback hrefs gdk_button
453 method private invoke_href_callback hrefs gdk_button =
454 let button = GdkEvent.Button.button gdk_button in
455 if button = MatitaMisc.left_button then
456 let time = GdkEvent.Button.time gdk_button in
457 match href_callback with
463 let menu = GMenu.menu () in
467 GMenu.menu_item ~label:uri ~packing:menu#append () in
468 connect_menu_item menu_item
469 (fun () -> try f uri with Not_found -> assert false))
471 menu#popup ~button ~time)
473 method private choose_selection_cb gdome_elt =
474 let set_selection elt =
475 let misc = self#coerce#misc in
476 self#set_selection (Some elt);
477 misc#add_selection_target ~target:"STRING" Gdk.Atom.primary;
478 ignore (misc#grab_selection Gdk.Atom.primary);
481 if (elt#getAttributeNS ~namespaceURI:helm_ns
482 ~localName:xref_ds)#to_string <> ""
487 (match elt#get_parentNode with
488 | None -> assert false
489 | Some p -> aux (new Gdome.element_of_node p))
490 with GdomeInit.DOMCastException _ -> ()
492 (match gdome_elt with
493 | Some elt when (elt#getAttributeNS ~namespaceURI:xlink_ns
494 ~localName:href_ds)#to_string <> "" ->
496 | Some elt -> aux elt
497 | None -> self#set_selection None);
498 selection_changed <- true
500 (** find a term by id from stored CIC infos @return either `Hyp if the id
501 * correspond to an hypothesis or `Term (cic, hyp) if the id correspond to a
502 * term. In the latter case hyp is either None (if the term is a subterm of
503 * the sequent conclusion) or Some hyp_name if the term belongs to an
505 method private get_term_by_id cic_info id =
506 let unsh_item, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, _, _ =
508 let rec find_father_hyp id =
509 if Hashtbl.mem ids_to_hypotheses id
510 then Some (name_of_hypothesis (Hashtbl.find ids_to_hypotheses id))
513 try Hashtbl.find ids_to_father_ids id
514 with Not_found -> assert false in
516 | Some id -> find_father_hyp id
520 let term = Hashtbl.find ids_to_terms id in
521 let father_hyp = find_father_hyp id in
522 SelTerm (term, father_hyp)
525 let hyp = Hashtbl.find ids_to_hypotheses id in
527 match unsh_item with Some seq -> seq | None -> assert false in
528 let context' = MatitaMisc.list_tl_at hyp context in
529 SelHyp (name_of_hypothesis hyp, context')
530 with Not_found -> assert false
532 method private find_obj_conclusion id =
533 match self#cic_info with
535 | Some (_, _, _, _, _, None) -> assert false
536 | Some (_, ids_to_terms, _, ids_to_father_ids, ids_to_inner_types, Some annobj) ->
538 find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types
540 (try Hashtbl.find ids_to_terms id with Not_found -> assert false)
542 method private string_of_node ~(paste_kind:paste_kind) node =
543 if node#hasAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds
545 match paste_kind with
547 let tactic_text_pattern = self#tactic_text_pattern_of_node node in
548 GrafiteAstPp.pp_tactic_pattern
549 ~term_pp:(fun s -> s) ~lazy_term_pp:(fun _ -> assert false)
550 ~map_unicode_to_tex:(Helm_registry.get_bool
551 "matita.paste_unicode_as_tex")
553 | `Term -> self#tactic_text_of_node node
554 else string_of_dom_node node
556 method private string_of_cic_sequent ~output_type cic_sequent =
557 let script = get_matita_script_current () in
559 if script#onGoingProof () then script#proofMetasenv else [] in
560 let map_unicode_to_tex =
561 Helm_registry.get_bool "matita.paste_unicode_as_tex" in
562 ApplyTransformation.txt_of_cic_sequent_conclusion ~map_unicode_to_tex
563 ~output_type text_width metasenv cic_sequent
565 method private pattern_of term father_hyp unsh_sequent =
566 let _, unsh_context, conclusion = unsh_sequent in
568 match father_hyp with
574 | Some (Cic.Name name', Cic.Decl ty)::_ when name' = name -> ty
575 | Some (Cic.Name name', Cic.Def (bo,_))::_ when name' = name-> bo
580 ProofEngineHelpers.pattern_of ~term:where [term]
582 method private get_cic_info id =
583 match self#cic_info with
584 | Some ((Some unsh_sequent, _, _, _, _, _) as info) -> info, unsh_sequent
585 | Some ((None, _, _, _, _, _) as info) ->
586 let t = self#find_obj_conclusion id in
587 info, (~-1, [], t) (* dummy sequent for obj *)
588 | None -> assert false
590 method private sequent_of_id ~(paste_kind:paste_kind) id =
591 let cic_info, unsh_sequent = self#get_cic_info id in
593 match self#get_term_by_id cic_info id with
594 | SelTerm (t, father_hyp) ->
596 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
599 ProofEngineHelpers.locate_in_conjecture t unsh_sequent in
600 (match occurrences with
602 (match paste_kind with
603 | `Term -> ~-1, context, t
604 | `Pattern -> ~-1, [], self#pattern_of t father_hyp unsh_sequent)
606 HLog.error (sprintf "found %d occurrences while 1 was expected"
607 (List.length occurrences));
608 assert false) (* since it uses physical equality *)
609 | SelHyp (_name, context) -> ~-1, context, Cic.Rel 1 in
612 method private string_of_selection ~(paste_kind:paste_kind) =
613 match self#get_selections with
615 | node :: _ -> Some (self#string_of_node ~paste_kind node)
617 (** @return an associative list format -> string with all possible selection
618 * formats. Rationale: in order to convert the selection to TERM or PATTERN
619 * format we need the sequent, the metasenv, ... keeping all of them in a
620 * closure would be more expensive than keeping their already converted
622 method strings_of_selection =
624 let misc = self#coerce#misc in
626 (fun target -> misc#add_selection_target ~target Gdk.Atom.clipboard)
627 [ "TERM"; "PATTERN"; "STRING" ];
628 ignore (misc#grab_selection Gdk.Atom.clipboard);
631 paste_kind, HExtlib.unopt (self#string_of_selection ~paste_kind))
633 with Failure _ -> failwith "no selection"
637 class _cicMathView obj =
639 inherit clickableMathView obj
641 val mutable current_mathml = None
643 method nload_sequent:
644 'status. #ApplyTransformation.status as 'status -> NCic.metasenv ->
645 NCic.substitution -> int -> unit
646 = fun status metasenv subst metano ->
647 let sequent = List.assoc metano metasenv in
649 ApplyTransformation.ntxt_of_cic_sequent
650 ~map_unicode_to_tex:false 80 status ~metasenv ~subst (metano,sequent)
652 (* MATITA 1.0 if BuildTimeConf.debug then begin
654 "/tmp/sequent_viewer_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
655 HLog.debug ("load_sequent: dumping MathML to ./" ^ name);
656 ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
658 self#load_root ~root:txt
660 method load_nobject :
661 'status. #ApplyTransformation.status as 'status -> NCic.obj -> unit
663 let txt = ApplyTransformation.ntxt_of_cic_object ~map_unicode_to_tex:false
667 (Some (None, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, ids_to_inner_types, Some annobj));
668 (match current_mathml with
669 | Some current_mathml when use_diff ->
671 XmlDiff.update_dom ~from:current_mathml mathml;
675 (* MATITA 1.0 if BuildTimeConf.debug then begin
677 "/tmp/cic_browser_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
678 HLog.debug ("cic_browser: dumping MathML to ./" ^ name);
679 ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
681 self#load_root ~root:txt;
682 (*current_mathml <- Some mathml*)(*)*);
687 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 () =
688 ((*SourceView.make_params [] ~cont:(
689 GtkText.View.make_params ~cont:( *)
690 GContainer.pack_container ~create:(fun pl ->
691 let obj = SourceView.new_ () in
692 Gobject.set_params (Gobject.try_cast obj "GtkSourceView") pl;
693 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)
695 let screenshot status sequents metasenv subst (filename as ofn) =
697 let w = GWindow.window ~title:"screenshot" () in
700 let m = GMathView.math_view
701 ~font_size:(MatitaMisc.get_current_font_size ()) ~width ~height
708 (fun (mno,_ as sequent) i ->
710 ApplyTransformation.nmml_of_cic_sequent
711 status metasenv subst sequent
713 m#load_root ~root:mathml#get_documentElement;
714 let pixmap = m#get_buffer in
715 let pixbuf = GdkPixbuf.create ~width ~height () in
716 GdkPixbuf.get_from_drawable ~dest:pixbuf pixmap;
718 filename ^ "-raw" ^ string_of_int i ^ ".png"
720 GdkPixbuf.save ~filename ~typ:"png" pixbuf;
725 List.map (fun (x,mno) ->
729 " '(' -gravity west -bordercolor grey -border 1 label:%d ')' "^^
730 " '(' -trim -bordercolor white -border 5 "^^
731 " -bordercolor grey -border 1 %s ')' -append %s ")
734 (Filename.quote (x ^ ".label.png"))));
738 let rec div2 = function
741 | x::y::tl -> [x;y] :: div2 tl
743 let items = div2 items in
744 ignore(Sys.command (Printf.sprintf
745 "convert %s -append %s"
747 (List.map (fun items ->
748 Printf.sprintf " '(' %s +append ')' "
750 (" '(' -gravity center -size 10x10 xc: ')' ") items)) items))
751 (Filename.quote (ofn ^ ".png"))));
752 List.iter (fun x,_ -> Sys.remove x) filenames;
753 List.iter Sys.remove (List.flatten items);