// This may look like C code, but it is really -*- C++ -*-
// Module PI : Peida Interactive      PIWdgGen
//                                    Reza 10/95            
// LAL (Orsay) / IN2P3-CNRS  DAPNIA/SPP (Saclay) / CEA

#ifndef PIWDG_H_SEEN
#define PIWDG_H_SEEN

#include "machdefs.h"
#include "pimsghandler.h"
#include "picolist.h"

#include <string>
#include <list>
#include <vector>


void PIBeep();

// Les differents types d accrochage aux containers  

enum PIBindingKind {    
  PIBK_free = 0,
  PIBK_fixed = 1,
  PIBK_elastic = 2
};

enum PICopyPasteKind {    // Pour gerer les types d objets echange en copier/coller
  PICP_string = 1
};

class PSFile;
class PIContainerGen;
class PIEventHandler;

//  -------------------- Classe PIWdgGen -----------------------
class PIWdgGen : public PIMsgHandler
{
public:
  enum {ClassId = 100};

                         PIWdgGen(PIContainerGen *par, const char *nom,
                                   int sx=10, int sy=10, int px=0, int py=0);
  virtual               ~PIWdgGen();
  virtual void		 FinishCreate()=0; // apres avoir installe les sous-vues

  virtual long           kind() {return ClassId; }
//  string               kindstr();

  inline PIContainerGen* Parent() { return( parent ); }

  inline void         	 SetUserData( void * p, int fg = 0) {pdata=p; flag=fg; }
  inline void*       	 UserData() { return (pdata); };
  inline void const* 	 UserData() const { return (pdata); };
  inline int         	 UserFlag() { return(flag); };


  virtual void           SetMsg(PIMessage msg = 0);
  inline  PIMessage      Msg() { return (myMsg); }

  virtual void           SetSize(int sx, int sy)=0;
  virtual void           SetPos(int px, int py)=0;
  virtual void           SetBorderWidth(int bw)=0;

//  Divers : couleur de fond, et d'avant plan Effacement fenetre,
  virtual void           SetBackgroundColor(PIColors col=PI_White)= 0;
  virtual void           SetForegroundColor(PIColors col=PI_Black)= 0;
  virtual void           EraseWindow(int x0=0, int y0=0, int dx=0, int dy=0)= 0;
  virtual PIColors       GetBackgroundColor()= 0;
  virtual PIColors       GetForegroundColor()= 0;

//   Methode permettant de decoder des options a partir de chaines
  virtual int            DecodeOptionString(vector<string> & opt, 
					    bool rmdecopt=true);

//  Gestion des accrochages (binding) aux containers
  virtual void           SetBinding(PIBindingKind left, PIBindingKind top, 
                                    PIBindingKind right, PIBindingKind bottom)      =0;
  virtual bool           GetBinding(PIBindingKind& left, PIBindingKind& top, 
                                    PIBindingKind& right, PIBindingKind& bottom)    =0;
  virtual void		 LockBinding();
  virtual void		 UnLockBinding();

  virtual int            XSize()=0;
  virtual int            YSize()=0;
  virtual int            XPos()=0;
  virtual int            YPos()=0;

  virtual string         Nom()=0;
  virtual void           GetScreenPos(int & spx, int & spy);

// Pour activer, desactiver un composant graphique (PIWdg)
  virtual void           Manage()=0;
  virtual void           UnManage()=0;
  virtual bool           IfManaged()=0;
  virtual bool           IsVisible()=0;

//  Fonction qui doit etre appelee pour rafraichir la fenetre 
  virtual void       	 Refresh()=0;

//  Pour rendre un composant graphique (PIWdg) sensible/insensible 
//  aux actions utilisateur (souris, clavier, ...)
  virtual void           SetSensitive()=0;
  virtual void           SetUnSensitive()=0;
  virtual bool           IfSensitive()=0;

  virtual void           PSPrint(PSFile *psf, int ofx=0, int ofy=0,
				 double scale_x=1., double scale_y=1.);

//  Gestion de copier-coller
  virtual bool           ClaimSelection(unsigned int typ=PICP_string)                     = 0;
  virtual void           SelectionLost()                                                  = 0;
  virtual unsigned int   RequestSelection(unsigned int typ=PICP_string)                   = 0;
  virtual void*          ProvideSelection(unsigned int& typ, unsigned int& len)           = 0;
  virtual void           SelectionTransferEnd()                                           = 0;
  virtual void           PasteSelection(unsigned int typ, void *pdata, unsigned int l)    = 0;

//  Copie depuis un PIWdgGen
  virtual void		 CopyFrom(PIWdgGen* wdg, int ox, int oy, int dx, int dy, int x, int y) = 0;

//  Gestion des EventHandler
  virtual void		 AddDrawHandler(PIEventHandler* drwh, bool ad=false);
  virtual void		 RemoveDrawHandler(PIEventHandler* drwh);
  virtual void		 AddEventHandler(PIEventHandler* evh, unsigned long evtmask, bool ad=false);
  virtual void		 RemoveEventHandler(PIEventHandler* evh);

// !! Devrait etre protected - mis ici a cause de cxx  Reza 12/98
  struct EvHand { PIEventHandler* evh; unsigned long mask;  bool ad; };
protected:
  PIContainerGen*        parent;
  PIMessage              myMsg;
  list<EvHand>		 mDHlist;
  list<EvHand>		 mEHlist;
  bool			 bindingLock;
private:
  int flag;
  void * pdata;
};

// ---- La classe PIScreenBuffer doit se conformer a l'interface suivante
// class PIScreenBuffer {
// public :
//  			PIScreenBuffer(int sx, int sy);
//  virtual		~PIScreenBuffer();
//  virtual int         XSize();
//  virtual int         YSize();
//  virtual  void 	CopyFromWdg(PIWdg* wdg, int ox, int oy, int dx, int dy, int x, int y);
//  virtual  void 	CopyToWdg(PIWdg* wdg, int ox, int oy, int dx, int dy, int x, int y);
//  virtual  void 	CopyFrom(PIScreenBuffer* grb, int ox, int oy, int dx, int dy, int x, int y);
// };
  

#endif/* PIWDG_H_SEEN */
