home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / com / inole2 / chap13 / cocosmo / cocosmo.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  8.3 KB  |  304 lines

  1. /*
  2.  * COCOSMO.H
  3.  * Component Cosmo Chapter 13
  4.  *
  5.  * Single include file that pulls in everything needed for other
  6.  * source files in the Cosmo application.
  7.  *
  8.  * Copyright (c)1993-1995 Microsoft Corporation, All Rights Reserved
  9.  *
  10.  * Kraig Brockschmidt, Microsoft
  11.  * Internet  :  kraigb@microsoft.com
  12.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  13.  */
  14.  
  15.  
  16. #ifndef _COCOSMO_H_
  17. #define _COCOSMO_H_
  18.  
  19. #define INC_CLASSLIB
  20. #define INC_CONTROLS
  21. #define INC_OLE2
  22. //CHAPTER13MOD
  23. #define CHAPTER13
  24. //CHAPTER13MOD
  25. #include <inole.h>
  26. #include <ipoly10.h>
  27. #include "resource.h"
  28.  
  29. //COCOSMO.CPP:  Frame object that creates a main window
  30.  
  31. class CCosmoFrame : public CFrame
  32.     {
  33.     private:
  34.         HBITMAP         m_hBmpLines[5];     //Menu item bitmaps
  35.         UINT            m_uIDCurLine;       //Current line selection
  36.         BOOL            m_fInitialized;     //OleInitialize work?
  37.  
  38.     protected:
  39.         //Overridable for creating a CClient for this frame
  40.         virtual PCClient  CreateCClient(void);
  41.  
  42.         virtual BOOL      RegisterAllClasses(void);
  43.         virtual BOOL      PreShowInit(void);
  44.         virtual UINT      CreateToolbar(void);
  45.  
  46.         virtual LRESULT   OnCommand(HWND, WPARAM, LPARAM);
  47.         virtual void      OnDocumentDataChange(PCDocument);
  48.         virtual void      OnDocumentActivate(PCDocument);
  49.  
  50.         //New for this class
  51.         virtual void      CreateLineMenu(void);
  52.  
  53.     public:
  54.         CCosmoFrame(HINSTANCE, HINSTANCE, LPSTR, int);
  55.         virtual ~CCosmoFrame(void);
  56.  
  57.         //Overrides
  58.         virtual BOOL      Init(PFRAMEINIT);
  59.         virtual void      UpdateMenus(HMENU, UINT);
  60.         virtual void      UpdateToolbar(void);
  61.  
  62.         //New for this class
  63.         virtual void      CheckLineSelection(UINT);
  64.     };
  65.  
  66.  
  67. typedef CCosmoFrame *PCCosmoFrame;
  68.  
  69.  
  70.  
  71.  
  72.  
  73. //CLIENT.CPP
  74.  
  75. /*
  76.  * The only reason we have a derived class here is to override
  77.  * CreateCDocument so we can create our own type as well as
  78.  * overriding NewDocument to perform one other piece of work once
  79.  * the document's been created.
  80.  */
  81.  
  82. class CCosmoClient : public CClient
  83.     {
  84.     protected:
  85.         //Overridable for creating a new CDocument
  86.         virtual PCDocument CreateCDocument(void);
  87.  
  88.     public:
  89.         CCosmoClient(HINSTANCE, PCFrame);
  90.         virtual ~CCosmoClient(void);
  91.  
  92.         virtual PCDocument NewDocument(BOOL);
  93.     };
  94.  
  95.  
  96. typedef CCosmoClient *PCCosmoClient;
  97.  
  98.  
  99.  
  100.  
  101. //DOCUMENT.CPP
  102.  
  103. class CCosmoDoc;
  104. typedef CCosmoDoc *PCCosmoDoc;
  105.  
  106. class CPolylineAdviseSink : public IPolylineAdviseSink10
  107.     {
  108.     private:
  109.         PCCosmoDoc  m_pDoc;         //Backpointer to document
  110.         ULONG       m_cRef;
  111.  
  112.     public:
  113.         CPolylineAdviseSink(PCCosmoDoc);
  114.         ~CPolylineAdviseSink(void);
  115.  
  116.         //IUnknown members
  117.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  118.         STDMETHODIMP_(ULONG) AddRef(void);
  119.         STDMETHODIMP_(ULONG) Release(void);
  120.  
  121.         //Advise members.
  122.         STDMETHODIMP_(void) OnPointChange(void);
  123.         STDMETHODIMP_(void) OnSizeChange(void);
  124.         STDMETHODIMP_(void) OnColorChange(void);
  125.         STDMETHODIMP_(void) OnLineStyleChange(void);
  126.     };
  127.  
  128. typedef CPolylineAdviseSink *PCPolylineAdviseSink;
  129.  
  130.  
  131. /*
  132.  * The generic advisory interface.  This object controls it's own
  133.  * lifetime and the document becomes a user of the object with
  134.  * the last reference count.
  135.  */
  136.  
  137. class CImpIAdviseSink : public IAdviseSink
  138.     {
  139.     protected:
  140.         ULONG               m_cRef;
  141.         LPVOID              m_pObj;
  142.         LPUNKNOWN           m_pUnkOuter;
  143.  
  144.     public:
  145.         CImpIAdviseSink(LPVOID, LPUNKNOWN);
  146.         ~CImpIAdviseSink(void);
  147.  
  148.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  149.         STDMETHODIMP_(ULONG) AddRef(void);
  150.         STDMETHODIMP_(ULONG) Release(void);
  151.  
  152.         STDMETHODIMP_(void)  OnDataChange(LPFORMATETC, LPSTGMEDIUM);
  153.         STDMETHODIMP_(void)  OnViewChange(DWORD, LONG);
  154.         STDMETHODIMP_(void)  OnRename(LPMONIKER);
  155.         STDMETHODIMP_(void)  OnSave(void);
  156.         STDMETHODIMP_(void)  OnClose(void);
  157.     };
  158.  
  159. typedef CImpIAdviseSink *PCImpIAdviseSink;
  160.  
  161.  
  162. //CHAPTER13MOD
  163. //Drag-drop interfaces we need in the document
  164.  
  165. class CDropTarget : public IDropTarget
  166.     {
  167.     protected:
  168.         ULONG                m_cRef;
  169.         class CCosmoDoc     *m_pDoc;
  170.  
  171.         LPDATAOBJECT         m_pIDataObject;
  172.  
  173.     public:
  174.         CDropTarget(class CCosmoDoc *);
  175.         ~CDropTarget(void);
  176.  
  177.         //IDropTarget interface members
  178.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  179.         STDMETHODIMP_(ULONG) AddRef(void);
  180.         STDMETHODIMP_(ULONG) Release(void);
  181.  
  182.         STDMETHODIMP DragEnter(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  183.         STDMETHODIMP DragOver(DWORD, POINTL, LPDWORD);
  184.         STDMETHODIMP DragLeave(void);
  185.         STDMETHODIMP Drop(LPDATAOBJECT, DWORD, POINTL, LPDWORD);
  186.     };
  187.  
  188. typedef CDropTarget * PCDropTarget;
  189.  
  190.  
  191. class CDropSource : public IDropSource
  192.     {
  193.     protected:
  194.         ULONG                m_cRef;
  195.         class CCosmoDoc     *m_pDoc;
  196.  
  197.     public:
  198.         CDropSource(class CCosmoDoc *);
  199.         ~CDropSource(void);
  200.  
  201.         //IDropSource interface members
  202.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  203.         STDMETHODIMP_(ULONG) AddRef(void);
  204.         STDMETHODIMP_(ULONG) Release(void);
  205.  
  206.         STDMETHODIMP QueryContinueDrag(BOOL, DWORD);
  207.         STDMETHODIMP GiveFeedback(DWORD);
  208.     };
  209.  
  210. typedef CDropSource * PCDropSource;
  211.  
  212. //End CHAPTER13MOD
  213.  
  214.  
  215.  
  216. //Constant ID for the window polyline that lives in a document window
  217. #define ID_POLYLINE         10
  218.  
  219. //Stream name to open with IPersistStream[Init]
  220. #define SZSTREAM                    OLETEXT("CONTENTS")
  221.  
  222.  
  223. class CCosmoDoc : public CDocument, public IUnknown
  224.     {
  225.     friend class CPolylineAdviseSink;
  226.     friend class CImpIAdviseSink;
  227.  
  228.     //CHAPTER13MOD
  229.     //These need access to FQueryPasteFromData, PasteFromData
  230.     friend class CDropTarget;
  231.     friend class CDropSource;
  232.     //End CHAPTER13MOD
  233.  
  234.     protected:
  235.         UINT                    m_uPrevSize;    //Last WM_SIZE wParam
  236.  
  237.         IPolyline10            *m_pPL;          //Polyline object
  238.         IPolylineAdviseSink10  *m_pPLAdv;
  239.  
  240.         IConnectionPoint       *m_pIConnectPt;
  241.         DWORD                   m_dwCookie;     //Connection key
  242.         IStorage               *m_pIStorage;    //Doc storage
  243.         PERSISTPOINTER          m_pp;
  244.  
  245.         PCImpIAdviseSink        m_pImpIAdviseSink;
  246.  
  247.         DWORD                   m_dwConn;       //Advisory connection
  248.         ULONG                   m_cRef;         //Document ref count
  249.         LPDATAOBJECT            m_pIDataClip;   //Clipboard object
  250.  
  251.         //CHAPTER13MOD
  252.         PCDropTarget            m_pDropTarget;  //Registered target
  253.         BOOL                    m_fDragSource;  //Source==target?
  254.         //End CHAPTER13MOD
  255.  
  256.     protected:
  257.         virtual BOOL     FMessageHook(HWND, UINT, WPARAM, LPARAM
  258.             , LRESULT *);
  259.  
  260.         //CHAPTER13MOD
  261.         virtual BOOL     FQueryPasteFromData(LPDATAOBJECT);
  262.         virtual BOOL     PasteFromData(LPDATAOBJECT);
  263.         LPDATAOBJECT     TransferObjectCreate(void);
  264.         void             DropSelectTargetWindow(void);
  265.         //End CHAPTER13MOD
  266.  
  267.  
  268.     public:
  269.         CCosmoDoc(HINSTANCE, PCFrame, PCDocumentAdviseSink);
  270.         virtual ~CCosmoDoc(void);
  271.  
  272.         //Need a controlling unknown for our interfaces
  273.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  274.         STDMETHODIMP_(ULONG) AddRef(void);
  275.         STDMETHODIMP_(ULONG) Release(void);
  276.  
  277.         virtual BOOL     Init(PDOCUMENTINIT);
  278.         virtual void     Clear(void);
  279.  
  280.         virtual UINT     Load(BOOL, LPTSTR);
  281.         virtual UINT     Save(UINT, LPTSTR);
  282.  
  283.         virtual void     Undo(void);
  284.         virtual BOOL     Clip(HWND, BOOL);
  285.  
  286.         virtual BOOL     FQueryPaste(void);
  287.         virtual BOOL     Paste(HWND);
  288.  
  289.         virtual COLORREF ColorSet(UINT, COLORREF);
  290.         virtual COLORREF ColorGet(UINT);
  291.  
  292.         virtual UINT     LineStyleSet(UINT);
  293.         virtual UINT     LineStyleGet(void);
  294.     };
  295.  
  296. typedef CCosmoDoc *PCCosmoDoc;
  297.  
  298.  
  299. //These color indices wrap the polyline definitions
  300. #define DOCCOLOR_BACKGROUND             POLYLINECOLOR_BACKGROUND
  301. #define DOCCOLOR_LINE                   POLYLINECOLOR_LINE
  302.  
  303. #endif //_COCOSMO_H_
  304.