## class fltk::Window

### Class Hierarchy

    fltk::Group
       |
       +----fltk::Window
               |
               +----fltk::DoubleBufferWindow, fltk::GlWindow,
                    fltk::OverlayWindow, fltk::Single_Window

### Include Files

    #include <fltk/Window.h>

### Description

This widget produces 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()`.

Once you create a window, you usually add children `fltk::Widget`'s to it by using `window->add(child)` for each new widget. See `fltk::Group` for more information on how to add and remove children.

There are several subclasses of `fltk::Window` that provide double-buffering, overlay, menu, and OpenGL support.

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

### Methods

fltk::Window ~Window border child_of clear_border current | cursor destroy exec first_window fullscreen | fullscreen_off hide hotspot iconic iconize iconlabel | label make_current next_window override resize | set_override show show_inside shown size_range

#### fltk::Window::Window(int w, int h, const char *title = 0)

The first form of the constructor should be used for a "top-level" window (that is, one that is not inside another window). It correctly sets `visible()` to false and `parent()` to `NULL`. By not specifying the position of the window, the window system will pick a place to show the window (some older X window managers will allow the user to place the window by hand). If you want to force a position you should call `position(x,y)` or `hotspot()` before calling `show()`.

`fltk::Widget::box()` is set to `fltk::FLAT_BOX`. If you plan to completely fill the window with children widgets you should change this to `fltk::NO_BOX`. If you turn the window border off you may want to change this to `fltk::UP_BOX`.

#### fltk::Window::Window(int x, int y, int w, int h, const char *title = 0)

The second form of the constructor is for creating child windows. It leaves `visible()` set to true.

#### virtual fltk::Window::~Window()

Calls destroy(). The destructor also deletes all the children. This allows a whole tree to be deleted at once, without having to keep a pointer to all the children in the user code. A kludge has been done so the `fltk::Window` and all of it's children can be automatic (local) variables, but you must declare the `fltk::Window` first so that it is destroyed last.

#### void fltk::Window::size_range(int minw, int minh, int maxw=0, int maxh=0, int dw=0, int dh=0, int aspect=0)

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

- `minw` and `minh` are the smallest the window can be.
- `maxw` and `maxh` are the largest the window can be. If either is equal to the minimum then you cannot resize in that direction. If either is zero then FLTK picks a maximum size in that direction such that the window will fill the screen.
- `dw` and `dh` are size increments. The window will be constrained to widths of `minw + N * dw`, where `N` is any non-negative integer. If these are less or equal to 1 they are ignored. (this is ignored on WIN32)
- `aspect` is a flag that indicates that the window should preserve it's aspect ratio. This is ignored by WIN32 and by most X window managers (in addition X does not describe what to do if the minimum and maximum sizes have different aspect ratios...)

It is undefined what happens if the current size does not fit in the constraints passed to `size_range()`.

If this function is not called, FLTK tries to figure out the range from the setting of `resizeable()`:

- If `resizeable()` is `NULL` (this is the default) then the window cannot be resized.
- If either dimension of `resizeable()` is less than 100, then that is considered the minimum size. Otherwise the `resizeable()` has a minimum size of 100.
- If either dimension of `resizeable()` is zero, then that is also the maximum size (so the window cannot resize in that direction).

#### void fltk::Window::show()

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

It is harmless to call show() multiple times. If the window is already shown then it is deiconized and raised to the top.

#### int fltk::Window::show(int argc, char **argv, int i);

This must be called after fltk::args(argc,argv) to show the "main" window, this indicates which window should be affected by any `-geometry` switch. In addition if fltk::args() has not been called yet this does so, this is a useful shortcut for the main window in a small program.

#### void fltk::Window::child_of(const fltk::Window* parent);
const fltk::Window* child_of() const;

Tell the system that this window will not have an icon, it will dissappear and reappear when the parent window is iconized or shown, and it is forced to always be above the parent window. On X this is called a "Transient window", and Windows calls this a "overlapping child". This value is different than the fltk::Widget::parent(), which must be zero).

On both X and win32 changing this value causes the window to be removed from the screen.

Win32 and some X window managers have an annoying bug where calling show() on this window will also raise the parent window to right below this, making many useful user interface designs impossible! On X some old window managers may ignore the "TransisentForHint" and these windows will come out the same as other windows.

If you want a dialog that blocks interaction with the other windows of your application or with all other applications, you need to look at exec() or possibly `fltk::modal()`

#### int fltk::Window::show(const fltk::Window* parent);

Same as `child_of(parent),show()`.

#### bool fltk::Window::exec(const fltk::Window* parent = 0, bool grab = false);

Simple description: the window is popped up and this function waits until the user closes it, this then returns a true if the user hit ok, false if the user cancelled or closed the window in some other way. During this time events to other windows in this application are either thrown away or redirected to this window.

This does `child_of(parent)` (using `fltk::first_window()` if parent is null). It then does `show()` to make the window visible and raise it. It then uses `fltk::modal(this,grab)` to make all events go to this window, and waits until `fltk::exit_modal()` is called (typically by the window being hidden or destroyed).

The return value is `value()` of the window, which is true only if some callback does `window->set()`. To use this, make an OK button with a callback that does this.

If parent is null the window that last received an event is used as the parent. This is convenient for popups that appear in response to a mouse or key click.

See `fltk::modal()` for what grab does. This is useful for popup menus.

#### bool fltk::Window::show_inside(const fltk::Window* frame);

Make the window with a normal system border and behavior, but place it inside the frame as though that was the desktop. This is what Windows calls "MDI". Typically the other window (which must already be shown) is a child window so that space can remain around it for a menu/tool bar.

Notice that parent() of the window must be zero and it will remain zero after this is called. Fltk uses a zero parent to indicate that the system is managing the window.

On systems that don't support nested desktops (i.e. X) this does `show(frame)`, which produces a normal overlapping window that is tied to remain atop and iconize with the frame window (IMHO this is a great improvement over MDI!).

#### virtual void fltk::Window::hide()

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

#### virtual void fltk::Window::destroy();

Hides the window and also deletes all window system information about the window, and thus returns if back to the state it was in before the first show(). It is harmless to call this if the window is already destroyed.

Subclasses can override this, if you do this you must also override the destructor and make it call destroy().

#### int fltk::Window::shown() const

Returns non-zero if `show()` has been called, but `destroy()` has not been called.

#### int fltk::Window::iconic() const

Returns true if the window is currently displayed as an icon. Returns false if the window is not shown() or hide() has been called. On X this will return true for a short time after show() is called the first time.

#### void fltk::Window::iconize()

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.

Currently there are only X and Win32 system-specific ways to control what is drawn in the icon. You should not rely on window managers displaying the icons.

#### void fltk::Window::resize(int,int,int,int)

Change the size and position of the window. If `shown()` is true, these changes are communicated to the window server (which may refuse that size and cause a further resize). If `shown()` is false, the size and position are used when `show()` is called. See `fltk::Group` for the effect of resizing on the child widgets.

You can also call the `fltk::Widget` methods `size(x,y)` and `position(w,h)`, which are inline wrappers for this virtual function.

The special value `fltk::USEDEFAULT` may be used for x and y indicate that the system should choose the window's position.

#### void fltk::Window::hotspot(int x, int y, int offscreen = 0)
void fltk::Window::hotspot(const fltk::Widget*, bool offscreen = false)
void fltk::Window::hotspot(const fltk::Widgetp, bool offscreen = false)

`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 `offscreen` is true then the window is allowed to extend off the screen (some X window managers do not allow this).

