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