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

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