Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXApp.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                     A p p l i c a t i o n   O b j e c t                       *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXAPP_H
00022 #define FXAPP_H
00023 
00024 #ifndef FXOBJECT_H
00025 #include "FXObject.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 // Forward declarations
00032 class FXApp;
00033 class FXWindow;
00034 class FXIcon;
00035 class FXBitmap;
00036 class FXCursor;
00037 class FXRootWindow;
00038 class FXMainWindow;
00039 class FXPopup;
00040 class FXFont;
00041 class FXDC;
00042 class FXDCWindow;
00043 class FXVisual;
00044 class FXGLVisual;
00045 class FXGLContext;
00046 class FXTranslator;
00047 class FXComposeContext;
00048 
00049 // Opaque FOX objects
00050 struct FXTimer;
00051 struct FXChore;
00052 struct FXSignal;
00053 struct FXRepaint;
00054 struct FXInput;
00055 struct FXHandles;
00056 struct FXInvocation;
00057 
00058 
00059 
00060 /// File input modes for addInput
00061 enum FXInputMode {
00062   INPUT_NONE   = 0,                 /// Inactive
00063   INPUT_READ   = 1,                 /// Read input fd
00064   INPUT_WRITE  = 2,                 /// Write input fd
00065   INPUT_EXCEPT = 4                  /// Except input fd
00066   };
00067 
00068 
00069 /// All ways of being modal
00070 enum FXModality {
00071   MODAL_FOR_NONE,                 /// Non modal event loop (dispatch normally)
00072   MODAL_FOR_WINDOW,               /// Modal dialog (beep if outside of modal dialog)
00073   MODAL_FOR_POPUP                 /// Modal for popup (always dispatch to popup)
00074   };
00075 
00076 
00077 /// Default cursors provided by the application
00078 enum FXDefaultCursor {
00079   DEF_ARROW_CURSOR,                     /// Arrow cursor
00080   DEF_RARROW_CURSOR,                    /// Reverse arrow cursor
00081   DEF_TEXT_CURSOR,                      /// Text cursor
00082   DEF_HSPLIT_CURSOR,                    /// Horizontal split cursor
00083   DEF_VSPLIT_CURSOR,                    /// Vertical split cursor
00084   DEF_XSPLIT_CURSOR,                    /// Cross split cursor
00085   DEF_SWATCH_CURSOR,                    /// Color swatch drag cursor
00086   DEF_MOVE_CURSOR,                      /// Move cursor
00087   DEF_DRAGH_CURSOR,                     /// Resize horizontal edge
00088   DEF_DRAGV_CURSOR,                     /// Resize vertical edge
00089   DEF_DRAGTL_CURSOR,                    /// Resize upper-leftcorner
00090   DEF_DRAGBR_CURSOR=DEF_DRAGTL_CURSOR,  /// Resize bottom-right corner
00091   DEF_DRAGTR_CURSOR,                    /// Resize upper-right corner
00092   DEF_DRAGBL_CURSOR=DEF_DRAGTR_CURSOR,  /// Resize bottom-left corner
00093   DEF_DNDSTOP_CURSOR,                   /// Drag and drop stop
00094   DEF_DNDASK_CURSOR,                    /// Drag and drop ask
00095   DEF_DNDCOPY_CURSOR,                   /// Drag and drop copy
00096   DEF_DNDMOVE_CURSOR,                   /// Drag and drop move
00097   DEF_DNDLINK_CURSOR,                   /// Drag and drop link
00098   DEF_CROSSHAIR_CURSOR,                 /// Cross hair cursor
00099   DEF_CORNERNE_CURSOR,                  /// North-east cursor
00100   DEF_CORNERNW_CURSOR,                  /// North-west cursor
00101   DEF_CORNERSE_CURSOR,                  /// South-east cursor
00102   DEF_CORNERSW_CURSOR,                  /// South-west cursor
00103   DEF_HELP_CURSOR,                      /// Help arrow cursor
00104   DEF_HAND_CURSOR,                      /// Hand cursor
00105   DEF_ROTATE_CURSOR,                    /// Rotate cursor
00106   DEF_BLANK_CURSOR,                     /// Blank cursor
00107   DEF_WAIT_CURSOR                       /// Wait cursor
00108   };
00109 
00110 
00111 /**
00112 * The Application object is the central point of a FOX user-interface.
00113 * It manages the event queue, timers, signals, chores, and input sources.
00114 * Each FOX application should have exactly one Application object, which
00115 * is the ultimate owner of the entire widget tree; when the application
00116 * object is deleted, all the widgets and other reachable resources of
00117 * the widget tree are also deleted.
00118 * When the Application is initialized using init(), it parses the
00119 * command line arguments meant for it, and opens the display.
00120 * The run() function is used to run the application; this function
00121 * does not return until the user is ready to quit the application.
00122 * During run(), the application processes events from the various
00123 * windows and dispatches them to the appropriate handlers.
00124 * Finally, a call to exit() terminates the application.
00125 * The Application object also manages a registry of configuration
00126 * data, which is read during init() and written back at the exit();
00127 * thus, all configurations changed by the user normally persist to
00128 * the next invocation of the application.
00129 * Since different organizations and different applications each need
00130 * to keep their own set of configuration data, an application name
00131 * and vendor name can be passed in the Application object's constructor
00132 * to identify a particular application's configuration data.
00133 */
00134 class FXAPI FXApp : public FXObject {
00135   FXDECLARE(FXApp)
00136 
00137   // We've got many friends
00138   friend class FXId;
00139   friend class FXBitmap;
00140   friend class FXImage;
00141   friend class FXIcon;
00142   friend class FXCursor;
00143   friend class FXDrawable;
00144   friend class FXWindow;
00145   friend class FXShell;
00146   friend class FXRootWindow;
00147   friend class FXTopWindow;
00148   friend class FXMainWindow;
00149   friend class FXPopup;
00150   friend class FXFont;
00151   friend class FXVisual;
00152   friend class FXGLVisual;
00153   friend class FXGLContext;
00154   friend class FXDC;
00155   friend class FXDCWindow;
00156   friend class FXDragCorner;
00157   friend class FXDockHandler;
00158   friend class FXComposeContext;
00159 
00160 private:
00161 
00162   // Platform independent private data
00163   void            *display;             // Display we're talking to
00164   const FXchar    *dpy;                 // Initial display guess
00165   FXHash           hash;                // Window handle hash table
00166   FXRegistry       registry;            // Application setting registry
00167   FXWindow        *activeWindow;        // Active toplevel window
00168   FXWindow        *cursorWindow;        // Window under the cursor
00169   FXWindow        *mouseGrabWindow;     // Window which grabbed the mouse
00170   FXWindow        *keyboardGrabWindow;  // Window which grabbed the keyboard
00171   FXWindow        *keyWindow;           // Window in which keyboard key was pressed
00172   FXWindow        *selectionWindow;     // Selection window
00173   FXWindow        *clipboardWindow;     // Clipboard window
00174   FXWindow        *dropWindow;          // Drop target window
00175   FXWindow        *dragWindow;          // Drag source window
00176   FXWindow        *refresher;           // GUI refresher pointer
00177   FXWindow        *refresherstop;       // GUI refresher end pointer
00178   FXPopup         *popupWindow;         // Current popup window
00179   FXRootWindow    *root;                // Root window
00180   FXVisual        *monoVisual;          // Monochrome visual
00181   FXVisual        *defaultVisual;       // Default [color] visual
00182   FXTimer         *timers;              // List of timers, sorted by time
00183   FXChore         *chores;              // List of chores
00184   FXRepaint       *repaints;            // Unhandled repaint rectangles
00185   FXTimer         *timerrecs;           // List of recycled timer records
00186   FXChore         *chorerecs;           // List of recycled chore records
00187   FXRepaint       *repaintrecs;         // List of recycled repaint records
00188   FXInvocation    *invocation;          // Modal loop invocation
00189   FXSignal        *signals;             // Array of signal records
00190   FXint            signalreceived;      // Latest signal received
00191   FXFont          *normalFont;          // Normal font
00192   FXFont          *stockFont;           // Stock font
00193   FXMutex          appMutex;            // Application wide mutex
00194   FXEvent          event;               // Event
00195   FXuint           stickyMods;          // Sticky modifier state
00196   FXInput         *inputs;              // Input file descriptors being watched
00197   FXint            ninputs;             // Number of inputs
00198   FXHandles       *handles;             // Input handles
00199   FXint            maxhandle;           // Maximum handle number
00200   FXuchar         *ddeData;             // DDE array
00201   FXuint           ddeSize;             // DDE array size
00202   FXuint           maxcolors;           // Maximum number of colors to allocate
00203   FXTime           typingSpeed;         // Typing speed
00204   FXTime           clickSpeed;          // Double click speed
00205   FXTime           scrollSpeed;         // Scroll speed
00206   FXTime           scrollDelay;         // Scroll delay
00207   FXTime           blinkSpeed;          // Cursor blink speed
00208   FXTime           animSpeed;           // Animation speed
00209   FXTime           menuPause;           // Menu popup delay
00210   FXTime           toolTipPause;        // Tooltip popup delay
00211   FXTime           toolTipTime;         // Tooltip display time
00212   FXTime           autoHideDelay;       // Cursor autohide delay time
00213   FXint            dragDelta;           // Minimum distance considered a move
00214   FXint            wheelLines;          // Scroll by this many lines
00215   FXint            scrollBarSize;       // Scrollbar size
00216   FXColor          borderColor;         // Border color
00217   FXColor          baseColor;           // Background color of GUI controls
00218   FXColor          hiliteColor;         // Highlight color of GUI controls
00219   FXColor          shadowColor;         // Shadow color of GUI controls
00220   FXColor          backColor;           // Background color
00221   FXColor          foreColor;           // Foreground color
00222   FXColor          selforeColor;        // Select foreground color
00223   FXColor          selbackColor;        // Select background color
00224   FXColor          tipforeColor;        // Tooltip foreground color
00225   FXColor          tipbackColor;        // Tooltip background color
00226   FXColor          selMenuTextColor;    // Select foreground color in menus
00227   FXColor          selMenuBackColor;    // Select background color in menus
00228   FXCursor        *waitCursor;          // Current wait cursor
00229   FXuint           waitCount;           // Number of times wait cursor was called
00230   FXuint           windowCount;         // Number of windows
00231   FXCursor        *cursor[DEF_WAIT_CURSOR+1];
00232   FXTranslator    *translator;          // Message translator
00233   FXint                appArgc;         // Argument count
00234   const FXchar *const *appArgv;         // Argument vector
00235   const FXchar    *inputmethod;         // Input method name
00236   const FXchar    *inputstyle;          // Input method style
00237   FXbool           initialized;         // Has been initialized
00238 
00239 private:
00240   static FXApp    *app;                 // Application pointer
00241 
00242   // Platform dependent private stuff
00243 #ifdef WIN32
00244 
00245   FXushort         ddeTargets;          // DDE targets atom
00246   FXushort         ddeAtom;             // DDE Exchange Atom
00247   FXDragType       ddeDelete;           // DDE Delete Target Atom
00248   FXDragType      *ddeTypeList;         // DDE drop type list
00249   FXuint           ddeNumTypes;         // DDE number of drop types
00250   FXDragAction     ddeAction;           // DDE action
00251   FXDragAction     ansAction;           // Reply action
00252   FXDragType      *xselTypeList;        // Selection type list
00253   FXuint           xselNumTypes;        // Selection number of types on list
00254   void*            xdndTypes;           // Handle to file mapping object for types list
00255   FXushort         xdndAware;           // XDND awareness atom
00256   FXID             xdndSource;          // XDND drag source window
00257   FXID             xdndTarget;          // XDND drop target window
00258   FXbool           xdndStatusPending;   // XDND waiting for status feedback
00259   FXbool           xdndFinishPending;   // XDND waiting for drop-confirmation
00260   FXbool           xdndStatusReceived;  // XDND received at least one status
00261   FXbool           xdndFinishSent;      // XDND finish sent
00262   FXRectangle      xdndRect;            // XDND rectangle bounding target
00263   FXID             stipples[17];        // Standard stipple bitmaps
00264 
00265 #else
00266 
00267 private:
00268   FXID             wmDeleteWindow;      // Catch delete window
00269   FXID             wmQuitApp;           // Catch quit application
00270   FXID             wmProtocols;         // Window manager protocols
00271   FXID             wmMotifHints;        // Motif hints
00272   FXID             wmTakeFocus;         // Focus explicitly set by app
00273   FXID             wmState;             // Window state
00274   FXID             wmNetState;          // Extended Window Manager window state
00275   FXID             wmNetIconName;       // Extended Window Manager icon name
00276   FXID             wmNetWindowName;     // Extended Window Manager window name
00277   FXID             wmNetSupported;      // Extended Window Manager states list
00278   FXID             wmNetHidden;         // Extended Window Manager hidden
00279   FXID             wmNetShaded;         // Extended Window Manager shaded
00280   FXID             wmNetHMaximized;     // Extended Window Manager horizontally maximized
00281   FXID             wmNetVMaximized;     // Extended Window Manager vertically maximized
00282   FXID             wmNetFullScreen;     // Extended Window Manager full screen
00283   FXID             wmNetBelowOthers;    // Extended Window Manager below others
00284   FXID             wmNetAboveOthers;    // Extended Window Manager above others
00285   FXID             wmNetNeedAttention;  // Extended Window Manager need attention
00286   FXID             wmNetMoveResize;     // Extended Window Manager drag corner
00287   FXID             wmNetRestack;        // Extended Window Manager change stacking order
00288   FXID             wmNetPing;           // Extended Window Manager ping
00289   FXID             wmNetWindowType;     // Extended Window Manager window type
00290   FXID             wmWindowTypes[14];   // Window types
00291   FXID             wmWindowRole;        // Window Role
00292   FXID             wmClientLeader;      // Client leader
00293   FXID             wmClientId;          // Client id
00294   FXID             embedAtom;           // XEMBED support
00295   FXID             embedInfoAtom;       // XEMBED info support
00296   FXID             timestampAtom;       // Server time
00297   FXID             ddeTargets;          // DDE targets atom
00298   FXID             ddeAtom;             // DDE exchange atom
00299   FXID             ddeDelete;           // DDE delete target atom
00300   FXID             ddeIncr;             // DDE incremental data exchange atom
00301   FXDragType      *ddeTypeList;         // DDE drop type list
00302   FXuint           ddeNumTypes;         // DDE number of drop types
00303   FXDragAction     ddeAction;           // DDE action
00304   FXDragAction     ansAction;           // Reply action
00305   FXID             xcbSelection;        // Clipboard selection
00306   FXDragType      *xcbTypeList;         // Clipboard type list
00307   FXuint           xcbNumTypes;         // Clipboard number of types on list
00308   FXDragType      *xselTypeList;        // Selection type list
00309   FXuint           xselNumTypes;        // Selection number of types on list
00310   FXDragType      *xdndTypeList;        // XDND type list
00311   FXuint           xdndNumTypes;        // XDND number of types
00312   FXID             xdndProxy;           // XDND proxy atom
00313   FXID             xdndAware;           // XDND awareness atom
00314   FXID             xdndEnter;           // XDND enter window message
00315   FXID             xdndLeave;           // XDND leave window message
00316   FXID             xdndPosition;        // XDND position update message
00317   FXID             xdndStatus;          // XDND status feedback message
00318   FXID             xdndDrop;            // XDND drop message
00319   FXID             xdndFinished;        // XDND finished message
00320   FXID             xdndSelection;       // XDND selection atom
00321   FXID             xdndTypes;           // XDND type list atom
00322   FXID             xdndActions;         // XDND action list atom
00323   FXID             xdndActionList[6];   // XDND actions
00324   FXID             xdndSource;          // XDND drag source window
00325   FXID             xdndTarget;          // XDND drop target window
00326   FXID             xdndProxyTarget;     // XDND window to set messages to
00327   FXbool           xdndStatusPending;   // XDND waiting for status feedback
00328   FXbool           xdndStatusReceived;  // XDND received at least one status
00329   FXbool           xdndWantUpdates;     // XDND target wants new positions while in rect
00330   FXbool           xdndFinishSent;      // XDND finish sent
00331   FXRectangle      xdndRect;            // XDND rectangle bounding target
00332   FXint            xrrScreenChange;     // Xrandr ScreenChange event
00333   FXint            xfxFixesSelection;   // Xfixes selection event
00334   FXint            xsbBallMotion;       // Space ball motion event
00335   FXint            xsbButtonPress;      // Space ball button press event
00336   FXint            xsbButtonRelease;    // Space ball button release event
00337   FXID             stipples[23];        // Standard stipple patterns
00338   void            *xsbDevice;           // Space ball input device
00339   void            *xim;                 // Input method
00340   FXbool           shmi;                // Use XSHM Image possible
00341   FXbool           shmp;                // Use XSHM Pixmap possible
00342   FXbool           xrender;             // XRender available
00343   FXbool           synchronize;         // Synchronized
00344 
00345 #endif
00346 
00347 private:
00348 
00349   // Internal helper functions
00350   FXApp(const FXApp&);
00351   FXApp &operator=(const FXApp&);
00352   static void signalhandler(int sig);
00353   static void immediatesignalhandler(int sig);
00354   void leaveWindow(FXWindow *window,FXWindow *ancestor);
00355   void enterWindow(FXWindow *window,FXWindow *ancestor);
00356   void selectionSetData(const FXWindow* window,FXDragType type,FXuchar* data,FXuint size);
00357   void selectionGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size);
00358   void selectionGetTypes(const FXWindow* window,FXDragType*& types,FXuint& numtypes);
00359   void clipboardSetData(const FXWindow* window,FXDragType type,FXuchar* data,FXuint size);
00360   void clipboardGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size);
00361   void clipboardGetTypes(const FXWindow* window,FXDragType*& types,FXuint& numtypes);
00362   void dragdropSetData(const FXWindow* window,FXDragType type,FXuchar* data,FXuint size);
00363   void dragdropGetData(const FXWindow* window,FXDragType type,FXuchar*& data,FXuint& size);
00364   void dragdropGetTypes(const FXWindow* window,FXDragType*& types,FXuint& numtypes);
00365   void openInputDevices();
00366   void closeInputDevices();
00367 #ifdef WIN32
00368   static long CALLBACK wndproc(FXID hwnd,unsigned int iMsg,unsigned int wParam,long lParam);
00369 protected:
00370   virtual long dispatchEvent(FXID hwnd,unsigned int iMsg,unsigned int wParam,long lParam);
00371 #else
00372   void addRepaint(FXID win,FXint x,FXint y,FXint w,FXint h,FXbool synth=false);
00373   void removeRepaints(FXID win,FXint x,FXint y,FXint w,FXint h);
00374   void scrollRepaints(FXID win,FXint dx,FXint dy);
00375   static void imcreatecallback(void*,FXApp*,void*);
00376   static void imdestroycallback(void*,FXApp*,void*);
00377 #endif
00378 
00379 protected:
00380 
00381   /// Return true if an event arrives within blocking nanoseconds
00382   virtual FXbool getNextEvent(FXRawEvent& ev,FXTime blocking=forever);
00383 
00384   /// Dispatch raw event
00385   virtual FXbool dispatchEvent(FXRawEvent& ev);
00386 
00387 public:
00388   long onCmdQuit(FXObject*,FXSelector,void*);
00389   long onCmdDump(FXObject*,FXSelector,void*);
00390   long onCmdHover(FXObject*,FXSelector,void*);
00391 
00392 public:
00393 
00394   /// Messages applications understand
00395   enum {
00396     ID_QUIT=1,    /// Terminate the application normally
00397     ID_DUMP,      /// Dump the current widget tree
00398     ID_HOVER,
00399     ID_LAST
00400     };
00401 
00402 public:
00403 
00404   /// Information
00405   static const FXuchar copyright[];     /// Copyright notice of library
00406 
00407 public:
00408 
00409   /**
00410   * Construct application object; the name and vendor strings are used
00411   * as keys into the registry database for this application's settings.
00412   * Only one single application object can be constructed.
00413   */
00414   FXApp(const FXString& name="Application",const FXString& vendor="FoxDefault");
00415 
00416   /// Get application name
00417   const FXString& getAppName() const { return registry.getAppKey(); }
00418 
00419   /// Get vendor name
00420   const FXString& getVendorName() const { return registry.getVendorKey(); }
00421 
00422   /// Connection to display; this is called by init()
00423   FXbool openDisplay(const FXchar* dpyname=NULL);
00424 
00425   /// Close connection to the display
00426   FXbool closeDisplay();
00427 
00428   /// Return pointer
00429   void* getDisplay() const { return display; }
00430 
00431   /// Is application initialized
00432   FXbool isInitialized() const { return initialized; }
00433 
00434   /// Get argument count
00435   FXint getArgc() const { return appArgc; }
00436 
00437   /// Get argument vector
00438   const FXchar *const *getArgv() const { return appArgv; }
00439 
00440   /// Return true if input method support
00441   FXbool hasInputMethod() const;
00442 
00443   /// Get default visual
00444   FXVisual* getDefaultVisual() const { return defaultVisual; }
00445 
00446   /// Change default visual
00447   void setDefaultVisual(FXVisual* vis);
00448 
00449   /// Get monochrome visual
00450   FXVisual* getMonoVisual() const { return monoVisual; }
00451 
00452   /// Get root Window
00453   FXRootWindow* getRootWindow() const { return root; }
00454 
00455   /// Set root Window
00456   void setRootWindow(FXRootWindow* rt);
00457 
00458   /// Return window at the end of the focus chain
00459   FXWindow *getFocusWindow() const;
00460 
00461   /// Get the window under the cursor, if any
00462   FXWindow *getCursorWindow() const { return cursorWindow; }
00463 
00464   /// Get the active toplevel window, if any
00465   FXWindow *getActiveWindow() const { return activeWindow; }
00466 
00467   /// Get current popup window, if any
00468   FXPopup* getPopupWindow() const { return popupWindow; }
00469 
00470   /// Return window currently owning primary selection
00471   FXWindow* getSelectionWindow() const { return selectionWindow; }
00472 
00473   /// Return window currently owning the clipboard
00474   FXWindow* getClipboardWindow() const { return clipboardWindow; }
00475 
00476   /// Return drag window if a drag operation is in progress
00477   FXWindow* getDragWindow() const { return dragWindow; }
00478 
00479   /// Find window from id
00480   FXWindow* findWindowWithId(FXID xid) const;
00481 
00482   /// Find window from root x,y, starting from given window
00483   FXWindow* findWindowAt(FXint rx,FXint ry,FXID window=0) const;
00484 
00485   /// Create application's windows
00486   virtual void create();
00487 
00488   /// Destroy application's windows
00489   virtual void destroy();
00490 
00491   /// Detach application's windows
00492   virtual void detach();
00493 
00494   /**
00495   * Add timeout message sel to be sent to target object tgt after an interval of ns
00496   * nanoseconds; the timer fires only once after the interval expires.
00497   * The void* ptr is user data which will be passed into the void* ptr of the message
00498   * handler.
00499   * If a timer with the same target and message already exists, it will be rescheduled.
00500   * Note: the smallest interval that one can wait is actually much larger
00501   * than a nanosecond; on Unix systems, the smallest interval is about 1000 ns,
00502   * whereas on Windows, it is about 1000000 ns.
00503   */
00504   void addTimeout(FXObject* tgt,FXSelector sel,FXTime ns=1000000000,void* ptr=NULL);
00505 
00506   /**
00507   * Add deadline timeout message sel to be sent to target object tgt when the due time,
00508   * expressed in nanoseconds since Epoch (Jan 1, 1970), is reached.
00509   * This is the preferred way to schedule regularly occuring events, as the exact time of issue will
00510   * not suffer accumulating errors as with the addTimeout() method.  However, it is important to ensure
00511   * that the due time is sufficiently far into the future, as otherwise the system may be swamped
00512   * executing nothing but timeout messages.
00513   */
00514   void addDeadline(FXObject* tgt,FXSelector sel,FXTime due=forever,void* ptr=NULL);
00515 
00516   /**
00517   * Remove timeout identified by target object tgt and message sel; if sel=0, remove all timeouts which
00518   * reference object tgt.
00519   */
00520   void removeTimeout(FXObject* tgt,FXSelector sel=0);
00521 
00522   /**
00523   * Return true if a timeout with target object tgt and message sel has been set;
00524   * if sel=0, return true if any timeout has been set with target object tgt.
00525   */
00526   FXbool hasTimeout(FXObject *tgt,FXSelector sel=0) const;
00527 
00528   /**
00529   * Return the time (in nanoseconds) remaining until the timer identified by target object
00530   * tgt and message sel will fire.
00531   * If the timer is past due, 0 is returned.  If there is no such timer, the constant
00532   * forever (LLONG_MAX) is returned.  If sel=0, return the earliest timeout that will be
00533   * received by target object tgt.
00534   */
00535   FXTime remainingTimeout(FXObject *tgt,FXSelector sel=0);
00536 
00537   /**
00538   * Add a chore message sel to be sent to target object tgt when
00539   * the system becomes idle, i.e. there are no events to be processed.
00540   * The void* ptr is user data which will be passed into the void* ptr
00541   * of the message handler. If a chore with the same target and message
00542   * already exists, it will be rescheduled.
00543   */
00544   void addChore(FXObject* tgt,FXSelector sel,void *ptr=NULL);
00545 
00546   /**
00547   * Remove chore identified by target object tgt and message sel; if sel=0,
00548   * remove all idle processing messages which refernce object tgt.
00549   */
00550   void removeChore(FXObject* tgt,FXSelector sel=0);
00551 
00552   /**
00553   * Return true if a chore with target object tgt and message sel has been set;
00554   * if sel=0, return true if any chore has been set with target object tgt.
00555   */
00556   FXbool hasChore(FXObject *tgt,FXSelector sel=0) const;
00557 
00558   /**
00559   * Add signal processing message to be sent to target object when
00560   * the signal sig is raised; flags are to be set as per POSIX definitions.
00561   * When immediate is true, the message will be sent to the target right away;
00562   * this should be used with extreme care as the application is interrupted
00563   * at an unknown point in its execution.
00564   */
00565   void addSignal(FXint sig,FXObject* tgt,FXSelector sel,FXbool immediate=false,FXuint flags=0);
00566 
00567   /// Remove signal message for signal sig
00568   void removeSignal(FXint sig);
00569 
00570   /**
00571   * Add a file descriptor fd to be watched for activity as determined by
00572   * mode, where mode is a bitwise OR of (INPUT_READ, INPUT_WRITE, INPUT_EXCEPT).
00573   * A message of type SEL_IO_READ, SEL_IO_WRITE, or SEL_IO_EXCEPT will be sent
00574   * to the target when the specified activity is detected on the file descriptor;
00575   * the void* ptr is user data which will be passed into the void* ptr of the
00576   * mesage handler; often you will want to pass the file descriptor fd itself
00577   * as the value for ptr so that the message handler knows which file descriptor
00578   * is involved.
00579   */
00580   FXbool addInput(FXObject *tgt,FXSelector sel,FXInputHandle fd,FXuint mode=INPUT_READ,void* ptr=NULL);
00581 
00582   /**
00583   * Remove input message and target object for the specified file descriptor
00584   * and mode, which is a bitwise OR of (INPUT_READ, INPUT_WRITE, INPUT_EXCEPT).
00585   * Omitting the last parameter will delete all the handlers associated with the
00586   * file descriptor.
00587   */
00588   FXbool removeInput(FXInputHandle fd,FXuint mode=INPUT_READ);
00589 
00590   /// Return key state of given key
00591   FXbool getKeyState(FXuint keysym) const;
00592 
00593   /// Peek to determine if there's an event
00594   FXbool peekEvent();
00595 
00596   /// Perform one event dispatch; return true if event was dispatched
00597   FXbool runOneEvent(FXTime blocking=forever);
00598 
00599   /**
00600   * Run the main application event loop until stop() is called,
00601   * and return the exit code passed as argument to stop().
00602   */
00603   FXint run();
00604 
00605   /**
00606   * Run an event loop till some flag becomes non-zero, and
00607   * then return.
00608   */
00609   FXint runUntil(FXuint& condition);
00610 
00611   /**
00612   * Run non-modal event loop while events arrive within blocking nanoseconds.
00613   * Returns when no new events arrive in this time, and no timers, or chores
00614   * are outstanding.
00615   */
00616   FXint runWhileEvents(FXTime blocking=0);
00617 
00618   /**
00619   * Run modal event loop while events arrive within blocking nanoseconds.
00620   * Returns 1 when all events in the queue have been handled, and 0 when
00621   * the event loop was terminated due to stop() or stopModal().
00622   * Except for the modal window and its children, user input to all windows
00623   * is blocked; if the modal window is NULL, all user input is blocked.
00624   */
00625   FXint runModalWhileEvents(FXWindow* window=NULL,FXTime blocking=0);
00626 
00627   /**
00628   * Run modal event loop, blocking keyboard and mouse events to all windows
00629   * until stopModal is called.
00630   */
00631   FXint runModal();
00632 
00633   /**
00634   * Run a modal event loop for the given window, until stop() or stopModal() is
00635   * called. Except for the modal window and its children, user input to all
00636   * windows is blocked; if the modal window is NULL all user input is blocked.
00637   */
00638   FXint runModalFor(FXWindow* window);
00639 
00640   /**
00641   * Run modal while window is shown, or until stop() or stopModal() is called.
00642   * Except for the modal window and its children, user input to all windows
00643   * is blocked; if the modal window is NULL all user input is blocked.
00644   */
00645   FXint runModalWhileShown(FXWindow* window);
00646 
00647   /**
00648   * Run popup menu while shown, until stop() or stopModal() is called.
00649   * Also returns when entering previous cascading popup menu.
00650   */
00651   FXint runPopup(FXWindow* window);
00652 
00653   /// True if the window is modal
00654   FXbool isModal(FXWindow* window) const;
00655 
00656   /// Return window of current modal loop
00657   FXWindow* getModalWindow() const;
00658 
00659   /// Return mode of current modal loop
00660   FXModality getModality() const;
00661 
00662   /**
00663   * Terminate the outermost event loop, and all inner modal loops;
00664   * All more deeper nested event loops will be terminated with code equal
00665   * to 0, while the outermost event loop will return code equal to value.
00666   */
00667   void stop(FXint value=0);
00668 
00669   /**
00670   * Break out of the matching modal loop, returning code equal to value.
00671   * All deeper nested event loops are terminated with code equal to 0.
00672   */
00673   void stopModal(FXWindow* window,FXint value=0);
00674 
00675   /**
00676   * Break out of the innermost modal loop, returning code equal to value.
00677   */
00678   void stopModal(FXint value=0);
00679 
00680   /// Force GUI refresh
00681   void forceRefresh();
00682 
00683   /// Schedule a refresh
00684   void refresh();
00685 
00686   /// Flush pending repaints
00687   void flush(FXbool sync=false);
00688 
00689   /**
00690   * Paint all windows marked for repainting.
00691   * On return all the applications windows have been painted.
00692   */
00693   void repaint();
00694 
00695   /**
00696   * Initialize application.
00697   * Parses and removes common command line arguments, reads the registry.
00698   * Finally, if connect is true, it opens the display.
00699   */
00700   virtual void init(int& argc,char** argv,FXbool connect=true);
00701 
00702   /**
00703   * Exit application.
00704   * Closes the display and writes the registry.
00705   */
00706   virtual void exit(FXint code=0);
00707 
00708   /**
00709   * Return a reference to the registry.  The registry keeps
00710   * settings and configuration information for an application,
00711   * which are automatically loaded when the application starts
00712   * up, and saved when the application terminates.
00713   */
00714   FXRegistry& reg(){ return registry; }
00715 
00716   /// Register new DND type
00717   FXDragType registerDragType(const FXString& name) const;
00718 
00719   /// Get drag type name
00720   FXString getDragTypeName(FXDragType type) const;
00721 
00722   /// Beep
00723   void beep();
00724 
00725   /// Return application instance
00726   static inline FXApp* instance(){ return app; }
00727 
00728   /// Change default font
00729   void setNormalFont(FXFont* font);
00730 
00731   /// Return default font
00732   FXFont* getNormalFont() const { return normalFont; }
00733 
00734   /// Begin of wait-cursor block; wait-cursor blocks may be nested.
00735   void beginWaitCursor();
00736 
00737   /// End of wait-cursor block
00738   void endWaitCursor();
00739 
00740   /// Change to a new wait cursor
00741   void setWaitCursor(FXCursor *cur);
00742 
00743   /// Return current wait cursor
00744   FXCursor* getWaitCursor() const { return waitCursor; }
00745 
00746   /// Obtain a default cursor
00747   FXCursor* getDefaultCursor(FXDefaultCursor which) const { return cursor[which]; }
00748 
00749   /// Change default cursor
00750   void setDefaultCursor(FXDefaultCursor which,FXCursor* cur);
00751 
00752   /**
00753   * Return a reference to the application-wide mutex.
00754   * Normally, the main user interface thread holds this mutex,
00755   * insuring that no other threads are modifying data during the
00756   * processing of user interface messages. However, whenever the
00757   * main user interface thread blocks for messages, it releases
00758   * this mutex, to allow other threads to modify the same data.
00759   * When a new message becomes available, the main user interface
00760   * thread regains the mutex prior to dispatching the message.
00761   * Other threads should hold this mutex only for short durations,
00762   * so as to not starve the main user interface thread.
00763   */
00764   FXMutex& mutex(){ return appMutex; }
00765 
00766   /**
00767   * Change message translator.
00768   * The new translator will be owned by FXApp.
00769   */
00770   void setTranslator(FXTranslator* trans);
00771 
00772   /// Return message translator
00773   FXTranslator* getTranslator() const { return translator; }
00774 
00775   /// Obtain application-wide timing constants, in nanoseconds
00776   FXTime getTypingSpeed() const { return typingSpeed; }
00777   FXTime getClickSpeed() const { return clickSpeed; }
00778   FXTime getScrollSpeed() const { return scrollSpeed; }
00779   FXTime getScrollDelay() const { return scrollDelay; }
00780   FXTime getBlinkSpeed() const { return blinkSpeed; }
00781   FXTime getAnimSpeed() const { return animSpeed; }
00782   FXTime getMenuPause() const { return menuPause; }
00783   FXTime getToolTipPause() const { return toolTipPause; }
00784   FXTime getToolTipTime() const { return toolTipTime; }
00785   FXTime getAutoHideDelay() const { return autoHideDelay; }
00786 
00787   /// Change application-wide timing constants, in nanoseconds
00788   void setTypingSpeed(FXTime speed);
00789   void setClickSpeed(FXTime speed);
00790   void setScrollSpeed(FXTime speed);
00791   void setScrollDelay(FXTime delay);
00792   void setBlinkSpeed(FXTime speed);
00793   void setAnimSpeed(FXTime speed);
00794   void setMenuPause(FXTime pause);
00795   void setToolTipPause(FXTime pause);
00796   void setToolTipTime(FXTime time);
00797   void setAutoHideDelay(FXTime time);
00798 
00799   /// Access drag hysteresis
00800   void setDragDelta(FXint delta);
00801   FXint getDragDelta() const { return dragDelta; }
00802 
00803   /// Access mouse wheel scroll lines
00804   void setWheelLines(FXint lines);
00805   FXint getWheelLines() const { return wheelLines; }
00806 
00807   /// Access scroll bar slot size
00808   void setScrollBarSize(FXint size);
00809   FXint getScrollBarSize() const { return scrollBarSize; }
00810 
00811   /// Obtain default colors
00812   FXColor getBorderColor() const { return borderColor; }
00813   FXColor getBaseColor() const { return baseColor; }
00814   FXColor getHiliteColor() const { return hiliteColor; }
00815   FXColor getShadowColor() const { return shadowColor; }
00816   FXColor getBackColor() const { return backColor; }
00817   FXColor getForeColor() const { return foreColor; }
00818   FXColor getSelforeColor() const { return selforeColor; }
00819   FXColor getSelbackColor() const { return selbackColor; }
00820   FXColor getTipforeColor() const { return tipforeColor; }
00821   FXColor getTipbackColor() const { return tipbackColor; }
00822   FXColor getSelMenuTextColor() const { return selMenuTextColor; }
00823   FXColor getSelMenuBackColor() const { return selMenuBackColor; }
00824 
00825   /// Change default colors
00826   void setBorderColor(FXColor color);
00827   void setBaseColor(FXColor color);
00828   void setHiliteColor(FXColor color);
00829   void setShadowColor(FXColor color);
00830   void setBackColor(FXColor color);
00831   void setForeColor(FXColor color);
00832   void setSelforeColor(FXColor color);
00833   void setSelbackColor(FXColor color);
00834   void setTipforeColor(FXColor color);
00835   void setTipbackColor(FXColor color);
00836   void setSelMenuTextColor(FXColor color);
00837   void setSelMenuBackColor(FXColor color);
00838 
00839   /// Get number of existing windows
00840   FXuint getWindowCount() const { return windowCount; }
00841 
00842   /// Save
00843   virtual void save(FXStream& store) const;
00844 
00845   /// Load
00846   virtual void load(FXStream& store);
00847 
00848   /// Dump widget information
00849   void dumpWidgets() const;
00850 
00851   /// Destroy the application and all reachable resources
00852   virtual ~FXApp();
00853   };
00854 
00855 }
00856 
00857 #endif

Copyright © 1997-2010 Jeroen van der Zijp