AeFieldUI.h 7.65 KB
#ifndef __AeFieldUI__
#define __AeFieldUI__

#include <Xm/TextF.h>

#include "AeTypes.h"
#include "AeBinEditor.h"

class VkPopupMenu;
class AeAsset;
class AeAssetUI;
class AeAssetBin;


typedef int (*TIntGetProc)(AeAsset *);
typedef void (*TIntSetProc)(AeAsset *, int);

typedef float (*TFloatGetProc)(AeAsset *);
typedef void (*TFloatSetProc)(AeAsset *, float);

typedef char * (*TStringGetProc)(AeAsset *);
typedef void (*TStringSetProc)(AeAsset *, char *);

typedef AeAsset * (*TRefGetProc)(AeAsset *);
typedef void (*TRefSetProc)(AeAsset *, AeAsset *);


typedef enum
{
    kLeftJustify = XmALIGNMENT_BEGINNING,
    kCenterJustify = XmALIGNMENT_CENTER,
    kRightJustify = XmALIGNMENT_END
} TJustify;


// note that widths are column attributes while
// lens are value attributes.  widths may be less
// than lens to keep the lists from growing too big.
enum
{
    kMinWidth = 3,
    kMaxWidth = 25,

    kIntMaxLen = 16,
    kFloatMaxLen = 16,
    kStringMaxLen = kNameMaxLen
};


class AeFieldUI
{
public:
                        AeFieldUI (const char * name,
				   Boolean isEditable,
				   Boolean isSelectable,
				   Boolean isHierarchical,
				   Boolean isCommon,
				   TJustify justify,
				   int maxLen);

    virtual		~AeFieldUI (void);

    virtual Boolean	IsIcon (void)	{ return False; }
    virtual Boolean	HasPopup (void)	{ return False; }

    virtual void       	GetValueString (AeAsset *, String);
    virtual Boolean	SetValueString (AeAsset *, String);
    virtual Boolean	VerifyValueString (String);
    virtual Boolean	VerifyInput (XmTextVerifyCallbackStruct *, const char * prevStr);
    virtual Boolean	SetValue (AeAsset *, void * value) { return False; }

    virtual Boolean	HandleButtonPress (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);
    virtual void	HandleDoubleClick (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);

    char *		GetName (void)	{ return fName; }
    TJustify		GetJustify (void) { return fJustify; }
    int			GetMaxLen (void) { return fMaxLen; }

    virtual Boolean	IsEditable (AeAsset *) { return fIsEditable; }
    Boolean		IsSelectable (void) { return fIsSelectable; }
    Boolean		IsHierarchical (void) { return fIsHierarchical; }
    Boolean		IsCommon (void) { return fIsCommon; }

    int			GetWidth (void) { return fWidth; }
    int			GetMaxWidth (void) { return fMaxWidth; }
    int			GetLabelWidth (void) { return fLabelWidth; }

    Boolean		NeedsWidthUpdate (void) { return fNeedsWidthUpdate; }
    virtual Boolean     NeedsWidthRecalc (void) { return fNeedsWidthRecalc; }
    void		SetNeedsWidthRecalc (Boolean needsRecalc) { fNeedsWidthRecalc = needsRecalc; }

    void       		SetWidth (int width);
    void       	      	UpdateWidth (String newString, String oldString);

    static void		CalcListFontRatio (void);

protected:

    TString63		fName;
    TJustify		fJustify;
    Boolean		fIsEditable;
    Boolean		fIsSelectable;
    Boolean		fIsHierarchical;   // true if field is part of hierarchy
    Boolean		fIsCommon;	   // true if field is common to all assets						     

 int			fMaxLen;

    // width information to make updating column widths easy
    int			fWidth;
    int			fMaxWidth;
    int			fLabelWidth;
    Boolean		fNeedsWidthUpdate;
    Boolean		fNeedsWidthRecalc;

    static double       fLabel2CellFontRatio;
};


class AeFloatFieldUI : public AeFieldUI
{
public:
                        AeFloatFieldUI (const char * name,
				      Boolean isEditable,
				      Boolean isSelectable,
				      Boolean isHierarchical,
				      TJustify justify,
				      TFloatGetProc getProc,
				      TFloatSetProc setProc);
                        AeFloatFieldUI (const char * name,
				      Boolean isEditable,
				      Boolean isSelectable,
				      Boolean isHierarchical,
				      TJustify justify,
				      TFloatGetProc getProc,
				      TFloatSetProc setProc,
				      float min, float max, float def);
    virtual		~AeFloatFieldUI (void);

