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