1 /********************************************************************************
2 *                                                                               *
3 *                     A p p l i c a t i o n   O b j e c t                       *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1997,2020 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU Lesser General Public License as published by   *
10 * the Free Software Foundation; either version 3 of the License, or             *
11 * (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                 *
16 * GNU Lesser General Public License for more details.                           *
17 *                                                                               *
18 * You should have received a copy of the GNU Lesser General Public License      *
19 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
20 ********************************************************************************/
21 #ifndef FXAPP_H
22 #define FXAPP_H
23 
24 #ifndef FXOBJECT_H
25 #include "FXObject.h"
26 #endif
27 
28 namespace FX {
29 
30 
31 // Forward declarations
32 class FXApp;
33 class FXWindow;
34 class FXIcon;
35 class FXBitmap;
36 class FXCursor;
37 class FXRootWindow;
38 class FXMainWindow;
39 class FXPopup;
40 class FXFont;
41 class FXDC;
42 class FXDCWindow;
43 class FXVisual;
44 class FXGLVisual;
45 class FXGLContext;
46 class FXTranslator;
47 class FXComposeContext;
48 
49 // Opaque FOX objects
50 struct FXTimer;
51 struct FXChore;
52 struct FXSignal;
53 struct FXRepaint;
54 struct FXInput;
55 struct FXHandles;
56 struct FXInvocation;
57 
58 
59 
60 /// File input modes for addInput
61 enum FXInputMode {
62   INPUT_NONE   = 0,                 /// Inactive
63   INPUT_READ   = 1,                 /// Read input fd
64   INPUT_WRITE  = 2,                 /// Write input fd
65   INPUT_EXCEPT = 4                  /// Except input fd
66   };
67 
68 
69 /// All ways of being modal
70 enum FXModality {
71   MODAL_FOR_NONE,                 /// Non modal event loop (dispatch normally)
72   MODAL_FOR_WINDOW,               /// Modal dialog (beep if outside of modal dialog)
73   MODAL_FOR_POPUP                 /// Modal for popup (always dispatch to popup)
74   };
75 
76 
77 /// Default cursors provided by the application
78 enum FXDefaultCursor {
79   DEF_ARROW_CURSOR,                     /// Arrow cursor
80   DEF_RARROW_CURSOR,                    /// Reverse arrow cursor
81   DEF_TEXT_CURSOR,                      /// Text cursor
82   DEF_HSPLIT_CURSOR,                    /// Horizontal split cursor
83   DEF_VSPLIT_CURSOR,                    /// Vertical split cursor
84   DEF_XSPLIT_CURSOR,                    /// Cross split cursor
85   DEF_SWATCH_CURSOR,                    /// Color swatch drag cursor
86   DEF_MOVE_CURSOR,                      /// Move cursor
87   DEF_DRAGH_CURSOR,                     /// Resize horizontal edge
88   DEF_DRAGV_CURSOR,                     /// Resize vertical edge
89   DEF_DRAGTL_CURSOR,                    /// Resize upper-leftcorner
90   DEF_DRAGBR_CURSOR=DEF_DRAGTL_CURSOR,  /// Resize bottom-right corner
91   DEF_DRAGTR_CURSOR,                    /// Resize upper-right corner
92   DEF_DRAGBL_CURSOR=DEF_DRAGTR_CURSOR,  /// Resize bottom-left corner
93   DEF_DNDSTOP_CURSOR,                   /// Drag and drop stop
94   DEF_DNDASK_CURSOR,                    /// Drag and drop ask
95   DEF_DNDCOPY_CURSOR,                   /// Drag and drop copy
96   DEF_DNDMOVE_CURSOR,                   /// Drag and drop move
97   DEF_DNDLINK_CURSOR,                   /// Drag and drop link
98   DEF_CROSSHAIR_CURSOR,                 /// Cross hair cursor
99   DEF_CORNERNE_CURSOR,                  /// North-east cursor
100   DEF_CORNERNW_CURSOR,                  /// North-west cursor
101   DEF_CORNERSE_CURSOR,                  /// South-east cursor
102   DEF_CORNERSW_CURSOR,                  /// South-west cursor
103   DEF_HELP_CURSOR,                      /// Help arrow cursor
104   DEF_HAND_CURSOR,                      /// Hand cursor
105   DEF_ROTATE_CURSOR,                    /// Rotate cursor
106   DEF_BLANK_CURSOR,                     /// Blank cursor
107   DEF_WAIT_CURSOR                       /// Wait cursor
108   };
109 
110 
111 /**
112 * The Application object is the central point of a FOX user-interface.
113 * It manages the event queue, timers, signals, chores, and input sources.
114 * Each FOX application should have exactly one Application object, which
115 * is the ultimate owner of the entire widget tree; when the application
116 * object is deleted, all the widgets and other reachable resources of
117 * the widget tree are also deleted.
118 * When the Application is initialized using init(), it parses the
119 * command line arguments meant for it, and opens the display.
120 * The run() function is used to run the application; this function
121 * does not return until the user is ready to quit the application.
122 * During run(), the application processes events from the various
123 * windows and dispatches them to the appropriate handlers.
124 * Finally, a call to exit() terminates the application.
125 * The Application object also manages a registry of configuration
126 * data, which is read during init() and written back at the exit();
127 * thus, all configurations changed by the user normally persist to
128 * the next invocation of the application.
129 * Since different organizations and different applications each need
130 * to keep their own set of configuration data, an application name
131 * and vendor name can be passed in the Application object's constructor
132 * to identify a particular application's configuration data.
133 */
134 class FXAPI FXApp : public FXObject {
135   FXDECLARE(FXApp)
136 
137   // We've got many friends
138   friend class FXId;
139   friend class FXBitmap;
140   friend class FXImage;
141   friend class FXIcon;
142   friend class FXCursor;
143   friend class FXDrawable;
144   friend class FXWindow;
145   friend class FXShell;
146   friend class FXRootWindow;
147   friend class FXTopWindow;
148   friend class FXMainWindow;
149   friend class FXPopup;
150   friend class FXFont;
151   friend class FXVisual;
152   friend class FXGLVisual;
153   friend class FXGLContext;
154   friend class FXDC;
155   friend class FXDCWindow;
156   friend class FXDragCorner;
157   friend class FXDockHandler;
158   friend class FXComposeContext;
159 
160 private:
161 
162   // Platform independent private data
163   void            *display;             // Display we're talking to
164   FXHash           hash;                // Window handle hash table
165   FXRegistry       registry;            // Application setting registry
166   FXWindow        *activeWindow;        // Active toplevel window
167   FXWindow        *cursorWindow;        // Window under the cursor
168   FXWindow        *mouseGrabWindow;     // Window which grabbed the mouse
169   FXWindow        *keyboardGrabWindow;  // Window which grabbed the keyboard
170   FXWindow        *keyWindow;           // Window in which keyboard key was pressed
171   FXWindow        *selectionWindow;     // Selection window
172   FXWindow        *clipboardWindow;     // Clipboard window
173   FXWindow        *dropWindow;          // Drop target window
174   FXWindow        *dragWindow;          // Drag source window
175   FXWindow        *refresher;           // GUI refresher pointer
176   FXWindow        *refresherstop;       // GUI refresher end pointer
177   FXPopup         *popupWindow;         // Current popup window
178   FXRootWindow    *root;                // Root window
179   FXVisual        *monoVisual;          // Monochrome visual
180   FXVisual        *defaultVisual;       // Default [color] visual
181   FXTimer         *timers;              // List of timers, sorted by time
182   FXChore         *chores;              // List of chores
183   FXRepaint       *repaints;            // Unhandled repaint rectangles
184   FXTimer         *timerrecs;           // List of recycled timer records
185   FXChore         *chorerecs;           // List of recycled chore records
186   FXRepaint       *repaintrecs;         // List of recycled repaint records
187   FXInvocation    *invocation;          // Modal loop invocation
188   FXSignal        *signals;             // Array of signal records
189   FXint            signalreceived;      // Latest signal received
190   FXFont          *normalFont;          // Normal font
191   FXFont          *stockFont;           // Stock font
192   FXMutex          appMutex;            // Application wide mutex
193   FXEvent          event;               // Event
194   FXuint           stickyMods;          // Sticky modifier state
195   FXInput         *inputs;              // Input file descriptors being watched
196   FXint            ninputs;             // Number of inputs
197   FXHandles       *handles;             // Input handles
198   FXint            maxhandle;           // Maximum handle number
199   FXuchar         *ddeData;             // DDE array
200   FXuint           ddeSize;             // DDE array size
201   FXuint           maxcolors;           // Maximum number of colors to allocate
202   FXTime           typingSpeed;         // Typing speed
203   FXTime           clickSpeed;          // Double click speed
204   FXTime           scrollSpeed;         // Scroll speed
205   FXTime           scrollDelay;         // Scroll delay
206   FXTime           blinkSpeed;          // Cursor blink speed
207   FXTime           animSpeed;           // Animation speed
208   FXTime           menuPause;           // Menu popup delay
209   FXTime           toolTipPause;        // Tooltip popup delay
210   FXTime           toolTipTime;         // Tooltip display time
211   FXTime           autoHideDelay;       // Cursor autohide delay time
212   FXint            dragDelta;           // Minimum distance considered a move
213   FXint            wheelLines;          // Scroll by this many lines
214   FXint            scrollBarSize;       // Scrollbar size
215   FXColor          borderColor;         // Border color
216   FXColor          baseColor;           // Background color of GUI controls
217   FXColor          hiliteColor;         // Highlight color of GUI controls
218   FXColor          shadowColor;         // Shadow color of GUI controls
219   FXColor          backColor;           // Background color
220   FXColor          foreColor;           // Foreground color
221   FXColor          selforeColor;        // Select foreground color
222   FXColor          selbackColor;        // Select background color
223   FXColor          tipforeColor;        // Tooltip foreground color
224   FXColor          tipbackColor;        // Tooltip background color
225   FXColor          selMenuTextColor;    // Select foreground color in menus
226   FXColor          selMenuBackColor;    // Select background color in menus
227   FXCursor        *waitCursor;          // Current wait cursor
228   FXuint           waitCount;           // Number of times wait cursor was called
229   FXuint           windowCount;         // Number of windows
230   FXCursor        *cursor[DEF_WAIT_CURSOR+1];
231   FXTranslator    *translator;          // Message translator
232   FXint                appArgc;         // Argument count
233   const FXchar *const *appArgv;         // Argument vector
234   const FXchar    *inputmethod;         // Input method name
235   const FXchar    *inputstyle;          // Input method style
236   FXbool           initialized;         // Has been initialized
237 
238 private:
239   static FXApp    *app;                 // Application pointer
240 
241   // Platform dependent private stuff
242 #ifdef WIN32
243 
244   FXushort         ddeTargets;          // DDE targets atom
245   FXushort         ddeAtom;             // DDE Exchange Atom
246   FXDragType       ddeDelete;           // DDE Delete Target Atom
247   FXDragType      *ddeTypeList;         // DDE drop type list
248   FXuint           ddeNumTypes;         // DDE number of drop types
249   FXDragAction     ddeAction;           // DDE action
250   FXDragAction     ansAction;           // Reply action
251   FXDragType      *xselTypeList;        // Selection type list
252   FXuint           xselNumTypes;        // Selection number of types on list
253   void*            xdndTypes;           // Handle to file mapping object for types list
254   FXushort         xdndAware;           // XDND awareness atom
255   FXID             xdndSource;          // XDND drag source window
256   FXID             xdndTarget;          // XDND drop target window
257   FXbool           xdndStatusPending;   // XDND waiting for status feedback
258   FXbool           xdndFinishPending;   // XDND waiting for drop-confirmation
259   FXbool           xdndStatusReceived;  // XDND received at least one status
260   FXbool           xdndFinishSent;      // XDND finish sent
261   FXRectangle      xdndRect;            // XDND rectangle bounding target
262   FXID             stipples[17];        // Standard stipple bitmaps
263 
264 #else
265 
266 private:
267   FXID             wmDeleteWindow;      // Catch delete window
268   FXID             wmSaveYourself;      // Catch shutdown
269   FXID             wmQuitApp;           // Catch quit application
270   FXID             wmProtocols;         // Window manager protocols
271   FXID             wmMotifHints;        // Motif hints
272   FXID             wmTakeFocus;         // Focus explicitly set by app
273   FXID             wmClientMachine;     // Client machine
274   FXID             wmState;             // Window state
275   FXID             wmNetState;          // Extended Window Manager window state
276   FXID             wmNetIconName;       // Extended Window Manager icon name
277   FXID             wmNetWindowName;     // Extended Window Manager window name
278   FXID             wmNetSupported;      // Extended Window Manager states list
279   FXID             wmNetHidden;         // Extended Window Manager hidden
280   FXID             wmNetShaded;         // Extended Window Manager shaded
281   FXID             wmNetHMaximized;     // Extended Window Manager horizontally maximized
282   FXID             wmNetVMaximized;     // Extended Window Manager vertically maximized
283   FXID             wmNetFullScreen;     // Extended Window Manager full screen
284   FXID             wmNetBelowOthers;    // Extended Window Manager below others
285   FXID             wmNetAboveOthers;    // Extended Window Manager above others
286   FXID             wmNetNeedAttention;  // Extended Window Manager need attention
287   FXID             wmNetMoveResize;     // Extended Window Manager drag corner
288   FXID             wmNetRestack;        // Extended Window Manager change stacking order
289   FXID             wmNetPing;           // Extended Window Manager ping
290   FXID             wmNetProcessId;      // Extended Window Manager process id
291   FXID             wmNetWindowType;     // Extended Window Manager window type
292   FXID             wmWindowTypes[14];   // Window types
293   FXID             wmWindowRole;        // Window Role
294   FXID             wmClientLeader;      // Client leader
295   FXID             wmClientId;          // Client id
296   FXID             embedAtom;           // XEMBED support
297   FXID             embedInfoAtom;       // XEMBED info support
298   FXID             timestampAtom;       // Server time
299   FXID             ddeTargets;          // DDE targets atom
300   FXID             ddeAtom;             // DDE exchange atom
301   FXID             ddeDelete;           // DDE delete target atom
302   FXID             ddeIncr;             // DDE incremental data exchange atom
303   FXDragType      *ddeTypeList;         // DDE drop type list
304   FXuint           ddeNumTypes;         // DDE number of drop types
305   FXDragAction     ddeAction;           // DDE action
306   FXDragAction     ansAction;           // Reply action
307   FXID             xcbSelection;        // Clipboard selection
308   FXDragType      *xcbTypeList;         // Clipboard type list
309   FXuint           xcbNumTypes;         // Clipboard number of types on list
310   FXDragType      *xselTypeList;        // Selection type list
311   FXuint           xselNumTypes;        // Selection number of types on list
312   FXDragType      *xdndTypeList;        // XDND type list
313   FXuint           xdndNumTypes;        // XDND number of types
314   FXID             xdndProxy;           // XDND proxy atom
315   FXID             xdndAware;           // XDND awareness atom
316   FXID             xdndEnter;           // XDND enter window message
317   FXID             xdndLeave;           // XDND leave window message
318   FXID             xdndPosition;        // XDND position update message
319   FXID             xdndStatus;          // XDND status feedback message
320   FXID             xdndDrop;            // XDND drop message
321   FXID             xdndFinished;        // XDND finished message
322   FXID             xdndSelection;       // XDND selection atom
323   FXID             xdndTypes;           // XDND type list atom
324   FXID             xdndActions;         // XDND action list atom
325   FXID             xdndActionList[6];   // XDND actions
326   FXID             xdndSource;          // XDND drag source window
327   FXID             xdndTarget;          // XDND drop target window
328   FXID             xdndProxyTarget;     // XDND window to set messages to
329   FXbool           xdndStatusPending;   // XDND waiting for status feedback
330   FXbool           xdndStatusReceived;  // XDND received at least one status
331   FXbool           xdndWantUpdates;     // XDND target wants new positions while in rect
332   FXbool           xdndFinishSent;      // XDND finish sent
333   FXRectangle      xdndRect;            // XDND rectangle bounding target
334   FXint            xrrScreenChange;     // Xrandr ScreenChange event
335   FXint            xfxFixesSelection;   // Xfixes selection event
336   FXint            xInputOpcode;        // XInput2 opcode
337   FXint            xsbDevice;           // Space ball input device id
338   FXID             stipples[23];        // Standard stipple patterns
339   void            *xim;                 // Input method
340   FXbool           shmi;                // Use XSHM Image possible
341   FXbool           shmp;                // Use XSHM Pixmap possible
342   FXbool           xrender;             // XRender available
343   FXbool           synchronize;         // Synchronized
344 
345 #endif
346 
347 private:
348 
349   // Internal helper functions
350   FXApp(const FXApp&);
351   FXApp &operator=(const FXApp&);
352   static void CDECL signalhandler(int sig);
353   static void CDECL immediatesignalhandler(int sig);
354   void leaveWindow(FXWindow *window,FXWindow *ancestor);
355   void enterWindow(FXWindow *window,FXWindow *ancestor);
356   void selectionSetData(const FXWindow* window,FXDragType type,FXuchar* data,FXuint size);
357   void selectionGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size);
358   void selectionGetTypes(const FXWindow* window,FXDragType*& types,FXuint& numtypes);
359   void clipboardSetData(const FXWindow* window,FXDragType type,FXuchar* data,FXuint size);
360   void clipboardGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size);
361   void clipboardGetTypes(const FXWindow* window,FXDragType*& types,FXuint& numtypes);
362   void dragdropSetData(const FXWindow* window,FXDragType type,FXuchar* data,FXuint size);
363   void dragdropGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size);
364   void dragdropGetTypes(const FXWindow* window,FXDragType*& types,FXuint& numtypes);
365   void openInputDevices();
366   void closeInputDevices();
367 #ifdef WIN32
368   static FXival CALLBACK wndproc(FXID hwnd,FXuint iMsg,FXuval wParam,FXival lParam);
369 protected:
370   virtual FXival dispatchEvent(FXID hwnd,FXuint iMsg,FXuval wParam,FXival lParam);
371 #else
372   void addRepaint(FXID win,FXint x,FXint y,FXint w,FXint h,FXbool synth=false);
373   void removeRepaints(FXID win,FXint x,FXint y,FXint w,FXint h);
374   void scrollRepaints(FXID win,FXint dx,FXint dy);
375   static void imcreatecallback(void*,FXApp*,void*);
376   static void imdestroycallback(void*,FXApp*,void*);
377 #endif
378 
379 protected:
380 
381   /// Return true if an event arrives within blocking nanoseconds
382   virtual FXbool getNextEvent(FXRawEvent& ev,FXTime blocking=forever);
383 
384   /// Dispatch raw event
385   virtual FXbool dispatchEvent(FXRawEvent& ev);
386 
387 public:
388   long onCmdQuit(FXObject*,FXSelector,void*);
389   long onCmdDump(FXObject*,FXSelector,void*);
390   long onCmdHover(FXObject*,FXSelector,void*);
391 
392 public:
393 
394   /// Messages applications understand
395   enum {
396     ID_QUIT=1,    /// Terminate the application normally
397     ID_DUMP,      /// Dump the current widget tree
398     ID_HOVER,
399     ID_LAST
400     };
401 
402 public:
403 
404   /// Copyright information
405   static const FXuchar copyright[];
406 
407 public:
408 
409   /**
410   * Construct application object; the name and vendor strings are used
411   * as keys into the registry database for this application's settings.
412   * Only one single application object can be constructed.
413   */
414   FXApp(const FXString& name="Application",const FXString& vendor=FXString::null);
415 
416   /// Change application name
417   void setAppName(const FXString& name);
418 
419   /// Get application name
420   const FXString& getAppName() const;
421 
422   /// Change vendor name
423   void setVendorName(const FXString& name);
424 
425   /// Get vendor name
426   const FXString& getVendorName() const;
427 
428   /// Return true if input method support
429   FXbool hasInputMethod() const;
430 
431   /// Change default visual
432   void setDefaultVisual(FXVisual* vis);
433 
434   /// Get default visual
getDefaultVisual()435   FXVisual* getDefaultVisual() const { return defaultVisual; }
436 
437   /// Get monochrome visual
getMonoVisual()438   FXVisual* getMonoVisual() const { return monoVisual; }
439 
440   /// Set root Window
441   void setRootWindow(FXRootWindow* rt);
442 
443   /// Get root Window
getRootWindow()444   FXRootWindow* getRootWindow() const { return root; }
445 
446   /// Return window at the end of the focus chain
447   FXWindow *getFocusWindow() const;
448 
449   /// Get the window under the cursor, if any
getCursorWindow()450   FXWindow *getCursorWindow() const { return cursorWindow; }
451 
452   /// Get the active toplevel window, if any
getActiveWindow()453   FXWindow *getActiveWindow() const { return activeWindow; }
454 
455   /// Get current popup window, if any
getPopupWindow()456   FXPopup* getPopupWindow() const { return popupWindow; }
457 
458   /// Return window currently owning primary selection
getSelectionWindow()459   FXWindow* getSelectionWindow() const { return selectionWindow; }
460 
461   /// Return window currently owning the clipboard
getClipboardWindow()462   FXWindow* getClipboardWindow() const { return clipboardWindow; }
463 
464   /// Return drag window if a drag operation is in progress
getDragWindow()465   FXWindow* getDragWindow() const { return dragWindow; }
466 
467   /// Find window from id
468   FXWindow* findWindowWithId(FXID xid) const;
469 
470   /// Find window from root x,y, starting from given window
471   FXWindow* findWindowAt(FXint rx,FXint ry,FXID window=0) const;
472 
473   /// Change default font
474   void setNormalFont(FXFont* font);
475 
476   /// Return default font
getNormalFont()477   FXFont* getNormalFont() const { return normalFont; }
478 
479   /// Begin of wait-cursor block; wait-cursor blocks may be nested.
480   void beginWaitCursor();
481 
482   /// End of wait-cursor block
483   void endWaitCursor();
484 
485   /// Change to a new wait cursor
486   void setWaitCursor(FXCursor *cur);
487 
488   /// Return current wait cursor
getWaitCursor()489   FXCursor* getWaitCursor() const { return waitCursor; }
490 
491   /// Change default cursor
492   void setDefaultCursor(FXDefaultCursor which,FXCursor* cur);
493 
494   /// Obtain a default cursor
getDefaultCursor(FXDefaultCursor which)495   FXCursor* getDefaultCursor(FXDefaultCursor which) const { return cursor[which]; }
496 
497   /// Register new DND type
498   FXDragType registerDragType(const FXString& name) const;
499 
500   /// Get drag type name
501   FXString getDragTypeName(FXDragType type) const;
502 
503   /**
504   * Change message translator.
505   * The new translator will be owned by FXApp.
506   */
507   void setTranslator(FXTranslator* trans);
508 
509   /**
510   * Return message translator.
511   */
getTranslator()512   FXTranslator* getTranslator() const { return translator; }
513 
514   /// Return pointer
getDisplay()515   void* getDisplay() const { return display; }
516 
517   /// Connection to display; this is called by init()
518   virtual FXbool openDisplay(const FXchar* dpy=NULL);
519 
520   /// Close connection to the display
521   virtual FXbool closeDisplay();
522 
523   /**
524   * Add timeout message sel to be sent to target object tgt after an interval of ns
525   * nanoseconds; the timer fires only once after the interval expires.
526   * The void* ptr is user data which will be passed into the void* ptr of the message
527   * handler.
528   * If a timer with the same target and message already exists, it will be rescheduled.
529   * Note: the smallest interval that one can wait is actually much larger
530   * than a nanosecond; on Unix systems, the smallest interval is about 1000 ns,
531   * whereas on Windows, it is about 1000000 ns.
532   * Return data pointer from original timeout, if any.
533   */
534   FXptr addTimeout(FXObject* tgt,FXSelector sel,FXTime ns=1000000000,FXptr ptr=NULL);
535 
536   /**
537   * Add deadline timeout message sel to be sent to target object tgt when the due time,
538   * expressed in nanoseconds since Epoch (Jan 1, 1970), is reached.
539   * This is the preferred way to schedule regularly occuring events, as the exact time of issue will
540   * not suffer accumulating errors as with the addTimeout() method.  However, it is important to ensure
541   * that the due time is sufficiently far into the future, as otherwise the system may be swamped
542   * executing nothing but timeout messages.
543   * Return data pointer from original timeout, if any.
544   */
545   FXptr addDeadline(FXObject* tgt,FXSelector sel,FXTime due=forever,FXptr ptr=NULL);
546 
547   /**
548   * Remove timeout identified by target object tgt and message sel; if sel=0, remove all timeouts which
549   * reference object tgt.
550   * Return data pointer from original timeout, if any.
551   */
552   FXptr removeTimeout(FXObject* tgt,FXSelector sel=0);
553 
554   /**
555   * Return true if a timeout with target object tgt and message sel has been set;
556   * if sel=0, return true if any timeout has been set with target object tgt.
557   */
558   FXbool hasTimeout(FXObject *tgt,FXSelector sel=0) const;
559 
560   /**
561   * Return the time (in nanoseconds) remaining until the timer identified by target object
562   * tgt and message sel will fire.
563   * If the timer is past due, 0 is returned.  If there is no such timer, the constant
564   * forever (LLONG_MAX) is returned.  If sel=0, return the earliest timeout that will be
565   * received by target object tgt.
566   */
567   FXTime remainingTimeout(FXObject *tgt,FXSelector sel=0) const;
568 
569   /**
570   * Add a chore message sel to be sent to target object tgt when
571   * the system becomes idle, i.e. there are no events to be processed.
572   * The void* ptr is user data which will be passed into the void* ptr
573   * of the message handler. If a chore with the same target and message
574   * already exists, it will be rescheduled.
575   * Returns the data pointer from the original chore, if any.
576   */
577   FXptr addChore(FXObject* tgt,FXSelector sel,FXptr ptr=NULL);
578 
579   /**
580   * Remove chore identified by target object tgt and message sel; if sel=0,
581   * remove all idle processing messages which reference object tgt.
582   * Returns the data pointer from the original chore, if any.
583   */
584   FXptr removeChore(FXObject* tgt,FXSelector sel=0);
585 
586   /**
587   * Return true if a chore with target object tgt and message sel has been set;
588   * if sel=0, return true if any chore has been set with target object tgt.
589   */
590   FXbool hasChore(FXObject *tgt,FXSelector sel=0) const;
591 
592   /**
593   * Add signal processing message to be sent to target object when
594   * the signal sig is raised; flags are to be set as per POSIX definitions.
595   * When immediate is true, the message will be sent to the target right away;
596   * this should be used with extreme care as the application is interrupted
597   * at an unknown point in its execution.
598   */
599   void addSignal(FXint sig,FXObject* tgt,FXSelector sel,FXbool immediate=false,FXuint flags=0);
600 
601   /// Remove signal message for signal sig
602   void removeSignal(FXint sig);
603 
604   /**
605   * Add a file descriptor fd to be watched for activity as determined by
606   * mode, where mode is a bitwise OR of (INPUT_READ, INPUT_WRITE, INPUT_EXCEPT).
607   * A message of type SEL_IO_READ, SEL_IO_WRITE, or SEL_IO_EXCEPT will be sent
608   * to the target when the specified activity is detected on the file descriptor;
609   * the void* ptr is user data which will be passed into the void* ptr of the
610   * mesage handler; often you will want to pass the file descriptor fd itself
611   * as the value for ptr so that the message handler knows which file descriptor
612   * is involved.
613   */
614   FXbool addInput(FXObject *tgt,FXSelector sel,FXInputHandle fd,FXuint mode=INPUT_READ,FXptr ptr=NULL);
615 
616   /**
617   * Remove input message and target object for the specified file descriptor
618   * and mode, which is a bitwise OR of (INPUT_READ, INPUT_WRITE, INPUT_EXCEPT).
619   * Omitting the last parameter will delete all the handlers associated with the
620   * file descriptor.
621   */
622   FXbool removeInput(FXInputHandle fd,FXuint mode=INPUT_READ);
623 
624   /// Return key state of given key
625   FXbool getKeyState(FXuint keysym) const;
626 
627   /// Peek to determine if there's an event
628   FXbool peekEvent();
629 
630   /// Perform one event dispatch; return true if event was dispatched
631   FXbool runOneEvent(FXTime blocking=forever);
632 
633   /**
634   * Run the main application event loop until stop() is called,
635   * and return the exit code passed as argument to stop().
636   */
637   FXint run();
638 
639   /**
640   * Run an event loop till some flag becomes non-zero, and
641   * then return.
642   */
643   FXint runUntil(FXuint& condition);
644 
645   /**
646   * Run non-modal event loop while events arrive within blocking nanoseconds.
647   * Returns when no new events arrive in this time, and no timers, or chores
648   * are outstanding.
649   */
650   FXint runWhileEvents(FXTime blocking=0);
651 
652   /**
653   * Run modal event loop while events arrive within blocking nanoseconds.
654   * Returns 1 when all events in the queue have been handled, and 0 when
655   * the event loop was terminated due to stop() or stopModal().
656   * Except for the modal window and its children, user input to all windows
657   * is blocked; if the modal window is NULL, all user input is blocked.
658   */
659   FXint runModalWhileEvents(FXWindow* window=NULL,FXTime blocking=0);
660 
661   /**
662   * Run modal event loop, blocking keyboard and mouse events to all windows
663   * until stopModal is called.
664   */
665   FXint runModal();
666 
667   /**
668   * Run a modal event loop for the given window, until stop() or stopModal() is
669   * called. Except for the modal window and its children, user input to all
670   * windows is blocked; if the modal window is NULL all user input is blocked.
671   */
672   FXint runModalFor(FXWindow* window);
673 
674   /**
675   * Run modal while window is shown, or until stop() or stopModal() is called.
676   * Except for the modal window and its children, user input to all windows
677   * is blocked; if the modal window is NULL all user input is blocked.
678   */
679   FXint runModalWhileShown(FXWindow* window);
680 
681   /**
682   * Run popup menu while shown, until stop() or stopModal() is called.
683   * Also returns when entering previous cascading popup menu.
684   */
685   FXint runPopup(FXWindow* window);
686 
687   /// True if the window is modal
688   FXbool isModal(FXWindow* window) const;
689 
690   /// Return window of current modal loop
691   FXWindow* getModalWindow() const;
692 
693   /// Return mode of current modal loop
694   FXModality getModality() const;
695 
696   /**
697   * Terminate the outermost event loop, and all inner modal loops;
698   * All more deeper nested event loops will be terminated with code equal
699   * to 0, while the outermost event loop will return code equal to value.
700   */
701   void stop(FXint value=0);
702 
703   /**
704   * Break out of the matching modal loop, returning code equal to value.
705   * All deeper nested event loops are terminated with code equal to 0.
706   */
707   void stopModal(FXWindow* window,FXint value=0);
708 
709   /**
710   * Break out of the innermost modal loop, returning code equal to value.
711   */
712   void stopModal(FXint value=0);
713 
714   /**
715   * Schedule SEL_UPDATE refreshes on the entire widget tree, to be
716   * performed at some future time.
717   */
718   void refresh();
719 
720   /**
721   * Perform SEL_UPDATE refreshes on the entire widget tree immediately.
722   */
723   void forceRefresh();
724 
725   /**
726   * Flush drawing commands to display; if sync then wait till drawing commands
727   * have been performed.
728   */
729   void flush(FXbool sync=false);
730 
731   /**
732   * Paint all windows marked for repainting.
733   * On return all the applications windows have been painted.
734   */
735   void repaint();
736 
737   /// Get argument count
getArgc()738   FXint getArgc() const { return appArgc; }
739 
740   /// Get argument vector
getArgv()741   const FXchar *const *getArgv() const { return appArgv; }
742 
743   /// Has application been initialized
isInitialized()744   FXbool isInitialized() const { return initialized; }
745 
746   /**
747   * Initialize application.
748   * Parses and removes common command line arguments, reads the registry.
749   * Finally, if connect is true, it opens the display.
750   */
751   virtual void init(int& argc,char** argv,FXbool connect=true);
752 
753   /**
754   * Exit application.
755   * Closes the display and writes the registry.
756   */
757   virtual void exit(FXint code=0);
758 
759   /**
760   * Return a reference to the registry.  The registry keeps
761   * settings and configuration information for an application,
762   * which are automatically loaded when the application starts
763   * up, and saved when the application terminates.
764   */
reg()765   FXRegistry& reg(){ return registry; }
766 
767   /**
768   * Return a reference to the application-wide mutex.
769   * Normally, the main user interface thread holds this mutex,
770   * insuring that no other threads are modifying data during the
771   * processing of user interface messages. However, whenever the
772   * main user interface thread blocks for messages, it releases
773   * this mutex, to allow other threads to modify the same data.
774   * When a new message becomes available, the main user interface
775   * thread regains the mutex prior to dispatching the message.
776   * Other threads should hold this mutex only for short durations,
777   * so as to not starve the main user interface thread.
778   */
mutex()779   FXMutex& mutex(){ return appMutex; }
780 
781   /// Beep the speaker
782   void beep();
783 
784   /// Obtain application-wide timing constants, in nanoseconds
getTypingSpeed()785   FXTime getTypingSpeed() const { return typingSpeed; }
getClickSpeed()786   FXTime getClickSpeed() const { return clickSpeed; }
getScrollSpeed()787   FXTime getScrollSpeed() const { return scrollSpeed; }
getScrollDelay()788   FXTime getScrollDelay() const { return scrollDelay; }
getBlinkSpeed()789   FXTime getBlinkSpeed() const { return blinkSpeed; }
getAnimSpeed()790   FXTime getAnimSpeed() const { return animSpeed; }
getMenuPause()791   FXTime getMenuPause() const { return menuPause; }
getToolTipPause()792   FXTime getToolTipPause() const { return toolTipPause; }
getToolTipTime()793   FXTime getToolTipTime() const { return toolTipTime; }
getAutoHideDelay()794   FXTime getAutoHideDelay() const { return autoHideDelay; }
795 
796   /// Change application-wide timing constants, in nanoseconds
797   void setTypingSpeed(FXTime speed);
798   void setClickSpeed(FXTime speed);
799   void setScrollSpeed(FXTime speed);
800   void setScrollDelay(FXTime delay);
801   void setBlinkSpeed(FXTime speed);
802   void setAnimSpeed(FXTime speed);
803   void setMenuPause(FXTime pause);
804   void setToolTipPause(FXTime pause);
805   void setToolTipTime(FXTime time);
806   void setAutoHideDelay(FXTime time);
807 
808   /// Access drag hysteresis
809   void setDragDelta(FXint delta);
getDragDelta()810   FXint getDragDelta() const { return dragDelta; }
811 
812   /// Access mouse wheel scroll lines
813   void setWheelLines(FXint lines);
getWheelLines()814   FXint getWheelLines() const { return wheelLines; }
815 
816   /// Access scroll bar slot size
817   void setScrollBarSize(FXint size);
getScrollBarSize()818   FXint getScrollBarSize() const { return scrollBarSize; }
819 
820   /// Obtain default colors
getBorderColor()821   FXColor getBorderColor() const { return borderColor; }
getBaseColor()822   FXColor getBaseColor() const { return baseColor; }
getHiliteColor()823   FXColor getHiliteColor() const { return hiliteColor; }
getShadowColor()824   FXColor getShadowColor() const { return shadowColor; }
getBackColor()825   FXColor getBackColor() const { return backColor; }
getForeColor()826   FXColor getForeColor() const { return foreColor; }
getSelforeColor()827   FXColor getSelforeColor() const { return selforeColor; }
getSelbackColor()828   FXColor getSelbackColor() const { return selbackColor; }
getTipforeColor()829   FXColor getTipforeColor() const { return tipforeColor; }
getTipbackColor()830   FXColor getTipbackColor() const { return tipbackColor; }
getSelMenuTextColor()831   FXColor getSelMenuTextColor() const { return selMenuTextColor; }
getSelMenuBackColor()832   FXColor getSelMenuBackColor() const { return selMenuBackColor; }
833 
834   /// Change default colors
835   void setBorderColor(FXColor color);
836   void setBaseColor(FXColor color);
837   void setHiliteColor(FXColor color);
838   void setShadowColor(FXColor color);
839   void setBackColor(FXColor color);
840   void setForeColor(FXColor color);
841   void setSelforeColor(FXColor color);
842   void setSelbackColor(FXColor color);
843   void setTipforeColor(FXColor color);
844   void setTipbackColor(FXColor color);
845   void setSelMenuTextColor(FXColor color);
846   void setSelMenuBackColor(FXColor color);
847 
848   /// Get number of existing windows
getWindowCount()849   FXuint getWindowCount() const { return windowCount; }
850 
851   /// Create application's windows
852   virtual void create();
853 
854   /// Destroy application's windows
855   virtual void destroy();
856 
857   /// Detach application's windows
858   virtual void detach();
859 
860   /// Save
861   virtual void save(FXStream& store) const;
862 
863   /// Load
864   virtual void load(FXStream& store);
865 
866   /// Dump widget information
867   void dumpWidgets() const;
868 
869   /// Return application instance
instance()870   static inline FXApp* instance(){ return app; }
871 
872   /// Destroy the application and all reachable resources
873   virtual ~FXApp();
874   };
875 
876 }
877 
878 #endif
879