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


// --------------------------------------------------------------------------------------------------------------
// Note! This class should be persistent because it is designed to be used inside userdata
class CStatesManager {
public:
				CStatesManager();
	// Do not make virtual destructors on the data
	// which is going to be stored in VW's memroy
				~CStatesManager();

public:
	void		ClearStatesToMonitor();
	void		AddStateToMonitor(ObjectState::EStateType type);

	void		ClearStates();
	void		ClearStates(MCObjectHandle hObject);
	void		AddState(MCObjectHandle hObject, ObjectState* pState);

	bool		PopState(MCObjectHandle hObject, ObjectState::EStateType type);
	bool		PopState(MCObjectHandle hObject, ObjectStateData_Position& outData, bool isMove);
	bool		PopState(MCObjectHandle hObject, ObjectStateData_ParamChanged& outData);
	bool		PopState(MCObjectHandle hObject, ObjectStateData_ObjectChanged& outData);
	bool		PopState(MCObjectHandle hObject, ObjectStateData_LayerChanged& outData);
	bool		PopState(MCObjectHandle hObject, ObjectStateData_ExitFromEditGroup& outData);
	bool		PopState(MCObjectHandle hObject, ObjectStateData_ObjectNameChanged& outData);

private:
	struct SStateValue{
		ObjectState::EStateType				type;
		ObjectStateData_Position			pos;
		ObjectStateData_ParamChanged		param;
		ObjectStateData_ObjectChanged		objChanged;
		ObjectStateData_LayerChanged		layerChanged;
		ObjectStateData_ExitFromEditGroup	editGroup;
		ObjectStateData_ObjectNameChanged	objNameChanged;
	};
	typedef std::multimap<MCObjectHandle, SStateValue, std::less<MCObjectHandle> , std::vwallocator< std::pair<const MCObjectHandle, SStateValue> > >		TVWMemoryValuesMap;

	TVWMemoryValuesMap::iterator	FindState(MCObjectHandle hObject, ObjectState::EStateType type);

private:
	typedef std::map<ObjectState::EStateType, bool, std::less<ObjectState::EStateType> , std::vwallocator< std::pair<const ObjectState::EStateType, bool> > >		TVWMemoryStateRegistryMap;

	TVWMemoryStateRegistryMap		fmapStateRegistry;
	TVWMemoryValuesMap				fmapValues;
};

// --------------------------------------------------------------------------------------------------------------
// 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 SObjectEventingData {
public:
	SObjectEventingData();
	// Do not make virtual destructors on the data
	// which is going to be stored in VW's memroy
	~SObjectEventingData();

	CStatesManager&		GetStateManager();

private:
	CStatesManager		fStateManager;
};

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

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

	SObjectEventingData&	GetData();

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

protected:
	void					InitValidFlags();

protected:
	MCObjectHandle			fhObject;
	MCObjectHandle			fhFormat;
	MCObjectHandle			fhRecord;

	SObjectEventingData*	fpUserData;

	// parameters chached data
	bool					fTextValid;
	TXString				fText;

	bool					fUseCustomTextValid;
	bool					fUseCustomText;

	bool					fPopupTextValid;
	TXString				fPopupText;

};
