/***************************************************************

Description:
  This interperts propaccumulator data to screen properties. 
  basically just colourizes strings passed in.

Methods:
  -- shared methods --

   PropFilter     ( PropAccumulator * source = NULL );

   int     SetSource  ( propAccumulator * source = NULL );	
   int     Colourize( char * LineBuff, char * PropBuff, long buffersizes, long accumulatorPos );
   
  -- internal methods --


 Dont use tab characters in this code.
  Dont use tab characters in this code.
   Dont use tab characters in this code.
    Dont use tab characters in this code.
     Dont use tab characters in this code.
      Dont use tab characters in this code.
       Dont use tab characters in this code.
        Dont use tab characters in this code.
         Dont use tab characters in this code.
          thanks.

History: 
 <Jul 28 2002> Creation Dan, 
 <Apr 13 2003> Added some code for colourize. Dan, 
 <Dec 13 2003> fixed for gcc 3.3 dan, 
 <Dec 16 2003> using proptypes dan
 

***************************************************************/

#include <stdlib.h>
#include <stdio.h>      // printf
#include <string.h>
#include "cestypes.h" 
#include "propfilter.h"       // class definition
#include "propaccumulator.h"  // dependencies.

/*****************************************
*
* Description:
*  Constructor.
*
* In:
*  VIF:             display device
*  PropAccumulator: deivice that holds prop information
*  X:               x scroll position
*  Y:               y scroll position
*
* Out:
*
*****************************************/
//PropFilter::PropFilter ( PropAccum * source = NULL ) {
PropFilter::PropFilter ( PropAccum * source ) {
  SetSource  ( source  );
  SetStyle ();
}


/****************************************
*
* This is a just a temp method to make 
*  debugging of this code esier to read.
* Though in the future, this class will have
*  a table defining how types of tags are 
*  interperted, and a method like this
*  will be needed.
*
* Summary: this is a copout
*
****************************************/

//CESError_t PropFilter::SetStyle ( int style = 31 ) {
CESError_t PropFilter::SetStyle ( int style ) {

  CursorStyle = style;
  
  return NoError;
}

/****************************************
*
* Description:
*  Set data source.
*
* In:
*   source: pointer to a prop accumulator.
*
* Out:
*   0
*
****************************************/
//CESError_t PropFilter::SetSource (  PropAccum * source = NULL ) {
CESError_t PropFilter::SetSource (  PropAccum * source  ) {
  
  SourceData = source;     // dont ask why its here...

  return NoError;
}
 



/************************************************
*
*  clean up.
*
************************************************/
PropFilter::~PropFilter ( void ) {
 return;
}



/************************************************
*
*  this will be really complicated, so for now
*   just hilight the cursor (Owner 0, Index 0)
*
************************************************/
CESError_t PropFilter::Colourize( char * LineBuff, char * PropBuff, long buffersizes, long accumulatorPos ){
 
 CES_FIELD_TAG * Cursor;
  
 // !!!???!!! this code is all temporary, darn I wish I had some help. 
 // we want to look this up by type...
// if (SourceData->get(0, 0, &Cursor) == NULL) {
 if ((Cursor = SourceData->locate(0, 0, PROP_CURSOR_START, 0)) == NULL){
   return IndexNotFound;
 }
  //for Owner 0 Index 0 (for lack of some search code in the propaccum)
    // is its position within ours? 
  if (WITHIN( accumulatorPos, accumulatorPos+strlen(LineBuff) , Cursor->getPosition() ) ) {
      // if so, apply it
      //we'll use white with a blue background which is .. 30... I think
      PropBuff[Cursor->getPosition() - accumulatorPos ] = CursorStyle;
     // LineBuff[Cursor.getPosition() - accumulatorPos ] = 'D';
  }
  
 
  return NoError; 
}
  
  
  
  
  
  
  
  
