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

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