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_ns node
15 (M.mDOMString_of_string "xlink")
16 (M.mDOMString_of_string "href")
18 None -> "DOES NOT WORKS (if you have clicked on the hyperlink)!!!!!"
19 | Some s -> M.string_of_mDOMString s
21 print_string ("jump: " ^
23 M.node_get_attribute node
24 (M.mDOMString_of_string "href")
26 None -> "DOES NOT WORKS (if you have clicked on the hyperlink)!!!!!"
27 | Some s -> M.string_of_mDOMString s
32 let selection_changed node =
33 let module M = Minidom in
34 print_string ("selection_changed: " ^
38 None -> "selection_changed on nothing (???)"
39 | Some s -> "selection changed on " ^ M.string_of_mDOMString s
46 let module M = Minidom in
47 print_string ("clicked: " ^
51 None -> "Nothing clicked (???)"
52 | Some s -> M.string_of_mDOMString s ^ " clicked"
58 let activate_t1 mathview sw () =
59 sw#remove !mathview#coerce ;
61 (GMathView.math_view ~packing:sw#add ~width:50 ~height:50
62 ~use_t1_lib:true ()) ;
63 ignore(!mathview#connect#jump jump) ;
64 ignore(!mathview#connect#clicked clicked) ;
65 ignore(!mathview#connect#selection_changed selection_changed) ;
66 print_string "WIDGET RECREATED WITH T1 FONTS ACTIVATED\n" ;
69 let load mathview () =
70 !mathview#load "test.xml" ;
71 print_string "load: SEEMS TO WORK\n" ;
76 let get_selection mathview () =
79 match !mathview#get_selection with
80 None -> "NO SELECTION"
83 print_string ("get_selection: " ^ selection ^ "\n") ;
88 let set_selection mathview () =
91 match !mathview#get_selection with
92 None -> "NO SELECTION"
95 print_string ("get_selection: " ^ selection ^ "\n") ;
100 let unload mathview () =
102 print_string "unload: SEEMS TO WORK\n" ;
106 let get_width mathview () =
107 print_string ("get_width: " ^ string_of_int (!mathview#get_width) ^ "\n") ;
111 let get_height mathview () =
112 print_string ("get_height: " ^ string_of_int (!mathview#get_height) ^ "\n") ;
116 let get_top mathview () =
117 let (x,y) = !mathview#get_top in
118 print_string ("get_top: ("^ string_of_int x ^ "," ^ string_of_int y ^ ")\n") ;
122 let set_top mathview () =
123 !mathview#set_top 0 0;
124 print_string "set_top: SEEM TO WORK\n" ;
128 let set_adjustments mathview () =
129 let adj1 = GData.adjustment () in
130 let adj2 = GData.adjustment () in
131 !mathview#set_adjustments adj1 adj2 ;
132 adj1#set_value ((adj1#lower +. adj1#upper) /. 2.0) ;
133 adj2#set_value ((adj2#lower +. adj2#upper) /. 2.0) ;
134 print_string "set_adjustments: SEEM TO WORK\n" ;
138 let get_hadjustment mathview () =
139 let adj = !mathview#get_hadjustment in
140 adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
141 print_string "get_hadjustment: SEEM TO WORK\n" ;
145 let get_vadjustment mathview () =
146 let adj = !mathview#get_vadjustment in
147 adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
148 print_string "get_vadjustment: SEEM TO WORK\n" ;
152 let get_buffer mathview () =
153 let buffer = !mathview#get_buffer in
154 Gdk.Draw.rectangle buffer (Gdk.GC.create buffer) ~x:0 ~y:0
155 ~width:50 ~height:50 ~filled:true () ;
156 print_string "get_buffer: SEEMS TO WORK (hint: force the widget redrawing)\n";
160 let get_frame mathview () =
161 let frame = !mathview#get_frame in
162 frame#set_shadow_type `NONE ;
163 print_string "get_frame: SEEMS TO WORK\n" ;
167 let set_font_size mathview () =
168 !mathview#set_font_size 24 ;
169 print_string "set_font_size: FONT IS NOW 24\n" ;
173 let get_font_size mathview () =
174 print_string ("get_font_size: " ^ string_of_int (!mathview#get_font_size) ^ "\n") ;
178 let set_anti_aliasing mathview () =
179 !mathview#set_anti_aliasing true ;
180 print_string "set_anti_aliasing: ON\n" ;
184 let get_anti_aliasing mathview () =
185 print_string ("get_anti_aliasing: " ^
186 (match !mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
191 let set_kerning mathview () =
192 !mathview#set_kerning true ;
193 print_string "set_kerning: ON\n" ;
197 let get_kerning mathview () =
198 print_string ("get_kerning: " ^
199 (match !mathview#get_kerning with true -> "ON" | false -> "OFF") ^
204 let set_log_verbosity mathview () =
205 !mathview#set_log_verbosity 3 ;
206 print_string "set_log_verbosity: NOW IS 3\n" ;
210 let get_log_verbosity mathview () =
211 print_string ("get_log_verbosity: " ^
212 string_of_int !mathview#get_log_verbosity ^
217 let export_to_postscript mathview () =
218 !mathview#export_to_postscript "test.ps" ;
219 print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n";
223 (* Widget creation *)
224 let main_window = GWindow.window ~title:"GtkMathView test" () in
225 let vbox = GPack.vbox ~packing:main_window#add () in
226 let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in
227 let mathview= ref (GMathView.math_view ~packing:sw#add ~width:50 ~height:50 ()) in
228 (*let hbox = GPack.hbox ~packing:vbox#pack () in*)
229 let table = GPack.table ~rows:5 ~columns:5 ~packing:vbox#pack () in
230 let button_t1=GButton.button ~label:"activate t1 fonts" ~packing:(table#attach ~left:0 ~top:0) () in
231 let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in
232 let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in
233 let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in
234 let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in
235 let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in
236 let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in
237 let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in
238 let button_set_top = GButton.button ~label:"set_top" ~packing:(table#attach ~left:3 ~top:1) () in
239 let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:(table#attach ~left:4 ~top:1) () in
240 let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:(table#attach ~left:0 ~top:2) () in
241 let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:(table#attach ~left:1 ~top:2) () in
242 let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:(table#attach ~left:2 ~top:2) () in
243 let button_get_frame = GButton.button ~label:"get_frame" ~packing:(table#attach ~left:3 ~top:2) () in
244 let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table#attach ~left:4 ~top:2) () in
245 let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in
246 let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in
247 let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in
248 let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in
249 let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in
250 let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in
251 let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in
252 let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in
253 (* Signals connection *)
254 ignore(button_t1#connect#clicked (activate_t1 mathview sw)) ;
255 ignore(button_load#connect#clicked (load mathview)) ;
256 ignore(button_unload#connect#clicked (unload mathview)) ;
257 ignore(button_get_selection#connect#clicked (get_selection mathview)) ;
258 ignore(button_set_selection#connect#clicked (set_selection mathview)) ;
259 ignore(button_get_width#connect#clicked (get_width mathview)) ;
260 ignore(button_get_height#connect#clicked (get_height mathview)) ;
261 ignore(button_get_top#connect#clicked (get_top mathview)) ;
262 ignore(button_set_top#connect#clicked (set_top mathview)) ;
263 ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ;
264 ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ;
265 ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ;
266 ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ;
267 ignore(button_get_frame#connect#clicked (get_frame mathview)) ;
268 ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ;
269 ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ;
270 ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ;
271 ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ;
272 ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ;
273 ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ;
274 ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ;
275 ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ;
276 ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ;
277 ignore(!mathview#connect#jump jump) ;
278 ignore(!mathview#connect#clicked clicked) ;
279 ignore(!mathview#connect#selection_changed selection_changed) ;
281 main_window#show () ;