////////////////////////////////////////////////////////////////////////////////
//
// parmacro.cpp -  
//
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"

#ifndef __PARMACRO_H
#include "parmacro.h"
#endif


//-------------------------------------------------------------------------------
//     - <studs3d.cpp>
// ---
LPTSTR LoadStr( int id );
 

//-------------------------------------------------------------------------------
// 
// ---
LPCTSTR ParMacroItem::GetString()
{
  static TCHAR buf[512];
  switch ( type ) 
  {
    case  pmFloat:
      ::_stprintf( buf, _T("%g"), *(float*)v );
      break;
    case  pmInt:
      ::_stprintf( buf, _T("%d"), *(int*)v );
      break;
    case  pmChar:
    {
      _bstr_t val = (char *)v;
      ::_tcscpy( buf, val );
      break;
    }
    case  pmWChar:
    { 
      _bstr_t val = (wchar_t *)v;
        ::_tcscpy( buf, val );
      break;
    }  
  }
  return buf;
}


//-------------------------------------------------------------------------------
// 
// --- 
void ParMacroListView::AddParItem( void* v, parMacroItemType par, int columnId ) 
{
	arrItem.Add( ParMacroItem(v, par, columnId) );
}


//-------------------------------------------------------------------------------
// 
// ---
void ParMacroListView::SetupView() 
{
  UINT count = arrItem.GetSize(); 
  if ( count ) 
  {
		CRect r;
		GetClientRect( &r );
    int width = (r.Width() - 2) / count; 

    for ( UINT i = 0; i < count; i++ ) 
    {
      InsertColumn( i, LoadStr( arrItem[i].columnId ), LVCFMT_LEFT, width );
    }
		InsertItem( 0, _T("") );  
  }

  Show();
  ShowScrollBar( SB_BOTH, false );
}


//-------------------------------------------------------------------------------
// 
// ---
void ParMacroListView::Flush() 
{
  UINT count = arrItem.GetSize(); 

  if ( count ) 
  {
    DeleteAllItems();
    for ( int i = count - 1; i >= 0; i-- )
      DeleteColumn( i );
  }
  arrItem.RemoveAll(); 
}


//-------------------------------------------------------------------------------
// 
// ---
void ParMacroListView::Show() 
{
  UINT count = arrItem.GetSize(); 
  if ( count ) 
    for ( UINT i = 0; i < count; i++ ) 
      SetItemText( 0, i, arrItem[i].GetString() );
}


