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 / dcdserve / paper.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-30  |  10.7 KB  |  281 lines

  1. /*+==========================================================================
  2.   File:      PAPER.H
  3.  
  4.   Summary:   Include file for the connectable COPaper COM object class.
  5.  
  6.              COPaper offers a main standard IUnknown interface (basic COM
  7.              object features), an implementation of the standard
  8.              IConnectionPointContainer interface (connectable object
  9.              features), and an implementation of the custom ISharePaper
  10.              interface (shared drawing Paper-related features). This
  11.              multiple interface COM Object Class is achieved via the
  12.              technique of nested classes.  The implementation of the
  13.              IConnectionPointContainer and ISharePaper interfaces are
  14.              nested inside of the COPaper Class.
  15.  
  16.              APPUTIL's CThreaded OwnThis technology is used in COPaper to
  17.              ensure mutually exclusive access by contending multiple
  18.              client threads.
  19.  
  20.              For a comprehensive tutorial code tour of this module's
  21.              contents and offerings see the tutorial DCDSERVE.HTM file.
  22.              For more specific technical details on the internal workings
  23.              see the comments dispersed throughout the module's source code.
  24.  
  25.   Functions: .
  26.  
  27.   Classes:   COPaper.
  28.  
  29.   Origin:    8-23-97: atrent - Editor-inheritance from BALL.H in
  30.              the CONSERVE Tutorial Code Sample. [Revised]
  31.  
  32. ----------------------------------------------------------------------------
  33.   This file is part of the Microsoft COM Tutorial Code Samples.
  34.  
  35.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  36.  
  37.   This source code is intended only as a supplement to Microsoft
  38.   Development Tools and/or on-line documentation.  See these other
  39.   materials for detailed information regarding Microsoft code samples.
  40.  
  41.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  42.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  43.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  44.   PARTICULAR PURPOSE.
  45. ==========================================================================+*/
  46.  
  47. #if !defined(PAPER_H)
  48. #define PAPER_H
  49.  
  50. #ifdef __cplusplus
  51.  
  52.  
  53. // Current format version of Ink Data is 1.0. Thus, the format version
  54. // is a compile-time constant.
  55. #define INKDATA_VERSION10 MAKELONG(0,1)
  56.  
  57. // InkData allocation sizes for the Dynamic InkData array.
  58. enum
  59. {
  60.   INKDATA_ALLOC_INIT = 3200,
  61.   INKDATA_ALLOC = 800
  62. };
  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 paper.
  76. #define PAPER_TITLE_SIZE 64
  77. typedef struct _PAPER_PROPERTIES
  78. {
  79.   LONG lInkDataVersion;
  80.   LONG lInkArraySize;
  81.   COLORREF crWinColor;
  82.   RECT WinRect;
  83.   WCHAR wszTitle[PAPER_TITLE_SIZE];
  84.   WCHAR wszAuthor[PAPER_TITLE_SIZE];
  85.   WCHAR wszReserved1[PAPER_TITLE_SIZE];
  86.   WCHAR wszReserved2[PAPER_TITLE_SIZE];
  87. } PAPER_PROPERTIES;
  88.  
  89.  
  90. // Drawing Paper event constants.
  91. enum PAPER_EVENT
  92. {
  93.   PAPER_EVENT_NONE = 0,
  94.   PAPER_EVENT_LOCKED,
  95.   PAPER_EVENT_UNLOCKED,
  96.   PAPER_EVENT_LOADED,
  97.   PAPER_EVENT_SAVED,
  98.   PAPER_EVENT_INKSTART,
  99.   PAPER_EVENT_INKDRAW,
  100.   PAPER_EVENT_INKSTOP,
  101.   PAPER_EVENT_ERASED,
  102.   PAPER_EVENT_RESIZED
  103. };
  104.  
  105. // Some strings used in file storage.
  106. #define STREAM_PAPERDATA_USTR L"PAPERDATA"
  107. #define CLIPBDFMT_STR "CTS.SharePaper.1"
  108. #define PAP_FILE_EXT ".PAP"
  109.  
  110.  
  111. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  112.   ObjectClass: COPaper
  113.  
  114.   Summary:     COM object class for COPaper COM objects.  COM objects of
  115.                this class offer custom ISharePaper interface features,
  116.                InitPaper, Lock, InkStart, InkDraw, InkStop, GetInk, Erase,
  117.                Resize. To make COPaper objects connectable, the standard
  118.                IConnectionPointContainer interface features,
  119.                FindConnectionPoint and EnumConnectionPoints are also
  120.                implemented. The mulitple interfaces on this COM object are
  121.                constructed via the nested interface classes technique.
  122.                COPaper is also derived from APPUTIL's CThreaded to provide
  123.                the OwnThis thread safety mechanism.
  124.  
  125.   Interfaces:  IUnknown
  126.                  Standard interface providing COM object features.
  127.                IConnectionPointContainer
  128.                  Standard Connection Point container features rendering
  129.                  COPaper objects connectable objects.
  130.                ISharePaper
  131.                  Custom interface providing basic electronic drawing paper
  132.                  features for a shared drawing.
  133.  
  134.   Aggregation: Yes, COPaper COM Objects are aggregatable by passing
  135.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  136. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  137. class COPaper : public IUnknown, public CThreaded
  138. {
  139.   public:
  140.     // Main Object Constructor & Destructor.
  141.     COPaper(IUnknown* pUnkOuter, CServer* pServer);
  142.     ~COPaper(void);
  143.  
  144.     // A general method for initializing this newly created object.
  145.     // Creates any subordinate arrays, structures, or objects.
  146.     HRESULT Init(void);
  147.  
  148.     // IUnknown methods. Main object, non-delegating.
  149.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  150.     STDMETHODIMP_(ULONG) AddRef(void);
  151.     STDMETHODIMP_(ULONG) Release(void);
  152.  
  153.   private:
  154.     // We declare nested class interface implementations here.
  155.  
  156.     class CImpIConnectionPointContainer : public IConnectionPointContainer,
  157.                                           public CThreaded
  158.     {
  159.       public:
  160.         // Interface Implementation Constructor & Destructor.
  161.         CImpIConnectionPointContainer(COPaper* pCO, IUnknown* pUnkOuter);
  162.         ~CImpIConnectionPointContainer(void);
  163.  
  164.         // IUnknown methods.
  165.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  166.         STDMETHODIMP_(ULONG) AddRef(void);
  167.         STDMETHODIMP_(ULONG) Release(void);
  168.  
  169.         // IConnectionPointContainer methods.
  170.         STDMETHODIMP         FindConnectionPoint(REFIID, IConnectionPoint**);
  171.         STDMETHODIMP         EnumConnectionPoints(IEnumConnectionPoints**);
  172.  
  173.       private:
  174.         // Data private to this interface implementation.
  175.         COPaper*      m_pCO;          // Parent Object back pointer.
  176.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  177.     };
  178.  
  179.     class CImpISharePaper : public ISharePaper, public CThreaded
  180.     {
  181.       public:
  182.         // Interface Implementation Constructor & Destructor.
  183.         CImpISharePaper(COPaper* pCO, IUnknown* pUnkOuter);
  184.         ~CImpISharePaper(void);
  185.  
  186.         // IUnknown methods.
  187.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  188.         STDMETHODIMP_(ULONG) AddRef(void);
  189.         STDMETHODIMP_(ULONG) Release(void);
  190.  
  191.         // ISharePaper methods.
  192.         STDMETHODIMP         InitPaper(RECT* pWinRect, BOOL* pbFirst);
  193.         STDMETHODIMP         Lock(BOOL bLock);
  194.         STDMETHODIMP         Load(RECT* pWinRect);
  195.         STDMETHODIMP         Save(void);
  196.         STDMETHODIMP         InkStart(
  197.                                SHORT nX,
  198.                                SHORT nY,
  199.                                SHORT nWidth,
  200.                                COLORREF crInkColor);
  201.         STDMETHODIMP         InkDraw(SHORT nX, SHORT nY);
  202.         STDMETHODIMP         InkStop(SHORT nX, SHORT nY);
  203.         STDMETHODIMP         GetInk(
  204.                                LONG lIndex,
  205.                                SHORT* pnInkType,
  206.                                SHORT* pnX,
  207.                                SHORT* pnY,
  208.                                SHORT* pnInkWidth,
  209.                                COLORREF* pcrInkColor);
  210.         STDMETHODIMP         Erase(void);
  211.         STDMETHODIMP         Resize(
  212.                                LONG lWidth,
  213.                                LONG lHeight);
  214.  
  215.       private:
  216.         // Data private to this interface implementation of ISharePaper.
  217.         COPaper*      m_pCO;          // Parent Object back pointer.
  218.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  219.  
  220.         // The following private data and methods constitute the working
  221.         // heart of COPaper as an actual application object.
  222.         PAPER_PROPERTIES m_PaperProperties; // For file storage.
  223.         UINT          m_ClipBdFmt;    // ClipBoard Format.
  224.         BOOL          m_bLocked;      // Paper lock state.
  225.         RECT          m_WinRect;      // Current Window rectangle.
  226.         COLORREF      m_crWinColor;   // Current window background color.
  227.         COLORREF      m_crInkColor;   // Current ink color.
  228.         SHORT         m_nInkWidth;    // Current ink width.
  229.         LONG          m_lInkDataEnd;  // Current end of the ink data.
  230.         LONG          m_lInkDataMax;  // Current end of the ink data array.
  231.         INKDATA*      m_paInkData;    // Dynamic Ink data array pointer.
  232.  
  233.         // Private utility methods of this interface implementation.
  234.         HRESULT NextSlot(void);
  235.     };
  236.  
  237.     // Make the otherwise private and nested ISharePaper and
  238.     // IConnectionPointContainer interface implementations a friend to
  239.     // COM object instantiations of this COPaper COM object class.
  240.     friend CImpIConnectionPointContainer;
  241.     friend CImpISharePaper;
  242.  
  243.     // Private method of main connectable COPaper COM object to broadcast
  244.     // event notifications to all connected listening sinks.
  245.     HRESULT NotifySinks(
  246.               PAPER_EVENT PaperEvent,
  247.               SHORT nX,
  248.               SHORT nY,
  249.               SHORT nInkWidth,
  250.               COLORREF crInkColor);
  251.  
  252.     // Private data of COPaper COM objects.
  253.  
  254.     // Nested ISharePaper implementation instantiation. This interface
  255.     // is instantiated inside this COPaper object as a native interface.
  256.     CImpISharePaper   m_ImpISharePaper;
  257.  
  258.     // Nested IConnectionPointContainer implementation instantiation.
  259.     CImpIConnectionPointContainer m_ImpIConnectionPointContainer;
  260.  
  261.     // Main Object reference count.
  262.     ULONG             m_cRefs;
  263.  
  264.     // Outer unknown (aggregation & delegation).
  265.     IUnknown*         m_pUnkOuter;
  266.  
  267.     // Pointer to this component server's control object.
  268.     CServer*          m_pServer;
  269.  
  270.     // The file path name for the paper file containing the shared drawing.
  271.     TCHAR             m_szPapFile[MAX_PATH];
  272.  
  273.     // The array of connection points for this connectable COM object.
  274.     IConnectionPoint* m_aConnectionPoints[MAX_CONNECTION_POINTS];
  275. };
  276.  
  277. #endif // __cplusplus
  278.  
  279.  
  280. #endif // PAPER_H
  281.