]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/otherlibs/labltk/examples_camltk/text.ml
update
[l4.git] / l4 / pkg / ocaml / contrib / otherlibs / labltk / examples_camltk / text.ml
1 (***********************************************************************)
2 (*                                                                     *)
3 (*                 MLTk, Tcl/Tk interface of Objective Caml            *)
4 (*                                                                     *)
5 (*    Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis    *)
6 (*               projet Cristal, INRIA Rocquencourt                    *)
7 (*            Jacques Garrigue, Kyoto University RIMS                  *)
8 (*                                                                     *)
9 (*  Copyright 2002 Institut National de Recherche en Informatique et   *)
10 (*  en Automatique and Kyoto University.  All rights reserved.         *)
11 (*  This file is distributed under the terms of the GNU Library        *)
12 (*  General Public License, with the special exception on linking      *)
13 (*  described in file LICENSE found in the Objective Caml source tree. *)
14 (*                                                                     *)
15 (***********************************************************************)
16 open Tk
17
18 let top = opentk ()
19
20 let scroll_link sb tx =
21   Text.configure tx [YScrollCommand (Scrollbar.set sb)];
22   Scrollbar.configure sb [ScrollCommand (Text.yview tx)]
23
24 let f = Frame.create top []
25 let text = Text.create f []
26 let scrollbar = Scrollbar.create f []
27
28 let buffer = ref ""
29
30 let kill () =
31   buffer := 
32      Text.get text (TextIndex (Insert, []))
33                    (TextIndex (Insert, [LineEnd]));
34      Text.delete text (TextIndex (Insert, []))
35                    (TextIndex (Insert, [LineEnd]))
36 ;;
37
38 let yank () =
39   Text.insert text (TextIndex (Insert, [])) !buffer [] 
40
41 let _ = bind text [[Control], KeyPressDetail "y"] (BindSet ([], fun _ ->
42   yank () ))
43 ;;
44 let _ = bind text [[Control], KeyPressDetail "k"] (BindSet ([], fun _ ->
45   kill () ))
46 ;;
47
48 let _ =
49   scroll_link scrollbar text;
50
51   pack [text;f][];
52   pack [f][];
53   mainLoop ()
54 ;;
55