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

  1. /*
  2.  * PAGES.H
  3.  * Patron Chapter 17
  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. //CHAPTER17MOD
  38. //Time to break this stuff out into another file.
  39. #include "tenant.h"
  40. //End CHAPTER17MOD
  41.  
  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. class CPage
  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.     protected:
  101.         BOOL         TenantGet(UINT, PCTenant *, BOOL);
  102.         BOOL         TenantAdd(UINT, DWORD, PCTenant *);
  103.         LPDATAOBJECT TransferObjectCreate(PPOINTL);
  104.  
  105.         //PAGEMOUS.CPP
  106.         //CHAPTER17MOD
  107.         BOOL         SelectTenantAtPoint(UINT, UINT);
  108.         //End CHAPTER17MOD
  109.  
  110.         UINT         TenantFromPoint(UINT, UINT, PCTenant *);
  111.         BOOL         DragDrop(UINT, UINT, UINT);
  112.  
  113.     public:
  114.         CPage(DWORD, HWND, class CPages *);
  115.         ~CPage(void);
  116.  
  117.         DWORD       GetID(void);
  118.         BOOL        Open(LPSTORAGE);
  119.         void        Close(BOOL);
  120.         BOOL        Update(void);
  121.         void        Destroy(LPSTORAGE);
  122.         UINT        GetStorageName(LPOLESTR);
  123.  
  124.         void        Draw(HDC, int, int, BOOL, BOOL);
  125.  
  126.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  127.                         , PPATRONOBJECT, DWORD);
  128.         BOOL        TenantDestroy(void);
  129.         BOOL        TenantClip(BOOL);
  130.         BOOL        FQueryObjectSelected(HMENU);
  131.         //CHAPTER17MOD
  132.         void        ActivateObject(LONG);
  133.         void        NotifyTenantsOfRename(LPTSTR, LPVOID);
  134.         BOOL        ConvertObject(HWND, BOOL);
  135.  
  136.         //PAGEMOUSE.CPP
  137.         BOOL        OnRightDown(UINT, UINT, UINT);
  138.         //End CHAPTER17MOD
  139.         BOOL        OnLeftDown(UINT, UINT, UINT);
  140.         BOOL        OnLeftDoubleClick(UINT, UINT, UINT);
  141.         BOOL        OnLeftUp(UINT, UINT, UINT);
  142.         void        OnMouseMove(UINT, int, int);
  143.         void        OnTimer(UINT);
  144.         void        StartSizeTracking(void);
  145.         void        OnNCHitTest(UINT, UINT);
  146.         BOOL        OnSetCursor(UINT);
  147.     };
  148.  
  149. typedef CPage *PCPage;
  150.  
  151.  
  152.  
  153. /*
  154.  * Structures to save with the document describing the device
  155.  * configuration and pages that we have.  This is followed by
  156.  * a list of DWORD IDs for the individual pages.
  157.  */
  158.  
  159. typedef struct tagDEVICECONFIG
  160.     {
  161.     DWORD       cb;                         //Size of structure
  162.     TCHAR       szDriver[CCHDEVICENAME];
  163.     TCHAR       szDevice[CCHDEVICENAME];
  164.     TCHAR       szPort[CCHDEVICENAME];
  165.     DWORD       cbDevMode;                  //Size of actual DEVMODE
  166.     DEVMODE     dm;                         //Variable
  167.     } DEVICECONFIG, *PDEVICECONFIG;
  168.  
  169. //Offset to cbDevMode
  170. #define CBSEEKOFFSETCBDEVMODE  (sizeof(DWORD)   \
  171.                                +(3*CCHDEVICENAME*sizeof(TCHAR)))
  172.  
  173. //Combined OLE and Patron device structures.
  174. typedef struct tagCOMBINEDEVICE
  175.     {
  176.     DVTARGETDEVICE  td;
  177.     DEVICECONFIG    dc;
  178.     } COMBINEBDEVICE, *PCOMBINEDEVICE;
  179.  
  180.  
  181. typedef struct tagPAGELIST
  182.     {
  183.     DWORD       cPages;
  184.     DWORD       iPageCur;
  185.     DWORD       dwIDNext;
  186.     } PAGELIST, *PPAGELIST;
  187.  
  188.  
  189. //PRINT.CPP
  190. BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  191. BOOL    APIENTRY AbortProc(HDC, int);
  192.  
  193.  
  194. //PAGEWIN.CPP
  195. LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  196. void             RectConvertMappings(LPRECT, HDC, BOOL);
  197.  
  198.  
  199. class CPages : public CWindow
  200.     {
  201.     friend LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  202.     friend BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  203.  
  204.     friend class CPage;
  205.     friend class CTenant;
  206.     friend class CDropTarget;
  207.  
  208.     //CHAPTER17MOD
  209.     friend class CImpIAdviseSink;
  210.     //End CHAPTER17MOD
  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.         POINTL      m_ptDrop;               //Where to move object
  241.  
  242.         BOOL        m_fDragRectShown;       //Is rect on the screen?
  243.         UINT        m_uScrollInset;         //Hit-test for drag-drop
  244.         UINT        m_uScrollDelay;         //Delay before repeat
  245.         DWORD       m_dwTimeLast;           //Ticks on last DragOver
  246.         UINT        m_uHScrollCode;         //L/R on scroll repeat?
  247.         UINT        m_uVScrollCode;         //U/D on scroll repeat?
  248.         UINT        m_uLastTest;            //Last test result
  249.         POINTL      m_ptlRect;              //Last feedback rectangle
  250.         SIZEL       m_szlRect;
  251.  
  252.     private:
  253.         void        Draw(HDC, BOOL, BOOL);
  254.         void        UpdateScrollRanges(void);
  255.         BOOL        ConfigureForDevice(void);
  256.         BOOL        PageGet(UINT, PCPage *, BOOL);
  257.         BOOL        PageAdd(UINT, DWORD, BOOL);
  258.  
  259.         void        CalcBoundingRect(LPRECT, BOOL);
  260.  
  261.         //DRAGDROP.CPP
  262.         UINT        UTestDroppablePoint(PPOINTL);
  263.         void        DrawDropTargetRect(PPOINTL, LPSIZEL);
  264.         void        AdjustPosition(PPOINTL, LPSIZEL);
  265.  
  266.     public:
  267.         CPages(HINSTANCE, UINT);
  268.         ~CPages(void);
  269.  
  270.         BOOL        Init(HWND, LPRECT, DWORD, UINT, LPVOID);
  271.  
  272.         BOOL        StorageSet(LPSTORAGE, BOOL, BOOL);
  273.         BOOL        StorageUpdate(BOOL);
  274.  
  275.         BOOL        Print(HDC, LPTSTR, DWORD, UINT, UINT, UINT);
  276.  
  277.         void        RectGet(LPRECT);
  278.         void        RectSet(LPRECT, BOOL);
  279.         void        SizeGet(LPRECT);
  280.         void        SizeSet(LPRECT, BOOL);
  281.  
  282.         PCPage      ActivePage(void);
  283.         UINT        PageInsert(UINT);
  284.         UINT        PageDelete(UINT);
  285.         UINT        CurPageGet(void);
  286.         UINT        CurPageSet(UINT);
  287.         UINT        NumPagesGet(void);
  288.  
  289.         BOOL        DevModeSet(HGLOBAL, HGLOBAL);
  290.         HGLOBAL     DevModeGet(void);
  291.  
  292.         BOOL        FIsDirty(void);
  293.         BOOL        DevReadConfig(PCOMBINEDEVICE *, HDC *);
  294.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  295.                         , PPATRONOBJECT, DWORD);
  296.         BOOL        TenantDestroy(void);
  297.         BOOL        TenantClip(BOOL);
  298.         BOOL        FQueryObjectSelected(HMENU);
  299.         //CHAPTER17MOD
  300.         void        ActivateObject(LONG);
  301.         void        NotifyTenantsOfRename(LPTSTR, LPVOID);
  302.         BOOL        ConvertObject(HWND);
  303.         //End CHAPTER17MOD
  304.     };
  305.  
  306. typedef CPages *PCPages;
  307.  
  308.  
  309. //Fixed names of streams in the Pages IStorage
  310. #define SZSTREAMPAGELIST        OLETEXT("Page List")
  311. #define SZSTREAMDEVICECONFIG    OLETEXT("Device Configuration")
  312.  
  313. //Return values for UTestDroppablePoint
  314. #define UDROP_NONE              0x0000      //Exclusive
  315. #define UDROP_CLIENT            0x0001      //Inclusive
  316. #define UDROP_INSETLEFT         0x0002      //L/R are exclusive
  317. #define UDROP_INSETRIGHT        0x0004
  318. #define UDROP_INSETHORZ         (UDROP_INSETLEFT | UDROP_INSETRIGHT)
  319.  
  320. #define UDROP_INSETTOP          0x0008      //T/B are exclusive
  321. #define UDROP_INSETBOTTOM       0x0010
  322. #define UDROP_INSETVERT         (UDROP_INSETTOP | UDROP_INSETBOTTOM)
  323.  
  324.  
  325. #endif  //_PAGES_H_
  326.