]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtkmathview/gMathView.ml
Initial revision
[helm.git] / helm / DEVEL / lablgtkmathview / gMathView.ml
1 (* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
2  *
3  * This file is part of lablgtkmathview, the Ocaml binding
4  * for the GtkMathView widget.
5  * 
6  * lablgtkmathview is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * lablgtkmathview is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with lablgtkmathview; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  * 
20  * For details, send a mail to the author.
21  *)
22
23 open Gaux
24 open Gtk
25 open Gtk_mathview
26 open GtkBase
27 open GtkMathView
28 open GObj
29
30 exception ErrorLoadingFile of string;;
31 exception ErrorWritingFile of string;;
32 exception ErrorLoadingDOM;;
33 exception NoSelection;;
34
35 class math_view_signals obj = object
36   inherit GContainer.container_signals obj
37   method clicked =
38    let module S = GtkSignal in
39     let new_clicked =
40      let new_marshaller f x y =
41       MathView.Signals.clicked.S.marshaller
42        (fun e -> f (new Gdome.element e)) x y
43      in
44       { S.name = "clicked"; S.classe = `math_view;
45         S.marshaller = new_marshaller }
46     in
47      GtkSignal.connect ~sgn:new_clicked obj ~after
48   method selection_changed =
49    let module S = GtkSignal in
50     let new_selection_changed =
51      let new_marshaller f x y =
52       MathView.Signals.selection_changed.S.marshaller
53        (function None -> f None | Some e -> f (Some (new Gdome.element e))) x y
54      in
55       { S.name = "selection_changed"; S.classe = `math_view;
56         S.marshaller = new_marshaller }
57     in
58      GtkSignal.connect ~sgn:new_selection_changed obj ~after
59   method element_changed =
60    let module S = GtkSignal in
61     let new_element_changed =
62      let new_marshaller f x y =
63       MathView.Signals.element_changed.S.marshaller
64        (function None -> f None | Some e -> f (Some (new Gdome.element e))) x y
65      in
66       { S.name = "element_changed"; S.classe = `math_view;
67         S.marshaller = new_marshaller }
68     in
69      GtkSignal.connect ~sgn:new_element_changed obj ~after
70 end
71
72 class math_view obj = object
73  inherit GContainer.container (obj : Gtk_mathview.math_view obj)
74  method connect = new math_view_signals obj
75  method load ~filename =
76   if not (MathView.load obj ~filename) then raise (ErrorLoadingFile filename)
77  method load_tree ~dom =
78   if not (MathView.load_tree obj ~dom:((dom : Gdome.document)#as_Document)) then
79    raise ErrorLoadingDOM
80  method unload = MathView.unload obj
81  method get_selection =
82   match MathView.get_selection obj with
83      None -> None
84    | Some element -> Some (new Gdome.element element)
85  method set_selection element =
86   let element =
87    match element with
88       None -> None
89     | Some element -> Some ((element : Gdome.element)#as_Element)
90   in
91    MathView.set_selection obj element
92  method get_width = MathView.get_width obj
93  method get_height = MathView.get_height obj
94  method get_top = MathView.get_top obj
95  method set_top = MathView.set_top obj
96  method set_adjustments =
97   fun adj1 adj2 ->
98    MathView.set_adjustments obj (GData.as_adjustment adj1)
99    (GData.as_adjustment adj2)
100  method get_hadjustment = new GData.adjustment (MathView.get_hadjustment obj)
101  method get_vadjustment = new GData.adjustment (MathView.get_vadjustment obj)
102  method get_buffer = MathView.get_buffer obj
103  method get_frame = new GBin.frame (MathView.get_frame obj)
104  method set_font_size = MathView.set_font_size obj
105  method get_font_size = MathView.get_font_size obj
106  method set_anti_aliasing = MathView.set_anti_aliasing obj
107  method get_anti_aliasing = MathView.get_anti_aliasing obj
108  method set_kerning = MathView.set_kerning obj
109  method get_kerning = MathView.get_kerning obj
110  method set_transparency = MathView.set_transparency obj
111  method get_transparency = MathView.get_transparency obj
112  method set_log_verbosity = MathView.set_log_verbosity obj
113  method get_log_verbosity = MathView.get_log_verbosity obj
114  method export_to_postscript
115         ?(width = 595) ?(height = 822) ?(x_margin = 72) ?(y_margin = 72)
116         ?(disable_colors = false) ~filename () =
117   let result = MathView.export_to_postscript obj
118         ~width ~height ~x_margin ~y_margin ~disable_colors ~filename
119   in
120   if not result then raise (ErrorWritingFile filename)
121  method get_font_manager_type = MathView.get_font_manager_type obj
122  method set_font_manager_type ~fm_type = MathView.set_font_manager_type obj ~fm_type
123  method get_element =
124   match MathView.get_element obj with
125      None -> None
126    | Some element -> Some (new Gdome.element element)
127  method action_get_selected = MathView.action_get_selected obj
128  method action_set_selected = MathView.action_set_selected obj
129  method get_action =
130   match MathView.get_action obj with
131      None -> None
132    | Some ac -> Some (new Gdome.element ac)
133  method action_toggle = MathView.action_toggle obj
134 end
135
136 let math_view ?adjustmenth ?adjustmentv ?font_size ?font_manager ?border_width
137  ?width ?height ?packing ?show () =
138  let w =
139    MathView.create
140     ?adjustmenth:(may_map ~f:GData.as_adjustment adjustmenth)
141     ?adjustmentv:(may_map ~f:GData.as_adjustment adjustmentv)
142     ()
143  in
144   Container.set w ?border_width ?width ?height;
145  let mathview = pack_return (new math_view w) ~packing ~show in
146  begin
147     match font_size with
148     | Some size -> mathview#set_font_size size
149     | None      -> ()
150   end;
151   begin
152     match font_manager with
153     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
154     | None         -> ()
155   end;
156   mathview
157 ;;