Index: /trunk/SophyaPI/PI/Makefile
===================================================================
--- /trunk/SophyaPI/PI/Makefile	(revision 8)
+++ /trunk/SophyaPI/PI/Makefile	(revision 9)
@@ -77,10 +77,8 @@
 #------------------------------------------------- End of Makefile.h ------- 
  
-all: $(LIB)libPI.a $(SLB)libPI.so 
-$(LIB)libPI.a : $(OBJ)ex_dessin.o $(OBJ)piapplgen.o $(OBJ)piapplx.o $(OBJ)pibwdggen.o $(OBJ)pibwdgx.o $(OBJ)picmap.o $(OBJ)picmapgen.o $(OBJ)picmapx.o $(OBJ)picontainergen.o $(OBJ)picontainerx.o $(OBJ)pidrawwin.o $(OBJ)pifilechogen.o $(OBJ)pifilechox.o $(OBJ)pihisto.o $(OBJ)piimage.o $(OBJ)pimenubargen.o $(OBJ)pimenubarx.o $(OBJ)pimenugen.o $(OBJ)pimenux.o $(OBJ)pimsghandler.o $(OBJ)pioptmenugen.o $(OBJ)pioptmenux.o $(OBJ)pipixmapgen.o $(OBJ)pipixmapx.o $(OBJ)piscdrawwdg.o $(OBJ)pistdwdggen.o $(OBJ)pistdwdgx.o $(OBJ)piwdggen.o $(OBJ)piwdgx.o $(OBJ)piwdgxt.o $(OBJ)piwindowgen.o $(OBJ)piwindowx.o $(OBJ)pixtbase.o $(OBJ)sc_sample.o
+all: $(LIB)libPI.a  
+$(LIB)libPI.a : $(OBJ)ex_dessin.o $(OBJ)piapplgen.o $(OBJ)piapplx.o $(OBJ)pibwdggen.o $(OBJ)pibwdgx.o $(OBJ)picmap.o $(OBJ)picmapgen.o $(OBJ)picmapx.o $(OBJ)picontainergen.o $(OBJ)picontainerx.o $(OBJ)pidrawwin.o $(OBJ)pifilechogen.o $(OBJ)pifilechox.o $(OBJ)pihisto.o $(OBJ)piimage.o $(OBJ)pimenubargen.o $(OBJ)pimenubarx.o $(OBJ)pimenugen.o $(OBJ)pimenux.o $(OBJ)pimsghandler.o $(OBJ)pioptmenugen.o $(OBJ)pioptmenux.o $(OBJ)pipixmapgen.o $(OBJ)pipixmapx.o $(OBJ)piscdrawwdg.o $(OBJ)pistdwdggen.o $(OBJ)pistdwdgx.o $(OBJ)piwdggen.o $(OBJ)piwdgx.o $(OBJ)piwindowgen.o $(OBJ)piwindowx.o $(OBJ)pixtbase.o 
 	ar -rs $@ $?
- 
-$(SLB)libPI.so : $(LIB)libPI.a
-	ld -S -shared -o $(SLB)libPI.so -all -L$(LIB) $(LIB)libPI.a 2>/dev/null
+
 $(OBJ)ex_dessin.o: ex_dessin.cc ex_dessin.h pisysdep.h pibwdgx.h pibwdggen.h \
  piwdgx.h piwdggen.h pimsghandler.h
@@ -170,6 +168,4 @@
 $(OBJ)piwdgx.o: piwdgx.cc piwdgx.h piwdggen.h pimsghandler.h picontainerx.h \
  pisysdep.h picontainergen.h
-$(OBJ)piwdgxt.o: piwdgxt.cc piwdggen.h pimsghandler.h picontainergen.h \
- pisysdep.h piwdgx.h
 $(OBJ)piwindowgen.o: piwindowgen.cc piwindowgen.h pisysdep.h picontainerx.h \
  picontainergen.h piwdgx.h piwdggen.h pimsghandler.h
@@ -213,8 +209,11 @@
  $(INC)fitskeys.h \
  $(INC)utils.h $(INC)peida.h 
+
 piapp : $(EXE)piapp 
 	
-$(EXE)piapp  : $(OBJ)pidemo.o $(OBJ)pidemoup.o $(LIB)libPI.a
-	g++ -o $(EXE)piapp $(OBJ)pidemo.o $(OBJ)pidemoup.o -L$(LIB) -lPI -lImages -lOutils -lmath -lXm -lXt -lX11 -lm
+$(EXE)piapp  : $(OBJ)pidemo.o $(OBJ)pidemoup.o \
+                $(SLB)libPI.so $(SLB)libpeida.so $(SLB)liberosc.so 
+	cc -o $(EXE)piapp $(OBJ)pidemo.o $(OBJ)pidemoup.o \
+              -L$(SLB) -lPI -lpeida -lerosc -lgcxx -lXm -lXt -lX11 -lm  
 
 $(OBJ)pitestapp.o: pitestapp.cc pisysdep.h piapplx.h piapplgen.h \
@@ -235,3 +234,3 @@
 	
 $(EXE)pitest  : $(OBJ)pitestapp.o $(LIB)libPI.a
-	g++ -o $(EXE)pitest $(OBJ)pitestapp.o -L$(LIB) -lPI -lImages -lOutils -lmath -lXm -lXt -lX11 -lm
+	g++ -v -o $(EXE)pitest $(OBJ)pitestapp.o -L$(LIB) -lPI -lImages -lOutils -lmath -lXm -lXt -lX11 -lm
Index: /trunk/SophyaPI/PI/ex_dessin.cc
===================================================================
--- /trunk/SophyaPI/PI/ex_dessin.cc	(revision 8)
+++ /trunk/SophyaPI/PI/ex_dessin.cc	(revision 9)
@@ -64,4 +64,9 @@
 SelLine(PI_ThickLine);
 DrawLine(70, 120, 100, 120);
+
+SelForeground(PI_Magenta);
+DrawFCircle(120, 30, 15);
+SelForeground(PI_Grey);
+DrawFCircle(120, 60, 15);
 
 return;
Index: /trunk/SophyaPI/PI/pi.rsc
===================================================================
--- /trunk/SophyaPI/PI/pi.rsc	(revision 8)
+++ /trunk/SophyaPI/PI/pi.rsc	(revision 9)
@@ -1,11 +1,2 @@
-PeidaInt*activeBackground:                   LightBlue
-PeidaInt*default*activeBackground:           LightBlue
-PeidaInt*activeBottomShadowColor:            Black
-PeidaInt*default*activeBottomShadowColor:    Black
-PeidaInt*activeForeground:                   LightBlue
-PeidaInt*default*activeForeground:           LightBlue
-PeidaInt*default*highlightColor:             LightBlue
-PeidaInt*activeTopShadowColor:               White
-PeidaInt*default*activeTopShadowColor:       White
 PeidaInt*background:                         LightGrey
 PeidaInt*default*background:                 LightGrey
@@ -31,6 +22,7 @@
 PeidaInt*fontList:           -*-helvetica-bold-r-normal-*-12-*-*-*-*-*-ISO8859-1
 PeidaInt*default*fontList:    -*-helvetica-bold-r-normal-*-12-*-*-*-*-*-ISO8859-1
-PidaInt*fontList:           -*-*-Bold-*-*-*-12-*-*-*-*-*-*-*
-PidaInt*default*fontList:   -*-*-Bold-*-*-*-12-*-*-*-*-*-*-*
+
+# Attention, ne pas mettre de blanc a la fin du nom de fonte
+PeidaInt*fontFamilyName:   *-helvetica
 
 PeidaInt*XmToggleButton*selectColor:                  Red
Index: /trunk/SophyaPI/PI/pibwdggen.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdggen.h	(revision 8)
+++ /trunk/SophyaPI/PI/pibwdggen.h	(revision 9)
@@ -9,7 +9,7 @@
 enum PIKeyModifier { PIKM_Blank = 0, PIKM_Shift = 1, PIKM_Alt = 2, PIKM_Cntl = 4 } ; 
 
-enum PIColors { PI_Black = 0, PI_White = 1, 
-                PI_Red = 2, PI_Blue = 3, PI_Green = 4,  
-                PI_Yellow = 5 } ; 
+enum PIColors { PI_Black = 0, PI_White = 1,  PI_Grey = 2,
+                PI_Red = 3, PI_Blue = 4, PI_Green = 5,  
+                PI_Yellow = 5, PI_Magenta =6} ; 
 enum PIFontSize {PI_SmallSizeFont = 1, PI_NormalSizeFont = 2, PI_BigSizeFont = 3 };
 enum PIFontAtt {PI_RomanFont = 1, PI_BoldFont = 2, PI_ItalicFont = 4 };
@@ -47,4 +47,6 @@
   virtual void       DrawFCircle(int x0, int y0, int r)                    = 0;
 
+  virtual int        CalcStringWidth(char const* s)                        = 0;
+
   virtual void       SelForeground(PIColors col=PI_Black)                  = 0;
   virtual void       SelBackground(PIColors col=PI_White)                  = 0;
