Index: /trunk/SophyaPI/PI/piapplx.cc
===================================================================
--- /trunk/SophyaPI/PI/piapplx.cc	(revision 51)
+++ /trunk/SophyaPI/PI/piapplx.cc	(revision 52)
@@ -64,5 +64,5 @@
 Display *mdsp;
 mdsp = XtDisplay (topwdg->XtWdg()); 
-topwdg->Unmanage();
+topwdg->UnManage();
 delete menubar;
 if (topcont != MBCont())  delete topcont;
Index: /trunk/SophyaPI/PI/pibwdggen.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdggen.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pibwdggen.cc	(revision 52)
@@ -2,4 +2,5 @@
 
 #include "pibwdggen.h"
+#include "pidrawer.h"
 #include "psfile.h"
 
@@ -12,4 +13,6 @@
 {
 mPSOut=NULL;
+mDrwId=0;   // Compteur des numeros sequentiel des PIDrawer
+mAdfg=false;    // Pour controle d'appel de RemoveDrawer()
 }
 
@@ -18,8 +21,33 @@
 PIBaseWdgGen::~PIBaseWdgGen()
 {
-}
-
+DeleteDrawers();
+}
  
 
+/* --Methode-- */
+void PIBaseWdgGen::SaveGraphicAtt()
+{
+  sFCol = GetForeground();
+  sBCol = GetBackground();
+  sGOm = GetGOMode();
+  sFAtt = GetFontAtt();   
+  sFSize = GetFontSize();
+  sLAtt = GetLineAtt();
+  sMrk = GetMarker();   
+  sMrkSz = GetMarkerSize();
+  return;
+}
+
+/* --Methode-- */
+void PIBaseWdgGen::RestoreGraphicAtt()
+{
+  SelForeground(sFCol);
+  SelBackground(sBCol);
+  SelGOMode(sGOm);
+  SelFontSzPt(sFSize, sFAtt);
+  SelLine(sLAtt);
+  SelMarker(sMrkSz, sMrk);
+  return;
+}
 
 /* --Methode-- */
@@ -131,2 +159,70 @@
 }
 
+
+/* --Methode-- */
+int PIBaseWdgGen::AddDrawer(PIDrawer* drw, int x0, int y0, int dx, int dy, bool ad)
+{
+if (drw == NULL)   return(0);
+mDrwId++;
+BWDrwId did;
+did.x0 = x0;  did.y0 = y0;
+did.dx = dx;  did.dy = dy;
+did.id = mDrwId;  did.ad = ad; 
+did.drw = drw;
+mDrwList.push_back(did);
+drw->Attach((PIBaseWdg*)this, mDrwId);
+return(mDrwId);
+}
+
+/* --Methode-- */
+void PIBaseWdgGen::RemoveDrawer(int id)
+{
+if (mAdfg)  return;
+list<BWDrwId>::iterator it;
+for(it = mDrwList.begin(); it != mDrwList.end(); it++)
+  if ((*it).id == id) 
+    { (*it).drw->Detach((PIBaseWdg*)this, id); mDrwList.erase(it); break; }
+return;
+}
+
+/* --Methode-- */
+void PIBaseWdgGen::DeleteDrawers()
+{
+mAdfg = true;
+list<BWDrwId>::iterator it;
+for(it = mDrwList.begin(); it != mDrwList.end(); it++)  
+  if ((*it).ad)  delete (*it).drw;
+mDrwList.erase(mDrwList.begin(), mDrwList.end() );
+mAdfg = false;
+return;
+}
+
+
+/* --Methode-- */
+void PIBaseWdgGen::CallDrawers(int x0, int y0, int dx, int dy)
+{
+double xmin,ymin, xmax, ymax;
+
+bool sxy = false;
+if ((dx > 0) && (dy > 0))  sxy = true;
+
+list<BWDrwId>::iterator it;
+bool fgc=false;
+for(it = mDrwList.begin(); it != mDrwList.end(); it++) {
+  SaveGraphicAtt();
+  (*it).drw->SetDrwWdg(this, (*it).x0, (*it).y0, (*it).dx, (*it).dy);
+  SetClipRectangle((*it).x0, (*it).y0, (*it).dx , (*it).dy);
+  fgc = true;
+  if (sxy) {
+    (*it).drw->Local2Sc(x0, y0, xmin, ymin);
+    (*it).drw->Local2Sc(x0+dx, y0+dy, xmax, ymax);
+    if (xmin > xmax)  swap(xmin,xmax);
+    if (ymin > ymax)  swap(ymin,ymax);
+    (*it).drw->Draw(xmin, ymin, xmax, ymax);
+  }
+  else (*it).drw->Draw();
+  RestoreGraphicAtt();
+  }
+if (fgc)  ClearClipRectangle();
+
+}
Index: /trunk/SophyaPI/PI/pibwdggen.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdggen.h	(revision 51)
+++ /trunk/SophyaPI/PI/pibwdggen.h	(revision 52)
@@ -2,16 +2,19 @@
 #define PIBWDGGEN_H_SEEN
 
+
 #include "pisysdep.h"
 #include PIWDG_H
+#include PICMAP_H
 
-#include "pibwdggen.h"
+// Mettre dans cet ordre, sinon g++ a des problemes   
+#include <list>   
 
 
 enum PIKeyModifier { PIKM_Blank = 0, PIKM_Shift = 1, PIKM_Alt = 2, PIKM_Cntl = 4 } ; 
 
-enum PIColors  { PI_NotDefColor = -1,
+enum PIColors  { PI_NotDefColor = -1, 
                  PI_Black = 0, PI_White = 1,  PI_Grey = 2,
                  PI_Red = 3, PI_Blue = 4, PI_Green = 5,  
-                 PI_Yellow = 6, PI_Magenta =7 }; 
+                 PI_Yellow = 6, PI_Magenta = 7 }; 
 
 enum PIFontSize { PI_NotDefFontSize = -1, 
@@ -61,6 +64,6 @@
 
 //  Trace graphiques
-  virtual void       EraseWindow()             = 0;
-  virtual void       DrawString(int x, int y, char* s, int pos = 0)  = 0;
+  virtual void       EraseWindow(int x0=0, int y0=0, int dx=0, int dy=0)   = 0;
+  virtual void       DrawString(int x, int y, char* s, int pos = 0)        = 0;
   virtual void       DrawLine(int x1, int y1, int x2, int y2)              = 0;
   virtual void       DrawBox(int x0, int y0, int dx, int dy)               = 0;
@@ -72,6 +75,6 @@
   virtual void       DrawMarker(int x0, int y0)                            = 0;
   virtual void       DrawMarkers(int *x, int *y, int n)                    = 0;
-
-
+  virtual void       DrawPixmap(int x, int y, unsigned char *pix, 
+                                int sx, int sy, PIColorMap* cmap)          = 0;
 
   virtual int        CalcStringWidth(char const* s)                        = 0;
@@ -88,4 +91,8 @@
   virtual void       SelMarker(int msz=3, PIMarker mrk=PI_DotMarker)       = 0;
 
+// Selection de zone de trace (clip)
+  virtual void       SetClipRectangle(int x0, int y0, int dx, int dy)      = 0;
+  virtual void       ClearClipRectangle() = 0;
+
 // Acces aux attributs graphiques 
   virtual PIColors   GetForeground()    = 0;
@@ -98,4 +105,9 @@
   virtual PIMarker   GetMarker()        = 0;
   virtual int        GetMarkerSize()    = 0;
+  virtual int        GetFontHeight(int& asc, int& desc) = 0;
+
+// Sauvegarde des attributs graphiques 
+  virtual void       SaveGraphicAtt();
+  virtual void       RestoreGraphicAtt();
 
 
@@ -122,8 +134,33 @@
 
 // PostScript output
-  virtual void       PSPrint(PSFile * psf, int ofx = 0, int ofy = 0); 
+  virtual void       PSPrint(PSFile * psf, int ofx = 0, int ofy = 0);
 
+// Gestion des Drawers 
+  friend class PIDrawer;
+          int        AddDrawer(PIDrawer* drw, int x0, int y0, int dx, int dy, 
+                               bool ad=false);
+          void       RemoveDrawer(int id);       // Ote un drawer de la liste
+          void       DeleteDrawers();            // Ote et detruit tous les drawers
+
+// Devrait etre protected - mis ici a cause de cxx  11/07/97  Reza
+  struct BWDrwId { int x0, y0; int dx, dy; int id; bool ad; PIDrawer* drw; };
+          
 protected:
+  virtual void       CallDrawers(int x0, int y0, int dx, int dy); // Appel le trace des drawers
+
   PSFile * mPSOut;  /* Fichier PostScript eventuel */
+
+  bool mAdfg;
+  int mDrwId;
+  list<BWDrwId> mDrwList;
+// Pour Save/Restore des attributs graphiques 
+  PIColors  sFCol, sBCol;
+  PIGOMode sGOm;
+  PIFontAtt sFAtt;
+  PILineAtt sLAtt;
+  int sFSize;
+  PIMarker sMrk;
+  int sMrkSz;
+
 };
 
Index: /trunk/SophyaPI/PI/pibwdgmac.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdgmac.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pibwdgmac.cc	(revision 52)
@@ -49,5 +49,5 @@
 
 /* --Methode-- */
-void PIBaseWdgMac::EraseWindow()
+void PIBaseWdgMac::EraseWindow(int x0, int y0, int dx, int dy)
 {
   if (mPane->FocusDraw()) {
Index: /trunk/SophyaPI/PI/pibwdgmac.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdgmac.h	(revision 51)
+++ /trunk/SophyaPI/PI/pibwdgmac.h	(revision 52)
@@ -25,5 +25,5 @@
 
 //  Trace graphiques
-  virtual void       EraseWindow();
+  virtual void       EraseWindow(int x0=0, int y0=0, int dx=0, int dy=0);
   virtual void       DrawString(int x, int y, char* s, int pos = 0);
   virtual void       DrawLine(int x1, int y1, int x2, int y2);
Index: /trunk/SophyaPI/PI/pibwdgx.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdgx.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pibwdgx.cc	(revision 52)
@@ -8,9 +8,9 @@
 #include <X11/CoreP.h>
 
-#include "pibwdgx.h"
-
 #include "pixtbaseP.h"
 #include "pixtbase.h"
 
+#include "pibwdgx.h"
+#include "pidrawer.h"
 #include "psfile.h"
 
@@ -26,4 +26,6 @@
 static Cursor curs[NMAXCURS];
 
+/*  GC pour DrawPixmap   */
+static GC dpxgc;
 
 // #define DEBUG_PIBWDGX     Flag pour impression de debug etc ...
@@ -60,4 +62,5 @@
 SelPointerShape();
 SelMarker(1, PI_DotMarker);
+
 Manage();
 }
@@ -67,7 +70,19 @@
 PIBaseWdgX::~PIBaseWdgX()
 {
-}
-
- 
+
+}
+
+/* --Methode-- */
+void PIBaseWdgX::FinishCreate()
+{
+// appele par la fenetre mere, apres XtRealize()
+// J'active le backing store pour la fenetre X
+XSetWindowAttributes xswa;
+Window mwi;
+mwi = XtWindow(XtWdg());
+xswa.backing_store = WhenMapped;
+xswa.backing_planes = ~0;
+XChangeWindowAttributes(PIXDisplay(), XtWindow(XtWdg()), CWBackingPlanes|CWBackingStore, &xswa);
+} 
 
 /* --Methode-- */
@@ -131,17 +146,18 @@
 }
 
-/* --Methode-- */
-void PIBaseWdgX::EraseWindow()
+
+/* --Methode-- */
+void PIBaseWdgX::EraseWindow(int x0, int y0, int dx, int dy)
 {
 if(mPSOut) return;
-XClearWindow   (XtDisplay(XtWdg()),XtWindow(XtWdg()) );
-return;
-}
-
-/* --Methode-- */
-void PIBaseWdgX::DrawString(int x, int y, char* s, int pos)
+XClearArea (XtDisplay(XtWdg()),XtWindow(XtWdg()), x0, y0, dx, dy, False );
+return;
+}
+
+/* --Methode-- */
+void PIBaseWdgX::DrawString(int x, int y, char* s, int /*pos*/)
 {
 if(mPSOut){
-mPSOut->DrawString((float)x,(float)y,s,mFCol,mFAtt,mFSize); /* PIFontSize ?? */
+mPSOut->DrawString((float)x,(float)y,s,mFCol,mFAtt,mFSize); /* $CHECK$ PIFontSize ?? */
 }
 else
@@ -183,5 +199,5 @@
 {
 if(mPSOut)
-mPSOut->DrawFBox((float)x0,(float)y0,(float)dx,(float)dy);
+mPSOut->DrawFBox((float)x0,(float)y0,(float)dx,(float)dy, mFCol, mFCol, mLAtt);
 else{
 if (dx < 0)  { x0 += dx;  dx = -dx; }
@@ -229,6 +245,6 @@
 if(mPSOut)
 {
-xtmp = (float*)malloc(n*sizeof(float));
-ytmp = (float*)malloc(n*sizeof(float));
+xtmp = new float[n];
+ytmp = new float[n];
 for(i=0;i<n;i++){
   xtmp[i] = (float)x[i];
@@ -236,6 +252,6 @@
 }
 mPSOut->DrawPolygon(xtmp,ytmp,n,mFCol,mLAtt);
-free(xtmp);
-free(ytmp);
+delete[] xtmp;
+delete[] ytmp;
 }
 else {
@@ -262,6 +278,6 @@
 if(mPSOut)
 {
-xtmp = (float*)malloc(n*sizeof(float));
-ytmp = (float*)malloc(n*sizeof(float));
+xtmp = new float[n];
+ytmp = new float[n];
 for(i=0;i<n;i++){
   xtmp[i] = (float)x[i];
@@ -269,6 +285,6 @@
 }
 mPSOut->DrawFPolygon(xtmp,ytmp,n,mFCol,mFCol,mLAtt);
-free(xtmp);
-free(ytmp);
+delete[] xtmp;
+delete[] ytmp;
 }
 else
@@ -354,6 +370,6 @@
 if(mPSOut)
 {
-xtmp = (float*)malloc(n*sizeof(float));
-ytmp = (float*)malloc(n*sizeof(float));
+xtmp = new float[n];
+ytmp = new float[n];
 for(i=0;i<n;i++){
   xtmp[i] = (float)x[i];
@@ -361,6 +377,6 @@
 }
 mPSOut->DrawMarkers(xtmp,ytmp,n,mMrk,mFCol, mMrkSz);
-free(xtmp);
-free(ytmp);
+delete[] xtmp;
+delete[] ytmp;
 }
 else
@@ -380,4 +396,50 @@
 }
 }
+
+
+/* --Methode-- */
+void PIBaseWdgX::DrawPixmap(int x, int y, unsigned char *pix, 
+                            int sx, int sy, PIColorMap* cmap)
+{
+Window xw;
+Display * mdsp;
+int scr;
+int depth;
+int pad;
+int i,j;
+XImage * ximg;
+
+if ( (sx < 1) || (sy < 1) )  return;
+if ((pix == NULL) || (cmap == NULL)) return; 
+
+if(mPSOut) {
+  mPSOut->Image((float)x, (float)y, (float)sx, (float)sy, sx, sy, pix, cmap);
+  return;
+  }
+  
+xw = XtWindow(XtWdg());
+mdsp = PIXDisplay();
+scr = PIXScreen();
+
+depth = DefaultDepth(mdsp,scr);
+pad = (depth > 8) ? 32 : 8;
+ximg = XCreateImage (mdsp,DefaultVisual(mdsp,scr),
+                     depth,ZPixmap,0,NULL, sx, sy, pad,0);
+if (ximg == NULL)  return;
+ximg->data = new char [sy*ximg->bytes_per_line];
+if (ximg->data == NULL)  
+  { XFree(ximg); return; }
+
+for(j=0; j<sy; j++)
+  for(i=0; i<sx; i++)
+    { XPutPixel(ximg, i, j, cmap->Color(*pix) );  pix++; }
+
+XPutImage(mdsp, xw, dpxgc, ximg, 0, 0, x, y, sx, sy);
+
+delete[] ximg->data;
+XFree(ximg); 
+return;
+}
+
 
 /* --Methode-- */
@@ -527,4 +589,24 @@
 }
 
+
+/* --Methode-- */
+void PIBaseWdgX::SetClipRectangle(int x0, int y0, int dx, int dy)
+{
+XRectangle xr;
+xr.x = x0;  xr.y = y0;
+xr.width = dx;  xr.height = dy;
+XSetClipRectangles(XtDisplay(XtWdg()), DefGC(), 0, 0, &xr, 1, Unsorted);
+XSetClipRectangles(XtDisplay(XtWdg()), dpxgc, 0, 0, &xr, 1, Unsorted);
+return;
+}
+
+/* --Methode-- */
+void PIBaseWdgX::ClearClipRectangle()
+{ 
+XSetClipMask(XtDisplay(XtWdg()), DefGC(), None);
+XSetClipMask(XtDisplay(XtWdg()), dpxgc, None);
+return;
+}
+
 /* --Methode-- */
 PIColors  PIBaseWdgX::GetForeground() 
@@ -582,5 +664,26 @@
 }
 
