1 (* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
3 * This file is part of lablgtkmathview, the Ocaml binding
4 * for the GtkMathView widget.
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.
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.
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.
20 * For details, send a mail to the author.
30 exception ErrorLoadingFile of string;;
31 exception ErrorWritingFile of string;;
32 exception ErrorLoadingDOM;;
33 exception NoSelection;;
35 class math_view_signals obj = object
36 inherit GContainer.container_signals obj
38 let module S = GtkSignal in
40 let new_marshaller f x y =
41 MathView.Signals.clicked.S.marshaller
42 (fun e -> f (new Gdome.element e)) x y
44 { S.name = "clicked"; S.marshaller = new_marshaller }
46 GtkSignal.connect ~sgn:new_clicked obj ~after
47 method selection_changed =
48 let module S = GtkSignal in
49 let new_selection_changed =
50 let new_marshaller f x y =
51 MathView.Signals.selection_changed.S.marshaller
52 (function None -> f None | Some e -> f (Some (new Gdome.element e))) x y
54 { S.name = "selection_changed"; S.marshaller = new_marshaller }
56 GtkSignal.connect ~sgn:new_selection_changed obj ~after
57 method element_changed =
58 let module S = GtkSignal in
59 let new_element_changed =
60 let new_marshaller f x y =
61 MathView.Signals.element_changed.S.marshaller
62 (function None -> f None | Some e -> f (Some (new Gdome.element e))) x y
64 { S.name = "element_changed"; S.marshaller = new_marshaller }
66 GtkSignal.connect ~sgn:new_element_changed obj ~after
69 class math_view obj = object
70 inherit GContainer.container (obj : Gtk_mathview.math_view obj)
71 method connect = new math_view_signals obj
72 method load ~filename =
73 if not (MathView.load obj ~filename) then raise (ErrorLoadingFile filename)
74 method load_tree ~dom =
75 if not (MathView.load_tree obj ~dom:((dom : Gdome.document)#as_Document)) then
77 method unload = MathView.unload obj
78 method get_selection =
79 match MathView.get_selection obj with
81 | Some element -> Some (new Gdome.element element)
82 method set_selection element =
86 | Some element -> Some ((element : Gdome.element)#as_Element)
88 MathView.set_selection obj element
89 method get_width = MathView.get_width obj
90 method get_height = MathView.get_height obj
91 method get_top = MathView.get_top obj
92 method set_top = MathView.set_top obj
93 method set_adjustments =
95 MathView.set_adjustments obj (GData.as_adjustment adj1)
96 (GData.as_adjustment adj2)
97 method get_hadjustment = new GData.adjustment (MathView.get_hadjustment obj)
98 method get_vadjustment = new GData.adjustment (MathView.get_vadjustment obj)
99 method get_buffer = MathView.get_buffer obj
100 method get_frame = new GBin.frame (MathView.get_frame obj)
101 method set_font_size = MathView.set_font_size obj
102 method get_font_size = MathView.get_font_size obj
103 method set_anti_aliasing = MathView.set_anti_aliasing obj
104 method get_anti_aliasing = MathView.get_anti_aliasing obj
105 method set_kerning = MathView.set_kerning obj
106 method get_kerning = MathView.get_kerning obj
107 method set_transparency = MathView.set_transparency obj
108 method get_transparency = MathView.get_transparency obj
109 method set_log_verbosity = MathView.set_log_verbosity obj
110 method get_log_verbosity = MathView.get_log_verbosity obj
111 method export_to_postscript
112 ?(width = 595) ?(height = 822) ?(x_margin = 72) ?(y_margin = 72)
113 ?(disable_colors = false) ~filename () =
114 let result = MathView.export_to_postscript obj
115 ~width ~height ~x_margin ~y_margin ~disable_colors ~filename
117 if not result then raise (ErrorWritingFile filename)
118 method get_font_manager_type = MathView.get_font_manager_type obj
119 method set_font_manager_type ~fm_type = MathView.set_font_manager_type obj ~fm_type
121 match MathView.get_element obj with
123 | Some element -> Some (new Gdome.element element)
124 method action_get_selected = MathView.action_get_selected obj
125 method action_set_selected = MathView.action_set_selected obj
127 match MathView.get_action obj with
129 | Some ac -> Some (new Gdome.element ac)
130 method action_toggle = MathView.action_toggle obj
133 let math_view ?adjustmenth ?adjustmentv ?font_size ?font_manager ?border_width
134 ?width ?height ?packing ?show () =
137 ?adjustmenth:(may_map ~f:GData.as_adjustment adjustmenth)
138 ?adjustmentv:(may_map ~f:GData.as_adjustment adjustmentv)
141 Container.set w ?border_width ?width ?height;
142 let mathview = pack_return (new math_view w) ~packing ~show in
145 | Some size -> mathview#set_font_size size
149 match font_manager with
150 | Some manager -> mathview#set_font_manager_type ~fm_type:manager