home *** CD-ROM | disk | FTP | other *** search
/ PC Press 1997 July / Sezamfile97_2.iso / windows / program / activex / axtsamp.exe / TSBRANCH.EXE / STOSERVE / PAPER.H < prev    next >
C/C++ Source or Header  |  1996-12-29  |  11KB  |  284 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 IPaper
  10.              interface (drawing Paper-related features). This multiple
  11.              interface COM Object Class is achieved via the technique of
  12.              nested classes.  The implementation of the
  13.              IConnectionPointContainer and IPaper interfaces are nested
  14.              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 STOSERVE.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:    6-10-96: atrent - Editor-inheritance from BALL.H in
  30.              the CONSERVE Tutorial Code Sample.
  31.  
  32. ----------------------------------------------------------------------------
  33.   This file is part of the Microsoft ActiveX 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 types of Ink Data.
  65. #define INKTYPE_NONE  0
  66. #define INKTYPE_START 1
  67. #define INKTYPE_DRAW  2
  68. #define INKTYPE_STOP  3
  69.  
  70. // The Ink Data structure.
  71. typedef struct _INKDATA
  72. {
  73.   SHORT nType;            // Ink Type.
  74.   SHORT nX;               // X-coordinate of ink point.
  75.   SHORT nY;               // Y-coordinate of ink point.
  76.   SHORT nWidth;           // Ink line width.
  77.   COLORREF crColor;       // Ink color.
  78. } INKDATA;
  79.  
  80.  
  81. // Properties of our electronic paper.
  82. #define PAPER_TITLE_SIZE 64
  83. typedef struct _PAPER_PROPERTIES
  84. {
  85.   LONG lInkDataVersion;
  86.   LONG lInkArraySize;
  87.   COLORREF crWinColor;
  88.   RECT WinRect;
  89.   WCHAR wszTitle[PAPER_TITLE_SIZE];
  90.   WCHAR wszAuthor[PAPER_TITLE_SIZE];
  91.   WCHAR wszReserved1[PAPER_TITLE_SIZE];
  92.   WCHAR wszReserved2[PAPER_TITLE_SIZE];
  93. } PAPER_PROPERTIES;
  94.  
  95.  
  96. // Drawing Paper event constants.
  97. enum PAPER_EVENT
  98. {
  99.   PAPER_EVENT_NONE = 0,
  100.   PAPER_EVENT_LOCKED,
  101.   PAPER_EVENT_UNLOCKED,
  102.   PAPER_EVENT_LOADED,
  103.   PAPER_EVENT_SAVED,
  104.   PAPER_EVENT_INKSTART,
  105.   PAPER_EVENT_INKDRAW,
  106.   PAPER_EVENT_INKSTOP,
  107.   PAPER_EVENT_ERASED,
  108.   PAPER_EVENT_RESIZED
  109. };
  110.  
  111. // Some strings used in file storage.
  112. #define STREAM_PAPERDATA_USTR L"PAPERDATA"
  113. #define CLIPBDFMT_STR "DllPaper1.0"
  114.  
  115.  
  116. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  117.   ObjectClass: COPaper
  118.  
  119.   Summary:     COM object class for COPaper COM objects.  COM objects of
  120.                this class offer custom IPaper interface features,
  121.                InitPaper, Lock, Unlock, Load, Save, InkStart, InkDraw,
  122.                InkStop, Erase, Resize, and Redraw. To make COPaper objects
  123.                connectable, the standard IConnectionPointContainer
  124.                interface features, FindConnectionPoint and
  125.                EnumConnectionPoints are also implemented. The mulitple
  126.                interfaces on this COM object are constructed via the
  127.                nested interface classes technique. COPaper is also derived
  128.                from APPUTIL's CThreaded to provide the OwnThis thread
  129.                safety mechanism.
  130.  
  131.   Interfaces:  IUnknown
  132.                  Standard interface providing COM object features.
  133.                IConnectionPointContainer
  134.                  Standard Connection Point container features rendering
  135.                  COPaper objects connectable objects.
  136.                IPaper
  137.                  Custom interface providing basic electronic drawing paper
  138.                  features.
  139.  
  140.   Aggregation: Yes, COPaper COM Objects are aggregatable by passing
  141.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  142. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  143. class COPaper : public IUnknown, public CThreaded
  144. {
  145.   public:
  146.     // Main Object Constructor & Destructor.
  147.     COPaper(IUnknown* pUnkOuter, CServer* pServer);
  148.     ~COPaper(void);
  149.  
  150.     // A general method for initializing this newly created object.
  151.     // Creates any subordinate arrays, structures, or objects.
  152.     HRESULT Init(void);
  153.  
  154.     // IUnknown methods. Main object, non-delegating.
  155.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  156.     STDMETHODIMP_(ULONG) AddRef(void);
  157.     STDMETHODIMP_(ULONG) Release(void);
  158.  
  159.   private:
  160.     // We declare nested class interface implementations here.
  161.  
  162.     class CImpIConnectionPointContainer : public IConnectionPointContainer,
  163.                                           public CThreaded
  164.     {
  165.       public:
  166.         // Interface Implementation Constructor & Destructor.
  167.         CImpIConnectionPointContainer(COPaper* pBackObj, IUnknown* pUnkOuter);
  168.         ~CImpIConnectionPointContainer(void);
  169.  
  170.         // IUnknown methods.
  171.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  172.         STDMETHODIMP_(ULONG) AddRef(void);
  173.         STDMETHODIMP_(ULONG) Release(void);
  174.  
  175.         // IConnectionPointContainer methods.
  176.         STDMETHODIMP         FindConnectionPoint(REFIID, IConnectionPoint**);
  177.         STDMETHODIMP         EnumConnectionPoints(IEnumConnectionPoints**);
  178.  
  179.       private:
  180.         // Data private to this interface implementation.
  181.         COPaper*      m_pBackObj;     // Parent Object back pointer.
  182.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  183.     };
  184.  
  185.     class CImpIPaper : public IPaper, public CThreaded
  186.     {
  187.       public:
  188.         // Interface Implementation Constructor & Destructor.
  189.         CImpIPaper(COPaper* pBackObj, IUnknown* pUnkOuter);
  190.         ~CImpIPaper(void);
  191.  
  192.         // IUnknown methods.
  193.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  194.         STDMETHODIMP_(ULONG) AddRef(void);
  195.         STDMETHODIMP_(ULONG) Release(void);
  196.  
  197.         // IPaper methods.
  198.         STDMETHODIMP         InitPaper(RECT* pWinRect, BOOL* pbFirst);
  199.         STDMETHODIMP         Lock(SHORT* pnLockKey);
  200.         STDMETHODIMP         Unlock(SHORT nLockKey);
  201.         STDMETHODIMP         Load(SHORT nLockKey, IStorage* pIStorage);
  202.         STDMETHODIMP         Save(SHORT nLockKey, IStorage* pIStorage);
  203.         STDMETHODIMP         InkStart(
  204.                                SHORT nLockKey,
  205.                                SHORT nX,
  206.                                SHORT nY,
  207.                                SHORT nWidth,
  208.                                COLORREF crInkColor);
  209.         STDMETHODIMP         InkDraw(SHORT nLockKey, SHORT nX, SHORT nY);
  210.         STDMETHODIMP         InkStop(SHORT nLockKey, SHORT nX, SHORT nY);
  211.         STDMETHODIMP         Erase(SHORT nLockKey);
  212.         STDMETHODIMP         Resize(
  213.                                SHORT nLockKey,
  214.                                SHORT nWidth,
  215.                                SHORT nHeight);
  216.         STDMETHODIMP         Redraw(SHORT nLockKey);
  217.  
  218.       private:
  219.         // Data private to this interface implementation of IPaper.
  220.         COPaper*      m_pBackObj;     // Parent Object back pointer.
  221.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  222.  
  223.         // The following private data and methods constitute the working
  224.         // heart of COPaper as an actual application object.
  225.         PAPER_PROPERTIES m_PaperProperties; // For file storage.
  226.         UINT          m_ClipBdFmt;    // ClipBoard Format.
  227.         BOOL          m_bLocked;      // Paper lock state.
  228.         SHORT         m_cLockKey;     // Paper lock key counter.
  229.         RECT          m_WinRect;      // Current Window rectangle.
  230.         COLORREF      m_crWinColor;   // Current window background color.
  231.         COLORREF      m_crInkColor;   // Current ink color.
  232.         SHORT         m_nInkWidth;    // Current ink width.
  233.         LONG          m_lInkDataEnd;  // Current end of the ink data.
  234.         LONG          m_lInkDataMax;  // Current end of the ink data array.
  235.         INKDATA*      m_paInkData;    // Dynamic Ink data array pointer.
  236.  
  237.         // Private utility methods of this interface implementation.
  238.         HRESULT NextSlot(void);
  239.     };
  240.  
  241.     // Make the otherwise private and nested IPaper and
  242.     // IConnectionPointContainer interface implementations a friend to
  243.     // COM object instantiations of this COPaper COM object class.
  244.     friend CImpIConnectionPointContainer;
  245.     friend CImpIPaper;
  246.  
  247.     // Private method of main connectable COPaper COM object to broadcast
  248.     // event notifications to all connected listening sinks.
  249.     HRESULT NotifySinks(
  250.               PAPER_EVENT PaperEvent,
  251.               SHORT nX,
  252.               SHORT nY,
  253.               SHORT nInkWidth,
  254.               COLORREF crInkColor);
  255.  
  256.     // Private data of COPaper COM objects.
  257.  
  258.     // Nested IPaper implementation instantiation.  This IPaper interface
  259.     // is instantiated inside this COPaper object as a native interface.
  260.     CImpIPaper        m_ImpIPaper;
  261.  
  262.     // Nested IConnectionPointContainer implementation instantiation.
  263.     CImpIConnectionPointContainer m_ImpIConnectionPointContainer;
  264.  
  265.     // Main Object reference count.
  266.     ULONG             m_cRefs;
  267.  
  268.     // Outer unknown (aggregation & delegation).
  269.     IUnknown*         m_pUnkOuter;
  270.  
  271.     // Pointer to this component server's control object.
  272.     CServer*          m_pServer;
  273.  
  274.     // The array of connection points for this connectable COM object.
  275.     IConnectionPoint* m_aConnectionPoints[MAX_CONNECTION_POINTS];
  276. };
  277.  
  278. typedef COPaper* PCOPaper;
  279.  
  280. #endif // __cplusplus
  281.  
  282.  
  283. #endif // PAPER_H
  284.