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