TENANT.H

/* 
* TENANT.H
* Patron Chapter 17
*
* Definitions and function prototypes for the CTenant class
*
* Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
*
* Kraig Brockschmidt, Microsoft
* Internet : kraigb@microsoft.com
* Compuserve: >INTERNET:kraigb@microsoft.com
*/


#ifndef _TENANT_H_
#define _TENANT_H_


//CHAPTER17MOD

class CImpIOleClientSite : public IOleClientSite
{
protected:
ULONG m_cRef;
class CTenant *m_pTen;
LPUNKNOWN m_pUnkOuter;

public:
CImpIOleClientSite(class CTenant *, LPUNKNOWN);
~CImpIOleClientSite(void);

STDMETHODIMP QueryInterface(REFIID, PPVOID);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);

STDMETHODIMP SaveObject(void);
STDMETHODIMP GetMoniker(DWORD, DWORD, LPMONIKER *);
STDMETHODIMP GetContainer(LPOLECONTAINER *);
STDMETHODIMP ShowObject(void);
STDMETHODIMP OnShowWindow(BOOL);
STDMETHODIMP RequestNewObjectLayout(void);
};

typedef CImpIOleClientSite *PCImpIOleClientSite;



class CImpIAdviseSink : public IAdviseSink
{
protected:
ULONG m_cRef;
class CTenant *m_pTen;
LPUNKNOWN m_pUnkOuter;

public:
CImpIAdviseSink(class CTenant *, LPUNKNOWN);
~CImpIAdviseSink(void);

STDMETHODIMP QueryInterface(REFIID, PPVOID);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);

STDMETHODIMP_(void) OnDataChange(LPFORMATETC, LPSTGMEDIUM);
STDMETHODIMP_(void) OnViewChange(DWORD, LONG);
STDMETHODIMP_(void) OnRename(LPMONIKER);
STDMETHODIMP_(void) OnSave(void);
STDMETHODIMP_(void) OnClose(void);
};


typedef CImpIAdviseSink *PCImpIAdviseSink;

//End CHAPTER17MOD


/*
* Tenant class describing an individual piece of data in a page.
* It knows where it sits, what object is inside of it, and what
* its idenitifer is such that it can find it's storage within a
* page.
*/

//Patron Objects clipboard format
typedef struct tagPATRONOBJECT
{
POINTL ptl; //Location of object
POINTL ptlPick; //Pick point from drag-drop operation
SIZEL szl; //Extents of object (absolute)
FORMATETC fe; //Actual object format
} PATRONOBJECT, *PPATRONOBJECT;



//Values for hit-testing, drawing, and resize-tracking tenants
#define CXYHANDLE 5

//Tenant types (not persistent, but determined at load time)
typedef enum
{
TENANTTYPE_NULL=0,
TENANTTYPE_STATIC,
//CHAPTER17MOD
TENANTTYPE_EMBEDDEDOBJECT,
TENANTTYPE_EMBEDDEDFILE,
TENANTTYPE_EMBEDDEDOBJECTFROMDATA
//End CHAPTER17MOD
} TENANTTYPE, *PTENANTTYPE;


//State flags
#define TENANTSTATE_DEFAULT 0x00000000
#define TENANTSTATE_SELECTED 0x00000001

//CHAPTER17MOD
#define TENANTSTATE_OPEN 0x00000002
//End CHAPTER17MOD


/*
* Persistent information we need to save for each tenant, which is
* done in the tenant list instead of with each tenant. Since this
* is a small structure it's best not to blow another stream for it
* (overhead).
*/
typedef struct tagTENANTINFO
{
DWORD dwID;
RECTL rcl;
FORMATETC fe; //Excludes ptd
short fSetExtent; //Call IOleObject::SetExtent on Run
} TENANTINFO, *PTENANTINFO;


