1 (* Copyright (C) 2000-2003, Luca Padovani <luca.padovani@cs.unibo.it>,
2 * Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>.
4 * This file is part of lablgtkmathview, the Ocaml binding
5 * for the GtkMathView widget.
7 * lablgtkmathview 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 * lablgtkmathview 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 lablgtkmathview; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 * For details, send a mail to the author.
31 exception ErrorLoadingFile of string;;
32 exception ErrorWritingFile of string;;
33 exception ErrorLoadingDOM;;
34 exception NoSelection;;
36 let option_element_of_option =
39 | Some v -> Some (new Gdome.element v)
41 class math_view_signals obj = object
42 inherit GContainer.container_signals obj
44 let module S = GtkSignal in
46 let new_marshaller f x y =
47 MathView.Signals.click.S.marshaller
48 (fun e s -> f (option_element_of_option e) s) x y
50 { S.name = "click"; S.classe = `math_view;
51 S.marshaller = new_marshaller }
53 GtkSignal.connect ~sgn:new_click obj ~after
55 let module S = GtkSignal in
56 let new_select_begin =
57 let new_marshaller f x y =
58 MathView.Signals.select_begin.S.marshaller
59 (fun e s -> f (option_element_of_option e) s) x y
61 { S.name = "select_begin"; S.classe = `math_view;
62 S.marshaller = new_marshaller }
64 GtkSignal.connect ~sgn:new_select_begin obj ~after
66 let module S = GtkSignal in
68 let new_marshaller f x y =
69 MathView.Signals.select_over.S.marshaller
70 (fun e s -> f (option_element_of_option e) s) x y
72 { S.name = "select_over"; S.classe = `math_view;
73 S.marshaller = new_marshaller }
75 GtkSignal.connect ~sgn:new_select_over obj ~after
77 let module S = GtkSignal in
79 let new_marshaller f x y =
80 MathView.Signals.select_end.S.marshaller
81 (fun e s -> f (option_element_of_option e) s) x y
83 { S.name = "select_end"; S.classe = `math_view;
84 S.marshaller = new_marshaller }
86 GtkSignal.connect ~sgn:new_select_end obj ~after
88 let module S = GtkSignal in
89 let new_select_abort =
90 let new_marshaller f x y =
91 MathView.Signals.select_abort.S.marshaller
94 { S.name = "select_abort"; S.classe = `math_view;
95 S.marshaller = new_marshaller }
97 GtkSignal.connect ~sgn:new_select_abort obj ~after
99 let module S = GtkSignal in
100 let new_element_over =
101 let new_marshaller f x y =
102 MathView.Signals.element_over.S.marshaller
103 (fun e s -> f (option_element_of_option e) s) x y
105 { S.name = "element_over"; S.classe = `math_view;
106 S.marshaller = new_marshaller }
108 GtkSignal.connect ~sgn:new_element_over obj ~after
111 class math_view_skel obj = object
112 inherit GContainer.container (obj : Gtk_mathview.math_view obj)
113 method freeze = MathView.freeze obj
114 method thaw = MathView.thaw obj
115 method load_uri ~filename =
116 if not (MathView.load_uri obj ~filename) then raise (ErrorLoadingFile filename)
117 method load_doc ~dom =
118 if not (MathView.load_doc obj ~dom:((dom : Gdome.document)#as_Document)) then
119 raise ErrorLoadingDOM
120 method unload = MathView.unload obj
121 method select element = MathView.select obj ((element : Gdome.element)#as_Element)
122 method unselect element = MathView.unselect obj ((element : Gdome.element)#as_Element)
123 method is_selected element = MathView.is_selected obj ((element : Gdome.element)#as_Element)
124 method get_element_at x y = option_element_of_option (MathView.get_element_at obj x y)
125 method get_width = MathView.get_width obj
126 method get_height = MathView.get_height obj
127 method get_top = MathView.get_top obj
128 method set_top = MathView.set_top obj
129 method set_adjustments =
131 MathView.set_adjustments obj (GData.as_adjustment adj1)
132 (GData.as_adjustment adj2)
133 method get_hadjustment = new GData.adjustment (MathView.get_hadjustment obj)
134 method get_vadjustment = new GData.adjustment (MathView.get_vadjustment obj)
135 method get_buffer = MathView.get_buffer obj
136 method get_frame = new GBin.frame (MathView.get_frame obj)
137 method get_drawing_area = new GMisc.drawing_area (MathView.get_drawing_area obj)
138 method set_font_size = MathView.set_font_size obj
139 method get_font_size = MathView.get_font_size obj
140 method set_anti_aliasing = MathView.set_anti_aliasing obj
141 method get_anti_aliasing = MathView.get_anti_aliasing obj
142 method set_transparency = MathView.set_transparency obj
143 method get_transparency = MathView.get_transparency obj
144 method set_log_verbosity = MathView.set_log_verbosity obj
145 method get_log_verbosity = MathView.get_log_verbosity obj
146 method export_to_postscript
147 ?(width = 595) ?(height = 822) ?(x_margin = 72) ?(y_margin = 72)
148 ?(disable_colors = false) ~filename () =
149 let result = MathView.export_to_postscript obj
150 ~width ~height ~x_margin ~y_margin ~disable_colors ~filename
152 if not result then raise (ErrorWritingFile filename)
153 method get_font_manager_type = MathView.get_font_manager_type obj
154 method set_font_manager_type ~fm_type = MathView.set_font_manager_type obj ~fm_type
157 class math_view obj = object
158 inherit math_view_skel (obj : Gtk_mathview.math_view obj)
159 method connect = new math_view_signals obj
162 let math_view ?adjustmenth ?adjustmentv ?font_size ?font_manager ?border_width
163 ?width ?height ?packing ?show () =
166 ?adjustmenth:(may_map ~f:GData.as_adjustment adjustmenth)
167 ?adjustmentv:(may_map ~f:GData.as_adjustment adjustmentv)
170 Container.set w ?border_width ?width ?height;
171 let mathview = pack_return (new math_view w) ~packing ~show in
174 | Some size -> mathview#set_font_size size
178 match font_manager with
179 | Some manager -> mathview#set_font_manager_type ~fm_type:manager