Fl_Window.H 20 KB

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