// Webplgin.h
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

// Header for the MWebPlugIn class & MWebUIPlugIn class
//
//=============================================================================
// An interface class for the API of a web plug in object. An instance of a
// web plug in object is responsible for controlling a retangular area of
// the displayed document.
// It receives all data contained in that area through the append methods.
// It must either handle the rendering of that token itself, or create a child
// plugin which deals with it. The area of screen given to a child to
// control is a section of its parent's. The object declares that it has finished 
// tokens in its area by returning EFalse from AppendToken. This is the signal to
// its parent container that it should start processing tokens again.
// MWebUIPlugIn is the interface of a UI plug in.
//=============================================================================
//=============================================================================

#ifndef __WEBPLGIN__H_
#define __WEBPLGIN__H_

#if !defined(__WEBEVHDL_H__)
#include "webevhdl.h"
#endif
#if !defined(__WEBDHAN_H__)
#include "webdhan.h"
#endif
#if !defined(__WEBACTOB_H__)
#include "webactob.h"
#endif

class CBase;
class CPicture;
class CWtlToken;
class MWebDataHandler;
class MWebPlugInContext;
class CGraphicsContext;
class TPoint;
class TRect;
class MGraphicsDeviceMap;
class TWebPageUpdate;

const TInt KDisplayWidthNotDefined=-1;		//Flag used instead of a display width to indicate that a width is not defined
const TInt KDisplayHeightNotDefined=-1;		//Flag used instead of a display height to indicate that a height is not defined

class MWebPlugIn: public MWebEventHandler, public MWebDataHandler
	{
public:

	//Enums
	enum TLayoutProperty
		{
		ELayoutHorizontal,
		ELayoutVertical,
		ELayoutFlowBefore,
		ELayoutFlowAfter
		};
	enum TLayoutHorizontal
		{
		ELayoutAlignLeft,
		ELayoutAlignRight,
		ELayoutAlignCentre
		};
	enum TLayoutVertical
		{
		ELayoutAlignNone,
		ELayoutAlignTop,
		ELayoutAlignMiddle,
		ELayoutAlignBottom,
		ELayoutAlignBaseline
		};
	enum TLayoutFlow
		{
		ELayoutParaBreak,
		ELayoutNoParaBreak
		};
	enum TFormatChange
		{
		EFormatNeitherChanged,
		EFormatWidthChanged,
		EFormatHeightChanged,
		EFormatBothChanged,
		EFormatDataAdded
		};
	enum TPlugInAction
		{
		EPlugInStartLoading,			//Signal a plugin to start loading content (eg in an image)
		EObjectDimensionsPending,	//Signal an object of unknown size has arrived (eg an image with no size in the html)
		EObjectDimensionsKnown,		//An object now knows its dimensions (eg an image has begun loading & therefore knows its size)	
		EObjectsFormatted				//Signal that a point in the plugin tree has formatted itself & therefore the counts of pending sizes should be reduced
		};

	//Return the frame ID of the frame to which this object belongs
	virtual TInt FrameID() = 0;

	// Return a pointer to the web engine model
	virtual CWebModel*  WebModel() = 0;

	// Call to inform plug in that the page is closing
	virtual void ClosePlugIn() = 0;              

	//Return pointers to C classes which are needed to 'de-abstract' this class for deletion & cleanupstack
	virtual CBase*    CBasePtr() = 0;
	virtual CPicture* CPicturePtr() = 0;

	// The generic method of sending updates (e.g new data and tokens) to plug-in
	virtual TBool OnUpdateL(TWebPageUpdate* aUpdate) = 0;

	// Append a token to the object. Return EFalse if the token has been rejected.  Used by TAG handlers
	virtual TBool AppendTokenL(CWtlToken* aToken) = 0;

	// Append data to the object. Return EFalse if the data has been rejected.  Used by MIME handlers.  Handler is required to copy the data.
	virtual TBool AppendDataL(const TDesC8& aData) = 0;

	// The Draw method
	virtual void Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,MGraphicsDeviceMap* aMap) const=0;

	// Layout components for the screen - just like in draw - but do not render
	virtual void LayoutL(const TPoint& aTopLeft, MGraphicsDeviceMap* aMap) = 0;

	// Format following a change to the container width or zoom state.
	virtual void FormatL() = 0;
	// Optimised version for faster re-formatting
	virtual void ReformatL() = 0;

	// Return a layout property of this plugin - eg alignment
	virtual TInt LayoutProperty (TLayoutProperty aLayoutProperty) = 0;

	// Return a pointer to the object's container
	virtual MWebPlugIn* Container() const = 0;

	// Return a pointer to an MWebDataHandler if this object is one, or NULL if it is not.
	virtual const MWebDataHandler* DataHandler() const = 0;

	// Get the plug in at a particular point - or the closest to it if NearestObject == ETrue
	virtual MWebPlugIn* EmbeddedObjectAt(TPoint aCoords, TBool NearestObject) = 0;

	// Supply an array of pointers to any embedded objects.
	virtual TBool GetEmbeddedObjectArray(TArray<MWebPlugIn*>& aArray) const = 0;

	// Used to set end points of a selection
	virtual void SetSelectAnchorL(const TPoint& aPoint) = 0;
	virtual void SetSelectCursorL(const TPoint& aPoint) = 0;

	// Return the object's current drawing dimensions in pixels.
	// Device map is essential for print preview
	virtual TInt DisplayWidthInPixels ( MGraphicsDeviceMap* aMap )  = 0;
	virtual TInt DisplayHeightInPixels( MGraphicsDeviceMap* aMap )  = 0;
	
	// Return the object's minimum dimensions in pixels.
	virtual TInt MinWidthInPixels ( MGraphicsDeviceMap* aMap )  = 0;
	virtual TInt MinHeightInPixels( MGraphicsDeviceMap* aMap )  = 0;

	// Return the object's desired dimensions in pixels (used in table formatting etc)
	virtual TInt DesiredWidthInPixels ( MGraphicsDeviceMap* aMap, TInt aMaxWidthInPixels)  = 0;
	virtual TInt DesiredHeightInPixels( MGraphicsDeviceMap* aMap, TInt aMaxHeightInPixels) = 0;

	// Set the object's dimensions (used in table formatting etc)
	virtual void SetWidthInPixels (TInt aWidthInPixels)  = 0;
	virtual void SetHeightInPixels(TInt aHeightInPixels) = 0;

	// Handle a change to embedded objects' size or other attributes that requires reformatting.
	virtual void OnFormatChangeL(MWebPlugIn* aChangedObject, TFormatChange aChangeType) = 0;

	// Return true if embedded objects are to be reloaded, not got from the cache.
	virtual TBool Reloading() const = 0;

	//Handle plug in context
	virtual MWebPlugInContext* Context() const = 0;
	virtual void SetContext(MWebPlugInContext* aContext) = 0;
	
	// Some generic methods for future expansion
	virtual TAny* ResourceItem(TInt aItem)                   = 0;
	virtual TBool SetResourceItemL(TInt aItem, TAny* aValue) = 0;
	virtual TAny* DoActionL(TInt aCode, TAny* aParam1, TAny* aParam2) = 0;

	// Reserved functions
	virtual void MWebPlugIn_Reserved1()=0;
	virtual void MWebPlugIn_Reserved2()=0;
	virtual void MWebPlugIn_Reserved3()=0;
	virtual void MWebPlugIn_Reserved4()=0;
	virtual void MWebPlugIn_Reserved5()=0;

};


