1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
|
|
|
(* General Public License. *)
|
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
2001-09-06 01:52:32 -07:00
|
|
|
open StdLabels
|
1999-11-30 06:59:39 -08:00
|
|
|
open Tk
|
|
|
|
open Jg_tk
|
|
|
|
|
|
|
|
(*
|
2000-04-11 20:43:25 -07:00
|
|
|
class formatted ~parent ~width ~maxheight ~minheight =
|
1999-11-30 06:59:39 -08:00
|
|
|
val parent = (parent : Widget.any Widget.widget)
|
|
|
|
val width = width
|
|
|
|
val maxheight = maxheight
|
|
|
|
val minheight = minheight
|
2000-04-11 20:43:25 -07:00
|
|
|
val tw = Text.create ~parent ~width ~wrap:`Word
|
1999-11-30 06:59:39 -08:00
|
|
|
val fof = Format.get_formatter_output_functions ()
|
|
|
|
method parent = parent
|
|
|
|
method init =
|
2000-04-11 20:43:25 -07:00
|
|
|
pack [tw] ~side:`Left ~fill:`Both ~expand:true;
|
1999-11-30 06:59:39 -08:00
|
|
|
Format.print_flush ();
|
|
|
|
Format.set_margin (width - 2);
|
2000-04-11 20:43:25 -07:00
|
|
|
Format.set_formatter_output_functions ~out:(Jg_text.output tw)
|
|
|
|
~flush:(fun () -> ())
|
1999-11-30 06:59:39 -08:00
|
|
|
method finish =
|
|
|
|
Format.print_flush ();
|
2000-04-11 20:43:25 -07:00
|
|
|
Format.set_formatter_output_functions ~out:(fst fof) ~flush:(snd fof);
|
|
|
|
let `Linechar (l, _) = Text.index tw ~index:(tposend 1) in
|
|
|
|
Text.configure tw ~height:(max minheight (min l maxheight));
|
1999-11-30 06:59:39 -08:00
|
|
|
if l > 5 then
|
2000-04-11 20:43:25 -07:00
|
|
|
pack [Jg_text.add_scrollbar tw] ~before:tw ~side:`Right ~fill:`Y
|
1999-11-30 06:59:39 -08:00
|
|
|
end
|
|
|
|
*)
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let formatted ~title ?on ?(ppf = Format.std_formatter)
|
|
|
|
?(width=60) ?(maxheight=10) ?(minheight=0) () =
|
1999-11-30 06:59:39 -08:00
|
|
|
let tl, frame =
|
|
|
|
match on with
|
2001-09-22 01:51:54 -07:00
|
|
|
Some frame ->
|
|
|
|
(* let label = Label.create frame ~anchor:`W ~padx:10 ~text:title in
|
|
|
|
pack [label] ~side:`Top ~fill:`X;
|
|
|
|
let frame2 = Frame.create frame in
|
|
|
|
pack [frame2] ~side:`Bottom ~fill:`Both ~expand:true; *)
|
|
|
|
coe frame, frame
|
1999-11-30 06:59:39 -08:00
|
|
|
| None ->
|
|
|
|
let tl = Jg_toplevel.titled title in
|
|
|
|
Jg_bind.escape_destroy tl;
|
|
|
|
let frame = Frame.create tl in
|
2000-04-11 20:43:25 -07:00
|
|
|
pack [frame] ~side:`Top ~fill:`Both ~expand:true;
|
1999-11-30 06:59:39 -08:00
|
|
|
coe tl, frame
|
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
let tw = Text.create frame ~width ~wrap:`Word in
|
|
|
|
pack [tw] ~side:`Left ~fill:`Both ~expand:true;
|
2000-03-14 21:51:26 -08:00
|
|
|
Format.pp_print_flush ppf ();
|
|
|
|
Format.pp_set_margin ppf (width - 2);
|
|
|
|
let fof,fff = Format.pp_get_formatter_output_functions ppf () in
|
|
|
|
Format.pp_set_formatter_output_functions ppf
|
2001-09-06 01:52:32 -07:00
|
|
|
(fun buf pos len -> Jg_text.output tw ~buf ~pos ~len)
|
|
|
|
ignore;
|
1999-11-30 06:59:39 -08:00
|
|
|
tl, tw,
|
|
|
|
begin fun () ->
|
2000-03-14 21:51:26 -08:00
|
|
|
Format.pp_print_flush ppf ();
|
2001-09-06 01:52:32 -07:00
|
|
|
Format.pp_set_formatter_output_functions ppf fof fff;
|
2000-04-11 20:43:25 -07:00
|
|
|
let `Linechar (l, _) = Text.index tw ~index:(tposend 1) in
|
|
|
|
Text.configure tw ~height:(max minheight (min l maxheight));
|
1999-11-30 06:59:39 -08:00
|
|
|
if l > 5 then
|
2000-04-11 20:43:25 -07:00
|
|
|
pack [Jg_text.add_scrollbar tw] ~before:tw ~side:`Right ~fill:`Y
|
1999-11-30 06:59:39 -08:00
|
|
|
end
|
|
|
|
|
2000-04-19 19:45:44 -07:00
|
|
|
let ask ~title ?master ?(cancel=true) text =
|
1999-11-30 06:59:39 -08:00
|
|
|
let tl = Jg_toplevel.titled title in
|
|
|
|
begin match master with None -> ()
|
2000-04-11 20:43:25 -07:00
|
|
|
| Some master -> Wm.transient_set tl ~master
|
1999-11-30 06:59:39 -08:00
|
|
|
end;
|
2000-04-11 20:43:25 -07:00
|
|
|
let mw = Message.create tl ~text ~padx:20 ~pady:10
|
|
|
|
~width:250 ~justify:`Left ~aspect:400 ~anchor:`W
|
1999-11-30 06:59:39 -08:00
|
|
|
and fw = Frame.create tl
|
2000-04-11 20:43:25 -07:00
|
|
|
and sync = Textvariable.create ~on:tl ()
|
1999-11-30 06:59:39 -08:00
|
|
|
and r = ref (`cancel : [`yes|`no|`cancel]) in
|
2000-04-11 20:43:25 -07:00
|
|
|
let accept = Button.create fw ~text:"Yes"
|
|
|
|
~command:(fun () -> r := `yes; destroy tl)
|
|
|
|
and refuse = Button.create fw ~text:"No"
|
|
|
|
~command:(fun () -> r := `no; destroy tl)
|
2000-04-19 19:45:44 -07:00
|
|
|
and cancelB = Button.create fw ~text:"Cancel"
|
2000-04-14 02:46:08 -07:00
|
|
|
~command:(fun () -> r := `cancel; destroy tl)
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
bind tl ~events:[`Destroy] ~extend:true
|
|
|
|
~action:(fun _ -> Textvariable.set sync "1");
|
2000-04-19 19:45:44 -07:00
|
|
|
pack [accept; refuse] ~side:`Left ~fill:`X ~expand:true;
|
|
|
|
if cancel then pack [cancelB] ~side:`Left ~fill:`X ~expand:true;
|
2000-04-11 20:43:25 -07:00
|
|
|
pack [mw] ~side:`Top ~fill:`Both;
|
|
|
|
pack [fw] ~side:`Bottom ~fill:`X ~expand:true;
|
1999-11-30 06:59:39 -08:00
|
|
|
Grab.set tl;
|
|
|
|
Tkwait.variable sync;
|
|
|
|
!r
|