TENANT.H
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:8k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * TENANT.H
  3.  * Patron Chapter 17
  4.  *
  5.  * Definitions and function prototypes for the CTenant class
  6.  *
  7.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  8.  *
  9.  * Kraig Brockschmidt, Microsoft
  10.  * Internet  :  kraigb@microsoft.com
  11.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  12.  */
  13. #ifndef _TENANT_H_
  14. #define _TENANT_H_
  15. //CHAPTER17MOD
  16. class CImpIOleClientSite : public IOleClientSite
  17.     {
  18.     protected:
  19.         ULONG               m_cRef;
  20.         class CTenant      *m_pTen;
  21.         LPUNKNOWN           m_pUnkOuter;
  22.     public:
  23.         CImpIOleClientSite(class CTenant *, LPUNKNOWN);
  24.         ~CImpIOleClientSite(void);
  25.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  26.         STDMETHODIMP_(ULONG) AddRef(void);
  27.         STDMETHODIMP_(ULONG) Release(void);
  28.         STDMETHODIMP SaveObject(void);
  29.         STDMETHODIMP GetMoniker(DWORD, DWORD, LPMONIKER *);
  30.         STDMETHODIMP GetContainer(LPOLECONTAINER *);
  31.         STDMETHODIMP ShowObject(void);
  32.         STDMETHODIMP OnShowWindow(BOOL);
  33.         STDMETHODIMP RequestNewObjectLayout(void);
  34.     };
  35. typedef CImpIOleClientSite *PCImpIOleClientSite;
  36. class CImpIAdviseSink : public IAdviseSink
  37.     {
  38.     protected:
  39.         ULONG               m_cRef;
  40.         class CTenant      *m_pTen;
  41.         LPUNKNOWN           m_pUnkOuter;
  42.     public:
  43.         CImpIAdviseSink(class CTenant *, LPUNKNOWN);
  44.         ~CImpIAdviseSink(void);
  45.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  46.         STDMETHODIMP_(ULONG) AddRef(void);
  47.         STDMETHODIMP_(ULONG) Release(void);
  48.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  49.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  50.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  51.         STDMETHODIMP_(void)  OnSave(void);
  52.         STDMETHODIMP_(void)  OnClose(void);
  53.     };
  54. typedef CImpIAdviseSink *PCImpIAdviseSink;
  55. //End CHAPTER17MOD
  56. /*
  57.  * Tenant class describing an individual piece of data in a page.
  58.  * It knows where it sits, what object is inside of it, and what
  59.  * its idenitifer is such that it can find it's storage within a
  60.  * page.
  61.  */
  62. //Patron Objects clipboard format
  63. typedef struct tagPATRONOBJECT
  64.     {
  65.     POINTL      ptl;        //Location of object
  66.     POINTL      ptlPick;    //Pick point from drag-drop operation
  67.     SIZEL       szl;        //Extents of object (absolute)
  68.     FORMATETC   fe;         //Actual object format
  69.     } PATRONOBJECT, *PPATRONOBJECT;
  70. //Values for hit-testing, drawing, and resize-tracking tenants
  71. #define CXYHANDLE       5
  72. //Tenant types (not persistent, but determined at load time)
  73. typedef enum
  74.     {
  75.     TENANTTYPE_NULL=0,
  76.     TENANTTYPE_STATIC,
  77.     //CHAPTER17MOD
  78.     TENANTTYPE_EMBEDDEDOBJECT,
  79.     TENANTTYPE_EMBEDDEDFILE,
  80.     TENANTTYPE_EMBEDDEDOBJECTFROMDATA
  81.     //End CHAPTER17MOD
  82.     } TENANTTYPE, *PTENANTTYPE;
  83. //State flags
  84. #define TENANTSTATE_DEFAULT      0x00000000
  85. #define TENANTSTATE_SELECTED     0x00000001
  86. //CHAPTER17MOD
  87. #define TENANTSTATE_OPEN         0x00000002
  88. //End CHAPTER17MOD
  89. /*
  90.  * Persistent information we need to save for each tenant, which is
  91.  * done in the tenant list instead of with each tenant.  Since this
  92.  * is a small structure it's best not to blow another stream for it
  93.  * (overhead).
  94.  */
  95. typedef struct tagTENANTINFO
  96.     {
  97.     DWORD       dwID;
  98.     RECTL       rcl;
  99.     FORMATETC   fe;             //Excludes ptd
  100.     short       fSetExtent;     //Call IOleObject::SetExtent on Run
  101.     } TENANTINFO, *PTENANTINFO;
  102. class CTenant : public IUnknown
  103.     {
  104.     //CHAPTER17MOD
  105.     friend CImpIOleClientSite;
  106.     friend CImpIAdviseSink;
  107.     //End CHAPTER17MOD
  108.     private:
  109.         HWND            m_hWnd;         //Pages window
  110.         DWORD           m_dwID;         //Persistent DWORD ID
  111.         DWORD           m_cOpens;       //Count calls to Open
  112.         BOOL            m_fInitialized; //Something here?
  113.         LPUNKNOWN       m_pObj;         //The object here
  114.         LPSTORAGE       m_pIStorage;    //Sub-storage for tenant
  115.         FORMATETC       m_fe;           //Used to create the object
  116.         DWORD           m_dwState;      //State flags
  117.         RECTL           m_rcl;          //Space of this object
  118.         CLSID           m_clsID;        //Object class (for statics)
  119.         BOOL            m_fSetExtent;   //Call SetExtent on next run
  120.         class CPages   *m_pPG;          //Pages window
  121.         //CHAPTER17MOD
  122.         TENANTTYPE      m_tType;            //Type identifier
  123.         ULONG           m_cRef;             //We're an object now
  124.         LPOLEOBJECT     m_pIOleObject;      //IOleObject on m_pObj
  125.         LPVIEWOBJECT2   m_pIViewObject2;    //IViewObject2 on m_pObj
  126.         ULONG           m_grfMisc;          //OLEMISC flags
  127.         BOOL            m_fRepaintEnabled;  //No redundant paints
  128.         //Our interfaces
  129.         PCImpIOleClientSite m_pImpIOleClientSite;
  130.         PCImpIAdviseSink    m_pImpIAdviseSink;
  131.         //End CHAPTER17MOD
  132.     protected:
  133.         //CHAPTER17MOD
  134.         BOOL    ObjectInitialize(LPUNKNOWN, LPFORMATETC, DWORD);
  135.         //End CHAPTER17MOD
  136.         HRESULT CreateStatic(LPDATAOBJECT, LPFORMATETC
  137.             , LPUNKNOWN *);
  138.     public:
  139.         CTenant(DWORD, HWND, CPages *);
  140.         ~CTenant(void);
  141.         //CHAPTER17MOD
  142.         //Gotta have an IUnknown for delegation
  143.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  144.         STDMETHODIMP_(ULONG) AddRef(void);
  145.         STDMETHODIMP_(ULONG) Release(void);
  146.         //End CHAPTER17MOD
  147.         DWORD       GetID(void);
  148.         UINT        GetStorageName(LPOLESTR);
  149.         //CHAPTER17MOD
  150.         void        StorageGet(LPSTORAGE *);
  151.         //End CHAPTER17MOD
  152.         UINT        Create(TENANTTYPE, LPVOID, LPFORMATETC, PPOINTL
  153.                         , LPSIZEL, LPSTORAGE, PPATRONOBJECT, DWORD);
  154.         BOOL        Load(LPSTORAGE, PTENANTINFO);
  155.         void        GetInfo(PTENANTINFO);
  156.         BOOL        Open(LPSTORAGE);
  157.         void        Close(BOOL);
  158.         BOOL        Update(void);
  159.         void        Destroy(LPSTORAGE);
  160.         void        Select(BOOL);
  161.         //CHAPTER17MOD
  162.         void        ShowAsOpen(BOOL);
  163.         void        ShowYourself(void);
  164.         void        AddVerbMenu(HMENU, UINT);
  165.         TENANTTYPE  TypeGet(void);
  166.         void        CopyEmbeddedObject(LPDATAOBJECT, LPFORMATETC
  167.                         , PPOINTL);
  168.         void        NotifyOfRename(LPTSTR, LPVOID);
  169.         //End CHAPTER17MOD
  170.         BOOL        Activate(LONG);
  171.         void        Draw(HDC, DVTARGETDEVICE *, HDC, int, int
  172.                         , BOOL, BOOL);
  173.         void        Repaint(void);
  174.         void        Invalidate(void);
  175.         //CHAPTER17MOD
  176.         void        ObjectClassFormatAndIcon(LPCLSID, LPWORD
  177.                         , LPTSTR *, HGLOBAL *, LPTSTR *);
  178.         BOOL        SwitchOrUpdateAspect(HGLOBAL, BOOL);
  179.         void        EnableRepaint(BOOL);
  180.         //End CHAPTER17MOD
  181.         void        ObjectGet(LPUNKNOWN *);
  182.         void        FormatEtcGet(LPFORMATETC, BOOL);
  183.         void        SizeGet(LPSIZEL, BOOL);
  184.         //CHAPTER17MOD
  185.         void        SizeSet(LPSIZEL, BOOL, BOOL);
  186.         //End CHAPTER17MOD
  187.         void        RectGet(LPRECTL, BOOL);
  188.         //CHAPTER17MOD
  189.         void        RectSet(LPRECTL, BOOL, BOOL);
  190.         //End CHAPTER17MOD
  191.     };
  192. typedef CTenant *PCTenant;
  193. //Return codes for Create
  194. #define CREATE_FAILED               0
  195. #define CREATE_GRAPHICONLY          1
  196. #define CREATE_PLACEDOBJECT         2
  197. #endif //_TENANT_H_