5 (* The memo class provides an easy way to remember the real class of
7 Insert all widgets of class in one single t memo, and you can then
8 recover their original ML object with #find.
11 class ['a] memo : unit ->
13 constraint 'a = #widget
14 val tbl : (int, 'a) Hashtbl.t
15 method add : 'a -> unit
16 method find : widget -> 'a
17 method remove : widget -> unit
20 (* The ML signal mechanism allows one to add GTK-like signals to
24 val next_callback_id : unit -> GtkSignal.id
29 val mutable callbacks : (GtkSignal.id * ('a -> unit)) list
30 method callbacks : (GtkSignal.id * ('a -> unit)) list
31 method call : 'a -> unit
32 method connect : after:bool -> callback:('a -> unit) -> GtkSignal.id
33 method disconnect : GtkSignal.id -> bool
35 (* As with GTK signals, you can use [GtkSignal.stop_emit] inside a
36 callback to prevent other callbacks from being called. *)
38 class virtual ml_signals : (GtkSignal.id -> bool) list ->
42 method disconnect : GtkSignal.id -> unit
43 val mutable disconnectors : (GtkSignal.id -> bool) list
45 class virtual add_ml_signals :
46 'a Gtk.obj -> (GtkSignal.id -> bool) list ->
48 method disconnect : GtkSignal.id -> unit
49 val mutable disconnectors : (GtkSignal.id -> bool) list
52 (* To add ML signals to a LablGTK object:
54 class mywidget_signals obj ~mysignal1 ~mysignal2 = object
55 inherit somewidget_signals obj
56 inherit add_ml_signals obj [mysignal1#disconnect; mysignal2#disconnect]
57 method mysignal1 = mysignal1#connect ~after
58 method mysignal2 = mysignal2#connect ~after
61 class mywidget obj = object (self)
62 inherit somewidget obj
63 val mysignal1 = new signal obj
64 val mysignal2 = new signal obj
65 method connect = new mywidget_signals obj ~mysignal1 ~mysignal2
66 method call1 = mysignal1#call
67 method call2 = mysignal2#call
70 You can also add ML signals to an arbitrary object; just inherit
71 from [ml_signals] in place of [widget_signals]+[add_ml_signals].
73 class mysignals ~mysignal1 ~mysignal2 = object
74 inherit ml_signals [mysignal1#disconnect; mysignal2#disconnect]
75 method mysignal1 = mysignal1#connect ~after
76 method mysignal2 = mysignal2#connect ~after
80 (* The variable class provides an easy way to propagate state modifications.
81 A new variable is created by [new variable init]. The [#set] method just
82 calls the [set] signal, which by default only calls [real_set].
83 [real_set] sets the variable and calls [changed] when needed.
84 Deep equality is used to compare values, but check is only done if
85 there are callbacks for [changed].
88 class ['a] variable_signals :
89 set:'a signal -> changed:'a signal ->
93 method set : callback:('a -> unit) -> GtkSignal.id
94 method changed : callback:('a -> unit) -> GtkSignal.id
95 method disconnect : GtkSignal.id -> unit
96 val mutable disconnectors : (GtkSignal.id -> bool) list
99 class ['a] variable : 'a ->
102 val changed : 'a signal
104 method connect : 'a variable_signals
106 method set : 'a -> unit
107 method private equal : 'a -> 'a -> bool
108 method private real_set : 'a -> unit