2 // "$Id: Fl_Window.H 8593 2011-04-15 21:38:05Z manolo $"
4 // Window header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
36 #define FL_WINDOW 0xF0 ///< window type id all subclasses have type() >= this
37 #define FL_DOUBLE_WINDOW 0xF1 ///< double window type id
42 This widget produces an actual window. This can either be a main
43 window, with a border and title and all the window management controls,
44 or a "subwindow" inside a window. This is controlled by whether or not
45 the window has a parent().
47 Once you create a window, you usually add children Fl_Widget
48 's to it by using window->add(child) for each new widget.
49 See Fl_Group for more information on how to add and remove children.
51 There are several subclasses of Fl_Window that provide
52 double-buffering, overlay, menu, and OpenGL support.
54 The window's callback is done if the user tries to close a window
55 using the window manager and Fl::modal() is zero or equal to the
56 window. Fl_Window has a default callback that calls Fl_Window::hide().
58 class FL_EXPORT Fl_Window : public Fl_Group {
60 static char *default_xclass_;
64 Fl_X *i; // points at the system-specific stuff
66 const char* iconlabel_;
70 int minw, minh, maxw, maxh;
74 Fl_Cursor cursor_default;
75 Fl_Color cursor_fg, cursor_bg;
77 void _Fl_Window(); // constructor innards
79 // unimplemented copy ctor and assignment operator
80 Fl_Window(const Fl_Window&);
81 Fl_Window& operator=(const Fl_Window&);
85 /** Stores the last window that was made current. See current() const */
86 static Fl_Window *current_;
88 /** Forces the window to be drawn, this window is also made current and calls draw(). */
92 Sets an internal flag that tells FLTK and the window manager to
93 honor position requests.
95 This is used internally and should not be needed by user code.
97 \param[in] force 1 to set the FORCE_POSITION flag, 0 to clear it
99 void force_position(int force) {
100 if (force) set_flag(FORCE_POSITION);
101 else clear_flag(FORCE_POSITION);
104 Returns the internal state of the window's FORCE_POSITION flag.
106 \retval 1 if flag is set
109 \see force_position(int)
111 int force_position() const { return ((flags() & FORCE_POSITION)?1:0); }
116 Creates a window from the given size and title.
117 If Fl_Group::current() is not NULL, the window is created as a
118 subwindow of the parent window.
120 The (w,h) form of the constructor creates a top-level window
121 and asks the window manager to position the window. The (x,y,w,h)
122 form of the constructor either creates a subwindow or a
123 top-level window at the specified location (x,y) , subject to window
124 manager configuration. If you do not specify the position of the
125 window, the window manager will pick a place to show the window
126 or allow the user to pick a location. Use position(x,y)
127 or hotspot() before calling show() to request a
128 position on the screen. See Fl_Window::resize()
129 for some more details on positioning windows.
131 Top-level windows initially have visible() set to 0
132 and parent() set to NULL. Subwindows initially
133 have visible() set to 1 and parent() set to
134 the parent window pointer.
136 Fl_Widget::box() defaults to FL_FLAT_BOX. If you plan to
137 completely fill the window with children widgets you should
138 change this to FL_NO_BOX. If you turn the window border off
139 you may want to change this to FL_UP_BOX.
141 \see Fl_Window(int x, int y, int w, int h, const char* title)
143 Fl_Window(int w, int h, const char* title= 0);
144 /** Creates a window from the given position, size and title.
146 \see Fl_Window(int w, int h, const char *title)
148 Fl_Window(int x, int y, int w, int h, const char* title = 0);
150 The destructor <I>also deletes all the children</I>. This allows a
151 whole tree to be deleted at once, without having to keep a pointer to
152 all the children in the user code. A kludge has been done so the
153 Fl_Window and all of its children can be automatic (local)
154 variables, but you must declare the Fl_Window <I>first</I> so
155 that it is destroyed last.
157 virtual ~Fl_Window();
159 virtual int handle(int);
162 Changes the size and position of the window. If shown() is true,
163 these changes are communicated to the window server (which may
164 refuse that size and cause a further resize). If shown() is
165 false, the size and position are used when show() is called.
166 See Fl_Group for the effect of resizing on the child widgets.
168 You can also call the Fl_Widget methods size(x,y) and position(w,h),
169 which are inline wrappers for this virtual function.
171 A top-level window can not force, but merely suggest a position and
172 size to the operating system. The window manager may not be willing or
173 able to display a window at the desired position or with the given
174 dimensions. It is up to the application developer to verify window
175 parameters after the resize request.
177 virtual void resize(int,int,int,int);
179 Sets whether or not the window manager border is around the
180 window. The default value is true. void border(int) can be
181 used to turn the border on and off. <I>Under most X window
182 managers this does not work after show() has been called,
183 although SGI's 4DWM does work.</I>
187 Fast inline function to turn the window manager border
188 off. It only works before show() is called.
190 void clear_border() {set_flag(NOBORDER);}
191 /** See void Fl_Window::border(int) */
192 unsigned int border() const {return !(flags() & NOBORDER);}
193 /** Activates the flags NOBORDER|FL_OVERRIDE */
194 void set_override() {set_flag(NOBORDER|OVERRIDE);}
195 /** Returns non zero if FL_OVERRIDE flag is set, 0 otherwise. */
196 unsigned int override() const { return flags()&OVERRIDE; }
198 A "modal" window, when shown(), will prevent any events from
199 being delivered to other windows in the same program, and will also
200 remain on top of the other windows (if the X window manager supports
201 the "transient for" property). Several modal windows may be shown at
202 once, in which case only the last one shown gets events. You can see
203 which window (if any) is modal by calling Fl::modal().
205 void set_modal() {set_flag(MODAL);}
206 /** Returns true if this window is modal. */
207 unsigned int modal() const {return flags() & MODAL;}
209 A "non-modal" window (terminology borrowed from Microsoft Windows)
210 acts like a modal() one in that it remains on top, but it has
211 no effect on event delivery. There are <I>three</I> states for a
212 window: modal, non-modal, and normal.
214 void set_non_modal() {set_flag(NON_MODAL);}
215 /** Returns true if this window is modal or non-modal. */
216 unsigned int non_modal() const {return flags() & (NON_MODAL|MODAL);}
219 Marks the window as a menu window.
221 This is intended for internal use, but it can also be used if you
222 write your own menu handling. However, this is not recommended.
224 This flag is used for correct "parenting" of windows in communication
225 with the windowing system. Modern X window managers can use different
226 flags to distinguish menu and tooltip windows from normal windows.
228 This must be called before the window is shown and cannot be changed
231 void set_menu_window() {set_flag(MENU_WINDOW);}
233 /** Returns true if this window is a menu window. */
234 unsigned int menu_window() const {return flags() & MENU_WINDOW;}
237 Marks the window as a tooltip window.
239 This is intended for internal use, but it can also be used if you
240 write your own tooltip handling. However, this is not recommended.
242 This flag is used for correct "parenting" of windows in communication
243 with the windowing system. Modern X window managers can use different
244 flags to distinguish menu and tooltip windows from normal windows.
246 This must be called before the window is shown and cannot be changed
249 \note Since Fl_Tooltip_Window is derived from Fl_Menu_Window, this
250 also \b clears the menu_window() state.
252 void set_tooltip_window() { set_flag(TOOLTIP_WINDOW);
253 clear_flag(MENU_WINDOW); }
254 /** Returns true if this window is a tooltip window. */
255 unsigned int tooltip_window() const {return flags() & TOOLTIP_WINDOW;}
258 Positions the window so that the mouse is pointing at the given
259 position, or at the center of the given widget, which may be the
260 window itself. If the optional offscreen parameter is
261 non-zero, then the window is allowed to extend off the screen (this
262 does not work with some X window managers). \see position()
264 void hotspot(int x, int y, int offscreen = 0);
265 /** See void Fl_Window::hotspot(int x, int y, int offscreen = 0) */
266 void hotspot(const Fl_Widget*, int offscreen = 0);
267 /** See void Fl_Window::hotspot(int x, int y, int offscreen = 0) */
268 void hotspot(const Fl_Widget& p, int offscreen = 0) {hotspot(&p,offscreen);}
271 Undoes the effect of a previous resize() or show() so that the next time
272 show() is called the window manager is free to position the window.
274 This is for Forms compatibility only.
276 \deprecated please use force_position(0) instead
278 void free_position() {clear_flag(FORCE_POSITION);}
280 Sets the allowable range the user can resize this window to.
281 This only works for top-level windows.
283 <LI>minw and minh are the smallest the window can be.
284 Either value must be greater than 0.</LI>
285 <LI>maxw and maxh are the largest the window can be. If either is
286 <I>equal</I> to the minimum then you cannot resize in that direction.
287 If either is zero then FLTK picks a maximum size in that direction
288 such that the window will fill the screen.</LI>
289 <LI>dw and dh are size increments. The window will be constrained
290 to widths of minw + N * dw, where N is any non-negative integer.
291 If these are less or equal to 1 they are ignored (this is ignored
293 <LI>aspect is a flag that indicates that the window should preserve its
294 aspect ratio. This only works if both the maximum and minimum have
295 the same aspect ratio (ignored on WIN32 and by many X window managers).
299 If this function is not called, FLTK tries to figure out the range
300 from the setting of resizable():
302 <LI>If resizable() is NULL (this is the default) then the window cannot
303 be resized and the resize border and max-size control will not be
304 displayed for the window.</LI>
305 <LI>If either dimension of resizable() is less than 100, then that is
306 considered the minimum size. Otherwise the resizable() has a minimum
308 <LI>If either dimension of resizable() is zero, then that is also the
309 maximum size (so the window cannot resize in that direction).</LI>
312 It is undefined what happens if the current size does not fit in the
313 constraints passed to size_range().
315 void size_range(int a, int b, int c=0, int d=0, int e=0, int f=0, int g=0) {
316 minw=a; minh=b; maxw=c; maxh=d; dw=e; dh=f; aspect=g; size_range_();}
318 /** See void Fl_Window::label(const char*) */
319 const char* label() const {return Fl_Widget::label();}
320 /** See void Fl_Window::iconlabel(const char*) */
321 const char* iconlabel() const {return iconlabel_;}
322 /** Sets the window title bar label. */
323 void label(const char*);
324 /** Sets the icon label. */
325 void iconlabel(const char*);
326 /** Sets the icon label. */
327 void label(const char* label, const char* iconlabel); // platform dependent
328 void copy_label(const char* a);
330 static void default_xclass(const char*);
331 static const char *default_xclass();
332 const char* xclass() const;
333 void xclass(const char* c);
334 const void* icon() const;
335 void icon(const void * ic);
338 Returns non-zero if show() has been called (but not hide()
339 ). You can tell if a window is iconified with (w->shown()
342 int shown() const {return i != 0;}
344 Puts the window on the screen. Usually (on X) this has the side
345 effect of opening the display.
347 If the window is already shown then it is restored and raised to the
348 top. This is really convenient because your program can call show()
349 at any time, even if the window is already up. It also means that
350 show() serves the purpose of raise() in other toolkits.
352 Fl_Window::show(int argc, char **argv) is used for top-level
353 windows and allows standard arguments to be parsed from the
356 \see Fl_Window::show(int argc, char **argv)
360 Removes the window from the screen. If the window is already hidden or
361 has not been shown then this does nothing and is harmless.
365 Puts the window on the screen and parses command-line arguments.
367 Usually (on X) this has the side effect of opening the display.
369 This form should be used for top-level windows, at least for the
370 first (main) window. It allows standard arguments to be parsed
371 from the command-line. You can use \p argc and \p argv from
372 main(int argc, char **argv) for this call.
374 The first call also sets up some system-specific internal
375 variables like the system colors.
377 \todo explain which system parameters are set up.
379 \param argc command-line argument count, usually from main()
380 \param argv command-line argument vector, usually from main()
382 \see virtual void Fl_Window::show()
384 void show(int argc, char **argv);
386 Makes the window completely fill the screen, without any window
387 manager border visible. You must use fullscreen_off() to undo
388 this. This may not work with all window managers.
392 Turns off any side effects of fullscreen() and does
395 void fullscreen_off(int,int,int,int);
397 Iconifies the window. If you call this when shown() is false
398 it will show() it as an icon. If the window is already
399 iconified this does nothing.
401 Call show() to restore the window.
403 When a window is iconified/restored (either by these calls or by the
404 user) the handle() method is called with FL_HIDE and
405 FL_SHOW events and visible() is turned on and off.
407 There is no way to control what is drawn in the icon except with the
408 string passed to Fl_Window::xclass(). You should not rely on
409 window managers displaying the icons.
416 static Fl_Window *current();
418 Sets things up so that the drawing functions in <FL/fl_draw.H> will go
419 into this window. This is useful for incremental update of windows, such
420 as in an idle callback, which will make your program behave much better
421 if it draws a slow graphic. <B>Danger: incremental update is very hard to
422 debug and maintain!</B>
424 This method only works for the Fl_Window and Fl_Gl_Window derived classes.
428 // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
429 virtual Fl_Window* as_window() { return this; }
432 Changes the cursor for this window. This always calls the system, if
433 you are changing the cursor a lot you may want to keep track of how
434 you set it in a static variable and call this only if the new cursor
437 The type Fl_Cursor is an enumeration defined in <FL/Enumerations.H>.
438 (Under X you can get any XC_cursor value by passing
439 Fl_Cursor((XC_foo/2)+1)). The colors only work on X, they are
440 not implemented on WIN32.
442 For back compatibility only.
444 void cursor(Fl_Cursor, Fl_Color=FL_BLACK, Fl_Color=FL_WHITE); // platform dependent
445 void default_cursor(Fl_Cursor, Fl_Color=FL_BLACK, Fl_Color=FL_WHITE);
446 static void default_callback(Fl_Window*, void* v);
448 /** Returns the window width including any frame added by the window manager.
450 Same as w() if applied to a subwindow.
453 /** Returns the window height including any window title bar and any frame
454 added by the window manager.
456 Same as h() if applied to a subwindow.
465 // End of "$Id: Fl_Window.H 8593 2011-04-15 21:38:05Z manolo $".