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

Windows编程

开发平台:

Visual C++

  1. /*
  2.  * TENANT.H
  3.  * Patron Chapter 22
  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. class CImpIOleClientSite : public IOleClientSite
  16.     {
  17.     protected:
  18.         ULONG               m_cRef;
  19.         class CTenant      *m_pTen;
  20.         LPUNKNOWN           m_pUnkOuter;
  21.     public:
  22.         CImpIOleClientSite(class CTenant *, LPUNKNOWN);
  23.         ~CImpIOleClientSite(void);
  24.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  25.         STDMETHODIMP_(ULONG) AddRef(void);
  26.         STDMETHODIMP_(ULONG) Release(void);
  27.         STDMETHODIMP SaveObject(void);
  28.         STDMETHODIMP GetMoniker(DWORD, DWORD, LPMONIKER *);
  29.         STDMETHODIMP GetContainer(LPOLECONTAINER *);
  30.         STDMETHODIMP ShowObject(void);
  31.         STDMETHODIMP OnShowWindow(BOOL);
  32.         STDMETHODIMP RequestNewObjectLayout(void);
  33.     };
  34. typedef CImpIOleClientSite *PCImpIOleClientSite;
  35. class CImpIAdviseSink : public IAdviseSink
  36.     {
  37.     protected:
  38.         ULONG               m_cRef;
  39.         class CTenant      *m_pTen;
  40.         LPUNKNOWN           m_pUnkOuter;
  41.     public:
  42.         CImpIAdviseSink(class CTenant *, LPUNKNOWN);
  43.         ~CImpIAdviseSink(void);
  44.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  45.         STDMETHODIMP_(ULONG) AddRef(void);
  46.         STDMETHODIMP_(ULONG) Release(void);
  47.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  48.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  49.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  50.         STDMETHODIMP_(void)  OnSave(void);
  51.         STDMETHODIMP_(void)  OnClose(void);
  52.     };
  53. typedef CImpIAdviseSink *PCImpIAdviseSink;
  54. //CHAPTER22MOD
  55. class CImpIOleInPlaceSite : public IOleInPlaceSite
  56.     {
  57.     protected:
  58.         ULONG               m_cRef;
  59.         class CTenant      *m_pTen;
  60.         LPUNKNOWN           m_pUnkOuter;
  61.     public:
  62.         CImpIOleInPlaceSite(class CTenant *, LPUNKNOWN);
  63.         ~CImpIOleInPlaceSite(void);
  64.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  65.         STDMETHODIMP_(ULONG) AddRef(void);
  66.         STDMETHODIMP_(ULONG) Release(void);
  67.         STDMETHODIMP GetWindow(HWND *);
  68.         STDMETHODIMP ContextSensitiveHelp(BOOL);
  69.         STDMETHODIMP CanInPlaceActivate(void);
  70.         STDMETHODIMP OnInPlaceActivate(void);
  71.         STDMETHODIMP OnUIActivate(void);
  72.         STDMETHODIMP GetWindowContext(LPOLEINPLACEFRAME *
  73.                         , LPOLEINPLACEUIWINDOW *, LPRECT, LPRECT
  74.                         , LPOLEINPLACEFRAMEINFO);
  75.         STDMETHODIMP Scroll(SIZE);
  76.         STDMETHODIMP OnUIDeactivate(BOOL);
  77.         STDMETHODIMP OnInPlaceDeactivate(void);
  78.         STDMETHODIMP DiscardUndoState(void);
  79.         STDMETHODIMP DeactivateAndUndo(void);
  80.         STDMETHODIMP OnPosRectChange(LPCRECT);
  81.     };
  82. typedef CImpIOleInPlaceSite *PCImpIOleInPlaceSite;
  83. //End CHAPTER22MOD
  84. /*
  85.  * Tenant class describing an individual piece of data in a page.
  86.  * It knows where it sits, what object is inside of it, and what
  87.  * its idenitifer is such that it can find it's storage within a
  88.  * page.
  89.  */
  90. //Patron Objects clipboard format
  91. typedef struct tagPATRONOBJECT
  92.     {
  93.     POINTL      ptl;        //Location of object
  94.     POINTL      ptlPick;    //Pick point from drag-drop operation
  95.     SIZEL       szl;        //Extents of object (absolute)
  96.     FORMATETC   fe;         //Actual object format
  97.     } PATRONOBJECT, *PPATRONOBJECT;
  98. //Values for hit-testing, drawing, and resize-tracking tenants
  99. #define CXYHANDLE       5
  100. //Tenant types (not persistent, but determined at load time)
  101. typedef enum
  102.     {
  103.     TENANTTYPE_NULL=0,
  104.     TENANTTYPE_STATIC,
  105.     TENANTTYPE_EMBEDDEDOBJECT,
  106.     TENANTTYPE_EMBEDDEDFILE,
  107.     TENANTTYPE_EMBEDDEDOBJECTFROMDATA,
  108.     TENANTTYPE_LINKEDOBJECT,
  109.     TENANTTYPE_LINKEDFILE,
  110.     TENANTTYPE_LINKEDOBJECTFROMDATA
  111.     } TENANTTYPE, *PTENANTTYPE;
  112. //State flags
  113. #define TENANTSTATE_DEFAULT      0x00000000
  114. #define TENANTSTATE_SELECTED     0x00000001
  115. #define TENANTSTATE_OPEN         0x00000002
  116. #define TENANTSTATE_SHOWTYPE     0x00000004
  117. /*
  118.  * Persistent information we need to save for each tenant, which is
  119.  * done in the tenant list instead of with each tenant.  Since this
  120.  * is a small structure it's best not to blow another stream for it
  121.  * (overhead).
  122.  */
  123. typedef struct tagTENANTINFO
  124.     {
  125.     DWORD       dwID;
  126.     RECTL       rcl;
  127.     FORMATETC   fe;             //Excludes ptd
  128.     short       fSetExtent;     //Call IOleObject::SetExtent on Run
  129.     } TENANTINFO, *PTENANTINFO;
  130. class CTenant : public IUnknown
  131.     {
  132.     friend CImpIOleClientSite;
  133.     friend CImpIAdviseSink;
  134.     //CHAPTER22MOD
  135.     friend CImpIOleInPlaceSite;
  136.     //End CHAPTER22MOD
  137.     private:
  138.         HWND            m_hWnd;         //Pages window
  139.         DWORD           m_dwID;         //Persistent DWORD ID
  140.         DWORD           m_cOpens;       //Count calls to Open
  141.         BOOL            m_fInitialized; //Something here?
  142.         LPUNKNOWN       m_pObj;         //The object here
  143.         LPSTORAGE       m_pIStorage;    //Sub-storage for tenant
  144.         FORMATETC       m_fe;           //Used to create the object
  145.         DWORD           m_dwState;      //State flags
  146.         RECTL           m_rcl;          //Space of this object
  147.         CLSID           m_clsID;        //Object class (for statics)
  148.         BOOL            m_fSetExtent;   //Call SetExtent on next run
  149.         class CPages   *m_pPG;          //Pages window
  150.         TENANTTYPE      m_tType;            //Type identifier
  151.         ULONG           m_cRef;             //We're an object now
  152.         LPOLEOBJECT     m_pIOleObject;      //IOleObject on m_pObj
  153.         LPVIEWOBJECT2   m_pIViewObject2;    //IViewObject2 on m_pObj
  154.         ULONG           m_grfMisc;          //OLEMISC flags
  155.         BOOL            m_fRepaintEnabled;  //No redundant paints
  156.         //Our interfaces
  157.         PCImpIOleClientSite m_pImpIOleClientSite;
  158.         PCImpIAdviseSink    m_pImpIAdviseSink;
  159.         LPMONIKER       m_pmk;          //Relative moniker
  160.         LPMONIKER       m_pmkFile;      //Container document moniker
  161.         //CHAPTER22MOD
  162.         PCImpIOleInPlaceSite m_pImpIOleIPSite; //Our interface
  163.         LPOLEINPLACEOBJECT   m_pIOleIPObject;  //The object
  164.         RECT                 m_rcPos;          //Last object rect
  165.         BOOL                 m_fInRectSet;     //Prevent reentrancy
  166.         //End CHAPTER22MOD
  167.     /*
  168.      * This flag is used exculsively by the implementation of
  169.      * IOleUILinkContainer on the page we're in for the Links
  170.      * Dialog. Since we never use it ourselves, public here
  171.      * is no big deal.
  172.      */
  173.     public:
  174.         BOOL            m_fLinkAvail;
  175.     protected:
  176.         BOOL    ObjectInitialize(LPUNKNOWN, LPFORMATETC, DWORD);
  177.         HRESULT CreateStatic(LPDATAOBJECT, LPFORMATETC
  178.             , LPUNKNOWN *);
  179.     public:
  180.         CTenant(DWORD, HWND, CPages *);
  181.         ~CTenant(void);
  182.         //Gotta have an IUnknown for delegation
  183.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  184.         STDMETHODIMP_(ULONG) AddRef(void);
  185.         STDMETHODIMP_(ULONG) Release(void);
  186.         DWORD       GetID(void);
  187.         UINT        GetStorageName(LPOLESTR);
  188.         void        StorageGet(LPSTORAGE *);
  189.         UINT        Create(TENANTTYPE, LPVOID, LPFORMATETC, PPOINTL
  190.                         , LPSIZEL, LPSTORAGE, PPATRONOBJECT, DWORD);
  191.         BOOL        Load(LPSTORAGE, PTENANTINFO);
  192.         void        GetInfo(PTENANTINFO);
  193.         BOOL        Open(LPSTORAGE);
  194.         void        Close(BOOL);
  195.         BOOL        Update(void);
  196.         void        Destroy(LPSTORAGE);
  197.         //CHAPTER22MOD
  198.         void        Select(BOOL, BOOL);
  199.         //End CHAPTER22MOD
  200.         void        ShowAsOpen(BOOL);
  201.         void        ShowYourself(void);
  202.         void        AddVerbMenu(HMENU, UINT);
  203.         TENANTTYPE  TypeGet(void);
  204.         void        CopyEmbeddedObject(LPDATAOBJECT, LPFORMATETC
  205.                         , PPOINTL);
  206.         void        ShowObjectType(BOOL);
  207.         void        CopyLinkedObject(LPDATAOBJECT, LPFORMATETC
  208.                         , PPOINTL);
  209.         void        NotifyOfRename(LPTSTR, LPMONIKER, LPMONIKER);
  210.         //CHAPTER22MOD
  211.         BOOL        Activate(LONG, LPMSG);
  212.         //End CHAPTER22MOD
  213.         void        Draw(HDC, DVTARGETDEVICE *, HDC, int, int
  214.                         , BOOL, BOOL);
  215.         void        Repaint(void);
  216.         void        Invalidate(void);
  217.         void        ObjectClassFormatAndIcon(LPCLSID, LPWORD
  218.                         , LPTSTR *, HGLOBAL *, LPTSTR *);
  219.         BOOL        SwitchOrUpdateAspect(HGLOBAL, BOOL);
  220.         void        EnableRepaint(BOOL);
  221.         BOOL        FIsSelected(void);
  222.         BOOL        ConvertToStatic(void);
  223.         void        ObjectGet(LPUNKNOWN *);
  224.         void        FormatEtcGet(LPFORMATETC, BOOL);
  225.         void        SizeGet(LPSIZEL, BOOL);
  226.         void        SizeSet(LPSIZEL, BOOL, BOOL);
  227.         void        RectGet(LPRECTL, BOOL);
  228.         void        RectSet(LPRECTL, BOOL, BOOL);
  229.         //CHAPTER22MOD
  230.         void        DeactivateInPlaceObject(BOOL);
  231.         void        UpdateInPlaceObjectRects(LPCRECT, BOOL);
  232.         HWND        ObjectWindow(void);
  233.         //End CHAPTER22MOD
  234.     };
  235. typedef CTenant *PCTenant;
  236. //Return codes for Create
  237. #define CREATE_FAILED               0
  238. #define CREATE_GRAPHICONLY          1
  239. #define CREATE_PLACEDOBJECT         2
  240. #endif //_TENANT_H_