From e7acaac33db5d0228f0f3d0cef88dfea6026dd7e Mon Sep 17 00:00:00 2001
From: Rene Brun <Rene.Brun@cern.ch>
Date: Thu, 5 Feb 2004 10:05:06 +0000
Subject: [PATCH] From Valeriy Onuchin: there was request (and few related
 requests in the past) for console keys  polling
 http://root.cern.ch/phpBB2/viewtopic.php?t=393 To make it possible I added
 signals to TApplication class:

virtual void    Terminate(int status = 0);   //*SIGNAL*
virtual void    KeyPressed(int key);         //*SIGNAL*
virtual void    ReturnPressed(char *text );  //*SIGNAL*


git-svn-id: http://root.cern.ch/svn/root/trunk@8131 27541ba8-7e3a-0410-8455-c3a389f83636
---
 base/inc/TApplication.h   | 13 ++++++++++---
 base/src/TApplication.cxx | 20 +++++++++++++++++++-
 clib/inc/Getline.h        |  3 ++-
 clib/src/Getline.c        |  6 +++++-
 rint/src/TRint.cxx        |  5 ++++-
 5 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/base/inc/TApplication.h b/base/inc/TApplication.h
index 7ecc3942ec8..3050a8144ad 100644
--- a/base/inc/TApplication.h
+++ b/base/inc/TApplication.h
@@ -1,4 +1,4 @@
-// @(#)root/base:$Name:  $:$Id: TApplication.h,v 1.10 2003/11/18 16:59:58 brun Exp $
+// @(#)root/base:$Name:  $:$Id: TApplication.h,v 1.11 2004/01/21 22:22:36 brun Exp $
 // Author: Fons Rademakers   22/12/95
 
 /*************************************************************************
@@ -29,6 +29,10 @@
 #include "TObject.h"
 #endif
 
+#ifndef ROOT_TQObject
+#include "TQObject.h"
+#endif
+
 #ifndef ROOT_TApplicationImp
 #include "TApplicationImp.h"
 #endif
@@ -38,7 +42,7 @@ class TTimer;
 class TSignalHandler;
 
 
-class TApplication : public TObject {
+class TApplication : public TObject, public TQObject {
 
 private:
    Int_t              fArgc;           //Number of com   mand line arguments
@@ -79,7 +83,6 @@ public:
    const char     *GetIdleCommand() const { return fIdleCommand; }
    virtual void    StartIdleing();
    virtual void    StopIdleing();
-   virtual void    Terminate(int status = 0);
 
    virtual const char *ApplicationName() const { return fAppImp->ApplicationName(); }
    virtual void    Show()    { fAppImp->Show(); }
@@ -105,6 +108,10 @@ public:
 
    static void     CreateApplication();
 
+   virtual void    Terminate(int status = 0);   //*SIGNAL* 
+   virtual void    KeyPressed(int key);         //*SIGNAL* 
+   virtual void    ReturnPressed(char *text );  //*SIGNAL* 
+
    ClassDef(TApplication,0)  //GUI application singleton
 };
 
diff --git a/base/src/TApplication.cxx b/base/src/TApplication.cxx
index e1fdf007778..91ca28e6531 100644
--- a/base/src/TApplication.cxx
+++ b/base/src/TApplication.cxx
@@ -1,4 +1,4 @@
-// @(#)root/base:$Name:  $:$Id: TApplication.cxx,v 1.50 2003/12/30 13:16:50 brun Exp $
+// @(#)root/base:$Name:  $:$Id: TApplication.cxx,v 1.51 2004/01/21 22:22:36 brun Exp $
 // Author: Fons Rademakers   22/12/95
 
 /*************************************************************************
@@ -834,12 +834,30 @@ void TApplication::Terminate(int status)
    // Terminate the application by call TSystem::Exit() unless application has
    // been told to return from Run(), by a call to SetReturnFromRun().
 
+   Emit("Terminate(int)", status);
+
    if (fReturnFromRun)
       gSystem->ExitLoop();
    else
       gSystem->Exit(status);
 }
 
+//______________________________________________________________________________
+void TApplication::KeyPressed(int key)
+{
+   // emit signal when console keyboard key was pressed
+
+   Emit("KeyPressed(int)", key);
+}
+
+//______________________________________________________________________________
+void TApplication::ReturnPressed(char *text )
+{
+   // emit signal when return key was pressed
+
+   Emit("ReturnPressed(char*)", text);
+}
+
 //______________________________________________________________________________
 void TApplication::CreateApplication()
 {
diff --git a/clib/inc/Getline.h b/clib/inc/Getline.h
index 88402bd42bc..52bc3b800b5 100644
--- a/clib/inc/Getline.h
+++ b/clib/inc/Getline.h
@@ -1,4 +1,4 @@
-/* @(#)root/clib:$Name:  $:$Id: Getline.h,v 1.4 2001/06/22 16:10:16 rdm Exp $ */
+/* @(#)root/clib:$Name:  $:$Id: Getline.h,v 1.5 2002/04/04 10:11:13 rdm Exp $ */
 /* Author: */
 
 /*************************************************************************
@@ -32,6 +32,7 @@ int  Gl_eof();
 R__EXTERN int (*Gl_in_hook)(char *buf);
 R__EXTERN int (*Gl_out_hook)(char *buf);
 R__EXTERN int (*Gl_tab_hook)(char *buf, int prompt_width, int *cursor_loc);
+R__EXTERN int (*Gl_in_key)(int key);
 
 #ifndef __CINT__
 #ifdef __cplusplus
diff --git a/clib/src/Getline.c b/clib/src/Getline.c
index 3f53f8da18f..0c80f44a522 100644
--- a/clib/src/Getline.c
+++ b/clib/src/Getline.c
@@ -1,4 +1,4 @@
-/* @(#)root/clib:$Name:  $:$Id: Getline.c,v 1.19 2004/01/31 16:06:35 brun Exp $ */
+/* @(#)root/clib:$Name:  $:$Id: Getline.c,v 1.20 2004/02/02 15:32:57 brun Exp $ */
 /* Author: */
 
 /*
@@ -241,6 +241,7 @@ void    Gl_histadd(char *buf);       /* adds entries to hist */
 int             (*Gl_in_hook)(char *buf) = 0;
 int             (*Gl_out_hook)(char *buf) = 0;
 int             (*Gl_tab_hook)(char *buf, int prompt_width, int *loc) = gl_tab;