Index: /trunk/SophyaPI/PI/pibwdgmac.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdgmac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pibwdgmac.cc	(revision 9)
@@ -4,4 +4,6 @@
 #include "pibwdgmac.h"
 #include "piupdattachment.h"
+#include <algobase.h>
+#include <string.h>
 
 // Les methodes de la classe  PIBWdgGen
@@ -63,7 +65,18 @@
     ::MoveTo(pt.h, pt.v);
     LStr255 ps = s;
+    ::TextFont(applFont);
     ::DrawString(ps);
   }
 }
+
+
+/* --Methode-- */
+int PIBaseWdgMac::CalcStringWidth(char const* s)
+{
+  if (mPane->FocusDraw())
+    ::TextFont(applFont);
+  return ::TextWidth(s,0,strlen(s));
+}
+
 
 /* --Methode-- */
@@ -87,4 +100,7 @@
     mPane->LocalToPortPoint(pt);
     Rect r = {pt.v, pt.h, pt.v+dy, pt.h+dx};
+    if (r.top  > r.bottom) swap(r.top,  r.bottom);
+    if (r.left > r.right)  swap(r.left, r.right);
+    r.right++; r.bottom++;
     ::FrameRect(&r);
   }
@@ -99,4 +115,7 @@
     mPane->LocalToPortPoint(pt);
     Rect r = {pt.v, pt.h, pt.v+dy, pt.h+dx};
+    if (r.top  > r.bottom) swap(r.top,  r.bottom);
+    if (r.left > r.right)  swap(r.left, r.right);
+    r.right++; r.bottom++;
     ::PaintRect(&r);
   }
@@ -110,4 +129,6 @@
     mPane->LocalToPortPoint(pt);
     Rect rr = {pt.v-r, pt.h-r, pt.v+r, pt.h+r};
+    if (rr.top  > rr.bottom) swap(rr.top,  rr.bottom);
+    if (rr.left > rr.right)  swap(rr.left, rr.right);
     ::FrameOval(&rr);
   }
@@ -121,4 +142,6 @@
     mPane->LocalToPortPoint(pt);
     Rect rr = {pt.v-r, pt.h-r, pt.v+r, pt.h+r};
+    if (rr.top  > rr.bottom) swap(rr.top,  rr.bottom);
+    if (rr.left > rr.right)  swap(rr.left, rr.right);
     ::PaintOval(&rr);
   }
