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://cs.unibo.it/helm/.
34 module Stack = Continuationals.Stack
36 (** inherit from this class if you want to access current script *)
37 class scriptAccessor =
39 method private script = MatitaScript.current ()
42 let cicBrowsers = ref []
43 let gui_instance = ref None
44 let set_gui gui = gui_instance := Some gui
46 match !gui_instance with
47 | None -> assert false
50 let default_font_size () =
51 Helm_registry.get_opt_default Helm_registry.int
52 ~default:BuildTimeConf.default_font_size "matita.font_size"
53 let current_font_size = ref ~-1
54 let increase_font_size () = incr current_font_size
55 let decrease_font_size () = decr current_font_size
56 let reset_font_size () = current_font_size := default_font_size ()
58 (* is there any lablgtk2 constant corresponding to the various mouse
64 let near (x1, y1) (x2, y2) =
65 let distance = sqrt (((x2 -. x1) ** 2.) +. ((y2 -. y1) ** 2.)) in
69 let mathml_ns = Gdome.domString "http://www.w3.org/1998/Math/MathML"
70 let xlink_ns = Gdome.domString "http://www.w3.org/1999/xlink"
71 let helm_ns = Gdome.domString "http://www.cs.unibo.it/helm"
72 let href_ds = Gdome.domString "href"
73 let maction_ds = Gdome.domString "maction"
74 let xref_ds = Gdome.domString "xref"
76 let domImpl = Gdome.domImplementation ()
78 (** Gdome.element of a MathML document whose rendering should be blank. Used
79 * by cicBrowser to render "about:blank" document *)
80 let empty_mathml = lazy (
81 domImpl#createDocument ~namespaceURI:(Some DomMisc.mathml_ns)
82 ~qualifiedName:(Gdome.domString "math") ~doctype:None)
84 let empty_boxml = lazy (
85 domImpl#createDocument ~namespaceURI:(Some DomMisc.boxml_ns)
86 ~qualifiedName:(Gdome.domString "box") ~doctype:None)
89 (** shown for goals closed by side effects *)
90 let closed_goal_mathml = lazy "chiuso per side effect..."
93 (* ids_to_terms should not be passed here, is just for debugging *)
94 let find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types =
95 assert false (* MATITA 1.0
96 let find_parent id ids =
98 (* (prerr_endline (sprintf "id %s = %s" id
100 CicPp.ppterm (Hashtbl.find ids_to_terms id)
101 with Not_found -> "NONE"))); *)
102 if List.mem id ids then Some id
105 (try Hashtbl.find ids_to_father_ids id with Not_found -> None)
108 | Some id' -> aux id')
112 let return_father id ids =
113 match find_parent id ids with
114 | None -> assert false
115 | Some parent_id -> parent_id
117 let mk_ids terms = List.map CicUtil.id_of_annterm terms in
121 match types.Cic2acic.annexpected with
122 None -> types.Cic2acic.annsynthesized :: acc
123 | Some ty -> ty :: types.Cic2acic.annsynthesized :: acc
124 ) ids_to_inner_types [] in
126 | Cic.AConstant (_, _, _, Some bo, ty, _, _)
127 | Cic.AVariable (_, _, Some bo, ty, _, _)
128 | Cic.ACurrentProof (_, _, _, _, bo, ty, _, _) ->
129 return_father id (mk_ids (ty :: bo :: inner_types))
130 | Cic.AConstant (_, _, _, None, ty, _, _)
131 | Cic.AVariable (_, _, None, ty, _, _) ->
132 return_father id (mk_ids (ty::inner_types))
133 | Cic.AInductiveDefinition _ ->
134 assert false (* TODO *)
137 (** @return string content of a dom node having a single text child node, e.g.
138 * <m:mi xlink:href="...">bool</m:mi> *)
139 let string_of_dom_node node =
140 match node#get_firstChild with
144 let text = new Gdome.text_of_node node in
145 text#get_data#to_string
146 with GdomeInit.DOMCastException _ -> "")
148 let name_of_hypothesis = function
149 | Some (Cic.Name s, _) -> s
152 let id_of_node (node: Gdome.element) =
154 node#getAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds in
156 List.hd (HExtlib.split ~sep:' ' xref_attr#to_string)
157 with Failure _ -> assert false
160 | SelTerm of Cic.term * string option (* term, parent hypothesis (if any) *)
161 | SelHyp of string * Cic.context (* hypothesis, context *)
163 let hrefs_of_elt elt =
164 let localName = href_ds in
165 if elt#hasAttributeNS ~namespaceURI:xlink_ns ~localName then
167 (elt#getAttributeNS ~namespaceURI:xlink_ns ~localName)#to_string in
168 Some (HExtlib.split text)
172 let rec has_maction (elt :Gdome.element) =
173 (* fix this comparison *)
174 if elt#get_tagName#to_string = "m:maction" ||
175 elt#get_tagName#to_string = "b:action" then
178 match elt#get_parentNode with
179 | Some node when node#get_nodeType = GdomeNodeTypeT.ELEMENT_NODE ->
180 has_maction (new Gdome.element_of_node node)
185 class clickableMathView obj =
186 let text_width = 80 in
188 inherit GSourceView2.source_view obj
190 method has_selection = (assert false : bool)
191 method strings_of_selection = (assert false : (paste_kind * string) list)
192 method update_font_size =
193 self#misc#modify_font_by_name
194 (sprintf "%s %d" BuildTimeConf.script_font !current_font_size)
195 method set_href_callback = (function _ -> () : (string -> unit) option -> unit)
196 method private set_cic_info = (function _ -> () : unit (*(Cic.conjecture option * (Cic.id, Cic.term) Hashtbl.t *
197 (Cic.id, Cic.hypothesis) Hashtbl.t *
198 (Cic.id, Cic.id option) Hashtbl.t * ('a, 'b) Hashtbl.t * 'c option)*) option -> unit)
199 (* dal widget di Luca *)
200 method load_root ~root =
201 self#buffer#delete ~start:(self#buffer#get_iter `START)
202 ~stop:(self#buffer#get_iter `END);
203 self#buffer#insert root
204 method remove_selections = (() : unit)
205 method set_selection = (fun _ -> () : unit option -> unit)
206 method get_selections = (assert false : unit list)
207 method set_font_size font_size =
208 self#misc#modify_font_by_name
209 (sprintf "%s %d" BuildTimeConf.script_font font_size)
212 self#set_font_size !current_font_size;
213 self#source_buffer#set_language (Some MatitaGtkMisc.matita_lang);
214 self#source_buffer#set_highlight_syntax true;
215 self#set_editable false
218 inherit GMathViewAux.multi_selection_math_view obj
220 val mutable href_callback: (string -> unit) option = None
221 method set_href_callback f = href_callback <- f
223 val mutable _cic_info = None
224 method private set_cic_info info = _cic_info <- info
225 method private cic_info = _cic_info
227 val normal_cursor = Gdk.Cursor.create `LEFT_PTR
228 val href_cursor = Gdk.Cursor.create `HAND2
229 val maction_cursor = Gdk.Cursor.create `QUESTION_ARROW
232 self#set_font_size !current_font_size;
233 ignore (self#connect#selection_changed self#choose_selection_cb);
234 ignore (self#event#connect#button_press self#button_press_cb);
235 ignore (self#event#connect#button_release self#button_release_cb);
236 ignore (self#event#connect#selection_clear self#selection_clear_cb);
237 ignore (self#connect#element_over self#element_over_cb);
238 ignore (self#coerce#misc#connect#selection_get self#selection_get_cb)
240 val mutable button_press_x = -1.
241 val mutable button_press_y = -1.
242 val mutable selection_changed = false
243 val mutable href_statusbar_msg:
244 (GMisc.statusbar_context * Gtk.statusbar_message) option = None
245 (* <statusbar ctxt, statusbar msg> *)
247 method private selection_get_cb ctxt ~info ~time =
249 match ctxt#target with
250 | "PATTERN" -> self#text_of_selection `Pattern
251 | "TERM" | _ -> self#text_of_selection `Term
255 | Some s -> ctxt#return s
257 method private text_of_selection fmt =
258 match self#get_selections with
260 | node :: _ -> Some (self#string_of_node ~paste_kind:fmt node)
262 method private selection_clear_cb sel_event =
263 self#remove_selections;
264 (GData.clipboard Gdk.Atom.clipboard)#clear ();
267 method private button_press_cb gdk_button =
268 let button = GdkEvent.Button.button gdk_button in
269 if button = left_button then begin
270 button_press_x <- GdkEvent.Button.x gdk_button;
271 button_press_y <- GdkEvent.Button.y gdk_button;
272 selection_changed <- false
273 end else if button = right_button then
274 self#popup_contextual_menu
276 (int_of_float (GdkEvent.Button.x gdk_button))
277 (int_of_float (GdkEvent.Button.y gdk_button)))
278 (GdkEvent.Button.time gdk_button);
281 method private element_over_cb (elt_opt, _, _, _) =
282 let win () = self#misc#window in
284 Gdk.Window.set_cursor (win ()) normal_cursor;
285 HExtlib.iter_option (fun (ctxt, msg) -> ctxt#remove msg)
290 if has_maction elt then
291 Gdk.Window.set_cursor (win ()) maction_cursor
293 (match hrefs_of_elt elt with
294 | Some ((_ :: _) as hrefs) ->
295 Gdk.Window.set_cursor (win ()) href_cursor;
296 let msg_text = (* now create statusbar msg and store it *)
298 | [ href ] -> sprintf "Hyperlink to %s" href
299 | _ -> sprintf "Hyperlinks to: %s" (String.concat ", " hrefs) in
300 let ctxt = (get_gui ())#main#statusBar#new_context ~name:"href" in
301 let msg = ctxt#push msg_text in
302 href_statusbar_msg <- Some (ctxt, msg)
303 | _ -> leave_href ())
304 | None -> leave_href ()
306 method private tactic_text_pattern_of_node node =
307 let id = id_of_node node in
308 let cic_info, unsh_sequent = self#get_cic_info id in
309 match self#get_term_by_id cic_info id with
310 | SelTerm (t, father_hyp) ->
311 let sequent = self#sequent_of_id ~paste_kind:`Pattern id in
312 let text = self#string_of_cic_sequent ~output_type:`Pattern sequent in
313 (match father_hyp with
314 | None -> None, [], Some text
315 | Some hyp_name -> None, [ hyp_name, text ], None)
316 | SelHyp (hyp_name, _ctxt) -> None, [ hyp_name, "%" ], None
318 method private tactic_text_of_node node =
319 let id = id_of_node node in
320 let cic_info, unsh_sequent = self#get_cic_info id in
321 match self#get_term_by_id cic_info id with
322 | SelTerm (t, father_hyp) ->
323 let sequent = self#sequent_of_id ~paste_kind:`Term id in
324 let text = self#string_of_cic_sequent ~output_type:`Term sequent in
326 | SelHyp (hyp_name, _ctxt) -> hyp_name
328 (** @return a pattern structure which contains pretty printed terms *)
329 method private tactic_text_pattern_of_selection =
330 match self#get_selections with
331 | [] -> assert false (* this method is invoked only if there's a sel. *)
332 | node :: _ -> self#tactic_text_pattern_of_node node
334 method private popup_contextual_menu element time =
335 let menu = GMenu.menu () in
336 let add_menu_item ?(menu = menu) ?stock ?label () =
337 GMenu.image_menu_item ?stock ?label ~packing:menu#append () in
338 let check = add_menu_item ~label:"Check" () in
339 let reductions_menu_item = GMenu.menu_item ~label:"βδιζ-reduce" () in
340 let tactics_menu_item = GMenu.menu_item ~label:"Apply tactic" () in
341 let hyperlinks_menu_item = GMenu.menu_item ~label:"Hyperlinks" () in
342 menu#append reductions_menu_item;
343 menu#append tactics_menu_item;
344 menu#append hyperlinks_menu_item;
345 let reductions = GMenu.menu () in
346 let tactics = GMenu.menu () in
347 let hyperlinks = GMenu.menu () in
348 reductions_menu_item#set_submenu reductions;
349 tactics_menu_item#set_submenu tactics;
350 hyperlinks_menu_item#set_submenu hyperlinks;
351 let normalize = add_menu_item ~menu:reductions ~label:"Normalize" () in
352 let simplify = add_menu_item ~menu:reductions ~label:"Simplify" () in
353 let whd = add_menu_item ~menu:reductions ~label:"Weak head" () in
355 | None -> hyperlinks_menu_item#misc#set_sensitive false
357 match hrefs_of_elt elt, href_callback with
361 let item = add_menu_item ~menu:hyperlinks ~label:h () in
362 connect_menu_item item (fun () -> f h)) l
363 | _ -> hyperlinks_menu_item#misc#set_sensitive false);
364 menu#append (GMenu.separator_item ());
365 let copy = add_menu_item ~stock:`COPY () in
366 let gui = get_gui () in
367 List.iter (fun item -> item#misc#set_sensitive gui#canCopy)
368 [ copy; check; normalize; simplify; whd ];
369 let reduction_action kind () =
370 let pat = self#tactic_text_pattern_of_selection in
372 let loc = HExtlib.dummy_floc in
374 GrafiteAstPp.pp_executable ~term_pp:(fun s -> s)
375 ~lazy_term_pp:(fun _ -> assert false) ~obj_pp:(fun _ -> assert false)
376 ~map_unicode_to_tex:(Helm_registry.get_bool
377 "matita.paste_unicode_as_tex")
378 (GrafiteAst.Tactic (loc,
379 Some (GrafiteAst.Reduce (loc, kind, pat)),
380 GrafiteAst.Semicolon loc)) in
381 (MatitaScript.current ())#advance ~statement () in
382 connect_menu_item copy gui#copy;
383 connect_menu_item normalize (reduction_action `Normalize);
384 connect_menu_item simplify (reduction_action `Simpl);
385 connect_menu_item whd (reduction_action `Whd);
386 menu#popup ~button:right_button ~time
388 method private button_release_cb gdk_button =
389 if GdkEvent.Button.button gdk_button = left_button then begin
390 let button_release_x = GdkEvent.Button.x gdk_button in
391 let button_release_y = GdkEvent.Button.y gdk_button in
392 if selection_changed then
394 else (* selection _not_ changed *)
395 if near (button_press_x, button_press_y)
396 (button_release_x, button_release_y)
398 let x = int_of_float button_press_x in
399 let y = int_of_float button_press_y in
400 (match self#get_element_at x y with
403 if has_maction elt then ignore(self#action_toggle elt) else
404 (match hrefs_of_elt elt with
405 | Some hrefs -> self#invoke_href_callback hrefs gdk_button
410 method private invoke_href_callback hrefs gdk_button =
411 let button = GdkEvent.Button.button gdk_button in
412 if button = left_button then
413 let time = GdkEvent.Button.time gdk_button in
414 match href_callback with
420 let menu = GMenu.menu () in
424 GMenu.menu_item ~label:uri ~packing:menu#append () in
425 connect_menu_item menu_item
426 (fun () -> try f uri with Not_found -> assert false))
428 menu#popup ~button ~time)
430 method private choose_selection_cb gdome_elt =
431 let set_selection elt =
432 let misc = self#coerce#misc in
433 self#set_selection (Some elt);
434 misc#add_selection_target ~target:"STRING" Gdk.Atom.primary;
435 ignore (misc#grab_selection Gdk.Atom.primary);
438 if (elt#getAttributeNS ~namespaceURI:helm_ns
439 ~localName:xref_ds)#to_string <> ""
444 (match elt#get_parentNode with
445 | None -> assert false
446 | Some p -> aux (new Gdome.element_of_node p))
447 with GdomeInit.DOMCastException _ -> ()
449 (match gdome_elt with
450 | Some elt when (elt#getAttributeNS ~namespaceURI:xlink_ns
451 ~localName:href_ds)#to_string <> "" ->
453 | Some elt -> aux elt
454 | None -> self#set_selection None);
455 selection_changed <- true
457 method update_font_size = self#set_font_size !current_font_size
459 (** find a term by id from stored CIC infos @return either `Hyp if the id
460 * correspond to an hypothesis or `Term (cic, hyp) if the id correspond to a
461 * term. In the latter case hyp is either None (if the term is a subterm of
462 * the sequent conclusion) or Some hyp_name if the term belongs to an
464 method private get_term_by_id cic_info id =
465 let unsh_item, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, _, _ =
467 let rec find_father_hyp id =
468 if Hashtbl.mem ids_to_hypotheses id
469 then Some (name_of_hypothesis (Hashtbl.find ids_to_hypotheses id))
472 try Hashtbl.find ids_to_father_ids id
473 with Not_found -> assert false in
475 | Some id -> find_father_hyp id
479 let term = Hashtbl.find ids_to_terms id in
480 let father_hyp = find_father_hyp id in
481 SelTerm (term, father_hyp)
484 let hyp = Hashtbl.find ids_to_hypotheses id in
486 match unsh_item with Some seq -> seq | None -> assert false in
487 let context' = MatitaMisc.list_tl_at hyp context in
488 SelHyp (name_of_hypothesis hyp, context')
489 with Not_found -> assert false
491 method private find_obj_conclusion id =
492 match self#cic_info with
494 | Some (_, _, _, _, _, None) -> assert false
495 | Some (_, ids_to_terms, _, ids_to_father_ids, ids_to_inner_types, Some annobj) ->
497 find_root_id annobj id ids_to_father_ids ids_to_terms ids_to_inner_types
499 (try Hashtbl.find ids_to_terms id with Not_found -> assert false)
501 method private string_of_node ~(paste_kind:paste_kind) node =
502 if node#hasAttributeNS ~namespaceURI:helm_ns ~localName:xref_ds
504 match paste_kind with
506 let tactic_text_pattern = self#tactic_text_pattern_of_node node in
507 GrafiteAstPp.pp_tactic_pattern
508 ~term_pp:(fun s -> s) ~lazy_term_pp:(fun _ -> assert false)
509 ~map_unicode_to_tex:(Helm_registry.get_bool
510 "matita.paste_unicode_as_tex")
512 | `Term -> self#tactic_text_of_node node
513 else string_of_dom_node node
515 method private string_of_cic_sequent ~output_type cic_sequent =
516 let script = MatitaScript.current () in
518 if script#onGoingProof () then script#proofMetasenv else [] in
519 let map_unicode_to_tex =
520 Helm_registry.get_bool "matita.paste_unicode_as_tex" in
521 ApplyTransformation.txt_of_cic_sequent_conclusion ~map_unicode_to_tex
522 ~output_type text_width metasenv cic_sequent
524 method private pattern_of term father_hyp unsh_sequent =
525 let _, unsh_context, conclusion = unsh_sequent in
527 match father_hyp with
533 | Some (Cic.Name name', Cic.Decl ty)::_ when name' = name -> ty
534 | Some (Cic.Name name', Cic.Def (bo,_))::_ when name' = name-> bo
539 ProofEngineHelpers.pattern_of ~term:where [term]
541 method private get_cic_info id =
542 match self#cic_info with
543 | Some ((Some unsh_sequent, _, _, _, _, _) as info) -> info, unsh_sequent
544 | Some ((None, _, _, _, _, _) as info) ->
545 let t = self#find_obj_conclusion id in
546 info, (~-1, [], t) (* dummy sequent for obj *)
547 | None -> assert false
549 method private sequent_of_id ~(paste_kind:paste_kind) id =
550 let cic_info, unsh_sequent = self#get_cic_info id in
552 match self#get_term_by_id cic_info id with
553 | SelTerm (t, father_hyp) ->
555 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
558 ProofEngineHelpers.locate_in_conjecture t unsh_sequent in
559 (match occurrences with
561 (match paste_kind with
562 | `Term -> ~-1, context, t
563 | `Pattern -> ~-1, [], self#pattern_of t father_hyp unsh_sequent)
565 HLog.error (sprintf "found %d occurrences while 1 was expected"
566 (List.length occurrences));
567 assert false) (* since it uses physical equality *)
568 | SelHyp (_name, context) -> ~-1, context, Cic.Rel 1 in
571 method private string_of_selection ~(paste_kind:paste_kind) =
572 match self#get_selections with
574 | node :: _ -> Some (self#string_of_node ~paste_kind node)
576 method has_selection = self#get_selections <> []
578 (** @return an associative list format -> string with all possible selection
579 * formats. Rationale: in order to convert the selection to TERM or PATTERN
580 * format we need the sequent, the metasenv, ... keeping all of them in a
581 * closure would be more expensive than keeping their already converted
583 method strings_of_selection =
585 let misc = self#coerce#misc in
587 (fun target -> misc#add_selection_target ~target Gdk.Atom.clipboard)
588 [ "TERM"; "PATTERN"; "STRING" ];
589 ignore (misc#grab_selection Gdk.Atom.clipboard);
592 paste_kind, HExtlib.unopt (self#string_of_selection ~paste_kind))
594 with Failure _ -> failwith "no selection"
600 let clickableMathView ?hadjustment ?vadjustment ?font_size ?log_verbosity =
601 SourceView.make_params [] ~cont:(
602 GtkText.View.make_params ~cont:(
603 GContainer.pack_container ~create:(fun pl ->
604 let obj = SourceView.new_ () in
605 Gobject.set_params (Gobject.try_cast obj "GtkSourceView") pl;
606 new clickableMathView obj)))
608 GtkBase.Widget.size_params
609 ~cont:(OgtkSourceView2Props.pack_return (fun p ->
610 OgtkSourceView2Props.set_params
611 (new clickableMathView (GtkSourceView2Props.MathView_GMetaDOM.create p))
612 ~font_size:None ~log_verbosity:None))
616 class cicMathView obj =
618 inherit clickableMathView obj
620 val mutable current_mathml = None
622 method nload_sequent:
623 'status. #NCicCoercion.status as 'status -> NCic.metasenv ->
624 NCic.substitution -> int -> unit
625 = fun status metasenv subst metano ->
626 let sequent = List.assoc metano metasenv in
628 ApplyTransformation.ntxt_of_cic_sequent
629 ~map_unicode_to_tex:false 80 status metasenv subst (metano,sequent)
631 (* MATITA 1.0 if BuildTimeConf.debug then begin
633 "/tmp/sequent_viewer_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
634 HLog.debug ("load_sequent: dumping MathML to ./" ^ name);
635 ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
637 self#load_root ~root:txt
639 method load_nobject :
640 'status. #NCicCoercion.status as 'status -> NCic.obj -> unit
642 let txt = ApplyTransformation.ntxt_of_cic_object ~map_unicode_to_tex:false
646 (Some (None, ids_to_terms, ids_to_hypotheses, ids_to_father_ids, ids_to_inner_types, Some annobj));
647 (match current_mathml with
648 | Some current_mathml when use_diff ->
650 XmlDiff.update_dom ~from:current_mathml mathml;
654 (* MATITA1.0 if BuildTimeConf.debug then begin
656 "/tmp/cic_browser_" ^ string_of_int (Unix.getuid ()) ^ ".xml" in
657 HLog.debug ("cic_browser: dumping MathML to ./" ^ name);
658 ignore (domImpl#saveDocumentToFile ~name ~doc:mathml ())
660 self#load_root ~root:txt;
661 (*current_mathml <- Some mathml*)(*)*);
664 let tab_label meta_markup =
667 | `Closed m -> sprintf "<s>%s</s>" (aux m)
668 | `Current m -> sprintf "<b>%s</b>" (aux m)
669 | `Shift (pos, m) -> sprintf "|<sub>%d</sub>: %s" pos (aux m)
670 | `Meta n -> sprintf "?%d" n
672 let markup = aux meta_markup in
673 (GMisc.label ~markup ~show:true ())#coerce
675 let goal_of_switch = function Stack.Open g | Stack.Closed g -> g
677 class sequentsViewer ~(notebook:GPack.notebook) ~(cicMathView:cicMathView) () =
679 inherit scriptAccessor
681 method cicMathView = cicMathView (** clickableMathView accessor *)
683 val mutable pages = 0
684 val mutable switch_page_callback = None
685 val mutable page2goal = [] (* associative list: page no -> goal no *)
686 val mutable goal2page = [] (* the other way round *)
687 val mutable goal2win = [] (* associative list: goal no -> scrolled win *)
688 val mutable _metasenv = `Old []
689 val mutable scrolledWin: GBin.scrolled_window option = None
690 (* scrolled window to which the sequentViewer is currently attached *)
691 val logo = (GMisc.image
692 ~file:(MatitaMisc.image_path "matita_medium.png") ()
695 val logo_with_qed = (GMisc.image
696 ~file:(MatitaMisc.image_path "matita_small.png") ()
700 notebook#set_show_tabs false;
701 ignore(notebook#append_page logo)
703 method load_logo_with_qed =
704 notebook#set_show_tabs false;
705 ignore(notebook#append_page logo_with_qed)
708 cicMathView#remove_selections;
709 (match scrolledWin with
711 (* removing page from the notebook will destroy all contained widget,
712 * we do not want the cicMathView to be destroyed as well *)
713 w#remove cicMathView#coerce;
716 (match switch_page_callback with
718 GtkSignal.disconnect notebook#as_widget id;
719 switch_page_callback <- None
721 for i = 0 to pages do notebook#remove_page 0 done;
722 notebook#set_show_tabs true;
727 _metasenv <- `Old [];
728 self#script#setGoal None
730 method nload_sequents : 'status. #NTacStatus.tac_status as 'status -> unit
732 let _,_,metasenv,subst,_ = status#obj in
733 _metasenv <- `New (metasenv,subst);
735 let win goal_switch =
737 GBin.scrolled_window ~hpolicy:`AUTOMATIC ~vpolicy:`ALWAYS
738 ~shadow_type:`IN ~show:true ()
741 scrolledWin <- Some w;
742 match cicMathView#misc#parent with
743 | None -> w#add cicMathView#coerce
746 match cicMathView#misc#parent with
748 | Some p -> GContainer.cast_container p
750 parent#remove cicMathView#coerce;
751 w#add cicMathView#coerce
753 goal2win <- (goal_switch, reparent) :: goal2win;
757 let stack_goals = Stack.open_goals status#stack in
758 let proof_goals = List.map fst metasenv in
760 HExtlib.list_uniq (List.sort Pervasives.compare stack_goals)
761 <> List.sort Pervasives.compare proof_goals
763 prerr_endline ("STACK GOALS = " ^ String.concat " " (List.map string_of_int stack_goals));
764 prerr_endline ("PROOF GOALS = " ^ String.concat " " (List.map string_of_int proof_goals));
770 function Stack.Open i ->`Meta i | Stack.Closed i ->`Closed (`Meta i)
773 let added_goals = ref [] in
774 (* goals can be duplicated on the tack due to focus, but we should avoid
775 * multiple labels in the user interface *)
776 let add_tab markup goal_switch =
777 let goal = Stack.goal_of_switch goal_switch in
778 if not (List.mem goal !added_goals) then begin
779 ignore(notebook#append_page
780 ~tab_label:(tab_label markup) (win goal_switch));
781 page2goal <- (!page, goal_switch) :: page2goal;
782 goal2page <- (goal_switch, !page) :: goal2page;
785 added_goals := goal :: !added_goals
788 let add_switch _ _ (_, sw) = add_tab (render_switch sw) sw in
789 Stack.iter (** populate notebook with tabs *)
790 ~env:(fun depth tag (pos, sw) ->
792 match depth, pos with
793 | 0, 0 -> `Current (render_switch sw)
794 | 0, _ -> `Shift (pos, `Current (render_switch sw))
795 | 1, pos when Stack.head_tag status#stack = `BranchTag ->
796 `Shift (pos, render_switch sw)
797 | _ -> render_switch sw
800 ~cont:add_switch ~todo:add_switch
802 switch_page_callback <-
803 Some (notebook#connect#switch_page ~callback:(fun page ->
805 try List.assoc page page2goal with Not_found -> assert false
807 self#script#setGoal (Some (goal_of_switch goal_switch));
808 self#render_page status ~page ~goal_switch))
810 method private render_page:
811 'status. #NCicCoercion.status as 'status -> page:int ->
812 goal_switch:Stack.switch -> unit
813 = fun status ~page ~goal_switch ->
814 (match goal_switch with
816 (match _metasenv with
817 `Old menv -> assert false (* MATITA 1.0 *)
818 | `New (menv,subst) ->
819 cicMathView#nload_sequent status menv subst goal)
820 | Stack.Closed goal ->
821 let doc = Lazy.force closed_goal_mathml in
822 cicMathView#load_root ~root:doc);
824 cicMathView#set_selection None;
825 List.assoc goal_switch goal2win ()
826 with Not_found -> assert false)
828 method goto_sequent: 'status. #NCicCoercion.status as 'status -> int -> unit
830 let goal_switch, page =
833 (function Stack.Open g, _ | Stack.Closed g, _ -> g = goal)
835 with Not_found -> assert false
837 notebook#goto_page page;
838 self#render_page status ~page ~goal_switch
843 type 'widget constructor =
844 ?hadjustment:GData.adjustment ->
845 ?vadjustment:GData.adjustment ->
847 ?log_verbosity:int ->
849 ?highlight_current_line:bool ->
850 ?indent_on_tab:bool ->
852 ?insert_spaces_instead_of_tabs:bool ->
853 ?right_margin_position:int ->
854 ?show_line_marks:bool ->
855 ?show_line_numbers:bool ->
856 ?show_right_margin:bool ->
857 ?smart_home_end:SourceView2Enums.source_smart_home_end_type ->
860 ?cursor_visible:bool ->
861 ?justification:GtkEnums.justification ->
862 ?wrap_mode:GtkEnums.wrap_mode ->
867 ?packing:(GObj.widget -> unit) ->
868 ?show:bool -> unit ->
871 let cicMathView ?hadjustment ?vadjustment ?font_size ?log_verbosity =
872 SourceView.make_params [] ~cont:(
873 GtkText.View.make_params ~cont:(
874 GContainer.pack_container ~create:(fun pl ->
875 let obj = SourceView.new_ () in
876 Gobject.set_params (Gobject.try_cast obj "GtkSourceView") pl;
877 new cicMathView obj)))
879 GtkBase.Widget.size_params
880 ~cont:(OgtkMathViewProps.pack_return (fun p ->
881 OgtkMathViewProps.set_params
882 (new cicMathView (GtkMathViewProps.MathView_GMetaDOM.create p))
883 ~font_size ~log_verbosity))
887 let blank_uri = BuildTimeConf.blank_uri
888 let current_proof_uri = BuildTimeConf.current_proof_uri
891 [ `Ast of NotationPt.term
892 | `NCic of NCic.term * NCic.context * NCic.metasenv * NCic.substitution
896 class cicBrowser_impl ~(history:MatitaTypes.mathViewer_entry MatitaMisc.history)
901 "^cic:/([^/]+/)*[^/]+\\.(con|ind|var)(#xpointer\\(\\d+(/\\d+)+\\))?$"
903 let dir_RE = Pcre.regexp "^cic:((/([^/]+/)*[^/]+(/)?)|/|)$" in
904 let is_uri txt = Pcre.pmatch ~rex:uri_RE txt in
905 let is_dir txt = Pcre.pmatch ~rex:dir_RE txt in
906 let gui = get_gui () in
907 let (win: MatitaGuiTypes.browserWin) = gui#newBrowserWin () in
908 let gviz = LablGraphviz.graphviz ~packing:win#graphScrolledWin#add () in
910 GSourceView2.source_view ~auto_indent:false ~editable:false ()
913 win#scrolledwinContent#add (searchText :> GObj.widget);
915 let text = win#entrySearch#text in
916 let highlight start end_ =
917 searchText#source_buffer#move_mark `INSERT ~where:start;
918 searchText#source_buffer#move_mark `SEL_BOUND ~where:end_;
919 searchText#scroll_mark_onscreen `INSERT
921 let iter = searchText#source_buffer#get_iter `SEL_BOUND in
922 match iter#forward_search text with
924 (match searchText#source_buffer#start_iter#forward_search text with
926 | Some (start,end_) -> highlight start end_)
927 | Some (start,end_) -> highlight start end_
929 ignore(win#entrySearch#connect#activate ~callback);
930 ignore(win#buttonSearch#connect#clicked ~callback);
932 let toplevel = win#toplevel in
933 let mathView = cicMathView ~packing:win#scrolledBrowser#add () in
935 MatitaGtkMisc.report_error ~title:"Cic browser" ~message
939 [ "dir", GdkPixbuf.from_file (MatitaMisc.image_path "matita-folder.png");
940 "obj", GdkPixbuf.from_file (MatitaMisc.image_path "matita-object.png") ]
942 let b = (not (Helm_registry.get_bool "matita.debug")) in
948 fail (snd (MatitaExcPp.to_string exn))
951 let handle_error' f = (fun () -> handle_error (fun () -> f ())) in
952 let load_easter_egg = lazy (
953 win#browserImage#set_file (MatitaMisc.image_path "meegg.png"))
956 let module Pp = GraphvizPp.Dot in
957 let filename, oc = Filename.open_temp_file "matita" ".dot" in
958 let fmt = Format.formatter_of_out_channel oc in
959 let status = (MatitaScript.current ())#grafite_status in
963 ~graph_attrs:["overlap", "false"]
964 ~node_attrs:["fontsize", "9"; "width", ".4";
965 "height", ".4"; "shape", "box"]
966 ~edge_attrs:["fontsize", "10"; "len", "2"] fmt;
967 NCicUnifHint.generate_dot_file status fmt;
971 gviz#load_graph_from_file ~gviz_cmd:"neato -Tpng" filename;
972 (*HExtlib.safe_remove filename*)
974 let load_coerchgraph tred () =
975 let module Pp = GraphvizPp.Dot in
976 let filename, oc = Filename.open_temp_file "matita" ".dot" in
977 let fmt = Format.formatter_of_out_channel oc in
980 ~node_attrs:["fontsize", "9"; "width", ".4"; "height", ".4"]
981 ~edge_attrs:["fontsize", "10"] fmt;
982 let status = (MatitaScript.current ())#grafite_status in
983 NCicCoercion.generate_dot_file status fmt;
988 gviz#load_graph_from_file
989 ~gviz_cmd:"dot -Txdot | tred |gvpack -gv | dot" filename
991 gviz#load_graph_from_file
992 ~gviz_cmd:"dot -Txdot | gvpack -gv | dot" filename;
993 HExtlib.safe_remove filename
996 inherit scriptAccessor
998 val mutable gviz_uri = UriManager.uri_of_string "cic:/dummy.con";
1000 val dep_contextual_menu = GMenu.menu ()
1003 win#mathOrListNotebook#set_show_tabs false;
1004 win#browserForwardButton#misc#set_sensitive false;
1005 win#browserBackButton#misc#set_sensitive false;
1006 ignore (win#browserUri#connect#activate (handle_error' (fun () ->
1007 self#loadInput win#browserUri#text)));
1008 ignore (win#browserHomeButton#connect#clicked (handle_error' (fun () ->
1009 self#load (`About `Current_proof))));
1010 ignore (win#browserRefreshButton#connect#clicked
1011 (handle_error' (self#refresh ~force:true)));
1012 ignore (win#browserBackButton#connect#clicked (handle_error' self#back));
1013 ignore (win#browserForwardButton#connect#clicked
1014 (handle_error' self#forward));
1015 ignore (win#toplevel#event#connect#delete (fun _ ->
1016 let my_id = Oo.id self in
1017 cicBrowsers := List.filter (fun b -> Oo.id b <> my_id) !cicBrowsers;
1019 ignore(win#whelpResultTreeview#connect#row_activated
1020 ~callback:(fun _ _ ->
1021 handle_error (fun () -> self#loadInput (self#_getSelectedUri ()))));
1022 mathView#set_href_callback (Some (fun uri ->
1023 handle_error (fun () ->
1026 `Uri (UriManager.uri_of_string uri)
1028 UriManager.IllFormedUri _ ->
1029 `NRef (NReference.reference_of_string uri)
1032 gviz#connect_href (fun button_ev attrs ->
1033 let time = GdkEvent.Button.time button_ev in
1034 let uri = List.assoc "href" attrs in
1035 gviz_uri <- UriManager.uri_of_string uri;
1036 match GdkEvent.Button.button button_ev with
1037 | button when button = left_button -> self#load (`Uri gviz_uri)
1038 | button when button = right_button ->
1039 dep_contextual_menu#popup ~button ~time
1041 connect_menu_item win#browserCloseMenuItem (fun () ->
1042 let my_id = Oo.id self in
1043 cicBrowsers := List.filter (fun b -> Oo.id b <> my_id) !cicBrowsers;
1044 win#toplevel#misc#hide(); win#toplevel#destroy ());
1047 connect_menu_item win#hBugsTutorsMenuItem (fun () ->
1048 self#load (`HBugs `Tutors));
1050 win#hBugsTutorsMenuItem#misc#hide ();
1051 connect_menu_item win#browserUrlMenuItem (fun () ->
1052 win#browserUri#misc#grab_focus ());
1053 connect_menu_item win#univMenuItem (fun () ->
1054 match self#currentCicUri with
1055 | Some uri -> self#load (`Univs uri)
1058 self#_load (`About `Blank);
1061 val mutable current_entry = `About `Blank
1063 (** @return None if no object uri can be built from the current entry *)
1064 method private currentCicUri =
1065 match current_entry with
1066 | `Uri uri -> Some uri
1070 new MatitaGtkMisc.taggedStringListModel tags win#whelpResultTreeview
1072 new MatitaGtkMisc.multiStringListModel ~cols:2 win#universesTreeview
1074 val mutable lastDir = "" (* last loaded "directory" *)
1076 method mathView = (mathView :> MatitaGuiTypes.clickableMathView)
1078 method private _getSelectedUri () =
1079 match model#easy_selection () with
1080 | [sel] when is_uri sel -> sel (* absolute URI selected *)
1081 (* | [sel] -> win#browserUri#entry#text ^ sel |+ relative URI selected +| *)
1082 | [sel] -> lastDir ^ sel
1085 (** history RATIONALE
1087 * All operations about history are done using _historyFoo.
1088 * Only toplevel functions (ATM load and loadInput) call _historyAdd.
1091 method private _historyAdd item =
1093 win#browserBackButton#misc#set_sensitive true;
1094 win#browserForwardButton#misc#set_sensitive false
1096 method private _historyPrev () =
1097 let item = history#previous in
1098 if history#is_begin then win#browserBackButton#misc#set_sensitive false;
1099 win#browserForwardButton#misc#set_sensitive true;
1102 method private _historyNext () =
1103 let item = history#next in
1104 if history#is_end then win#browserForwardButton#misc#set_sensitive false;
1105 win#browserBackButton#misc#set_sensitive true;
1108 (** notebook RATIONALE
1110 * Use only these functions to switch between the tabs
1112 method private _showMath = win#mathOrListNotebook#goto_page 0
1113 method private _showList = win#mathOrListNotebook#goto_page 1
1114 method private _showList2 = win#mathOrListNotebook#goto_page 5
1115 method private _showSearch = win#mathOrListNotebook#goto_page 6
1116 method private _showGviz = win#mathOrListNotebook#goto_page 3
1117 method private _showHBugs = win#mathOrListNotebook#goto_page 4
1119 method private back () =
1121 self#_load (self#_historyPrev ())
1122 with MatitaMisc.History_failure -> ()
1124 method private forward () =
1126 self#_load (self#_historyNext ())
1127 with MatitaMisc.History_failure -> ()
1129 (* loads a uri which can be a cic uri or an about:* uri
1130 * @param uri string *)
1131 method private _load ?(force=false) entry =
1132 handle_error (fun () ->
1133 if entry <> current_entry || entry = `About `Current_proof || entry =
1134 `About `Coercions || entry = `About `CoercionsFull || force then
1137 | `About `Current_proof -> self#home ()
1138 | `About `Blank -> self#blank ()
1139 | `About `Us -> self#egg ()
1140 | `About `CoercionsFull -> self#coerchgraph false ()
1141 | `About `Coercions -> self#coerchgraph true ()
1142 | `About `Hints -> self#hints ()
1143 | `About `TeX -> self#tex ()
1144 | `About `Grammar -> self#grammar ()
1145 | `Check term -> self#_loadCheck term
1146 | `NCic (term, ctx, metasenv, subst) ->
1147 self#_loadTermNCic term metasenv subst ctx
1148 | `Dir dir -> self#_loadDir dir
1149 | `HBugs `Tutors -> self#_loadHBugsTutors
1150 | `Uri uri -> assert false (* MATITA 1.0 *)
1151 | `NRef nref -> self#_loadNReference nref
1152 | `Univs uri -> assert false (* MATITA 1.0 *));
1156 method private blank () =
1158 mathView#load_root ""
1160 method private _loadCheck term =
1161 failwith "not implemented _loadCheck";
1162 (* self#_showMath *)
1164 method private egg () =
1165 win#mathOrListNotebook#goto_page 2;
1166 Lazy.force load_easter_egg
1168 method private redraw_gviz ?center_on () =
1169 if Sys.command "which dot" = 0 then
1170 let tmpfile, oc = Filename.open_temp_file "matita" ".dot" in
1171 let fmt = Format.formatter_of_out_channel oc in
1172 (* MATITA 1.0 MetadataDeps.DepGraph.render fmt gviz_graph;*)
1174 gviz#load_graph_from_file ~gviz_cmd:"tred | dot" tmpfile;
1175 (match center_on with
1177 | Some uri -> gviz#center_on_href (UriManager.string_of_uri uri));
1178 HExtlib.safe_remove tmpfile
1180 MatitaGtkMisc.report_error ~title:"graphviz error"
1181 ~message:("Graphviz is not installed but is necessary to render "^
1182 "the graph of dependencies amoung objects. Please install it.")
1183 ~parent:win#toplevel ()
1185 method private dependencies direction uri () =
1186 assert false (* MATITA 1.0
1187 let dbd = LibraryDb.instance () in
1189 match direction with
1190 | `Fwd -> MetadataDeps.DepGraph.direct_deps ~dbd uri
1191 | `Back -> MetadataDeps.DepGraph.inverse_deps ~dbd uri in
1192 gviz_graph <- graph; (** XXX check this for memory consuption *)
1193 self#redraw_gviz ~center_on:uri ();
1196 method private coerchgraph tred () =
1197 load_coerchgraph tred ();
1200 method private hints () =
1204 method private tex () =
1205 let b = Buffer.create 1000 in
1206 Printf.bprintf b "UTF-8 equivalence classes (rotate with ALT-L):\n\n";
1209 List.iter (fun sym ->
1210 Printf.bprintf b " %s" (Glib.Utf8.from_unichar sym)
1212 Printf.bprintf b "\n";
1215 (fun l1 l2 -> compare (List.hd l1) (List.hd l2))
1216 (Virtuals.get_all_eqclass ()));
1217 Printf.bprintf b "\n\nVirtual keys (trigger with ALT-L):\n\n";
1220 Printf.bprintf b " %s:\n" tag;
1222 (fun names, symbol ->
1223 Printf.bprintf b " \t%s\t%s\n"
1224 (Glib.Utf8.from_unichar symbol)
1225 (String.concat ", " names))
1227 (fun (_,a) (_,b) -> compare a b)
1229 Printf.bprintf b "\n")
1231 (fun (a,_) (b,_) -> compare a b)
1232 (Virtuals.get_all_virtuals ()));
1233 self#_loadText (Buffer.contents b)
1235 method private _loadText text =
1236 searchText#source_buffer#set_text text;
1237 win#entrySearch#misc#grab_focus ();
1240 method private grammar () =
1241 self#_loadText (Print_grammar.ebnf_of_term ());
1243 method private home () =
1245 match self#script#grafite_status#ng_mode with
1247 self#_loadNObj self#script#grafite_status
1248 self#script#grafite_status#obj
1249 | _ -> self#blank ()
1251 method private _loadNReference (NReference.Ref (uri,_)) =
1252 let obj = NCicEnvironment.get_checked_obj uri in
1253 self#_loadNObj self#script#grafite_status obj
1255 method private _loadDir dir =
1256 let content = Http_getter.ls ~local:false dir in
1262 | Http_getter_types.Ls_section s -> "dir", s
1263 | Http_getter_types.Ls_object o -> "obj", o.Http_getter_types.uri)
1269 method private _loadHBugsTutors =
1272 method private setEntry entry =
1273 win#browserUri#set_text (MatitaTypes.string_of_entry entry);
1274 current_entry <- entry
1276 method private _loadNObj status obj =
1277 (* showMath must be done _before_ loading the document, since if the
1278 * widget is not mapped (hidden by the notebook) the document is not
1281 mathView#load_nobject status obj
1283 method private _loadTermNCic term m s c =
1285 let m = (0,([],c,term))::m in
1286 let status = (MatitaScript.current ())#grafite_status in
1287 mathView#nload_sequent status m s d;
1290 method private _loadList l =
1291 model#list_store#clear ();
1292 List.iter (fun (tag, s) -> model#easy_append ~tag s) l;
1295 method private _loadList2 l =
1296 model_univs#list_store#clear ();
1297 List.iter model_univs#easy_mappend l;
1300 (** { public methods, all must call _load!! } *)
1303 handle_error (fun () -> self#_load entry; self#_historyAdd entry)
1305 (** this is what the browser does when you enter a string an hit enter *)
1306 method loadInput txt =
1307 let txt = HExtlib.trim_blanks txt in
1308 (* (* ZACK: what the heck? *)
1310 UriManager.string_of_uri
1311 (UriManager.strip_xpointer (UriManager.uri_of_string txt))
1316 | txt when is_uri txt ->
1317 `Uri (UriManager.uri_of_string ((*fix_uri*) txt))
1318 | txt when is_dir txt -> `Dir (MatitaMisc.normalize_dir txt)
1321 MatitaTypes.entry_of_string txt
1322 with Invalid_argument _ ->
1324 (GrafiteTypes.Command_error(sprintf "unsupported uri: %s" txt)))
1327 self#_historyAdd entry
1329 (** {2 methods accessing underlying GtkMathView} *)
1331 method updateFontSize = mathView#set_font_size !current_font_size
1333 (** {2 methods used by constructor only} *)
1336 method history = history
1337 method currentEntry = current_entry
1338 method refresh ~force () = self#_load ~force current_entry
1342 let sequentsViewer ~(notebook:GPack.notebook) ~(cicMathView:cicMathView) ():
1343 MatitaGuiTypes.sequentsViewer
1345 new sequentsViewer ~notebook ~cicMathView ()
1348 let size = BuildTimeConf.browser_history_size in
1349 let rec aux history =
1350 let browser = new cicBrowser_impl ~history () in
1351 let win = browser#win in
1352 ignore (win#browserNewButton#connect#clicked (fun () ->
1354 new MatitaMisc.browser_history ~memento:history#save size
1357 let newBrowser = aux history in
1358 newBrowser#load browser#currentEntry));
1360 (* attempt (failed) to close windows on CTRL-W ... *)
1361 MatitaGtkMisc.connect_key win#browserWinEventBox#event ~modifiers:[`CONTROL]
1362 GdkKeysyms._W (fun () -> win#toplevel#destroy ());
1364 cicBrowsers := browser :: !cicBrowsers;
1365 (browser :> MatitaGuiTypes.cicBrowser)
1367 let history = new MatitaMisc.browser_history size (`About `Blank) in
1370 let default_cicMathView () = cicMathView ~show:true ()
1371 let cicMathView_instance = MatitaMisc.singleton default_cicMathView
1373 let default_sequentsViewer () =
1374 let gui = get_gui () in
1375 let cicMathView = cicMathView_instance () in
1376 sequentsViewer ~notebook:gui#main#sequentsNotebook ~cicMathView ()
1377 let sequentsViewer_instance = MatitaMisc.singleton default_sequentsViewer
1381 method private get_browser reuse =
1383 (match !cicBrowsers with
1384 | [] -> cicBrowser ()
1385 | b :: _ -> (b :> MatitaGuiTypes.cicBrowser))
1389 method show_entry ?(reuse=false) t = (self#get_browser reuse)#load t
1391 method show_uri_list ?(reuse=false) ~entry l =
1392 (self#get_browser reuse)#load entry
1394 method screenshot status sequents metasenv subst (filename as ofn) =
1396 let w = GWindow.window ~title:"screenshot" () in
1398 let height = 2000 in
1399 let m = GMathView.math_view
1400 ~font_size:!current_font_size ~width ~height
1407 (fun (mno,_ as sequent) i ->
1409 ApplyTransformation.nmml_of_cic_sequent
1410 status metasenv subst sequent
1412 m#load_root ~root:mathml#get_documentElement;
1413 let pixmap = m#get_buffer in
1414 let pixbuf = GdkPixbuf.create ~width ~height () in
1415 GdkPixbuf.get_from_drawable ~dest:pixbuf pixmap;
1417 filename ^ "-raw" ^ string_of_int i ^ ".png"
1419 GdkPixbuf.save ~filename ~typ:"png" pixbuf;
1424 List.map (fun (x,mno) ->
1428 " '(' -gravity west -bordercolor grey -border 1 label:%d ')' "^^
1429 " '(' -trim -bordercolor white -border 5 "^^
1430 " -bordercolor grey -border 1 %s ')' -append %s ")
1433 (Filename.quote (x ^ ".label.png"))));
1437 let rec div2 = function
1440 | x::y::tl -> [x;y] :: div2 tl
1442 let items = div2 items in
1443 ignore(Sys.command (Printf.sprintf
1444 "convert %s -append %s"
1446 (List.map (fun items ->
1447 Printf.sprintf " '(' %s +append ')' "
1449 (" '(' -gravity center -size 10x10 xc: ')' ") items)) items))
1450 (Filename.quote (ofn ^ ".png"))));
1451 List.iter (fun x,_ -> Sys.remove x) filenames;
1452 List.iter Sys.remove (List.flatten items);
1457 let refresh_all_browsers () =
1458 List.iter (fun b -> b#refresh ~force:false ()) !cicBrowsers
1460 let update_font_sizes () =
1461 List.iter (fun b -> b#updateFontSize) !cicBrowsers;
1462 (cicMathView_instance ())#update_font_size
1464 let get_math_views () =
1465 ((cicMathView_instance ()) :> MatitaGuiTypes.clickableMathView)
1466 :: (List.map (fun b -> b#mathView) !cicBrowsers)
1468 let find_selection_owner () =
1471 | [] -> raise Not_found
1473 (match mv#get_selections with
1477 aux (get_math_views ())
1479 let has_selection () =
1480 try ignore (find_selection_owner ()); true
1481 with Not_found -> false
1483 let math_view_clipboard = ref None (* associative list target -> string *)
1484 let has_clipboard () = !math_view_clipboard <> None
1485 let empty_clipboard () = math_view_clipboard := None
1487 let copy_selection () =
1489 math_view_clipboard :=
1490 Some ((find_selection_owner ())#strings_of_selection)
1491 with Not_found -> failwith "no selection"
1493 let paste_clipboard paste_kind =
1494 match !math_view_clipboard with
1495 | None -> failwith "empty clipboard"
1497 (try List.assoc paste_kind cb with Not_found -> assert false)