Class Window

(back to index)

A window containing other widgets.

Inherits from Group

Property index

bordermodalshown
iconlabelnon_modalxclass

Function index

free_positionfullscreen_offhotspotset_modalshow
fullscreenhideiconizeset_non_modalsize_range

Key properties

typenamesummary
boolean borderUse window manager border around window?
string iconlabelWindow icon label

Key functions

typenamesummary
void show()Show this window
void hide()Hide this window
void iconize()Iconify window
void set_modal()Make window modal
void set_non_modal()Make window non-modal

Description

This widget is an actual window. This can either be a main window, with a border and title and all the window management controls, or a "subwindow" inside a window. This is controlled by whether or not the window has a parent. In normal programming, it usually makes much more sense to use a Group instead of a subwindow unless you need to set a specific visual or request double buffering, or similar low-level requests.

Once you create a window, you usually add child Widgets to it. As with all Groups, upon creation a Window becomes the current group, the group widgets are added to upon creation. You may also add widgets using window:add(child) for each new widget. See Group for more information on how to add and remove children.

Top level Windows should be created using only two coordinates, with the constructor Window{integer width, integer height}. (You can add a label or properties, like Window{200,200, "label"; box=Boxtype.up}). A Window created this way is hidden, has no parent, and allows the window manager to choose a location to display the window. You can force a position by calling position(x,y) or hotspot() before calling show().

See size_range() for a description of how window resizing is handled. In most cases, you should be able to get reasonable behavior by setting the resizable property. See Group for more detail on resizable.

There are several subclasses of Window that provide double-buffering, overlay, menu, and OpenGL support. They are not currently used in Lua Fltk.

The window's callback is performed if the user tries to close a window using the window manager and Fl.modal is nil or equal to the window. Window has a default callback that calls Window:hide() and calls exit(0) if this is the last top-level window.

Detailed reference

border: boolean

Gets or sets whether or not the window manager border is around the window. The default value is true. Under most X window managers this does not work after show() has been called, although SGI's 4DWM does work.

Check the value of border after setting it to determine whether it really changed.

set_modal(): void

A "modal" window, when shown(), will prevent any events from being delivered to other windows in the same program, and will also remain on top of the other windows (if the X window manager supports the "transient for" property). Several modal windows may be shown at once, in which case only the last one shown gets events. You can see which window (if any) is modal by the value of Fl.modal.

modal: readonly boolean

True if this window is modal. See set_modal() for more information on modal windows.

set_non_modal(): void

A "non-modal" window (terminology borrowed from Microsoft Windows) acts like a modal one in that it remains on top, but it has no effect on event delivery. There are three states for a window: modal, non-modal, and normal.

non_modal: readonly boolean

True if this window is non-modal. See set_non_modal() for more information on non-modal windows.

hotspot(integer x, integer y, boolean offscreen = nil): void

May also be called as hotspot(Widget w, [boolean offscreen]). position() the window so that the mouse is pointing at the given position, or at the center of the given widget, which may be the window itself. If the optional offscreen parameter is true, then the window is allowed to extend off the screen (this does not work with some X window managers).

free_position(): void

Undoes the effect of a previous resize() or show() so that the next time show() is called the window manager is free to position the window.

size_range(integer minw, integer minh, integer maxw=0, integer maxh=0, integer dw=0, integer dh=0, boolean aspect=nil): void

Set the allowable range the user can resize this window to. This only works for top-level windows.

If this function is not called, FLTK tries to figure out the range from the setting of
resizeable : It is undefined what happens if the current size does not fit in the constraints passed to size_range().

iconlabel: string

The label used for this window's icon. Ignored by some window managers.

xclass: string

A string used to tell the system what type of window this is. Mostly this identifies the picture to draw in the icon. Under X, this is turned into a XA_WM_CLASS pair by truncating at the first non-alphanumeric character and capitalizing the first character, and the second one if the first is 'x'. Thus "foo" turns into "foo, Foo", and "xprog.1" turns into "xprog, XProg". This only works if called before calling show().

Under Microsoft Windows this string is used as the name of the WNDCLASS structure, though it is not clear if this can have any visible effect.

shown: readonly boolean

Returns true if show() has been called (but not hide()). You can tell if a window is iconified with w.shown and not w.visible.

show(): void

Put the window on the screen. (Usually this has the side effect of opening the X display.)

If the window is already shown then it is restored and raised to the top. This is really convenient because your program can call show() at any time, even if the window is already up. It also means that show() serves the purpose of raise() in other toolkits.

hide(): void

Remove the window from the screen. If the window is already hidden or has not been shown then this does nothing and is harmless.

Note that the normal Fl:run() loop will terminate if there are no shown windows on screen.

fullscreen(): void

Makes the window completely fill the screen, without any window manager border visible. You must use fullscreen_off() to undo this. This may not work with all window managers.

fullscreen_off(integer x, integer y, integer w, integer h): void

Turns off any side effects of fullscreen() and performs resize(x,y,w,h).

iconize(): void

Iconifies the window. If you call this when shown is false it will show() it as an icon. If the window is already iconified this does nothing.

Call show() to restore the window.

When a window is iconified/restored (either by these calls or by the user) the Window receives Event.hide and Event.show events and visible is turned on or off.

There is no way to control what is drawn in the icon except with the string in xclass. You should not rely on window managers displaying the icons.


doctool generated at Sun Aug 5 20:52:29 2001