include "tk.m"; tk:= load Tk Tk->PATH; Tki: type ref Draw->Image; Toplevel: adt { id: int; image: Tki; }; toplevel: fn(screen: ref Draw->Screen, arg: string)
: ref Toplevel; intop: fn(screen: ref Draw->Screen, x, y: int)
: ref Toplevel; namechan: fn(t: ref Toplevel, c: chan of string, n: string)
: string; cmd: fn(t: ref Toplevel, arg: string): string; mouse: fn(screen: ref Draw->Screen, x, y, button: int); keyboard: fn(screen: ref Draw->Screen, key: int); imageput: fn(t: ref Toplevel, name: string, i, m: Tki)
: string; imageget: fn(t: ref Toplevel, name: string)
: (Tki, Tki, string);
toplevel: fn(screen: ref Draw->Screen, arg: string)
: ref Toplevel;
## returns nil on error.The toplevel function, given an existing Screen (usually one inherited from the graphics Context; see Context - graphics environment in Chapter 11), creates a new window, called a Toplevel, under the control of the Limbo/Tk toolkit. The Toplevel is passed to the cmd and namechan functions to drive the widgets in the window. The arg parameter is a string containing creation options (such as -borderwidth 2) that are applied when creating the toplevel window.
cmd: fn(t: ref Toplevel, arg: string): string;
## returns string result from Limbo/Tk command.The cmd function passes command strings to the widgets in the Toplevel t and returns the string resulting from their execution. For example, given a canvas .c in the Toplevel t,
x:= int tk->cmd (t, ".c cget -actx");returns the integer x coordinate of the canvas.
namechan: fn(t: ref Toplevel, c: chan of string, n: string)
: string;
## returns empty string on success; error message on failure.Bindings can be created in a Toplevel that trigger strings to be sent on Limbo channels. Such channels must be declared to the Tk module using namechan. The following example creates a button that sends the word Ouch when it is pressed:
hitchannel:= chan of string; tk->namechan(t, hitchannel, "channel"); tk->cmd(t, "button.b.Hit -text Hit -command {send channel Ouch}"); expl:= <-hitchannel; # will see "Ouch" when button pressed
mouse: fn(screen: ref Draw->Screen, x, y, button: int); keyboard: fn(screen: ref Draw->Screen, key: int);The mouse and keyboard functions deliver mouse and keyboard events to Limbo/Tk for delivery to widgets. They are usually called only by the Window Manager.