Index: /trunk/SophyaPI/PI/pibwdggen.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdggen.cc	(revision 2528)
+++ /trunk/SophyaPI/PI/pibwdggen.cc	(revision 2529)
@@ -531,5 +531,5 @@
 vector<BWDrwId>::iterator it;
 for(it = mDrwList.begin(); it != mDrwList.end(); it++)  
-  if ((*it).id == id)  return(! (*it).autoszp );
+  if ((*it).id == id)  return( (*it).autoszp );
 return false;
 }
Index: /trunk/SophyaPI/PI/pidrwtools.cc
===================================================================
--- /trunk/SophyaPI/PI/pidrwtools.cc	(revision 2528)
+++ /trunk/SophyaPI/PI/pidrwtools.cc	(revision 2529)
@@ -885,9 +885,19 @@
 class PIDrwPosSizeEvH : public PIEventHandler {
 public: 
-  PIDrwPosSizeEvH(PIBaseWdg* bwdg);
+  PIDrwPosSizeEvH(PIBaseWdg* bwdg, bool fgxor=true);
+          void    CheckBeforeDelete();
   virtual void    ProcessEvent(); 
+
 protected:
+  void ComputeResizeZone();
+  void ComputeMoveZone();
+  inline void ComputeDrawerZone() 
+    { x1 = _x1;  y1 = _y1; x2 = _x2-_x1;  y2 = _y2-_y1; }
+
+
   PIBaseWdg* mBWdg;
+  bool _fgxor;
   int _x1, _y1, _x2, _y2;
+  PIGrCoord x1, y1, x2, y2;
   bool _elastic;
   int _ipx, _ipy;
@@ -896,10 +906,12 @@
   bool _rsz; // true -> resize option
   bool _okend;
+  bool _rmok;
 };
 
 /* --Methode-- */
-PIDrwPosSizeEvH::PIDrwPosSizeEvH(PIBaseWdg* bwdg)
+PIDrwPosSizeEvH::PIDrwPosSizeEvH(PIBaseWdg* bwdg, bool fgxor)
 {
   mBWdg = bwdg;
+  _fgxor = fgxor;
   _x1 = _y1 = _x2 = _y2 = -1;
   _ipx = _ipy = -1;
@@ -908,8 +920,8 @@
   _rsz = false;
   _okend = false;
+  _rmok = false;
   if (bwdg == NULL) return;
   int aid = bwdg->GetActiveDrawerId();
   if (aid < 0) return;
-  PIGrCoord x1, y1, x2, y2;
   
   _elastic = false;
@@ -933,6 +945,4 @@
     _y1 = y1; _y2 = y2;
   }
-  _x2 -= _x1;  _y2 -= _y1;
-  cout << "DBG: x1=" << _x1 << " y1=" << _y1 << " x2=" << _x2 << " y2=" << _y2 << endl;
 
   PIGraphic* gr = mBWdg->WindowGraphic();
@@ -941,15 +951,18 @@
   PILineAtt gline = gr->GetLineAtt();
   PIColors gcol = gr->GetForeground();
-  gr->SelForeground(PI_Magenta);
-  gr->SelGOMode(PI_GOXOR);
+  if (_fgxor) {
+    gr->SelForeground(PI_Magenta);
+    gr->SelGOMode(PI_GOXOR);
+  }
+  else {
+    gr->SelForeground(PI_HighlightBlue);
+    gr->SelGOMode(PI_GOCopy);
+  }
   gr->SelLine(PI_ThinLine);
+  ComputeDrawerZone();
   gr->DrawBox(x1,y1, x2, y2);
-  x1 = _x1+0.9*(_x2-_x1);
-  y1 = _y1+0.9*(_y2-_y1);
+  ComputeResizeZone();
   gr->DrawFBox(x1,y1, x2, y2);