    virtual void       	GetValueString (AeAsset *, String);
    virtual Boolean	SetValueString (AeAsset *, String);
    virtual Boolean	VerifyValueString (String);
    virtual Boolean	VerifyInput (XmTextVerifyCallbackStruct *, const char * prevStr);

private:
    TFloatGetProc      	fGetProc;
    TFloatSetProc      	fSetProc;

    float	       	fMin;
    float	       	fMax;
    float	       	fDefault;
};


class AeRefFieldUI : public AeFieldUI
{
public:
                        AeRefFieldUI (const char * name,
				      Boolean isEditable,
				      Boolean isSelectable,
				      Boolean isHierarchical,
				      TJustify justify,
				      AeAssetBin * refBin,
				      TRefGetProc getProc,
				      TRefSetProc setProc);
    virtual		~AeRefFieldUI (void);

    virtual Boolean	HasPopup (void) { return True; }
    virtual void       	GetValueString (AeAsset *, String);
    virtual Boolean	SetValueString (AeAsset *, String);
    virtual Boolean	VerifyValueString (String);
    virtual Boolean    	SetValue (AeAsset *, void * value);
    AeAsset *		GetValue (AeAsset *);

    virtual Boolean	HandleButtonPress (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);
    virtual void	HandleDoubleClick (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);

private:
    TRefGetProc		fGetProc;
    TRefSetProc		fSetProc;
    AeAssetBin *	fRefBin;

    // routines and variables to handle reference field menu editing
    void	       	addMenuItems (VkPopupMenu *);
};


class AeStringFieldUI : public AeFieldUI
{
public:
                        AeStringFieldUI (const char * name,
					 Boolean isEditable,
					 Boolean isSelectable,
					 Boolean isHierarchical,
					 Boolean isCommon,
					 TJustify justify,
					 TStringGetProc getProc,
					 TStringSetProc setProc);
    virtual		~AeStringFieldUI (void);

    virtual void       	GetValueString (AeAsset *, String);
    virtual Boolean	SetValueString (AeAsset *, String);
    virtual Boolean	VerifyValueString (String);

private:
    TStringGetProc     	fGetProc;
    TStringSetProc     	fSetProc;
};


class AeIconFieldUI : public AeFieldUI
{
public:
                        AeIconFieldUI (const char * name,
				       Boolean isSelectable,
				       Boolean isCommon,
				       TJustify justify);
    virtual		~AeIconFieldUI (void);

    virtual void       	GetValueString (AeAsset *, String);
    virtual Boolean	HandleButtonPress (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);
    virtual void	HandleDoubleClick (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);
    virtual Boolean	IsIcon (void) { return True; }
    virtual Boolean     NeedsWidthRecalc (void) { return False; }

private:
};


class AeContainerFieldUI : public AeFieldUI
{
public:
                        AeContainerFieldUI (const char * name,
					    Boolean orphansOnly,
					    TIntGetProc getProc);
    virtual		~AeContainerFieldUI (void);

    virtual void       	GetValueString (AeAsset *, String);
    virtual Boolean	HandleButtonPress (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);
    virtual void	HandleDoubleClick (AeBinEditor *, AeAssetUI *, XEvent *, TEditModifier);
    virtual Boolean     NeedsWidthRecalc (void) { return False; }

private:
    void	       	addMenuItems (VkPopupMenu *, AeBinEditor *, AeAssetUI *);
    void		handleMenuItem (AeBinEditor *, AeAssetUI *, AeAsset *);
    static void		MenuCallback (Widget, XtPointer, XtPointer);

    TIntGetProc		fGetProc;
    AeAssetBin *	fParentBin;
    Boolean		fOrphansOnly;
};


class AeTypeFieldUI : public AeFieldUI
{
public:
                        AeTypeFieldUI (const char * name,
				       TJustify justify,
				       TIntGetProc getProc);
    virtual		~AeTypeFieldUI (void);

    virtual void       	GetValueString (AeAsset *, String);

private:
    void		assettype2assetstr (int, String);
    TIntGetProc		fGetProc;
};


#endif __AeFieldUI__