blob: 9632895d72728e0057078b0dcc1c623b529a15d3 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl_Window.H 8593 2011-04-15 21:38:05Z manolo $"
3//
4// Window header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
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.
12//
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.
17//
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
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28/* \file
29 Fl_Window widget . */
30
31#ifndef Fl_Window_H
32#define Fl_Window_H
33
Pierre Ossmanab8aeed2012-04-25 14:57:22 +000034#ifdef WIN32
35#include <windows.h>
36#endif
37
DRC2ff39b82011-07-28 08:38:59 +000038#include "Fl_Group.H"
39
40#define FL_WINDOW 0xF0 ///< window type id all subclasses have type() >= this
41#define FL_DOUBLE_WINDOW 0xF1 ///< double window type id
42
43class Fl_X;
DRC685f17e2011-07-28 09:23:00 +000044class Fl_RGB_Image;
DRC2ff39b82011-07-28 08:38:59 +000045
46/**
47 This widget produces an actual window. This can either be a main
48 window, with a border and title and all the window management controls,
49 or a "subwindow" inside a window. This is controlled by whether or not
50 the window has a parent().
51
52 Once you create a window, you usually add children Fl_Widget
53 's to it by using window->add(child) for each new widget.
54 See Fl_Group for more information on how to add and remove children.
55
56 There are several subclasses of Fl_Window that provide
57 double-buffering, overlay, menu, and OpenGL support.
58
59 The window's callback is done if the user tries to close a window
60 using the window manager and Fl::modal() is zero or equal to the
61 window. Fl_Window has a default callback that calls Fl_Window::hide().
62*/
63class FL_EXPORT Fl_Window : public Fl_Group {
64
65 static char *default_xclass_;
66
67 friend class Fl_X;
68 Fl_X *i; // points at the system-specific stuff
69
Pierre Ossmanab8aeed2012-04-25 14:57:22 +000070 struct icon_data {
71 const void *legacy_icon;
72 Fl_RGB_Image **icons;
73 int count;
74#ifdef WIN32
75 HICON big_icon;
76 HICON small_icon;
77#endif
78 };
79
DRC2ff39b82011-07-28 08:38:59 +000080 const char* iconlabel_;
81 char* xclass_;
Pierre Ossmanab8aeed2012-04-25 14:57:22 +000082 struct icon_data *icon_;
DRC2ff39b82011-07-28 08:38:59 +000083 // size_range stuff:
84 int minw, minh, maxw, maxh;
85 int dw, dh, aspect;
86 uchar size_range_set;
DRC685f17e2011-07-28 09:23:00 +000087 int no_fullscreen_x, no_fullscreen_y, no_fullscreen_w, no_fullscreen_h;
DRC2ff39b82011-07-28 08:38:59 +000088 // cursor stuff
89 Fl_Cursor cursor_default;
DRC2ff39b82011-07-28 08:38:59 +000090 void size_range_();
91 void _Fl_Window(); // constructor innards
92
93 // unimplemented copy ctor and assignment operator
94 Fl_Window(const Fl_Window&);
95 Fl_Window& operator=(const Fl_Window&);
96
97protected:
98
99 /** Stores the last window that was made current. See current() const */
100 static Fl_Window *current_;
101 virtual void draw();
102 /** Forces the window to be drawn, this window is also made current and calls draw(). */
103 virtual void flush();
104
105 /**
106 Sets an internal flag that tells FLTK and the window manager to
107 honor position requests.
108
109 This is used internally and should not be needed by user code.
110
111 \param[in] force 1 to set the FORCE_POSITION flag, 0 to clear it
112 */
113 void force_position(int force) {
114 if (force) set_flag(FORCE_POSITION);
115 else clear_flag(FORCE_POSITION);
116 }
117 /**
118 Returns the internal state of the window's FORCE_POSITION flag.
119
120 \retval 1 if flag is set
121 \retval 0 otherwise
122
123 \see force_position(int)
124 */
125 int force_position() const { return ((flags() & FORCE_POSITION)?1:0); }
126
Pierre Ossmanab8aeed2012-04-25 14:57:22 +0000127 void free_icons();
128
DRC2ff39b82011-07-28 08:38:59 +0000129public:
130
131 /**
132 Creates a window from the given size and title.
133 If Fl_Group::current() is not NULL, the window is created as a
134 subwindow of the parent window.
135
136 The (w,h) form of the constructor creates a top-level window
137 and asks the window manager to position the window. The (x,y,w,h)
138 form of the constructor either creates a subwindow or a
139 top-level window at the specified location (x,y) , subject to window
140 manager configuration. If you do not specify the position of the
141 window, the window manager will pick a place to show the window
142 or allow the user to pick a location. Use position(x,y)
143 or hotspot() before calling show() to request a
144 position on the screen. See Fl_Window::resize()
145 for some more details on positioning windows.
146
147 Top-level windows initially have visible() set to 0
148 and parent() set to NULL. Subwindows initially
149 have visible() set to 1 and parent() set to
150 the parent window pointer.
151
152 Fl_Widget::box() defaults to FL_FLAT_BOX. If you plan to
153 completely fill the window with children widgets you should
154 change this to FL_NO_BOX. If you turn the window border off
155 you may want to change this to FL_UP_BOX.
156
157 \see Fl_Window(int x, int y, int w, int h, const char* title)
158 */
159 Fl_Window(int w, int h, const char* title= 0);
160 /** Creates a window from the given position, size and title.
161
162 \see Fl_Window(int w, int h, const char *title)
163 */
164 Fl_Window(int x, int y, int w, int h, const char* title = 0);
165 /**
166 The destructor <I>also deletes all the children</I>. This allows a
167 whole tree to be deleted at once, without having to keep a pointer to
168 all the children in the user code. A kludge has been done so the
169 Fl_Window and all of its children can be automatic (local)
170 variables, but you must declare the Fl_Window <I>first</I> so
171 that it is destroyed last.
172 */
173 virtual ~Fl_Window();
174
175 virtual int handle(int);
176
177 /**
178 Changes the size and position of the window. If shown() is true,
179 these changes are communicated to the window server (which may
180 refuse that size and cause a further resize). If shown() is
181 false, the size and position are used when show() is called.
182 See Fl_Group for the effect of resizing on the child widgets.
183
184 You can also call the Fl_Widget methods size(x,y) and position(w,h),
185 which are inline wrappers for this virtual function.
186
187 A top-level window can not force, but merely suggest a position and
188 size to the operating system. The window manager may not be willing or
189 able to display a window at the desired position or with the given
190 dimensions. It is up to the application developer to verify window
191 parameters after the resize request.
192 */
193 virtual void resize(int,int,int,int);
194 /**
195 Sets whether or not the window manager border is around the
196 window. The default value is true. void border(int) can be
197 used to turn the border on and off. <I>Under most X window
198 managers this does not work after show() has been called,
199 although SGI's 4DWM does work.</I>
200 */
201 void border(int b);
202 /**
203 Fast inline function to turn the window manager border
204 off. It only works before show() is called.
205 */
206 void clear_border() {set_flag(NOBORDER);}
207 /** See void Fl_Window::border(int) */
208 unsigned int border() const {return !(flags() & NOBORDER);}
209 /** Activates the flags NOBORDER|FL_OVERRIDE */
210 void set_override() {set_flag(NOBORDER|OVERRIDE);}
211 /** Returns non zero if FL_OVERRIDE flag is set, 0 otherwise. */
212 unsigned int override() const { return flags()&OVERRIDE; }
213 /**
214 A "modal" window, when shown(), will prevent any events from
215 being delivered to other windows in the same program, and will also
216 remain on top of the other windows (if the X window manager supports
217 the "transient for" property). Several modal windows may be shown at
218 once, in which case only the last one shown gets events. You can see
219 which window (if any) is modal by calling Fl::modal().
220 */
221 void set_modal() {set_flag(MODAL);}
222 /** Returns true if this window is modal. */
223 unsigned int modal() const {return flags() & MODAL;}
224 /**
225 A "non-modal" window (terminology borrowed from Microsoft Windows)
226 acts like a modal() one in that it remains on top, but it has
227 no effect on event delivery. There are <I>three</I> states for a
228 window: modal, non-modal, and normal.
229 */
230 void set_non_modal() {set_flag(NON_MODAL);}
231 /** Returns true if this window is modal or non-modal. */
232 unsigned int non_modal() const {return flags() & (NON_MODAL|MODAL);}
233
234 /**
235 Marks the window as a menu window.
236
237 This is intended for internal use, but it can also be used if you
238 write your own menu handling. However, this is not recommended.
239
240 This flag is used for correct "parenting" of windows in communication
241 with the windowing system. Modern X window managers can use different
242 flags to distinguish menu and tooltip windows from normal windows.
243
244 This must be called before the window is shown and cannot be changed
245 later.
246 */
247 void set_menu_window() {set_flag(MENU_WINDOW);}
248
249 /** Returns true if this window is a menu window. */
250 unsigned int menu_window() const {return flags() & MENU_WINDOW;}
251
252 /**
253 Marks the window as a tooltip window.
254
255 This is intended for internal use, but it can also be used if you
256 write your own tooltip handling. However, this is not recommended.
257
258 This flag is used for correct "parenting" of windows in communication
259 with the windowing system. Modern X window managers can use different
260 flags to distinguish menu and tooltip windows from normal windows.
261
262 This must be called before the window is shown and cannot be changed
263 later.
264
265 \note Since Fl_Tooltip_Window is derived from Fl_Menu_Window, this
266 also \b clears the menu_window() state.
267 */
268 void set_tooltip_window() { set_flag(TOOLTIP_WINDOW);
269 clear_flag(MENU_WINDOW); }
270 /** Returns true if this window is a tooltip window. */
271 unsigned int tooltip_window() const {return flags() & TOOLTIP_WINDOW;}
272
273 /**
274 Positions the window so that the mouse is pointing at the given
275 position, or at the center of the given widget, which may be the
276 window itself. If the optional offscreen parameter is
277 non-zero, then the window is allowed to extend off the screen (this
278 does not work with some X window managers). \see position()
279 */
280 void hotspot(int x, int y, int offscreen = 0);
281 /** See void Fl_Window::hotspot(int x, int y, int offscreen = 0) */
282 void hotspot(const Fl_Widget*, int offscreen = 0);
283 /** See void Fl_Window::hotspot(int x, int y, int offscreen = 0) */
284 void hotspot(const Fl_Widget& p, int offscreen = 0) {hotspot(&p,offscreen);}
285
286 /**
287 Undoes the effect of a previous resize() or show() so that the next time
288 show() is called the window manager is free to position the window.
289
290 This is for Forms compatibility only.
291
292 \deprecated please use force_position(0) instead
293 */
294 void free_position() {clear_flag(FORCE_POSITION);}
295 /**
296 Sets the allowable range the user can resize this window to.
297 This only works for top-level windows.
298 <UL>
299 <LI>minw and minh are the smallest the window can be.
300 Either value must be greater than 0.</LI>
301 <LI>maxw and maxh are the largest the window can be. If either is
302 <I>equal</I> to the minimum then you cannot resize in that direction.
303 If either is zero then FLTK picks a maximum size in that direction
304 such that the window will fill the screen.</LI>
305 <LI>dw and dh are size increments. The window will be constrained
306 to widths of minw + N * dw, where N is any non-negative integer.
307 If these are less or equal to 1 they are ignored (this is ignored
308 on WIN32).</LI>
309 <LI>aspect is a flag that indicates that the window should preserve its
310 aspect ratio. This only works if both the maximum and minimum have
311 the same aspect ratio (ignored on WIN32 and by many X window managers).
312 </LI>
313 </UL>
314
315 If this function is not called, FLTK tries to figure out the range
316 from the setting of resizable():
317 <UL>
318 <LI>If resizable() is NULL (this is the default) then the window cannot
319 be resized and the resize border and max-size control will not be
320 displayed for the window.</LI>
321 <LI>If either dimension of resizable() is less than 100, then that is
322 considered the minimum size. Otherwise the resizable() has a minimum
323 size of 100.</LI>
324 <LI>If either dimension of resizable() is zero, then that is also the
325 maximum size (so the window cannot resize in that direction).</LI>
326 </UL>
327
328 It is undefined what happens if the current size does not fit in the
329 constraints passed to size_range().
330 */
331 void size_range(int a, int b, int c=0, int d=0, int e=0, int f=0, int g=0) {
332 minw=a; minh=b; maxw=c; maxh=d; dw=e; dh=f; aspect=g; size_range_();}
333
334 /** See void Fl_Window::label(const char*) */
335 const char* label() const {return Fl_Widget::label();}
336 /** See void Fl_Window::iconlabel(const char*) */
337 const char* iconlabel() const {return iconlabel_;}
338 /** Sets the window title bar label. */
339 void label(const char*);
340 /** Sets the icon label. */
341 void iconlabel(const char*);
342 /** Sets the icon label. */
343 void label(const char* label, const char* iconlabel); // platform dependent
344 void copy_label(const char* a);
345
346 static void default_xclass(const char*);
347 static const char *default_xclass();
348 const char* xclass() const;
349 void xclass(const char* c);
Pierre Ossmanab8aeed2012-04-25 14:57:22 +0000350
351 static void default_icon(const Fl_RGB_Image*);
352 static void default_icons(const Fl_RGB_Image*[], int);
353 void icon(const Fl_RGB_Image*);
354 void icons(const Fl_RGB_Image*[], int);
355
356#ifdef WIN32
357 static void default_icons(HICON big_icon, HICON small_icon);
358 void icons(HICON big_icon, HICON small_icon);
359#endif
360
361 /* for legacy compatibility */
DRC2ff39b82011-07-28 08:38:59 +0000362 const void* icon() const;
363 void icon(const void * ic);
364
365 /**
366 Returns non-zero if show() has been called (but not hide()
367 ). You can tell if a window is iconified with (w->shown()
368 && !w->visible()).
369 */
370 int shown() {return i != 0;}
371 /**
372 Puts the window on the screen. Usually (on X) this has the side
373 effect of opening the display.
374
375 If the window is already shown then it is restored and raised to the
376 top. This is really convenient because your program can call show()
377 at any time, even if the window is already up. It also means that
378 show() serves the purpose of raise() in other toolkits.
379
380 Fl_Window::show(int argc, char **argv) is used for top-level
381 windows and allows standard arguments to be parsed from the
382 command-line.
383
384 \see Fl_Window::show(int argc, char **argv)
385 */
386 virtual void show();
387 /**
388 Removes the window from the screen. If the window is already hidden or
389 has not been shown then this does nothing and is harmless.
390 */
391 virtual void hide();
392 /**
393 Puts the window on the screen and parses command-line arguments.
394
395 Usually (on X) this has the side effect of opening the display.
396
397 This form should be used for top-level windows, at least for the
398 first (main) window. It allows standard arguments to be parsed
399 from the command-line. You can use \p argc and \p argv from
400 main(int argc, char **argv) for this call.
401
402 The first call also sets up some system-specific internal
403 variables like the system colors.
404
405 \todo explain which system parameters are set up.
406
407 \param argc command-line argument count, usually from main()
408 \param argv command-line argument vector, usually from main()
409
410 \see virtual void Fl_Window::show()
411 */
412 void show(int argc, char **argv);
413 /**
414 Makes the window completely fill the screen, without any window
415 manager border visible. You must use fullscreen_off() to undo
DRC685f17e2011-07-28 09:23:00 +0000416 this.
417
418 \note On some platforms, this can result in the keyboard being
419 grabbed. The window may also be recreated, meaning hide() and
420 show() will be called.
DRC2ff39b82011-07-28 08:38:59 +0000421 */
422 void fullscreen();
423 /**
DRC685f17e2011-07-28 09:23:00 +0000424 Turns off any side effects of fullscreen()
425 */
426 void fullscreen_off();
427 /**
DRC2ff39b82011-07-28 08:38:59 +0000428 Turns off any side effects of fullscreen() and does
429 resize(x,y,w,h).
430 */
431 void fullscreen_off(int,int,int,int);
432 /**
DRC685f17e2011-07-28 09:23:00 +0000433 Returns non zero if FULLSCREEN flag is set, 0 otherwise.
434 */
435 unsigned int fullscreen_active() const { return flags() & FULLSCREEN; }
436 /**
DRC2ff39b82011-07-28 08:38:59 +0000437 Iconifies the window. If you call this when shown() is false
438 it will show() it as an icon. If the window is already
439 iconified this does nothing.
440
441 Call show() to restore the window.
442
443 When a window is iconified/restored (either by these calls or by the
444 user) the handle() method is called with FL_HIDE and
445 FL_SHOW events and visible() is turned on and off.
446
447 There is no way to control what is drawn in the icon except with the
448 string passed to Fl_Window::xclass(). You should not rely on
449 window managers displaying the icons.
450 */
451 void iconize();
452
453 int x_root() const ;
454 int y_root() const ;
455
456 static Fl_Window *current();
457 /**
458 Sets things up so that the drawing functions in <FL/fl_draw.H> will go
459 into this window. This is useful for incremental update of windows, such
460 as in an idle callback, which will make your program behave much better
461 if it draws a slow graphic. <B>Danger: incremental update is very hard to
462 debug and maintain!</B>
463
464 This method only works for the Fl_Window and Fl_Gl_Window derived classes.
465 */
466 void make_current();
467
468 // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
469 virtual Fl_Window* as_window() { return this; }
470
471 /**
472 Changes the cursor for this window. This always calls the system, if
473 you are changing the cursor a lot you may want to keep track of how
474 you set it in a static variable and call this only if the new cursor
475 is different.
476
477 The type Fl_Cursor is an enumeration defined in <FL/Enumerations.H>.
DRC2ff39b82011-07-28 08:38:59 +0000478
DRC685f17e2011-07-28 09:23:00 +0000479 \see cursor(const Fl_RGB_Image*, int, int), default_cursor()
DRC2ff39b82011-07-28 08:38:59 +0000480 */
DRC685f17e2011-07-28 09:23:00 +0000481 void cursor(Fl_Cursor);
482 void cursor(const Fl_RGB_Image*, int, int);
483 void default_cursor(Fl_Cursor);
484
485 /* for legacy compatibility */
486 void cursor(Fl_Cursor c, Fl_Color, Fl_Color=FL_WHITE) { cursor(c); };
487 void default_cursor(Fl_Cursor c, Fl_Color, Fl_Color=FL_WHITE) { default_cursor(c); };
488
DRC2ff39b82011-07-28 08:38:59 +0000489 static void default_callback(Fl_Window*, void* v);
490
491 /** Returns the window width including any frame added by the window manager.
492
493 Same as w() if applied to a subwindow.
494 */
495 int decorated_w();
496 /** Returns the window height including any window title bar and any frame
497 added by the window manager.
498
499 Same as h() if applied to a subwindow.
500 */
501 int decorated_h();
502
503};
504
505#endif
506
507//
508// End of "$Id: Fl_Window.H 8593 2011-04-15 21:38:05Z manolo $".
509//