AeAssetBinUI.c++ 4.18 KB
#include <assert.h>
#include <string.h>

#include "Matrix.h"
#include "GList.h"
#include "AeAssetBinUI.h"
#include "AeAssetUI.h"
#include "AeFieldUI.h"
#include "AeAssetBin.h"
#include "AeAsset.h"
#include "AeBinView.h"


AeAssetBinUI::AeAssetBinUI (AeAssetBin * bin, AeClient * client)
{
    fBin = bin;
    fChildBinUI = NULL;
    fClient = client;

    fFieldUIList = new GList<AeFieldUI *>;
}


AeAssetBinUI::~AeAssetBinUI (void)
{
    int i;

    if (fFieldUIList)
    {
	AeFieldUI * fieldUI;

	fFieldUIList->Start (i);
	while (fFieldUIList->Next (i, fieldUI))
	    delete fieldUI;
       
	delete fFieldUIList;
    }
}


TAssetType
AeAssetBinUI::GetType (void)
{
    assert (fBin);
    return fBin->GetType ();
}


void
AeAssetBinUI::SetName (const char * name)
{
    assert (name);
    assert (strlen(name) < kNameMaxLen);
    strcpy (fName, name);
}


int
AeAssetBinUI::GetNumFields (void)
{
    return fFieldUIList->GetNum ();
}


void
AeAssetBinUI::GetFieldLabels (String * labelArray)
{
    AeFieldUI *	fieldUI;
    int		i;

    fFieldUIList->Start (i);
 
    while (fFieldUIList->Next (i, fieldUI))
	*labelArray++ = fieldUI->GetName ();
}


void
AeAssetBinUI::GetFieldMaxLens (int * maxLenArray)
{
    AeFieldUI *	fieldUI;
    int		i;

    fFieldUIList->Start (i);

    while (fFieldUIList->Next (i, fieldUI))
	*maxLenArray++ = fieldUI->GetMaxLen ();
}


void
AeAssetBinUI::GetFieldAligns (unsigned char * alignArray)
{
    AeFieldUI *	fieldUI;
    int		i;

    fFieldUIList->Start (i);

    while (fFieldUIList->Next (i, fieldUI))
	*alignArray++ = (unsigned char)fieldUI->GetJustify ();
}    


void
AeAssetBinUI::GetFieldWidths (short * widthArray)
{
    AeAssetBin *	bin;
    GList<AeAsset *> *	assetList;
    AeFieldUI *		fieldUI;
    int			widthMax;
    int			i;

    bin = GetBin ();
    assetList = bin->GetAssetList ();

    fFieldUIList->Start (i);
    while (fFieldUIList->Next (i, fieldUI))
    {
	if (fieldUI->NeedsWidthRecalc ())
	{
	    widthMax = fieldUI->GetLabelWidth ();
	    calcWidth (assetList, fieldUI, widthMax);
	    fieldUI->SetWidth (widthMax);
	}

	*widthArray++ = fieldUI->GetWidth ();
    }
}


void
AeAssetBinUI::SetNeedsWidthRecalc (Boolean recalc)
{
    AeFieldUI *	fieldUI;
    int		i;

    fFieldUIList->Start (i);

    while (fFieldUIList->Next (i, fieldUI))
	fieldUI->SetNeedsWidthRecalc (recalc);
}


void
AeAssetBinUI::AppendFieldUI (AeFieldUI * fieldUI)
{
    fFieldUIList->Append (fieldUI);
}


void
AeAssetBinUI::UpdateHierarchy (void)
{
    AeFieldUI * fieldUI;
    int i;

    // Mark each hierarchical field for width recalculation
    fFieldUIList->Start (i);
    while (fFieldUIList->Next (i, fieldUI))
	if (fieldUI->IsHierarchical ())
	    fieldUI->SetNeedsWidthRecalc (True);
}


void
AeAssetBinUI::UpdateAssetUIFields (AeBinView * view, AeAssetUI * assetUI, int row)
{
    AeFieldUI *	fieldUI;
    int		col;
    TString63	string;

    fFieldUIList->Start (col);

    while (fFieldUIList->Next (col, fieldUI))
    {
	if (assetUI->IsEditable (fieldUI))
	{
	    assetUI->GetFieldString (fieldUI, string);
	    view->ListUpdateCell (row, col-1, string);
	}
    }
}


void
AeAssetBinUI::SetListFieldData (Widget list)
{
    AeFieldUI *	fieldUI;
    int		i;

    fFieldUIList->Start (i);

    while (fFieldUIList->Next (i, fieldUI))
	XbaeMatrixSetColumnUserData (list, i-1, fieldUI);

    assert (i == XbaeMatrixNumColumns (list));
}


//
// This routine updates the width of the given fieldUI
// by finding the asset with the largest value in terms
// of string length.
// The width value is used by list views of asset data.
//
void
AeAssetBinUI::calcWidth (GList<AeAsset *> * assetList,
			 AeFieldUI * fieldUI, int & widthMax)
{
    AeAsset *	       	asset;
    AeAssetUI *	       	assetUI;
    int		       	width;
    TString63	       	string;
    int		       	i;
 
    assetList->Start (i);

    while (assetList->Next (i, asset))
    {
	if (asset->GetClientData (fClient, (void **)&assetUI))
	{
	    assetUI->GetFieldString (fieldUI, string);

	    if ((width = strlen (string)) > widthMax)
	    {
		widthMax = width;
		if (widthMax >= fieldUI->GetMaxWidth ())
		    break;
	    }

	    if (assetUI->IsOpen ())
		fChildBinUI->calcWidth (((AeContainerAsset *)asset)->GetChildList (), fieldUI, widthMax);
	}
    }
}