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