ROOT logo
// @(#)root/base:$Id$
// Author: Fons Rademakers   22/12/95

/*************************************************************************
 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TApplication
#define ROOT_TApplication


//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TApplication                                                         //
//                                                                      //
// This class creates the ROOT Application Environment that interfaces  //
// to the windowing system eventloop and eventhandlers.                 //
// This class must be instantiated exactly once in any given            //
// application. Normally the specific application class inherits from   //
// TApplication (see TRint).                                            //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TObject
#include "TObject.h"
#endif

#ifndef ROOT_TQObject
#include "TQObject.h"
#endif

#ifndef ROOT_TApplicationImp
#include "TApplicationImp.h"
#endif

class TObjArray;
class TTimer;
class TSignalHandler;


class TApplication : public TObject, public TQObject {

public:
   // TApplication specific bits
   enum EStatusBits {
      kProcessRemotely = BIT(15),   // TRUE if this line has to be processed remotely
      kDefaultApplication = BIT(16) // TRUE if created via CreateApplication()
   };
   enum EExitOnException {
      kDontExit,
      kExit,
      kAbort
   };

private:
   Int_t              fArgc;            //Number of com   mand line arguments
   char             **fArgv;            //Command line arguments
   TApplicationImp   *fAppImp;          //!Window system specific application implementation
   Bool_t             fIsRunning;       //True when in event loop (Run() has been called)
   Bool_t             fReturnFromRun;   //When true return from Run()
   Bool_t             fNoLog;           //Do not process logon and logoff macros
   Bool_t             fNoLogo;          //Do not show splash screen and welcome message
   Bool_t             fQuit;            //Exit after having processed input files
   Bool_t             fUseMemstat;      //Run with TMemStat enabled
   TObjArray         *fFiles;           //Array of input files (TObjString's) specified via argv
   TString            fWorkDir;         //Working directory specified via argv
   TString            fIdleCommand;     //Command to execute while application is idle
   TTimer            *fIdleTimer;       //Idle timer
   TSignalHandler    *fSigHandler;      //Interrupt handler
   EExitOnException   fExitOnException; //Exit on exception option

   static Bool_t      fgGraphNeeded;    // True if graphics libs need to be initialized
   static Bool_t      fgGraphInit;      // True if graphics libs initialized

   TApplication(const TApplication&);             // not implemented
   TApplication& operator=(const TApplication&);  // not implemented

protected:
   TApplication      *fAppRemote;      //Current remote application, if defined

   static TList      *fgApplications;  //List of available applications

   TApplication();

   virtual Long_t     ProcessRemote(const char *line, Int_t *error = 0);
   virtual void       Help(const char *line);
   virtual void       LoadGraphicsLibs();
   virtual void       MakeBatch();
   void               SetSignalHandler(TSignalHandler *sh) { fSigHandler = sh; }

   static Int_t       ParseRemoteLine(const char *ln,
                                      TString &hostdir, TString &user,
                                      Int_t &dbg, TString &script);
   static TApplication *Open(const char *url, Int_t debug, const char *script);
   static void          Close(TApplication *app);

public:
   TApplication(const char *appClassName, Int_t *argc, char **argv,
                void *options = 0, Int_t numOptions = 0);
   virtual ~TApplication();

   void            InitializeGraphics();
   virtual void    GetOptions(Int_t *argc, char **argv);
   TSignalHandler *GetSignalHandler() const { return fSigHandler; }
   virtual void    SetEchoMode(Bool_t mode);

   virtual void    HandleException(Int_t sig);
   virtual void    HandleIdleTimer();   //*SIGNAL*
   virtual Bool_t  HandleTermInput() { return kFALSE; }
   virtual void    Init() { fAppImp->Init(); }
   virtual Long_t  ProcessLine(const char *line, Bool_t sync = kFALSE, Int_t *error = 0);
   virtual Long_t  ProcessFile(const char *file, Int_t *error = 0, Bool_t keep = kFALSE);
   virtual void    Run(Bool_t retrn = kFALSE);
   virtual void    SetIdleTimer(UInt_t idleTimeInSec, const char *command);
   virtual void    RemoveIdleTimer();
   const char     *GetIdleCommand() const { return fIdleCommand; }
   virtual void    StartIdleing();
   virtual void    StopIdleing();
   EExitOnException ExitOnException(EExitOnException opt = kExit);

   virtual const char *ApplicationName() const { return fAppImp->ApplicationName(); }
   virtual void    Show()    { fAppImp->Show(); }
   virtual void    Hide()    { fAppImp->Hide(); }
   virtual void    Iconify() { fAppImp->Iconify(); }
   virtual void    Open()    { fAppImp->Open(); }
   virtual void    Raise()   { fAppImp->Raise(); }
   virtual void    Lower()   { fAppImp->Lower(); }
   virtual Bool_t  IsCmdThread() { return fAppImp ? fAppImp->IsCmdThread() : kTRUE; }
   virtual TApplicationImp *GetApplicationImp() { return fAppImp;}

   virtual void    ls(Option_t *option="") const;

   Int_t           Argc() const  { return fArgc; }
   char          **Argv() const  { return fArgv; }
   char           *Argv(Int_t index) const;
   Bool_t          NoLogOpt() const { return fNoLog; }
   Bool_t          NoLogoOpt() const { return fNoLogo; }
   Bool_t          QuitOpt() const { return fQuit; }
   TObjArray      *InputFiles() const { return fFiles; }
   const char     *WorkingDirectory() const { return fWorkDir; }
   void            ClearInputFiles();

   TApplication   *GetAppRemote() const { return fAppRemote; }

   Bool_t          IsRunning() const { return fIsRunning; }
   Bool_t          ReturnFromRun() const { return fReturnFromRun; }
   void            SetReturnFromRun(Bool_t ret) { fReturnFromRun = ret; }

   virtual void    LineProcessed(const char *line);   //*SIGNAL*
   virtual void    Terminate(Int_t status = 0);       //*SIGNAL*
   virtual void    KeyPressed(Int_t key);             //*SIGNAL*
   virtual void    ReturnPressed(char *text );        //*SIGNAL*
   virtual Int_t   TabCompletionHook(char *buf, int *pLoc, ostream& out);

   static Long_t   ExecuteFile(const char *file, Int_t *error = 0, Bool_t keep = kFALSE);
   static TList   *GetApplications();
   static void     CreateApplication();
   static void     NeedGraphicsLibs();

   ClassDef(TApplication,0)  //GUI application singleton
};

R__EXTERN TApplication *gApplication;

#endif
 TApplication.h:1
 TApplication.h:2
 TApplication.h:3
 TApplication.h:4
 TApplication.h:5
 TApplication.h:6
 TApplication.h:7
 TApplication.h:8
 TApplication.h:9
 TApplication.h:10
 TApplication.h:11
 TApplication.h:12
 TApplication.h:13
 TApplication.h:14
 TApplication.h:15
 TApplication.h:16
 TApplication.h:17
 TApplication.h:18
 TApplication.h:19
 TApplication.h:20
 TApplication.h:21
 TApplication.h:22
 TApplication.h:23
 TApplication.h:24
 TApplication.h:25
 TApplication.h:26
 TApplication.h:27
 TApplication.h:28
 TApplication.h:29
 TApplication.h:30
 TApplication.h:31
 TApplication.h:32
 TApplication.h:33
 TApplication.h:34
 TApplication.h:35
 TApplication.h:36
 TApplication.h:37
 TApplication.h:38
 TApplication.h:39
 TApplication.h:40
 TApplication.h:41
 TApplication.h:42
 TApplication.h:43
 TApplication.h:44
 TApplication.h:45
 TApplication.h:46
 TApplication.h:47
 TApplication.h:48
 TApplication.h:49
 TApplication.h:50
 TApplication.h:51
 TApplication.h:52
 TApplication.h:53
 TApplication.h:54
 TApplication.h:55
 TApplication.h:56
 TApplication.h:57
 TApplication.h:58
 TApplication.h:59
 TApplication.h:60
 TApplication.h:61
 TApplication.h:62
 TApplication.h:63
 TApplication.h:64
 TApplication.h:65
 TApplication.h:66
 TApplication.h:67
 TApplication.h:68
 TApplication.h:69
 TApplication.h:70
 TApplication.h:71
 TApplication.h:72
 TApplication.h:73
 TApplication.h:74
 TApplication.h:75
 TApplication.h:76
 TApplication.h:77
 TApplication.h:78
 TApplication.h:79
 TApplication.h:80
 TApplication.h:81
 TApplication.h:82
 TApplication.h:83
 TApplication.h:84
 TApplication.h:85
 TApplication.h:86
 TApplication.h:87
 TApplication.h:88
 TApplication.h:89
 TApplication.h:90
 TApplication.h:91
 TApplication.h:92
 TApplication.h:93
 TApplication.h:94
 TApplication.h:95
 TApplication.h:96
 TApplication.h:97
 TApplication.h:98
 TApplication.h:99
 TApplication.h:100
 TApplication.h:101
 TApplication.h:102
 TApplication.h:103
 TApplication.h:104
 TApplication.h:105
 TApplication.h:106
 TApplication.h:107
 TApplication.h:108
 TApplication.h:109
 TApplication.h:110
 TApplication.h:111
 TApplication.h:112
 TApplication.h:113
 TApplication.h:114
 TApplication.h:115
 TApplication.h:116
 TApplication.h:117
 TApplication.h:118
 TApplication.h:119
 TApplication.h:120
 TApplication.h:121
 TApplication.h:122
 TApplication.h:123
 TApplication.h:124
 TApplication.h:125
 TApplication.h:126
 TApplication.h:127
 TApplication.h:128
 TApplication.h:129
 TApplication.h:130
 TApplication.h:131
 TApplication.h:132
 TApplication.h:133
 TApplication.h:134
 TApplication.h:135
 TApplication.h:136
 TApplication.h:137
 TApplication.h:138
 TApplication.h:139
 TApplication.h:140
 TApplication.h:141
 TApplication.h:142
 TApplication.h:143
 TApplication.h:144
 TApplication.h:145
 TApplication.h:146
 TApplication.h:147
 TApplication.h:148
 TApplication.h:149
 TApplication.h:150
 TApplication.h:151
 TApplication.h:152
 TApplication.h:153
 TApplication.h:154
 TApplication.h:155
 TApplication.h:156
 TApplication.h:157
 TApplication.h:158
 TApplication.h:159
 TApplication.h:160
 TApplication.h:161
 TApplication.h:162
 TApplication.h:163
 TApplication.h:164
 TApplication.h:165
 TApplication.h:166
 TApplication.h:167
 TApplication.h:168
 TApplication.h:169