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

  1. /*
  2.  * PAGES.H
  3.  * Patron Chapter 24
  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.         BOOL                m_fFirstUIActivate;
  109.  
  110.     protected:
  111.         BOOL         TenantGet(UINT, PCTenant *, BOOL);
  112.         BOOL         TenantGetFromID(DWORD, PCTenant *, BOOL);
  113.         BOOL         TenantAdd(UINT, DWORD, PCTenant *);
  114.         LPDATAOBJECT TransferObjectCreate(PPOINTL);
  115.  
  116.         //PAGEMOUS.CPP
  117.         BOOL         SelectTenantAtPoint(UINT, UINT);
  118.         UINT         TenantFromPoint(UINT, UINT, PCTenant *);
  119.         BOOL         DragDrop(UINT, UINT, UINT);
  120.  
  121.     public:
  122.         CPage(DWORD, HWND, class CPages *);
  123.         ~CPage(void);
  124.  
  125.         //IUnknown for delegation
  126.         STDMETHODIMP QueryInterface(REFIID, PPVOID);
  127.         STDMETHODIMP_(ULONG) AddRef(void);
  128.         STDMETHODIMP_(ULONG) Release(void);
  129.  
  130.         DWORD       GetID(void);
  131.         BOOL        Open(LPSTORAGE);
  132.         void        Close(BOOL);
  133.         BOOL        Update(void);
  134.         void        Destroy(LPSTORAGE);
  135.         UINT        GetStorageName(LPOLESTR);
  136.  
  137.         void        Draw(HDC, int, int, BOOL, BOOL);
  138.  
  139.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  140.                         , PPATRONOBJECT, DWORD);
  141.         BOOL        TenantDestroy(void);
  142.         BOOL        TenantClip(BOOL);
  143.         BOOL        FQueryObjectSelected(HMENU);
  144.         void        ActivateObject(LONG, LPMSG);
  145.  
  146.         void        ShowObjectTypes(BOOL);
  147.         void        NotifyTenantsOfRename(LPTSTR, LPMONIKER);
  148.         BOOL        FQueryLinksInPage(void);
  149.         BOOL        ConvertObject(HWND, BOOL);
  150.         void        ScrolledWindow(void);
  151.         void        SwitchActiveTenant(PCTenant);
  152.         //CHAPTER24MOD
  153.         void        ToggleDesignMode(BOOL);
  154.         void        ToggleUIDead(BOOL);
  155.         void        ToggleHatchHandles(BOOL);
  156.         BOOL        FQueryEnableEvents(void);
  157.         void        AssignEvents(HWND);
  158.         BOOL        TryMnemonic(LPMSG);
  159.         //End CHAPTER24MOD
  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. //CHAPTER24MOD
  224. //EVENTS.CPP
  225. BOOL    APIENTRY EventsDlgProc(HWND, UINT, WPARAM, LPARAM);
  226.  
  227. //Helpers for EventsDlgProc
  228. void CheckAction(HWND, HWND);
  229. void UpdateAction(HWND, UINT);
  230. void TestSelection(HWND);
  231.  
  232. #ifdef WIN32
  233. #define PROP_POINTER    TEXT("Pointer")
  234. #else
  235. #define PROP_SELECTOR   "Selector"
  236. #define PROP_OFFSET     "Offset"
  237. #endif
  238.  
  239. //End CHAPTER24MOD
  240.  
  241.  
  242. class CPages : public CWindow
  243.     {
  244.     friend LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  245.     friend BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  246.  
  247.     friend class CPage;
  248.     friend class CTenant;
  249.     friend class CDropTarget;
  250.     friend class CImpIAdviseSink;
  251.     friend class CImpIOleItemContainer;
  252.     friend class CImpIOleInPlaceSite;
  253.  
  254.     protected:
  255.         PCPage      m_pPageCur;             //Current page
  256.         UINT        m_iPageCur;             //Current page
  257.         UINT        m_cPages;               //Number of pages
  258.  
  259.         HWND        m_hWndPageList;         //Listbox with page list
  260.         HFONT       m_hFont;                //Page font
  261.         BOOL        m_fSystemFont;          //m_hFont system object?
  262.  
  263.         UINT        m_cx;                   //Page size in LOMETRIC
  264.         UINT        m_cy;
  265.  
  266.         UINT        m_xMarginLeft;          //Unusable margins,
  267.         UINT        m_xMarginRight;         //in LOMETRIC
  268.         UINT        m_yMarginTop;
  269.         UINT        m_yMarginBottom;
  270.  
  271.         UINT        m_xPos;                 //Viewport scroll pos,
  272.         UINT        m_yPos;                 //both in *PIXELS*
  273.  
  274.         DWORD       m_dwIDNext;             //Next ID for a page.
  275.         LPSTORAGE   m_pIStorage;            //Root storage
  276.  
  277.         UINT        m_cf;                   //Clipboard format
  278.         BOOL        m_fDirty;
  279.  
  280.         BOOL        m_fDragSource;          //Source==target?
  281.         BOOL        m_fMoveInPage;          //Moving in same page
  282.         BOOL        m_fLinkAllowed;         //Linking in drag-drop?
  283.         POINTL      m_ptDrop;               //Where to move object
  284.  
  285.         BOOL        m_fDragRectShown;       //Is rect on the screen?
  286.         UINT        m_uScrollInset;         //Hit-test for drag-drop
  287.         UINT        m_uScrollDelay;         //Delay before repeat
  288.         DWORD       m_dwTimeLast;           //Ticks on last DragOver
  289.         UINT        m_uHScrollCode;         //L/R on scroll repeat?
  290.         UINT        m_uVScrollCode;         //U/D on scroll repeat?
  291.         UINT        m_uLastTest;            //Last test result
  292.         POINTL      m_ptlRect;              //Last feedback rectangle
  293.         SIZEL       m_szlRect;
  294.  
  295.         BOOL        m_fShowTypes;           //Show Object active?
  296.         LPMONIKER   m_pmkFile;
  297.         BOOL        m_fAddUI;
  298.         //CHAPTER24MOD
  299.         BOOL        m_fDesignMode;
  300.         BOOL        m_fUIDead;
  301.         BOOL        m_fHatchHandles;
  302.         IFontDisp  *m_pIFont;               //Ambient font
  303.         //End CHAPTER24MOD
  304.  
  305.     private:
  306.         void        Draw(HDC, BOOL, BOOL);
  307.         void        UpdateScrollRanges(void);
  308.         BOOL        ConfigureForDevice(void);
  309.         BOOL        PageGet(UINT, PCPage *, BOOL);
  310.         BOOL        PageAdd(UINT, DWORD, BOOL);
  311.  
  312.         void        CalcBoundingRect(LPRECT, BOOL);
  313.  
  314.         //DRAGDROP.CPP
  315.         UINT        UTestDroppablePoint(PPOINTL);
  316.         void        DrawDropTargetRect(PPOINTL, LPSIZEL);
  317.         void        AdjustPosition(PPOINTL, LPSIZEL);
  318.  
  319.     public:
  320.         CPages(HINSTANCE, UINT);
  321.         ~CPages(void);
  322.  
  323.         BOOL        Init(HWND, LPRECT, DWORD, UINT, LPVOID);
  324.  
  325.         BOOL        StorageSet(LPSTORAGE, BOOL, BOOL);
  326.         BOOL        StorageUpdate(BOOL);
  327.  
  328.         BOOL        Print(HDC, LPTSTR, DWORD, UINT, UINT, UINT);
  329.  
  330.         void        RectGet(LPRECT);
  331.         void        RectSet(LPRECT, BOOL);
  332.         void        SizeGet(LPRECT);
  333.         void        SizeSet(LPRECT, BOOL);
  334.  
  335.         PCPage      ActivePage(void);
  336.         UINT        PageInsert(UINT);
  337.         UINT        PageDelete(UINT);
  338.         UINT        CurPageGet(void);
  339.         UINT        CurPageSet(UINT);
  340.         UINT        NumPagesGet(void);
  341.  
  342.         BOOL        DevModeSet(HGLOBAL, HGLOBAL);
  343.         HGLOBAL     DevModeGet(void);
  344.  
  345.         BOOL        FIsDirty(void);
  346.         BOOL        DevReadConfig(PCOMBINEDEVICE *, HDC *);
  347.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  348.                         , PPATRONOBJECT, DWORD);
  349.         BOOL        TenantDestroy(void);
  350.         BOOL        TenantClip(BOOL);
  351.         BOOL        FQueryObjectSelected(HMENU);
  352.         void        ActivateObject(LONG, LPMSG);
  353.         //CHAPTER24MOD
  354.         void        ToggleDesignMode(BOOL);
  355.         void        ToggleUIDead(BOOL);
  356.         void        ToggleHatchHandles(BOOL);
  357.         BOOL        FQueryEnableEvents(void);
  358.         void        AssignEvents(HWND);
  359.         BOOL        TryMnemonic(LPMSG);
  360.         //End CHAPTER24MOD
  361.  
  362.         void        ShowObjectTypes(BOOL);
  363.         void        NotifyTenantsOfRename(LPTSTR, LPMONIKER);
  364.         BOOL        FQueryLinksInPage(void);
  365.         BOOL        GetUILinkContainer(class CIOleUILinkContainer **);
  366.         BOOL        ConvertObject(HWND);
  367.         UINT        IPageGetFromID(DWORD, PCPage *, BOOL);
  368.     };
  369.  
  370. typedef CPages *PCPages;
  371.  
  372.  
  373. //Fixed names of streams in the Pages IStorage
  374. #define SZSTREAMPAGELIST        OLETEXT("Page List")
  375. #define SZSTREAMDEVICECONFIG    OLETEXT("Device Configuration")
  376.  
  377. //Return values for UTestDroppablePoint
  378. #define UDROP_NONE              0x0000      //Exclusive
  379. #define UDROP_CLIENT            0x0001      //Inclusive
  380. #define UDROP_INSETLEFT         0x0002      //L/R are exclusive
  381. #define UDROP_INSETRIGHT        0x0004
  382. #define UDROP_INSETHORZ         (UDROP_INSETLEFT | UDROP_INSETRIGHT)
  383.  
  384. #define UDROP_INSETTOP          0x0008      //T/B are exclusive
  385. #define UDROP_INSETBOTTOM       0x0010
  386. #define UDROP_INSETVERT         (UDROP_INSETTOP | UDROP_INSETBOTTOM)
  387.  
  388.  
  389. //Object used for the Links dialog
  390.  
  391. class CIOleUILinkContainer : public IOleUILinkContainer
  392.     {
  393.     private:
  394.         ULONG                   m_cRef;
  395.         PCPage                  m_pPage;
  396.         UINT                    m_iTenant;
  397.         LPOLEUILINKCONTAINER    m_pDelIUILinks;
  398.  
  399.     public:
  400.         BOOL                    m_fDirty;   //No reason to hide it
  401.  
  402.     protected:
  403.         STDMETHODIMP GetObjectInterface(DWORD, REFIID, PPVOID);
  404.  
  405.     public:
  406.         CIOleUILinkContainer(PCPage);
  407.         ~CIOleUILinkContainer(void);
  408.  
  409.         BOOL Init(void);
  410.         BOOL IsDirty(void);
  411.  
  412.         STDMETHODIMP         QueryInterface(REFIID, PPVOID);
  413.         STDMETHODIMP_(ULONG) AddRef(void);
  414.         STDMETHODIMP_(ULONG) Release(void);
  415.  
  416.         STDMETHODIMP_(DWORD) GetNextLink(DWORD);
  417.         STDMETHODIMP         SetLinkUpdateOptions(DWORD, DWORD);
  418.         STDMETHODIMP         GetLinkUpdateOptions(DWORD, LPDWORD);
  419.         STDMETHODIMP         SetLinkSource(DWORD, LPTSTR, ULONG
  420.                                  , ULONG *, BOOL);
  421.         STDMETHODIMP         GetLinkSource(DWORD, LPTSTR *, ULONG *
  422.                                  , LPTSTR *, LPTSTR *, BOOL *
  423.                                  , BOOL *);
  424.         STDMETHODIMP         OpenLinkSource(DWORD);
  425.         STDMETHODIMP         UpdateLink(DWORD, BOOL, BOOL);
  426.         STDMETHODIMP         CancelLink(DWORD);
  427.     };
  428.  
  429. typedef CIOleUILinkContainer *PCIOleUILinkContainer;
  430.  
  431.  
  432. #endif  //_PAGES_H_
  433.