//The UI plugIn interface definition
class MWebUIPlugIn
	{
public:
	
	// Launch the dialog which allows the user to interact with the plugin
	virtual void LaunchSettingsDialogL() = 0;
	
	// Return a CBase pointer for deletion & cleanup
	virtual CBase* CBaseUIPtr() = 0;

	// Reserved functions
	virtual void MWebUIPlugIn_Reserved1()=0;
	virtual void MWebUIPlugIn_Reserved2()=0;
	virtual void MWebUIPlugIn_Reserved3()=0;
	virtual void MWebUIPlugIn_Reserved4()=0;
	virtual void MWebUIPlugIn_Reserved5()=0;
	};


//Class which stores contextual information about a point in the page.  Each PI has one,
//and it is an M class so as to be independent of MarkUp language.
class MWebPlugInContext
	{
public:
	enum TContextPropertyType
		{
		EContextPropertyUnknown = 0,
		EContextPropertyColor,
		};
	
	enum TContextPropertyColor
		{
		EForegroundColor,
		EBackgroundColor,
		ETextColor,
		};

	enum TSizeProperty
		{
		ERelativeFontSize,
		};

	virtual CBase* CBaseContextPtr() = 0;

	virtual TRgb PropertyColor(TContextPropertyColor aProperty) = 0;
	virtual TInt PropertySize(TSizeProperty aProperty) = 0;
	virtual CFont* FontSpec() = 0;

	virtual TAny* PropertyValue(TContextPropertyType aPropertyType, TInt aProperty) = 0;
	};

#endif __WEBPLGIN__H_
