home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / tutsamp / perdraw / drawpage.h < prev    next >
C/C++ Source or Header  |  1997-08-05  |  12KB  |  303 lines

  1. /*+==========================================================================
  2.   File:      DRAWPAGE.H
  3.  
  4.   Summary:   Include file for the connectable CODrawPage COM object class.
  5.  
  6.              CODrawPage offers an implementation of a main standard
  7.              IUnknown interface (basic COM object features), an
  8.              implementation of the standard IConnectionPointContainer
  9.              interface (connectable object features), an implementation of
  10.              the standard IPersistStorage interface (storage-based
  11.              persistent object features), and an implementation of the
  12.              custom IDrawPage interface (free-form drawing page features).
  13.  
  14.              For a comprehensive tutorial code tour of this module's
  15.              contents and offerings see the tutorial PERDRAW.HTM file.
  16.              For more specific technical details on the internal workings
  17.              see the comments dispersed throughout the module's source code.
  18.  
  19.   Functions: .
  20.  
  21.   Classes:   CODrawPage.
  22.  
  23.   Origin:    5-20-97: atrent - Editor-inheritance from PAPER.H in
  24.              the STOSERVE Tutorial Code Sample.
  25.  
  26. ----------------------------------------------------------------------------
  27.   This file is part of the Microsoft COM Tutorial Code Samples.
  28.  
  29.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  30.  
  31.   This source code is intended only as a supplement to Microsoft
  32.   Development Tools and/or on-line documentation.  See these other
  33.   materials for detailed information regarding Microsoft code samples.
  34.  
  35.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  36.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  37.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  38.   PARTICULAR PURPOSE.
  39. ==========================================================================+*/
  40.  
  41. #if !defined(DRAWPAGE_H)
  42. #define DRAWPAGE_H
  43.  
  44. #ifdef __cplusplus
  45.  
  46.  
  47. // Current format version of Ink Data is 1.0. Thus, the format version
  48. // is a compile-time constant.
  49. #define INKDATA_VERSION20 MAKELONG(0,2)
  50.  
  51. // InkData allocation sizes for the Dynamic InkData array.
  52. enum
  53. {
  54.   INKDATA_ALLOC_INIT = 3200,
  55.   INKDATA_ALLOC = 800
  56. };
  57.  
  58. // The types of Ink Data.
  59. #define INKTYPE_NONE  0
  60. #define INKTYPE_START 1
  61. #define INKTYPE_DRAW  2
  62. #define INKTYPE_STOP  3
  63.  
  64. // The Ink Data structure.
  65. typedef struct _INKDATA
  66. {
  67.   SHORT nType;            // Ink Type.
  68.   SHORT nX;               // X-coordinate of ink point.
  69.   SHORT nY;               // Y-coordinate of ink point.
  70.   SHORT nWidth;           // Ink line width.
  71.   COLORREF crColor;       // Ink color.
  72. } INKDATA;
  73.  
  74.  
  75. // Properties of our electronic DrawPage.
  76. typedef struct _DRAWPROPS
  77. {
  78.   LONG lInkDataVersion;
  79.   LONG lInkArraySize;
  80.   COLORREF crWinColor;
  81.   RECT WinRect;
  82.   WCHAR wszTitle[PAGE_TITLE_SIZE];
  83.   WCHAR wszAuthor[PAGE_TITLE_SIZE];
  84.   WCHAR wszReserved1[PAGE_TITLE_SIZE];
  85. } DRAWPROPS;
  86.  
  87.  
  88. // Drawing DrawPage event constants.
  89. enum DRAWPAGE_EVENT
  90. {
  91.   DRAWPAGE_EVENT_NONE = 0,
  92.   DRAWPAGE_EVENT_LOADED,
  93.   DRAWPAGE_EVENT_SAVED,
  94.   DRAWPAGE_EVENT_INKSTART,
  95.   DRAWPAGE_EVENT_INKDRAW,
  96.   DRAWPAGE_EVENT_INKSTOP,
  97.   DRAWPAGE_EVENT_CLEARED,
  98.   DRAWPAGE_EVENT_RESIZED
  99. };
  100.  
  101. // Some strings used in compound file storage.
  102.  
  103. // Name of the stream containing the DrawPage properties.
  104. #define WSZ_DRAWPROPS L"DRAWPROPS"
  105.  
  106. // Name of the stream containing the DrawPage ink data.
  107. #define WSZ_DRAWDATA L"DRAWDATA"
  108.  
  109. // User type name for DrawPages.
  110. #define SZ_CLIPUSERTYPE "DrawPage1.0 Drawing"
  111.  
  112.  
  113. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  114.   ObjectClass: CODrawPage
  115.  
  116.   Summary:     CODrawPage COM objects expose functionality to support
  117.                drawing pages. This multiple interface COM Object Class is
  118.                achieved via the technique of nested classes.  The
  119.                implementation of the various interfaces are nested inside
  120.                of the CODrawPage Class.
  121.  
  122.   Interfaces:  IUnknown
  123.                  Standard interface providing COM object features.
  124.                IConnectionPointContainer
  125.                  Standard Connection Point container features rendering
  126.                  CODrawPage objects connectable objects.
  127.                IPersistStorage
  128.                  Standard interface providing features for object
  129.                  persistence in compound file storages. Renders
  130.                  CODrawPage objects persistent objects.
  131.                IDrawPage
  132.                  Custom interface providing free-form drawing
  133.                  page features.
  134.  
  135.   Aggregation: Yes, CODrawPage COM Objects are aggregatable by passing
  136.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  137. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  138. class CODrawPage : public IUnknown
  139. {
  140.   public:
  141.     // Main Object Constructor & Destructor.
  142.     CODrawPage(IUnknown* pUnkOuter, CServer* pServer);
  143.     ~CODrawPage(void);
  144.  
  145.     // A general public method for initializing this newly created
  146.     // object. Creates any subordinate arrays, structures, or objects.
  147.     // Not exposed as part of an interface. Used in Class Factory.
  148.     HRESULT Init(void);
  149.  
  150.     // IUnknown methods. Main object, non-delegating.
  151.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  152.     STDMETHODIMP_(ULONG) AddRef(void);
  153.     STDMETHODIMP_(ULONG) Release(void);
  154.  
  155.   private:
  156.     // We declare nested class interface implementations here.
  157.  
  158.     class CImpIConnectionPointContainer : public IConnectionPointContainer
  159.     {
  160.       public:
  161.         // Interface Implementation Constructor & Destructor.
  162.         CImpIConnectionPointContainer(CODrawPage* pCO, IUnknown* pUnkOuter);
  163.         ~CImpIConnectionPointContainer(void);
  164.  
  165.         // IUnknown methods.
  166.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  167.         STDMETHODIMP_(ULONG) AddRef(void);
  168.         STDMETHODIMP_(ULONG) Release(void);
  169.  
  170.         // IConnectionPointContainer methods.
  171.         STDMETHODIMP         FindConnectionPoint(REFIID, IConnectionPoint**);
  172.         STDMETHODIMP         EnumConnectionPoints(IEnumConnectionPoints**);
  173.  
  174.       private:
  175.         // Data private to this interface implementation.
  176.         CODrawPage*   m_pCO;          // Parent COM Object back pointer.
  177.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  178.     };
  179.  
  180.     class CImpIPersistStorage : public IPersistStorage
  181.     {
  182.       public:
  183.         // Interface Implementation Constructor & Destructor.
  184.         CImpIPersistStorage(CODrawPage* pCO, IUnknown* pUnkOuter);
  185.         ~CImpIPersistStorage(void);
  186.  
  187.         // IUnknown methods.
  188.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  189.         STDMETHODIMP_(ULONG) AddRef(void);
  190.         STDMETHODIMP_(ULONG) Release(void);
  191.  
  192.         // IPersistStorage methods.
  193.         STDMETHODIMP         GetClassID(CLSID* pClassID);
  194.         STDMETHODIMP         IsDirty(void);
  195.         STDMETHODIMP         InitNew(IStorage* pIStorage);
  196.         STDMETHODIMP         Load(IStorage* pIStorage);
  197.         STDMETHODIMP         Save(IStorage* pIStorage, BOOL bSameAsLoad);
  198.         STDMETHODIMP         SaveCompleted(IStorage* pIStorage);
  199.         STDMETHODIMP         HandsOffStorage(void);
  200.  
  201.       private:
  202.         // Data private to this interface implementation.
  203.         CODrawPage*   m_pCO;            // Parent COM Object back pointer.
  204.         IUnknown*     m_pUnkOuter;      // Outer unknown for Delegation.
  205.         IStorage*     m_pIStorage;      // Main DrawPage storage.
  206.         IStream*      m_pIStream_Props; // Stream for Drawing Properties.
  207.         IStream*      m_pIStream_Data;  // Stream for Drawing Ink Data.
  208.     };
  209.  
  210.     class CImpIDrawPage : public IDrawPage
  211.     {
  212.       public:
  213.         // Interface Implementation Constructor & Destructor.
  214.         CImpIDrawPage(CODrawPage* pCO, IUnknown* pUnkOuter);
  215.         ~CImpIDrawPage(void);
  216.  
  217.         // IUnknown methods.
  218.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  219.         STDMETHODIMP_(ULONG) AddRef(void);
  220.         STDMETHODIMP_(ULONG) Release(void);
  221.  
  222.         // IDrawPage methods.
  223.         STDMETHODIMP         InkStart(
  224.                                SHORT nX,
  225.                                SHORT nY,
  226.                                SHORT nWidth,
  227.                                COLORREF crInkColor);
  228.         STDMETHODIMP         InkDraw(SHORT nX, SHORT nY);
  229.         STDMETHODIMP         InkStop(SHORT nX, SHORT nY);
  230.         STDMETHODIMP         Clear(BOOL bSaveNeeded);
  231.         STDMETHODIMP         Resize(SHORT nWidth, SHORT nHeight);
  232.         STDMETHODIMP         Redraw(void);
  233.  
  234.       private:
  235.         // Private utility methods of this interface implementation.
  236.         HRESULT NextSlot(void);
  237.  
  238.         // Data private to this interface implementation of IDrawPage.
  239.         CODrawPage*   m_pCO;          // Parent COM Object back pointer.
  240.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  241.     };
  242.  
  243.     // Make the otherwise private and nested interface implementations
  244.     // friends to COM object instantiations of this CODrawPage
  245.     // COM object class.
  246.     friend CImpIConnectionPointContainer;
  247.     friend CImpIPersistStorage;
  248.     friend CImpIDrawPage;
  249.  
  250.     // Private Methods of CODrawPage COM objects.
  251.  
  252.     // Private method of main connectable CODrawPage COM object to
  253.     // broadcast event notifications to all connected listening sinks.
  254.     HRESULT NotifySinks(
  255.               DRAWPAGE_EVENT DrawPageEvent,
  256.               SHORT nX,
  257.               SHORT nY,
  258.               SHORT nInkWidth,
  259.               COLORREF crInkColor);
  260.  
  261.     // Private data of CODrawPage COM objects.
  262.  
  263.     // Nested IConnectionPointContainer implementation instantiation.
  264.     CImpIConnectionPointContainer m_ImpIConnectionPointContainer;
  265.  
  266.     // Nested IPersistStorage implementation instantiation.
  267.     CImpIPersistStorage m_ImpIPersistStorage;
  268.  
  269.     // Nested IDrawPage implementation instantiation. Custom interface.
  270.     CImpIDrawPage     m_ImpIDrawPage;
  271.  
  272.     // Main Object reference count.
  273.     ULONG             m_cRefs;
  274.  
  275.     // Outer unknown (aggregation & delegation).
  276.     IUnknown*         m_pUnkOuter;
  277.  
  278.     // Pointer to this component server's control object.
  279.     CServer*          m_pServer;
  280.  
  281.     // The array of connection points for this connectable COM object.
  282.     IConnectionPoint* m_aConnectionPoints[MAX_CONNECTION_POINTS];
  283.  
  284.     // The following private data is the working heart of DrawPage objects.
  285.     RECT              m_WinRect;        // Current window rectangle.
  286.     COLORREF          m_crWinColor;     // Current window background color.
  287.     COLORREF          m_crInkColor;     // Current ink color.
  288.     SHORT             m_nInkWidth;      // Current ink width.
  289.     LONG              m_lInkDataEnd;    // Current end of the ink data.
  290.     LONG              m_lInkDataMax;    // Current max end of the ink data.
  291.     INKDATA*          m_paInkData;      // Dynamic Ink data array pointer.
  292.     DRAWPROPS         m_DrawProps;      // Drawing Page properties.
  293.     CLSID             m_ClassID;        // CLSID of this COM Object.
  294.     UINT              m_ClipFmt;        // ClipBoard format.
  295.     PERSTGSTATE       m_StgState;       // Persistent Storage State.
  296.     BOOL              m_bDirty;         // RAM no match file--save needed.
  297. };
  298.  
  299. #endif // __cplusplus
  300.  
  301.  
  302. #endif // DRAWPAGE_H
  303.