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 / pertext / textpage.h < prev   
C/C++ Source or Header  |  1997-08-05  |  10KB  |  255 lines

  1. /*+==========================================================================
  2.   File:      TEXTPAGE.H
  3.  
  4.   Summary:   Include file for the connectable COTextPage COM object class.
  5.  
  6.              COTextPage offers a main standard IUnknown interface (basic
  7.              COM object features), an implementation of the standard
  8.              IConnectionPointContainer interface (connectable object
  9.              features), an implementation of the standard
  10.              IPersistStreamInit interface (stream persistent object
  11.              features), and an implementation of the custom ITextPage
  12.              interface (editable TextPage features). This multiple
  13.              interface COM Object Class is achieved via the technique of
  14.              nested classes.  The implementation of the various interfaces
  15.              are nested inside of the COTextPage Class.
  16.  
  17.              For a comprehensive tutorial code tour of this module's
  18.              contents and offerings see the tutorial PERTEXT.HTM file.
  19.              For more specific technical details on the internal workings
  20.              see the comments dispersed throughout the module's source code.
  21.  
  22.   Functions: .
  23.  
  24.   Classes:   COTextPage.
  25.  
  26.   Origin:    5-20-97: atrent - Editor-inheritance from PAPER.H in
  27.              the STOSERVE Tutorial Code Sample.
  28.  
  29. ----------------------------------------------------------------------------
  30.   This file is part of the Microsoft COM Tutorial Code Samples.
  31.  
  32.   Copyright (C) Microsoft Corporation, 1997.  All rights reserved.
  33.  
  34.   This source code is intended only as a supplement to Microsoft
  35.   Development Tools and/or on-line documentation.  See these other
  36.   materials for detailed information regarding Microsoft code samples.
  37.  
  38.   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  39.   KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  40.   IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  41.   PARTICULAR PURPOSE.
  42. ==========================================================================+*/
  43.  
  44. #if !defined(TEXTPAGE_H)
  45. #define TEXTPAGE_H
  46.  
  47. #ifdef __cplusplus
  48.  
  49.  
  50. // Current format version of TextPage is 1.0. Thus, the format version
  51. // is a compile-time constant.
  52. #define TEXTPAGE_VERSION10 MAKELONG(0,1)
  53.  
  54. // TextPage allocation sizes for the TextPage.
  55. enum
  56. {
  57.   TEXTPAGE_V10_MAX = 32000
  58. };
  59.  
  60. // Properties of the TextPage.
  61. typedef struct _TEXTPROPS
  62. {
  63.   ULONG ulVersion;
  64.   ULONG ulMaxLength;
  65.   ULONG ulLength;
  66.   WCHAR wszTitle[PAGE_TITLE_SIZE];
  67. } TEXTPROPS;
  68.  
  69.  
  70. // TextPage event constants.
  71. enum TEXTPAGE_EVENT
  72. {
  73.   TEXTPAGE_EVENT_NONE = 0,
  74.   TEXTPAGE_EVENT_LOADED,
  75.   TEXTPAGE_EVENT_SAVED,
  76.   TEXTPAGE_EVENT_PUT,
  77.   TEXTPAGE_EVENT_CLEARED
  78. };
  79.  
  80.  
  81. /*O+O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O+++O
  82.   ObjectClass: COTextPage
  83.  
  84.   Summary:     COM object class for COTextPage COM objects.  COM objects
  85.                of this class offer custom ITextPage interface features,
  86.                GetLength, GetText, PutText, and Clear. To make COTextPage
  87.                objects connectable, the standard IConnectionPointContainer
  88.                interface features, FindConnectionPoint and
  89.                EnumConnectionPoints are also implemented. The mulitple
  90.                interfaces on this COM object are constructed via the
  91.                nested interface classes technique.
  92.  
  93.   Interfaces:  IUnknown
  94.                  Standard interface providing COM object features.
  95.                IConnectionPointContainer
  96.                  Standard Connection Point container features rendering
  97.                  COTextPage objects connectable objects.
  98.                IPersistStreamInit
  99.                  Standard Stream Persistance features rendering
  100.                  COTextPage objects persistent objects.
  101.                ITextPage
  102.                  Custom interface providing basic TextPage features.
  103.  
  104.   Aggregation: Yes, COTextPage COM Objects are aggregatable by passing
  105.                a non-NULL pUnkOuter IUnknown pointer into the constructor.
  106. O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O---O-O*/
  107. class COTextPage : public IUnknown
  108. {
  109.   public:
  110.     // Main COM Object Constructor & Destructor.
  111.     COTextPage(IUnknown* pUnkOuter, CServer* pServer);
  112.     ~COTextPage(void);
  113.  
  114.     // A general public method for initializing this newly created
  115.     // object. Creates any subordinate arrays, structures, or objects.
  116.     // Not exposed as part of an interface. Used by Class Factory.
  117.     HRESULT Init(void);
  118.  
  119.     // Main COM Object IUnknown interface. Non-delegating.
  120.     STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  121.     STDMETHODIMP_(ULONG) AddRef(void);
  122.     STDMETHODIMP_(ULONG) Release(void);
  123.  
  124.   private:
  125.     // We declare nested class interface implementations here.
  126.  
  127.     // Standard Connectable Object features.
  128.     class CImpIConnectionPointContainer : public IConnectionPointContainer
  129.     {
  130.       public:
  131.         // Interface Implementation Constructor & Destructor.
  132.         CImpIConnectionPointContainer(COTextPage* pCO, IUnknown* pUnkOuter);
  133.         ~CImpIConnectionPointContainer(void);
  134.  
  135.         // IUnknown methods.
  136.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  137.         STDMETHODIMP_(ULONG) AddRef(void);
  138.         STDMETHODIMP_(ULONG) Release(void);
  139.  
  140.         // IConnectionPointContainer methods.
  141.         STDMETHODIMP         FindConnectionPoint(REFIID, IConnectionPoint**);
  142.         STDMETHODIMP         EnumConnectionPoints(IEnumConnectionPoints**);
  143.  
  144.       private:
  145.         // Data private to this interface implementation.
  146.         COTextPage*   m_pCO;          // Parent Object back pointer.
  147.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  148.     };
  149.  
  150.     // Standard Object Persistence (in Streams) features.
  151.     class CImpIPersistStreamInit : public IPersistStreamInit
  152.     {
  153.       public:
  154.         // Interface Implementation Constructor & Destructor.
  155.         CImpIPersistStreamInit(COTextPage* pCO, IUnknown* pUnkOuter);
  156.         ~CImpIPersistStreamInit(void);
  157.  
  158.         // IUnknown methods.
  159.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  160.         STDMETHODIMP_(ULONG) AddRef(void);
  161.         STDMETHODIMP_(ULONG) Release(void);
  162.  
  163.         // IPersistStreamInit methods.
  164.         STDMETHODIMP         GetClassID(CLSID* pClassID);
  165.         STDMETHODIMP         IsDirty(void);
  166.         STDMETHODIMP         Load(IStream* pIStream);
  167.         STDMETHODIMP         Save(IStream* pIStream, BOOL bClearDirty);
  168.         STDMETHODIMP         GetSizeMax(ULARGE_INTEGER* pcbSize);
  169.         STDMETHODIMP         InitNew(void);
  170.  
  171.       private:
  172.         // Data private to this interface implementation.
  173.         COTextPage*   m_pCO;          // Parent Object back pointer.
  174.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  175.     };
  176.  
  177.     // Custom Text Entry/Edit page features.
  178.     class CImpITextPage : public ITextPage
  179.     {
  180.       public:
  181.         // Interface Implementation Constructor & Destructor.
  182.         CImpITextPage(COTextPage* pCO, IUnknown* pUnkOuter);
  183.         ~CImpITextPage(void);
  184.  
  185.         // IUnknown methods.
  186.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  187.         STDMETHODIMP_(ULONG) AddRef(void);
  188.         STDMETHODIMP_(ULONG) Release(void);
  189.  
  190.         // ITextPage methods.
  191.         STDMETHODIMP         GetLength(INT* piLength);
  192.         STDMETHODIMP         GetText(WCHAR* pwszText);
  193.         STDMETHODIMP         PutText(WCHAR* pwszText, INT iLength);
  194.         STDMETHODIMP         Clear(BOOL bSaveNeeded);
  195.  
  196.       private:
  197.         // Data private to this interface implementation of ITextPage.
  198.         COTextPage*   m_pCO;          // Parent Object back pointer.
  199.         IUnknown*     m_pUnkOuter;    // Outer unknown for Delegation.
  200.     };
  201.  
  202.     // Make the otherwise private and nested interface implementations
  203.     // friends to instantiations of this COTextPage COM object class.
  204.     friend CImpIConnectionPointContainer;
  205.     friend CImpIPersistStreamInit;
  206.     friend CImpITextPage;
  207.  
  208.     // Private Methods of COTextPage COM objects.
  209.  
  210.     // Method to clear the COTextPage's current page text and reset
  211.     // the page properties appropriately.
  212.     HRESULT Clear(BOOL bSaveNeeded);
  213.  
  214.     // Method of main connectable COTextPage COM object to broadcast
  215.     // event notifications to all connected listening sinks.
  216.     HRESULT NotifySinks(TEXTPAGE_EVENT TextPageEvent);
  217.  
  218.     // Private Data of COTextPage COM objects.
  219.  
  220.     // Nested IConnectionPointContainer implementation instantiation.
  221.     CImpIConnectionPointContainer m_ImpIConnectionPointContainer;
  222.  
  223.     // Nested IPersistStreamInit implementation instantiation.
  224.     CImpIPersistStreamInit m_ImpIPersistStreamInit;
  225.  
  226.     // Nested ITextPage implementation instantiation. This ITextPage
  227.     // interface is instantiated as a native interface of COTextPage.
  228.     CImpITextPage     m_ImpITextPage;
  229.  
  230.     // Main Object reference count.
  231.     ULONG             m_cRefs;
  232.  
  233.     // Outer unknown (aggregation & delegation).
  234.     IUnknown*         m_pUnkOuter;
  235.  
  236.     // Pointer to this component server's control object.
  237.     CServer*          m_pServer;
  238.  
  239.     // The array of connection points for this connectable COM object.
  240.     IConnectionPoint* m_aConnectionPoints[MAX_CONNECTION_POINTS];
  241.  
  242.     // The following private data and methods constitute the working
  243.     // heart of COTextPage as an actual application object.
  244.     TEXTPROPS         m_TextProps;    // For saving properties in stream.
  245.     CLSID             m_ClassID;      // CLSID of this COM Object.
  246.     WCHAR*            m_pwszPageText; // The text to edit.
  247.     BOOL              m_bInitNew;     // TRUE=>obj newly initialized in RAM.
  248.     BOOL              m_bDirty;       // RAM no match file--save needed.
  249. };
  250.  
  251. #endif // __cplusplus
  252.  
  253.  
  254. #endif // TEXTPAGE_H
  255.