00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 #include "qrootapplication.h"
00029 
00030 #include "Riostream.h"
00031 #include <stdlib.h>
00032 #include "TTimer.h"
00033 #include "TSystem.h"
00034 #include "TGX11.h"
00035 
00036 #include "qobject.h"
00037 #include "qtimer.h"
00038 
00039 #include "lockguard.h"
00040 
00041 extern void qt_ignore_badwindow();
00042 extern bool qt_badwindow();
00043 extern bool qt_xdnd_handle_badwindow();
00044 
00045 static  int qt_x11_errhandler( Display *dpy, XErrorEvent *err ){
00046   
00047   if ( err->error_code == BadWindow ) {
00048     if ( err->request_code == 25 && qt_xdnd_handle_badwindow() )
00049       return 0;
00050   }
00051   
00052   else if ( err->error_code == BadMatch
00053        && err->request_code == 42  ) {
00054     return 0;
00055   }
00056   
00057   char errstr[256];
00058   XGetErrorText( dpy, err->error_code, errstr, 256 );
00059   qWarning( "X11 Error: %s %d\n  Major opcode:  %d",
00060              errstr, err->error_code, err->request_code );
00061   return 0;
00062 
00063 }
00064 
00065 
00066 bool QRootApplication::fDebug=false;
00067 bool QRootApplication::fWarning=false;
00068 
00069 void qMessageOutput( QtMsgType type, const char *msg )
00070     {
00071         switch ( type ) {
00072             case QtDebugMsg:
00073              if(QRootApplication::fDebug)
00074                 fprintf( stderr, "QtRoot-Debug: \n %s\n", msg );
00075                 break;
00076             case QtWarningMsg:
00077              if(QRootApplication::fWarning)
00078                 fprintf( stderr, "QtRoot-Warning: \n %s\n", msg );
00079                 break;
00080             case QtFatalMsg:
00081                 fprintf( stderr, "QtRoot-Fatal: \n %s\n", msg );
00082                 abort();         
00083         }
00084    }
00085 
00086 
00087 QRootApplication::QRootApplication(int& argc, char **argv, int poll) :
00088    QApplication(argc,argv, true)
00089 {
00090 
00091   
00092 
00093 
00094   if (poll == 0){
00095     timer = new QTimer( this );
00096     QObject::connect( timer, SIGNAL(timeout()),
00097             this, SLOT(execute()) );
00098     timer->start( 20, FALSE );
00099 
00100     rtimer = new TTimer(20);
00101     rtimer->Start(20, kFALSE);
00102 
00103   }
00104 
00105 
00106   
00107   fWarning=fDebug=false;
00108   qInstallMsgHandler( qMessageOutput );
00109 
00110   
00111 
00112 
00113 
00114    
00115 
00116   
00117    setErrorHandler();
00118 }
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131 
00132 
00133 
00134 
00135 QRootApplication::~QRootApplication()
00136 {
00137 }
00138 
00139 void QRootApplication::execute()
00140 
00141 {
00142    gSystem->InnerLoop();
00143 }
00144 
00145 void QRootApplication::setErrorHandler()
00146 
00147 {
00148    XSetErrorHandler( qt_x11_errhandler );
00149 }
00150 
00151 void QRootApplication::quit()
00152 {
00153    gSystem->Exit( 0 );
00154 }
00155 
00156