+int             (*Gl_in_key)(int ch) = 0;
 
 /******************** imported interface *********************************/
 
@@ -795,6 +796,9 @@ Getlinem(int mode, const char *prompt)
     }
     while ((c = gl_getc()) >= 0) {
         gl_extent = 0;          /* reset to full extent */
+
+        if (Gl_in_key)
+            Gl_in_key(c); 
 #ifndef WIN32
         if (isprint(c)) {
 #else
diff --git a/rint/src/TRint.cxx b/rint/src/TRint.cxx
index bb5c61186a9..5cc00058336 100644
--- a/rint/src/TRint.cxx
+++ b/rint/src/TRint.cxx
@@ -1,4 +1,4 @@
-// @(#)root/rint:$Name:  $:$Id: TRint.cxx,v 1.24 2004/01/21 22:22:36 brun Exp $
+// @(#)root/rint:$Name:  $:$Id: TRint.cxx,v 1.25 2004/01/28 19:06:05 brun Exp $
 // Author: Rene Brun   17/02/95
 
 /*************************************************************************
@@ -50,6 +50,7 @@ extern "C" {
 }
 #endif
 
+static int key_pressed(int key) { gApplication->KeyPressed(key); return 0; }
 
 
 //----- Interrupt signal handler -----------------------------------------------
@@ -183,6 +184,7 @@ TRint::TRint(const char *appClassName, int *argc, char **argv, void *options,
 
    // Setup for tab completion
    gTabCom = new TTabCom;
+   Gl_in_key = &key_pressed;
 }
 
 //______________________________________________________________________________
@@ -368,6 +370,7 @@ Bool_t TRint::HandleTermInput()
       // strip off '\n' and leading and trailing blanks
       sline = sline.Chop();
       sline = sline.Strip(TString::kBoth);
+      ReturnPressed((char*)sline.Data());
 
       fInterrupt = kFALSE;
 
-- 
GitLab