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