@@ -191,4 +214,5 @@
 {
   if (mPane->FocusDraw()) {
+    ::TextFont(applFont);
     switch(sz) {
       case PI_SmallSizeFont:
@@ -202,4 +226,24 @@
         break;
     }
+    switch(att) {
+      case PI_RomanFont:
+        ::TextFace(0);
+        break;
+      case PI_BoldFont:
+        ::TextFace(bold);
+        break;
+      case PI_ItalicFont:
+        ::TextFace(italic);
+        break;
+    }
+  }
+}
+
+/* --Methode-- */
+void PIBaseWdgMac::SelFontSzPt(int npt, PIFontAtt att)
+{
+  if (mPane->FocusDraw()) {
+    ::TextFont(applFont);
+    ::TextSize(npt);
     switch(att) {
       case PI_RomanFont:
Index: /trunk/SophyaPI/PI/pibwdgmac.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdgmac.h	(revision 8)
+++ /trunk/SophyaPI/PI/pibwdgmac.h	(revision 9)
@@ -32,4 +32,5 @@
   virtual void       DrawCircle(int x0, int y0, int r);
   virtual void       DrawFCircle(int x0, int y0, int r);
+  virtual int        CalcStringWidth(char const* s);  
   
   virtual void       SelForeground(PIColors col=PI_White);
@@ -37,4 +38,5 @@
   virtual void       SelFont(PIFontSize sz=PI_NormalSizeFont, 
                              PIFontAtt att=PI_RomanFont);
+  virtual void       SelFontSzPt(int npt=12, PIFontAtt att=PI_RomanFont); 
   virtual void       SelLine(PILineAtt att=PI_NormalLine);
   virtual void       SelPointerShape(PIPointer ptr);
Index: /trunk/SophyaPI/PI/pibwdgx.cc
===================================================================
--- /trunk/SophyaPI/PI/pibwdgx.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pibwdgx.cc	(revision 9)
@@ -16,6 +16,6 @@
 /*  Variables globales pour modifier les GC  */
 #define NMAXFONTSZ  5
-static Font fnt[NMAXFONTSZ][3];
-static int fntsz[NMAXFONTSZ] = {9,10,12,14,16};
+static XFontStruct * fntst[NMAXFONTSZ][3];
+static int fntsz[NMAXFONTSZ] = {7,10,12,14,16};
 static  PIFontAtt fntatt[3] = { PI_RomanFont, PI_BoldFont, PI_ItalicFont }; 
 #define NMAXCOL  10
@@ -182,4 +182,9 @@
 }
 
+/* --Methode-- */
+int PIBaseWdgX::CalcStringWidth(char const* s)
+{
+return(XTextWidth(mFSt, s, strlen(s)));
+}
 
 /* --Methode-- */
@@ -254,5 +259,6 @@
 mFAtt = fntatt[jat];
 mFSize = fntsz[isz];
-XSetFont(XtDisplay(XtWdg()), DefGC(), fnt[isz][jat]);
+mFSt = fntst[isz][jat];
+XSetFont(XtDisplay(XtWdg()), DefGC(), fntst[isz][jat]->fid);
 return;
 }
@@ -319,5 +325,5 @@
 
 /* --Methode-- */
-void PIBaseWdgX::Draw(int x0, int y0, int dx, int dy)
+void PIBaseWdgX::Draw(int /*x0*/, int /*y0*/, int /*dx*/, int /*dy*/)
 {
 this->Draw();
@@ -374,30 +380,30 @@
 
 /* --Methode-- */
-void PIBaseWdgX::But2Press(int x, int y)
-{
-return;
-}
-
-/* --Methode-- */
-void PIBaseWdgX::But2Release(int x, int y)
-{
-return;
-}
-
-/* --Methode-- */
-void PIBaseWdgX::But3Press(int x, int y)
-{
-return;
-}
-
-/* --Methode-- */
-void PIBaseWdgX::But3Release(int x, int y)
-{
-return;
-}
-
-
-/* --Methode-- */
-void PIBaseWdgX::Ptr1Move(int x, int y)
+void PIBaseWdgX::But2Press(int /* x */, int /* y */)
+{
+return;
+}
+
+/* --Methode-- */
+void PIBaseWdgX::But2Release(int /* x */, int /* y */)
+{
+return;
+}
+
+/* --Methode-- */
+void PIBaseWdgX::But3Press(int /* x */, int /* y */) 
+{
+return;
+}
+
+/* --Methode-- */
+void PIBaseWdgX::But3Release(int /* x */, int /* y */) 
+{
+return;
+}
+
+
+/* --Methode-- */
+void PIBaseWdgX::Ptr1Move(int  x, int  y ) 
 {
 #ifdef DEBUG_PIBWDGX
@@ -408,12 +414,12 @@
 
 /* --Methode-- */
-void PIBaseWdgX::Ptr2Move(int x, int y)
-{
-return;
-}
-
-
-/* --Methode-- */
-void PIBaseWdgX::Ptr3Move(int x, int y)
+void PIBaseWdgX::Ptr2Move(int /* x */, int /* y */)  
+{
+return;
+}
+
+
+/* --Methode-- */
+void PIBaseWdgX::Ptr3Move(int /* x */, int /* y */)  
 {
 return;
@@ -434,9 +440,27 @@
 static bool fgbwdg = false ;
 
+// Le bazar pour recuperer des resources de .Xdefault et autres 
+typedef struct 
+  {
+  String fntFam;
+  } myAppData;
+static myAppData  apd;
+
+static XtResource resources[] = {
+  { "fontFamilyName", "FontFamilyName", XtRString, sizeof(String),
+    /*XtOffset(apdp, fntFam)*/ 0, XtRString, "*-helvetica" }
+};
+ 
+static char * fnbi_b[4] = { "medium-r-normal", "bold-r-normal", 
+                          "medium-o-normal", "medium-i-normal" };
+
 /* --Methode-- */
 void PIBaseWdgX::Init()
 {
-char buff[200];
-int i,j;
+char buff[256];
+int i,j,jj,k, count;
+char **list;
+XFontStruct * defnt;
+char * fnbi[3];
 
 if (fgbwdg)  return;
@@ -447,26 +471,83 @@
 XColor exact,mycol;
 Colormap  cmap;
-Status rc;
 
 mdsp = PIXDisplay();
 scr = XDefaultScreen(mdsp);
 
+XtGetApplicationResources(PIXtTopWdg(), &apd, resources, 
+                          XtNumber(resources), NULL, 0);
+sprintf(buff,"-%s-*-*-*-*-*-*-*-*-*-*-*-*", apd.fntFam);
+list = XListFonts(mdsp, buff, 15, &count);
+XFreeFontNames(list);
+if (count < 5)
+  { 
+  printf("PIBaseWdgX::Init %d fonts found for %s , switching to helvetica\n",
+         count, apd.fntFam);
+  apd.fntFam = "*-helvetica";
+  }
+sprintf(buff,"-%s-%s-*-*-*-*-*-*-*-*-*", apd.fntFam, fnbi_b[0]);
+list = XListFonts(mdsp, buff, 10, &count);
+XFreeFontNames(list);
+if (count < 2) fnbi[0] = "*-*-*";
+else  fnbi[0] = fnbi_b[0];
+sprintf(buff,"-%s-%s-*-*-*-*-*-*-*-*-*", apd.fntFam, fnbi_b[1]);
+list = XListFonts(mdsp, buff, 10, &count);
+XFreeFontNames(list);
+if (count < 2) fnbi[1] = "*-*-*";
+else  fnbi[1] = fnbi_b[1];
+sprintf(buff,"-%s-%s-*-*-*-*-*-*-*-*-*", apd.fntFam, fnbi_b[2]);
+list = XListFonts(mdsp, buff, 10, &count);
+XFreeFontNames(list);
+fnbi[2] = fnbi_b[2];
+if (count < 2) 
+  {
+  sprintf(buff,"-%s-%s-*-*-*-*-*-*-*-*-*", apd.fntFam, fnbi_b[3]);
+  list = XListFonts(mdsp, buff, 10, &count);
+  XFreeFontNames(list);
+  fnbi[2] = fnbi_b[3];
+  }
+if (count < 2) fnbi[2] = "*-*-*";
+
+sprintf(buff,"-*-fixed-*-*-*-*-14-*-*-*-*-*-*-*");
+list = XListFonts(mdsp, buff, 10, &count);
+XFreeFontNames(list);
+if (count < 1) 
+  {  
+  sprintf(buff,"fixed");
+  list = XListFonts(mdsp, buff, 10, &count);
+  XFreeFontNames(list);
+  }
+if (count < 1) 
+  {  
+  strcpy(buff,"");
+  list = XListFonts(mdsp, buff, 10, &count);
+  XFreeFontNames(list);
+  printf("PIBaseWdgX::Init/ Erreur, no font found ... \n");
+  defnt = NULL;
+  }
+else defnt = XLoadQueryFont(mdsp, buff);
+
 /* Allocation des fonts */
 for (i=0; i<NMAXFONTSZ; i++)
+  for (j=0; j<3; j++)
   {
-  sprintf(buff,"-*-helvetica-medium-r-normal-*-%d-*-*-*-*-*-ISO8859-1", fntsz[i]);
-  fnt[i][0] = XLoadFont(mdsp, buff);
-  if (fnt[i][0] == 0)  printf("PIBaseWdgX::Init: Pb font %s \n", buff);
-  sprintf(buff,"-*-helvetica-bold-r-normal-*-%d-*-*-*-*-*-ISO8859-1", fntsz[i]);
-  fnt[i][1] = XLoadFont(mdsp, buff);
-  if (fnt[i][0] == 0)  printf("PIBaseWdgX::Init: Pb font %s \n", buff);
-  sprintf(buff,"-*-helvetica-medium-o-normal-*-%d-*-*-*-*-*-ISO8859-1", fntsz[i]);
-  fnt[i][2] = XLoadFont(mdsp, buff);
-  if (fnt[i][0] == 0)  printf("PIBaseWdgX::Init: Pb font %s \n", buff);
-  }
-
-for(i=0; i<NMAXFONTSZ; i++)
-  for(j=0; j<3; j++)
-    if (fnt[i][j] == 0) XLoadFont(mdsp, "fixed");
+  for (k=0; k<5; k++)
+    {
+    sprintf(buff,"-%s-%s-*-%d-*-*-*-*-*-*-*", apd.fntFam, fnbi[j], fntsz[i]+k);
+    list = XListFonts(mdsp, buff, 10, &count);
+    XFreeFontNames(list);
+    if (count > 0)  break;
+    }
+  if (count > 0)
+    {  
+    fntst[i][j] = XLoadQueryFont(mdsp, buff);
+//    printf("PIBaseWdgX::Init:  font %s loaded \n", buff);
+    }
+  else
+    {   
+    printf("PIBaseWdgX::Init: Pb font %s \n", buff);    
+    fntst[i][j] = defnt;
+    }
+  }
 
  
@@ -477,13 +558,16 @@
 colpix[PI_Black] = XBlackPixel(mdsp, scr);
 colpix[PI_White] = XWhitePixel(mdsp, scr);
-
-if ( XAllocNamedColor (mdsp, cmap, "Red", &mycol, &exact) )
+if ( XAllocNamedColor (mdsp, cmap, "LightGray", &mycol, &exact) )
+  colpix[PI_Grey] = mycol.pixel;
+if ( XAllocNamedColor (mdsp, cmap, "red", &mycol, &exact) )
   colpix[PI_Red] = mycol.pixel;
-if ( XAllocNamedColor (mdsp, cmap, "Blue", &mycol, &exact) )
+if ( XAllocNamedColor (mdsp, cmap, "blue", &mycol, &exact) )
   colpix[PI_Blue] = mycol.pixel;
-if ( XAllocNamedColor (mdsp, cmap, "Green", &mycol, &exact) )
+if ( XAllocNamedColor (mdsp, cmap, "green", &mycol, &exact) )
   colpix[PI_Green] = mycol.pixel;
-if ( XAllocNamedColor (mdsp, cmap, "Yellow", &mycol, &exact) )
+if ( XAllocNamedColor (mdsp, cmap, "yellow", &mycol, &exact) )
   colpix[PI_Yellow] = mycol.pixel;
+if ( XAllocNamedColor (mdsp, cmap, "magenta", &mycol, &exact) )
+  colpix[PI_Magenta] = mycol.pixel;
 
 curs[0] = XCreateFontCursor(mdsp, XC_X_cursor);
Index: /trunk/SophyaPI/PI/pibwdgx.h
===================================================================
--- /trunk/SophyaPI/PI/pibwdgx.h	(revision 8)
+++ /trunk/SophyaPI/PI/pibwdgx.h	(revision 9)
@@ -31,4 +31,6 @@
   virtual void   DrawCircle(int x0, int y0, int r);
   virtual void   DrawFCircle(int x0, int y0, int r);
+
+  virtual int    CalcStringWidth(char const* s);
 
   virtual void   SelForeground(PIColors col=PI_Black);
@@ -71,4 +73,5 @@
   PIFontAtt mFAtt;
   int mFSize;
+  XFontStruct *mFSt;
 };
 
Index: /trunk/SophyaPI/PI/pidemo.cc
===================================================================
--- /trunk/SophyaPI/PI/pidemo.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pidemo.cc	(revision 9)
@@ -1,4 +1,6 @@
 #include <stdlib.h>
 #include <stdio.h>
+#include <string.h>
+#include <dlfcn.h>
 
 #include "perrors.h"
@@ -6,8 +8,48 @@
 
 #include "pidemo.h"
-#include "pidemoup.h"
-
-
-
+#include "piup.h"
+
+
+/*  Pour le link dynamique  */
+typedef FitsImageR4 * (* UsPrFunc) (FitsImageR4 * myimg, int xp, int yp,
+                                    char * arg1, char * arg2);
+static UsPrFunc  userFunc[3] = { NULL, NULL, NULL };
+static void *dlhandle = NULL;
+
+static char userlibname[256];
+
+static int DynLink(char *usln);
+
+int DynLink(char *usln)
+{
+UsPrFunc uf;
+int i, rc;
+
+if (usln != NULL)  strncpy(userlibname, usln, 255);  userlibname[255] = '\0';
+
+printf("PIDemo_DynLink(): Relinking from %s \n", userlibname);
+if (dlhandle != NULL)  dlclose(dlhandle);
+for(i=0; i<3; i++)  userFunc[i] = NULL;
+dlhandle =  dlopen(userlibname, RTLD_NOW);
+if (dlhandle == NULL)  
+  { printf("PIDemo_DynLink(), Erreur d'ouverture UserShLib %s \n", userlibname);
+  return(100); }
+rc = 0;
+printf("PIDemo_DynLink(): Searching for PIUserProc_1 (Rc=%d) \n", rc);
+uf = dlsym(dlhandle, "PIUserProc_1__FPt9FitsImage1ZfiiPcT3");
+if (uf != NULL)  userFunc[0] = uf;
+else rc += 2;
+printf("PIDemo_DynLink(): Searching for PIUserProc_3 (Rc=%d) \n", rc);
+uf = dlsym(dlhandle, "PIUserProc_2__FPt9FitsImage1ZfiiPcT3");
+if (uf != NULL)  userFunc[1] = uf;
+else rc += 4;
+printf("PIDemo_DynLink(): Searching for PIUserProc_3 (Rc=%d) \n", rc);
+uf = dlsym(dlhandle, "PIUserProc_3__FPt9FitsImage1ZfiiPcT3");
+if (uf != NULL)  userFunc[2] = uf;
+else rc += 8;
+
+if (rc != 0)  printf("PIDemo_DynLink() / Erreur, Rc = %d \n", rc);
+return(rc);
+}
 
 /* ........................................................... */
@@ -28,5 +70,6 @@
 m[0]->AppendItem("Close", 10102);
 m[0]->AppendItem("Save", 10103);
-m[0]->AppendItem("Exit", 10104);
+m[0]->AppendItem("Relink", 10104);
+m[0]->AppendItem("Exit", 10105);
 
 m[1] = new PIPDMenu((PIMsgHandler *)Menubar(),"Image");
@@ -188,4 +231,10 @@
 
     case 10104:
+      SetBusy();
+      DynLink(NULL);
+      SetReady();
+      break;
+
+    case 10105:
       Stop();
       break;
@@ -407,13 +456,14 @@
 int n;
 if ((n=GetNumCurrent()) < 0)  return;
+zoom->SetPixmap(NULL,0,0);
+zoom->EraseWindow();
+labimg->SetLabel("");
 wpii[n]->Hide();
 delete pii[n];
 delete img[n];
 delete wpii[n];
-zoom->EraseWindow();
-labimg->SetLabel("");
-pii[n] = pii[mNimg];
-wpii[n] = wpii[mNimg];
-img[n] = img[mNimg];
+pii[n] = pii[mNimg-1];
+wpii[n] = wpii[mNimg-1];
+img[n] = img[mNimg-1];
 mNimg--;
 mCur = NULL;
@@ -648,9 +698,11 @@
       {
       case 1 :
-        oimg = PIUserProc_1(mimg, xp, yp, 
+      case 2 :
+      case 3 :
+        oimg = userFunc[mUpr-1] (mimg, xp, yp, 
                             (char *) (mText[1]->GetText().c_str()), 
                             (char *) (mText[2]->GetText().c_str()));
         break;
-
+/*
       case 2 :
         oimg = PIUserProc_2(mimg, xp, yp, 
@@ -664,5 +716,5 @@
                             (char *) (mText[2]->GetText().c_str()));
         break;
-
+*/
       }    
     if (oimg)  dap->AddImage(oimg,mText[0]->GetText());
@@ -680,12 +732,22 @@
 
 char *path;
+int rc;
   
 if (narg > 1)  path = arg[1];
 else path = NULL;
 
+if (narg > 2)  rc = DynLink(arg[2]);
+else rc = DynLink("piup.so");
+if (rc != 0)
+  {
+  printf("PIApp:: Erreur d'ouverture UserProcFunc Shared-Object ... \n");
+  exit(0);
+  }
+
 PIDemoApp app(path);
 
 app.Run();
 
+dlclose(dlhandle);
 exit(0);
 }
Index: /trunk/SophyaPI/PI/pidrawwin.cc
===================================================================
--- /trunk/SophyaPI/PI/pidrawwin.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pidrawwin.cc	(revision 9)
@@ -22,7 +22,7 @@
 
 void
-PIDrawWindow::SetAxesKind(int axesKind, int tickLevel, int markLevel)
+PIDrawWindow::SetAxesFlags(int flags)
 {
-  mDrawWdg->SetAxesKind(axesKind, tickLevel, markLevel);
+  mDrawWdg->SetAxesFlags(flags);
 }
 
Index: /trunk/SophyaPI/PI/pidrawwin.h
===================================================================
--- /trunk/SophyaPI/PI/pidrawwin.h	(revision 8)
+++ /trunk/SophyaPI/PI/pidrawwin.h	(revision 9)
@@ -16,5 +16,5 @@
                 
  virtual void    AddDrawer(PIScDrawer*);                
- virtual void    SetAxesKind(int axesChoice=1, int tickLevel=1, int markLevel=1);
+ virtual void    SetAxesFlags(int flags=-1);
 private:
   PIScDrawWdg*   mDrawWdg;
@@ -22,4 +22,4 @@
 
 
+#endif
 
-#endif
Index: /trunk/SophyaPI/PI/pifilechomac.cc
===================================================================
--- /trunk/SophyaPI/PI/pifilechomac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pifilechomac.cc	(revision 9)
@@ -10,5 +10,5 @@
   
   string fName;
-  int i = dir.rfind('/');
+  int i = dir.rfind(':');
   if (i == NPOS)
     fName = dir;
@@ -27,5 +27,6 @@
   p2cstr(reply.sfFile.name);
   
-  return directory + '/' + (char*)reply.sfFile.name;
+//  return directory + '/' + (char*)reply.sfFile.name;
+  return directory + ':' + (char*)reply.sfFile.name;
 }
 
@@ -42,5 +43,6 @@
   p2cstr(reply.sfFile.name);
   
-  return directory + '/' + (char*)reply.sfFile.name;
+//  return directory + '/' + (char*)reply.sfFile.name;
+  return directory + ':' + (char*)reply.sfFile.name;
 }
 
@@ -62,5 +64,7 @@
 			err = PBGetCatInfoSync(CInfoPBPtr(&block));
 			p2cstr(directoryName);
-			fullPathName = '/' + ((char*)directoryName + fullPathName);
+			if (fullPathName != "") fullPathName = ':' + fullPathName;
+			fullPathName =  ((char*)directoryName + fullPathName);
+//			fullPathName = '/' + ((char*)directoryName + fullPathName);
 	} while (block.ioDrDirID != 2);
 	return fullPathName;
