]> matita.cs.unibo.it Git - helm.git/blob - helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/test/test.ml
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / DEVEL / lablgtk_gtkmathview / lablgtk-20000829_gtkmathview-0.1.0 / test / test.ml
1 (******************************************************************************)
2 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
3 (*                                 25/09/2000                                 *)
4 (*                                                                            *)
5 (*     This is a simple test for the OCaml (LablGtk indeed) binding of the    *)
6 (*                             MathView widget                                *)
7 (******************************************************************************)
8
9 (* Callbacks *)
10 let jump s =
11  print_string ("jump: " ^ s ^ "\n") ;
12  flush stdout
13 ;;
14
15 let clicked () =
16  print_string "clicked: IT WORKS\n" ;
17  flush stdout
18 ;;
19
20 let load mathview () =
21  mathview#load "test.xml" ;
22  print_string "load: SEEMS TO WORK\n" ;
23  flush stdout
24 ;;
25
26 exception Ok;;
27 let get_selection mathview () =
28  let selection =
29   match mathview#get_selection with
30      None -> "NO SELECTION"
31    | Some s -> s
32  in
33   print_string ("get_selection: " ^ selection ^ "\n") ;
34   flush stdout
35 ;;
36
37 let unload mathview () =
38  mathview#unload ;
39  print_string "unload: SEEMS TO WORK\n" ;
40  flush stdout
41 ;;
42
43 let dump mathview () =
44  mathview#dump ;
45  print_string "dump: SEEMS TO WORK\n" ;
46  flush stdout
47 ;;
48
49 let get_width mathview () =
50  print_string ("get_width: " ^ string_of_int (mathview#get_width) ^ "\n") ;
51  flush stdout
52 ;;
53
54 let get_height mathview () =
55  print_string ("get_height: " ^ string_of_int (mathview#get_height) ^ "\n") ;
56  flush stdout
57 ;;
58
59 let set_adjustments mathview () =
60  let adj1 = GData.adjustment () in
61  let adj2 = GData.adjustment () in
62   mathview#set_adjustments adj1 adj2 ;
63   adj1#set_value ((adj1#lower +. adj1#upper) /. 2.0) ;
64   adj2#set_value ((adj2#lower +. adj2#upper) /. 2.0) ;
65   print_string "set_adjustments: SEEM TO WORK\n" ;
66   flush stdout
67 ;;
68
69 let get_hadjustment mathview () =
70  let adj = mathview#get_hadjustment in
71   adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
72   print_string "get_hadjustment: SEEM TO WORK\n" ;
73   flush stdout
74 ;;
75
76 let get_vadjustment mathview () =
77  let adj = mathview#get_vadjustment in
78   adj#set_value ((adj#lower +. adj#upper) /. 2.0) ;
79   print_string "get_vadjustment: SEEM TO WORK\n" ;
80   flush stdout
81 ;;
82
83 let get_buffer mathview () =
84  let buffer = mathview#get_buffer in
85   Gdk.Draw.rectangle buffer (Gdk.GC.create buffer) ~x:0 ~y:0
86    ~width:50 ~height:50 ~filled:true () ;
87   print_string "get_buffer: SEEMS TO WORK (hint: force the widget redrawing)\n";
88   flush stdout
89 ;;
90
91 let get_frame mathview () =
92  let frame = mathview#get_frame in
93   frame#set_shadow_type `NONE ;
94   print_string "get_frame: SEEMS TO WORK\n" ;
95   flush stdout
96 ;;
97
98 let set_font_size mathview () =
99  mathview#set_font_size 24 ;
100  print_string "set_font_size: FONT IS NOW 24\n" ;
101  flush stdout
102 ;;
103  
104 (* Widget creation *)
105 let main_window = GWindow.window ~title:"GtkMathView test" () in
106 let vbox = GPack.vbox ~packing:main_window#add () in
107 let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in
108 (*let mathview = GMathView.math_view ~packing:sw#add_with_viewport ~width:50 ~height:50 () in*)
109 let mathview = GMathView.math_view ~packing:sw#add ~width:50 ~height:50 () in
110 let hbox = GPack.hbox ~packing:vbox#pack () in
111 let button_load = GButton.button ~label:"load" ~packing:hbox#pack () in
112 let button_get_selection = GButton.button ~label:"get_selection" ~packing:hbox#pack () in
113 let button_unload = GButton.button ~label:"unload" ~packing:hbox#pack () in
114 let button_dump = GButton.button ~label:"dump" ~packing:hbox#pack () in
115 let button_get_width = GButton.button ~label:"get_width" ~packing:hbox#pack () in
116 let button_get_height = GButton.button ~label:"get_height" ~packing:hbox#pack () in
117 let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:hbox#pack () in
118 let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:hbox#pack () in
119 let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:hbox#pack () in
120 let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:hbox#pack () in
121 let button_get_frame = GButton.button ~label:"get_frame" ~packing:hbox#pack () in
122 let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:hbox#pack () in
123 (* Signals connection *)
124 ignore(button_load#connect#clicked (load mathview)) ;
125 ignore(button_get_selection#connect#clicked (get_selection mathview)) ;
126 ignore(button_unload#connect#clicked (unload mathview)) ;
127 ignore(button_dump#connect#clicked (dump mathview)) ;
128 ignore(button_get_width#connect#clicked (get_width mathview)) ;
129 ignore(button_get_height#connect#clicked (get_height mathview)) ;
130 ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ;
131 ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ;
132 ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ;
133 ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ;
134 ignore(button_get_frame#connect#clicked (get_frame mathview)) ;
135 ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ;
136 ignore(mathview#connect#jump jump) ;
137 ignore(mathview#connect#clicked clicked) ;
138 (* Main Loop *)
139 main_window#show () ;
140 GMain.Main.main ()
141 ;;