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 / chap21 / patron / pages.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  13.4 KB  |  405 lines

  1. /*
  2.  * PAGES.H
  3.  * Patron Chapter 21
  4.  *
  5.  * Definitions and function prototypes for the Pages window control
  6.  * as well as the CPage class.
  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 _PAGES_H_
  17. #define _PAGES_H_
  18.  
  19. //CHAPTER21MOD
  20. #include <stdlib.h>     //For atol
  21. //End CHAPTER21MOD
  22.  
  23. //Versioning.
  24. #define VERSIONMAJOR                2
  25. #define VERSIONMINOR                0
  26. #define VERSIONCURRENT              0x00020000
  27.  
  28. //Classname
  29. #define SZCLASSPAGES                TEXT("pages")
  30.  
  31. #define HIMETRIC_PER_INCH           2540
  32. #define LOMETRIC_PER_INCH           254
  33. #define LOMETRIC_BORDER             60          //Border around page
  34.  
  35.  
  36. //Window extra bytes and offsets
  37. #define CBPAGESWNDEXTRA             (sizeof(LONG))
  38. #define PAGEWL_STRUCTURE            0
  39.  
  40.  
  41. #include "tenant.h"
  42.  
  43. typedef struct tagTENANTLIST
  44.     {
  45.     DWORD       cTenants;
  46.     DWORD       dwIDNext;
  47.     } TENANTLIST, *PTENANTLIST;
  48.  
  49. #define SZSTREAMTENANTLIST        OLETEXT("Tenant List")
  50.  
  51. //Delay timer used in mouse debouncing
  52. #define IDTIMER_DEBOUNCE          120
  53.  
  54.  
  55.  
  56. /*
  57.  * Page class describing an individual page and what things it
  58.  * contains, managing an IStorage for us.
  59.  *
  60.  * A DWORD is used to identify this page as the name of the storage
  61.  * is the string form of this ID.  If we added a page every second,
  62.  * it would take 136 years to overrun this counter, so we can
  63.  * get away with saving it persistently.  I hope this software is
  64.  * obsolete by then.
  65.  */
  66.  
  67. //CHAPTER21MOD
  68. class CPage : public IUnknown
  69. //End CHAPTER21MOD
  70.     {
  71.     friend class CIOleUILinkContainer;
  72.     //CHAPTER21MOD
  73.     friend class CImpIOleItemContainer;
  74.     //End CHAPTER21MOD
  75.  
  76.     private:
  77.         DWORD       m_dwID;             //Persistent identifier
  78.         LPSTORAGE   m_pIStorage;        //Substorage for this page
  79.         HWND        m_hWnd;             //Pages window
  80.         DWORD       m_cOpens;           //Calls to Open
  81.  
  82.         class CPages *m_pPG;            //Pages window
  83.  
  84.         DWORD       m_dwIDNext;
  85.         DWORD       m_cTenants;
  86.         HWND        m_hWndTenantList;   //Listbox; our tenant list
  87.  
  88.         UINT        m_iTenantCur;
  89.         PCTenant    m_pTenantCur;
  90.  
  91.         UINT        m_uHTCode;          //Last hit-test/mouse move
  92.         UINT        m_uSizingFlags;     //Restrictions on sizing
  93.         BOOL        m_fTracking;        //Tracking resize?
  94.         RECTL       m_rclOrg;           //Original before tracking
  95.         RECTL       m_rcl;              //Tracking rectangle
  96.         RECTL       m_rclBounds;        //Boundaries f/size tracking
  97.         HDC         m_hDC;              //Tracking hDC
  98.  
  99.         BOOL        m_fDragPending;     //Waiting for drag?
  100.         BOOL        m_fSizePending;     //Waiting for debounce?
  101.         int         m_cxyDist;          //Debounce distance
  102.         UINT        m_cDelay;           //Debounce delay
  103.         POINTS      m_ptDown;           //Point of click to debounce
  104.         UINT        m_uKeysDown;        //Keys when click happens
  105.         DWORD       m_fTimer;           //Timer active?
  106.         BOOL        m_fReopen;          //Did we just close?
  107.  
  108.         //CHAPTER21MOD
  109.         LPMONIKER               m_pmkFile;  //Document name
  110.         ULONG                   m_cRef;
  111.         DWORD                   m_dwRegROTWild;
  112.  
  113.         class CImpIOleItemContainer *m_pImpIOleItemContainer;
  114.         //End CHAPTER21MOD
  115.  
  116.     protected:
  117.         BOOL         TenantGet(UINT, PCTenant *, BOOL);
  118.         //CHAPTER21MOD
  119.         BOOL         TenantGetFromID(DWORD, PCTenant *, BOOL);
  120.         //End CHAPTER21MOD
  121.         BOOL         TenantAdd(UINT, DWORD, PCTenant *);
  122.         LPDATAOBJECT TransferObjectCreate(PPOINTL);
  123.  
  124.         //PAGEMOUS.CPP
  125.         BOOL         SelectTenantAtPoint(UINT, UINT);
  126.         UINT         TenantFromPoint(UINT, UINT, PCTenant *);
  127.         BOOL         DragDrop(UINT, UINT, UINT);
  128.  
  129.     public:
  130.         CPage(DWORD, HWND, class CPages *);
  131.         ~CPage(void);
  132.  
  133.         //CHAPTER21MOD
  134.         //IUnknown for delegation
  135.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  136.         STDMETHODIMP_(ULONG) AddRef(void);
  137.         STDMETHODIMP_(ULONG) Release(void);
  138.         //End CHAPTER21MOD
  139.  
  140.         DWORD       GetID(void);
  141.         BOOL        Open(LPSTORAGE);
  142.         void        Close(BOOL);
  143.         BOOL        Update(void);
  144.         void        Destroy(LPSTORAGE);
  145.         UINT        GetStorageName(LPOLESTR);
  146.  
  147.         void        Draw(HDC, int, int, BOOL, BOOL);
  148.  
  149.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  150.                         , PPATRONOBJECT, DWORD);
  151.         BOOL        TenantDestroy(void);
  152.         BOOL        TenantClip(BOOL);
  153.         BOOL        FQueryObjectSelected(HMENU);
  154.         void        ActivateObject(LONG);
  155.         void        ShowObjectTypes(BOOL);
  156.         void        NotifyTenantsOfRename(LPTSTR, LPMONIKER);
  157.         BOOL        FQueryLinksInPage(void);
  158.         BOOL        ConvertObject(HWND, BOOL);
  159.  
  160.         //PAGEMOUSE.CPP
  161.         BOOL        OnRightDown(UINT, UINT, UINT);
  162.         BOOL        OnLeftDown(UINT, UINT, UINT);
  163.         BOOL        OnLeftDoubleClick(UINT, UINT, UINT);
  164.         BOOL        OnLeftUp(UINT, UINT, UINT);
  165.         void        OnMouseMove(UINT, int, int);
  166.         void        OnTimer(UINT);
  167.         void        StartSizeTracking(void);
  168.         void        OnNCHitTest(UINT, UINT);
  169.         BOOL        OnSetCursor(UINT);
  170.     };
  171.  
  172. typedef CPage *PCPage;
  173.  
  174.  
  175.  
  176. /*
  177.  * Structures to save with the document describing the device
  178.  * configuration and pages that we have.  This is followed by
  179.  * a list of DWORD IDs for the individual pages.
  180.  */
  181.  
  182. typedef struct tagDEVICECONFIG
  183.     {
  184.     DWORD       cb;                         //Size of structure
  185.     TCHAR       szDriver[CCHDEVICENAME];
  186.     TCHAR       szDevice[CCHDEVICENAME];
  187.     TCHAR       szPort[CCHDEVICENAME];
  188.     DWORD       cbDevMode;                  //Size of actual DEVMODE
  189.     DEVMODE     dm;                         //Variable
  190.     } DEVICECONFIG, *PDEVICECONFIG;
  191.  
  192. //Offset to cbDevMode
  193. #define CBSEEKOFFSETCBDEVMODE  (sizeof(DWORD)   \
  194.                                +(3*CCHDEVICENAME*sizeof(TCHAR)))
  195.  
  196. //Combined OLE and Patron device structures.
  197. typedef struct tagCOMBINEDEVICE
  198.     {
  199.     DVTARGETDEVICE  td;
  200.     DEVICECONFIG    dc;
  201.     } COMBINEBDEVICE, *PCOMBINEDEVICE;
  202.  
  203.  
  204. typedef struct tagPAGELIST
  205.     {
  206.     DWORD       cPages;
  207.     DWORD       iPageCur;
  208.     DWORD       dwIDNext;
  209.     } PAGELIST, *PPAGELIST;
  210.  
  211.  
  212. //PRINT.CPP
  213. BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  214. BOOL    APIENTRY AbortProc(HDC, int);
  215.  
  216.  
  217. //PAGEWIN.CPP
  218. LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  219. void             RectConvertMappings(LPRECT, HDC, BOOL);
  220.  
  221.  
  222. class CPages : public CWindow
  223.     {
  224.     friend LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  225.     friend BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  226.  
  227.     friend class CPage;
  228.     friend class CTenant;
  229.     friend class CDropTarget;
  230.     friend class CImpIAdviseSink;
  231.  
  232.     //CHAPTER21MOD
  233.     friend class CImpIOleItemContainer;
  234.     //End CHAPTER21MOD
  235.  
  236.     protected:
  237.         PCPage      m_pPageCur;             //Current page
  238.         UINT        m_iPageCur;             //Current page
  239.         UINT        m_cPages;               //Number of pages
  240.  
  241.         HWND        m_hWndPageList;         //Listbox with page list
  242.         HFONT       m_hFont;                //Page font
  243.         BOOL        m_fSystemFont;          //m_hFont system object?
  244.  
  245.         UINT        m_cx;                   //Page size in LOMETRIC
  246.         UINT        m_cy;
  247.  
  248.         UINT        m_xMarginLeft;          //Unusable margins,
  249.         UINT        m_xMarginRight;         //in LOMETRIC
  250.         UINT        m_yMarginTop;
  251.         UINT        m_yMarginBottom;
  252.  
  253.         UINT        m_xPos;                 //Viewport scroll pos,
  254.         UINT        m_yPos;                 //both in *PIXELS*
  255.  
  256.         DWORD       m_dwIDNext;             //Next ID for a page.
  257.         LPSTORAGE   m_pIStorage;            //Root storage
  258.  
  259.         UINT        m_cf;                   //Clipboard format
  260.         BOOL        m_fDirty;
  261.  
  262.         BOOL        m_fDragSource;          //Source==target?
  263.         BOOL        m_fMoveInPage;          //Moving in same page
  264.         BOOL        m_fLinkAllowed;         //Linking in drag-drop?
  265.         POINTL      m_ptDrop;               //Where to move object
  266.  
  267.         BOOL        m_fDragRectShown;       //Is rect on the screen?
  268.         UINT        m_uScrollInset;         //Hit-test for drag-drop
  269.         UINT        m_uScrollDelay;         //Delay before repeat
  270.         DWORD       m_dwTimeLast;           //Ticks on last DragOver
  271.         UINT        m_uHScrollCode;         //L/R on scroll repeat?
  272.         UINT        m_uVScrollCode;         //U/D on scroll repeat?
  273.         UINT        m_uLastTest;            //Last test result
  274.         POINTL      m_ptlRect;              //Last feedback rectangle
  275.         SIZEL       m_szlRect;
  276.  
  277.         BOOL        m_fShowTypes;           //Show Object active?
  278.  
  279.         //CHAPTER21MOD
  280.         LPMONIKER   m_pmkFile;
  281.         //End CHAPTER21MOD
  282.  
  283.     private:
  284.         void        Draw(HDC, BOOL, BOOL);
  285.         void        UpdateScrollRanges(void);
  286.         BOOL        ConfigureForDevice(void);
  287.         BOOL        PageGet(UINT, PCPage *, BOOL);
  288.         BOOL        PageAdd(UINT, DWORD, BOOL);
  289.  
  290.         void        CalcBoundingRect(LPRECT, BOOL);
  291.  
  292.         //DRAGDROP.CPP
  293.         UINT        UTestDroppablePoint(PPOINTL);
  294.         void        DrawDropTargetRect(PPOINTL, LPSIZEL);
  295.         void        AdjustPosition(PPOINTL, LPSIZEL);
  296.  
  297.     public:
  298.         CPages(HINSTANCE, UINT);
  299.         ~CPages(void);
  300.  
  301.         BOOL        Init(HWND, LPRECT, DWORD, UINT, LPVOID);
  302.  
  303.         BOOL        StorageSet(LPSTORAGE, BOOL, BOOL);
  304.         BOOL        StorageUpdate(BOOL);
  305.  
  306.         BOOL        Print(HDC, LPTSTR, DWORD, UINT, UINT, UINT);
  307.  
  308.         void        RectGet(LPRECT);
  309.         void        RectSet(LPRECT, BOOL);
  310.         void        SizeGet(LPRECT);
  311.         void        SizeSet(LPRECT, BOOL);
  312.  
  313.         PCPage      ActivePage(void);
  314.         UINT        PageInsert(UINT);
  315.         UINT        PageDelete(UINT);
  316.         UINT        CurPageGet(void);
  317.         UINT        CurPageSet(UINT);
  318.         UINT        NumPagesGet(void);
  319.  
  320.         BOOL        DevModeSet(HGLOBAL, HGLOBAL);
  321.         HGLOBAL     DevModeGet(void);
  322.  
  323.         BOOL        FIsDirty(void);
  324.         BOOL        DevReadConfig(PCOMBINEDEVICE *, HDC *);
  325.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  326.                         , PPATRONOBJECT, DWORD);
  327.         BOOL        TenantDestroy(void);
  328.         BOOL        TenantClip(BOOL);
  329.         BOOL        FQueryObjectSelected(HMENU);
  330.         void        ActivateObject(LONG);
  331.  
  332.         void        ShowObjectTypes(BOOL);
  333.         void        NotifyTenantsOfRename(LPTSTR, LPMONIKER);
  334.         BOOL        FQueryLinksInPage(void);
  335.         BOOL        GetUILinkContainer(class CIOleUILinkContainer **);
  336.         BOOL        ConvertObject(HWND);
  337.         //CHAPTER21MOD
  338.         UINT        IPageGetFromID(DWORD, PCPage *, BOOL);
  339.         //End CHAPTER21MOD
  340.     };
  341.  
  342. typedef CPages *PCPages;
  343.  
  344.  
  345. //Fixed names of streams in the Pages IStorage
  346. #define SZSTREAMPAGELIST        OLETEXT("Page List")
  347. #define SZSTREAMDEVICECONFIG    OLETEXT("Device Configuration")
  348.  
  349. //Return values for UTestDroppablePoint
  350. #define UDROP_NONE              0x0000      //Exclusive
  351. #define UDROP_CLIENT            0x0001      //Inclusive
  352. #define UDROP_INSETLEFT         0x0002      //L/R are exclusive
  353. #define UDROP_INSETRIGHT        0x0004
  354. #define UDROP_INSETHORZ         (UDROP_INSETLEFT | UDROP_INSETRIGHT)
  355.  
  356. #define UDROP_INSETTOP          0x0008      //T/B are exclusive
  357. #define UDROP_INSETBOTTOM       0x0010
  358. #define UDROP_INSETVERT         (UDROP_INSETTOP | UDROP_INSETBOTTOM)
  359.  
  360.  
  361. //Object used for the Links dialog
  362.  
  363. class CIOleUILinkContainer : public IOleUILinkContainer
  364.     {
  365.     private:
  366.         ULONG                   m_cRef;
  367.         PCPage                  m_pPage;
  368.         UINT                    m_iTenant;
  369.         LPOLEUILINKCONTAINER    m_pDelIUILinks;
  370.  
  371.     public:
  372.         BOOL                    m_fDirty;   //No reason to hide it
  373.  
  374.     protected:
  375.         STDMETHODIMP GetObjectInterface(DWORD, REFIID, PPVOID);
  376.  
  377.     public:
  378.         CIOleUILinkContainer(PCPage);
  379.         ~CIOleUILinkContainer(void);
  380.  
  381.         BOOL Init(void);
  382.         BOOL IsDirty(void);
  383.  
  384.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  385.         STDMETHODIMP_(ULONG) AddRef(void);
  386.         STDMETHODIMP_(ULONG) Release(void);
  387.  
  388.         STDMETHODIMP_(DWORD) GetNextLink(DWORD);
  389.         STDMETHODIMP         SetLinkUpdateOptions(DWORD, DWORD);
  390.         STDMETHODIMP         GetLinkUpdateOptions(DWORD, LPDWORD);
  391.         STDMETHODIMP         SetLinkSource(DWORD, LPTSTR, ULONG
  392.                                  , ULONG *, BOOL);
  393.         STDMETHODIMP         GetLinkSource(DWORD, LPTSTR *, ULONG *
  394.                                  , LPTSTR *, LPTSTR *, BOOL *
  395.                                  , BOOL *);
  396.         STDMETHODIMP         OpenLinkSource(DWORD);
  397.         STDMETHODIMP         UpdateLink(DWORD, BOOL, BOOL);
  398.         STDMETHODIMP         CancelLink(DWORD);
  399.     };
  400.  
  401. typedef CIOleUILinkContainer *PCIOleUILinkContainer;
  402.  
  403.  
  404. #endif  //_PAGES_H_
  405.