Index: /trunk/SophyaPI/PI/pifilechomac.h
===================================================================
--- /trunk/SophyaPI/PI/pifilechomac.h	(revision 8)
+++ /trunk/SophyaPI/PI/pifilechomac.h	(revision 9)
@@ -28,4 +28,6 @@
 typedef PIFileChooserMac     PIFileChooser ;
 
+#define FILESEP ':'
+
 #endif
 
Index: /trunk/SophyaPI/PI/pihisto.cc
===================================================================
--- /trunk/SophyaPI/PI/pihisto.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pihisto.cc	(revision 9)
@@ -1,2 +1,3 @@
+#include <stdio.h>
 #include "pihisto.h"
 
@@ -26,16 +27,11 @@
   
   double xmin = mHisto->XMin();
-  double xmax = (mHisto->XMax())*1.2;
-  double margeH = (xmax-xmin)/10;
-  xmin -= margeH;
-  xmax += margeH;
+  double xmax = (mHisto->XMax());
 
-  double ymax = (*mHisto)(mHisto->IMax());
-  double margeV = ymax / 10;
-  double ymin = -margeV;
-  ymax += margeV;
+  double ymax = (*mHisto)(mHisto->IMax())*1.2;
+  double ymin = 0;
   
   mDrawWdg->SetLimits(xmin, xmax, ymin, ymax);
-  mDrawWdg->SetBBoxMargin(margeH, margeV);
+  mDrawWdg->SetAxesFlags(kBoxAxes | kExtTicks | kLabels);
 }
 
@@ -45,5 +41,4 @@
 {
   if (!mDrawWdg) return;
-  mDrawWdg->DrawBBox(1,2,1);
   for (int i=0; i<mHisto->NBins(); i++) {
 		double left   = mHisto->BinLowEdge(i);
@@ -52,6 +47,25 @@
 		double height = (*mHisto)(i);
 		mDrawWdg->ScDrawFBox(left,bottom,width,height);
-//		mDrawWdg->ScDrawLine(left, bottom, left, bottom + height);
+		mDrawWdg->ScDrawLine(left, bottom, left, bottom + height); // Au moins une ligne...
 	}
+  DrawStats();
+}
+
+void
+PIHisto::DrawStats()
+{
+  // Une boite dans le coin superieur droit
+  if (!mDrawWdg) return;
+  double cellHeight = (mDrawWdg->YMax() - mDrawWdg->YMin()) * 0.05;
+  double cellWidth  = (mDrawWdg->XMax() - mDrawWdg->XMin()) * 0.23;
+  mDrawWdg->ScDrawLine(mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax(),
+                       mDrawWdg->XMax() - cellWidth, mDrawWdg->YMax() - cellHeight);
+  mDrawWdg->ScDrawLine(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);
+                       
 }
 
Index: /trunk/SophyaPI/PI/pihisto.h
===================================================================
--- /trunk/SophyaPI/PI/pihisto.h	(revision 8)
+++ /trunk/SophyaPI/PI/pihisto.h	(revision 9)
@@ -11,4 +11,5 @@
   virtual           ~PIHisto();
   virtual void       Draw();
+  virtual void       DrawStats();
   virtual void       Refresh();  // Recalcule les limites, et reaffiche
 protected:
