1 (* Copyright (C) 2000, Luca Padovani <luca.padovani@cs.unibo.it>.
3 * This file is part of lablgtkmathview, the Ocaml binding
4 * for the GtkMathView widget.
6 * lablgtkmathview is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * lablgtkmathview is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with lablgtkmathview; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * For details, send a mail to the author.
23 (******************************************************************************)
24 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
27 (* This is a simple test for the OCaml (LablGtk indeed) binding of the *)
29 (******************************************************************************)
32 let jump (node : Ominidom.o_mDOMNode) =
33 let module O = Ominidom in
34 print_string ("jump: " ^
35 (match node#get_attribute (O.o_mDOMString_of_string "href") with
36 | Some x -> x#get_string
37 | None -> "NO HREF FOR THIS NODE"
42 let selection_changed mathview (node : Ominidom.o_mDOMNode option) =
43 let module O = Ominidom in
44 print_string ("selection_changed: " ^
46 None -> "selection_changed on nothing"
48 match node#get_name with
49 | Some x -> x#get_string
50 | None -> "on element without name"
52 mathview#set_selection node;
57 let clicked (node : Ominidom.o_mDOMNode) =
58 let module O = Ominidom in
59 print_string ("clicked: " ^
60 (match node#get_name with
61 | Some x -> x#get_string
68 let activate_t1 mathview () =
69 mathview#set_font_manager_type `font_manager_t1;
70 print_string "WIDGET SET WITH T1 FONTS\n" ;
74 let activate_gtk mathview () =
75 mathview#set_font_manager_type `font_manager_gtk;
76 print_string "WIDGET SET WITH GTK FONTS\n" ;
80 let get_font_manager_type mathview () =
81 print_string "CURRENT FONT MANAGER TYPE: ";
83 match mathview#get_font_manager_type with
84 | `font_manager_t1 -> print_string "T1"
85 | `font_manager_gtk -> print_string "GTK"
91 let load mathview () =
92 mathview#load "test.xml" ;
93 print_string "load: SEEMS TO WORK\n" ;
97 let get_selection mathview () =
98 let module O = Ominidom in
100 match mathview#get_selection with
103 match node#get_name with
104 | Some name -> name#get_string
105 | None -> "element with no name!"
107 | None -> "no selection!"
109 print_string ("get_selection: " ^ selection ^ "\n") ;
113 let set_selection mathview () =
114 let module O = Ominidom in
116 match mathview#get_selection with
120 let parent_node = node#get_parent in
121 mathview#set_selection (Some parent_node);
122 print_string "set selection: SEEMS TO WORK\n"
124 _ -> print_string "EXCEPTION: no parent\n"
127 mathview#set_selection None;
128 print_string "no selection\n"
133 let unload mathview () =
135 print_string "unload: SEEMS TO WORK\n" ;
139 let get_width mathview () =
140 print_string ("get_width: " ^ string_of_int (mathview#get_width) ^ "\n") ;
144 let get_height mathview () =
145 print_string ("get_height: " ^ string_of_int (mathview#get_height) ^ "\n") ;
149 let get_top mathview () =
150 let (x,y) = mathview#get_top in
151 print_string ("get_top: ("^ string_of_int x ^ "," ^ string_of_int y ^ ")\n") ;
155 let set_top mathview () =
156 mathview#set_top 0 0;
157 print_string "set_top: SEEM TO WORK\n" ;
161 let set_adjustments mathview () =
162 let adj1 = GData.adjustment () in
163 let adj2 = GData.adjustment () in
164 mathview#set_adjustments adj1 adj2 ;
165 adj1#set_value ((adj1#lower +. adj1#upper) /. 2.0) ;
166 adj2#set_value ((adj2#lower +. adj2#upper) /. 2.0) ;
167 print_string "set_adjustments: SEEM TO WORK\n" ;
171 let get_hadjustment mathview () =
172 let adj = mathview#get_hadjustment in
173 adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
174 print_string "get_hadjustment: SEEM TO WORK\n" ;
178 let get_vadjustment mathview () =
179 let adj = mathview#get_vadjustment in
180 adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
181 print_string "get_vadjustment: SEEM TO WORK\n" ;
185 let get_buffer mathview () =
186 let buffer = mathview#get_buffer in
187 Gdk.Draw.rectangle buffer (Gdk.GC.create buffer) ~x:0 ~y:0
188 ~width:50 ~height:50 ~filled:true () ;
189 print_string "get_buffer: SEEMS TO WORK (hint: force the widget redrawing)\n";
193 let get_frame mathview () =
194 let frame = mathview#get_frame in
195 frame#set_shadow_type `NONE ;
196 print_string "get_frame: SEEMS TO WORK\n" ;
200 let set_font_size mathview () =
201 mathview#set_font_size 24 ;
202 print_string "set_font_size: FONT IS NOW 24\n" ;
206 let get_font_size mathview () =
207 print_string ("get_font_size: " ^ string_of_int (mathview#get_font_size) ^ "\n") ;
211 let set_anti_aliasing mathview () =
212 mathview#set_anti_aliasing true ;
213 print_string "set_anti_aliasing: ON\n" ;
217 let get_anti_aliasing mathview () =
218 print_string ("get_anti_aliasing: " ^
219 (match mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^
224 let set_kerning mathview () =
225 mathview#set_kerning true ;
226 print_string "set_kerning: ON\n" ;
230 let get_kerning mathview () =
231 print_string ("get_kerning: " ^
232 (match mathview#get_kerning with true -> "ON" | false -> "OFF") ^
237 let set_log_verbosity mathview () =
238 mathview#set_log_verbosity 3 ;
239 print_string "set_log_verbosity: NOW IS 3\n" ;
243 let get_log_verbosity mathview () =
244 print_string ("get_log_verbosity: " ^
245 string_of_int mathview#get_log_verbosity ^
250 let export_to_postscript (mathview : GMathView.math_view) () =
251 mathview#export_to_postscript ~filename:"test.ps" ();
252 print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n";
256 (* Widget creation *)
257 let main_window = GWindow.window ~title:"GtkMathView test" () in
258 let vbox = GPack.vbox ~packing:main_window#add () in
259 let sw = GFrame.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in
260 let mathview= GMathView.math_view ~packing:sw#add ~width:50 ~height:50 () in
261 let table = GPack.table ~rows:6 ~columns:5 ~packing:vbox#pack () in
262 let button_gtk=GButton.button ~label:"activate Gtk fonts" ~packing:(table#attach ~left:0 ~top:0) () in
263 let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in
264 let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in
265 let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in
266 let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in
267 let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in
268 let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in
269 let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in
270 let button_set_top = GButton.button ~label:"set_top" ~packing:(table#attach ~left:3 ~top:1) () in
271 let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:(table#attach ~left:4 ~top:1) () in
272 let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:(table#attach ~left:0 ~top:2) () in
273 let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:(table#attach ~left:1 ~top:2) () in
274 let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:(table#attach ~left:2 ~top:2) () in
275 let button_get_frame = GButton.button ~label:"get_frame" ~packing:(table#attach ~left:3 ~top:2) () in
276 let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table#attach ~left:4 ~top:2) () in
277 let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in
278 let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in
279 let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in
280 let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in
281 let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in
282 let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in
283 let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in
284 let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in
285 let button_t1 = GButton.button ~label:"activate T1 fonts" ~packing:(table#attach ~left:3 ~top:4) () in
286 let button_get_font_manager_type = GButton.button ~label:"get_font_manager" ~packing:(table#attach ~left:4 ~top:4) () in
287 (* Signals connection *)
288 ignore(button_gtk#connect#clicked (activate_gtk mathview)) ;
289 ignore(button_load#connect#clicked (load mathview)) ;
290 ignore(button_unload#connect#clicked (unload mathview)) ;
291 ignore(button_get_selection#connect#clicked (get_selection mathview)) ;
292 ignore(button_set_selection#connect#clicked (set_selection mathview)) ;
293 ignore(button_get_width#connect#clicked (get_width mathview)) ;
294 ignore(button_get_height#connect#clicked (get_height mathview)) ;
295 ignore(button_get_top#connect#clicked (get_top mathview)) ;
296 ignore(button_set_top#connect#clicked (set_top mathview)) ;
297 ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ;
298 ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ;
299 ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ;
300 ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ;
301 ignore(button_get_frame#connect#clicked (get_frame mathview)) ;
302 ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ;
303 ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ;
304 ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ;
305 ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ;
306 ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ;
307 ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ;
308 ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ;
309 ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ;
310 ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ;
311 ignore(button_t1#connect#clicked (activate_t1 mathview)) ;
312 ignore(button_get_font_manager_type#connect#clicked (get_font_manager_type mathview)) ;
313 ignore(mathview#connect#jump jump) ;
314 ignore(mathview#connect#clicked clicked) ;
315 ignore(mathview#connect#selection_changed (selection_changed mathview)) ;
317 main_window#show () ;