-
+/* --Methode-- */
+int        PIBaseWdgX::GetFontHeight(int& asc, int& desc)   
+{
+char a[2];
+XCharStruct  ovr;
+int hd, fa, fd;
+XTextExtents(mFSt, a, 0, &hd, &fa, &fd, &ovr);
+asc = fa; desc = fd; 
+return(fa+fd);
+}
+
+
+/* --Methode-- */
+void PIBaseWdgX::SaveGraphicAtt()
+{  
+// Pour optimier l'implementation de PIBaseWdgGen
+sFCol = mFCol;    sBCol = mBCol;
+sGOm = mGOm;
+sFAtt = mFAtt;   sFSize = mFSize;
+sMrk = mMrk;   sMrkSz = mMrkSz;
+return;
+}
 
 /* --Methode-- */
@@ -620,4 +723,5 @@
 this->DrawFBox(10,10, XSize()*2/3, YSize()*2/3);
 #endif
+CallDrawers(0,0,0,0);
 return;
 }
@@ -644,5 +748,5 @@
 
 /* --Methode-- */
-void PIBaseWdgX::But1Press(int x, int y)
+void PIBaseWdgX::But1Press(int, int)
 {
 #ifdef DEBUG_PIBWDGX
@@ -653,5 +757,5 @@
 
 /* --Methode-- */
-void PIBaseWdgX::But1Release(int x, int y)
+void PIBaseWdgX::But1Release(int, int)
 {
 Send(Msg(), PIMsg_Active);
@@ -688,5 +792,5 @@
 
 /* --Methode-- */
-void PIBaseWdgX::Ptr1Move(int  x, int  y ) 
+void PIBaseWdgX::Ptr1Move(int , int ) 
 {
 #ifdef DEBUG_PIBWDGX
@@ -710,5 +814,5 @@
 
 /* --Methode-- */
-void PIBaseWdgX::Keyboard(int key, PIKeyModifier kmod)
+void PIBaseWdgX::Keyboard(int /*key*/, PIKeyModifier /*kmod*/)
 {
 
@@ -844,4 +948,10 @@
 curs[PI_TDLRArrowPointer] =  XCreateFontCursor(mdsp, XC_fleur);
 
+/*  le GC pour DrawPixmap  */
+XGCValues  xgv;
+xgv.function = GXcopy;
+xgv.plane_mask = ~0;
+dpxgc = XCreateGC(mdsp, DefaultRootWindow(mdsp), GCFunction | GCPlaneMask, &xgv);
+
 return;
 }
@@ -879,2 +989,4 @@
 return;
 }
+
+
Index: /trunk/SophyaPI/PI/pibwdgx.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdgx.h	(revision 51)
+++ /trunk/SophyaPI/PI/pibwdgx.h	(revision 52)
@@ -16,4 +16,5 @@
   virtual         ~PIBaseWdgX();
 
+  virtual void    FinishCreate(); // appele par la fenetre mere, apres XtRealize()
 
 //  Activation des evenements   
@@ -24,5 +25,5 @@
 
 //  Trace graphiques
-  virtual void   EraseWindow();
+  virtual void   EraseWindow(int x0=0, int y0=0, int dx=0, int dy=0);
   virtual void   DrawString(int x, int y, char* s, int pos = 0);
   virtual void   DrawLine(int x1, int y1, int x2, int y2);
@@ -35,4 +36,6 @@
   virtual void   DrawMarker(int x0, int y0);
   virtual void   DrawMarkers(int *x, int *y, int n);
+  virtual void   DrawPixmap(int x, int y, unsigned char *pix, 
+                            int sx, int sy, PIColorMap* cmap);
 
   virtual int    CalcStringWidth(char const* s);
@@ -49,4 +52,7 @@
   virtual void   SelMarker(int msz, PIMarker mrk=PI_DotMarker);
   
+// Selection de zone de trace (clip)
+  virtual void       SetClipRectangle(int x0, int y0, int dx, int dy);
+  virtual void       ClearClipRectangle();
 
 // Acces aux attributs graphiques 
@@ -60,4 +66,8 @@
   virtual PIMarker   GetMarker();
   virtual int        GetMarkerSize();
+  virtual int        GetFontHeight(int& asc, int& desc);
+
+// Sauvegarde des attributs graphiques 
+  virtual void       SaveGraphicAtt();
 
 //  Fonction qui doit etre appelee pour rafraichir (retracer) tout 
@@ -85,4 +95,5 @@
 
 protected:
+
   void           Init();
   void           SelectFont(int isz, int jat);
Index: /trunk/SophyaPI/PI/picontainergen.cc
===================================================================
--- /trunk/SophyaPI/PI/picontainergen.cc	(revision 51)
+++ /trunk/SophyaPI/PI/picontainergen.cc	(revision 52)
@@ -10,5 +10,6 @@
 {
 mNCh = 0;
-mACSup = mPaSup = false;
+mACSup = false;   // Pas de suppression auto des widgets fils au delete
+mPaSup = false;
 mChilds = new (PIWdgGen * [NCHALGRP]);
 mMxCh = NCHALGRP;
@@ -39,4 +40,5 @@
 {
 stvis = 1;
+Manage();
 return;
 }
@@ -46,4 +48,5 @@
 {
 stvis = 0;
+UnManage();
 return;
 }
Index: /trunk/SophyaPI/PI/picontainerx.cc
===================================================================
--- /trunk/SophyaPI/PI/picontainerx.cc	(revision 51)
+++ /trunk/SophyaPI/PI/picontainerx.cc	(revision 52)
@@ -26,5 +26,5 @@
 {}
 
-/* --Methode-- */
+/* --Methode-- 
 void PIContainerX::Show()
 {
@@ -33,9 +33,9 @@
 }
 
-/* --Methode-- */
 void PIContainerX::Hide()
 {
 PIContainerGen::Hide();
-Unmanage();
+UnManage();
 }
 
+*/
Index: /trunk/SophyaPI/PI/picontainerx.h
===================================================================
--- /trunk/SophyaPI/PI/picontainerx.h	(revision 51)
+++ /trunk/SophyaPI/PI/picontainerx.h	(revision 52)
@@ -18,7 +18,4 @@
   virtual     ~PIContainerX();
 
-  virtual void           Show();
-  virtual void           Hide();
-
 };
 
Index: /trunk/SophyaPI/PI/pidrawer.cc
===================================================================
--- /trunk/SophyaPI/PI/pidrawer.cc	(revision 52)
+++ /trunk/SophyaPI/PI/pidrawer.cc	(revision 52)
@@ -0,0 +1,775 @@
+#include "pidrawer.h"
+#include "psfile.h"
+
+PIDrawer::PIDrawer()
+{
+  mBWdg = NULL; 
+  xW0 = yW0 = 0; xWd = yWd = 100; 
+  aXdir = false;  // Vrai si Axe X de Droite vers Gauche 
+  aYdir = false;  // Vrai si Axe Y de Haut vers Bas
+  SetLimits(-1, 1, -1, 1, kAxeDirLtoR, kAxeDirDownUp);
+  limitsFixed = 0;
+  SetAxesFlags(kAxesDflt);
+  clip = true;  
+  mDndfg = false;  // Pour controle de l'appel de Detach() si delete
+}
+
+PIDrawer::~PIDrawer()
+{
+  list<DrwBWId>::iterator it;
+  mDndfg = true;
+  for(it = mBWdgList.begin(); it != mBWdgList.end(); it++)
+         (*it).wdg->RemoveDrawer((*it).id);
+}
+
+
+void
+PIDrawer::SetLimits(double xmin, double xmax, double ymin, double ymax,
+                    int axrl, int ayud)
+{
+  if (xmax <= xmin || ymax <= ymin)
+    return; // $CHECK$ exception ?
+  if (axrl == kAxeDirLtoR)  aXdir = false;
+  else if (axrl == kAxeDirRtoL)  aXdir = true;
+  if (ayud == kAxeDirDownUp)  aYdir = false;
+  else if (ayud == kAxeDirUpDown)  aYdir = true;
+  xMin = xmin;
+  xMax = xmax;
+  yMin = ymin;
+  yMax = ymax;
+  SetDrwWdg(mBWdg, xW0, yW0, xWd, yWd);
+  CalcTicks();
+  limitsFixed = 1;
+}
+
+void
+PIDrawer::Attach(PIBaseWdgGen* wdg, int id)
+{
+  if (!wdg) return;
+  DrwBWId bwi;
+  bwi.id = id;  bwi.wdg = wdg;
+  mBWdgList.push_back(bwi);
+  return;
+}
+
+void
+PIDrawer::Detach(PIBaseWdgGen* wdg, int id)
+{
+  if (mDndfg) return;
+  if (!wdg) return;
+  list<DrwBWId>::iterator it;
+  for(it = mBWdgList.begin(); it != mBWdgList.end(); it++)
+     if ( ((*it).id == id) && ((*it).wdg == wdg) ) { mBWdgList.erase(it);  break; }
+  return;
+}
+
+
+void
+PIDrawer::SetDrwWdg(PIBaseWdgGen* drw, int x0, int y0, int dx, int dy)
+{
+  mBWdg = drw;
+  xW0 = x0;   yW0 = y0;
+  xWd = dx;   yWd = dy;
+  xScale = (double)dx/(xMax-xMin);
+  if (aXdir)  { 
+    xScale = -xScale;
+    xOrg   = -xMax * xScale;
+  }
+  else xOrg   = -xMin * xScale;
+  xOrg += xW0;
+
+  yScale = (double)dy/(yMax-yMin);
+  if (!aYdir) {
+    yScale = -yScale;
+    yOrg   = -yMax  * yScale;
+    }
+  else yOrg   = -yMin * yScale;
+  yOrg += yW0;
+  return;
+}
+
+
+void
+PIDrawer::CalcTicks()
+{
+	double xExt = xMax-xMin;
+	int lx = (int) ceil(log10(xExt)-0.1);
+	xExt = pow(10.0,lx);
+	xMajTickStep = xExt/10;
+	xMinTickStep = xMajTickStep/10;
+    xFirstMajTick = int(xMin / xMajTickStep) * xMajTickStep;
+    if (xFirstMajTick < xMin) xFirstMajTick += xMajTickStep;
+    xFirstMinTick = int(xMin / xMinTickStep) * xMinTickStep;
+    if (xFirstMinTick < xMin) xFirstMinTick += xMinTickStep;
+    
+    
+	double yExt = yMax-yMin;
+	int ly = (int) ceil(log10(yExt)-0.1);
+	yExt = pow(10.0,ly);
+	yMajTickStep = yExt/10;
+	yMinTickStep = yMajTickStep/10;
+    yFirstMajTick = int(yMin / yMajTickStep) * yMajTickStep;
+    if (yFirstMajTick < yMin) yFirstMajTick += yMajTickStep;
+    yFirstMinTick = int(yMin / yMinTickStep) * yMinTickStep;
+    if (yFirstMinTick < yMin) yFirstMinTick += yMinTickStep;
+    
+    yMajTickLen = (xMax-xMin)/100;
+    yMinTickLen = (xMax-xMin)/250;
+    xMajTickLen = (yMax-yMin)/100;
+    xMinTickLen = (yMax-yMin)/250;
+
+}
+
+void
+PIDrawer::Sc2Local(double x, double y, int& xpix, int& ypix)
+{
+  xpix = int(xOrg + x*xScale + .5);
+  ypix = int(yOrg + y*yScale + .5);
+}
+
+void
+PIDrawer::Sc2LocalF(double x, double y, float& xpix, float& ypix)
+{
+  xpix = (float)(xOrg + x*xScale + .5);
+  ypix = (float)(yOrg + y*yScale + .5);
+}
+
+void
+PIDrawer::Local2Sc(int xpix, int ypix, double& x, double& y)
+{
+  x = (xpix-xOrg)/xScale;
+  y = (ypix-yOrg)/yScale;
+}
+
+
+void
+PIDrawer::DSc2Local(double dx, double dy, int& dxpix, int& dypix)
+{
+  dxpix = int(dx*xScale + .5);
+  if (dxpix < 0)  dxpix = -dxpix;
+  dypix = int(dy*yScale + .5);
+  if (dypix < 0)  dypix = -dxpix;
+}
+
+
+void
+PIDrawer::Erase()
+{
+  if (!mBWdg) return;
+  mBWdg->EraseWindow(xW0, yW0, xWd, yWd);
+}
+
+void
+PIDrawer::DrawString(double x, double y, char* s, int pos)
+{
+  if (!mBWdg) return;
+  if (mBWdg->mPSOut) {
+    float xf, yf;
+    Sc2LocalF(x, y, xf, yf);
+    (mBWdg->mPSOut)->DrawString(xf,yf,s, mBWdg->GetForeground(), /* $CHECK$ PIFontSize ?? */
+                                mBWdg->GetFontAtt(),  mBWdg->GetFontSize()); 
+  }
+  else {
+    int xPix, yPix;
+    Sc2Local(x, y, xPix, yPix);
+    mBWdg->DrawString(xPix, yPix, s, pos);
+  }
+}
+
+void
+PIDrawer::DrawLine(double x1, double y1, double x2, double y2)
+{
+  
+  if (!mBWdg) return;
+  if (clip) {
+    if (x2 < xMin && x1 < xMin) return;
+    if (x2 > xMax && x1 > xMax) return;
+    if (y1 < yMin && y2 < yMin) return;
+    if (y1 > yMax && y2 > yMax) return;
+    if (x2 < x1) {
+      swap(x1,x2);
+      swap(y1,y2);
+    }
+    if (x2>xMax) {
+      y2 = y1 + (y2-y1)/(x2-x1)*(xMax-x1);
+      x2 = xMax;
+    }
+    if (x1<xMin) {
+      y1 = y2 + (y1-y2)/(x1-x2)*(xMin-x2);
+      x1 = xMin;
+    }
+    if (y2 < y1) {
+      swap(x1,x2);
+      swap(y1,y2);
+    }
+    if (y2>yMax) {
+      x2 = x1 + (x2-x1)/(y2-y1)*(yMax-y1);
+      y2 = yMax;
+    }
+    if (y1<yMin) {
+      x1 = x2 + (x1-x2)/(y1-y2)*(yMin-y2);
+      y1 = yMin;
+    }
+  }
+
+  if (mBWdg->mPSOut) {
+    float xf1, yf1, xf2, yf2;
+    Sc2LocalF(x1, y1, xf1, yf1);
+    Sc2LocalF(x2, y2, xf2, yf2);
+    (mBWdg->mPSOut)->DrawLine(xf1, yf1, xf2, yf2, mBWdg->GetForeground(), mBWdg->GetLineAtt());
+
+    return;
+  }
+  
+  int x1Pix, y1Pix, x2Pix, y2Pix;
+  Sc2Local(x1, y1, x1Pix, y1Pix);
+  Sc2Local(x2, y2, x2Pix, y2Pix);
+  mBWdg->DrawLine(x1Pix, y1Pix, x2Pix, y2Pix);
+}  
+
+
+void
+PIDrawer::DrawBox(double x, double y, double dx, double dy)
+{
+  if (!mBWdg) return;
+  if (clip) {
+    if (dx < 0) {
+      x = x+dx;
+      dx = -dx;
+    }
+    if (dy < 0) {
+      y = y+dy;
+      dy = -dy;
+    }
+    if (x > xMax || x+dx < xMin || y > yMax || y+dy < yMin) return;
+    if (x < xMin) {
+      dx -= (xMin-x);
+      x = xMin;
+    }
+    if (y < yMin) {
+      dy -= (yMin-y);
+      y = yMin;
+    }
+    if (x+dx > xMax)
+      dx = (xMax-x);
+    if (y+dy > yMax)
+      dy = (yMax-y);
+  }
+
+  if (mBWdg->mPSOut) {
+    float xf, yf, xf2, yf2;
+    Sc2LocalF(x, y, xf, yf);
+    Sc2LocalF(x+dx, y+dy, xf2, yf2);
+    if (xf2 < xf)  swap(xf, xf2);
+    if (yf2 < yf)  swap(yf, yf2);
+    (mBWdg->mPSOut)->DrawBox(xf, yf, xf2-xf, yf2-yf, mBWdg->GetForeground(), mBWdg->GetLineAtt() );
+    return;
+  }
+
+  int xPix, yPix, x2Pix, y2Pix;
+  Sc2Local(x, y, xPix, yPix);
+  Sc2Local(x+dx, y+dy, x2Pix, y2Pix);
+  if (x2Pix < xPix)  swap(xPix, x2Pix);
+  if (y2Pix < yPix)  swap(yPix, y2Pix);
+  mBWdg->DrawBox(xPix, yPix, x2Pix-xPix, y2Pix-yPix);
+}  
+
+void
+PIDrawer::DrawFBox(double x, double y, double dx, double dy)
+{
+
+  if (!mBWdg) return;
+  if (clip) {
+    if (dx < 0) {
+      x = x+dx;
+      dx = -dx;
+    }
+    if (dy < 0) {
+      y = y+dy;
+      dy = -dy;
+    }
+    if (x > xMax || x+dx < xMin || y > yMax || y+dy < yMin) return;
+    if (x < xMin) {
+      dx -= (xMin-x);
+      x = xMin;
+    }
+    if (y < yMin) {
+      dy -= (yMin-y);
+      y = yMin;
+    }
+    if (x+dx > xMax)
+      dx = (xMax-x);
+    if (y+dy > yMax)
+      dy = (yMax-y);
+  }
+
+  if (mBWdg->mPSOut) {
+    float xf, yf, xf2, yf2;
+    Sc2LocalF(x, y, xf, yf);
+    Sc2LocalF(x+dx, y+dy, xf2, yf2);
+    if (xf2 < xf)  swap(xf, xf2);
+    if (yf2 < yf)  swap(yf, yf2);
+    (mBWdg->mPSOut)->DrawFBox(xf, yf, xf2-xf, yf2-yf, mBWdg->GetForeground(), 
+                              mBWdg->GetForeground(), mBWdg->GetLineAtt());
+    return;
+  }
+
+  int xPix, yPix, x2Pix, y2Pix;
+  Sc2Local(x, y, xPix, yPix);
+  Sc2Local(x+dx, y+dy, x2Pix, y2Pix);
+  if (x2Pix < xPix)  swap(xPix, x2Pix);
+  if (y2Pix < yPix)  swap(yPix, y2Pix);
+  mBWdg->DrawFBox(xPix, yPix, x2Pix-xPix, y2Pix-yPix);
+}  
+
+void
+PIDrawer::DrawCircle(double x, double y, double r)
+{
+  if (!mBWdg) return;
+  if (mBWdg->mPSOut) {
+    float xf, yf, rf;
+    Sc2LocalF(x, y, xf, yf);
+    rf = r * xScale;
+    if (xScale < 0.)  rf = -rf;
+    (mBWdg->mPSOut)->DrawCircle(xf, yf, rf,mBWdg->GetForeground(), mBWdg->GetLineAtt());
+    return;
+  }
+
+  int xPix, yPix, rPix;
+  Sc2Local(x, y, xPix, yPix);
+  rPix = (int)(r * xScale);
+  if (xScale < 0.)  rPix = -rPix;
+  mBWdg->DrawCircle(xPix, yPix, rPix);
+}  
+
+void
+PIDrawer::DrawFCircle(double x, double y, double r)
+{
+  if (!mBWdg) return;
+  if (mBWdg->mPSOut) {
+    float xf, yf, rf;
+    Sc2LocalF(x, y, xf, yf);
+    rf = r * xScale;
+    if (xScale < 0.)  rf = -rf;
+    (mBWdg->mPSOut)->DrawFCircle(xf, yf, rf, mBWdg->GetForeground(), 
+                                 mBWdg->GetForeground(), mBWdg->GetLineAtt());
+    return;
+  }
+  int xPix, yPix, rPix;
+  Sc2Local(x, y, xPix, yPix);
+  rPix = (int)(r * xScale);
+  if (xScale < 0.)  rPix = -rPix;
+  mBWdg->DrawFCircle(xPix, yPix, rPix);
+}
+
+#define NMXMULTP  30   // Pour multipoint sans new
+
+void  
+PIDrawer::DrawPolygon(double *x, double *y, int n)
+{
+int ix[NMXMULTP], iy[NMXMULTP];
+int *pxi, *pyi;
+int i;
+ 
+if (!mBWdg) return;
+if (n <= 0)  return;
+
+if(mBWdg->mPSOut) {
+  float *xf, *yf;
+  xf = new float[n];
+  yf = new float[n];
+  for(i=0;i<n;i++)
+    Sc2LocalF(x[i], y[i], xf[i], yf[i]);
+    (mBWdg->mPSOut)->DrawPolygon(xf,yf,n, mBWdg->GetForeground(), mBWdg->GetLineAtt());
+  delete[] xf;
+  delete[] yf;
+  return;
+  }
+
+if (n > NMXMULTP) { pxi = new int[n];  pyi = new int[n]; }
+else { pxi = ix;  pyi = iy; }
+for(i=0; i<n; i++)  
+  Sc2Local(x[i], y[i], pxi[i], pyi[i]);
+mBWdg->DrawPolygon(pxi, pyi, n);
+if (n > NMXMULTP) { delete[] pxi;  delete[] pyi; }
+return;
+}
+  
+void  
+PIDrawer::DrawFPolygon(double *x, double *y, int n)
+{
+int xi[NMXMULTP], yi[NMXMULTP];
+int *pxi, *pyi;
+int i;
+ 
+if (!mBWdg) return;
+if (n <= 0)  return;
+
+if(mBWdg->mPSOut) {
+  float *xf, *yf;
+  xf = new float[n];
+  yf = new float[n];
+  for(i=0;i<n;i++)
+    Sc2LocalF(x[i], y[i], xf[i], yf[i]);
+    (mBWdg->mPSOut)->DrawFPolygon(xf, yf, n, mBWdg->GetForeground(), 
+                                  mBWdg->GetForeground(), mBWdg->GetLineAtt());
+  delete[] xf;
+  delete[] yf;
+  return;
+  }
+
+if (n > NMXMULTP) { pxi = new int[n];  pyi = new int[n]; }
+else { pxi = xi;  pyi = yi; }
+for(i=0; i<n; i++)  
+  Sc2Local(x[i], y[i], pxi[i], pyi[i]);
+mBWdg->DrawFPolygon(pxi, pyi, n);
+if (n > NMXMULTP) { delete[] pxi;  delete[] pyi; }
+return;
+}
+
+void  
+PIDrawer::DrawMarker(double x0, double y0)
+{
+  if (!mBWdg) return;
+  if(mBWdg->mPSOut) {
+    float xf, yf;
+    Sc2LocalF(x0, y0, xf, yf);
+    (mBWdg->mPSOut)->DrawMarker(xf, yf, mBWdg->GetMarker(), 
+                                mBWdg->GetForeground(), mBWdg->GetMarkerSize() );
+    return;    
+  }
+  int xPix, yPix;
+  Sc2Local(x0, y0, xPix, yPix);
+  mBWdg->DrawMarker(xPix, yPix);
+  return;
+}
+
+void  
+PIDrawer::DrawMarkers(double *x, double *y, int n)
+{
+int xi[NMXMULTP], yi[NMXMULTP];
+int *pxi, *pyi;
+int i;
+ 
+if (!mBWdg) return;
+if (n <= 0)  return;
+
+if(mBWdg->mPSOut) {
+  float *xf, *yf;
+  xf = new float[n];
+  yf = new float[n];
+  for(i=0;i<n;i++)
+    Sc2LocalF(x[i], y[i], xf[i], yf[i]);
+
+  (mBWdg->mPSOut)->DrawMarkers(xf, yf, n, mBWdg->GetMarker(), 
+                               mBWdg->GetForeground(), mBWdg->GetMarkerSize() );
+  delete[] xf;
+  delete[] yf;
+  return;
+  }
+
+if (n > NMXMULTP) { pxi = new int[n];  pyi = new int[n]; }
+else { pxi = xi;  pyi = yi; }
+for(i=0; i<n; i++)  
+  Sc2Local(x[i], y[i], pxi[i], pyi[i]);
+mBWdg->DrawMarkers(pxi, pyi, n);
+if (n > NMXMULTP) { delete[] pxi;  delete[] pyi; }
+return;
+}
+
+void  
+PIDrawer::DrawPixmap(double x, double y, unsigned char *pix,
+                          int sx, int sy, PIColorMap* cmap)
+{
+  if (!mBWdg) return;
+  if ( (sx < 1) || (sy < 1) )  return;
+  if ((pix == NULL) || (cmap == NULL)) return; 
+
+  if(mBWdg->mPSOut) {
+    float xf,yf;
+    Sc2LocalF(x, y, xf, yf);
+    (mBWdg->mPSOut)->Image(xf, yf, (float)sx, (float)sy, sx, sy, pix, cmap);
+    return;
+    }
+
+  int xPix, yPix;
+  Sc2Local(x, y, xPix, yPix);
+  mBWdg->DrawPixmap(xPix, yPix, pix, sx, sy, cmap);
+}
+
+double
+PIDrawer::StringWidth(char const* s)
+{
+  if (!mBWdg) return(0.);
+  return mBWdg->CalcStringWidth(s) / xScale;
+}
+
+double
+PIDrawer::FontHeight(double& asc, double& desc)
+{
+  if (!mBWdg) return(0.);
+  int h,a,d;
+  h = mBWdg->GetFontHeight(a,d);
+  asc = (double)a / yScale;
+  desc = (double)d / yScale;
+  return((double)h / yScale);
+}
+
+
+void
+PIDrawer::SelForeground(PIColors col)
+{
+  if (!mBWdg) return;
+  mBWdg->SelForeground(col);
+  return;  
+}
+
+
+void
+PIDrawer::SelBackground(PIColors col)
+{
+  if (!mBWdg) return;
+  mBWdg->SelBackground(col);
+  return;  
+}
+
+void
+PIDrawer::SelGOMode(PIGOMode mod)
+{
+  if (!mBWdg) return;
+  mBWdg->SelGOMode(mod);
+  return;  
+}
+
+void
+PIDrawer::SelFont(PIFontSize sz, PIFontAtt att)
+{
+  if (!mBWdg) return;
+  mBWdg->SelFont(sz, att);
+  return;  
+}
+
+void
+PIDrawer::SelLine(PILineAtt att)
+{
+  if (!mBWdg) return;
+  mBWdg->SelLine(att);
+  return;  
+}
+
+
+void
+PIDrawer::SelFontSz(double size, PIFontAtt att)
+{
+  if (!mBWdg) return;
+  int npt = int(fabs(size * yScale)+.5);
+  if (npt < 8) npt = 8;
+  if (npt > 127) npt = 127;
+  mBWdg->SelFontSzPt(npt, att);
+}
+
+void
+PIDrawer::SelMarker(double size, PIMarker mrk)
+{
+  if (!mBWdg) return;
+  int isz = int(fabs(size * xScale)+.5);
+  mBWdg->SelMarker( isz, mrk);
+}
+
+void
+PIDrawer::SelMarker(int msz, PIMarker mrk)
+{
+  if (!mBWdg) return;
+  mBWdg->SelMarker( msz, mrk);
+}
+
+
+
+void
+PIDrawer::SetAxesFlags(int flags)
+{
+  axesFlags = flags;
+  if (axesFlags & (kIntTicks | kExtTicks | kMajTicks | kMinTicks))
+    axesFlags |= kTicks;
+  if ((axesFlags & (kTicks | kIntTicks | kExtTicks)) == kTicks)
+    axesFlags |= kIntTicks | kExtTicks;
+  if ((axesFlags & (kTicks | kMajTicks | kMinTicks)) == kTicks)
+    axesFlags |= kMajTicks;
+}
+
+
+void
+PIDrawer::DrawAxes(int flags)
+{
+  NoClip();
+  if (flags == -1)
+    flags = axesFlags;
+    
+  
+  if (flags & kStdAxes) {
+  
+    // Les axes
+    
+    DrawLine(xMin, 0, xMax, 0);
+    DrawLine(0, yMin, 0, yMax);
+  
+    // Les ticks majeurs
+  
+    if (flags & kMajTicks) {
+        DrawHTicks(0, xMajTickLen, xMajTickLen, xFirstMajTick, xMajTickStep);
+        DrawVTicks(0, yMajTickLen, yMajTickLen, yFirstMajTick, yMajTickStep);
+    }
+    
+    // Les ticks mineurs
+  
+    if (flags & kMinTicks) {
+        DrawHTicks(0, xMinTickLen, xMinTickLen, xFirstMinTick, xMinTickStep);
+        DrawVTicks(0, yMinTickLen, yMinTickLen, yFirstMinTick, yMinTickStep);
+    }
+    
+    // Les labels
+    
+    if (flags & kLabels) {
+      if (!aYdir)
+        DrawHLabels(-xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
+      else 
+        DrawHLabels(xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
+      if (!aXdir)
+        DrawVLabels(-yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
+      else 
+        DrawVLabels(yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
+    }
+    
+  }
+  
+  if (flags & kBoxAxes) {
+  
+    // La boite
+    
+    DrawLine(xMin, yMin, xMax, yMin);
+    DrawLine(xMax, yMin, xMax, yMax);
+    DrawLine(xMax, yMax, xMin, yMax);
+    DrawLine(xMin, yMax, xMin, yMin);
+
+    // Longueur des ticks
+    
+    double extXMajTickLen = flags&kExtTicks ? xMajTickLen : 0;
+    double intXMajTickLen = flags&kIntTicks ? xMajTickLen : 0;
+    double extXMinTickLen = flags&kExtTicks ? xMinTickLen : 0;
+    double intXMinTickLen = flags&kIntTicks ? xMinTickLen : 0;
+    double extYMajTickLen = flags&kExtTicks ? yMajTickLen : 0;
+    double intYMajTickLen = flags&kIntTicks ? yMajTickLen : 0;
+    double extYMinTickLen = flags&kExtTicks ? yMinTickLen : 0;
+    double intYMinTickLen = flags&kIntTicks ? yMinTickLen : 0;
+
+    // Les ticks majeurs
+  
+    if (flags & kMajTicks) {
+        DrawHTicks(yMin, intXMajTickLen, extXMajTickLen, xFirstMajTick, xMajTickStep);
+        DrawHTicks(yMax, extXMajTickLen, intXMajTickLen, xFirstMajTick, xMajTickStep);
+        DrawVTicks(xMin, extYMajTickLen, intYMajTickLen, yFirstMajTick, yMajTickStep);
+        DrawVTicks(xMax, intYMajTickLen, extYMajTickLen, yFirstMajTick, yMajTickStep);
+    }
+    
+    // Les ticks mineurs
+  
+    if (flags & kMinTicks) {
+        DrawHTicks(yMin, intXMinTickLen, extXMinTickLen, xFirstMinTick, xMinTickStep);
+        DrawHTicks(yMax, extXMinTickLen, intXMinTickLen, xFirstMinTick, xMinTickStep);
+        DrawVTicks(xMin, extYMinTickLen, intYMinTickLen, yFirstMinTick, yMinTickStep);
+        DrawVTicks(xMax, intYMinTickLen, extYMinTickLen, yFirstMinTick, yMinTickStep);
+    }
+
+
+    // Les labels
+    
+    if (flags & kLabels) {
+      if (!aYdir) {
+        DrawHLabels(yMin-xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
+        DrawHLabels(yMax+xMajTickLen*2, xFirstMajTick, xMajTickStep,0);
+      }
+      else {
+        DrawHLabels(yMin-xMajTickLen*2, xFirstMajTick, xMajTickStep,0);
+        DrawHLabels(yMax+xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
+      }
+      if (!aXdir) {
+        DrawVLabels(xMin-yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
+        DrawVLabels(xMax+yMajTickLen*2, yFirstMajTick, yMajTickStep,-1);
+      }
+      else {
+        DrawVLabels(xMin-yMajTickLen*2, yFirstMajTick, yMajTickStep,-1);
+        DrawVLabels(xMax+yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
+      }
+    }
+  }
+  Clip();
+}
+
+  
+void
+PIDrawer::Draw()
+{
+}
+
+void
+PIDrawer::Draw(double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
+{
+Draw();
+}
+
+
+void
+PIDrawer::DrawHTicks(double y, double tickUp, double tickDown, double xBeg, double xStep)
+{
+  for (double x=xBeg; x<=xMax; x += xStep)
+    DrawLine(x, y-tickDown, x, y+tickUp);
+}
+
+void
+PIDrawer::DrawVTicks(double x, double tickLeft, double tickRight, double yBeg, double yStep)
+{
+  for (double y=yBeg; y<=yMax; y += yStep)
+    DrawLine(x-tickLeft, y, x+tickRight, y);
+}
+
+void
+PIDrawer::DrawHLabels(double y, double xBeg, double xStep, int just)
+{
+  double xOffset = 0;
+  int kk;
+  SelFontSz(xMajTickLen*4.);
+  for (double x=xBeg; x<=xMax; x += xStep) {
+      char label[20]; sprintf(label, "%-6g", x);
+      for(kk=0; kk<20; kk++)
+        if (label[kk] == ' ')   { label[kk] = '\0' ; break; }
+      double largeur = StringWidth(label);
+      if (just == 1)
+        xOffset = -largeur;
+      else if (just == 0)
+        xOffset = -largeur/2;
+      else
+        xOffset = 0;
+      if (aXdir)  xOffset = -xOffset;
+      DrawString(x+xOffset, y, label);
+  }
+}
+
+void
+PIDrawer::DrawVLabels(double x, double yBeg, double yStep, int just)
+{
+  double xOffset = 0;
+  SelFontSz(xMajTickLen*4.);
+  for (double y=yBeg; y<=yMax; y += yStep) {
+      char label[20]; sprintf(label, "%-6g", y);
+      double largeur = StringWidth(label);
+      if (just == 1)
+        xOffset = -largeur;
+      else if (just == 0)
+        xOffset = -largeur/2;
+      else
+        xOffset = 0;
+      if (aXdir)  xOffset = -xOffset;
+      DrawString(x+xOffset, y, label);
+  }
+}
+
Index: /trunk/SophyaPI/PI/pidrawer.h
===================================================================
--- /trunk/SophyaPI/PI/pidrawer.h	(revision 52)
+++ /trunk/SophyaPI/PI/pidrawer.h	(revision 52)
@@ -0,0 +1,131 @@
+#ifndef PIDRAWER_H
+#define PIDRAWER_H
+
+#include "pibwdggen.h"
+#include <list>
+
+enum {
+  kStdAxes     = 0x0001,
+  kBoxAxes     = 0x0002,
+  kTicks       = 0x0004,
+  kIntTicks    = 0x0010,
+  kExtTicks    = 0x0020,
+  kMajTicks    = 0x0040,
+  kMinTicks    = 0x0080,
+  kLabels      = 0x1000,
+  kAxesDflt    = kStdAxes | kTicks | kLabels
+};
+
+enum {
+  kAxeDirSame     = 0,
+  kAxeDirLtoR     = 1,
+  kAxeDirRtoL     = 2,
+  kAxeDirDownUp   = 3,
+  kAxeDirUpDown   = 4
+};
+
+
+class PIDrawer {
+public:
+                     PIDrawer();
+  virtual           ~PIDrawer();
+
+  virtual void       SetLimits(double xmin, double xmax, double ymin, double ymax,
+                               int axrl=kAxeDirSame, int ayud=kAxeDirSame);
+
+
+  virtual void       Erase();
+  virtual void       DrawString(double x, double y, char* s, int pos = 0);
+  virtual void       DrawLine(double x1, double y1, double x2, double y2);
+  virtual void       DrawBox(double x0, double y0, double dx, double dy);
+  virtual void       DrawFBox(double x0, double y0, double dx, double dy);
+  virtual void       DrawCircle(double x0, double y0, double r);
+  virtual void       DrawFCircle(double x0, double y0, double r);
+  virtual void       DrawPolygon(double *x, double *y, int n);  
+  virtual void       DrawFPolygon(double *x, double *y, int n);
+  virtual void       DrawMarker(double x0, double y0);
+  virtual void       DrawMarkers(double *x0, double *y0, int n);
+  virtual void       DrawPixmap(double x, double y, unsigned char *pix, 
+                                int sx, int sy, PIColorMap* cmap);
+
+  virtual double     StringWidth(char const*);
+  virtual double     FontHeight(double& asc, double& desc);
+
+  virtual void       SelForeground(PIColors col=PI_Black);
+  virtual void       SelBackground(PIColors col=PI_White);
+  virtual void       SelGOMode(PIGOMode mod=PI_GOCopy);
+  virtual void       SelFont(PIFontSize sz=PI_NormalSizeFont, 
+                             PIFontAtt att=PI_RomanFont);
+  virtual void       SelLine(PILineAtt att=PI_NormalLine);
+  virtual void       SelFontSz(double size, PIFontAtt att=PI_RomanFont); 
+  virtual void       SelMarker(double size=0, PIMarker mrk=PI_DotMarker); 
+  virtual void       SelMarker(int msz=3, PIMarker mrk=PI_DotMarker); 
+
+  virtual void       DrawAxes(int flags = -1);
+  virtual void       SetAxesFlags(int flags=kAxesDflt);
+    
+  virtual void       Draw();
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax);
+  
+  virtual void       Sc2Local(double x, double y, int& xpix, int& ypix);
+  virtual void       Sc2LocalF(double x, double y, float& xpix, float& ypix);
+  virtual void       Local2Sc(int xpix, int ypix, double& x, double& y);
+  virtual void       DSc2Local(double dx, double dy, int& dxpix, int& dypix);
+  
+
+
+  double XMin() const {return xMin;}
+  double XMax() const {return xMax;}
+  double YMin() const {return yMin;}
+  double YMax() const {return yMax;}
+
+  int    LimitsFixed() const {return limitsFixed;}
+  void   FreeLimits() {limitsFixed = 0;}
+  void   NoClip() {clip = false;}
+  void   Clip() {clip = true;}
+
+//  Les objets/methodes suivants devraient etre protected     
+//  Pb avec acces depuis PIBaseWdgGen (Reza 11/07/97) 
+  virtual void       SetDrwWdg(PIBaseWdgGen* drw, int x0, int y0, int dx, int dy);
+//  Je declare en public a cause de cxx - Reza 11/07/97 
+  struct DrwBWId { int id; PIBaseWdgGen* wdg; };
+  
+protected:
+  friend class PIBaseWdgGen;
+  virtual void       Attach(PIBaseWdgGen*, int id);
+  virtual void       Detach(PIBaseWdgGen*, int id);
+
+  void CalcTicks();
+
+  void DrawHTicks(double y, double tickUp, double tickDown, double xBeg, double xStep);
+  void DrawVTicks(double x, double tickLeft, double tickRight, double yBeg, double yStep);
+  void DrawHLabels(double y, double xBeg, double xStep, int just=0);
+  void DrawVLabels(double x, double yBeg, double yStep, int just=0);
+
+  
+  double xMin, xMax, yMin, yMax; // Valeurs en unites user
+  double xOrg, yOrg;             // Position en pixels de (0.0, 0.0)
+  double xScale, yScale;         // Pixels par unites graphiques
+  int xW0, yW0, xWd, yWd;        // Origine/largeur ds la fenetre de trace
+  bool   aXdir, aYdir;           // Sens des axes horiz, vertical 
+
+  double xFirstMajTick, xFirstMinTick;
+  double yFirstMajTick, yFirstMinTick;
+  double xMajTickStep, xMinTickStep;
+  double yMajTickStep, yMinTickStep;
+  double xMajTickLen,  xMinTickLen;
+  double yMajTickLen,  yMinTickLen;
+  
+  int limitsFixed;
+  int axesFlags;
+  
+  PIBaseWdgGen* mBWdg;
+  bool clip;
+
+  list<DrwBWId>  mBWdgList;
+  bool mDndfg;
+  
+};
+
+
+#endif
Index: /trunk/SophyaPI/PI/pidrawwin.cc
===================================================================
--- /trunk/SophyaPI/PI/pidrawwin.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pidrawwin.cc	(revision 52)
@@ -16,7 +16,7 @@
 
 void
-PIDrawWindow::AddDrawer(PIScDrawer* d)
+PIDrawWindow::AddScDrawer(PIScDrawer* d, bool ad)
 {
-  mDrawWdg->AddDrawer(d);
+  mDrawWdg->AddScDrawer(d, ad);
 }
 
Index: /trunk/SophyaPI/PI/pidrawwin.h
===================================================================
--- /trunk/SophyaPI/PI/pidrawwin.h	(revision 51)
+++ /trunk/SophyaPI/PI/pidrawwin.h	(revision 52)
@@ -15,5 +15,5 @@
                 ~PIDrawWindow();
                 
- virtual void    AddDrawer(PIScDrawer*);                
+ virtual void    AddScDrawer(PIScDrawer*, bool ad=false);                
  virtual void    SetAxesFlags(int flags=-1);
  inline PIScDrawWdg * DrawWdg() { return mDrawWdg; }
Index: /trunk/SophyaPI/PI/pifilechox.cc
===================================================================
--- /trunk/SophyaPI/PI/pifilechox.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pifilechox.cc	(revision 52)
@@ -25,5 +25,5 @@
 pif = (PIFileChooserX *) usd ;
 pif->mSt = 1;
-pif->MWin()->Unmanage();
+pif->MWin()->UnManage();
 //pif->Send(pif->Msg(), (void *) (pif->GetFileName().c_str()));
 CStrFrXmStr(calld->value, pif->mFName, 512); 
@@ -39,5 +39,5 @@
 pif->mSt = 0;
 pif->mFName[0] = '\0';
-pif->MWin()->Unmanage();
+pif->MWin()->UnManage();
 pif->Send(pif->Msg(), PIMsg_Cancel, NULL);
 return;
Index: /trunk/SophyaPI/PI/pihisto.cc
===================================================================
--- /trunk/SophyaPI/PI/pihisto.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pihisto.cc	(revision 52)
@@ -2,23 +2,16 @@
 #include "pihisto.h"
 
-PIHisto::PIHisto(Histo* histo)
+PIHisto::PIHisto(Histo* histo, bool ad)
 : PIScDrawer(), mHisto(histo)
 {
-  ahisup = false;     // Flag pour suppression automatique de mHisto
+  mAdDO = ad;     // Flag pour suppression automatique de mHisto
 }
 
 PIHisto::~PIHisto()
 {
-  if (ahisup)
+  if (mAdDO)
     delete mHisto;
 }
 
-
-void
-PIHisto::AttachTo(PIScDrawWdg* wdg)
-{
-  PIScDrawer::AttachTo(wdg);
-  UpdateSize();
-}
 
 
@@ -26,6 +19,6 @@
 PIHisto::UpdateSize()
 {
-  if (!mDrawWdg) return;
-  if (mDrawWdg->LimitsFixed()) return;
+  if (!mDrawer) return;
+  if (mDrawer->LimitsFixed()) return;
   // Commencer par trouver nos limites
   
@@ -36,13 +29,17 @@
   double ymin = mHisto->VMin();
   
-  mDrawWdg->SetLimits(xmin, xmax, ymin, ymax);
-  mDrawWdg->SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
+  if (mDrawWdg)
+    mDrawWdg->SetLimits(xmin, xmax, ymin, ymax);
+  else 
+    mDrawer->SetLimits(xmin, xmax, ymin, ymax);
+
+  mDrawer->SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
 }
 
 
 void
-PIHisto::Draw()
+PIHisto::Draw(double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
 {
-  if (!mDrawWdg) return;
+  if (!mDrawer) return;
   for (int i=0; i<mHisto->NBins(); i++) {
 		double left   = mHisto->BinLowEdge(i);
@@ -50,6 +47,6 @@
 		double bottom = 0;
 		double height = (*mHisto)(i);
-		mDrawWdg->ScDrawFBox(left,bottom,width,height);
-		mDrawWdg->ScDrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
+		mDrawer->DrawFBox(left,bottom,width,height);
+		mDrawer->DrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
 	}
   DrawStats();
@@ -60,24 +57,15 @@
 {
   // Une boite dans le coin superieur droit
-  if (!mDrawWdg) return;
+  if (!mDrawer) return;
   double cellHeight = (mDrawWdg->YMax() - mDrawWdg->YMin()) * 0.05;
   double cellWidth  = (mDrawWdg->XMax() - mDrawWdg->XMin()) * 0.23;
-  mDrawWdg->ScDrawLine(mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax(),
+  mDrawer->DrawLine(mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax(),
                        mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax() - cellHeight);
-  mDrawWdg->ScDrawLine(mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax() - cellHeight,
+  mDrawer->DrawLine(mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax() - cellHeight,
                        mDrawWdg->XMax()            , mDrawWdg->YMax() - cellHeight);
   char label[50];
   sprintf(label, "N = %.6g", mHisto->NData());
-  mDrawWdg->ScSelFontSz((mDrawWdg->YMax() - mDrawWdg->YMin())/30);
-  mDrawWdg->ScDrawString(mDrawWdg->XMax() - cellWidth*0.9, mDrawWdg->YMax() - cellHeight*0.8, label);
+  mDrawer->SelFontSz((mDrawWdg->YMax() - mDrawWdg->YMin())/30);
+  mDrawer->DrawString(mDrawWdg->XMax() - cellWidth*0.9, mDrawWdg->YMax() - cellHeight*0.8, label);
                        
 }
-
-void
-PIHisto::Refresh()
-{
-  if (!mDrawWdg) return;
-  mDrawWdg->FreeLimits();
-  UpdateSize();
-  mDrawWdg->Refresh();
-}
Index: /trunk/SophyaPI/PI/pihisto.h
===================================================================
--- /trunk/SophyaPI/PI/pihisto.h	(revision 51)
+++ /trunk/SophyaPI/PI/pihisto.h	(revision 52)
@@ -2,24 +2,18 @@
 #define PIHISTO_H
 
-
+#include "histos.h"
 #include "piscdrawwdg.h"
-#include "histos.h"
 
 class PIHisto : public PIScDrawer {
 public:
-                     PIHisto(Histo* histo);
+                     PIHisto(Histo* histo, bool ad=false);
   virtual           ~PIHisto();
-  virtual void       Draw();
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax);
+  virtual void       UpdateSize();
   virtual void       DrawStats();
-  virtual void       Refresh();  // Recalcule les limites, et reaffiche
-  inline  void       SetAutoDelHisto(bool ad=false) {  ahisup = ad; } 
   inline  Histo*     Histogram() { return(mHisto); }
 
 protected:
   Histo* mHisto;
-  bool   ahisup;
-
-  virtual void       AttachTo(PIScDrawWdg*);
-  virtual void       UpdateSize();
 };
 
Index: /trunk/SophyaPI/PI/pimenux.cc
===================================================================
--- /trunk/SophyaPI/PI/pimenux.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pimenux.cc	(revision 52)
@@ -18,5 +18,5 @@
 
 /* Nouvelle-Fonction */
-void  menub_action(Widget w, XtPointer *usd, XtPointer *calld)
+void  menub_action(Widget /*w*/, XtPointer *usd, XtPointer* /*calld*/)
 {
 PIMenuX *pim;
@@ -131,5 +131,5 @@
 
 /* --Methode-- */
-void PIMenuX::CheckItemNum(int n, bool st)
+void PIMenuX::CheckItemNum(int n, bool /*st*/)
 {
 printf("PIMenuX::CheckItemNum(%d,bool) Error/ Not yet implemented \n", n);
@@ -144,5 +144,5 @@
 
 /* --Methode-- */
-void PIMenuX::Show(PIWdg *w, int px, int py)
+void PIMenuX::Show(PIWdg* /*w*/, int /*px*/, int /*py*/)
 {
 Manage();
@@ -153,5 +153,5 @@
 void PIMenuX::Hide()
 {
-// Unmanage();
+// UnManage();
 }
 
Index: /trunk/SophyaPI/PI/pimsghandler.h
===================================================================
--- /trunk/SophyaPI/PI/pimsghandler.h	(revision 51)
+++ /trunk/SophyaPI/PI/pimsghandler.h	(revision 52)
@@ -13,16 +13,20 @@
         PIMsg_Resize        = 3,
 
-	PIMsg_OK            = 11,
-	PIMsg_Cancel        = 12,
-	PIMsg_Help          = 13,
-
-	PIMsg_DataChanged   = 21,
-	PIMsg_Click         = 22,
-        PIMsg_Press         = 23,
+	PIMsg_Click         = 21,
+        PIMsg_Press         = 22,
+        PIMsg_Release       = 23,
         PIMsg_Drag          = 24,
         PIMsg_Drop          = 25,
+        PIMsg_Copy          = 26,
+        PIMsg_Paste         = 27,
+        PIMsg_Cut           = 28,
 
-        PIMsg_Select        = 31,
-        PIMsg_ClearSel      = 32
+	PIMsg_OK            = 21,
+	PIMsg_Cancel        = 22,
+	PIMsg_Help          = 23,
+
+	PIMsg_DataChanged   = 31,
+        PIMsg_Select        = 32,
+        PIMsg_ClearSel      = 33
 
 };
Index: /trunk/SophyaPI/PI/pintuple.cc
===================================================================
--- /trunk/SophyaPI/PI/pintuple.cc	(revision 52)
+++ /trunk/SophyaPI/PI/pintuple.cc	(revision 52)
@@ -0,0 +1,108 @@
+#include <stdio.h>
+#include "pintuple.h"
+
+ 
+/* --Methode-- */
+PINTuple::PINTuple(NTuple* nt, bool ad)
+: PIScDrawer()
+{
+  mNT = nt;
+  mAdDO = ad; 
+  SelectXY(NULL, NULL);
+  SelectErrBar();
+}
+
+PINTuple::~PINTuple()
+{
+  if (mAdDO && mNT)  delete mNT;
+}
+
+/* --Methode-- */
+void  PINTuple::SelectXY(char* px, char* py)
+{
+if (mNT == NULL)  xK = yK = -1;
+if (px == NULL) xK = -1;
+else xK = mNT->IndexNom(px);
+if (py == NULL) yK = -1;
+else yK = mNT->IndexNom(py);
+}
+
+/* --Methode-- */
+void  PINTuple::SelectErrBar(char* erbx, char* erby)
+{
+if (mNT == NULL)  xebK = yebK = -1;
+if (erbx == NULL) xebK = -1;
+else xebK = mNT->IndexNom(erbx);
+if (erby == NULL) yebK = -1;
+else yebK = mNT->IndexNom(erby);
+}
+
+
+/* --Methode-- */
+void PINTuple::UpdateSize()
+{
+  if (!mNT) return;
+  if (mNT->NEntry() <= 0)  return;
+  if ( (xK < 0) || (yK < 0) )   return;
+  if (!mDrawer) return;
+  if (mDrawer->LimitsFixed()) return;
+
+  // Commencer par trouver nos limites
+  float dx, dy;
+  float xmin, xmax, ymin, ymax;
+  xmin = ymin = 9.e19;
+  xmax = ymax = -9.e19;
+  mNT->GetMinMax(xK, xmin, xmax);
+  mNT->GetMinMax(yK, ymin, ymax);
+    
+  dx = 0.02*(xmax-xmin);
+  dy = 0.02*(ymax-ymin);
+  
+  if (mDrawWdg) 
+    mDrawWdg->SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy, 
+                        kAxeDirLtoR, kAxeDirDownUp); 
+  else 
+    mDrawer->SetLimits(xmin-dx, xmax+dx, ymin-dy, ymax+dy, 
+                        kAxeDirLtoR, kAxeDirDownUp); 
+  
+  mDrawer->SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
+}
+
+
+/* --Methode-- */
+void PINTuple::Draw(double xmin, double ymin, double xmax, double ymax)
+{
+double xp,yp,xer,yer;
+char buff[128];
+int nok, nl2;
+
+if (!mNT) return;
+if (!mDrawer) return;
+if ( (xK < 0) || (yK < 0) )  return;
+bool fgseb = false;
+if ( (xebK < 0) || (yebK < 0) ) fgseb = true;
+
+nok = 0;  
+for (int i=0; i<mNT->NEntry(); i++) {
+  xp = mNT->GetVal(i, xK);
+  yp = mNT->GetVal(i, xK);
+  if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
+  nok++;
+  mDrawer->DrawMarker(xp, yp); 
+  if ( xebK >= 0 ) {
+    xer = mNT->GetVal(i, xebK);
+    mDrawer->DrawLine(xp-xer/2., yp, xp+xer/2., yp);
+  }
+  if ( yebK >= 0 ) {
+    yer = mNT->GetVal(i, yebK);
+    mDrawer->DrawLine(xp, yp-yer/2., xp, yp+yer/2.);
+  }
+}
+
+if (!mDrawWdg)  return;
+if (!MainScDrawer())  return;
+sprintf(buff, "NTuple:  NEntry= %d  NDisp= %d", (int)mNT->NEntry(), nok);
+mDrawWdg->DrawString(15,15,buff);
+return;
+}
+
Index: /trunk/SophyaPI/PI/pintuple.h
===================================================================
--- /trunk/SophyaPI/PI/pintuple.h	(revision 52)
+++ /trunk/SophyaPI/PI/pintuple.h	(revision 52)
@@ -0,0 +1,30 @@
+#ifndef PISTLIST_H
+#define PISTLIST_H
+
+#include "ntuple.h"
+#include "piscdrawwdg.h"
+
+class PINTuple : public PIScDrawer {
+public:
+                     PINTuple(NTuple* nt, bool ad);
+  virtual           ~PINTuple();
+  
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax);
+  virtual void       UpdateSize();
+  
+          void       SelectXY(char* px, char* py);
+          void       SelectErrBar(char* erbx=NULL, char* erby=NULL);
+
+       
+protected:
+  NTuple* mNT;
+  int xK, yK;          // Index du nom de variable en X/Y ds le ntuple
+  int xebK, yebK;      // Index du nom de variable en ErrBarX/Y ds le ntuple
+
+};
+
+#endif
+
+
+
+
Index: /trunk/SophyaPI/PI/pipixmapx.cc
===================================================================
--- /trunk/SophyaPI/PI/pipixmapx.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pipixmapx.cc	(revision 52)
@@ -169,5 +169,5 @@
 myximg->data = new char [YSize()*myximg->bytes_per_line];
 if (myximg->data == NULL)  
-  { XFree(myximg); myximg = NULL; } 
+  { XFree(myximg); myximg = NULL;  return; } 
 
 for(j=0; j<YSize(); j++)
Index: /trunk/SophyaPI/PI/piscdrawwdg.cc
===================================================================
--- /trunk/SophyaPI/PI/piscdrawwdg.cc	(revision 51)
+++ /trunk/SophyaPI/PI/piscdrawwdg.cc	(revision 52)
@@ -1,6 +1,4 @@
+#include "generalfit.h"
 #include "piscdrawwdg.h"
-#include "generalfit.h"
-#include <algorithm>
-
 
 PIScDrawWdg::PIScDrawWdg(PIContainerGen *par, char *nom,
@@ -8,13 +6,17 @@
 :PIBaseWdg(par, nom, sx, sy, px, py)
 {
-  SetLimits(-1, 1, -1, 1);
-  limitsFixed = 0;
+  mBDrw = new PIDrawer;
+  SetSpan();
+  SetLimits(-1.,1.,-1.,1.);
+  FreeLimits();
   xEndDrag = yEndDrag = xBegDrag = yBegDrag = 0;
-  SetAxesFlags(kAxesDflt);
-  clip = true;
+
+  Clip();
+
   padsup = false;
   mTrlb = mTxw = NULL;
   mTrW = NULL;
   SetTextWin(NULL);
+
   ActivateButton(1);    // Pour pouvoir activer la fenetre et coordonnees 
   ActivateMove(1);      //    "         "         "        "
@@ -26,5 +28,6 @@
 PIScDrawWdg::~PIScDrawWdg()
 {
-  DeleteDrawers();
+  DeleteScDrawers();
+  delete mBDrw;
   if (mTrW)  delete mTrW;
 }
@@ -33,16 +36,11 @@
 void
 PIScDrawWdg::SetLimits(double xmin, double xmax, double ymin, double ymax,
-                       bool axrl, bool ayud, bool tmp)
+                       int axrl, int ayud, bool tmp)
 {
   if (xmax <= xmin || ymax <= ymin)
     return; // $CHECK$ exception ?
-  aXdir = axrl;      // Vrai si Axe X de Droite vers Gauche
-  aYdir = ayud;      // Vrai si Axe Y de Haut vers Bas
-  xMin = xmin;
-  xMax = xmax;
-  yMin = ymin;
-  yMax = ymax;
-  mPPos[0] = 0.5*(xMin+xMax);
-  mPPos[1] = 0.5*(yMin+yMax);
+  mBDrw->SetLimits(xmin, xmax, ymin, ymax, axrl, ayud);
+  mPPos[0] = 0.5*(XMin()+XMax());
+  mPPos[1] = 0.5*(YMin()+YMax());
   if (!tmp) {
     xMinS = xmin;
@@ -51,7 +49,4 @@
     yMaxS = ymax;
   }
-  CalcScale();
-  CalcTicks();
-  limitsFixed = 1;
 }
 
@@ -59,514 +54,89 @@
 PIScDrawWdg::Resize()
 {
-  CalcScale();
-  CalcTicks();
+  SetSpan();
   Refresh();
 }
 
 void
-PIScDrawWdg::CalcScale()
-{
-  double margeH = (xMax-xMin)*0.15;
-  double margeV = (yMax-yMin)*0.15;
-  xScale = XSize() / (xMax-xMin + 2*margeH);
-  if (aXdir)  { 
-    xScale = -xScale;
-    xOrg   = (-xMax - margeH) * xScale;// + XPos();
-  }
-  else xOrg   = (-xMin + margeH) * xScale;// + XPos();
-  yScale = YSize() / (yMax-yMin + 2*margeV);
-  if (!aYdir) {
-    yScale = -yScale;
-    yOrg   = (-yMax - margeV) * yScale;// + YPos();
-  }
-  else yOrg   = (-yMin + margeV) * yScale;// + YPos();
-return;
-}
-
-void
-PIScDrawWdg::CalcTicks()
-{
-	double xExt = xMax-xMin;
-	int lx = (int) ceil(log10(xExt)-0.1);
-	xExt = pow(10.0,lx);
-	xMajTickStep = xExt/10;
-	xMinTickStep = xMajTickStep/10;
-    xFirstMajTick = int(xMin / xMajTickStep) * xMajTickStep;
-    if (xFirstMajTick < xMin) xFirstMajTick += xMajTickStep;
-    xFirstMinTick = int(xMin / xMinTickStep) * xMinTickStep;
-    if (xFirstMinTick < xMin) xFirstMinTick += xMinTickStep;
-    
-    
-	double yExt = yMax-yMin;
-	int ly = (int) ceil(log10(yExt)-0.1);
-	yExt = pow(10.0,ly);
-	yMajTickStep = yExt/10;
-	yMinTickStep = yMajTickStep/10;
-    yFirstMajTick = int(yMin / yMajTickStep) * yMajTickStep;
-    if (yFirstMajTick < yMin) yFirstMajTick += yMajTickStep;
-    yFirstMinTick = int(yMin / yMinTickStep) * yMinTickStep;
-    if (yFirstMinTick < yMin) yFirstMinTick += yMinTickStep;
-    
-//    xMajTickLen = -2/yScale;
-//    xMinTickLen = -1/yScale;
-//    yMajTickLen = 2/xScale;
-//    yMinTickLen = 1/xScale;
-
-    yMajTickLen = (xMax-xMin)/100;
-    yMinTickLen = (xMax-xMin)/250;
-    xMajTickLen = (yMax-yMin)/100;
-    xMinTickLen = (yMax-yMin)/250;
-
-}
-
-void
-PIScDrawWdg::Sc2Local(double x, double y, int& xpix, int& ypix)
-{
-  xpix = int(xOrg + x*xScale + .5);
-  ypix = int(yOrg + y*yScale + .5);
-}
-
-void
-PIScDrawWdg::Local2Sc(int xpix, int ypix, double& x, double& y)
-{
-  x = (xpix-xOrg)/xScale;
-  y = (ypix-yOrg)/yScale;
-}
-
-
-void
-PIScDrawWdg::DSc2Local(double dx, double dy, int& dxpix, int& dypix)
-{
-  dxpix = int(dx*xScale + .5);
-  dypix = int(dy*yScale + .5);
-}
-
-double
-PIScDrawWdg::ScStringWidth(char const* s)
-{
-  return CalcStringWidth(s) / xScale;
-}
-
-void
-PIScDrawWdg::ScSelFontSz(double size, PIFontAtt att)
-{
-  int npt = int(fabs(size * yScale)+.5);
-  if (npt < 8) npt = 8;
-  if (npt > 127) npt = 127;
-  SelFontSzPt(npt, att);
-}
-
-void
-PIScDrawWdg::ScSelMarker(double size, PIMarker mrk)
-{
-  int isz = int(fabs(size * xScale)+.5);
-  SelMarker( isz, mrk);
-}
-
-void
-PIScDrawWdg::ScDrawString(double x, double y, char* s, int pos)
-{
-  int xPix, yPix;
-  Sc2Local(x, y, xPix, yPix);
-  DrawString(xPix, yPix, s, pos);
-}
-
-void
-PIScDrawWdg::ScDrawLine(double x1, double y1, double x2, double y2)
-{
+PIScDrawWdg::SetSpan()
+{
+  int x0, y0, dx, dy;
+  x0 = (int)(XSize()*0.12);
+  y0 = (int)(YSize()*0.12);
+  dx = (int)(XSize()*0.76+0.5);
+  dy = (int)(YSize()*0.76+0.5);
+  mBDrw->SetDrwWdg(this, x0, y0, dx, dy);
+  return;
+}
+
+void
+PIScDrawWdg::DrawAxes(int flags)
+{
+  mBDrw->DrawAxes(flags);
+}
+
+
+void
+PIScDrawWdg::SetAxesFlags(int flags)
+{
+  mBDrw->SetAxesFlags(flags);
+}
   
-  if (clip) {
-    if (x2 < xMin && x1 < xMin) return;
-    if (x2 > xMax && x1 > xMax) return;
-    if (y1 < yMin && y2 < yMin) return;
-    if (y1 > yMax && y2 > yMax) return;
-    if (x2 < x1) {
-      swap(x1,x2);
-      swap(y1,y2);
-    }
-    if (x2>xMax) {
-      y2 = y1 + (y2-y1)/(x2-x1)*(xMax-x1);
-      x2 = xMax;
-    }
-    if (x1<xMin) {
-      y1 = y2 + (y1-y2)/(x1-x2)*(xMin-x2);
-      x1 = xMin;
-    }
-    if (y2 < y1) {
-      swap(x1,x2);
-      swap(y1,y2);
-    }
-    if (y2>yMax) {
-      x2 = x1 + (x2-x1)/(y2-y1)*(yMax-y1);
-      y2 = yMax;
-    }
-    if (y1<yMin) {
-      x1 = x2 + (x1-x2)/(y1-y2)*(yMin-y2);
-      y1 = yMin;
-    }
-  }
-  int x1Pix, y1Pix, x2Pix, y2Pix;
-  Sc2Local(x1, y1, x1Pix, y1Pix);
-  Sc2Local(x2, y2, x2Pix, y2Pix);
-  DrawLine(x1Pix, y1Pix, x2Pix, y2Pix);
-}  
-
-
-void
-PIScDrawWdg::ScDrawBox(double x, double y, double dx, double dy)
-{
-  if (clip) {
-    if (dx < 0) {
-      x = x+dx;
-      dx = -dx;
-    }
-    if (dy < 0) {
-      y = y+dy;
-      dy = -dy;
-    }
-    if (x > xMax || x+dx < xMin || y > yMax || y+dy < yMin) return;
-    if (x < xMin) {
-      dx -= (xMin-x);
-      x = xMin;
-    }
-    if (y < yMin) {
-      dy -= (yMin-y);
-      y = yMin;
-    }
-    if (x+dx > xMax)
-      dx = (xMax-x);
-    if (y+dy > yMax)
-      dy = (yMax-y);
-  }
-  int xPix, yPix, x2Pix, y2Pix;
-  Sc2Local(x, y, xPix, yPix);
-  Sc2Local(x+dx, y+dy, x2Pix, y2Pix);
-  DrawBox(xPix, yPix, x2Pix-xPix, y2Pix-yPix);
-}  
-
-void
-PIScDrawWdg::ScDrawFBox(double x, double y, double dx, double dy)
-{
-  if (clip) {
-    if (dx < 0) {
-      x = x+dx;
-      dx = -dx;
-    }
-    if (dy < 0) {
-      y = y+dy;
-      dy = -dy;
-    }
-    if (x > xMax || x+dx < xMin || y > yMax || y+dy < yMin) return;
-    if (x < xMin) {
-      dx -= (xMin-x);
-      x = xMin;
-    }
-    if (y < yMin) {
-      dy -= (yMin-y);
-      y = yMin;
-    }
-    if (x+dx > xMax)
-      dx = (xMax-x);
-    if (y+dy > yMax)
-      dy = (yMax-y);
-  }
-  int xPix, yPix, x2Pix, y2Pix;
-  Sc2Local(x, y, xPix, yPix);
-  Sc2Local(x+dx, y+dy, x2Pix, y2Pix);
-  DrawFBox(xPix, yPix, x2Pix-xPix, y2Pix-yPix);
-}  
-
-void
-PIScDrawWdg::ScDrawCircle(double x, double y, double r)
-{
-  int xPix, yPix, rPix;
-  Sc2Local(x, y, xPix, yPix);
-  rPix = r * xScale;
-  DrawCircle(xPix, yPix, rPix);
-}  
-
-void
-PIScDrawWdg::ScDrawFCircle(double x, double y, double r)
-{
-  int xPix, yPix, rPix;
-  Sc2Local(x, y, xPix, yPix);
-  rPix = r * xScale;
-  DrawFCircle(xPix, yPix, rPix);
-}
-
-#define NMXMULTP  30   // Pour multipoint sans new
-
-void  
-PIScDrawWdg::ScDrawPolygon(double *x, double *y, int n)
-{
-int ix[NMXMULTP], iy[NMXMULTP];
-int *pxi, *pyi;
-int i;
- 
-if (n <= 0)  return;
-if (n > NMXMULTP) { pxi = new int[n];  pyi = new int[n]; }
-else { pxi = ix;  pyi = iy; }
-for(i=0; i<n; i++)  
-  Sc2Local(x[i], y[i], pxi[i], pyi[i]);
-DrawPolygon(pxi, pyi, n);
-if (n > NMXMULTP) { delete[] pxi;  delete[] pyi; }
-return;
-}
-  
-void  
-PIScDrawWdg::ScDrawFPolygon(double *x, double *y, int n)
-{
-int xi[NMXMULTP], yi[NMXMULTP];
-int *pxi, *pyi;
-int i;
- 
-if (n <= 0)  return;
-if (n > NMXMULTP) { pxi = new int[n];  pyi = new int[n]; }
-else { pxi = xi;  pyi = yi; }
-for(i=0; i<n; i++)  
-  Sc2Local(x[i], y[i], pxi[i], pyi[i]);
-DrawFPolygon(pxi, pyi, n);
-if (n > NMXMULTP) { delete[] pxi;  delete[] pyi; }
-return;
-}
-
-void  
-PIScDrawWdg::ScDrawMarker(double x0, double y0)
-{
-  int xPix, yPix;
-  Sc2Local(x0, y0, xPix, yPix);
-  DrawMarker(xPix, yPix);
-  return;
-}
-void  
-PIScDrawWdg::ScDrawMarkers(double *x, double *y, int n)
-{
-int xi[NMXMULTP], yi[NMXMULTP];
-int *pxi, *pyi;
-int i;
- 
-if (n <= 0)  return;
-if (n > NMXMULTP) { pxi = new int[n];  pyi = new int[n]; }
-else { pxi = xi;  pyi = yi; }
-for(i=0; i<n; i++)  
-  Sc2Local(x[i], y[i], pxi[i], pyi[i]);
-DrawMarkers(pxi, pyi, n);
-if (n > NMXMULTP) { delete[] pxi;  delete[] pyi; }
-return;
-}
-
-void
-PIScDrawWdg::DrawHTicks(double y, double tickUp, double tickDown, double xBeg, double xStep)
-{
-  for (double x=xBeg; x<=xMax; x += xStep)
-    ScDrawLine(x, y-tickDown, x, y+tickUp);
-}
-
-void
-PIScDrawWdg::DrawVTicks(double x, double tickLeft, double tickRight, double yBeg, double yStep)
-{
-  for (double y=yBeg; y<=yMax; y += yStep)
-    ScDrawLine(x-tickLeft, y, x+tickRight, y);
-}
-
-void
-PIScDrawWdg::DrawHLabels(double y, double xBeg, double xStep, int just)
-{
-  double xOffset = 0;
-  int kk;
-  ScSelFontSz(xMajTickLen*4);
-  for (double x=xBeg; x<=xMax; x += xStep) {
-      char label[20]; sprintf(label, "%-6g", x);
-      for(kk=0; kk<20; kk++)
-        if (label[kk] == ' ')   { label[kk] = '\0' ; break; }
-      double largeur = ScStringWidth(label);
-      if (just == 1)
-        xOffset = -largeur;
-      else if (just == 0)
-        xOffset = -largeur/2;
-      else
-        xOffset = 0;
-      if (aXdir)  xOffset = -xOffset;
-      ScDrawString(x+xOffset, y, label);
-  }
-}
-
-void
-PIScDrawWdg::DrawVLabels(double x, double yBeg, double yStep, int just)
-{
-  double xOffset = 0;
-  ScSelFontSz(xMajTickLen*4);
-  for (double y=yBeg; y<=yMax; y += yStep) {
-      char label[20]; sprintf(label, "%-6g", y);
-      double largeur = ScStringWidth(label);
-      if (just == 1)
-        xOffset = -largeur;
-      else if (just == 0)
-        xOffset = -largeur/2;
-      else
-        xOffset = 0;
-      if (aXdir)  xOffset = -xOffset;
-      ScDrawString(x+xOffset, y, label);
-  }
-}
-
-
-void
-PIScDrawWdg::DrawAxes(int flags)
-{
-  NoClip();
-  if (flags == -1)
-    flags = axesFlags;
-    
-  
-  if (flags & kStdAxes) {
-  
-    // Les axes
-    
-    ScDrawLine(xMin, 0, xMax, 0);
-    ScDrawLine(0, yMin, 0, yMax);
-  
-    // Les ticks majeurs
-  
-    if (flags & kMajTicks) {
-        DrawHTicks(0, xMajTickLen, xMajTickLen, xFirstMajTick, xMajTickStep);
-        DrawVTicks(0, yMajTickLen, yMajTickLen, yFirstMajTick, yMajTickStep);
-    }
-    
-    // Les ticks mineurs
-  
-    if (flags & kMinTicks) {
-        DrawHTicks(0, xMinTickLen, xMinTickLen, xFirstMinTick, xMinTickStep);
-        DrawVTicks(0, yMinTickLen, yMinTickLen, yFirstMinTick, yMinTickStep);
-    }
-    
-    // Les labels
-    
-    if (flags & kLabels) {
-      if (!aYdir)
-        DrawHLabels(-xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
-      else 
-        DrawHLabels(xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
-      if (!aXdir)
-        DrawVLabels(-yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
-      else 
-        DrawVLabels(yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
-    }
-    
-  }
-  
-  if (flags & kBoxAxes) {
-  
-    // La boite
-    
-    ScDrawLine(xMin, yMin, xMax, yMin);
-    ScDrawLine(xMax, yMin, xMax, yMax);
-    ScDrawLine(xMax, yMax, xMin, yMax);
-    ScDrawLine(xMin, yMax, xMin, yMin);
-
-    // Longueur des ticks
-    
-    double extXMajTickLen = flags&kExtTicks ? xMajTickLen : 0;
-    double intXMajTickLen = flags&kIntTicks ? xMajTickLen : 0;
-    double extXMinTickLen = flags&kExtTicks ? xMinTickLen : 0;
-    double intXMinTickLen = flags&kIntTicks ? xMinTickLen : 0;
-    double extYMajTickLen = flags&kExtTicks ? yMajTickLen : 0;
-    double intYMajTickLen = flags&kIntTicks ? yMajTickLen : 0;
-    double extYMinTickLen = flags&kExtTicks ? yMinTickLen : 0;
-    double intYMinTickLen = flags&kIntTicks ? yMinTickLen : 0;
-
-    // Les ticks majeurs
-  
-    if (flags & kMajTicks) {
-        DrawHTicks(yMin, intXMajTickLen, extXMajTickLen, xFirstMajTick, xMajTickStep);
-        DrawHTicks(yMax, extXMajTickLen, intXMajTickLen, xFirstMajTick, xMajTickStep);
-        DrawVTicks(xMin, extYMajTickLen, intYMajTickLen, yFirstMajTick, yMajTickStep);
-        DrawVTicks(xMax, intYMajTickLen, extYMajTickLen, yFirstMajTick, yMajTickStep);
-    }
-    
-    // Les ticks mineurs
-  
-    if (flags & kMinTicks) {
-        DrawHTicks(yMin, intXMinTickLen, extXMinTickLen, xFirstMinTick, xMinTickStep);
-        DrawHTicks(yMax, extXMinTickLen, intXMinTickLen, xFirstMinTick, xMinTickStep);
-        DrawVTicks(xMin, extYMinTickLen, intYMinTickLen, yFirstMinTick, yMinTickStep);
-        DrawVTicks(xMax, intYMinTickLen, extYMinTickLen, yFirstMinTick, yMinTickStep);
-    }
-
-
-    // Les labels
-    
-    if (flags & kLabels) {
-      if (!aYdir) {
-        DrawHLabels(yMin-xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
-        DrawHLabels(yMax+xMajTickLen*2, xFirstMajTick, xMajTickStep,0);
-      }
-      else {
-        DrawHLabels(yMin-xMajTickLen*2, xFirstMajTick, xMajTickStep,0);
-        DrawHLabels(yMax+xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
-      }
-      if (!aXdir) {
-        DrawVLabels(xMin-yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
-        DrawVLabels(xMax+yMajTickLen*2, yFirstMajTick, yMajTickStep,-1);
-      }
-      else {
-        DrawVLabels(xMin-yMajTickLen*2, yFirstMajTick, yMajTickStep,-1);
-        DrawVLabels(xMax+yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
-      }
-    }
-  }
-  Clip();
-}
-
-  
-
-void
-PIScDrawWdg::AddDrawer(PIScDrawer* d)
-{
-  mDrawers.push_back(d);
-  d->AttachTo(this);
-}
-
-void
-PIScDrawWdg::RemoveDrawer(PIScDrawer* d)
+
+void
+PIScDrawWdg::AddScDrawer(PIScDrawer* d, bool ad)
+{
+  bool pd=false;
+  if (mScDrawers.size() == 0)  pd = true;
+  mScDrawers.push_back(d);
+  d->AttachTo(this, ad, pd);
+}
+
+void
+PIScDrawWdg::RemoveScDrawer(PIScDrawer* d)
 {
   if (padsup)  return;
-  mDrawers.remove(d);
-  d->mDrawWdg = NULL;
-}
-
-void
-PIScDrawWdg::DeleteDrawers()
+  vector<PIScDrawer*>::iterator drw;
+  for(drw = mScDrawers.begin(); drw != mScDrawers.end(); drw++) 
+    if (d == (*drw)) { mScDrawers.erase(drw);  break; }
+  d->mDrawWdg = NULL;  d->mDrawer = NULL; 
+}
+
+int 
+PIScDrawWdg::NbScDrawers()
+{
+  return(mScDrawers.size());
+}
+
+PIScDrawer*
+PIScDrawWdg::ScDrawer(int i)
+{
+ if ( (i<0) || (i>mScDrawers.size()) )  return(NULL);
+ return(mScDrawers[i]);
+}
+
+
+void
+PIScDrawWdg::DeleteScDrawers()
 {
   padsup = true;
-  for(list<PIScDrawer*>::iterator i = mDrawers.begin(); i != mDrawers.end(); i++)
-    delete *i;
-  mDrawers.erase(mDrawers.begin(),mDrawers.end());
+  vector<PIScDrawer*>::iterator i;
+  for(i = mScDrawers.begin(); i != mScDrawers.end(); i++) {
+    if ( (*i)->ADelByDrwWdg() )  delete *i;
+  }
+  mScDrawers.erase(mScDrawers.begin(),mScDrawers.end());
   padsup = false;
 }
 
 void
-PIScDrawWdg::CallDrawer(PIScDrawer* d)
-{
-  d->Draw();
-}
-
-void
-PIScDrawWdg::CallDrawers()
-{
-  for_each(mDrawers.begin(), mDrawers.end(), CallDrawer);
-}
-
-void
-PIScDrawWdg::SetAxesFlags(int flags)
-{
-  axesFlags = flags;
-  if (axesFlags & (kIntTicks | kExtTicks | kMajTicks | kMinTicks))
-    axesFlags |= kTicks;
-  if ((axesFlags & (kTicks | kIntTicks | kExtTicks)) == kTicks)
-    axesFlags |= kIntTicks | kExtTicks;
-  if ((axesFlags & (kTicks | kMajTicks | kMinTicks)) == kTicks)
-    axesFlags |= kMajTicks;
-}
+PIScDrawWdg::CallScDrawers(double xmin, double ymin, double xmax, double ymax)
+{
+  vector<PIScDrawer*>::iterator drw;
+  for(drw = mScDrawers.begin(); drw != mScDrawers.end(); drw++) {
+    (*drw)->SelGraAtt();
+    (*drw)->Draw(xmin, ymin, xmax, ymax);
+  }
+}
+
 void
 PIScDrawWdg::SetTextWin(PILabel * tw, bool trw, int tx, int ty)
@@ -580,5 +150,5 @@
     mTrW = new PIWindow(this, "Point", PIWK_transient, tx, ty, 0, 0);
     mTrW->SetAutoDelChilds(true);
-    mTrlb = new PILabel(mTrW, "PixVal", tx, ty, 0, 0);
+    mTrlb = new PILabel(mTrW, "PointCoord", tx, ty, 0, 0);
     mTrlb->SetBinding(PIBK_fixed,PIBK_fixed, PIBK_fixed,PIBK_fixed);
     }
@@ -595,8 +165,34 @@
   EraseWindow();
   DrawAxes();
-  CallDrawers();
-  DrawSelf();
-}
-
+  DrawSelf(-9.e19, -9.e19, 9.e19, 9.e19);
+  CallScDrawers(-9.e19, -9.e19, 9.e19, 9.e19);
+  CallDrawers(0,0,0,0);
+}
+
+void
+PIScDrawWdg::Draw(int x0, int y0, int dx, int dy)
+{
+  double xmin,xmax,ymin,ymax;
+  mBDrw->Local2Sc(x0, y0, xmin, ymin);
+  mBDrw->Local2Sc(x0+dx, y0+dy, xmax, ymax);
+  if (xmin > xmax) swap(xmin,xmax);
+  if (ymin > ymax) swap(ymin,ymax);
+  DrawAxes();
+  DrawSelf(xmin, ymin, xmax, ymax);
+  CallScDrawers(xmin, ymin, xmax, ymax);  
+  CallDrawers(x0, y0, dx, dy);
+}
+
+void
+PIScDrawWdg::DrawSelf()
+{
+return;
+}
+
+void
+PIScDrawWdg::DrawSelf(double /*xmin*/, double /*ymin*/, double /*xmax*/, double /*ymax*/)
+{
+return;
+}
 
 
@@ -641,5 +237,5 @@
 
   double dx, dy;
-  Local2Sc(xp, yp, dx, dy); 
+  mBDrw->Local2Sc(xp, yp, dx, dy); 
   mPPos[0] = dx;  mPPos[1] = dy; 
   if ((mTxw == NULL) && (mTrlb == NULL)) return(false);
@@ -684,12 +280,12 @@
   
   if (xBegDrag == xEndDrag || yBegDrag == yEndDrag)
-    SetLimits(xMinS, xMaxS, yMinS, yMaxS, aXdir, aYdir );
+    SetLimits(xMinS, xMaxS, yMinS, yMaxS, kAxeDirSame, kAxeDirSame );
   else {
     double xl,yl,xh,yh;
-    Local2Sc(xBegDrag, yBegDrag, xl, yl);
-    Local2Sc(xEndDrag, yEndDrag, xh, yh);
+    mBDrw->Local2Sc(xBegDrag, yBegDrag, xl, yl);
+    mBDrw->Local2Sc(xEndDrag, yEndDrag, xh, yh);
     if (xl > xh) swap(xl, xh);
     if (yl > yh) swap(yl, yh);
-    SetLimits(xl,xh,yl,yh, aXdir, aYdir, true);
+    SetLimits(xl,xh,yl,yh, kAxeDirSame, kAxeDirSame, true);
   }
   
@@ -710,23 +306,139 @@
 //================================================================
 
+
+
 PIScDrawer::PIScDrawer()
-: mDrawWdg(NULL)
-{}
+: mDrawWdg(NULL), mDrawer(NULL)
+{
+  mADbW = mAdDO = mPrDw = false;
+  mFCol = mBCol = PI_NotDefColor;
+  mLAtt = PI_NotDefLineAtt;
+  mFSz = PI_NotDefFontSize;
+  mFAtt = PI_NotDefFontAtt;
+  mMSz = -1;
+  mMrk = PI_NotDefMarker;
+}
 
 PIScDrawer::~PIScDrawer()
 {
   if (mDrawWdg)
-    mDrawWdg->RemoveDrawer(this);
-}
-
-void
-PIScDrawer::AttachTo(PIScDrawWdg* wdg)
+    mDrawWdg->RemoveScDrawer(this);
+}
+
+void
+PIScDrawer::UpdateSize()
+{
+// Ne fait rien !
+  return;
+}
+
+void
+PIScDrawer::Refresh()
+{
+// Recalcule les limites, et reaffiche
+  if (!mDrawer) return;
+  mDrawWdg->FreeLimits();
+  UpdateSize();
+  if (mDrawWdg) mDrawWdg->Refresh();
+}
+
+void
+PIScDrawer::AttachTo(PIScDrawWdg* wdg, bool ad, bool prd)
 {
   if (mDrawWdg)
-    mDrawWdg->RemoveDrawer(this);
-  mDrawWdg = wdg;
-}
-
-
+    mDrawWdg->RemoveScDrawer(this);
+  mDrawWdg = wdg;  
+  mDrawer = wdg->BaseDrawer();
+  UpdateSize();
+  mADbW = ad;
+  mPrDw = prd;
+}
+
+// Classe PIDrawer special pour enrober un PIScDrawer en PIDrawer
+class PIScContDrw : public PIDrawer {
+public :
+                     PIScContDrw(PIScDrawer* d, bool ad=false);
+  virtual            ~PIScContDrw();
+  virtual  void      Draw();
+  virtual  void      Draw(double xmin, double ymin, double xmax, double ymax);
+private:
+  PIScDrawer* mScDrw;
+  bool mAD;
+};
+
+PIScContDrw::PIScContDrw(PIScDrawer* d, bool ad)  
+{ 
+  mScDrw = d; 
+  mAD=ad; 
+}
+
+PIScContDrw::~PIScContDrw() 
+{ 
+  if (mAD)  delete mScDrw; 
+}
+
+void PIScContDrw::Draw() 
+{ 
+  mScDrw->SelGraAtt(); 
+  mScDrw->Draw(-9.e19, -9.e19, 9.e19, 9.e19); 
+}
+
+void PIScContDrw::Draw(double xmin, double ymin, double xmax, double ymax)
+{ 
+  mScDrw->SelGraAtt(); 
+  mScDrw->Draw(xmin, ymin, xmax, ymax); 
+}
+
+PIDrawer*
+PIScDrawer::Convert()
+{
+  PIScContDrw* rd;
+  if (mDrawWdg) mDrawWdg->RemoveScDrawer(this);
+  mDrawWdg = NULL; 
+  rd = new PIScContDrw(this);
+  mDrawer = rd;
+  UpdateSize();
+  return((PIDrawer*)rd);
+}
+
+void 
+PIScDrawer::SetColAtt(PIColors fg, PIColors bg)
+{
+  if (fg != PI_NotDefColor) mFCol = fg;
+  if (bg != PI_NotDefColor) mBCol = bg;
+}
+
+void 
+PIScDrawer::SetLineAtt(PILineAtt lat)
+{
+  if (lat != PI_NotDefLineAtt) mLAtt = lat;
+}
+
+void 
+PIScDrawer::SetFontAtt(PIFontSize fsz, PIFontAtt fat)
+{
+  if (fsz != PI_NotDefFontSize) mFSz = fsz;
+  if (fat != PI_NotDefFontAtt) mFAtt = fat;
+}
+
+void 
+PIScDrawer::SetMarkerAtt(int sz, PIMarker mrk)
+{
+  if (sz >= 0)  mMSz = sz;
+  if (mrk != PI_NotDefMarker) mMrk = mrk;
+}
+
+void 
+PIScDrawer::SelGraAtt()
+{
+  if (mDrawer == NULL)   return;
+  if (mFCol != PI_NotDefColor)    mDrawer->SelForeground(mFCol);
+  if (mBCol != PI_NotDefColor)    mDrawer->SelBackground(mBCol);
+  if (mLAtt != PI_NotDefLineAtt)  mDrawer->SelLine(mLAtt);
+  if ( (mFSz != PI_NotDefFontSize) || (mFAtt != PI_NotDefFontAtt) )
+                                  mDrawer->SelFont(mFSz, mFAtt);
+  if ( (mMrk != PI_NotDefMarker) || (mMSz >= 0) )
+                                  mDrawer->SelMarker(mMSz, mMrk);
+}
 
 //================================================================
@@ -743,11 +455,11 @@
 
 void
-PIScFuncDrawer::Draw()
-{
-  if (!mDrawWdg) return;
-  double xMax = mDrawWdg->XMax();
-  double xMin = mDrawWdg->XMin();
-  double yMax = mDrawWdg->YMax();
-  double yMin = mDrawWdg->YMin();
+PIScFuncDrawer::Draw(double /*xmin*/, double/*ymin*/, double/*xmax*/, double/*ymax*/)
+{
+  if (!mDrawer) return;
+  double xMax = mDrawer->XMax();
+  double xMin = mDrawer->XMin();
+  double yMax = mDrawer->YMax();
+  double yMin = mDrawer->YMin();
   double xStep = (xMax - xMin)/100;
   double xOld = xMin;
@@ -757,5 +469,5 @@
     if (y>yMin && yOld>yMin && 
         y<yMax && yOld<yMax) 
-           mDrawWdg->ScDrawLine(xOld, yOld, x, y);
+           mDrawer->DrawLine(xOld, yOld, x, y);
     xOld = x;
     yOld = y;
@@ -787,11 +499,11 @@
 
 void
-PIScGFFDrawer::Draw()
-{
-  if (!mDrawWdg) return;
-  double xMax = mDrawWdg->XMax();
-  double xMin = mDrawWdg->XMin();
-  double yMax = mDrawWdg->YMax();
-  double yMin = mDrawWdg->YMin();
+PIScGFFDrawer::Draw(double /*xmin*/, double/*ymin*/, double/*xmax*/, double/*ymax*/)
+{
+  if (!mDrawer) return;
+  double xMax = mDrawer->XMax();
+  double xMin = mDrawer->XMin();
+  double yMax = mDrawer->YMax();
+  double yMin = mDrawer->YMin();
   double xStep = (xMax - xMin)/100;
   double xOld = xMin;
@@ -803,5 +515,5 @@
     if (y>yMin && yOld>yMin && 
         y<yMax && yOld<yMax) 
-           mDrawWdg->ScDrawLine(xOld, yOld, x, y);
+           mDrawer->DrawLine(xOld, yOld, x, y);
     xOld = x;
     yOld = y;
Index: /trunk/SophyaPI/PI/piscdrawwdg.h
===================================================================
--- /trunk/SophyaPI/PI/piscdrawwdg.h	(revision 51)
+++ /trunk/SophyaPI/PI/piscdrawwdg.h	(revision 52)
@@ -2,4 +2,5 @@
 #define PISCDRAWWDG_H
 
+#include <vector>
 
 #include "pisysdep.h"
@@ -7,19 +8,9 @@
 #include PISTDWDG_H
 #include PIWIN_H
+#include "pidrawer.h"
 
-#include <list>
 
-  enum {
-    kStdAxes     = 0x0001,
-    kBoxAxes     = 0x0002,
-    kTicks       = 0x0004,
-    kIntTicks    = 0x0010,
-    kExtTicks    = 0x0020,
-    kMajTicks    = 0x0040,
-    kMinTicks    = 0x0080,
-    kLabels      = 0x1000,
-    kAxesDflt    = kStdAxes | kTicks | kLabels
-  };
 
+class PIScDrawer;
 
 class PIScDrawWdg : public PIBaseWdg {
@@ -29,58 +20,37 @@
   virtual           ~PIScDrawWdg();
 
-  virtual void       SetLimits(double xmin, double xmax, double ymin, double ymax, 
-                               bool axrl=false, bool ayud=false, bool tmp=false);
-  
-  virtual void       ScDrawString(double x, double y, char* s, int pos = 0);
-  virtual void       ScDrawLine(double x1, double y1, double x2, double y2);
-  virtual void       ScDrawBox(double x0, double y0, double dx, double dy);
-  virtual void       ScDrawFBox(double x0, double y0, double dx, double dy);
-  virtual void       ScDrawCircle(double x0, double y0, double r);
-  virtual void       ScDrawFCircle(double x0, double y0, double r);
-  virtual void       ScDrawPolygon(double *x, double *y, int n);  
-  virtual void       ScDrawFPolygon(double *x, double *y, int n);
-  virtual void       ScDrawMarker(double x0, double y0);
-  virtual void       ScDrawMarkers(double *x0, double *y0, int n);
-
-  virtual double     ScStringWidth(char const*);
-
-  virtual void       ScSelFontSz(double size, PIFontAtt att=PI_RomanFont); 
-  virtual void       ScSelMarker(double size=0, PIMarker mrk=PI_DotMarker); 
-
-  virtual void       DrawAxes(int flags = -1);
-  virtual void       DrawSelf() {}
-  
   virtual void       Resize();
   
-  virtual void       CalcTicks();
-  virtual void       CalcScale();
+  virtual void       Draw();
+  virtual void       Draw(int x0, int y0, int dx, int dy);
+  virtual void       DrawSelf();
+  virtual void       DrawSelf(double xmin, double ymin, double xmax, double ymax);
   
-  virtual void       Sc2Local(double x, double y, int& xpix, int& ypix);
-  virtual void       Local2Sc(int xpix, int ypix, double& x, double& y);
-  virtual void       DSc2Local(double dx, double dy, int& dxpix, int& dypix);
-  
-  virtual void       Draw();
-  
-  friend class PIScDrawer;
-  virtual void       AddDrawer(PIScDrawer*);   // Ajoute un drawer
-  virtual void       RemoveDrawer(PIScDrawer*);  // Ote un drawer sans le detruire
-  virtual void       DeleteDrawers();            // Ote et detruit tous les drawers
-  static  void       CallDrawer(PIScDrawer*);
-  virtual void       CallDrawers();
-  virtual void       SetAxesFlags(int flags=kAxesDflt);
-  
-  void               SetTextWin(PILabel * tw, bool trw=true, int tx=200, int ty=30);
+  void               SetLimits(double xmin, double xmax, double ymin, double ymax, 
+                               int axrl=kAxeDirSame, int ayud=kAxeDirSame, bool tmp=false);
 
-  double XMin() const {return xMin;}
-  double XMax() const {return xMax;}
-  double YMin() const {return yMin;}
-  double YMax() const {return yMax;}
+  void               SetAxesFlags(int flags=kAxesDflt);
+  void               DrawAxes(int flags = -1);
+
+  void               AddScDrawer(PIScDrawer*, bool ad=false);   // Ajoute un ScDrawer
+  void               RemoveScDrawer(PIScDrawer*);  // Ote un ScDrawer sans le detruire
+  int                NbScDrawers();
+  PIScDrawer*        ScDrawer(int i);          
+
+  PIDrawer*          BaseDrawer() { return mBDrw; };
+
+  double XMin() const {return mBDrw->XMin();}
+  double XMax() const {return mBDrw->XMax();}
+  double YMin() const {return mBDrw->YMin();}
+  double YMax() const {return mBDrw->YMax();}
   double XPPos() const { return mPPos[0]; }
   double YPPos() const { return mPPos[1]; }
-  int    LimitsFixed() const {return limitsFixed;}
-  void   FreeLimits() {limitsFixed = 0;}
-  void   NoClip() {clip = false;}
-  void   Clip() {clip = true;}
+  int    LimitsFixed() const {return mBDrw->LimitsFixed();}
+  void   FreeLimits() { mBDrw->FreeLimits(); }
+  void   NoClip() { mBDrw->NoClip(); }
+  void   Clip() { mBDrw->NoClip(); }
     
+
+  void               SetTextWin(PILabel * tw, bool trw=true, int tx=200, int ty=30);
 
   virtual void       But1Press(int x, int y);
@@ -93,20 +63,14 @@
   
 protected:
-  double xMin, xMax, yMin, yMax; // Valeurs en unites user
+          void       DeleteScDrawers();    // Ote et detruit tous les ScDrawers
+          void       CallScDrawers(double xmin, double ymin, double xmax, double ymax);
+          void       SetSpan();
+
   double xMinS, xMaxS, yMinS, yMaxS; // Sauvegarde pour zoom
-  double xOrg, yOrg;             // Position en pixels de (0.0, 0.0)
-  double xScale, yScale;         // Pixels par unites graphiques
-  bool   aXdir, aYdir;           // Sens des axes horiz, vertical 
   double mPPos[2];               // Position click souris X,Y
-  double xFirstMajTick, xFirstMinTick;
-  double yFirstMajTick, yFirstMinTick;
-  double xMajTickStep, xMinTickStep;
-  double yMajTickStep, yMinTickStep;
-  double xMajTickLen,  xMinTickLen;
-  double yMajTickLen,  yMinTickLen;
-  
-  int limitsFixed;
-  int axesFlags;
-  list<PIScDrawer*>   mDrawers;
+
+  PIDrawer* mBDrw;
+  vector<PIScDrawer*>   mScDrawers;
+  bool padsup;
   
   int xBegDrag, yBegDrag;
@@ -119,16 +83,10 @@
   PILabel * mTrlb;
   PIWindow * mTrW;
-  bool clip;
-  bool padsup;
 
 
 private:
-  void DrawHTicks(double y, double tickUp, double tickDown, double xBeg, double xStep);
-  void DrawVTicks(double x, double tickLeft, double tickRight, double yBeg, double yStep);
-  void DrawHLabels(double y, double xBeg, double xStep, int just=0);
-  void DrawVLabels(double x, double yBeg, double yStep, int just=0);
-  
   bool  UpdateText(int xp, int yp);
 };
+
 
 class PIScDrawer {
@@ -137,9 +95,36 @@
   virtual           ~PIScDrawer();
 
-  virtual void       Draw() = 0;
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax) = 0; 
+  virtual void       UpdateSize();   // Calcule et change les limites si non fixees 
+  virtual void       Refresh();      // Recalcule les limites et reaffiche
+
+  PIDrawer*          Convert();
+
+  void               SetColAtt(PIColors fg=PI_NotDefColor, 
+                                PIColors bg=PI_NotDefColor);
+  void               SetLineAtt(PILineAtt lat=PI_NotDefLineAtt);
+  void               SetFontAtt(PIFontSize fsz=PI_NotDefFontSize,
+                                PIFontAtt fat=PI_NotDefFontAtt);
+  void               SetMarkerAtt(int sz=-1, PIMarker mrk=PI_NotDefMarker);
+
+  void               SelGraAtt();
+
+  inline void        SetAutoDelDataObj(bool ad=false) { mAdDO = ad; }
+  inline bool        ADelByDrwWdg() { return mADbW; }
+  inline bool        MainScDrawer() { return mPrDw; }
+
 protected:
   friend class       PIScDrawWdg;
-  virtual void       AttachTo(PIScDrawWdg*);
+  virtual void       AttachTo(PIScDrawWdg*, bool, bool);
+
   PIScDrawWdg*       mDrawWdg;
+  PIDrawer*          mDrawer;
+  bool               mADbW, mAdDO, mPrDw;
+  PIColors           mFCol, mBCol;
+  PILineAtt          mLAtt;
+  PIFontSize         mFSz;
+  PIFontAtt          mFAtt;
+  int                mMSz;
+  PIMarker           mMrk;     
 };
 
@@ -150,5 +135,5 @@
   virtual           ~PIScFuncDrawer();
   
-  virtual void       Draw();
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax);
 protected:
   FUNC               mFunc;
@@ -161,5 +146,5 @@
   virtual           ~PIScGFFDrawer();
   
-  virtual void       Draw();
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax);
   virtual void       SetParms(double const*);
 protected:
Index: /trunk/SophyaPI/PI/pistlist.cc
===================================================================
--- /trunk/SophyaPI/PI/pistlist.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pistlist.cc	(revision 52)
@@ -4,8 +4,8 @@
  
 /* --Methode-- */
-PIStarList::PIStarList(StarList* stl, bool ayud)
+PIStarList::PIStarList(StarList* stl, bool ad, int ayud)
 : PIScDrawer(), mStL(stl)
 {
-  mAdelStl = false;   
+  mAdDO = ad;   
   mAYdir = ayud;  
   if (stl == NULL) return;
@@ -16,6 +16,5 @@
 PIStarList::~PIStarList()
 {
-  if (mAdelStl && mStL)
-    delete mStL;
+  if (mAdDO && mStL)  delete mStL;
 }
 
@@ -57,11 +56,4 @@
 }  
 
-/* --Methode-- */
-void  PIStarList::AttachTo(PIScDrawWdg* wdg)
-{
-  PIScDrawer::AttachTo(wdg);
-  UpdateSize();
-}
-
 
 /* --Methode-- */
@@ -69,6 +61,6 @@
 {
   if (!mStL) return;
-  if (!mDrawWdg) return;
-  if (mDrawWdg->LimitsFixed()) return;
+  if (!mDrawer) return;
+  if (mDrawer->LimitsFixed()) return;
 
   // Commencer par trouver nos limites
@@ -78,11 +70,15 @@
   dy = 0.02*(mYMax-mYMin);
   
-  mDrawWdg->SetLimits(mXMin-dx, mXMax+dx, mYMin-dy, mYMax+dy, false, mAYdir); 
-  mDrawWdg->SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
+  if (mDrawWdg) 
+    mDrawWdg->SetLimits(mXMin-dx, mXMax+dx, mYMin-dy, mYMax+dy, kAxeDirLtoR, mAYdir); 
+  else 
+    mDrawer->SetLimits(mXMin-dx, mXMax+dx, mYMin-dy, mYMax+dy, false, mAYdir); 
+
+  mDrawer->SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
 }
 
 
 /* --Methode-- */
-void PIStarList::Draw()
+void PIStarList::Draw(double xmin, double ymin, double xmax, double ymax)
 {
 BStar *sti;
@@ -93,7 +89,7 @@
 
 if (!mStL) return;
-if (!mDrawWdg) return;
+if (!mDrawer) return;
 
-mDrawWdg->SelFont();
+mDrawer->SelFont();
 nok = 0;  nl2 = mNLev*2-1;
 for (int i=0; i<mStL->NbStars(); i++) {
@@ -104,15 +100,19 @@
   xp = sti->PosX();   yp = sti->PosY();
   if ( (xp < mXMin) || (xp > mXMax) || (yp < mYMin) || (yp > mYMax) )  continue;
+  if ( (xp < xmin) || (xp > xmax) || (yp < ymin) || (yp > ymax) )  continue;
   nok++;
   sz = (int)((log10((double)flx/mF0))/mDLgF*(double)nl2-0.01) + mMSz0;
-  if (sz < 2)  mDrawWdg->SelMarker(sz, PI_DotMarker);
-  else mDrawWdg->SelMarker(sz, PI_FCircleMarker);
-  mDrawWdg->ScDrawMarker((double)xp,(double)yp ); 
+  if (sz < 2)  mDrawer->SelMarker(sz, PI_DotMarker);
+  else mDrawer->SelMarker(sz, PI_FCircleMarker);
+  mDrawer->DrawMarker((double)xp,(double)yp ); 
   if (mDspFV) {  
     sprintf(buff," F=%g", flx);
-    mDrawWdg->Sc2Local(xp, yp, ixp, iyp);
-    mDrawWdg->DrawString( ixp+sz/2+1, iyp-4, buff);
+    mDrawer->Sc2Local(xp, yp, ixp, iyp);
+    mDrawer->DrawString( ixp+sz/2+1, iyp-4, buff);
     } 
   }
+
+if (!MainScDrawer()) return;
+if (!mDrawWdg)  return;
 
 sprintf(buff, "StarList:  NbStars= %d  NDisp= %d", (int)mStL->NbStars(), nok);
@@ -123,11 +123,2 @@
 }
 
-
-/* --Methode-- */
-void PIStarList::Refresh()
-{
-  if (!mDrawWdg) return;
-  mDrawWdg->FreeLimits();
-  UpdateSize();
-  mDrawWdg->Refresh();
-}
Index: /trunk/SophyaPI/PI/pistlist.h
===================================================================
--- /trunk/SophyaPI/PI/pistlist.h	(revision 51)
+++ /trunk/SophyaPI/PI/pistlist.h	(revision 52)
@@ -2,17 +2,15 @@
 #define PISTLIST_H
 
-
+#include "stlist.h"
 #include "piscdrawwdg.h"
-#include "stlist.h"
 
 class PIStarList : public PIScDrawer {
 public:
-                     PIStarList(StarList* stl, bool ayud=true);
+                     PIStarList(StarList* stl, bool ad, int ayud=kAxeDirUpDown);
   virtual           ~PIStarList();
   
-  virtual void       Draw();
-  virtual void       Refresh();  // Recalcule les limites, et reaffiche
+  virtual void       Draw(double xmin, double ymin, double xmax, double ymax);
+  virtual void       UpdateSize();
   
-  inline  void       SetAutoDelStList(bool ad=false)   { mAdelStl = ad; }
   void               SetFluxLimits(float min=1., float max=-1., int nl=5, 
                                    int msz0=0, bool refr=false);
@@ -30,5 +28,4 @@
 protected:
   StarList* mStL;
-  bool   mAdelStl;
   float mFmin, mFmax;
   int mNLev, mMSz0;
@@ -37,8 +34,6 @@
   float mYMin, mYMax;
   bool mDspFV;
-  bool mAYdir;
+  int  mAYdir;
 
-  virtual void       AttachTo(PIScDrawWdg*);
-  virtual void       UpdateSize();
 };
 
Index: /trunk/SophyaPI/PI/piwdggen.h
===================================================================
--- /trunk/SophyaPI/PI/piwdggen.h	(revision 51)
+++ /trunk/SophyaPI/PI/piwdggen.h	(revision 52)
@@ -60,4 +60,8 @@
   virtual void           GetScreenPos(int & spx, int & spy);
 
+  virtual void           Manage()=0;
+  virtual void           UnManage()=0;
+  virtual int            IfManaged()=0;
+
   virtual void           PSPrint(PSFile *psf, int ofx=0, int ofy=0);
 
Index: /trunk/SophyaPI/PI/piwdgx.cc
===================================================================
--- /trunk/SophyaPI/PI/piwdgx.cc	(revision 51)
+++ /trunk/SophyaPI/PI/piwdgx.cc	(revision 52)
@@ -11,5 +11,4 @@
 #include <Xm/Xm.h>       // A cause des container XmForm 
 #include <Xm/Form.h>     // Idem 
-
 
 #include "piwdgx.h"
@@ -188,8 +187,8 @@
 
 /* --Methode-- */
-void PIWdgX::Unmanage()
-{
-#ifdef DEBUG_PIWdgX
-printf("Debug_PIWdgX::Unmanage  this=%lx sdw=%lx \n", (long)this, (long)sdw);
+void PIWdgX::UnManage()
+{
+#ifdef DEBUG_PIWdgX
+printf("Debug_PIWdgX::UnManage  this=%lx sdw=%lx \n", (long)this, (long)sdw);
 #endif
 if (!sdw)  return;
Index: /trunk/SophyaPI/PI/piwdgx.h
===================================================================
--- /trunk/SophyaPI/PI/piwdgx.h	(revision 51)
+++ /trunk/SophyaPI/PI/piwdgx.h	(revision 52)
@@ -5,10 +5,7 @@
 #define PIWDG_X_SEEN
 
-#include <string>
-
 #include <X11/Xlib.h>
 #include <X11/Intrinsic.h>
 
-#include "piwdggen.h"
 #include "piwdggen.h"
 
@@ -53,7 +50,7 @@
   virtual void   GetScreenPos(int & spx, int & spy);
 
-  void Manage();
-  void Unmanage();
-  int  IfManaged();
+  virtual void   Manage();
+  virtual void   UnManage();
+  virtual int    IfManaged();
 
   inline SysDWdg XtWdg() const {return(sdw); }; 
@@ -77,4 +74,6 @@
 Display * PIXDisplay();
 #define  PIXScreen()  DefaultScreen(PIXDisplay()) 
+Time PIXGetLastEventTime();
+unsigned long PIXGetLastEventSerial();
 
 #endif/* PIWDGX_SEEN */
Index: /trunk/SophyaPI/PI/piwindowx.cc
===================================================================
--- /trunk/SophyaPI/PI/piwindowx.cc	(revision 51)
+++ /trunk/SophyaPI/PI/piwindowx.cc	(revision 52)
@@ -130,5 +130,5 @@
 
 PIContainerGen::Show();
-Manage();
+// Manage();  $CHECK$ Ca ne doit plus etre necessaire Reza 9/7/97
 if (!XtIsRealized(pwm->XtWdg()))  fgr = 1;
 pwm->Manage();
@@ -143,4 +143,7 @@
   else 
     XSetTransientForHint(mdsp, XtWindow(PIXtTopWdg()), XtWindow(pwm->XtWdg()));
+  //  Pour faire les actions sur les fenetres X, sinon fenetre pas cree 
+  int k;
+  for(k=0; k<mNCh; k++)  mChilds[k]->FinishCreate();
   }
 
@@ -156,6 +159,6 @@
 {
 PIWindowGen::Hide();
-Unmanage();
-pwm->Unmanage();
+// UnManage();  $CHECK$ Ca ne doit plus etre necessaire Reza 9/7/97
+pwm->UnManage();
 }
 
Index: /trunk/SophyaPI/PI/pixtbase.cc
===================================================================
--- /trunk/SophyaPI/PI/pixtbase.cc	(revision 51)
+++ /trunk/SophyaPI/PI/pixtbase.cc	(revision 52)
@@ -110,4 +110,10 @@
 
 
+static Time last_time_xevt = 0;
+static unsigned long last_serial_xevt = 0;
+
+Time PIXGetLastEventTime() { return(last_time_xevt); }
+unsigned long PIXGetLastEventSerial() { return(last_serial_xevt); }
+
 /* Nouvelle-Fonction */
 static void init_class_pixtbase()
@@ -174,7 +180,9 @@
 
 /* Nouvelle-Fonction */
-static void enter_pixtbase (Widget wdgp, XEvent* /*evt*/, 
+static void enter_pixtbase (Widget wdgp, XEvent* evt, 
                             String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xcrossing.time;
+last_serial_xevt = evt->xcrossing.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
    (((PIXtBaseWidget)wdgp)->pixtbase.objet)->Enter();
@@ -183,7 +191,9 @@
 
 /* Nouvelle-Fonction */
-static void leave_pixtbase (Widget wdgp, XEvent* /*evt*/, 
+static void leave_pixtbase (Widget wdgp, XEvent* evt, 
                             String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xcrossing.time;
+last_serial_xevt = evt->xcrossing.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
    (((PIXtBaseWidget)wdgp)->pixtbase.objet)->Leave();
@@ -196,4 +206,6 @@
 
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
   {
@@ -211,4 +223,6 @@
 
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
   {
@@ -225,4 +239,6 @@
 
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
   {
@@ -239,4 +255,6 @@
                            String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet)
   { 
@@ -255,4 +273,6 @@
 
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
   {
@@ -270,4 +290,6 @@
 
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet) 
   {
@@ -284,4 +306,6 @@
                            String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet)  
   {
@@ -298,4 +322,6 @@
                            String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet)  
   {
@@ -312,4 +338,6 @@
                            String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xbutton.time;
+last_serial_xevt = evt->xbutton.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet)  
   {
@@ -326,4 +354,6 @@
                            String* /*args*/, Cardinal* /*narg*/)
 {
+last_time_xevt = evt->xkey.time;
+last_serial_xevt = evt->xkey.serial;
 if (((PIXtBaseWidget)wdgp)->pixtbase.objet)  
   {
Index: /trunk/SophyaPI/PI/sc_sample.cc
===================================================================
--- /trunk/SophyaPI/PI/sc_sample.cc	(revision 51)
+++ /trunk/SophyaPI/PI/sc_sample.cc	(revision 52)
@@ -29,17 +29,17 @@
 int i;
 SelForeground(PI_Green);
-ScSelMarker(0.3, PI_BoxMarker);
-ScDrawMarkers(x, y, 5);
+BaseDrawer()->SelMarker(0.3, PI_BoxMarker);
+BaseDrawer()->DrawMarkers(x, y, 5);
 SelForeground(PI_Magenta);
-ScSelMarker(0.3, PI_FCircleMarker);
+BaseDrawer()->SelMarker(0.3, PI_FCircleMarker);
 for(i=0; i<5; i++)
    y[i]+=1.;
-ScDrawMarkers(x, y, 5);
+BaseDrawer()->DrawMarkers(x, y, 5);
 SelForeground(PI_Black);
 
-ScDrawLine(-4, -4, 4, 4);
-ScDrawLine(-2, -5, 5, 2);
-ScDrawLine(-5, -4, -2, -2);
-ScDrawLine(1, -10, 1, 10);
+BaseDrawer()->DrawLine(-4, -4, 4, 4);
+BaseDrawer()->DrawLine(-2, -5, 5, 2);
+BaseDrawer()->DrawLine(-5, -4, -2, -2);
+BaseDrawer()->DrawLine(1, -10, 1, 10);
 return;  
 }