Index: /trunk/SophyaPI/PI/piimage.cc
===================================================================
--- /trunk/SophyaPI/PI/piimage.cc	(revision 8)
+++ /trunk/SophyaPI/PI/piimage.cc	(revision 9)
@@ -173,4 +173,5 @@
 {
 // printf("PIImage::Resize\n");
+PIPixmapX::Resize();
 SetPave();
 Apply();
@@ -393,4 +394,6 @@
   ofy = ypav+(ywsz*zm/2);
   }
+if (ofx < 0)  ofx = 0;
+if (ofy < 0)  ofy = 0;
 
 zpixm = ComputePixmap(ofx, ofy, zm, xwsz, ywsz, zpixm, &xszpxm, &yszpxm);
Index: /trunk/SophyaPI/PI/pimenumac.cc
===================================================================
--- /trunk/SophyaPI/PI/pimenumac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pimenumac.cc	(revision 9)
@@ -26,4 +26,5 @@
 PIMenuMac::FindItemByMsg(long msg)
 {
+  if (mMsgs.size() == 0) return -1;
   int i = find(mMsgs.begin(), mMsgs.end(), msg) - mMsgs.begin();
   return (i>=mMsgs.size()) ? -1 : i;
@@ -53,4 +54,5 @@
 PIMenuMac::CheckItemNum(int n, bool st)
 {
+  if (n<0 || n >= mMsgs.size()) return; // $CHECK$ exception ?
   ::CheckItem(macMenu->GetMacMenuH(), n, st);
 }
@@ -75,4 +77,5 @@
 PIMenuMac::DeleteItemNum(int n)
 {
+  if (n<0 || n >= mMsgs.size()) return; // $CHECK$ exception ?
   macMenu->RemoveItem(n+1);
   mMsgs.erase(mMsgs.begin()+n);
@@ -100,4 +103,5 @@
 PIMenuMac::ItemSelected(int item)
 {
+  if (item<0 || item >= mMsgs.size()) return; // $CHECK$ exception ?
   Send(mMsgs[item], (void*) GetMenuItemText(item).c_str());
 }
@@ -106,4 +110,8 @@
 void
 PIMenuMac::Show()
+{}
+
+void
+PIMenuMac::Show(PIWdg *w, int px, int py)
 {}
 
@@ -141,4 +149,5 @@
 PIMenuMac::GetMenuItemText(int item)
 {
+  if (item<0 || item >= mMsgs.size()) return ""; // $CHECK$ exception ?
   MenuHandle h = GetMacMenuHandle();
   Str255 txt;
@@ -147,4 +156,11 @@
   return (char*) txt;
 }
+
+PIMenuMac::GetMenuItemMsg(int item)
+{
+  if (item<0 || item >= mMsgs.size()) return -1; // $CHECK$ exception ?
+  return mMsgs[item];
+}
+
 
 
Index: /trunk/SophyaPI/PI/pimenumac.h
===================================================================
--- /trunk/SophyaPI/PI/pimenumac.h	(revision 8)
+++ /trunk/SophyaPI/PI/pimenumac.h	(revision 9)
@@ -24,4 +24,6 @@
 	
     virtual void    Show();
+    virtual void    Show(PIWdg *w, int px, int py);
+
     virtual void    Hide();
     
@@ -29,10 +31,11 @@
     void            ItemSelected(int item);
     
-	static PIMenuMac* findMenu(int id);
-	MenuHandle      GetMacMenuHandle();
-	ResIDT          GetMacMenuID();
 	string          GetMenuItemText(int item);
+	int             GetMenuItemMsg(int item);
+	int             FindItemByMsg(long msg);
+	int             FindItemByName(string const& nom);
 	
 protected:
+	static PIMenuMac* findMenu(int id);
 	LMenu*          macMenu;
 	int             mMenuId;
@@ -42,7 +45,9 @@
 	
 	friend class    PIMenubarMac;
+	friend class    PIOptMenuMac;
+	friend class    PIPPMenuBar;
+	MenuHandle      GetMacMenuHandle();
+	ResIDT          GetMacMenuID();
 	
-	int             FindItemByMsg(long msg);
-	int             FindItemByName(string const& nom);
    
 };
Index: /trunk/SophyaPI/PI/pioptmenumac.cc
===================================================================
--- /trunk/SophyaPI/PI/pioptmenumac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pioptmenumac.cc	(revision 9)
@@ -2,7 +2,7 @@
 
 /* --Methode-- */
-PIOptMenuMac::PIOptMenuMac(PIContainerGen* par, PIPDMenu *pdm,
+PIOptMenuMac::PIOptMenuMac(PIContainerGen* par, PIPUMenu *pdm,
                      int sx, int sy, int px, int py)
-: PIOptMenuGen(par, pdm, sx, sy, px, py), mPDMenu(pdm)
+: PIOptMenuGen(par, pdm, sx, sy, px, py), mPUMenu(pdm)
 {
   delete mPane;
@@ -41,8 +41,8 @@
 
 void
-PIOptMenuMac::ListenToMessage(MessageT inMessage, void *)
+PIOptMenuMac::ListenToMessage(MessageT /*inMessage*/, void *)
 {
 //  if (inMessage == msg_Click)
-    mPDMenu->ItemSelected(((LStdPopupMenu*)mPane)->GetValue()-1);
+    mPUMenu->ItemSelected(((LStdPopupMenu*)mPane)->GetValue()-1);
 }
 
@@ -52,2 +52,31 @@
 mStext = txt;  mSmsg = msg;
 }
+
+/* --Methode-- */
+void PIOptMenuMac::SetValueStr(string & s)
+{
+int n;
+n=mPUMenu->FindItemByName((char *)s.c_str());
+if (n < 0)  return;  
+
+((LStdPopupMenu*)mPane)->SetValue(n+1);
+mStext = s;
+mSmsg  = mPUMenu->GetMenuItemMsg(n);
+
+return;
+}
+
+/* --Methode-- */
+void PIOptMenuMac::SetValue(long msg)
+{
+int n;
+n=mPUMenu->FindItemByMsg(msg);
+if (n < 0)  return;
+  
+((LStdPopupMenu*)mPane)->SetValue(n+1);
+mStext = mPUMenu->GetMenuItemText(n);
+mSmsg  = msg;
+
+return;
+}
+
Index: /trunk/SophyaPI/PI/pioptmenumac.h
===================================================================
--- /trunk/SophyaPI/PI/pioptmenumac.h	(revision 8)
+++ /trunk/SophyaPI/PI/pioptmenumac.h	(revision 9)
@@ -6,5 +6,5 @@
 class PIOptMenuMac : public PIOptMenuGen {
 public:
-	                PIOptMenuMac(PIContainerGen* par, PIPDMenu *pdm,  
+	                PIOptMenuMac(PIContainerGen* par, PIPUMenu *pdm,  
                                int sx=10, int sy=10, int px=0, int py=0);
 	               ~PIOptMenuMac();
@@ -15,4 +15,6 @@
   virtual string    GetValueStr() { return(mStext); }
   virtual long      GetValue()    { return(mSmsg); } 
+  virtual void      SetValueStr(string & s);
+  virtual void      SetValue(long msg);
   
   inline void       Select(char *txt, long msg); // public ou protege ???
@@ -23,5 +25,5 @@
   long      mSmsg;
   //MenuHandle macMenu;
-  PIPDMenu* mPDMenu;
+  PIPUMenu* mPUMenu;
 };
 
Index: /trunk/SophyaPI/PI/pipixmapx.cc
===================================================================
--- /trunk/SophyaPI/PI/pipixmapx.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pipixmapx.cc	(revision 9)
@@ -15,4 +15,5 @@
 {
 Init();
+AllocXImg();
 }
 
@@ -20,18 +21,41 @@
 /* --Methode-- */
 PIPixmapX::~PIPixmapX()
-{}
+{
+delete[] myximg->data;
+XFree(myximg); 
+}
 
+/* --Methode-- */
+void PIPixmapX::Refresh()
+{
+int i,j;
+unsigned char *pp;
+
+for(j=0; j<ny; j++)
+  {
+  pp = pixmap+j*nx;
+  for(i=0; i<nx; i++)
+    { XPutPixel(myximg, i, j, cmap->Color(*pp) );  pp++; }
+  }
+
+for(j=ny; j<YSize(); j++)
+  for(i=nx; i<XSize(); i++)
+    XPutPixel(myximg, i, j, 0 );
+
+PIBaseWdgX::Refresh();
+}
 
 
 /* --Methode-- */
+void PIPixmapX::Resize()
+{
+delete[] myximg->data;
+XFree(myximg); 
+AllocXImg();
+}
+/* --Methode-- */
 void PIPixmapX::Draw()
 {
-Window xw;
-Display * mdsp;
-xw = XtWindow(XtWdg());
-mdsp = PIXDisplay();
-if (nx < XSize())  XClearArea(mdsp, xw, nx, 0, XSize()-nx, YSize(), False);
-if (ny < YSize())  XClearArea(mdsp, xw, 0, ny, XSize(), YSize()-ny, False);
-Draw(0,0,XSize(),YSize());
+Draw(0, 0, XSize(), YSize());
 }
 
@@ -39,45 +63,29 @@
 void PIPixmapX::Draw(int x0, int y0, int dx, int dy)
 {
-int depth;
-XImage * ximg;
 Window xw;
 Display * mdsp;
-int scr;
-
-int i,j;
-unsigned char *pp;
-
-
-if ((pixmap == NULL) || (cmap == NULL)) return;
+if ((myximg == NULL) || (cmap == NULL)) return;
 
 xw = XtWindow(XtWdg());
 mdsp = PIXDisplay();
-scr = PIXScreen();
 
 if (x0 < 0)  x0 = 0;
 if (y0 < 0)  y0 = 0;
 
-if (dx > (nx-x0)) dx = nx-x0;
-if (dy > (ny-y0)) dy = ny-y0;
+if (dx > (XSize()-x0)) dx = XSize()-x0;
+if (dy > (YSize()-y0)) dy = YSize()-y0;
 if ((dx <= 0) || (dy <= 0))  return;
 
-depth = DefaultDepth(mdsp,scr);
-ximg = XCreateImage (mdsp,DefaultVisual(mdsp,scr),
-       depth,ZPixmap,0,NULL,dx,dy,8,0);
-if (ximg == NULL)  return;
-ximg->data = new char [dy*ximg->bytes_per_line];
-if (ximg->data == NULL)  { XFree(ximg); return; }
+if ( (nx < x0 ) || (ny < y0) )
+  { XClearArea(mdsp, xw, x0, y0, dx, dy, False);  return; }
 
-for(j=0; j<dy; j++)
-  {
-  pp = pixmap+(j+y0)*nx+x0;
-  for(i=0; i<dx; i++)
-    { XPutPixel(ximg, i, j, cmap->Color(*pp) );  pp++; }
-  }
-XPutImage(mdsp, xw, mygc, ximg, 0,0, x0, y0, nx, ny);
+if (nx < (x0+dx))
+  { XClearArea(mdsp, xw, nx, y0, x0+dx-nx, dy, False);  dx = nx-x0; }
+if (ny < (y0+dy))
+  { XClearArea(mdsp, xw, x0, ny, dx, y0+dy-ny, False);  dy = ny-y0; }
+  
+XPutImage(mdsp, xw, mygc, myximg, x0, y0, x0, y0, dx, dy);
 XSync(mdsp, 0);
 
-delete[] ximg->data;
-XFree(ximg);
 return;
  
@@ -111,2 +119,26 @@
 return;
 }
+
+
+/* --Methode-- */
+void PIPixmapX::AllocXImg()
+{
+Window xw;
+Display * mdsp;
+int scr;
+int depth;
+int pad;
+
+xw = XtWindow(XtWdg());
+mdsp = PIXDisplay();
+scr = PIXScreen();
+
+depth = DefaultDepth(mdsp,scr);
+pad = (depth > 8) ? 32 : 8;
+myximg = XCreateImage (mdsp,DefaultVisual(mdsp,scr),
+           depth,ZPixmap,0,NULL, XSize(), YSize(), pad,0);
+if (myximg == NULL)  return;
+myximg->data = new char [YSize()*myximg->bytes_per_line];
+if (myximg->data == NULL)  XFree(myximg); 
+return;
+}
Index: /trunk/SophyaPI/PI/pipixmapx.h
===================================================================
--- /trunk/SophyaPI/PI/pipixmapx.h	(revision 8)
+++ /trunk/SophyaPI/PI/pipixmapx.h	(revision 9)
@@ -11,4 +11,6 @@
   virtual      ~PIPixmapX();
 
+  virtual void  Refresh();
+  virtual void  Resize();
   virtual void  Draw();
   virtual void  Draw(int x0, int y0, int dx, int dy);
@@ -17,4 +19,6 @@
 protected:
   void          Init();
+  void          AllocXImg();
+  XImage * myximg;  
 };
 
Index: /trunk/SophyaPI/PI/pippapplmac.cc
===================================================================
--- /trunk/SophyaPI/PI/pippapplmac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pippapplmac.cc	(revision 9)
@@ -21,2 +21,8 @@
   }   
 }
