//
// ObjectWithWidgetsData.h
//
//	Copyright © Nemetschek North America, Inc  2005.
//	All Rights Reserved.
#pragma once

// The persistent string implementation
// NOTE! TXString is not sutable for persistent memory data
// because it has virtual destructor
class CPersistentString {
public:
						CPersistentString();
						CPersistentString(const TXString& src);
						CPersistentString(const CPersistentString& src);
						// Do not make virtual destructors on the data
						// which is going to be stored in VW's memroy
						~CPersistentString();

	CPersistentString&	operator=(const TXString& src);
	CPersistentString&	operator=(const CPersistentString& src);

						operator TXString() const;

protected:
	bool				AllocateLength(size_t len);

private:
	size_t		fStringLen;
	size_t		fAllocatedSize;
	char*		fpString;
};

// NOTE! TXString is not sutable for persistent memory data
// because it has virtual destructor
typedef std::vector<CPersistentString, std::vwallocator<CPersistentString> >		TVWMemoryStringArray;

// --------------------------------------------------------------------------------------------------------------
// This class is allocated persistent memory for the plug-in
// So it is the same every call
// That's why it is important that all data that it contains to be in the VW memory too
// Note! the TXString itself is persistent
struct SObjectWithWidgetsData {
public:
								SObjectWithWidgetsData();
								// Do not make virtual destructors on the data
								// which is going to be stored in VW's memroy
								~SObjectWithWidgetsData();

	bool						IsPopupListDirty() const;
	void						ClearPopupListDirty();
	const TVWMemoryStringArray&	GetPopupList() const;
	TVWMemoryStringArray&		GetPopupListForEdit();

private:
	bool					fbPopupListDirty;
	// vw memory 'std::array' see 'std::vwallocator'
	TVWMemoryStringArray	farrPopupList;
};

// --------------------------------------------------------------------------------------------------------------
// this class is used to handle object's parameters
class CObjectWithWidgetsObjectData {
public:
							CObjectWithWidgetsObjectData(long userData);
	virtual					~CObjectWithWidgetsObjectData();

	void					InitUserdata(bool bSetup);
	long					GetUserData() const;
	bool					SetObject(MCObjectHandle objHand);
	MCObjectHandle			GetDataObject() const;

	SObjectWithWidgetsData&	GetData();

public:
	TXString				GetText();
	bool					GetUseCustomText();
	void					SetPopupText(const TXString& text);
	TXString				GetPopupText();
	TXString				GetNormalPopupText();

protected:
	void					InitValidFlags();

protected:
	MCObjectHandle			fhObject;
	MCObjectHandle			fhFormat;
	MCObjectHandle			fhRecord;

	SObjectWithWidgetsData*	fpUserData;

	// parameters chached data
	bool					fTextValid;
	TXString				fText;

	bool					fUseCustomTextValid;
	bool					fUseCustomText;

	bool					fPopupTextValid;
	TXString				fPopupText;

	bool					fNormalPopupTextValid;
	TXString				fNormalPopupText;

};
