//
//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#pragma once

using namespace VWFC::Math;

namespace VWFC
{
	namespace PluginSupport
	{
		// ------------------------------------------------------------------------------
		enum EObjectEvent {
				kObjectEventNoErr			= kParametricNoErr,			//= 0;		// 
				kObjectEventSetupFailed		= kParametricSetupFailed,	//= -1;
				kObjectEventError			= kParametricError,			//= -2;
				kObjectEventNotImplemented	= kParametricNotImplemented,//= -3;		// The Plug-in did not present its own preference dialog, it is up to the VW application to do it.
				kObjectEventPrefOK			= kParametricPrefOK,		//= -4;		// The Plug-in presented its own preferences dialog, and the user hit OK.
				kObjectEventPrefCancel		= kParametricPrefCancel,	//= -5;		// The Plug-in presented its own preferences dialog, and the user hit Cancel.
				kObjectEventHadError		= kParametricHadError,		//= -6;		// The Plug-in compiled but had an error during execution.
				kObjectEventHadWarning		= kParametricHadWarning,	//= -7;		// The Plug-in compiled but had a warning during execution.
                kObjectEventStayLoaded      = -12,                       //= -12;    // The Plug-in returns this value on InitializeApp in order to stay loaded indefinitely
				kObjectEventUIButtonOK		= kObjectUIButtonHitOK,
				kObjectEventUIButtonCancel	= kObjectUIButtonHitCancel,
		};

		// ------------------------------------------------------------------------------
		class VWPluginParametricApp
		{
		public:
									VWPluginParametricApp(MCObjectHandle hParametric);
			virtual					~VWPluginParametricApp();


		// Plug-in Object action/events constants 
		public:
			virtual EObjectEvent	InitializeApp();
			virtual EObjectEvent	DeinitializeApp();
			// The Plug-in Object code should re-create all its component objects using current parameter values.
			virtual EObjectEvent	Recalculate();
			// Object Definition Procedure (ODP) may optionally present its own preferences dialog, or let VW pose the default dialog.
			virtual EObjectEvent	Preference();

		public:
			// The Plug-in Object may add extended properties.
			virtual EObjectEvent	OnInitXProperties(CodeRefID objectID);
			// The Plug-in Object called with kParametricOnMove when kHasMoveDependancy extended property set
			virtual EObjectEvent	OnSpecialEditID();
			// The user has pressed a button in the Properties UI of an object
			virtual EObjectEvent	OnObjectUIButtonHit(long buttonID);
			// Update object's shape pane widgets
			virtual bool			OnWidgetUpdate(IWidgetsProvider* pWidgetProvider);
			// Handle widget change
			virtual EObjectEvent	OnAddState(ObjectState& stateInfo);
            // The user has manipulated one of plugin object's control points.
            virtual long            OnCursorEvent(ObjectEventID action, long message);
			// Obtain the tool name that is to be activated for this object
			// when doing 'create similar object' command
			virtual TXString		OnGetToolName() const;
			// Object context menu support
			virtual void			OnContextMenuInit(IContextMenuProvider* pContextMenuProvider);
			virtual void			OnContextMenuEvent(const ObjectContextMenuEvent& eventData);
			// Eyedropper notifies that it is going to put the record 'hObjRecordCopy' as record for the current parametric object
			// In this event the object can alter the copy to ensure correct data transfer (the data has already been copied to the record)
			// NOTE! This object's record is still in place when this event is called
			virtual void			OnEyedropperPrepareCopy(MCObjectHandle hObjRecordCopy);
			// The default event notificaiotn
			// if no virutal is present for an event, this function is called to allow the user to catch everything
			virtual long			OnDefaultEvent(long action, long message);

		public:
			virtual long			GetUserData() const;
			virtual void			SetUserData(long userData);

		protected:
			VWObjects::VWParametricObj	fParametricObj;
		};
	}
}

// ------------------------------------------------------------------------------
// On Windows use 'static' since VW loads every time the plug-in into the memory and unloads it when finished
// On Mac it stays always in the memroy
// And there is the difference ... on Win every time it constructs this object -- we need the same effect on Mac
// and if it is 'static' on mac it will get constructed only once -- fist time called
#define	INSTANTIATE_PARAMETRIC_APP(T)	VWPluginParametricApp* CreateParametricInstance(MCObjectHandle hParametric) { void* pRawMem = malloc( sizeof(T) ); return (T*) new (pRawMem) T( hParametric ); }