+
+
+// $CHECK$
+// Gerer AllowSubRemoval, qui envoie un evenement a l'application PI.
+// Eventuellement avoir des fenetres qui se cachent lors d'un close et d'autres
+// qui se detruisent ??
Index: /trunk/SophyaPI/PI/piscdrawwdg.cc
===================================================================
--- /trunk/SophyaPI/PI/piscdrawwdg.cc	(revision 8)
+++ /trunk/SophyaPI/PI/piscdrawwdg.cc	(revision 9)
@@ -3,5 +3,4 @@
 #include <algo.h>
 
-
 PIScDrawWdg::PIScDrawWdg(PIContainerGen *par, char *nom,
                          int sx, int sy, int px, int py)
@@ -11,4 +10,6 @@
   limitsFixed = 0;
   xEndDrag = yEndDrag = xBegDrag = yBegDrag = 0;
+  SetAxesFlags(kAxesDflt);
+  clip = true;
 }
 
@@ -51,8 +52,10 @@
 PIScDrawWdg::CalcScale()
 {
-  xScale = XSize() / (xMax-xMin);
-  yScale = -YSize() / (yMax-yMin);
-  xOrg   = -xMin * xScale + XPos();
-  yOrg   = -yMax * yScale + YPos();
+  double margeH = (xMax-xMin)*0.2;
+  double margeV = (yMax-yMin)*0.2;
+  xScale = XSize() / (xMax-xMin + 2*margeH);
+  yScale = -YSize() / (yMax-yMin + 2*margeV);
+  xOrg   = (-xMin + margeH) * xScale + XPos();
+  yOrg   = (-yMax - margeV) * yScale + YPos();
 }
 
@@ -81,8 +84,14 @@
     if (yFirstMinTick < yMin) yFirstMinTick += yMinTickStep;
     
-    xMajTickLen = -2/yScale;
-    xMinTickLen = -1/yScale;
-    yMajTickLen = 2/xScale;
-    yMinTickLen = 1/xScale;
+//    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;
+
 }
 
@@ -108,4 +117,20 @@
   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
@@ -120,4 +145,35 @@
 PIScDrawWdg::ScDrawLine(double x1, double y1, double x2, double y2)
 {
+  
+  if (clip) {
+    if (x2 < xMin && x1 < xMin) return;
+    if (x2 > xMax && x1 > xMax) return;
+    if (y1 < yMin && y2 < yMin) return;
+    if (y2 > 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);
@@ -129,4 +185,27 @@
 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);
@@ -138,4 +217,27 @@
 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);
@@ -163,106 +265,145 @@
 
 void
