1 //
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 
34 #include "Fl_Group.H"
35 
36 #define FL_WINDOW 0xF0		///< window type id all subclasses have type() >= this
37 #define FL_DOUBLE_WINDOW 0xF1   ///< double window type id
38 
39 class Fl_X;
40 
41 /**
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().
46 
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.
50 
51   There are several subclasses of Fl_Window that provide
52   double-buffering, overlay, menu, and OpenGL support.
53 
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().
57 */
58 class FL_EXPORT Fl_Window : public Fl_Group {
59 
60   static char *default_xclass_;
61 
62   friend class Fl;
63   friend class Fl_X;
64   Fl_X *i; // points at the system-specific stuff
65 
66   const char* iconlabel_;
67   char* xclass_;
68   const void* icon_;
69   // size_range stuff:
70   int minw, minh, maxw, maxh;
71   int dw, dh, aspect;
72   uchar size_range_set;
73   // cursor stuff
74   Fl_Cursor cursor_default;
75   Fl_Color cursor_fg, cursor_bg;
76   void size_range_();
77   void _Fl_Window(); // constructor innards
78 
79   // unimplemented copy ctor and assignment operator
80   Fl_Window(const Fl_Window&);
81   Fl_Window& operator=(const Fl_Window&);
82 
83 protected:
84 
85   /** Stores the last window that was made current. See current() const */
86   static Fl_Window *current_;
87   virtual void draw();
88   /** Forces the window to be drawn, this window is also made current and calls draw(). */
89   virtual void flush();
90 
91   /**
92     Sets an internal flag that tells FLTK and the window manager to
93     honor position requests.
94 
95     This is used internally and should not be needed by user code.
96 
97     \param[in] force 1 to set the FORCE_POSITION flag, 0 to clear it
98   */
force_position(int force)99   void force_position(int force) {
100     if (force) set_flag(FORCE_POSITION);
101     else clear_flag(FORCE_POSITION);
102   }
103   /**
104     Returns the internal state of the window's FORCE_POSITION flag.
105 
106     \retval 1 if flag is set
107     \retval 0 otherwise
108 
109     \see force_position(int)
110   */
force_position()111   int force_position() const { return ((flags() & FORCE_POSITION)?1:0); }
112 
113 public:
114 
115   /**
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.
119 
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.
130 
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.
135 
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.
140 
141     \see Fl_Window(int x, int y, int w, int h, const char* title)
142   */
143     Fl_Window(int w, int h, const char* title= 0);
144   /** Creates a window from the given position, size and title.
145 
146     \see Fl_Window(int w, int h, const char *title)
147   */
148     Fl_Window(int x, int y, int w, int h, const char* title = 0);
149   /**
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.
156   */
157     virtual ~Fl_Window();
158 
159   virtual int handle(int);
160 
161   /**
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.
167 
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.
170 
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.
176   */
177   virtual void resize(int,int,int,int);
178   /**
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>
184   */
185   void border(int b);
186   /**
187     Fast inline function to turn the window manager border
188     off. It only works before show() is called.
189   */
clear_border()190   void clear_border()	{set_flag(NOBORDER);}
191   /** See void Fl_Window::border(int) */
border()192   unsigned int border() const	{return !(flags() & NOBORDER);}
193   /** Activates the flags NOBORDER|FL_OVERRIDE */
set_override()194   void set_override()	{set_flag(NOBORDER|OVERRIDE);}
195   /** Returns non zero if FL_OVERRIDE flag is set, 0 otherwise. */
override()196   unsigned int override() const  { return flags()&OVERRIDE; }
197   /**
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().
204   */
set_modal()205   void set_modal()	{set_flag(MODAL);}
206   /**  Returns true if this window is modal.  */
modal()207   unsigned int modal() const	{return flags() & MODAL;}
208   /**
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.
213   */
set_non_modal()214   void set_non_modal()	{set_flag(NON_MODAL);}
215   /**  Returns true if this window is modal or non-modal. */
non_modal()216   unsigned int non_modal() const {return flags() & (NON_MODAL|MODAL);}
217 
218   /**
219     Marks the window as a menu window.
220 
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.
223 
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.
227 
228     This must be called before the window is shown and cannot be changed
229     later.
230   */
set_menu_window()231   void set_menu_window()	{set_flag(MENU_WINDOW);}
232 
233   /**  Returns true if this window is a menu window. */
menu_window()234   unsigned int menu_window() const {return flags() & MENU_WINDOW;}
235 
236   /**
237     Marks the window as a tooltip window.
238 
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.
241 
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.
245 
246     This must be called before the window is shown and cannot be changed
247     later.
248 
249     \note Since Fl_Tooltip_Window is derived from Fl_Menu_Window, this
250     also \b clears the menu_window() state.
251   */
set_tooltip_window()252   void set_tooltip_window()	{ set_flag(TOOLTIP_WINDOW);
253 				  clear_flag(MENU_WINDOW); }
254   /**  Returns true if this window is a tooltip window. */
tooltip_window()255   unsigned int tooltip_window() const {return flags() & TOOLTIP_WINDOW;}
256 
257   /**
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()
263   */
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);}
269 
270   /**
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.
273 
274     This is for Forms compatibility only.
275 
276     \deprecated please use force_position(0) instead
277   */
free_position()278   void free_position()	{clear_flag(FORCE_POSITION);}
279   /**
280     Sets the allowable range the user can resize this window to.
281     This only works for top-level windows.
282     <UL>
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
292 	on WIN32).</LI>
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).
296 	</LI>
297     </UL>
298 
299     If this function is not called, FLTK tries to figure out the range
300     from the setting of resizable():
301     <UL>
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
307 	size of 100.</LI>
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>
310     </UL>
311 
312     It is undefined what happens if the current size does not fit in the
313     constraints passed to size_range().
314   */
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_();}
317 
318   /** See void Fl_Window::label(const char*)   */
label()319   const char* label() const	{return Fl_Widget::label();}
320   /**  See void Fl_Window::iconlabel(const char*)   */
iconlabel()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);
329 
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);
336 
337   /**
338     Returns non-zero if show() has been called (but not hide()
339     ). You can tell if a window is iconified with (w->shown()
340     && !w->visible()).
341   */
shown()342   int shown() const {return i != 0;}
343   /**
344     Puts the window on the screen. Usually (on X) this has the side
345     effect of opening the display.
346 
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.
351 
352     Fl_Window::show(int argc, char **argv) is used for top-level
353     windows and allows standard arguments to be parsed from the
354     command-line.
355 
356     \see Fl_Window::show(int argc, char **argv)
357   */
358   virtual void show();
359   /**
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.
362   */
363   virtual void hide();
364   /**
365     Puts the window on the screen and parses command-line arguments.
366 
367     Usually (on X) this has the side effect of opening the display.
368 
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.
373 
374     The first call also sets up some system-specific internal
375     variables like the system colors.
376 
377     \todo explain which system parameters are set up.
378 
379     \param argc command-line argument count, usually from main()
380     \param argv command-line argument vector, usually from main()
381 
382     \see virtual void Fl_Window::show()
383   */
384   void show(int argc, char **argv);
385   /**
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.
389   */
390   void fullscreen();
391   /**
392     Turns off any side effects of fullscreen() and does
393     resize(x,y,w,h).
394   */
395   void fullscreen_off(int,int,int,int);
396   /**
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.
400 
401     Call show() to restore the window.
402 
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.
406 
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.
410   */
411   void iconize();
412 
413   int x_root() const ;
414   int y_root() const ;
415 
416  static Fl_Window *current();
417   /**
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>
423 
424     This method only works for the Fl_Window and Fl_Gl_Window derived classes.
425   */
426   void make_current();
427 
428   // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
as_window()429   virtual Fl_Window* as_window() { return this; }
430 
431   /**
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
435     is different.
436 
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.
441 
442     For back compatibility only.
443   */
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);
447 
448   /** Returns the window width including any frame added by the window manager.
449 
450    Same as w() if applied to a subwindow.
451    */
452   int decorated_w();
453   /** Returns the window height including any window title bar and any frame
454    added by the window manager.
455 
456    Same as h() if applied to a subwindow.
457    */
458   int decorated_h();
459 
460 };
461 
462 #endif
463 
464 //
465 // End of "$Id: Fl_Window.H 8593 2011-04-15 21:38:05Z manolo $".
466 //
467