// WEBOBJ.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

// Header for the CWebObject class
//
//=============================================================================
// Plug In version of the base Web Object - A object which controls and renders
// a rectangular screen area.
//=============================================================================
//=============================================================================

#ifndef __WEBWOBJ_H__
#define __WEBWOBJ_H__

#define KDefaultEmbeddedObjectColour KRgbDarkGray
#define KEmbeddedObjectGranularity 5
#define KObjectVerticalGap 3

#if !defined(__WEBPLGIN_H__)
#include "webplgin.h"	// for the basic plug in API
#endif

#if !defined(__WEBPI_H__)
#include "webpi.h"	// for factory 
#endif

typedef CArrayPtrSeg<MWebPlugIn> CWebPlugInArray;

class CWebModel;
class TWebPageUpdate;


class TWebBitSet
	{
public:
	IMPORT_C TWebBitSet();
	// aField range is 0..31
	IMPORT_C TBool Bit(TInt aField);
	IMPORT_C void SetBit(TInt aField, TBool aValue);
private:
	TUint32 iBits;
	};


class CWebObject: public CPicture, public MWebPlugIn
	{
public:
	IMPORT_C CWebObject();   // Must only be used by registry when it creates a dummy instance
	
	IMPORT_C CWebObject(TInt aFrameID, MWebPlugIn* aContainer, TPlugInAllParams* aRegistryInfo, CWebModel* aWebModel);
	
	IMPORT_C virtual void ClosePlugIn();

	IMPORT_C virtual ~CWebObject();

	IMPORT_C CBase*    CBasePtr();
    IMPORT_C CPicture* CPicturePtr();

	IMPORT_C CWebModel* WebModel();

	IMPORT_C virtual void  GetImageInfo(TObjectInfo& aInfo) const;
	IMPORT_C virtual TBool ExpandL();
	IMPORT_C virtual TBool ExpandEmbeddedL();

	// virtual functions from CPicture
	IMPORT_C virtual void GetOriginalSizeInTwips(TSize& aSize) const;
	IMPORT_C virtual void ExternalizeL(RWriteStream& aStream) const;

	IMPORT_C virtual void Draw(CGraphicsContext& aGc,const TPoint& aTopLeft,const TRect& aClipRect,MGraphicsDeviceMap* aMap) const;

	// functions from MWebPlugIn

	// Return a pointer to the object's container
	IMPORT_C MWebPlugIn* Container() const;

	IMPORT_C virtual TInt FrameID();

	// Append a token or data to the object. Return EFalse when the token has been rejected
	// The Generic method of sending updates (e.g new data and tokens) to plug-in
	IMPORT_C virtual TBool OnUpdateL(TWebPageUpdate* aUpdate);
	IMPORT_C virtual TBool AppendTokenL(CWtlToken*   aToken);
	IMPORT_C virtual TBool AppendDataL(const TDesC8& aData);

	IMPORT_C virtual void LayoutL(const TPoint& aTopLeft, MGraphicsDeviceMap* aMap);
	
	// Format if necessary following a change to the container width or zoom state.
	IMPORT_C virtual void ReformatL();

	// Handle a change to embedded objects' size or other attributes that requires reformatting.
	IMPORT_C virtual void OnFormatChangeL(MWebPlugIn* aChangedObject, TFormatChange aChangeType);

	// Get the plug in at a particular point - or the closest to it if NearestObject == ETrue
	IMPORT_C virtual MWebPlugIn* EmbeddedObjectAt(TPoint aCoords, TBool aNearestObject);
	
	// Supply an array of pointers to any embedded objects.
	IMPORT_C virtual TBool GetEmbeddedObjectArray(TArray<MWebPlugIn*>& aArray) const;

	// Return a layout property of this plugin eg alignment
	IMPORT_C virtual TInt LayoutProperty (TLayoutProperty aLayoutProperty);

	// Return the object's normal dimensions in pixels.
	IMPORT_C virtual TInt DisplayWidthInPixels( MGraphicsDeviceMap* aMap )   ;
	IMPORT_C virtual TInt DisplayHeightInPixels( MGraphicsDeviceMap* aMap )  ;

	// Return the object's minimum dimensions in pixels.
	IMPORT_C virtual TInt MinWidthInPixels( MGraphicsDeviceMap* aMap )  ;
	IMPORT_C virtual TInt MinHeightInPixels( MGraphicsDeviceMap* aMap ) ;

	// Return the object's desired dimensions in pixels (used in table formatting etc)
	IMPORT_C virtual TInt DesiredWidthInPixels( MGraphicsDeviceMap* aMap,  TInt aMaxWidthInPixels) ;
	IMPORT_C virtual TInt DesiredHeightInPixels(MGraphicsDeviceMap* aMap,  TInt aMaxHeightInPixels) ;

	// Set the object's dimensions (used in table formatting etc)
	IMPORT_C virtual void SetWidthInPixels(TInt aWidthInPixels) ;
	IMPORT_C virtual void SetHeightInPixels(TInt aHeightInPixels) ;

	// Return true if embedded objects are to be reloaded, not got from the cache.
	IMPORT_C virtual TBool Reloading() const;
	
	//Handle plug in context
	IMPORT_C virtual MWebPlugInContext* Context() const;
	IMPORT_C virtual void SetContext(MWebPlugInContext* aContext);

	IMPORT_C void DrawL(const TRect* aRect=NULL);

	IMPORT_C virtual void SetSelectAnchorL(const TPoint& aPoint);
	IMPORT_C virtual void SetSelectCursorL(const TPoint& aPoint);

	IMPORT_C virtual TBool HandleRawPointerEventL(const TPointerEvent& aEvent,TPoint aObjectPos);
	IMPORT_C virtual void  HandlePointerEventL(const TEventInput& aInput,TEventOutput& aOutput,TBool aRedraw);
	IMPORT_C virtual void  HandleEventL(const TEventInput& aInput,TEventOutput& aOutput,TBool aRedraw);

	IMPORT_C virtual CWtlDocument* Document() const;

	// Routines to instruct or query the active object.
	IMPORT_C virtual void  StartGettingDataL();
	IMPORT_C virtual void  StopGettingData();
	IMPORT_C virtual TBool GettingData() const;

	// Return true if the document is ready (EReady has been received)
	IMPORT_C virtual TBool IsReady() const;

	IMPORT_C virtual void OnReadyL   (MWebDataHandler* Source, MWebDataHandler* aTarget);
	IMPORT_C virtual void OnSizeL    (MWebDataHandler* Source, MWebDataHandler* aTarget);
	IMPORT_C virtual void OnTypeL    (MWebDataHandler* Source, MWebDataHandler* aTarget);
	IMPORT_C virtual void OnNewDataL (MWebDataHandler* Source, MWebDataHandler* aTarget);
	IMPORT_C virtual void OnCompleteL(MWebDataHandler* Source, MWebDataHandler* aTarget);
	IMPORT_C virtual void OnErrorL   (MWebDataHandler* Source, MWebDataHandler* aTarget, TInt aCode);
	IMPORT_C virtual void OnStatusL  (MWebDataHandler* Source, MWebDataHandler* aTarget, MWebModelObserver::TWebModelObserverStatus aStatus);
																		// called when the connection status has changed
	IMPORT_C virtual void OnMimeTypeL    (MWebDataHandler* aSource, MWebDataHandler* aTarget) ;
	IMPORT_C virtual void OnUnparsedTokensL    (MWebDataHandler* aSource, MWebDataHandler* aTarget) ;
	IMPORT_C virtual void OnNeedsCredentialsL    (MWebDataHandler* aSource, MWebDataHandler* aTarget) ;
	IMPORT_C virtual void OnResourceMovedL    (MWebDataHandler* aSource, MWebDataHandler* aTarget) ;
	IMPORT_C virtual void OnAuthenticationSuccessL(MWebDataHandler* Source, MWebDataHandler* aTarget);
	IMPORT_C virtual void OnAuthenticationFailureL(MWebDataHandler* Source, MWebDataHandler* aTarget);

	IMPORT_C virtual TAny* ResourceItem(TInt aItem);
	IMPORT_C virtual TBool SetResourceItemL(TInt aItem, TAny* aValue);
	IMPORT_C virtual TAny* DoActionL(TInt aCode, TAny* aParam1, TAny* aParam2);
	

	IMPORT_C void SendObserverMessageL( CWebModel* aWebModel,
										TInt       aMessageSubType,
										MWebModelObserver::TWebModelObserverSource aSource,
										MWebModelObserver::TWebModelObserverLevel  aLevel,
										const      TDesC& aURL,
										const      TDesC& aDescriptor,
										TDataType* aMimeType,
										TAny*      aData);


	IMPORT_C void SendObserverErrorL (  CWebModel* aWebModel,
										TInt       aMessageSubType,
										MWebModelObserver::TWebModelObserverSource aSource,
										MWebModelObserver::TWebModelObserverLevel  aLevel,
										const      TDesC& aURL,
										const      TDesC& aDescriptor,
										TDataType* aMimeType,
										TAny*      aData);

	//Reserved functions
	IMPORT_C virtual void MWebPlugIn_Reserved1();
	IMPORT_C virtual void MWebPlugIn_Reserved2();
	IMPORT_C virtual void MWebPlugIn_Reserved3();
	IMPORT_C virtual void MWebPlugIn_Reserved4();
	IMPORT_C virtual void MWebPlugIn_Reserved5();

protected:
	IMPORT_C void DrawRectangle (CGraphicsContext& aGc, TRect aRect, CGraphicsContext::TPenStyle aStyle);
	IMPORT_C TBool GetTagPlugInIDL(TInt& aID, CWebModel* aWebModel, const TDesC& aTarget);
	IMPORT_C TBool GetMimePlugInIDL(TInt& aID, CWebModel* aWebModel, const TDesC8& aTarget, const TDesC& aURL);
	IMPORT_C TBool GetPlugInInstanceL(MWebPlugIn*& aNewPlugIn, CWebModel* aWebModel, TInt aPIID, MWebPlugInFactory::TWebPlugInFactoryError& aErrorCode);
	IMPORT_C TFormatChange FormatChangeType(TSize aOld,TSize aNew);

	TInt iFrameID;		                  // The frame ID that the object belongs to
	TPlugInAllParams iRegistryInfo;       // All the registry information about this plugin
	CWebModel* iWebModel;                 // The model
	MWebPlugIn*        iContainer;        // the container
	TSize              iSizeInTwips;      // size in twips
	TInt	           iDisplayWidthInPixels;
	TInt               iDisplayHeightInPixels;
	MWebPlugInContext* iContext;
	TBool			iWidthChanged;		//Flags that the width of the object has been changed and therefore the next format should take this into account
	
	//Optimisation of formatting
	TInt iObjectsOfUnknownSize;		//Total number of unsized objects in the tree under this plugin
	TInt iObjectsOfKnownSizeNeedingFormat;		//Total number of newly changed size objects asking for a format under this plugin

protected:
	__DECLARE_LOG;

	};
#endif //__WEBWOBJ_H__