-PIScDrawWdg::DrawAxes(int tickLevel, int markLevel)
-{
-  // Les axes
-  
-  ScDrawLine(xMin, 0, xMax, 0);
-  ScDrawLine(0, yMin, 0, yMax);
-  
-  // Les ticks majeurs
-  
-  if (tickLevel > 0) {
-    for (double x=xFirstMajTick; x<=xMax; x += xMajTickStep)
-      ScDrawLine(x, -xMajTickLen, x, xMajTickLen);
-    for (double y=yFirstMajTick; y<=yMax; y += yMajTickStep)
-      ScDrawLine(-yMajTickLen, y, yMajTickLen, y);
-  }
-
-  // Les ticks mineurs
-  
-  if (tickLevel > 1) {
-    for (double x=xFirstMinTick; x<=xMax; x += xMinTickStep)
-      ScDrawLine(x, -xMinTickLen, x, xMinTickLen);
-    for (double y=yFirstMinTick; y<=yMax; y += yMinTickStep)
-      ScDrawLine(-yMinTickLen, y, yMinTickLen, y);
-  }
-
-
-}
-
-void
-PIScDrawWdg::SetBBoxMargin(double h, double v)
-{
-  bbmargeh = h;
-  bbmargev = v; 
-}
-
-void
-PIScDrawWdg::DrawBBox(int tickLevel, int tickFlags, int markLevel)
-{
-
-  double xLow = xMin + bbmargeh;
-  double xHig = xMax - bbmargeh;
-  double yLow = yMin + bbmargev;
-  double yHig = yMax - bbmargev;
-  
-  double extXMajTickLen = tickFlags&2 ? xMajTickLen : 0;
-  double intXMajTickLen = tickFlags&1 ? xMajTickLen : 0;
-  double extXMinTickLen = tickFlags&2 ? xMinTickLen : 0;
-  double intXMinTickLen = tickFlags&1 ? xMinTickLen : 0;
-  double extYMajTickLen = tickFlags&2 ? yMajTickLen : 0;
-  double intYMajTickLen = tickFlags&1 ? yMajTickLen : 0;
-  double extYMinTickLen = tickFlags&2 ? yMinTickLen : 0;
-  double intYMinTickLen = tickFlags&1 ? yMinTickLen : 0;
-  
-  
-  // Les bordures
-  
-  ScDrawLine(xLow, yLow, xHig, yLow);
-  ScDrawLine(xHig, yLow, xHig, yHig);
-  ScDrawLine(xHig, yHig, xLow, yHig);
-  ScDrawLine(xLow, yHig, xLow, yLow);
-  
-  // Les ticks majeurs
-  
-  if (tickLevel > 0) {
-    for (double x=xFirstMajTick; x<=xHig; x += xMajTickStep) {
-      ScDrawLine(x, yLow - extXMajTickLen, x, yLow + intXMajTickLen);
-      ScDrawLine(x, yHig + extXMajTickLen, x, yHig + intXMajTickLen);
-    }
-    for (double y=yFirstMajTick; y<=yHig; y += yMajTickStep) {
-      ScDrawLine(xLow - extYMajTickLen, y, xLow + intYMajTickLen, y);
-      ScDrawLine(xHig + extYMajTickLen, y, xHig - intYMajTickLen, y);
-    }
-  }
-  
-
-  // Les ticks mineurs
-  
-  if (tickLevel > 1) {
-    for (double x=xFirstMinTick; x<=xHig; x += xMinTickStep) {
-      ScDrawLine(x, yLow - extXMinTickLen, x, yLow + intXMinTickLen);
-      ScDrawLine(x, yHig + extXMinTickLen, x, yHig + intXMinTickLen);
-    }
-    for (double y=yFirstMinTick; y<=yHig; y += yMinTickStep) {
-      ScDrawLine(xLow - extYMinTickLen, y, xLow + intYMinTickLen, y);
-      ScDrawLine(xHig + extYMinTickLen, y, xHig - intYMinTickLen, y);
-    }
-  }
-  
-  // Les labels
-  if (markLevel > 0) {
-    for (double x=xFirstMajTick; x<=xHig; x += xMajTickStep) {
+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;
+  
+  ScSelFontSz(xMajTickLen*4);
+  for (double x=xBeg; x<=xMax; x += xStep) {
       char label[20]; sprintf(label, "%-6g", x);
-      ScDrawString(x, yLow - 8 * xMajTickLen, label);
-      ScDrawString(x, yHig + 2 * xMajTickLen, label);
-    }
-    for (double y=yFirstMajTick; y<=yHig; y += yMajTickStep) {
+      double largeur = ScStringWidth(label);
+      if (just == 1)
+        xOffset = -largeur;
+      else if (just == 0)
+        xOffset = -largeur/2;
+      else
+        xOffset = 0;
+      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);
-      ScDrawString(xLow - 8 * yMajTickLen, y, label);
-      ScDrawString(xHig + 2 * yMajTickLen, y, label);
-    }
-  }
-}
+      double largeur = ScStringWidth(label);
+      if (just == 1)
+        xOffset = -largeur;
+      else if (just == 0)
+        xOffset = -largeur/2;
+      else
+        xOffset = 0;
+      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) {
+        DrawHLabels(-xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
+        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) {
+        DrawHLabels(yMin-xMajTickLen*8, xFirstMajTick, xMajTickStep,0);
+        DrawHLabels(yMax+xMajTickLen*2, xFirstMajTick, xMajTickStep,0);
+        DrawVLabels(xMin-yMajTickLen*2, yFirstMajTick, yMajTickStep,1);
+        DrawVLabels(xMax+yMajTickLen*2, yFirstMajTick, yMajTickStep,-1);
+    }
+  }
+  Clip();
+}
+
+  
 
 void
@@ -302,9 +443,13 @@
 
 void
-PIScDrawWdg::SetAxesKind(int axesKind, int tickLevel, int markLevel)
-{
-  axesChoice  = axesKind;
-  tickChoice  = tickLevel;
-  labelChoice = markLevel;
+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;
 }
 
@@ -313,9 +458,7 @@
 {
   EraseWindow();
-  if (axesChoice == 1)
-    DrawAxes(tickChoice, labelChoice);
-  else if (axesChoice == 2)
-    DrawBBox(tickChoice, labelChoice);
+  DrawAxes();
   CallDrawers();
+  DrawSelf();
 }
 
@@ -329,5 +472,4 @@
   xEndDrag = xBegDrag = x;
   yEndDrag = yBegDrag = y;
-  PIBeep();
 }
 
@@ -429,5 +571,7 @@
 PIScGFFDrawer::PIScGFFDrawer(GeneralFitFunction* f)
 : mFunc(f), mNParms(f->NPar()), mParms(new double[mNParms])
-{}
+{
+  ASSERT(f->NVar() == 1);
+}
 
 PIScGFFDrawer::~PIScGFFDrawer()
@@ -437,6 +581,9 @@
 
 void
-PIScGFFDrawer::SetParms(double const*)
-{}
+PIScGFFDrawer::SetParms(double const* p)
+{
+  for (int i=0; i<mNParms; i++)
+    mParms[i] = p[i];
+}
 
 
@@ -444,4 +591,22 @@
 PIScGFFDrawer::Draw()
 {
-}
-
+  if (!mDrawWdg) return;
+  double xMax = mDrawWdg->XMax();
+  double xMin = mDrawWdg->XMin();
+  double yMax = mDrawWdg->YMax();
+  double yMin = mDrawWdg->YMin();
+  double xStep = (xMax - xMin)/100;
+  double xOld = xMin;
+  double yOld = 0;
+//  double yOld = f->Value(&xMin, mParms);
+  for (double x = xMin+xStep; x<xMax; x+=xStep) {
+   double y = 0; // $CHECK$
+//    double y = f->Value(&x, mParms);
+    if (y>yMin && yOld>yMin && 
+        y<yMax && yOld<yMax) 
+           mDrawWdg->ScDrawLine(xOld, yOld, x, y);
+    xOld = x;
+    yOld = y;
+  }
+}
+
Index: /trunk/SophyaPI/PI/piscdrawwdg.h
===================================================================
--- /trunk/SophyaPI/PI/piscdrawwdg.h	(revision 8)
+++ /trunk/SophyaPI/PI/piscdrawwdg.h	(revision 9)
@@ -7,4 +7,17 @@
 
 #include <list.h>
+
+  enum {
+    kStdAxes     = 0x0001,
+    kBoxAxes     = 0x0002,
+    kTicks       = 0x0004,
+    kIntTicks    = 0x0010,
+    kExtTicks    = 0x0020,
+    kMajTicks    = 0x0040,
+    kMinTicks    = 0x0080,
+    kLabels      = 0x1000,
+    kAxesDflt    = kStdAxes | kTicks | kLabels
+  };
+
 
 class PIScDrawWdg : public PIBaseWdg {
@@ -22,8 +35,9 @@
   virtual void       ScDrawCircle(double x0, double y0, double r);
   virtual void       ScDrawFCircle(double x0, double y0, double r);
+  virtual double     ScStringWidth(char const*);
+  virtual void       ScSelFontSz(double size, PIFontAtt att=PI_RomanFont); 
 
-  virtual void       DrawAxes(int tickLevel=1, int markLevel=1);
-  virtual void       DrawBBox(int tickLevel=1, int tickFlags=3, int markLevel=1);
-  virtual void       SetBBoxMargin(double h, double v);
+  virtual void       DrawAxes(int flags = -1);
+  virtual void       DrawSelf() {}
   
   virtual void       Resize();
@@ -44,5 +58,5 @@
   static  void       CallDrawer(PIScDrawer*);
   virtual void       CallDrawers();
-  virtual void       SetAxesKind(int axesChoice=1, int tickLevel=1, int markLevel=1);
+  virtual void       SetAxesFlags(int flags=kAxesDflt);
   
   double XMin() const {return xMin;}
@@ -52,4 +66,6 @@
   int    LimitsFixed() const {return limitsFixed;}
   void   FreeLimits() {limitsFixed = 0;}
+  void   NoClip() {clip = false;}
+  void   Clip() {clip = true;}
   
   
@@ -71,10 +87,17 @@
   
   int limitsFixed;
-  int axesChoice, tickChoice, labelChoice;
-  double bbmargeh, bbmargev;
+  int axesFlags;
   list<PIScDrawer*>   mDrawers;
   
   int xBegDrag, yBegDrag;
   int xEndDrag, yEndDrag;
+  
+  bool clip;
+  
+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);
 };
 
Index: /trunk/SophyaPI/PI/pistdwdgmac.cc
===================================================================
--- /trunk/SophyaPI/PI/pistdwdgmac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/pistdwdgmac.cc	(revision 9)
@@ -23,6 +23,6 @@
 
 PIButtonMac::PIButtonMac(PIContainerGen *par, char *nom, long msg,
-                         int sx, int sy, int px, int py)
-: PIButtonGen(par, nom, msg, sx, sy, px, py)
+                         int sx, int sy, int px, int py, PIBtnSign bsgn)
+: PIButtonGen(par, nom, msg, sx, sy, px, py, bsgn)
 {
   delete mPane;
Index: /trunk/SophyaPI/PI/pistdwdgmac.h
===================================================================
--- /trunk/SophyaPI/PI/pistdwdgmac.h	(revision 8)
+++ /trunk/SophyaPI/PI/pistdwdgmac.h	(revision 9)
@@ -17,5 +17,6 @@
 public:
                      PIButtonMac(PIContainerGen *par, char *nom, long msg = PIMsg_Click,
-                                  int sx=10, int sy=10, int px=0, int py=0);
+                                 int sx=10, int sy=10, int px=0, int py=0,
+                                 PIBtnSign bsgn = PIBtn_Label);
   virtual           ~PIButtonMac();
   virtual void	     ListenToMessage(MessageT inMessage, void *ioParam);
