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: " ^
14 let href = node#get_attribute (O.o_mDOMString_of_string "href") in
17 O.Minidom_exception s -> "EXCEPTION: " ^ s
22 let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
23 let module O = Ominidom in
24 print_string ("selection_changed: " ^
26 None -> "selection_changed on nothing"
29 mathview#set_selection node ;
30 let node_name = node#get_name in
33 O.Minidom_exception s -> "EXCEPTION: " ^ s
39 let clicked (node : Ominidom.o_mDOMNode) =
40 let module O = Ominidom in
41 print_string ("clicked: " ^
43 let node_name = node#get_name in
46 O.Minidom_exception s -> "EXCEPTION: " ^ s
52 let activate_t1 mathview () =
53 mathview#set_font_manager_type GtkMathView.MathView.FontManagerT1;
54 print_string "WIDGET SET WITH T1 FONTS\n" ;
58 let activate_gtk mathview () =
59 mathview#set_font_manager_type GtkMathView.MathView.FontManagerGtk;
60 print_string "WIDGET SET WITH GTK FONTS\n" ;
64 let get_font_manager_type mathview () =
65 print_string "CURRENT FONT MANAGER TYPE: ";
67 match mathview#get_font_manager_type with
68 | GtkMathView.MathView.FontManagerT1 -> print_string "T1"
69 | GtkMathView.MathView.FontManagerGtk -> print_string "GTK"
75 let load mathview () =
76 mathview#load "test.xml" ;
77 print_string "load: SEEMS TO WORK\n" ;
81 let get_selection mathview () =
82 let module O = Ominidom in
84 if not mathview#has_selection then "nothing"
86 let node = mathview#get_selection in
87 (try node#get_name#get_string
89 O.Minidom_exception s -> "EXCEPTION: " ^ s
92 print_string ("get_selection: " ^ selection ^ "\n") ;
96 let set_selection mathview () =
97 let module O = Ominidom in
100 let selected_node = mathview#get_selection in
102 let parent_node = selected_node#get_parent in
103 mathview#set_selection parent_node;
104 print_string "set selection: SEEMS TO WORK\n"
106 O.Minidom_exception s ->
107 print_string ("EXCEPTION: " ^ s ^ "\n")
109 GtkMathView.MathView.NoSelection ->
110 print_string "set_selection: YOU MUST PREVIOUSLY SELECT A NON-ROOT NODE\n"
115 let reset_selection mathview () =
116 mathview#reset_selection ;
117 print_string "reset_selection: SEEMS TO WORK\n" ;
121 let unload mathview () =
123 print_string "unload: SEEMS TO WORK\n" ;
127 let get_width mathview () =
128 print_string ("get_width: " ^ string_of_int (mathview#get_width) ^ "\n") ;
132 let get_height mathview () =
133 print_string ("get_height: " ^ string_of_int (mathview#get_height) ^ "\n") ;
137 let get_top mathview () =
138 let (x,y) = mathview#get_top in
139 print_string ("get_top: ("^ string_of_int x ^ "," ^ string_of_int y ^ ")\n") ;
143 let set_top mathview () =
144 mathview#set_top 0 0;
145 print_string "set_top: SEEM TO WORK\n" ;
149 let set_adjustments mathview () =
150 let adj1 = GData.adjustment () in
151 let adj2 = GData.adjustment () in
152 mathview#set_adjustments adj1 adj2 ;
153 adj1#set_value ((adj1#lower +. adj1#upper) /. 2.0) ;
154 adj2#set_value ((adj2#lower +. adj2#upper) /. 2.0) ;
155 print_string "set_adjustments: SEEM TO WORK\n" ;
159 let get_hadjustment mathview () =
160 let adj = mathview#get_hadjustment in
161 adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
162 print_string "get_hadjustment: SEEM TO WORK\n" ;
166 let get_vadjustment mathview () =
167 let adj = mathview#get_vadjustment in
168 adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
169 print_string "get_vadjustment: SEEM TO WORK\n" ;
173 let get_buffer mathview () =
174 let buffer = mathview#get_buffer in
175 Gdk.Draw.rectangle buffer (Gdk.GC.create buffer) ~x:0 ~y:0
176 ~width:50 ~height:50 ~filled:true () ;
177 print_string "get_buffer: SEEMS TO WORK (hint: force the widget redrawing)\n";
181 let get_frame mathview () =
182 let frame = mathview#get_frame in
183 frame#set_shadow_type `NONE ;
184 print_string "get_frame: SEEMS TO WORK\n" ;
188 let set_font_size mathview () =
189 mathview#set_font_size 24 ;
190 print_string "set_font_size: FONT IS NOW 24\n" ;
194 let get_font_size mathview () =
195 print_string ("get_font_size: " ^ string_of_int (mathview#get_font_size) ^ "\n") ;
199 let set_anti_aliasing mathview () =
200 mathview#set_anti_aliasing true ;
201 print_string "set_anti_aliasing: ON\n" ;
205 let get_anti_aliasing mathview () =
206 print_string ("get_anti_aliasing: " ^
207 (match mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
212 let set_kerning mathview () =
213 mathview#set_kerning true ;
214 print_string "set_kerning: ON\n" ;
218 let get_kerning mathview () =
219 print_string ("get_kerning: " ^
220 (match mathview#get_kerning with true -> "ON" | false -> "OFF") ^
225 let set_log_verbosity mathview () =
226 mathview#set_log_verbosity 3 ;
227 print_string "set_log_verbosity: NOW IS 3\n" ;
231 let get_log_verbosity mathview () =
232 print_string ("get_log_verbosity: " ^
233 string_of_int mathview#get_log_verbosity ^
238 let export_to_postscript mathview () =
239 mathview#export_to_postscript 595 822 72 72 false "test.ps" ;
240 print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n";
244 (* Widget creation *)
245 let main_window = GWindow.window ~title:"GtkMathView test" () in
246 let vbox = GPack.vbox ~packing:main_window#add () in
247 let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in
248 let mathview= GMathView.math_view ~packing:sw#add ~width:50 ~height:50 () in
249 let table = GPack.table ~rows:6 ~columns:5 ~packing:vbox#pack () in
250 let button_gtk=GButton.button ~label:"activate Gtk fonts" ~packing:(table#attach ~left:0 ~top:0) () in
251 let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in
252 let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in
253 let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in
254 let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in
255 let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in
256 let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in
257 let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in
258 let button_set_top = GButton.button ~label:"set_top" ~packing:(table#attach ~left:3 ~top:1) () in
259 let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:(table#attach ~left:4 ~top:1) () in
260 let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:(table#attach ~left:0 ~top:2) () in
261 let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:(table#attach ~left:1 ~top:2) () in
262 let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:(table#attach ~left:2 ~top:2) () in
263 let button_get_frame = GButton.button ~label:"get_frame" ~packing:(table#attach ~left:3 ~top:2) () in
264 let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table#attach ~left:4 ~top:2) () in
265 let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in
266 let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in
267 let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in
268 let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in
269 let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in
270 let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in
271 let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in
272 let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in
273 let button_t1 = GButton.button ~label:"activate T1 fonts" ~packing:(table#attach ~left:3 ~top:4) () in
274 let button_get_font_manager_type = GButton.button ~label:"get_font_manager" ~packing:(table#attach ~left:4 ~top:4) () in
275 let button_reset_selection = GButton.button ~label:"reset_selection" ~packing:(table#attach ~left:0 ~top:5) () in
276 (* Signals connection *)
277 ignore(button_gtk#connect#clicked (activate_gtk mathview)) ;
278 ignore(button_load#connect#clicked (load mathview)) ;
279 ignore(button_unload#connect#clicked (unload mathview)) ;
280 ignore(button_get_selection#connect#clicked (get_selection mathview)) ;
281 ignore(button_set_selection#connect#clicked (set_selection mathview)) ;
282 ignore(button_reset_selection#connect#clicked (reset_selection mathview)) ;
283 ignore(button_get_width#connect#clicked (get_width mathview)) ;
284 ignore(button_get_height#connect#clicked (get_height mathview)) ;
285 ignore(button_get_top#connect#clicked (get_top mathview)) ;
286 ignore(button_set_top#connect#clicked (set_top mathview)) ;
287 ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ;
288 ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ;
289 ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ;
290 ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ;
291 ignore(button_get_frame#connect#clicked (get_frame mathview)) ;
292 ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ;
293 ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ;
294 ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ;
295 ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ;
296 ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ;
297 ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ;
298 ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ;
299 ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ;
300 ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ;
301 ignore(button_t1#connect#clicked (activate_t1 mathview)) ;
302 ignore(button_get_font_manager_type#connect#clicked (get_font_manager_type mathview)) ;
303 ignore(mathview#connect#jump jump) ;
304 ignore(mathview#connect#clicked clicked) ;
305 ignore(mathview#connect#selection_changed (selection_changed mathview)) ;
307 main_window#show () ;