1 (******************************************************************************)
2 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
5 (* This is a simple test for the OCaml (LablGtk indeed) binding of the *)
7 (******************************************************************************)
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"
20 let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
21 let module O = Ominidom in
22 print_string ("selection_changed: " ^
24 None -> "selection_changed on nothing"
26 match node#get_name with
27 | Some x -> x#get_string
28 | None -> "on element without name"
30 mathview#set_selection node;
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
46 let activate_t1 mathview () =
47 mathview#set_font_manager_type `font_manager_t1;
48 print_string "WIDGET SET WITH T1 FONTS\n" ;
52 let activate_gtk mathview () =
53 mathview#set_font_manager_type `font_manager_gtk;
54 print_string "WIDGET SET WITH GTK FONTS\n" ;
58 let get_font_manager_type mathview () =
59 print_string "CURRENT FONT MANAGER TYPE: ";
61 match mathview#get_font_manager_type with
62 | `font_manager_t1 -> print_string "T1"
63 | `font_manager_gtk -> print_string "GTK"
69 let load mathview () =
70 mathview#load "test.xml" ;
71 print_string "load: SEEMS TO WORK\n" ;
75 let get_selection mathview () =
76 let module O = Ominidom in
78 match mathview#get_selection with
81 match node#get_name with
82 | Some name -> name#get_string
83 | None -> "element with no name!"
85 | None -> "no selection!"
87 print_string ("get_selection: " ^ selection ^ "\n") ;
91 let set_selection mathview () =
92 let module O = Ominidom in
94 match mathview#get_selection with
98 let parent_node = node#get_parent in
99 mathview#set_selection (Some parent_node);
100 print_string "set selection: SEEMS TO WORK\n"
102 _ -> print_string "EXCEPTION: no parent\n"
105 mathview#set_selection None;
106 print_string "no selection\n"
111 let unload mathview () =
113 print_string "unload: SEEMS TO WORK\n" ;
117 let get_width mathview () =
118 print_string ("get_width: " ^ string_of_int (mathview#get_width) ^ "\n") ;
122 let get_height mathview () =
123 print_string ("get_height: " ^ string_of_int (mathview#get_height) ^ "\n") ;
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") ;
133 let set_top mathview () =
134 mathview#set_top 0 0;
135 print_string "set_top: SEEM TO WORK\n" ;
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" ;
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" ;
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" ;
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";
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" ;
178 let set_font_size mathview () =
179 mathview#set_font_size 24 ;
180 print_string "set_font_size: FONT IS NOW 24\n" ;
184 let get_font_size mathview () =
185 print_string ("get_font_size: " ^ string_of_int (mathview#get_font_size) ^ "\n") ;
189 let set_anti_aliasing mathview () =
190 mathview#set_anti_aliasing true ;
191 print_string "set_anti_aliasing: ON\n" ;
195 let get_anti_aliasing mathview () =
196 print_string ("get_anti_aliasing: " ^
197 (match mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
202 let set_kerning mathview () =
203 mathview#set_kerning true ;
204 print_string "set_kerning: ON\n" ;
208 let get_kerning mathview () =
209 print_string ("get_kerning: " ^
210 (match mathview#get_kerning with true -> "ON" | false -> "OFF") ^
215 let set_log_verbosity mathview () =
216 mathview#set_log_verbosity 3 ;
217 print_string "set_log_verbosity: NOW IS 3\n" ;
221 let get_log_verbosity mathview () =
222 print_string ("get_log_verbosity: " ^
223 string_of_int mathview#get_log_verbosity ^
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";
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)) ;
295 main_window#show () ;