You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

467 lines
17KB

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