#### void fltk::Window::fullscreen()

Makes the window completely fill the screen, without any window manager border or taskbar or anything else visible (at least that is the intention, it is currenty not well implemented, only older X window managers work. The Windows and Gnome and KDE taskbars remain visible. Anybody who knows how to get this to work reliably is welcome to contribute code to do so).

You must use `fullscreen_off()` to undo this. This may not work with all X window managers (and currently it is not successful at hiding the Windows taskbar).

#### int fltk::Window::fullscreen_off(int x, int y, int w, int h)

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

#### void fltk::Window::clear_border()

You may turn off the window manager border before calling show() on the window the first time. On most window managers this means the user cannot move, iconize, or resize the window (unless your program does it).

#### bool fltk::Window::border() const

Returns false if clear_border() has been called.

#### bool fltk::Window::set_override()

Windows with this property set will use the exact position and size set by the programmer (will not be handled by the window manager) and will not have an entry in the task list. This will also clear the window's border like clear_border() above. This is used by the fltk menus and tooltips.

On X this causes "override redirect". This is only good for short-lived windows as it can confuse X window managers, however this is the only reliable and fast way to do it. This also turns on "save under" which on many X servers (like XFree86) can make the window disappear much faster by having the server rememeber what was behind it.

#### bool fltk::Window::override() const

Returns true if set_override() has been called.

#### void fltk::Window::label(const char*)
const char* fltk::Window::label() const

Gets or sets the window title bar label.

#### void fltk::Window::iconlabel(const char*)
const char* fltk::Window::iconlabel() const

Gets or sets the icon label.

#### void fltk::Window::make_current()

`make_current()` sets things up so that the drawing functions in `<fltk/draw.h>` will go into this window. This is useful for incremental update of windows, such as in an idle callback, which will make your program behave much better if it draws a slow graphic. This call does not work for fltk::DoubleBufferWindow!.

#### static fltk::Window* fltk::Window::current()

Returns the last window that was made current.

#### void fltk::Window::cursor(fltk::Cursor, fltk::Color = fltk::WHITE, fltk::Color = fltk::BLACK)

Change the cursor for this window. This always calls the system, if you are changing the cursor a lot you may want to keep track of how you set it in a static varaible and call this only if the new cursor is different. The colors only work on X, they are not implemented on WIN32.

The following constants define the mouse cursors that are available:

- `fltk::CURSOR_DEFAULT` - the default cursor, usually an arrow (0)
- `fltk::CURSOR_ARROW` - an arrow pointer
- `fltk::CURSOR_CROSS` - crosshair
- `fltk::CURSOR_WAIT` - watch or hourglass
- `fltk::CURSOR_INSERT` - I-beam
- `fltk::CURSOR_HAND` - hand (uparrow on MSWindows)
- `fltk::CURSOR_HELP` - question mark
- `fltk::CURSOR_MOVE` - 4-pointed arrow
- `fltk::CURSOR_NS` - up/down arrow
- `fltk::CURSOR_WE` - left/right arrow
- `fltk::CURSOR_NWSE` - diagonal arrow
- `fltk::CURSOR_NESW` - diagonal arrow
- `fltk::CURSOR_NONE` - invisible
- Under X you can get any XC_cursor value by passing `fltk::Cursor((XC_foo/2)+1)`).