Index: /trunk/SophyaPI/PI/piup.h
===================================================================
--- /trunk/SophyaPI/PI/piup.h	(revision 9)
+++ /trunk/SophyaPI/PI/piup.h	(revision 9)
@@ -0,0 +1,8 @@
+#include "fitsimage.h"
+
+FitsImageR4 * PIUserProc_1(FitsImageR4 * myimg, int xp, int yp, 
+                           char * arg1, char * arg2);
+FitsImageR4 * PIUserProc_2(FitsImageR4 * myimg, int xp, int yp, 
+                           char * arg1, char * arg2);
+FitsImageR4 * PIUserProc_3(FitsImageR4 * myimg, int xp, int yp, 
+                           char * arg1, char * arg2);
Index: /trunk/SophyaPI/PI/piup_def.cc
===================================================================
--- /trunk/SophyaPI/PI/piup_def.cc	(revision 9)
+++ /trunk/SophyaPI/PI/piup_def.cc	(revision 9)
@@ -0,0 +1,30 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "ctimer.h"
+#include "imageop.h"
+
+#include "piup.h"
+
+FitsImageR4 * PIUserProc_1(FitsImageR4 * myimg, int xp, int yp, 
+                           char * arg1, char * arg2)
+{
+printf("PIUserProc_1/Dummy (%d %d %s %s) ne fait rien !\n", xp, yp, arg1, arg2);
+return(NULL);
+}
+ 
+FitsImageR4 * PIUserProc_2(FitsImageR4 * myimg, int xp, int yp, 
+                           char * arg1, char * arg2)
+{
+printf("PIUserProc_2/Dummy (%d %d %s %s) ne fait rien !\n", xp, yp, arg1, arg2);
+return(NULL);
+}
+ 
+FitsImageR4 * PIUserProc_3(FitsImageR4 * /*myimg*/, int xp, int yp, 
+                           char * arg1, char * arg2)
+{
+printf("PIUserProc_3/Dummy (%d %d %s %s) ne fait rien !\n", xp, yp, arg1, arg2);
+return(NULL);
+}
+ 
Index: /trunk/SophyaPI/PI/piupdattachment.cc
===================================================================
--- /trunk/SophyaPI/PI/piupdattachment.cc	(revision 8)
+++ /trunk/SophyaPI/PI/piupdattachment.cc	(revision 9)
@@ -6,5 +6,5 @@
 PIUpdAttachment* PIUpdAttachment::lastCursPane = NULL;
 bool PIUpdAttachment::hit = false;
-bool PIUpdAttachment::down = false;
+int PIUpdAttachment::down = 0;
 
 PIUpdAttachment::PIUpdAttachment(PIBaseWdgMac* wdg)
@@ -12,4 +12,9 @@
 {
 
+}
+
+PIUpdAttachment::~PIUpdAttachment()
+{
+  SysBeep(1);
 }
 
@@ -28,13 +33,12 @@
         break;
       case msg_Click: {
-        down = true;
         SMouseDownEvent* evt = (SMouseDownEvent*) data;
         EventModifiers mod = evt->macEvent.modifiers;
         if ((mod & cmdKey) && (mod & optionKey))
-          myWdg->But3Press(evt->whereLocal.h,evt->whereLocal.v);
+          { myWdg->But3Press(evt->whereLocal.h,evt->whereLocal.v); down = 3;}
         else if (mod & cmdKey)
-          myWdg->But2Press(evt->whereLocal.h,evt->whereLocal.v);
+          { myWdg->But2Press(evt->whereLocal.h,evt->whereLocal.v); down = 2;}
         else
-          myWdg->But1Press(evt->whereLocal.h,evt->whereLocal.v);
+          { myWdg->But1Press(evt->whereLocal.h,evt->whereLocal.v); down = 1;}
  		break;
  		}
@@ -63,6 +67,5 @@
  	    SetExecuteHost(!myWdg->AdjustCursor());
  	    // Est-ce un move, i.e. le bouton est-il toujours appuye depuis le dernier MouseDown ?
- 	    if (::StillDown()) {
- 	      down = true;
+ 	    if (::StillDown() && down) {
  	      Point pt = evt->where;
  	      myWdg->mPane->GlobalToPortPoint(pt);
@@ -79,15 +82,17 @@
           }
  	    } else if (down) {  // A changer le jour ou les attachements recoivent les mouseup.
- 	      down = false;
  	      Point pt = evt->where;
  	      myWdg->mPane->GlobalToPortPoint(pt);
  	      myWdg->mPane->PortToLocalPoint(pt);
           EventModifiers mod = evt->modifiers;
-          if ((mod & cmdKey) && (mod & optionKey))
+          //if ((mod & cmdKey) && (mod & optionKey))
+          if (down == 3)
             myWdg->But3Release(pt.h,pt.v);
-          else if (mod & cmdKey)
+          //else if (mod & cmdKey)
+          else if (down == 2)
             myWdg->But2Release(pt.h,pt.v);
           else
             myWdg->But1Release(pt.h,pt.v);
+ 	      down = 0;
         }
  	    break;
Index: /trunk/SophyaPI/PI/piupdattachment.h
===================================================================
--- /trunk/SophyaPI/PI/piupdattachment.h	(revision 8)
+++ /trunk/SophyaPI/PI/piupdattachment.h	(revision 9)
@@ -7,4 +7,5 @@
 public:
   PIUpdAttachment(PIBaseWdgMac* wdg);
+  ~PIUpdAttachment();
   
 protected:
@@ -18,5 +19,6 @@
  static PIUpdAttachment* lastCursPane;
  static bool hit;
- static bool down;
+ static int down;
  Point lastPt;
 };
+
Index: /trunk/SophyaPI/PI/piwdgmac.cc
===================================================================
--- /trunk/SophyaPI/PI/piwdgmac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/piwdgmac.cc	(revision 9)
@@ -7,5 +7,8 @@
 #include <LString.h>
 
-
+void PIBeep()
+{
+  ::SysBeep(1);
+}
 
 
Index: /trunk/SophyaPI/PI/piwdgmac.h
===================================================================
--- /trunk/SophyaPI/PI/piwdgmac.h	(revision 8)
+++ /trunk/SophyaPI/PI/piwdgmac.h	(revision 9)
@@ -19,4 +19,5 @@
   virtual void           SetSize(int sx, int sy);
   virtual void           SetPos(int px, int py);
+  virtual void           SetBorderWidth(int /*bw*/) {}
   virtual void           SetBinding(bool left, bool top, bool right, bool bottom);
   virtual int            XSize();
Index: /trunk/SophyaPI/PI/piwindowmac.cc
===================================================================
--- /trunk/SophyaPI/PI/piwindowmac.cc	(revision 8)
+++ /trunk/SophyaPI/PI/piwindowmac.cc	(revision 9)
@@ -14,4 +14,5 @@
 	                            windAttr_TitleBar |
 	                            windAttr_SizeBox |
+	                            windAttr_CloseBox |
 	                            windAttr_Resizable;
 	  mWindowInfo.layer = windLayer_Regular;
Index: /trunk/SophyaPI/PI/sc_sample.cc
===================================================================
--- /trunk/SophyaPI/PI/sc_sample.cc	(revision 8)
+++ /trunk/SophyaPI/PI/sc_sample.cc	(revision 9)
@@ -18,5 +18,5 @@
 ScSample::Draw()
 {
-  DrawAxes(1,0);
+  DrawAxes();
   PlotFunc(f);
 }
Index: /trunk/SophyaPI/PI/so_locations
===================================================================
--- /trunk/SophyaPI/PI/so_locations	(revision 8)
+++ /trunk/SophyaPI/PI/so_locations	(revision 9)
@@ -1,8 +1,12 @@
-libPeidaInter.so \
-		:st = .text 0x000003ffbffe0000, 0x0000000000020000:\
+piup.so \
+		:st = .text 0x000003ffbfff0000, 0x0000000000010000:\
 		:st = .data 0x000003ffffff0000, 0x0000000000010000:\
 
-libPI.so \
-		:st = .text 0x000003ffbffb0000, 0x0000000000030000:\
+piup_def.so \
+		:st = .text 0x000003ffbffe0000, 0x0000000000010000:\
 		:st = .data 0x000003fffffe0000, 0x0000000000010000:\
 
+user.so \
+		:st = .text 0x000003ffbffd0000, 0x0000000000010000:\
+		:st = .data 0x000003fffffd0000, 0x0000000000010000:\
+
