typedef drawing window; typedef void (*actionfn)(window w); typedef void (*drawfn)(window w, rect r);
window newwindow(char *name, rect r, long flags); void del(window w); /* destroy window */ void settext(window w, char *newname); /* set window title */ rect getrect(window w); /* drawable area */ int getdepth(window w); /* screen resolution */ void show(window w); /* make window visible, frontmost */ void hide(window w); /* hide but do not destroy window */ void addto(window w); /* add new controls to this window */ void setredraw(control c, drawfn fn); /* window redrawn */ void setresize(control c, drawfn fn); /* window resized */ void setclose(control c, actionfn fn); /* window closed */
#define SimpleWindow 0x00000000 #define StandardWindow 0x000003E0 #define Menubar 0x00000010 #define Titlebar 0x00000020 #define Closebox 0x00000040 #define Resize 0x00000080 #define Maximize 0x00000100 #define Minimize 0x00000200 #define Modal 0x00001000 #define Floating 0x00002000 #define Centered 0x00004000 #define Centred 0x00004000 #define Workspace 0x00010000 #define Document 0x00020000 #define UsePalette 0x00100000
A window is a rectangular area displayed on a screen. A window has a zero origin in its own co-ordinate system, but may have various structures built around its drawable area, such as titlebars, borders and menubars. A window is also a drawing, and as such can be used with all of the drawing operations (see later sections for details).
The newwindow function creates a window with the given name. The rectangle specifies where the window's drawable area should appear on the screen, with zero being the top-left point of the screen. The flags parameter is usually the constant StandardWindow. If an error occurs the function returns NULL.
The flags field in newwindow is a bit-field. Various constants can be combined using the plus or bitwise-or operators to specify how the window should look. Here is a list of those constants and their meanings:
The del function destroys the specified window, hiding it first if necessary. If a window can be re-used, it is more efficient to hide it and then show it later on, rather than del the window and recreate it every time the user needs the window.
The settext function changes the name of the window as shown in the window's titlebar.
The getrect function returns the window's drawable rectangle in window co-ordinates; hence the top-left point will be zero. The getdepth function returns the pixel-depth of the screen on which the window is displayed.
The show function makes the specified window visible on the screen and ensures it is the frontmost application window. The hide function causes the specified window to vanish from the screen.
The addto function can be used to specify which window is to receive any newly created controls. Normally, controls are added to the most recently created window. The addto function provides a way of choosing a destination window instead.
The setredraw function is used to attach a call-back function to a window, which will be called every time that window needs to be redrawn. There is no need for this call-back to clear the window since this will automatically be done by the window manager.
The setresize function sets the call-back to be used when a window is resized by the user. The window is always resized before being redrawn, in circumstances where both of these events must be occur.
The setclose function sets the call-back to be used when the user tries to close the window using the window's close-box. If this call-back is not set, the window will simply be hidden. If the call-back is supplied, it will be called instead, and the window will not be hidden. It is then up to the programmer to achieve the desired effect.