]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.1/test/test.ml
This commit was manufactured by cvs2svn to create branch 'start'.
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20000829_gtkmathview-0.2.1 / test / test.ml
1 (******************************************************************************)
2 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
3 (*                                 25/09/2000                                 *)
4 (*                                                                            *)
5 (*     This is a simple test for the OCaml (LablGtk indeed) binding of the    *)
6 (*                             MathView widget                                *)
7 (******************************************************************************)
8
9 (* Callbacks *)
10 let jump (node : Ominidom.o_mDOMNode) =
11  let module O = Ominidom in
12   print_string ("jump: " ^
13    (try 
14       let href = node#get_attribute (O.o_mDOMString_of_string "href") in
15       href#get_string
16     with
17       O.Minidom_exception s -> "EXCEPTION: " ^ s
18    ) ^ "\n");
19   flush stdout
20 ;;
21
22 let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
23  let module O = Ominidom in
24   print_string ("selection_changed: " ^
25    (match node with
26        None -> "selection_changed on nothing"
27      | Some node ->
28         try
29           mathview#set_selection node ;
30           let node_name = node#get_name in
31           node_name#get_string
32         with
33           O.Minidom_exception s -> "EXCEPTION: " ^ s
34    ) ^ "\n");
35   flush stdout
36 ;;
37
38
39 let clicked (node : Ominidom.o_mDOMNode) =
40  let module O = Ominidom in
41   print_string ("clicked: " ^
42    (try
43       let node_name = node#get_name in
44       node_name#get_string
45     with
46       O.Minidom_exception s -> "EXCEPTION: " ^ s
47    ) ^ "\n");
48   flush stdout
49 ;;
50
51
52 let activate_t1 mathview () =
53  mathview#set_font_manager_type GtkMathView.MathView.FontManagerT1;
54  print_string "WIDGET SET WITH T1 FONTS\n" ;
55  flush stdout
56 ;;
57
58 let activate_gtk mathview () =
59  mathview#set_font_manager_type GtkMathView.MathView.FontManagerGtk;
60  print_string "WIDGET SET WITH GTK FONTS\n" ;
61  flush stdout
62 ;;
63
64 let get_font_manager_type mathview () =
65  print_string "CURRENT FONT MANAGER TYPE: ";
66  begin
67   match mathview#get_font_manager_type with
68   | GtkMathView.MathView.FontManagerT1 -> print_string "T1"
69   | GtkMathView.MathView.FontManagerGtk -> print_string "GTK"
70  end;
71  print_newline();
72  flush stdout
73 ;;
74
75 let load mathview () =
76  mathview#load "test.xml" ;
77  print_string "load: SEEMS TO WORK\n" ;
78  flush stdout
79 ;;
80
81 let get_selection mathview () =
82  let module O = Ominidom in
83   let selection =
84    if not mathview#has_selection then "nothing"
85    else
86      let node = mathview#get_selection in
87      (try node#get_name#get_string
88       with
89         O.Minidom_exception s -> "EXCEPTION: " ^ s
90      ) 
91   in
92    print_string ("get_selection: " ^ selection ^ "\n") ;
93    flush stdout
94 ;;
95
96 let set_selection mathview () =
97  let module O = Ominidom in
98   begin
99    try
100     let selected_node = mathview#get_selection in
101     try
102       let parent_node = selected_node#get_parent in
103       mathview#set_selection parent_node;
104       print_string "set selection: SEEMS TO WORK\n"
105     with
106       O.Minidom_exception s ->
107         print_string ("EXCEPTION: " ^ s ^ "\n")
108    with
109     GtkMathView.MathView.NoSelection ->
110      print_string "set_selection: YOU MUST PREVIOUSLY SELECT A NON-ROOT NODE\n" 
111   end ;
112   flush stdout
113 ;;
114
115 let reset_selection mathview () =
116  mathview#reset_selection ;
117  print_string "reset_selection: SEEMS TO WORK\n" ;
118  flush stdout
119 ;;
120
121 let unload mathview () =
122  mathview#unload ;
123  print_string "unload: SEEMS TO WORK\n" ;
124  flush stdout
125 ;;
126
127 let get_width mathview () =
128  print_string ("get_width: " ^ string_of_int (mathview#get_width) ^ "\n") ;
129  flush stdout
130 ;;
131
132 let get_height mathview () =
133  print_string ("get_height: " ^ string_of_int (mathview#get_height) ^ "\n") ;
134  flush stdout
135 ;;
136
137 let get_top mathview () =
138  let (x,y) = mathview#get_top in
139   print_string ("get_top: ("^ string_of_int x ^ "," ^ string_of_int y ^ ")\n") ;
140   flush stdout
141 ;;
142
143 let set_top mathview () =
144  mathview#set_top 0 0;
145  print_string "set_top: SEEM TO WORK\n" ;
146  flush stdout
147 ;;
148
149 let set_adjustments mathview () =
150  let adj1 = GData.adjustment () in
151  let adj2 = GData.adjustment () in
152   mathview#set_adjustments adj1 adj2 ;
153   adj1#set_value ((adj1#lower +. adj1#upper) /. 2.0) ;
154   adj2#set_value ((adj2#lower +. adj2#upper) /. 2.0) ;
155   print_string "set_adjustments: SEEM TO WORK\n" ;
156   flush stdout
157 ;;
158
159 let get_hadjustment mathview () =
160  let adj = mathview#get_hadjustment in
161   adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
162   print_string "get_hadjustment: SEEM TO WORK\n" ;
163   flush stdout
164 ;;
165
166 let get_vadjustment mathview () =
167  let adj = mathview#get_vadjustment in
168   adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
169   print_string "get_vadjustment: SEEM TO WORK\n" ;
170   flush stdout
171 ;;
172
173 let get_buffer mathview () =
174  let buffer = mathview#get_buffer in
175   Gdk.Draw.rectangle buffer (Gdk.GC.create buffer) ~x:0 ~y:0
176    ~width:50 ~height:50 ~filled:true () ;
177   print_string "get_buffer: SEEMS TO WORK (hint: force the widget redrawing)\n";
178   flush stdout
179 ;;
180
181 let get_frame mathview () =
182  let frame = mathview#get_frame in
183   frame#set_shadow_type `NONE ;
184   print_string "get_frame: SEEMS TO WORK\n" ;
185   flush stdout
186 ;;
187
188 let set_font_size mathview () =
189  mathview#set_font_size 24 ;
190  print_string "set_font_size: FONT IS NOW 24\n" ;
191  flush stdout
192 ;;
193  
194 let get_font_size mathview () =
195  print_string ("get_font_size: " ^ string_of_int (mathview#get_font_size) ^ "\n") ;
196  flush stdout
197 ;;
198  
199 let set_anti_aliasing mathview () =
200  mathview#set_anti_aliasing true ;
201  print_string "set_anti_aliasing: ON\n" ;
202  flush stdout
203 ;;
204  
205 let get_anti_aliasing mathview () =
206  print_string ("get_anti_aliasing: " ^
207   (match mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
208   "\n") ;
209  flush stdout
210 ;;
211  
212 let set_kerning mathview () =
213  mathview#set_kerning true ;
214  print_string "set_kerning: ON\n" ;
215  flush stdout
216 ;;
217  
218 let get_kerning mathview () =
219  print_string ("get_kerning: " ^
220   (match mathview#get_kerning with true -> "ON" | false -> "OFF") ^
221   "\n") ;
222  flush stdout
223 ;;
224
225 let set_log_verbosity mathview () =
226  mathview#set_log_verbosity 3 ;
227  print_string "set_log_verbosity: NOW IS 3\n" ;
228  flush stdout
229 ;;
230  
231 let get_log_verbosity mathview () =
232  print_string ("get_log_verbosity: " ^
233   string_of_int mathview#get_log_verbosity ^
234   "\n") ;
235  flush stdout
236 ;;
237
238 let export_to_postscript mathview () =
239  mathview#export_to_postscript 595 822 72 72 false "test.ps" ;
240  print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n";
241  flush stdout
242 ;;
243  
244 (* Widget creation *)
245 let main_window = GWindow.window ~title:"GtkMathView test" () in
246 let vbox = GPack.vbox ~packing:main_window#add () in
247 let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in
248 let mathview= GMathView.math_view ~packing:sw#add ~width:50 ~height:50 () in
249 let table = GPack.table ~rows:6 ~columns:5 ~packing:vbox#pack () in
250 let button_gtk=GButton.button ~label:"activate Gtk fonts" ~packing:(table#attach ~left:0 ~top:0) () in
251 let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in
252 let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in
253 let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in
254 let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in
255 let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in
256 let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in
257 let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in
258 let button_set_top = GButton.button ~label:"set_top" ~packing:(table#attach ~left:3 ~top:1) () in
259 let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:(table#attach ~left:4 ~top:1) () in
260 let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:(table#attach ~left:0 ~top:2) () in
261 let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:(table#attach ~left:1 ~top:2) () in
262 let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:(table#attach ~left:2 ~top:2) () in
263 let button_get_frame = GButton.button ~label:"get_frame" ~packing:(table#attach ~left:3 ~top:2) () in
264 let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table#attach ~left:4 ~top:2) () in
265 let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in
266 let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in
267 let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in
268 let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in
269 let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in
270 let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in
271 let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in
272 let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in
273 let button_t1 = GButton.button ~label:"activate T1 fonts" ~packing:(table#attach ~left:3 ~top:4) () in
274 let button_get_font_manager_type = GButton.button ~label:"get_font_manager" ~packing:(table#attach ~left:4 ~top:4) () in
275 let button_reset_selection = GButton.button ~label:"reset_selection" ~packing:(table#attach ~left:0 ~top:5) () in
276 (* Signals connection *)
277 ignore(button_gtk#connect#clicked (activate_gtk mathview)) ;
278 ignore(button_load#connect#clicked (load mathview)) ;
279 ignore(button_unload#connect#clicked (unload mathview)) ;
280 ignore(button_get_selection#connect#clicked (get_selection mathview)) ;
281 ignore(button_set_selection#connect#clicked (set_selection mathview)) ;
282 ignore(button_reset_selection#connect#clicked (reset_selection mathview)) ;
283 ignore(button_get_width#connect#clicked (get_width mathview)) ;
284 ignore(button_get_height#connect#clicked (get_height mathview)) ;
285 ignore(button_get_top#connect#clicked (get_top mathview)) ;
286 ignore(button_set_top#connect#clicked (set_top mathview)) ;
287 ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ;
288 ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ;
289 ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ;
290 ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ;
291 ignore(button_get_frame#connect#clicked (get_frame mathview)) ;
292 ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ;
293 ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ;
294 ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ;
295 ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ;
296 ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ;
297 ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ;
298 ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ;
299 ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ;
300 ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ;
301 ignore(button_t1#connect#clicked (activate_t1 mathview)) ;
302 ignore(button_get_font_manager_type#connect#clicked (get_font_manager_type mathview)) ;
303 ignore(mathview#connect#jump jump) ;
304 ignore(mathview#connect#clicked clicked) ;
305 ignore(mathview#connect#selection_changed (selection_changed mathview)) ;
306 (* Main Loop *)
307 main_window#show () ;
308 GMain.Main.main ()
309 ;;