-  x1 = _x1+0.4*(_x2-_x1);
-  x2 = _x2-0.4*(_x2-_x1);
-  y1 = _y1+0.4*(_y2-_y1);
-  y2 = _y2-0.4*(_y2-_y1);
+  ComputeMoveZone();
   gr->DrawBox(x1,y1, x2, y2);
   gr->SelGOMode(gmod);
@@ -957,7 +970,47 @@
   gr->SelForeground(gcol);
 
-  cout << "DBG- Adding Event-Handler " << endl;
+//  cout << "DBG- Adding Event-Handler " << endl;
   mBWdg->AddEventHandler(this, PIEvent_But1Press|PIEvent_Ptr1Move|PIEvent_But1Release);
 }
+/* --Methode-- */
+void PIDrwPosSizeEvH::CheckBeforeDelete()
+{
+  if (!_rmok) 
+    mBWdg->RemoveEventHandler(this);	
+  _rmok = true; 
+}
+
+/* --Methode-- */
+void PIDrwPosSizeEvH::ComputeResizeZone()
+{
+  int dx = (int)(0.05*(_x2-_x1));
+  int dy = (int)(0.05*(_y2-_y1));
+  int maxdx = (int)(0.20*(_x2-_x1));
+  int maxdy = (int)(0.20*(_y2-_y1));
+  if (dx < 20)  dx = 20;
+  if (dx > maxdx) dx = maxdx;
+  if (dy < 20)  dx = 20;
+  if (dy > maxdy) dy = maxdy;
+  int dxy = (dx < dy) ? dx : dy ;
+  x1 = _x2-dxy;  y1 = _y2-dxy;
+  x2 = y2 = dxy;
+}
+
+/* --Methode-- */
+void PIDrwPosSizeEvH::ComputeMoveZone()
+{
+  int dx = (int)(0.08*(_x2-_x1));
+  int dy = (int)(0.08*(_y2-_y1));
+  int maxdx = (int)(0.20*(_x2-_x1));
+  int maxdy = (int)(0.20*(_y2-_y1));
+  if (dx < 20)  dx = 20;
+  if (dx > maxdx) dx = maxdx;
+  if (dy < 20)  dx = 20;
+  if (dy > maxdy) dy = maxdy;
+  int dxy = (dx < dy) ? dx : dy ;
+  x1 = (_x1+_x2)*0.5-dxy;  
+  y1 = (_y1+_y2)*0.5-dxy;    
+  x2 = y2 = 2*dxy;
+}
 
 /* --Methode-- */
