1 (******************************************************************************)
2 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
5 (* This is a simple test for the OCaml (LablGtk indeed) binding of the *)
7 (******************************************************************************)
11 let module M = Minidom in
12 print_string ("jump: " ^
14 M.node_get_attribute node
15 (M.mDOMString_of_string "href")
17 None -> "DOES NOT WORKS (if you have clicked on the hyperlink)!!!!!"
18 | Some s -> M.string_of_mDOMString s
23 let selection_changed node =
24 let module M = Minidom in
25 print_string ("selection_changed: " ^
27 None -> "selection_changed on nothing"
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
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"
48 let activate_t1 mathview sw () =
49 sw#remove !mathview#coerce ;
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" ;
59 let load mathview () =
60 !mathview#load "test.xml" ;
61 print_string "load: SEEMS TO WORK\n" ;
65 let get_selection mathview () =
67 match !mathview#get_selection with
68 None -> "NO SELECTION"
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
74 print_string ("get_selection: " ^ selection ^ "\n") ;
78 let set_selection mathview () =
81 match !mathview#get_selection with
82 None -> raise Not_found
84 match Minidom.node_get_parent node with
85 None -> raise Not_found
87 !mathview#set_selection (Some node) ;
88 print_string "set_selection: SEEMS TO WORK\n"
91 print_string "set_selection: YOU MUST PREVIOUSLY SELECT A NON-ROOT NODE"
96 let unload mathview () =
98 print_string "unload: SEEMS TO WORK\n" ;
102 let get_width mathview () =
103 print_string ("get_width: " ^ string_of_int (!mathview#get_width) ^ "\n") ;
107 let get_height mathview () =
108 print_string ("get_height: " ^ string_of_int (!mathview#get_height) ^ "\n") ;
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") ;
118 let set_top mathview () =
119 !mathview#set_top 0 0;
120 print_string "set_top: SEEM TO WORK\n" ;
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" ;
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" ;
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" ;
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";
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" ;
163 let set_font_size mathview () =
164 !mathview#set_font_size 24 ;
165 print_string "set_font_size: FONT IS NOW 24\n" ;
169 let get_font_size mathview () =
170 print_string ("get_font_size: " ^ string_of_int (!mathview#get_font_size) ^ "\n") ;
174 let set_anti_aliasing mathview () =
175 !mathview#set_anti_aliasing true ;
176 print_string "set_anti_aliasing: ON\n" ;
180 let get_anti_aliasing mathview () =
181 print_string ("get_anti_aliasing: " ^
182 (match !mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
187 let set_kerning mathview () =
188 !mathview#set_kerning true ;
189 print_string "set_kerning: ON\n" ;
193 let get_kerning mathview () =
194 print_string ("get_kerning: " ^
195 (match !mathview#get_kerning with true -> "ON" | false -> "OFF") ^
200 let set_log_verbosity mathview () =
201 !mathview#set_log_verbosity 3 ;
202 print_string "set_log_verbosity: NOW IS 3\n" ;
206 let get_log_verbosity mathview () =
207 print_string ("get_log_verbosity: " ^
208 string_of_int !mathview#get_log_verbosity ^
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";
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) ;
276 main_window#show () ;