class CTenant : public IUnknown
{
//CHAPTER17MOD
friend CImpIOleClientSite;
friend CImpIAdviseSink;
//End CHAPTER17MOD

private:
HWND m_hWnd; //Pages window
DWORD m_dwID; //Persistent DWORD ID
DWORD m_cOpens; //Count calls to Open

BOOL m_fInitialized; //Something here?
LPUNKNOWN m_pObj; //The object here
LPSTORAGE m_pIStorage; //Sub-storage for tenant

FORMATETC m_fe; //Used to create the object
DWORD m_dwState; //State flags
RECTL m_rcl; //Space of this object
CLSID m_clsID; //Object class (for statics)
BOOL m_fSetExtent; //Call SetExtent on next run

class CPages *m_pPG; //Pages window

//CHAPTER17MOD
TENANTTYPE m_tType; //Type identifier
ULONG m_cRef; //We're an object now
LPOLEOBJECT m_pIOleObject; //IOleObject on m_pObj
LPVIEWOBJECT2 m_pIViewObject2; //IViewObject2 on m_pObj
ULONG m_grfMisc; //OLEMISC flags
BOOL m_fRepaintEnabled; //No redundant paints

//Our interfaces
PCImpIOleClientSite m_pImpIOleClientSite;
PCImpIAdviseSink m_pImpIAdviseSink;
//End CHAPTER17MOD

protected:
//CHAPTER17MOD
BOOL ObjectInitialize(LPUNKNOWN, LPFORMATETC, DWORD);
//End CHAPTER17MOD
HRESULT CreateStatic(LPDATAOBJECT, LPFORMATETC
, LPUNKNOWN *);

public:
CTenant(DWORD, HWND, CPages *);
~CTenant(void);

//CHAPTER17MOD
//Gotta have an IUnknown for delegation
STDMETHODIMP QueryInterface(REFIID, PPVOID);
STDMETHODIMP_(ULONG) AddRef(void);
STDMETHODIMP_(ULONG) Release(void);
//End CHAPTER17MOD

DWORD GetID(void);
UINT GetStorageName(LPOLESTR);
//CHAPTER17MOD
void StorageGet(LPSTORAGE *);
//End CHAPTER17MOD
UINT Create(TENANTTYPE, LPVOID, LPFORMATETC, PPOINTL
, LPSIZEL, LPSTORAGE, PPATRONOBJECT, DWORD);
BOOL Load(LPSTORAGE, PTENANTINFO);
void GetInfo(PTENANTINFO);
BOOL Open(LPSTORAGE);
void Close(BOOL);
BOOL Update(void);
void Destroy(LPSTORAGE);

void Select(BOOL);
//CHAPTER17MOD
void ShowAsOpen(BOOL);
void ShowYourself(void);
void AddVerbMenu(HMENU, UINT);
TENANTTYPE TypeGet(void);
void CopyEmbeddedObject(LPDATAOBJECT, LPFORMATETC
, PPOINTL);
void NotifyOfRename(LPTSTR, LPVOID);
//End CHAPTER17MOD

BOOL Activate(LONG);
void Draw(HDC, DVTARGETDEVICE *, HDC, int, int
, BOOL, BOOL);
void Repaint(void);
void Invalidate(void);

//CHAPTER17MOD
void ObjectClassFormatAndIcon(LPCLSID, LPWORD
, LPTSTR *, HGLOBAL *, LPTSTR *);
BOOL SwitchOrUpdateAspect(HGLOBAL, BOOL);
void EnableRepaint(BOOL);
//End CHAPTER17MOD

void ObjectGet(LPUNKNOWN *);
void FormatEtcGet(LPFORMATETC, BOOL);
void SizeGet(LPSIZEL, BOOL);
//CHAPTER17MOD
void SizeSet(LPSIZEL, BOOL, BOOL);
//End CHAPTER17MOD
void RectGet(LPRECTL, BOOL);
//CHAPTER17MOD
void RectSet(LPRECTL, BOOL, BOOL);
//End CHAPTER17MOD
};


typedef CTenant *PCTenant;

//Return codes for Create
#define CREATE_FAILED 0
#define CREATE_GRAPHICONLY 1
#define CREATE_PLACEDOBJECT 2



#endif //_TENANT_H_