@@ -965,5 +1018,5 @@
 {
   int delx, dely;
-  PIGrCoord x1,y1,x2,y2;
+  int ix1,iy1,ix2,iy2;
   x1 = _x1; x2 = _x2;
   y1 = _y1; y2 = _y2;
@@ -977,22 +1030,19 @@
   PIColors gcol = gr->GetForeground();
 
-  cout << " DBG - PIDrwPosSizeEvH::ProcessEvent() EventType=" << EventType() << endl;
   switch (EventType()) {
     case PIEvent_But1Press :
       // Zone de changement de taille 
-      x1 = _x1+0.9*(_x2-_x1);
-      y1 = _y1+0.9*(_y2-_y1);
-      if ( (GetPosX() >= (int)x1) && (GetPosX() <= (int)x2) && 
-	   (GetPosY() >= (int)y1) && ((GetPosY() <= (int)y2) ) ) 
+      ComputeResizeZone();
+      ix1 = x1;  iy1 = y1;
+      ix2 = _x2;  iy2 = _y2;
+      if ( (GetPosX() >= ix1) && (GetPosX() <= ix2) && 
+	   (GetPosY() >= iy1) && ((GetPosY() <= iy2) ) ) 
 	{ fgok = true; _rsz = true; }		 
-      x1 = _x1+0.4*(_x2-_x1);
-      x2 = _x2-0.4*(_x2-_x1);
-      y1 = _y1+0.4*(_y2-_y1);
-      y2 = _y2-0.4*(_y2-_y1);
-      if ( (GetPosX() >= (int)x1) && (GetPosX() <= (int)x2) && 
-	   (GetPosY() >= (int)y1) && ((GetPosY() <= (int)y2) ) ) 
+      ComputeMoveZone();
+      ix1 = x1;  iy1 = y1;
+      ix2 = (int)x2+ix1;  iy2 = (int)y2+iy1;
+      if ( (GetPosX() >= ix1) && (GetPosX() <= ix2) && 
+	   (GetPosY() >= iy1) && ((GetPosY() <= iy2) ) ) 
 	{ fgok = true; _rsz = false; }
-      cout << " DBG-GetPosX()= " << GetPosX() << " GetPosY()= " << GetPosY() << endl;
-      if (GetPosX() < 5) fgok = false;
       if (!fgok) _okend = true;
       else { 
@@ -1010,16 +1060,19 @@
       _cpy = GetPosY(); 
       
-      gr->SelForeground(PI_Magenta);
-      gr->SelGOMode(PI_GOXOR);
+      if (_fgxor) {
+        gr->SelForeground(PI_Magenta);
+        gr->SelGOMode(PI_GOXOR);
+      }
+      else {
+        gr->SelForeground(mBWdg->GetBackgroundColor());
+        gr->SelGOMode(PI_GOCopy);
+      }
       gr->SelLine(PI_ThinLine);
 
+      ComputeDrawerZone();
       gr->DrawBox(x1,y1, x2, y2);
-      x1 = _x1+0.9*(_x2-_x1);
-      y1 = _y1+0.9*(_y2-_y1);
+      ComputeResizeZone();
       gr->DrawFBox(x1,y1, x2, y2);
-      x1 = _x1+0.4*(_x2-_x1);
-      x2 = _x2-0.4*(_x2-_x1);
-      y1 = _y1+0.4*(_y2-_y1);
-      y2 = _y2-0.4*(_y2-_y1);
+      ComputeMoveZone();
       gr->DrawBox(x1,y1, x2, y2);
 
@@ -1029,14 +1082,10 @@
       if (!_rsz) { _x1 += delx;  _y1 += dely; }
 
-      x1 = _x1; x2 = _x2;
-      y1 = _y1; y2 = _y2;
+      if (!_fgxor) gr->SelForeground(PI_HighlightBlue);
+      ComputeDrawerZone();
       gr->DrawBox(x1,y1, x2, y2);
-      x1 = _x1+0.9*(_x2-_x1);
-      y1 = _y1+0.9*(_y2-_y1);
+      ComputeResizeZone();
       gr->DrawFBox(x1,y1, x2, y2);
-      x1 = _x1+0.4*(_x2-_x1);
-      x2 = _x2-0.4*(_x2-_x1);
-      y1 = _y1+0.4*(_y2-_y1);
-      y2 = _y2-0.4*(_y2-_y1);
+      ComputeMoveZone();
       gr->DrawBox(x1,y1, x2, y2);      
       gr->SelGOMode(gmod);
@@ -1047,91 +1096,81 @@
 
     case  PIEvent_But1Release :
+      if (_ipx < 0)  return;
       if (_okend) {
-	// On enleve le handler et on efface de rectangle de resize/move
+   // On efface de rectangle de resize/move
+        if (_fgxor) {
+          gr->SelForeground(PI_Magenta);
+          gr->SelGOMode(PI_GOXOR);
+        }       
+        else {
+          gr->SelForeground(mBWdg->GetBackgroundColor());
+          gr->SelGOMode(PI_GOCopy);
+        }
+        gr->SelLine(PI_ThinLine);
 	
-	gr->SelForeground(PI_Magenta);
-	gr->SelGOMode(PI_GOXOR);
-	gr->SelLine(PI_ThinLine);
-	
-	gr->DrawBox(x1,y1, x2, y2);
-	x1 = _x1+0.9*(_x2-_x1);
-	y1 = _y1+0.9*(_y2-_y1);
-	gr->DrawFBox(x1,y1, x2, y2);
-	x1 = _x1+0.4*(_x2-_x1);
-	x2 = _x2-0.4*(_x2-_x1);
-	y1 = _y1+0.4*(_y2-_y1);
-	y2 = _y2-0.4*(_y2-_y1);
-	gr->DrawBox(x1,y1, x2, y2);
+        ComputeDrawerZone();
+        gr->DrawBox(x1,y1, x2, y2);
+        ComputeResizeZone();
+        gr->DrawFBox(x1,y1, x2, y2);
+        ComputeMoveZone();
+        gr->DrawBox(x1,y1, x2, y2);
 	gr->SelGOMode(gmod);
 	gr->SelLine(gline);
 	gr->SelForeground(gcol);
-
-	cout << " DBG- 	mBWdg->RemoveEventHandler(this); " << endl;
+  // On enleve le handler 
+//	cout << " DBG- 	mBWdg->RemoveEventHandler(this); " << endl;
 	mBWdg->RemoveEventHandler(this);
-
+        _rmok = true;
 	return;
       }
 
-      if (_ipx < 0)  return;
+      // Nouvelle position / taille 
       delx = GetPosX()-_cpx;
       dely = GetPosY()-_cpy;
-
-      gr->SelForeground(PI_Magenta);
-      gr->SelGOMode(PI_GOXOR);
-      gr->SelLine(PI_ThinLine);
-
+      _x2 += delx;
+      _y2 += dely;
+      if (!_rsz) { _x1 += delx;  _y1 += dely; }
+      if (_elastic) {
+	x1 = (double)_x1/(double)mBWdg->XSize();
+	x2 = (double)_x2/(double)mBWdg->XSize();
+	y1 = (double)_y1/(double)mBWdg->YSize();
+	y2 = (double)_y2/(double)mBWdg->YSize();
+      }
+      else {
+	x1 = _x1; x2 = _x2;
+	y1 = _y1; y2 = _y2;
+      }
+      if (_defrect) {
+	mBWdg->SetDefaultDrawRectangle(x1, y1, x2, y2, _elastic);
+//	cout << "DBG-SetDefaultDrawRectangle() x1,y1=" << _x1 << "," << _y1 
+//     << " x2,y2=" << _x2 << "," << _y2 << endl;
+      }
+      else {
+        aid = mBWdg->GetActiveDrawerId();
+        mBWdg->MoveResizeDrawer(aid, x1, y1, x2, y2, _elastic);
+//	cout << "DBG-MoveResizeDrawer() x1,y1=" << _x1 << "," << _y1 
+//	     << " x2,y2=" << _x2 << "," << _y2 << endl;
+      }	
+      mBWdg->Refresh();
+
+      if (_fgxor) {
+        gr->SelForeground(PI_Magenta);
+        gr->SelGOMode(PI_GOXOR);
+      }
+      else {
+        gr->SelForeground(PI_HighlightBlue);
+        gr->SelGOMode(PI_GOCopy);
+      }
+      ComputeDrawerZone();
       gr->DrawBox(x1,y1, x2, y2);
-      x1 = _x1+0.9*(_x2-_x1);
-      y1 = _y1+0.9*(_y2-_y1);
+      ComputeResizeZone();
       gr->DrawFBox(x1,y1, x2, y2);
-      x1 = _x1+0.4*(_x2-_x1);
-      x2 = _x2-0.4*(_x2-_x1);
-      y1 = _y1+0.4*(_y2-_y1);
-      y2 = _y2-0.4*(_y2-_y1);
-      gr->DrawBox(x1,y1, x2, y2);
+      ComputeMoveZone();
+      gr->DrawBox(x1,y1, x2, y2);      
+
       gr->SelGOMode(gmod);
       gr->SelLine(gline);
       gr->SelForeground(gcol);
 
-      // Nouvelle position / taille 
-      _x2 += delx;
-      _y2 += dely;
-      if (!_rsz) { _x1 += delx;  _y1 += dely; }
-
-      x1 = _x1; x2 = _x2;
-      y1 = _y1; y2 = _y2;
-      gr->DrawBox(x1,y1, x2, y2);
-      x1 = _x1+0.9*(_x2-_x1);
-      y1 = _y1+0.9*(_y2-_y1);
-      gr->DrawFBox(x1,y1, x2, y2);
-      x1 = _x1+0.4*(_x2-_x1);
-      x2 = _x2-0.4*(_x2-_x1);
-      y1 = _y1+0.4*(_y2-_y1);
-      y2 = _y2-0.4*(_y2-_y1);
-      gr->DrawBox(x1,y1, x2, y2);      
-      gr->RestoreGraphicAtt();
-
-      aid = mBWdg->GetActiveDrawerId();
-      if (aid < 0) return;
-
-      if (_elastic) {
-	x1 = (double)_x1/(double)mBWdg->XSize();
-	x2 = (double)_x2/(double)mBWdg->XSize()+(double)_x1;
-	y1 = (double)_y1/(double)mBWdg->YSize();
-	y2 = (double)_y2/(double)mBWdg->YSize()+(double)_y1;
-      }
-      else {
-	x1 = _x1; x2 = _x2+_x1;
-	y1 = _y1; y2 = _y2+_y1;
-      }
-      if (_defrect) 
-	//	mBWdg->SetDefaultDrawRectangle(x1, y1, x2, y2, _elastic);
-	cout << "DBG-SetDefaultDrawRectangle() x1,y1=" << _x1 << "," << _y1 
-	     << " x2,y2=" << _x2 << "," << _y2 << endl;
-      else // mBWdg->MoveResizeDrawer(aid, x1, y1, x2, y2, _elastic);
-	cout << "DBG-MoveResizeDrawer() x1,y1=" << _x1 << "," << _y1 
-	     << " x2,y2=" << _x2 << "," << _y2 << endl;
-	
-      mBWdg->Refresh();
       break; 
 
@@ -1144,9 +1183,10 @@
 //------------------------------------------------------------
 /* --Methode-- */
-PIDrwMgrMenu::PIDrwMgrMenu(PIBaseWdg* bwdg) 
+PIDrwMgrMenu::PIDrwMgrMenu(PIBaseWdg* bwdg, bool fgxor) 
   : PIMenu(bwdg, "PIDrwMgrMenu", k_PopupMenu)
 {
   mBWdg = bwdg;
   mListDrw = NULL;
+  mFgxor = fgxor;
   mEvH = NULL;
 
@@ -1184,4 +1224,6 @@
     AppendPDMenu(mListDrw);
   }
+  PIDrawer*  actdr = mBWdg->GetActiveDrawer();
+  if (actdr)  actdr->HighLight(true);
 }
 
@@ -1190,5 +1232,8 @@
 {
   if (mListDrw) delete mListDrw;
-  if (mEvH) delete mEvH;
+  if (mEvH) { 
+    mEvH->CheckBeforeDelete();
+    delete mEvH;
+  }
 }
 
@@ -1204,10 +1249,10 @@
     case 401 :
       if (aid >= 0)  PIDrwTools::ShowPIDrwTools(mBWdg);
-      //	if (actdrw != NULL) actdrw->HighLight(false);
+      if (actdrw != NULL) actdrw->HighLight(false);
       break;
     case 402 :
       if (actdrw != NULL) { 
 	PIDrwOptionStringWindow::ShowDrwOptionStringWindow(actdrw);
-	//	actdrw->HighLight(false);
+	actdrw->HighLight(false);
       }
       break;
@@ -1215,10 +1260,11 @@
       if (actdrw != NULL) { 
 	actdrw->ShowControlWindow(mBWdg);
-	// actdrw->HighLight(false);
+	actdrw->HighLight(false);
       }
       break;
     case 404 :
       if (mEvH) delete mEvH;
-      mEvH = new PIDrwPosSizeEvH(mBWdg);
+      if (actdrw != NULL) actdrw->HighLight(false);
+      mEvH = new PIDrwPosSizeEvH(mBWdg, mFgxor);
       break;
     case 405 :
@@ -1235,5 +1281,5 @@
       break;
     default :
-      //      if (actdrw != NULL) actdrw->HighLight(false);
+      if (actdrw != NULL) actdrw->HighLight(false);
       if (msg >= 1000)
 	mBWdg->SetActiveDrawer(msg-1000);
Index: /trunk/SophyaPI/PI/pidrwtools.h
===================================================================
--- /trunk/SophyaPI/PI/pidrwtools.h	(revision 2528)
+++ /trunk/SophyaPI/PI/pidrwtools.h	(revision 2529)
@@ -88,5 +88,5 @@
 class PIDrwMgrMenu : public PIMenu {
 public:
-                  PIDrwMgrMenu(PIBaseWdg* bwdg);
+                  PIDrwMgrMenu(PIBaseWdg* bwdg, bool fgxor=true);
   virtual         ~PIDrwMgrMenu();
   virtual void    Process(PIMessage msg, PIMsgHandler* sender, void* data=NULL);
@@ -94,4 +94,5 @@
   PIMenu*  mListDrw;
   PIBaseWdg* mBWdg;
+  bool mFgxor;
   PIDrwPosSizeEvH* mEvH;
 };
Index: /trunk/SophyaPI/PI/piscdrawwdg.cc
===================================================================
--- /trunk/SophyaPI/PI/piscdrawwdg.cc	(revision 2528)
+++ /trunk/SophyaPI/PI/piscdrawwdg.cc	(revision 2529)
@@ -96,5 +96,5 @@
   FreeLimits();
   xEndDrag = yEndDrag = xBegDrag = yBegDrag = 0;
-  AddDrawer(mBDrw, true, false, false, false);
+  AddDrawer(mBDrw, true, false, false, true);
 
 //  Pour afficher les coordonnees courante (click-bouton-1)  
@@ -158,5 +158,5 @@
   else if (key == 'D' || key == 'd') {
     if (mDrwMen) delete mDrwMen;
-    mDrwMen = new PIDrwMgrMenu(this);
+    mDrwMen = new PIDrwMgrMenu(this, true);
     mDrwMen->Show();
   }  
@@ -428,8 +428,8 @@
     int nid = FindNearestDrawerId(x,y);
     SetActiveDrawerId(nid);
-    PIDrawer*  actdr = GetActiveDrawer();
-    if (actdr) { 
-      actdr->HighLight(true);
-    }
+//    PIDrawer*  actdr = GetActiveDrawer();
+//    if (actdr) { 
+//      actdr->HighLight(true);
+//    }
     return;
   }
@@ -476,9 +476,10 @@
     PIDrawer*  actdr = GetActiveDrawer();
     if (actdr) { 
-      actdr->HighLight(false);
+//      actdr->HighLight(false);
       if (mDrwMen) delete mDrwMen;
       mDrwMen = new PIDrwMgrMenu(this);
-      mDrwMen->Show(this, x, y);
-    }
+      mDrwMen->Show();
+    }
+
     return;
   }
Index: /trunk/SophyaPI/PI/piversion.h
===================================================================
--- /trunk/SophyaPI/PI/piversion.h	(revision 2528)
+++ /trunk/SophyaPI/PI/piversion.h	(revision 2529)
@@ -2,5 +2,5 @@
 #define PIVERSION_H_SEEN
 
-#define PI_VERSIONNUMBER  3.96
+#define PI_VERSIONNUMBER  3.97
 
 #endif
