class Fl_Window : public Fl_Group
This widget produces an actual X 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 Fl_Widgets to it
by using window->add(child) for each new widget. See Fl_Group for more information on how to add and
remove children.
Depending on what you need to draw, there are subclasses of
Fl_Window with some extra drawing capabilities:
The window's callback is done if the user tries to close a window
using the window manager (and Fl::modal() is zero or equal to this).
Fl_Window has a default callback that calls Fl_Window::hide() and
calls exit(0) if this is the last window (not counting child,
non_modal(), and modal() windows).
Methods
Fl_Window::Fl_Window(int,int,int,int, const char * = 0);
Fl_Window::Fl_Window(int,int, const char * = 0);
The first constructor takes 4 int arguments to create the window with
a preset position and size. The second constructor with 2 arguments
will create the window with a preset size, but the X window manager
will choose the position according to it's own whims.
Fl_Widget::box() is set to FL_FLAT_BOX. If you plan to completely fill
the window with children widgets you should change this to FL_NO_BOX.
If you want to turn the border off you may want to change this to
FL_UP_BOX.
virtual Fl_Window::~Fl_Window();
The destructor does hide(). Because this is a Fl_Group, it also
deletes all the children, which means you must be careful if the
children are not allocated with new. See Fl_Group for more information.
int Fl::x();
int Fl::y();
int Fl::w();
int Fl::h();
Return the size and position of the screen/root/desktop. In all
current implementations x() and y() return zero. w() and h() will
cause the display to be opened if it is not opened yet. These are
useful for setting the size and position of windows.
void Fl_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 integer >= 0). If
these are less or equal to 1 they are ignored.
- aspect is a flag that indicates that the window should
preserve it's aspect ratio. I wanted this to mean that the allowable
sizes are on a straight line between the minimum and maximum sizes.
Unfortunately X is stupid so this only works if both the maximum and
minimum have the same aspect ratio.
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 and the resize
border and max-size control will disappear in a MWM-style window
manager.
- 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).
It is undefined what happens if the current size does not fit in
the constraints passed to size_range. [imho, this should only
affect what happens when the user tries to change the window
size. The program should be able to set the size to any value, and
calling this should not change the window. Unfortunately most X
window managers do not act this way!]
virtual void Fl_Window::show();
Put the window on the screen. Usually this will have the side effect
of opening the display.
If the window is already shown then it is deiconized 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.
int Fl_Window::show(int argc, char **argv, int i);
void Fl_Window::show(int argc, char **argv);
virtual void Fl_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). On X
this actually destroys the xid.
int Fl_Window::shown() const ;
Returns non-zero between calls to show() and hide(). You can tell if
a window is iconized with (w->shown() && !w->visible())
.
void Fl_Window::iconize();
Iconizes/minimizes the window. If you call this when shown() is false
it will show() it as an icon. If the window is already iconized this
does nothing.
Call show() to de-iconize the window.
When a window is iconized/deiconized (either by these calls or by
the user) the handle() method is called with FL_HIDE/FL_SHOW and
visible() is turned on and off.
There is no way to control what is drawn in the icon except with
the string passed to Fl_Window::xclass(). You should not rely on
window managers displaying the icons, anyway.
Fl_Window *Fl::first_window();
Fl_Window *Fl::next_window(const Fl_Window*);
You can use these calls to iterate through all the windows that are
shown(). This is also useful to test if there are any windows
displayed, if none Fl::first_window() returns null.
void Fl_Window::resize(int,int,int,int);
Change the size and position of the window. If shown() then these
changes are communicated to the window server (which may refuse that
size and cause a further resize). If not shown() the size and
position are used when show() is called (on X this is passed as a
"user-specified size and position"). See Fl_Group for the effect of resizing on the
child widgets.
You can also call the Fl_Widget methods size(x,y) and
position(w,h), which are inline wrappers for this virtual function.
void Fl_Window::free_position();
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.
void Fl_Window::hotspot(int x, int y, int offscreen = 0);
void Fl_Window::hotspot(const Fl_Widget*, int offscreen = 0);
void Fl_Window::hotspot(const Fl_Widget& p, int offscreen = 0);
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
non-zero, then the window is allowed to extend off the screen (this
will not work with some X window managers).
void Fl_Window::fullscreen();
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.
int Fl_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).
int Fl_Window::border(int);
void Fl_Window::clear_border();
uchar Fl_Window::border() const;
Whether or not the window manager border is around the window. The
default value is true. border(n) can be used to turn the border on
and off, and returns non-zero if the value has been changed. Under
most X window managers this does not work after show() has been
called, although SGI's 4DWM does work. clear_border() is a fast inline
function to turn the border off, it only works before show() is
called.
void Fl_Window::set_modal();
uchar Fl_Window::modal() const;
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 calling Fl::modal().
void Fl_Window::set_non_modal();
uchar Fl_Window::non_modal() const;
A "non_modal" window (terminology borrowed from MSWindows) 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". Fl_Window::non_modal() returns true for
both non_modal and modal windows.
void Fl_Window::label(const char*);
const char* Fl_Window::label() const;
void Fl_Window::iconlabel(const char*);
const char* Fl_Window::iconlabel() const;
void Fl_Window::label(const char* label, const char* iconlabel);
Changing the label will tell the window system to change the title
bar. Changing the iconlabel will change the title of the icon that is
displayed when the user minimizes the window. The single-argument
version of label() sets iconlabel() to filename_name(label()). The
two-argument version sets them independently. Notice that the string
pointers are simply copied, so the strings themselves must be in
static or persistent storage.
void Fl_Window::xclass(const char*);
const char* Fl_Window::xclass() const;
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().
void Fl_Window::make_current();
static Fl_Window* Fl_Window::current();
Fl_Window::make_current() sets things up so that the drawing functions
in <FL/fl_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. [Danger, Will Robinson: incremental update is very
hard to debug and maintain!]
Under X this only works for the base Fl_Window class, not for
Fl_Double_Window or Fl_Overlay_Window! OpenGL windows have an
identically-named function to serve the same purpose, but this is not
a virtual function.
(back to contents)