]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtkmathview/gMathView.ml
updated the binding so that it works well with lablgtk-1.00,
[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 open Misc
30
31 exception ErrorLoadingFile of string;;
32 exception ErrorWritingFile of string;;
33 exception NoSelection;;
34
35 class math_view_signals obj = object
36   inherit GContainer.container_signals obj
37   method clicked = GtkSignal.connect ~sgn:MathView.Signals.clicked obj ~after
38   method jump = GtkSignal.connect ~sgn:MathView.Signals.jump obj ~after
39   method selection_changed =
40   GtkSignal.connect ~sgn:MathView.Signals.selection_changed obj ~after
41 end
42
43 class math_view obj = object
44  inherit GContainer.container (obj : Gtk_mathview.math_view obj)
45  method connect = new math_view_signals obj
46  method load ~filename =
47   if not (MathView.load obj ~filename) then raise (ErrorLoadingFile filename)
48  method unload = MathView.unload obj
49  method get_selection = MathView.get_selection obj
50  method set_selection (node : Ominidom.o_mDOMNode option) = MathView.set_selection obj node
51  method get_width = MathView.get_width obj
52  method get_height = MathView.get_height obj
53  method get_top = MathView.get_top obj
54  method set_top = MathView.set_top obj
55  method set_adjustments =
56   fun adj1 adj2 ->
57    MathView.set_adjustments obj (GData.as_adjustment adj1)
58    (GData.as_adjustment adj2)
59  method get_hadjustment = new GData.adjustment (MathView.get_hadjustment obj)
60  method get_vadjustment = new GData.adjustment (MathView.get_vadjustment obj)
61  method get_buffer = MathView.get_buffer obj
62  method get_frame = new GFrame.frame (MathView.get_frame obj)
63  method set_font_size = MathView.set_font_size obj
64  method get_font_size = MathView.get_font_size obj
65  method set_anti_aliasing = MathView.set_anti_aliasing obj
66  method get_anti_aliasing = MathView.get_anti_aliasing obj
67  method set_kerning = MathView.set_kerning obj
68  method get_kerning = MathView.get_kerning obj
69  method set_log_verbosity = MathView.set_log_verbosity obj
70  method get_log_verbosity = MathView.get_log_verbosity obj
71  method export_to_postscript
72         ?(width = 595) ?(height = 822) ?(x_margin = 72) ?(y_margin = 72)
73         ?(disable_colors = false) ~filename () =
74   let result = MathView.export_to_postscript obj
75         ~width ~height ~x_margin ~y_margin ~disable_colors ~filename
76   in
77   if not result then raise (ErrorWritingFile filename)
78  method get_font_manager_type = MathView.get_font_manager_type obj
79  method set_font_manager_type ~fm_type = MathView.set_font_manager_type obj ~fm_type
80 end
81
82 let math_view ?adjustmenth ?adjustmentv ?font_size ?font_manager ?border_width
83  ?width ?height ?packing ?show () =
84  let w =
85    MathView.create
86     ?adjustmenth:(may_map ~f:GData.as_adjustment adjustmenth)
87     ?adjustmentv:(may_map ~f:GData.as_adjustment adjustmentv)
88     ()
89  in
90   Container.set w ?border_width ?width ?height;
91  let mathview = pack_return (new math_view w) ~packing ~show in
92  begin
93     match font_size with
94     | Some size -> mathview#set_font_size size
95     | None      -> ()
96   end;
97   begin
98     match font_manager with
99     | Some manager -> mathview#set_font_manager_type ~fm_type:manager
100     | None         -> ()
101   end;
102   mathview
103 ;;