include "draw.m"; include "tk.m"; tk := load Tk Tk->PATH; Image: import Draw; Toplevel: adt { display: ref Draw->Display; wreq: chan of string; image: ref Image; ctxt: ref Draw->Wmcontext; screenr: Draw->Rect; }; toplevel: fn(display: ref Draw->Display, arg: string): ref Toplevel; namechan: fn(top: ref Toplevel, c: chan of string, n: string): string; cmd: fn(top: ref Toplevel, arg: string): string; pointer: fn(top: ref Toplevel, p: Draw->Pointer); keyboard: fn(top: ref Toplevel, key: int); getimage: fn(top: ref Toplevel, name: string): (ref Image, ref Image, string); putimage: fn(top: ref Toplevel, name: string, i, m: ref Image): string; rect: fn(top: ref Toplevel, name: string, flags: int): Draw->Rect; quote: fn(s: string): string; color: fn(s: string): int;
Toplevel creates a new window called a Toplevel, which is under the control of the Tk toolkit, on an existing display, usually one inherited from the graphics Context (see draw-context(2)). The Toplevel is passed to cmd and namechan (q.v.) to drive the widgets in the window. Arg is a string containing creation options (such as -borderwidth 2) that are applied when creating the toplevel window.
Cmd 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.
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. For example, to create 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
Pointer and keyboard pass mouse and keyboard events to a Tk window for delivery to widgets; they must be called by each application, which usually receives them via a Wmcontext structure (see draw-context(2)) obtained from the window manager, often via tkclient(2).
Putimage passes an image and a mask into Tk. If name is the name of a Tk widget, it must be either a panel(9) widget, or a top level widget (ie, ``.'') ``.'') or a menu widget, in which case the associated image or window image is set to i. (m is ignored for menu and top-level widgets.) Otherwise, name must be the name of an existing image(9) which has its image and mask set to copies of i and m respectively.
Initially, a Tk toplevel has no image to draw on. Tk uses wreq to request new images of an external authority, and to inform said authority when the images are to be deleted. The requests are formatted as per quoted in string(2), and hold one of the following:
Wreq may be set to nil if an application is not prepared to read requests sent on this channel.
Rect returns the bounding rectangle of widget name in top. Flags determines the form of rectangle returned. If flags is zero, the actual rectangle of name in screen coordinates, not including its border, is returned. The bitmask flags that can change this are:
Quote returns a string that is the same as its arguments, but enclosed in curly braces and with internal curly braces escaped. This can be used to make an arbitrary string into a word suitable as an argument to a Tk function.
Color returns a colour in 32-bit RGBA format corresponding to the tk colour name s. (see types(9) for details).
Screenr gives the rectangle of the screen containing the toplevel window. Tk has no a priori way of knowing what this is; it is initially set to the rectangle of the display image, and may be set by the application if it knows better (e.g. from the wmrect file served by wm(1)).
TK(2 ) | Rev: Thu Feb 15 14:43:27 GMT 2007 |