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 / chap22 / patron / pages.h < prev    next >
C/C++ Source or Header  |  1995-05-03  |  14KB  |  408 lines

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