]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.2.0/test/test.ml
Test improved
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20000829_gtkmathview-0.2.0 / 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 =
11  let module M = Minidom in
12   print_string ("jump: " ^
13    (match
14      M.node_get_attribute_ns node
15       (M.mDOMString_of_string "xlink")
16       (M.mDOMString_of_string "href")
17     with
18        None   -> "DOES NOT WORKS (if you have clicked on the hyperlink)!!!!!" 
19      | Some s -> M.string_of_mDOMString s
20    ) ^ "\n");
21   print_string ("jump: " ^
22    (match
23      M.node_get_attribute node
24       (M.mDOMString_of_string "href")
25     with
26        None   -> "DOES NOT WORKS (if you have clicked on the hyperlink)!!!!!" 
27      | Some s -> M.string_of_mDOMString s
28    ) ^ "\n");
29   flush stdout
30 ;;
31
32 let selection_changed node =
33  let module M = Minidom in
34   print_string ("selection_changed: " ^
35    (match M.node_get_name node with
36        None   -> "selection_changed on nothing" 
37      | Some s -> "selection changed on " ^ M.string_of_mDOMString s
38    ) ^ "\n");
39   flush stdout
40 ;;
41
42
43 let clicked node =
44  let module M = Minidom in
45   print_string ("clicked: " ^
46    (match M.node_get_name node with
47        None   -> "Nothing clicked (???)" 
48      | Some s -> M.string_of_mDOMString s ^ " clicked"
49    ) ^ "\n");
50   flush stdout
51 ;;
52
53
54 let activate_t1 mathview sw () =
55  sw#remove !mathview#coerce ;
56  mathview :=
57  (GMathView.math_view ~packing:sw#add ~width:50 ~height:50
58   ~use_t1_lib:true ()) ;
59  ignore(!mathview#connect#jump jump) ;
60  ignore(!mathview#connect#clicked clicked) ;
61  ignore(!mathview#connect#selection_changed selection_changed) ;
62  print_string "WIDGET RECREATED WITH T1 FONTS ACTIVATED\n" ;
63 ;;
64
65 let load mathview () =
66  !mathview#load "test.xml" ;
67  print_string "load: SEEMS TO WORK\n" ;
68  flush stdout
69 ;;
70
71 let get_selection mathview () =
72  let selection =
73 (*  match !mathview#get_selection with
74      None -> "NO SELECTION"
75    | Some node ->
76 *) let node = !mathview#get_selection in
77       match Minidom.node_get_name node with
78         None   -> "selection is on nothing" 
79       | Some s -> "selection is on " ^ Minidom.string_of_mDOMString s
80  in
81   print_string ("get_selection: " ^ selection ^ "\n") ;
82   flush stdout
83 ;;
84
85 let set_selection mathview () =
86  begin
87   try
88 (*   match !mathview#get_selection with
89       None -> raise Not_found
90     | Some node ->
91 *) let node = !mathview#get_selection in
92        match Minidom.node_get_parent node with
93           None -> raise Not_found
94         | Some node ->
95            !mathview#set_selection node ;
96            print_string "set_selection: SEEMS TO WORK\n"
97   with
98    Not_found ->
99     print_string "set_selection: YOU MUST PREVIOUSLY SELECT A NON-ROOT NODE" 
100  end ;
101  flush stdout
102 ;;
103
104 let unload mathview () =
105  !mathview#unload ;
106  print_string "unload: SEEMS TO WORK\n" ;
107  flush stdout
108 ;;
109
110 let get_width mathview () =
111  print_string ("get_width: " ^ string_of_int (!mathview#get_width) ^ "\n") ;
112  flush stdout
113 ;;
114
115 let get_height mathview () =
116  print_string ("get_height: " ^ string_of_int (!mathview#get_height) ^ "\n") ;
117  flush stdout
118 ;;
119
120 let get_top mathview () =
121  let (x,y) = !mathview#get_top in
122   print_string ("get_top: ("^ string_of_int x ^ "," ^ string_of_int y ^ ")\n") ;
123   flush stdout
124 ;;
125
126 let set_top mathview () =
127  !mathview#set_top 0 0;
128  print_string "set_top: SEEM TO WORK\n" ;
129  flush stdout
130 ;;
131
132 let set_adjustments mathview () =
133  let adj1 = GData.adjustment () in
134  let adj2 = GData.adjustment () in
135   !mathview#set_adjustments adj1 adj2 ;
136   adj1#set_value ((adj1#lower +. adj1#upper) /. 2.0) ;
137   adj2#set_value ((adj2#lower +. adj2#upper) /. 2.0) ;
138   print_string "set_adjustments: SEEM TO WORK\n" ;
139   flush stdout
140 ;;
141
142 let get_hadjustment mathview () =
143  let adj = !mathview#get_hadjustment in
144   adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
145   print_string "get_hadjustment: SEEM TO WORK\n" ;
146   flush stdout
147 ;;
148
149 let get_vadjustment mathview () =
150  let adj = !mathview#get_vadjustment in
151   adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
152   print_string "get_vadjustment: SEEM TO WORK\n" ;
153   flush stdout
154 ;;
155
156 let get_buffer mathview () =
157  let buffer = !mathview#get_buffer in
158   Gdk.Draw.rectangle buffer (Gdk.GC.create buffer) ~x:0 ~y:0
159    ~width:50 ~height:50 ~filled:true () ;
160   print_string "get_buffer: SEEMS TO WORK (hint: force the widget redrawing)\n";
161   flush stdout
162 ;;
163
164 let get_frame mathview () =
165  let frame = !mathview#get_frame in
166   frame#set_shadow_type `NONE ;
167   print_string "get_frame: SEEMS TO WORK\n" ;
168   flush stdout
169 ;;
170
171 let set_font_size mathview () =
172  !mathview#set_font_size 24 ;
173  print_string "set_font_size: FONT IS NOW 24\n" ;
174  flush stdout
175 ;;
176  
177 let get_font_size mathview () =
178  print_string ("get_font_size: " ^ string_of_int (!mathview#get_font_size) ^ "\n") ;
179  flush stdout
180 ;;
181  
182 let set_anti_aliasing mathview () =
183  !mathview#set_anti_aliasing true ;
184  print_string "set_anti_aliasing: ON\n" ;
185  flush stdout
186 ;;
187  
188 let get_anti_aliasing mathview () =
189  print_string ("get_anti_aliasing: " ^
190   (match !mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
191   "\n") ;
192  flush stdout
193 ;;
194  
195 let set_kerning mathview () =
196  !mathview#set_kerning true ;
197  print_string "set_kerning: ON\n" ;
198  flush stdout
199 ;;
200  
201 let get_kerning mathview () =
202  print_string ("get_kerning: " ^
203   (match !mathview#get_kerning with true -> "ON" | false -> "OFF") ^
204   "\n") ;
205  flush stdout
206 ;;
207
208 let set_log_verbosity mathview () =
209  !mathview#set_log_verbosity 3 ;
210  print_string "set_log_verbosity: NOW IS 3\n" ;
211  flush stdout
212 ;;
213  
214 let get_log_verbosity mathview () =
215  print_string ("get_log_verbosity: " ^
216   string_of_int !mathview#get_log_verbosity ^
217   "\n") ;
218  flush stdout
219 ;;
220
221 let export_to_postscript mathview () =
222  !mathview#export_to_postscript "test.ps" ;
223  print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n";
224  flush stdout
225 ;;
226  
227 (* Widget creation *)
228 let main_window = GWindow.window ~title:"GtkMathView test" () in
229 let vbox = GPack.vbox ~packing:main_window#add () in
230 let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in
231 let mathview= ref (GMathView.math_view ~packing:sw#add ~width:50 ~height:50 ()) in
232 let table = GPack.table ~rows:5 ~columns:5 ~packing:vbox#pack () in
233 let button_t1=GButton.button ~label:"activate t1 fonts" ~packing:(table#attach ~left:0 ~top:0) () in
234 let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in
235 let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in
236 let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in
237 let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in
238 let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in
239 let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in
240 let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in
241 let button_set_top = GButton.button ~label:"set_top" ~packing:(table#attach ~left:3 ~top:1) () in
242 let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:(table#attach ~left:4 ~top:1) () in
243 let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:(table#attach ~left:0 ~top:2) () in
244 let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:(table#attach ~left:1 ~top:2) () in
245 let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:(table#attach ~left:2 ~top:2) () in
246 let button_get_frame = GButton.button ~label:"get_frame" ~packing:(table#attach ~left:3 ~top:2) () in
247 let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table#attach ~left:4 ~top:2) () in
248 let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in
249 let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in
250 let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in
251 let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in
252 let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in
253 let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in
254 let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in
255 let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in
256 (* Signals connection *)
257 ignore(button_t1#connect#clicked (activate_t1 mathview sw)) ;
258 ignore(button_load#connect#clicked (load mathview)) ;
259 ignore(button_unload#connect#clicked (unload mathview)) ;
260 ignore(button_get_selection#connect#clicked (get_selection mathview)) ;
261 ignore(button_set_selection#connect#clicked (set_selection mathview)) ;
262 ignore(button_get_width#connect#clicked (get_width mathview)) ;
263 ignore(button_get_height#connect#clicked (get_height mathview)) ;
264 ignore(button_get_top#connect#clicked (get_top mathview)) ;
265 ignore(button_set_top#connect#clicked (set_top mathview)) ;
266 ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ;
267 ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ;
268 ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ;
269 ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ;
270 ignore(button_get_frame#connect#clicked (get_frame mathview)) ;
271 ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ;
272 ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ;
273 ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ;
274 ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ;
275 ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ;
276 ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ;
277 ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ;
278 ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ;
279 ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ;
280 ignore(!mathview#connect#jump jump) ;
281 ignore(!mathview#connect#clicked clicked) ;
282 ignore(!mathview#connect#selection_changed selection_changed) ;
283 (* Main Loop *)
284 main_window#show () ;
285 GMain.Main.main ()
286 ;;