From 35667e24851618733d8ef7576a6550f6e2f0b26b Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Tue, 7 Nov 2000 11:07:25 +0000 Subject: [PATCH] Test almost finished. Some bugs found. --- .../gMathView.ml | 6 +- .../gtkMathView.ml | 2 +- .../ml_gtk_mathview.c | 19 ++- .../test/test.ml | 126 ++++++++++++++++-- 4 files changed, 135 insertions(+), 18 deletions(-) diff --git a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gMathView.ml b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gMathView.ml index f83774444..87f0d5035 100644 --- a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gMathView.ml +++ b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gMathView.ml @@ -6,6 +6,7 @@ open GtkMathView open GObj exception ErrorLoadingFile of string;; +exception ErrorWritingFile of string;; class math_view_signals obj = object inherit GContainer.container_signals obj @@ -21,7 +22,6 @@ class math_view obj = object method load ~filename = if not (MathView.load obj ~filename) then raise (ErrorLoadingFile filename) method unload = MathView.unload obj - (*method dump = MathView.dump obj*) method get_selection = MathView.get_selection obj method set_selection = MathView.set_selection obj method get_width = MathView.get_width obj @@ -44,7 +44,9 @@ class math_view obj = object method get_kerning = MathView.get_kerning obj method set_log_verbosity = MathView.set_log_verbosity obj method get_log_verbosity = MathView.get_log_verbosity obj - method export_to_postscript = MathView.export_to_postscript obj + method export_to_postscript ~filename = + if not (MathView.export_to_postscript obj ~filename) then + raise (ErrorWritingFile filename) end let math_view ?adjustmenth ?adjustmentv ?(use_t1_lib=false) ?border_width diff --git a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gtkMathView.ml b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gtkMathView.ml index 1deb11182..62cd5409d 100644 --- a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gtkMathView.ml +++ b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/gtkMathView.ml @@ -57,7 +57,7 @@ module MathView = struct "ml_gtk_math_view_set_log_verbosity" external get_log_verbosity : [>`math_view] obj -> int = "ml_gtk_math_view_get_log_verbosity" - external export_to_postscript : [>`math_view] obj -> int = + external export_to_postscript : [>`math_view] obj -> filename:string -> bool = "ml_gtk_math_view_export_to_postscript" module Signals = struct diff --git a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/ml_gtk_mathview.c b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/ml_gtk_mathview.c index a51539791..3286f9054 100644 --- a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/ml_gtk_mathview.c +++ b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/ml_gtk_mathview.c @@ -43,9 +43,26 @@ ML_2 (gtk_math_view_set_kerning, GtkMathView_val, Bool_val, Unit) ML_1 (gtk_math_view_get_kerning, GtkMathView_val, Val_bool) ML_2 (gtk_math_view_set_log_verbosity, GtkMathView_val, Int_val, Unit) ML_1 (gtk_math_view_get_log_verbosity, GtkMathView_val, Val_int) -ML_2 (gtk_math_view_export_to_postscript, GtkMathView_val, Int_val, Unit) +value ml_gtk_math_view_export_to_postscript (value arg1, value arg2) +{ + CAMLparam1(arg1); + char *filename; + FILE *fd; + int res; + filename = String_val (arg2); + if ((fd = fopen(filename, "w"))) { + gtk_math_view_export_to_postscript (GtkMathView_val (arg1), fd); + fclose (fd); + res = 1; + } else { + fprintf(stderr, "Error opening file %s for writing\n", filename); + res = 0; + } + CAMLreturn (Val_bool(res)); +} + value ml_gtk_math_view_get_top (value arg1) { CAMLparam1(arg1); diff --git a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/test/test.ml b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/test/test.ml index c58549e51..a7c9eb79c 100644 --- a/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/test/test.ml +++ b/helm/DEVEL/lablgtk_gtkmathview/lablgtk-20000829_gtkmathview-0.1.0/test/test.ml @@ -29,6 +29,7 @@ let clicked node = ;; let activate_t1 mathview sw () = + sw#remove !mathview#coerce ; mathview := (GMathView.math_view ~packing:sw#add ~width:50 ~height:50 ~use_t1_lib:true ()) ; @@ -57,6 +58,18 @@ let get_selection mathview () = *) () ;; +let set_selection mathview () = +(* + let selection = + match !mathview#get_selection with + None -> "NO SELECTION" + | Some s -> s + in + print_string ("get_selection: " ^ selection ^ "\n") ; + flush stdout +*) () +;; + let unload mathview () = !mathview#unload ; print_string "unload: SEEMS TO WORK\n" ; @@ -73,6 +86,18 @@ let get_height mathview () = flush stdout ;; +let get_top mathview () = + let (x,y) = !mathview#get_top in + print_string ("get_top: (" ^ string_of_int x ^ "," ^ string_of_int y ^ "\n") ; + flush stdout +;; + +let set_top mathview () = + !mathview#set_top 0 0; + print_string "set_top: SEEM TO WORK\n" ; + flush stdout +;; + let set_adjustments mathview () = let adj1 = GData.adjustment () in let adj2 = GData.adjustment () in @@ -118,37 +143,110 @@ let set_font_size mathview () = flush stdout ;; +let get_font_size mathview () = + print_string ("get_font_size: " ^ string_of_int (!mathview#get_font_size) ^ "\n") ; + flush stdout +;; + +let set_anti_aliasing mathview () = + !mathview#set_anti_aliasing true ; + print_string "set_anti_aliasing: ON\n" ; + flush stdout +;; + +let get_anti_aliasing mathview () = + print_string ("get_anti_aliasing: " ^ + (match !mathview#get_anti_aliasing with true -> "ON" | false -> "OFF") ^ + "\n") ; + flush stdout +;; + +let set_kerning mathview () = + !mathview#set_kerning true ; + print_string "set_kerning: ON\n" ; + flush stdout +;; + +let get_kerning mathview () = + print_string ("get_kerning: " ^ + (match !mathview#get_kerning with true -> "ON" | false -> "OFF") ^ + "\n") ; + flush stdout +;; + +let set_log_verbosity mathview () = + !mathview#set_log_verbosity 3 ; + print_string "set_log_verbosity: NOW IS 3\n" ; + flush stdout +;; + +let get_log_verbosity mathview () = + print_string ("get_log_verbosity: " ^ + string_of_int !mathview#get_log_verbosity ^ + "\n") ; + flush stdout +;; + +let export_to_postscript mathview () = + !mathview#export_to_postscript "test.ps" ; + print_string "expor_to_postscript: SEEMS TO WORK (hint: look at test.ps)\n"; + flush stdout +;; + (* Widget creation *) let main_window = GWindow.window ~title:"GtkMathView test" () in let vbox = GPack.vbox ~packing:main_window#add () in let sw = GBin.scrolled_window ~width:50 ~height:50 ~packing:vbox#pack () in let mathview= ref (GMathView.math_view ~packing:sw#add ~width:50 ~height:50 ()) in -let hbox = GPack.hbox ~packing:vbox#pack () in -let button_t1=GButton.button ~label:"activate t1 fonts" ~packing:hbox#pack () in -let button_load = GButton.button ~label:"load" ~packing:hbox#pack () in -let button_get_selection = GButton.button ~label:"get_selection" ~packing:hbox#pack () in -let button_unload = GButton.button ~label:"unload" ~packing:hbox#pack () in -let button_get_width = GButton.button ~label:"get_width" ~packing:hbox#pack () in -let button_get_height = GButton.button ~label:"get_height" ~packing:hbox#pack () in -let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:hbox#pack () in -let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:hbox#pack () in -let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:hbox#pack () in -let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:hbox#pack () in -let button_get_frame = GButton.button ~label:"get_frame" ~packing:hbox#pack () in -let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:hbox#pack () in +(*let hbox = GPack.hbox ~packing:vbox#pack () in*) +let table = GPack.table ~rows:5 ~columns:5 ~packing:vbox#pack () in +let button_t1=GButton.button ~label:"activate t1 fonts" ~packing:(table#attach ~left:0 ~top:0) () in +let button_load = GButton.button ~label:"load" ~packing:(table#attach ~left:1 ~top:0) () in +let button_unload = GButton.button ~label:"unload" ~packing:(table#attach ~left:2 ~top:0) () in +let button_get_selection = GButton.button ~label:"get_selection" ~packing:(table#attach ~left:3 ~top:0) () in +let button_set_selection = GButton.button ~label:"set_selection" ~packing:(table#attach ~left:4 ~top:0) () in +let button_get_width = GButton.button ~label:"get_width" ~packing:(table#attach ~left:0 ~top:1) () in +let button_get_height = GButton.button ~label:"get_height" ~packing:(table#attach ~left:1 ~top:1) () in +let button_get_top = GButton.button ~label:"get_top" ~packing:(table#attach ~left:2 ~top:1) () in +let button_set_top = GButton.button ~label:"set_top" ~packing:(table#attach ~left:3 ~top:1) () in +let button_set_adjustments = GButton.button ~label:"set_adjustments" ~packing:(table#attach ~left:4 ~top:1) () in +let button_get_hadjustment = GButton.button ~label:"get_hadjustment" ~packing:(table#attach ~left:0 ~top:2) () in +let button_get_vadjustment = GButton.button ~label:"get_vadjustment" ~packing:(table#attach ~left:1 ~top:2) () in +let button_get_buffer = GButton.button ~label:"get_buffer" ~packing:(table#attach ~left:2 ~top:2) () in +let button_get_frame = GButton.button ~label:"get_frame" ~packing:(table#attach ~left:3 ~top:2) () in +let button_set_font_size = GButton.button ~label:"set_font_size" ~packing:(table#attach ~left:4 ~top:2) () in +let button_get_font_size = GButton.button ~label:"get_font_size" ~packing:(table#attach ~left:0 ~top:3) () in +let button_set_anti_aliasing = GButton.button ~label:"set_anti_aliasing" ~packing:(table#attach ~left:1 ~top:3) () in +let button_get_anti_aliasing = GButton.button ~label:"get_anti_aliasing" ~packing:(table#attach ~left:2 ~top:3) () in +let button_set_kerning = GButton.button ~label:"set_kerning" ~packing:(table#attach ~left:3 ~top:3) () in +let button_get_kerning = GButton.button ~label:"get_kerning" ~packing:(table#attach ~left:4 ~top:3) () in +let button_set_log_verbosity = GButton.button ~label:"set_log_verbosity" ~packing:(table#attach ~left:0 ~top:4) () in +let button_get_log_verbosity = GButton.button ~label:"get_log_verbosity" ~packing:(table#attach ~left:1 ~top:4) () in +let button_export_to_postscript = GButton.button ~label:"export_to_postscript" ~packing:(table#attach ~left:2 ~top:4) () in (* Signals connection *) ignore(button_t1#connect#clicked (activate_t1 mathview sw)) ; ignore(button_load#connect#clicked (load mathview)) ; -ignore(button_get_selection#connect#clicked (get_selection mathview)) ; ignore(button_unload#connect#clicked (unload mathview)) ; +ignore(button_get_selection#connect#clicked (get_selection mathview)) ; +ignore(button_set_selection#connect#clicked (set_selection mathview)) ; ignore(button_get_width#connect#clicked (get_width mathview)) ; ignore(button_get_height#connect#clicked (get_height mathview)) ; +ignore(button_get_top#connect#clicked (get_top mathview)) ; +ignore(button_set_top#connect#clicked (set_top mathview)) ; ignore(button_set_adjustments#connect#clicked (set_adjustments mathview)) ; ignore(button_get_hadjustment#connect#clicked (get_hadjustment mathview)) ; ignore(button_get_vadjustment#connect#clicked (get_vadjustment mathview)) ; ignore(button_get_buffer#connect#clicked (get_buffer mathview)) ; ignore(button_get_frame#connect#clicked (get_frame mathview)) ; ignore(button_set_font_size#connect#clicked (set_font_size mathview)) ; +ignore(button_get_font_size#connect#clicked (get_font_size mathview)) ; +ignore(button_set_anti_aliasing#connect#clicked (set_anti_aliasing mathview)) ; +ignore(button_get_anti_aliasing#connect#clicked (get_anti_aliasing mathview)) ; +ignore(button_set_kerning#connect#clicked (set_kerning mathview)) ; +ignore(button_get_kerning#connect#clicked (get_kerning mathview)) ; +ignore(button_set_log_verbosity#connect#clicked (set_log_verbosity mathview)) ; +ignore(button_get_log_verbosity#connect#clicked (get_log_verbosity mathview)) ; +ignore(button_export_to_postscript#connect#clicked (export_to_postscript mathview)) ; ignore(!mathview#connect#jump jump) ; ignore(!mathview#connect#clicked clicked) ; ignore(!mathview#connect#selection_changed selection_changed) ; -- 2.39.2