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$ *)
|
|
|
|
|
|
|
|
open Tk
|
|
|
|
|
|
|
|
let add_scrollbar lb =
|
|
|
|
let sb =
|
2000-04-11 20:43:25 -07:00
|
|
|
Scrollbar.create (Winfo.parent lb) ~command:(Listbox.yview lb) in
|
|
|
|
Listbox.configure lb ~yscrollcommand:(Scrollbar.set sb); sb
|
1999-11-30 06:59:39 -08:00
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let create_with_scrollbar ?selectmode parent =
|
1999-11-30 06:59:39 -08:00
|
|
|
let frame = Frame.create parent in
|
2000-04-11 20:43:25 -07:00
|
|
|
let lb = Listbox.create frame ?selectmode in
|
1999-11-30 06:59:39 -08:00
|
|
|
frame, lb, add_scrollbar lb
|
|
|
|
|
|
|
|
(* from frx_listbox,adapted *)
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let recenter lb ~index =
|
|
|
|
Listbox.selection_clear lb ~first:(`Num 0) ~last:`End;
|
1999-11-30 06:59:39 -08:00
|
|
|
(* Activate it, to keep consistent with Up/Down.
|
|
|
|
You have to be in Extended or Browse mode *)
|
2000-04-11 20:43:25 -07:00
|
|
|
Listbox.activate lb ~index;
|
|
|
|
Listbox.selection_anchor lb ~index;
|
|
|
|
Listbox.yview_index lb ~index
|
1999-11-30 06:59:39 -08:00
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
class timed ?wait ?nocase get_texts = object
|
1999-11-30 06:59:39 -08:00
|
|
|
val get_texts = get_texts
|
2000-04-11 20:43:25 -07:00
|
|
|
inherit Jg_completion.timed [] ?wait ?nocase as super
|
1999-11-30 06:59:39 -08:00
|
|
|
method reset =
|
|
|
|
texts <- get_texts ();
|
|
|
|
super#reset
|
|
|
|
end
|
|
|
|
|
2001-04-13 02:27:04 -07:00
|
|
|
let add_completion ?action ?wait ?nocase ?(double=true) lb =
|
1999-11-30 06:59:39 -08:00
|
|
|
let comp =
|
2000-04-11 20:43:25 -07:00
|
|
|
new timed ?wait ?nocase
|
|
|
|
(fun () -> Listbox.get_range lb ~first:(`Num 0) ~last:`End) in
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
Jg_bind.enter_focus lb;
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
bind lb ~events:[`KeyPress] ~fields:[`Char] ~action:
|
1999-12-16 00:37:38 -08:00
|
|
|
begin fun ev ->
|
1999-11-30 06:59:39 -08:00
|
|
|
(* consider only keys producing characters. The callback is called
|
|
|
|
even if you press Shift. *)
|
|
|
|
if ev.ev_Char <> "" then
|
2000-04-11 20:43:25 -07:00
|
|
|
recenter lb ~index:(`Num (comp#add ev.ev_Char))
|
1999-12-16 00:37:38 -08:00
|
|
|
end;
|
1999-11-30 06:59:39 -08:00
|
|
|
|
|
|
|
begin match action with
|
|
|
|
Some action ->
|
2000-04-11 20:43:25 -07:00
|
|
|
bind lb ~events:[`KeyPressDetail "Return"]
|
|
|
|
~action:(fun _ -> action `Active);
|
2001-04-13 02:27:04 -07:00
|
|
|
let bmod = if double then [`Double] else [] in
|
|
|
|
bind lb ~events:[`Modified(bmod, `ButtonPressDetail 1)]
|
2000-04-11 20:43:25 -07:00
|
|
|
~breakable:true ~fields:[`MouseY]
|
2001-04-13 02:27:04 -07:00
|
|
|
~action:
|
|
|
|
begin fun ev ->
|
|
|
|
let index = Listbox.nearest lb ~y:ev.ev_MouseY in
|
|
|
|
if not double then begin
|
|
|
|
Listbox.selection_clear lb ~first:(`Num 0) ~last:`End;
|
|
|
|
Listbox.selection_set lb ~first:index ~last:index;
|
|
|
|
end;
|
|
|
|
action index;
|
|
|
|
break ()
|
|
|
|
end
|
1999-11-30 06:59:39 -08:00
|
|
|
| None -> ()
|
|
|
|
end;
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
recenter lb ~index:(`Num 0) (* so that first item is active *)
|