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

  1. /*
  2.  * PAGES.H
  3.  * Patron Chapter 13
  4.  *
  5.  * Definitions and function prototypes for the Pages window control
  6.  * as well as the CPage and CTenant classes.
  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.  
  38. /*
  39.  * Tenant class describing an individual piece of data in a page.
  40.  * It knows where it sits, what object is inside of it, and what
  41.  * its identifer is such that it can find it's storage within a
  42.  * page.
  43.  */
  44.  
  45. //Patron Objects clipboard format
  46. typedef struct tagPATRONOBJECT
  47.     {
  48.     POINTL      ptl;        //Location of object
  49.     POINTL      ptlPick;    //Pick point from drag-drop operation
  50.     SIZEL       szl;        //Extents of object (absolute)
  51.     FORMATETC   fe;         //Actual object format
  52.     } PATRONOBJECT, *PPATRONOBJECT;
  53.  
  54.  
  55.  
  56. //Values for hit-testing, drawing, and resize-tracking tenants
  57. #define CXYHANDLE       5
  58.  
  59. //Tenant creation types (not persistent)
  60. typedef enum
  61.     {
  62.     TENANTTYPE_NULL=0,
  63.     TENANTTYPE_STATIC,
  64.     } TENANTTYPE, *PTENANTTYPE;
  65.  
  66.  
  67. //State flags
  68. #define TENANTSTATE_DEFAULT      0x00000000
  69. #define TENANTSTATE_SELECTED     0x00000001
  70.  
  71.  
  72. /*
  73.  * Persistent information we need to save for each tenant, which is
  74.  * done in the tenant list instead of with each tenant.  Since this
  75.  * is a small structure it's best not to blow another stream for it
  76.  * (overhead).  (fSetExtent used in compound documents later on.)
  77.  */
  78. typedef struct tagTENANTINFO
  79.     {
  80.     DWORD       dwID;
  81.     RECTL       rcl;
  82.     FORMATETC   fe;             //Excludes ptd
  83.     short       fSetExtent;     //Call IOleObject::SetExtent on Run
  84.     } TENANTINFO, *PTENANTINFO;
  85.  
  86.  
  87. class CTenant
  88.     {
  89.     private:
  90.         HWND            m_hWnd;         //Pages window
  91.         DWORD           m_dwID;         //Persistent DWORD ID
  92.         DWORD           m_cOpens;       //Count calls to Open
  93.  
  94.         BOOL            m_fInitialized; //Something here?
  95.         LPUNKNOWN       m_pObj;         //The object here
  96.         LPSTORAGE       m_pIStorage;    //Sub-storage for tenant
  97.  
  98.         FORMATETC       m_fe;           //Used to create the object
  99.         DWORD           m_dwState;      //State flags
  100.         RECTL           m_rcl;          //Space of this object
  101.         CLSID           m_clsID;        //Object class (for statics)
  102.         BOOL            m_fSetExtent;   //Call SetExtent on next run
  103.  
  104.         class CPages   *m_pPG;          //Pages window
  105.  
  106.     protected:
  107.         HRESULT CreateStatic(LPDATAOBJECT, LPFORMATETC
  108.             , LPUNKNOWN *);
  109.  
  110.     public:
  111.         CTenant(DWORD, HWND, CPages *);
  112.         ~CTenant(void);
  113.  
  114.         DWORD       GetID(void);
  115.         UINT        GetStorageName(LPOLESTR);
  116.         UINT        Create(TENANTTYPE, LPVOID, LPFORMATETC, PPOINTL
  117.                         , LPSIZEL, LPSTORAGE, PPATRONOBJECT, DWORD);
  118.         BOOL        Load(LPSTORAGE, PTENANTINFO);
  119.         void        GetInfo(PTENANTINFO);
  120.         BOOL        Open(LPSTORAGE);
  121.         void        Close(BOOL);
  122.         BOOL        Update(void);
  123.         void        Destroy(LPSTORAGE);
  124.  
  125.         void        Select(BOOL);
  126.         BOOL        Activate(LONG);
  127.         void        Draw(HDC, DVTARGETDEVICE *, HDC, int, int
  128.                         , BOOL, BOOL);
  129.         void        Repaint(void);
  130.         void        Invalidate(void);
  131.  
  132.         void        ObjectGet(LPUNKNOWN *);
  133.         void        FormatEtcGet(LPFORMATETC, BOOL);
  134.         void        SizeGet(LPSIZEL, BOOL);
  135.         void        SizeSet(LPSIZEL, BOOL);
  136.         void        RectGet(LPRECTL, BOOL);
  137.         void        RectSet(LPRECTL, BOOL);
  138.     };
  139.  
  140.  
  141. typedef CTenant *PCTenant;
  142.  
  143. //Return codes for Create
  144. #define CREATE_FAILED               0
  145. #define CREATE_GRAPHICONLY          1
  146. #define CREATE_PLACEDOBJECT         2
  147.  
  148.  
  149.  
  150. typedef struct tagTENANTLIST
  151.     {
  152.     DWORD       cTenants;
  153.     DWORD       dwIDNext;
  154.     } TENANTLIST, *PTENANTLIST;
  155.  
  156. #define SZSTREAMTENANTLIST        OLETEXT("Tenant List")
  157.  
  158. //Delay timer used in mouse debouncing
  159. #define IDTIMER_DEBOUNCE          120
  160.  
  161.  
  162.  
  163. /*
  164.  * Page class describing an individual page and what things it
  165.  * contains, managing an IStorage for us.
  166.  *
  167.  * A DWORD is used to identify this page as the name of the storage
  168.  * is the string form of this ID.  If we added a page every second,
  169.  * it would take 136 years to overrun this counter, so we can
  170.  * get away with saving it persistently.  I hope this software is
  171.  * obsolete by then.
  172.  */
  173.  
  174. class CPage
  175.     {
  176.     private:
  177.         DWORD       m_dwID;             //Persistent identifier
  178.         LPSTORAGE   m_pIStorage;        //Substorage for this page
  179.         HWND        m_hWnd;             //Pages window
  180.         DWORD       m_cOpens;           //Calls to Open
  181.  
  182.         class CPages *m_pPG;            //Pages window
  183.  
  184.         DWORD       m_dwIDNext;
  185.         DWORD       m_cTenants;
  186.         HWND        m_hWndTenantList;   //Listbox; our tenant list
  187.  
  188.         UINT        m_iTenantCur;
  189.         PCTenant    m_pTenantCur;
  190.  
  191.         UINT        m_uHTCode;          //Last hit-test/mouse move
  192.         UINT        m_uSizingFlags;     //Restrictions on sizing
  193.         BOOL        m_fTracking;        //Tracking resize?
  194.         RECTL       m_rclOrg;           //Original before tracking
  195.         RECTL       m_rcl;              //Tracking rectangle
  196.         RECTL       m_rclBounds;        //Boundaries f/size tracking
  197.         HDC         m_hDC;              //Tracking hDC
  198.  
  199.         //CHAPTER13MOD
  200.         BOOL        m_fDragPending;     //Waiting for drag?
  201.         //End CHAPTER13MOD
  202.         BOOL        m_fSizePending;     //Waiting for debounce?
  203.         int         m_cxyDist;          //Debounce distance
  204.         UINT        m_cDelay;           //Debounce delay
  205.         POINTS      m_ptDown;           //Point of click to debounce
  206.         //CHAPTER13MOD
  207.         UINT        m_uKeysDown;        //Keys when click happens
  208.         //End CHAPTER13MOD
  209.         DWORD       m_fTimer;           //Timer active?
  210.  
  211.     protected:
  212.         BOOL         TenantGet(UINT, PCTenant *, BOOL);
  213.         BOOL         TenantAdd(UINT, DWORD, PCTenant *);
  214.         LPDATAOBJECT TransferObjectCreate(PPOINTL);
  215.  
  216.         //PAGEMOUS.CPP
  217.         UINT         TenantFromPoint(UINT, UINT, PCTenant *);
  218.         //CHAPTER13MOD
  219.         BOOL         DragDrop(UINT, UINT, UINT);
  220.         //End CHAPTER13MOD
  221.  
  222.     public:
  223.         CPage(DWORD, HWND, class CPages *);
  224.         ~CPage(void);
  225.  
  226.         DWORD       GetID(void);
  227.         BOOL        Open(LPSTORAGE);
  228.         void        Close(BOOL);
  229.         BOOL        Update(void);
  230.         void        Destroy(LPSTORAGE);
  231.         UINT        GetStorageName(LPOLESTR);
  232.  
  233.         void        Draw(HDC, int, int, BOOL, BOOL);
  234.  
  235.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  236.                         , PPATRONOBJECT, DWORD);
  237.         BOOL        TenantDestroy(void);
  238.         BOOL        TenantClip(BOOL);
  239.         BOOL        FQueryObjectSelected(HMENU);
  240.  
  241.         //PAGEMOUSE.CPP
  242.         BOOL        OnLeftDown(UINT, UINT, UINT);
  243.         BOOL        OnLeftDoubleClick(UINT, UINT, UINT);
  244.         BOOL        OnLeftUp(UINT, UINT, UINT);
  245.         void        OnMouseMove(UINT, int, int);
  246.         void        OnTimer(UINT);
  247.         void        StartSizeTracking(void);
  248.         void        OnNCHitTest(UINT, UINT);
  249.         BOOL        OnSetCursor(UINT);
  250.     };
  251.  
  252. typedef CPage *PCPage;
  253.  
  254.  
  255.  
  256. /*
  257.  * Structures to save with the document describing the device
  258.  * configuration and pages that we have.  This is followed by
  259.  * a list of DWORD IDs for the individual pages.
  260.  */
  261.  
  262. typedef struct tagDEVICECONFIG
  263.     {
  264.     DWORD       cb;                         //Size of structure
  265.     TCHAR       szDriver[CCHDEVICENAME];
  266.     TCHAR       szDevice[CCHDEVICENAME];
  267.     TCHAR       szPort[CCHDEVICENAME];
  268.     DWORD       cbDevMode;                  //Size of actual DEVMODE
  269.     DEVMODE     dm;                         //Variable
  270.     } DEVICECONFIG, *PDEVICECONFIG;
  271.  
  272. //Offset to cbDevMode
  273. #define CBSEEKOFFSETCBDEVMODE  (sizeof(DWORD)   \
  274.                                +(3*CCHDEVICENAME*sizeof(TCHAR)))
  275.  
  276. //Combined OLE and Patron device structures.
  277. typedef struct tagCOMBINEDEVICE
  278.     {
  279.     DVTARGETDEVICE  td;
  280.     DEVICECONFIG    dc;
  281.     } COMBINEBDEVICE, *PCOMBINEDEVICE;
  282.  
  283.  
  284. typedef struct tagPAGELIST
  285.     {
  286.     DWORD       cPages;
  287.     DWORD       iPageCur;
  288.     DWORD       dwIDNext;
  289.     } PAGELIST, *PPAGELIST;
  290.  
  291.  
  292. //PRINT.CPP
  293. BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  294. BOOL    APIENTRY AbortProc(HDC, int);
  295.  
  296.  
  297. //PAGEWIN.CPP
  298. LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  299. void             RectConvertMappings(LPRECT, HDC, BOOL);
  300.  
  301.  
  302. class CPages : public CWindow
  303.     {
  304.     friend LRESULT APIENTRY PagesWndProc(HWND, UINT, WPARAM, LPARAM);
  305.     friend BOOL    APIENTRY PrintDlgProc(HWND, UINT, WPARAM, LPARAM);
  306.  
  307.     friend class CPage;
  308.     friend class CTenant;
  309.     //CHAPTER13MOD
  310.     friend class CDropTarget;
  311.     //End CHAPTER13MOD
  312.  
  313.     protected:
  314.         PCPage      m_pPageCur;             //Current page
  315.         UINT        m_iPageCur;             //Current page
  316.         UINT        m_cPages;               //Number of pages
  317.  
  318.         HWND        m_hWndPageList;         //Listbox with page list
  319.         HFONT       m_hFont;                //Page font
  320.         BOOL        m_fSystemFont;          //m_hFont system object?
  321.  
  322.         UINT        m_cx;                   //Page size in LOMETRIC
  323.         UINT        m_cy;
  324.  
  325.         UINT        m_xMarginLeft;          //Unusable margins,
  326.         UINT        m_xMarginRight;         //in LOMETRIC
  327.         UINT        m_yMarginTop;
  328.         UINT        m_yMarginBottom;
  329.  
  330.         UINT        m_xPos;                 //Viewport scroll pos,
  331.         UINT        m_yPos;                 //both in *PIXELS*
  332.  
  333.         DWORD       m_dwIDNext;             //Next ID for a page.
  334.         LPSTORAGE   m_pIStorage;            //Root storage
  335.  
  336.         UINT        m_cf;                   //Clipboard format
  337.         BOOL        m_fDirty;
  338.  
  339.         //CHAPTER13MOD
  340.         BOOL        m_fDragSource;          //Source==target?
  341.         BOOL        m_fMoveInPage;          //Moving in same page
  342.         POINTL      m_ptDrop;               //Where to move object
  343.  
  344.         BOOL        m_fDragRectShown;       //Is rect on the screen?
  345.         UINT        m_uScrollInset;         //Hit-test for drag-drop
  346.         UINT        m_uScrollDelay;         //Delay before repeat
  347.         DWORD       m_dwTimeLast;           //Ticks on last DragOver
  348.         UINT        m_uHScrollCode;         //L/R on scroll repeat?
  349.         UINT        m_uVScrollCode;         //U/D on scroll repeat?
  350.         UINT        m_uLastTest;            //Last test result
  351.         POINTL      m_ptlRect;              //Last feedback rectangle
  352.         SIZEL       m_szlRect;
  353.         //End CHAPTER13MOD
  354.  
  355.     protected:
  356.         void        Draw(HDC, BOOL, BOOL);
  357.         void        UpdateScrollRanges(void);
  358.         BOOL        ConfigureForDevice(void);
  359.         BOOL        PageGet(UINT, PCPage *, BOOL);
  360.         BOOL        PageAdd(UINT, DWORD, BOOL);
  361.  
  362.         void        CalcBoundingRect(LPRECT, BOOL);
  363.  
  364.         //CHAPTER13MOD
  365.         //DRAGDROP.CPP
  366.         UINT        UTestDroppablePoint(PPOINTL);
  367.         void        DrawDropTargetRect(PPOINTL, LPSIZEL);
  368.         void        AdjustPosition(PPOINTL, LPSIZEL);
  369.         //End CHAPTER13MOD
  370.  
  371.  
  372.     public:
  373.         CPages(HINSTANCE, UINT);
  374.         ~CPages(void);
  375.  
  376.         BOOL        Init(HWND, LPRECT, DWORD, UINT, LPVOID);
  377.  
  378.         BOOL        StorageSet(LPSTORAGE, BOOL, BOOL);
  379.         BOOL        StorageUpdate(BOOL);
  380.  
  381.         BOOL        Print(HDC, LPTSTR, DWORD, UINT, UINT, UINT);
  382.  
  383.         void        RectGet(LPRECT);
  384.         void        RectSet(LPRECT, BOOL);
  385.         void        SizeGet(LPRECT);
  386.         void        SizeSet(LPRECT, BOOL);
  387.  
  388.         PCPage      ActivePage(void);
  389.         UINT        PageInsert(UINT);
  390.         UINT        PageDelete(UINT);
  391.         UINT        CurPageGet(void);
  392.         UINT        CurPageSet(UINT);
  393.         UINT        NumPagesGet(void);
  394.  
  395.         BOOL        DevModeSet(HGLOBAL, HGLOBAL);
  396.         HGLOBAL     DevModeGet(void);
  397.  
  398.         BOOL        FIsDirty(void);
  399.         BOOL        DevReadConfig(PCOMBINEDEVICE *, HDC *);
  400.         BOOL        TenantCreate(TENANTTYPE, LPVOID, LPFORMATETC
  401.                         , PPATRONOBJECT, DWORD);
  402.         BOOL        TenantDestroy(void);
  403.         BOOL        TenantClip(BOOL);
  404.         BOOL        FQueryObjectSelected(HMENU);
  405.     };
  406.  
  407. typedef CPages *PCPages;
  408.  
  409.  
  410. //Fixed names of streams in the Pages IStorage
  411. #define SZSTREAMPAGELIST        OLETEXT("Page List")
  412. #define SZSTREAMDEVICECONFIG    OLETEXT("Device Configuration")
  413.  
  414. //CHAPTER13MOD
  415. //Return values for UTestDroppablePoint
  416. #define UDROP_NONE              0x0000      //Exclusive
  417. #define UDROP_CLIENT            0x0001      //Inclusive
  418. #define UDROP_INSETLEFT         0x0002      //L/R are exclusive
  419. #define UDROP_INSETRIGHT        0x0004
  420. #define UDROP_INSETHORZ         (UDROP_INSETLEFT | UDROP_INSETRIGHT)
  421.  
  422. #define UDROP_INSETTOP          0x0008      //T/B are exclusive
  423. #define UDROP_INSETBOTTOM       0x0010
  424. #define UDROP_INSETVERT         (UDROP_INSETTOP | UDROP_INSETBOTTOM)
  425. //End CHAPTER13MOD
  426.  
  427. #endif  //_PAGES_H_
  428.