home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / VFORM.ZIP / Source / vform.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-10  |  29.7 KB  |  702 lines

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5. #ifndef __VFORM_H__
  6. #define __VFORM_H__
  7.  
  8. #ifdef VF_STATIC
  9.     #undef AFX_EXT_CLASS
  10.     #define AFX_EXT_CLASS
  11. #endif
  12.  
  13. #include "VRow.h"
  14. #include "afxtempl.h"
  15. // #include "CircTpl.h"
  16. #include "NumList.h"
  17. #include "VCtlHelp.h"
  18. #include "VfUtil.h"
  19. #include "VfScrollTip.h"
  20.  
  21. // #ifdef VF_DRAGDROP
  22.     #include "VfOleDropTarget.h"
  23. // #endif
  24.  
  25. #define VFR_SCREEN        1
  26. #define VFR_MEMORY        2
  27. #define VFR_BOTH        3
  28. #define VFRS_NORMALROW    0
  29. #define VFRS_FOCUSROW    1
  30. #define VFRS_ADDROW        2
  31. #define VFCTL_FIRST        0
  32. #define VFCTL_SAME        1
  33. #define VFCTL_LAST        2
  34. #define VFCTL_SECT        3
  35.  
  36. #define VFSECT_HDR        0x01
  37. #define VFSECT_DTL        0x02
  38. #define VFSECT_FTR        0x04
  39.  
  40. #define VFMOUSE_IDLE            0
  41. #define VFMOUSE_COL_SELECTING    1
  42. #define VFMOUSE_COL_SIZING        2
  43. #define VFMOUSE_COL_MOVING        3
  44. #define VFMOUSE_ROW_SIZING        4
  45.  
  46. #define VFPRINT_SCREEN            0
  47. #define VFPRINT_ALL                1
  48. #define VFPRINT_SELECTED        2
  49.  
  50. #define VFGRID_FLAT                0
  51. #define VFGRID_SUNKEN            1
  52. #define VFGRID_RAISED            2
  53. #define VFGRID_NOLINES            3
  54. #define VFGRID_VERTLINES        4
  55. #define VFGRID_HORZLINES        5
  56. #define VFGRID_ALTERNATING        6
  57.  
  58. #define VFORM_CLASSNAME    _T("VFormControl")
  59.  
  60. #define VMAX_HELPER_CTLS    10
  61.  
  62. #define IDC_VFORM_LIST        300
  63.  
  64. // This setting always displays a vertical scrollbar
  65. // - but its position is always 100% accurate
  66. // #define VF_VERTSCROLL_MAX    m_nRows + m_nRowsPerScreen - 2
  67.  
  68. // This setting will hide the vertical scrollbar if its not needed
  69. // - but there will be a "jump" if using the scrollbar after manually
  70. //   scrolling the last row past the bottom of the screen
  71. //   - this is because the actual row position is > the max scroll position
  72. #define VF_VERTSCROLL_MAX    m_nRows - 1
  73.  
  74. // --- Forward Declarations ---
  75. class CVfBldrDoc;
  76. class CVfbSection;
  77. class VfbCtl;
  78.  
  79. // -------------------------------------------------------------------------
  80. // VFormRegistrar 
  81. //    - Registers VFormControl - using a global instance of this class
  82. // -------------------------------------------------------------------------
  83. class AFX_EXT_CLASS VFormRegistrar
  84. {
  85. protected:
  86.     static BOOL m_bRegistered;
  87. public:
  88.     VFormRegistrar();                // Ensures VForm WndClass is registered
  89.     static BOOL IsRegistered() { return m_bRegistered; }
  90. };
  91.  
  92. // -------------------------------------------------------------------------
  93. // VfGridCol 
  94. //    - VForm grid column
  95. // -------------------------------------------------------------------------
  96. class VfGridCol
  97. {
  98. protected:
  99.     VCtl*    m_pCtl;            // Active Control
  100.     VCtl*    m_pTmpCtl;        // Temporary Control
  101.     int        m_nWidth;        // Width of the column
  102. public:
  103.     VfGridCol() {};
  104.  
  105.     void    Ctl(VCtl *pCtl)            { m_pCtl = pCtl; }
  106.     void    TmpCtl(VCtl *pCtl)        { m_pTmpCtl = pCtl; }
  107.     void    Width(int nWidth)        { m_nWidth = nWidth; }
  108.  
  109.     VCtl*    Ctl()                    { return m_pCtl; }
  110.     VCtl*    TmpCtl()                { return m_pTmpCtl; }
  111.     int        Width()                    { return m_nWidth; }
  112. };
  113.  
  114. typedef CArray<VfGridCol, VfGridCol&> VfGridColArray;
  115.  
  116. // -------------------------------------------------------------------------
  117. // VForm 
  118. //    - uses mapping modes to let rows draw themselves (always at same offsets)
  119. // -------------------------------------------------------------------------
  120. class AFX_EXT_CLASS VForm : public CWnd
  121. {
  122. protected:
  123.     // Base Data Members
  124.     CBitmap        m_bmMem;            // Memory Bitmap of screen
  125.     VCtlHelper*    m_ctlHelper[VMAX_HELPER_CTLS];    // helper controls
  126.     int            m_nHelperId;        // Index of current helper control
  127.     CListBox    m_ctlList;            // ListBox Control
  128.     VfScrollTip    m_ctlScrollTip;        // Scroll tip control
  129.     VNumList    m_selectedList;        // List of selected Row Ids
  130.  
  131.     // Section Info - Header, Detail, Footer
  132.     int            m_nSection;            // Which section is current
  133.     VHeader*    m_pHeader;            // Pointer to Header Row
  134.     VHeader*    m_pFooter;            // Pointer to Footer Row
  135.     VRow*        m_pDtlRow;            // Current Edit Row
  136.     VRow*        m_pTmpRow;            // Temporary Row
  137.     int            m_nHdrCtl;            // Current Header Control Index
  138.     int            m_nFtrCtl;            // Current Footer Control Index
  139.     int            m_nDtlCtl;            // Current Detail Control Index
  140.     int            m_nFormHdrHeight;    // height of the form header
  141.     int            m_nHeaderHeight;    // height of the header
  142.     int            m_nFooterHeight;    // height of the footer
  143.     
  144.     // State Info
  145.     BOOL        m_bAdding;            // Adding a row currently?
  146.     BOOL        m_bListBoxOpen;        // Are we using the listbox
  147.     BOOL        m_bSelecting;        // In the middle of a selection?
  148.     BOOL        m_bSelectPrimed;    // Was last action for selection?
  149.     long        m_nSelStartRowId;        // Starting Row for selecting
  150.     BOOL        m_bCaptureOn;        // Are we capturing mouse input
  151.     BOOL        m_bShiftKey;        // Is Shift key down
  152.     BOOL        m_bCtlKey;            // Is Control key down
  153.     BOOL        m_bScrolling;        // Are we scrolling
  154.     int            m_nScrollCnt;        // How many lines/pages we have scrolled
  155.     BOOL        m_bHelperSaved;        // Has helper ctl been saved?
  156.                                     // - used during scrolling
  157.  
  158.     long        m_nTopRowId;        // Row Id of Top Row
  159.     long        m_nCurRowId;        // Current Row Id
  160.  
  161.     CSize        m_size;                // size of the screen
  162.     SCROLLINFO    m_si;                // keep the scrolling info
  163.     SCROLLINFO    m_siHorz;            // the horizontal scrolling info
  164.     long        m_nRows;            // number of rows in the data
  165.     int            m_nRowsPerScreen;    // number of rows visible on one screen
  166.  
  167.     // Settings
  168.     CFont*    m_pFont;            // Default font
  169.     int        m_nRowHeight;        // height of one row
  170.     int        m_nFormRowHeight;    // height of one row when in Form Mode
  171.     int        m_nRowWidth;        // width of one row
  172.     BOOL    m_bReadOnly;        // Is Entire VForm Read Only
  173.     BOOL    m_bAllowAdd;        // Allow adding of rows
  174.     BOOL    m_bSnapResize;        // TRUE to resize to a row boundary when resizing
  175.     BOOL    m_bAllowRowSizing;    // Allow Row Sizing
  176.     BOOL    m_bLiveAdjust;        // TRUE for Live Adjustments
  177.     BOOL    m_bMultiColSelect;    // Allow multiple column select (grid mode)
  178.     BOOL    m_bAutoSelect;        // TRUE for automatic selecting behavior
  179.     BOOL    m_bUseSelectors;    // TRUE to use selector tabs
  180.     BOOL    m_bDrawSelectRows;    // TRUE to redraw entire row when selected
  181.     int        m_nSelectorWidth;    // Width of one selector
  182.     int        m_nCurSelWidth;        // Current selector width
  183.  
  184.     // ---- Drag & Drop ----
  185.     VfOleDropTarget    m_dropTarget;    // Our Ole Drop Target
  186.     BOOL    m_bUseAsDropTarget;    // TRUE if we are a drop target
  187.     long    m_nDropRowId;        // Drop row id
  188.  
  189.     // ---- Printing/Reports ----
  190.     int        m_nRowsPerPage;        // Number of detail lines per page
  191.     int        m_nPrintStyle;        // What we should print
  192.     int        m_nPageHeight;        // Height of the report page
  193.     int        m_nPageWidth;        // Width of the report page
  194.     BOOL    m_bUseRptForm;        // Use a custom report form for printing
  195.     VRow*    m_pRptHdr;            // Custom Report Header
  196.     VRow*    m_pRptDtl;            // Custom Report Detail
  197.     VRow*    m_pRptFtr;            // Custom Report Footer
  198.  
  199.     // ---- Grid Mode ----
  200.     BOOL    m_bGridMode;        // TRUE when in grid mode
  201.     BOOL    m_bGridColsSizable; // TRUE if grid columns are sizable
  202.     BOOL    m_bGridColsMoveable; // TRUE if grid columns are moveable
  203.     int        m_nGridHdrHeight;    // height of the grid header
  204.     int        m_nGridRowHeight;    // height of one row when using Grid View
  205.     int        m_nGridCol;            // current grid column - when sizing
  206.     int        m_nGridCol1;        // Anchor when selecting columns
  207.     int        m_nGridCol2;        // Non-Anchor when selecting multiple columns
  208.     int        m_nGridFrozenCols;    // No of frozen columns on the grid
  209.     VfGridColArray m_gridCtl;    // Array of controls in grid
  210.     BOOL    m_bInGridHeading;    // Is control in the Grid Column Headings?
  211.     BOOL    m_bColsSelected;    // Did user just select multiple columns?
  212.     int        m_nMouseState;        // Mouse state
  213.     VColor  m_vclrHidden;        // Hidden area color
  214.     VColor  m_vclrGridBack;        // Grid background color
  215.     VColor  m_vclrGridLine;        // Grid line color
  216.     int        m_nGridStyle;        // Grid Style
  217.     int        m_nAdjustX;            // X position used when column sizing
  218.     int        m_nBaseY;            // Base Y position used when row sizing
  219.     int        m_nAdjustY;            // Y position used when row sizing
  220.  
  221.     // ---- Context Menu Support ----
  222.     // you can additionally override OnContextMenu
  223.     UINT    m_nGridHdrContextMenu;    // Context menu for the Grid Header
  224.     CPoint    m_ptContextMenu;        // point where context menu click occured
  225.  
  226.     // ---- Static Members ----
  227.     static VFonts    m_fonts;    // Static list of fonts
  228.         
  229. public:
  230.     VForm();                    // Constructor
  231.     virtual ~VForm();            // Destructor
  232.  
  233.     // --------------- Initialization Functions ------------
  234.     BOOL    Create(LPCTSTR lpszWindowName, const RECT& rect, CWnd* pParentWnd,
  235.                 UINT nID, DWORD dwStyle=0, DWORD dwExStyle=0);
  236.     int        Init();
  237.  
  238.     // ---- Settings ----
  239.     BOOL    ReadOnly()                    { return m_bReadOnly; }
  240.     void    ReadOnly(BOOL bFlag)        { m_bReadOnly = bFlag; }
  241.     BOOL    AllowAdd()                    { return m_bAllowAdd; }
  242.     void    AllowAdd(BOOL bFlag)        { m_bAllowAdd = bFlag; }
  243.     void    LiveAdjust(BOOL bFlag)        { m_bLiveAdjust = bFlag; }
  244.     BOOL    LiveAdjust()                { return m_bLiveAdjust; }
  245.     void    AllowRowSizing(BOOL bFlag)    { m_bAllowRowSizing = bFlag; }
  246.     BOOL    AllowRowSizing()            { return m_bAllowRowSizing; }
  247.     BOOL    SnapResize()                { return m_bSnapResize; }
  248.     void    SnapResize(BOOL bFlag)        { m_bSnapResize = bFlag; }
  249.     BOOL    UseSelectors()                { return m_bUseSelectors; }
  250.     void    UseSelectors(BOOL bFlag);
  251.     BOOL    ScrollTips()                { return m_ctlScrollTip.IsOn(); }
  252.     void    ScrollTips(BOOL bFlag)        { m_ctlScrollTip.IsOn(bFlag); }
  253.     void    HiddenColor(COLORREF clr)    { m_vclrHidden.CustomRGB(clr); }
  254.     void    HiddenColor(VColor &vclr)    { m_vclrHidden = vclr; }
  255.     COLORREF    HiddenColor()            { return m_vclrHidden.GetRGB(); }
  256.  
  257.     // ---- Print Settings ----
  258.     int        PrintStyle()                { return m_nPrintStyle; }
  259.     void    PrintStyle(int nStyle)        { m_nPrintStyle = nStyle; }
  260.     BOOL    UseRptForm()                { return m_bUseRptForm; }
  261.     void    UseRptForm(BOOL bFlag)        { m_bUseRptForm = bFlag; }
  262.  
  263.     // ---- VForm Builder .vfb load Functions ----
  264.     BOOL    LoadVfbFile(LPCTSTR szVfbFile, CVfBldrDoc *pVfbDoc=NULL, 
  265.                 BOOL bRptLoad=FALSE);
  266.     BOOL    LoadRptVfbFile(LPCTSTR szVfbFile, CVfBldrDoc *pVfbDoc=NULL); 
  267.     void    LoadVfbData(CVfBldrDoc *pVfbDoc);
  268.     void    LoadRptVfbData(CVfBldrDoc *pVfbDoc);
  269.     void    CopyBasicVfbAttribs(VCtl *p, VfbCtl *pCtl, VRow *pRow);
  270.     void    CreateCtlsFromVfb(VRow *pRow, CVfbSection *pSect);
  271.  
  272.     // ---- Drag & Drop functions ----
  273.     BOOL    UseAsDropTarget()            { return m_bUseAsDropTarget; }
  274.     BOOL    UseAsDropTarget(BOOL bFlag);
  275.     virtual void        SelectDropTarget(long nRowId=-1);
  276.     virtual DROPEFFECT    OnDragEnter(CWnd *pWnd, COleDataObject* pDataObject, 
  277.                                         DWORD dwKeyState, CPoint point);
  278.     virtual    void        OnDragLeave(CWnd *pWnd);
  279.     virtual DROPEFFECT    OnDragOver(CWnd *pWnd, COleDataObject* pDataObject, 
  280.                                         DWORD dwKeyState, CPoint point);
  281.     virtual DROPEFFECT    OnDropEx(CWnd *pWnd, COleDataObject* pDataObject, 
  282.                                         DROPEFFECT dropDefault, 
  283.                                         DROPEFFECT dropList, CPoint point);
  284.     virtual BOOL        OnDrop(CWnd *pWnd, COleDataObject* pDataObject, 
  285.                                         DROPEFFECT dropEffect, CPoint point);
  286.     virtual DROPEFFECT    OnDragScroll(CWnd *pWnd, DWORD dwKeyState, CPoint point);
  287.     virtual BOOL        OnDrop(long nRowId, COleDataObject* pDataObject, 
  288.                                         DROPEFFECT dropEffect);
  289.     virtual BOOL        OnBeginDrag(long nRowId) { return FALSE; }
  290.  
  291.     // ---- Grid Mode ----
  292.     BOOL    GridMode()                    { return m_bGridMode; }
  293.     void    GridMode(BOOL bMode);        // Turn Grid Mode On/Off
  294.     void    CreateGrid();    
  295.  
  296.     CString    GetGridSettings();    
  297.     void    SetGridSettings(LPCTSTR szSettings, BOOL bSetHeight=TRUE, BOOL bSetWidths=TRUE);    
  298.  
  299.     int        GridStyle()                    { return m_nGridStyle; }
  300.     void    GridStyle(int nStyle)        { m_nGridStyle = nStyle; }
  301.     void    GridBackColor(COLORREF clr)    { m_vclrGridBack.UseCustomRGB(clr); }
  302.     void    GridBackColor(VColor &vclr)    { m_vclrGridBack = vclr; }
  303.     COLORREF    GridBackColor()            { return m_vclrGridBack.GetRGB(); }
  304.     void    GridLineColor(COLORREF clr)    { m_vclrGridLine.CustomRGB(clr); }
  305.     void    GridLineColor(VColor &vclr)    { m_vclrGridLine = vclr; }
  306.     COLORREF    GridLineColor()            { return m_vclrGridLine.GetRGB(); }
  307.  
  308.     BOOL    GridColsSizable()            { return m_bGridColsSizable; }
  309.     void    GridColsSizable(BOOL bFlag){ m_bGridColsSizable = bFlag; }
  310.     BOOL    GridColsMoveable()            { return m_bGridColsMoveable; }
  311.     void    GridColsMoveable(BOOL bFlag){ m_bGridColsMoveable = bFlag; }
  312.     int        GridHdrHeight()            { return m_nGridHdrHeight; }
  313.     void    GridHdrHeight(int nHeight);    // Sets the Grid header height
  314.     int        GridRowHeight()                { return m_nGridRowHeight; }
  315.     void    GridRowHeight(int nHeight)    { m_nGridRowHeight = nHeight; }
  316.  
  317.     int        GridCol()                    { return m_nGridCol; }
  318.     int        GridFirstCol()                { return m_siHorz.nPos; }
  319.     int        GridColCount()                { return m_gridCtl.GetSize(); }
  320.     int        GridFrozenColCount()        { return m_nGridFrozenCols; }
  321.     void    GridFrozenColCount(int nCount)    { m_nGridFrozenCols = nCount; }
  322.     int        GridWidth();                    // Returns width of grid columns
  323.     int        GridWidthVisCols(CRect rect);    // Returns width of visible columns
  324.  
  325.     void    MultiColSelect(BOOL bFlag)    { m_bMultiColSelect = bFlag; }
  326.     BOOL    MultiColSelect()            { return m_bMultiColSelect; }
  327.     void    ColsSelected(BOOL bFlag)    { m_bColsSelected = bFlag; }
  328.     BOOL    ColsSelected()                { return m_bColsSelected; }
  329.     BOOL    InGridHeading()                { return m_bInGridHeading; }
  330.  
  331.     void    GridHdrContextMenu(UINT nMenuID)    { m_nGridHdrContextMenu = nMenuID; }
  332.     UINT    GridHdrContextMenu()        { return m_nGridHdrContextMenu; }
  333.     CPoint    GetContextMenuPoint()        { return m_ptContextMenu; }
  334.  
  335.     // ---- Grid Mode Internal ----
  336.     int        GridPageLeft();                // Returns column to make first
  337.     int        GridPageRight();            // Returns column to make first
  338.     int        GridLastVisCol(BOOL &bPartial);    // Returns the last visible column
  339.     int        GridFirstColForVisLast();    // First column to make last visible
  340.     int        GetGridColToSize(CPoint pt);// Checks point position
  341.     int        GetGridRowToSize(CPoint pt);// Checks point position
  342.  
  343.     void    DrawGridHeader(CDC *pDC, CRect rect);            // Draws the grid header
  344.     void    DrawGridRow(CDC *pDC, CRect rect, VRow *pRow);    // Draws a grid row
  345.     void    DrawGridCtl(CDC *pDC, VCtl *pCtl);                // Draws a grid Control
  346.     void    DrawGridCell(CDC *pDC, VCtl *pCtl, CRect rectCell,    // Draws a Grid Cell
  347.                         CBrush &brBack, CPen &penLine);
  348.     void    Draw3dCell(CDC *pDC, CRect rect, CBrush &brBack, BOOL bIn=TRUE);
  349.     CRect    GridRect(int nCtlIdx);                    // Rect of specified cell
  350.     void    GetGridFirstLastX(int& nFirstX, int& nLastX);
  351.     void    GetGridLeftRightSelCols(int &nLeftCol, int &nRightCol);
  352.     CRect    GridHelperRect(int nCtlIdx);            // Rect of control in cell
  353.     int        GetGridCtlIdx(CPoint pt);                // Gets index of specified control
  354.     int        GetGridCtlIdx(int nCtlPos, int nCurCtl); // Gets index of specified control
  355.     int        GetGridCtlIdx(VCtl *pCtl);            // Gets index of specified control
  356.     int        GetGridCtlIdx(LPCTSTR szCtlName);    // Gets index of specified control
  357.     void    ProcessGridTab();                    // Called when tab key is pressed
  358.  
  359.     void    ColSelecting(CPoint point);            // Called when selecting columns
  360.     void    LiveColMoving(CPoint point);        // Called when moving a column
  361.     void    NonLiveColMoving(CPoint point);        // Called when moving a column
  362.  
  363.     // ----------- Printing Functions -------------------
  364.     void    DoPrepareDC(CDC* pDC, CPrintInfo* pInfo); 
  365.     BOOL    DoPreparePrinting(CView *pView, CPrintInfo* pInfo);
  366.     void    CalcPageInfo(CDC* pDC, CPrintInfo* pInfo);
  367.     void    DoPrint(CDC* pDC, CPrintInfo* pInfo);
  368.     void    DoPrintScreen(CDC *pDC, CPrintInfo* pInfo=0); 
  369.     void    DoPrintAll(CDC *pDC, CPrintInfo* pInfo); 
  370.     void    DoPrintSelected(CDC *pDC, CPrintInfo* pInfo); 
  371.     void    DoPrintScreenAsReport(CDC *pDC, CPrintInfo* pInfo=0); 
  372.     void    DoPrintAllAsReport(CDC *pDC, CPrintInfo* pInfo); 
  373.     void    DoPrintSelectedAsReport(CDC *pDC, CPrintInfo* pInfo); 
  374.  
  375.     VRow*    GetRptHdr()                { return m_pRptHdr; }
  376.     VRow*    GetRptDtl()                { return m_pRptDtl; }
  377.     VRow*    GetRptFtr()                { return m_pRptFtr; }
  378.     void    SetRptHdr(VRow* pRow);    // Sets the Report Header
  379.     void    SetRptDtl(VRow* pRow);    // Sets the Report Detail
  380.     void    SetRptFtr(VRow* pRow);    // Sets the Report Footer
  381.  
  382.     // -------------- Primary Functions --------------
  383.     void    ResetNumRows(long xNumRows, long nRowId=-1);    // Resets the window
  384.     void    ResizeToParent();                        // Resize window to parents size
  385.  
  386.     // ----------- Reset/Set Section/Control Functions ---------
  387.     BOOL    GoToRow(long nRowId);
  388.     BOOL    GoToRowOld(long nRowId);        // Older simpler version
  389.     BOOL    CycleSection(BOOL bRepaint);    // Changes to next section
  390.     BOOL    ChangeSection(int nSection, int nCtlPos, BOOL bRepaint);
  391.     BOOL    ChangeSectionAndCtl(int nSection, int nCtl, BOOL bRepaint);
  392.     BOOL    SetCurRow(long nRowId, int nCtlPos, BOOL bRepaint=TRUE);
  393.     BOOL    SetCurRowAndCtl(long nRowId, long nCtl=-1, BOOL bRepaint=TRUE);
  394.     BOOL    SetCurRowAndCtl(long nRowId, CPoint point, BOOL bRepaint=TRUE);
  395.     void    ResetSelectors(long nRowId, BOOL bCtlKey, BOOL bShiftKey);
  396.     void    ResetVertScroll(BOOL bRedraw=TRUE);        // Reset Vertical Scroll settings
  397.     void    ResetHorzScroll(BOOL bRedraw=TRUE);        // Reset Horizontal Scroll settings
  398.     BOOL    SaveCurRow(BOOL bCancelAdd=FALSE, BOOL bChangeRow=TRUE);
  399.     void    SetCurCtlOnSameRow(int nCtl, BOOL bToScreen=TRUE, 
  400.                         BOOL bActivateHelper=TRUE);
  401.     void    SaveCurCtl();
  402.  
  403.     BOOL    StartAddRow();                    // Starts Adding a row
  404.     void    CancelAdd();                            // Cancel Add Mode 
  405.  
  406.     // -------- Header/Footer/Detail Section and Control Functions ------
  407.     VHeader*    Header()    { return m_pHeader; }
  408.     VHeader*    Footer()    { return m_pFooter; }
  409.     void        SetHeader(VHeader* pHeader, BOOL bRedraw);
  410.     void        SetDetailRows(VRow *pDtlRow, VRow *pTmpRow, BOOL bRedraw); 
  411.     void        SetFooter(VHeader* pFooter, BOOL bRedraw);
  412.     VRow*    ActiveSection();
  413.     VRow*    DtlRow()        { return m_pDtlRow; }
  414.     VCtl*    DtlCtl()        { return m_pDtlRow->GetCtlPtr(m_nDtlCtl); }
  415.     VCtl*    DtlCtl(int nCtl){ return m_pDtlRow->GetCtlPtr(nCtl); }
  416.     int        DtlCtlIdx()        { return m_nDtlCtl; }
  417.     int        ActiveCtlIdx();                    // Returns idx of active control
  418.     void    ActiveCtlIdx(int nCtl);            // Sets Idx of active control
  419.     VCtl*    ActiveCtl();                    // Returns active control Ptr
  420.     VCtl*    ActiveCtl(int nCtl);            // Returns pointer to specified ctl
  421.     BOOL    IsActiveCtlAMultiLineEdit();    // check for a multi-line edit ctl
  422.     BOOL    IsDtlRow(VRow *pRow);            // Returns TRUE if row is a Dtl Row
  423.  
  424.     // --------------- Static Members/Functions --------------
  425.     static    BOOL IsRegistered() { return VFormRegistrar::IsRegistered(); }
  426.     afx_msg LRESULT OnMyMessage(WPARAM wParam, LPARAM lParam);
  427.  
  428.     // DECLARE_DYNCREATE(VForm)
  429.  
  430.     // ----------- Row State Functions -------------------
  431.     BOOL    IsRowSelected(long nRowId);
  432.     BOOL    IsRowHidden(long nRowId){ return (nRowId >= m_nRows); }
  433.     BOOL    IsFocusRow(long nRowId)    { return (nRowId == CurRowId()); }
  434.     BOOL    IsRowVisible(long x)    
  435.             { return (x >= m_nTopRowId && x < m_nTopRowId + m_nRowsPerScreen); }
  436.     BOOL    IsAnyPartOfRowVisible(long x)    
  437.             { return (x >= m_nTopRowId && x <= m_nTopRowId + m_nRowsPerScreen); }
  438.     BOOL    IsRowPartiallyVisible(long x)    
  439.             { return x == m_nTopRowId + m_nRowsPerScreen; }
  440.     BOOL    GetRowRect(VRow *pRow, CRect &rectRow, CRect &rectClip);
  441.  
  442.     // ----------- Selector Tab Functions -------------------
  443.     BOOL    AutoSelect()            { return m_bAutoSelect; }
  444.     void    AutoSelect(BOOL bFlag)    { m_bAutoSelect = bFlag; }
  445.     BOOL    DrawSelectRows()            { return m_bDrawSelectRows; }
  446.     void    DrawSelectRows(BOOL bFlag)    { m_bDrawSelectRows = bFlag; }
  447.     int        SelectorWidth()            { return m_nSelectorWidth; }
  448.     void    SelectorWidth(int nWidth)
  449.             { m_nSelectorWidth = nWidth; 
  450.               if(m_bUseSelectors) m_nCurSelWidth = m_nSelectorWidth; 
  451.               ResetHorzScroll(); }
  452.     int        CurSelectorWidth()        { return m_nCurSelWidth; }
  453.  
  454.     long    FirstSelected()            { return m_selectedList.First(); }
  455.     long    LastSelected()            { return m_selectedList.Last(); }
  456.     long    NextSelected()            { return m_selectedList.Next(); }
  457.     long    PrevSelected()            { return m_selectedList.Prev(); }
  458.     long    SelectedCount()            { return m_selectedList.Count(); }
  459.  
  460.     // ----------- Simple Values -------------------
  461.     BOOL    IsEmpty()            { return (m_nRows == 0); }
  462.     long    BtmVisibleRowId();    // Last Visible Row on the screen
  463.     long    TopRowId()        { return m_nTopRowId; }
  464.     long    BtmRowId()        { return m_nTopRowId + m_nRowsPerScreen - 1; }
  465.     long    CurRowId()        { return m_nCurRowId; }
  466.     long    LastRowId()        { return m_nRows - 1; }
  467.     long    AddRowId()        { return m_bAdding ? m_nRows - 1 : m_nRows; }
  468.     long    RowCount()        { return m_nRows; }
  469.     static  VFonts*    GetFonts()    { return &m_fonts; }
  470.  
  471.     // ----------- Get/Set Attributes --------------------
  472.     void    Font(CFont *pFont)        { m_pFont = pFont; }
  473.     CFont*    Font()                    { return m_pFont; }
  474.     int        RowHeight()                { return m_nRowHeight; }
  475.     void    RowHeight(int nHeight)    { m_nRowHeight = nHeight; }
  476.     int        RowWidth()                { return m_nRowWidth; }
  477.     void    RowWidth(int nWidth)    { m_nRowWidth = nWidth; ResetHorzScroll(); }
  478.     int        RowWidthMax()    
  479.             { return max(m_nRowWidth, (m_size.cx - m_nCurSelWidth)); }
  480.     int        FormHdrHeight()            { return m_nFormHdrHeight; }
  481.     void    FormHdrHeight(int nHeight);    // Sets the Form header height
  482.     int        FormRowHeight()                { return m_nFormRowHeight; }
  483.     void    FormRowHeight(int nHeight)    { m_nFormRowHeight = nHeight; }
  484.     int        HeaderHeight()            { return m_nHeaderHeight; }
  485.     int        FooterHeight()            { return m_nFooterHeight; }
  486.     int        TopOfFooter()            { return m_size.cy - m_nFooterHeight; }
  487.  
  488.     // ---------------------------------------------------------------------
  489.     // ----------- Internal Utility Functions used by VForm ------
  490.     // ---------------------------------------------------------------------
  491.  
  492.     // ----------- Functions to get Detail Controls/Indexes ------
  493.     int        GetNextDtlIdx(int nIdx);
  494.     int        GetPrevDtlIdx(int nIdx);
  495.     int        GetFirstDtlIdx();
  496.     int        GetLastDtlIdx();
  497.     int        GetDtlCtlIdx(CPoint pt, BOOL bMustBeLive=TRUE);
  498.     VCtl*    GetDtlCtlPtr(CPoint pt, BOOL bMustBeLive=TRUE);
  499.  
  500.     // ----------- Slot Functions - Used Internally -------------------
  501.     int        TopSlot()        { return 0; }                // Always 0
  502.     int        BtmSlot()        { return m_nRowsPerScreen - 1; }
  503.     int        BtmVisibleSlot();    // Last Visible slot on the screen
  504.     BOOL    IsSlotVisible(int x)            { return (x >= 0 && x <= BtmSlot()+1); }
  505.     int        CurSlot()        { return (m_nCurRowId - m_nTopRowId); }
  506.  
  507.     // ----------- Conversion Utility Functions - Used Internally ---------------
  508.     int        PointToSection(CPoint point);
  509.     int        PointToSlot(CPoint point);
  510.     long    GetRowId(CPoint point);
  511.     long    SlotToRow(int nSlot) { return (nSlot + m_nTopRowId); }
  512.     long    RowToSlot(long nRow) { return (nRow - m_nTopRowId); }
  513.     CRect    GetCtlRect(VCtl *pCtl);
  514.  
  515.     // ------------ Offset Rect - Used Internally -----------------
  516.     void    OffsetHdrToScreen(CRect &rect)
  517.             {    rect.OffsetRect((m_nCurSelWidth - m_siHorz.nPos), 0); }
  518.     void    OffsetFtrToScreen(CRect &rect)
  519.             {    rect.OffsetRect((m_nCurSelWidth - m_siHorz.nPos), 
  520.                     m_size.cy - m_nFooterHeight);
  521.             }
  522.     void    OffsetRowToScreen(CRect &rect, int nSlot)
  523.             { if(GridMode())
  524.                 rect.OffsetRect(m_nCurSelWidth,
  525.                     (nSlot * m_nRowHeight)+m_nHeaderHeight);
  526.                 else
  527.                 rect.OffsetRect((m_nCurSelWidth - m_siHorz.nPos),
  528.                     (nSlot * m_nRowHeight)+m_nHeaderHeight);
  529.             }
  530.     void    OffsetScreenToRow(CRect &rect, int nSlot)
  531.             { if(GridMode())
  532.                 rect.OffsetRect(m_nCurSelWidth * -1,
  533.                     ((nSlot * m_nRowHeight)+m_nHeaderHeight) * -1);
  534.                 else
  535.                 rect.OffsetRect((m_siHorz.nPos - m_nCurSelWidth),
  536.                     ((nSlot * m_nRowHeight)+m_nHeaderHeight) * -1);
  537.             }
  538.  
  539.     // ------------------ Offset Point -----------------
  540.     void    OffsetScreenToHdr(CPoint &pt) 
  541.             {    pt.x -= (m_nCurSelWidth - m_siHorz.nPos); }
  542.     void    OffsetScreenToFtr(CPoint &pt) 
  543.             {    pt.x -= (m_nCurSelWidth - m_siHorz.nPos); 
  544.                 pt.y -= (m_size.cy - m_nFooterHeight); 
  545.             }
  546.     void    OffsetRowToScreen(CPoint &pt, int nSlot) 
  547.             {    if(GridMode()) pt.x += (m_nCurSelWidth); 
  548.                 else pt.x += (m_nCurSelWidth - m_siHorz.nPos); 
  549.                 pt.y += ((nSlot * m_nRowHeight) + m_nHeaderHeight); 
  550.             }
  551.     void    OffsetScreenToRow(CPoint &pt, int nSlot) 
  552.             {    if(GridMode()) pt.x -= (m_nCurSelWidth); 
  553.                 else pt.x -= (m_nCurSelWidth - m_siHorz.nPos); 
  554.                 pt.y -= ((nSlot * m_nRowHeight) + m_nHeaderHeight); 
  555.             }
  556.  
  557.     // ------------------ Offset Value (X or Y) -----------------
  558.     int        OffsetRowToScreenY(int nSlot) 
  559.             { return ((nSlot * m_nRowHeight) + m_nHeaderHeight); }
  560.     int        OffsetScreenToRowY(int nSlot) 
  561.             { return (-((nSlot * m_nRowHeight) + m_nHeaderHeight)); }
  562.     int        OffsetRowToScreenX()
  563.             {    if (GridMode()) return m_nCurSelWidth;
  564.                 return (m_nCurSelWidth - m_siHorz.nPos); }
  565.     int        OffsetScreenToRowX()
  566.             {    if (GridMode()) return (m_nCurSelWidth * -1);
  567.                 return (m_siHorz.nPos - m_nCurSelWidth); }
  568.  
  569.     // ------------ Helper Control Functions -------------------
  570.     BOOL    UseHelperForCurCtl()
  571.             { VCtl *pCtl = ActiveCtl(); if(!pCtl) return FALSE;
  572.                         return pCtl->UseHelper(); }
  573.     VCtlHelper* GetHelperCtl();                // Returns NULL or helper pointer
  574.     VCtlHelper* GetOrCreateHelperCtl(VCtl *pCtl);
  575.     void    HideHelperCtl();                // Hides active helper (if any)
  576.     void    ActivateHelperCtl();            // Activates helper control
  577.     void    MoveHelperCtl();                // Moves helper control
  578.     void    ActivateListCtl();                // Activates list control
  579.     void    MoveListCtl();                    // Moves the list control
  580.     void    CloseListCtl();                    // Closes the list control
  581.  
  582.     // ------------------ Focus Functions ------------
  583.     //        OnSetFocus();
  584.     //        OnKillFocus();
  585.  
  586.     // ----------- Drawing Functions -------------------
  587.     void    ResetPalette(CDC *pDC);            // Resets the palette 
  588.  
  589.     //        void OnPaint();                    // Handled by Map
  590.     void    RefreshData();
  591.     void    RefreshScreen(int nRefreshType, 
  592.                 int nSectionFlags=VFSECT_HDR | VFSECT_DTL | VFSECT_FTR);
  593.     void    ShiftRowsUp(BOOL bToScreen, int nNumRowsToShift=1);
  594.     void    ShiftRowsDown(BOOL bToScreen, int nNumRowsToShift=1);    
  595.     void    DrawRow(long nRowId, BOOL bToScreen);    // Draws row (by Row Id)    
  596.     void    DrawRow(VRow *pRow, BOOL bToScreen);    // Draws a row on memdc
  597.     void    DrawSelector(long nRowId, BOOL bToScreen);    // Draws sel (by Row Id)    
  598.     void    DrawSelector(VRow *pRow, BOOL bToScreen);    // Draws a sel on memdc
  599.     void    DrawCtl(VCtl *pCtl, BOOL bToScreen);    // Draws a control on memdc
  600.     void    RefreshSelectors(int nRefreshType);        // Refreshes all selectors
  601.  
  602.     // --------------------------------------------------------------------
  603.     // ----------- FOLLOWING ARE IN vFrmScroll.cpp ------------------------
  604.     // --------------------------------------------------------------------
  605.     // ----------- Scrolling/Movement -------------------
  606.     void    ScrollStart();            // Must be called when scrolling starts
  607.     void    ScrollStop();            // Must be called when scrolling stops
  608.  
  609.     BOOL    ScrollUpOnePage(BOOL bChgCurRow=TRUE);
  610.     BOOL    ScrollDownOnePage(BOOL bChgCurRow=TRUE);
  611.  
  612.     BOOL    ScrollUpOneLine(BOOL bChgCurRow=TRUE, int nCtlPos=VFCTL_SAME);
  613.     BOOL    ScrollDownOneLine(BOOL bChgCurRow=TRUE, int nCtlPos=VFCTL_SAME);
  614.     BOOL    MoveUpOneLine(int nCtlPos=VFCTL_SAME);
  615.     BOOL    MoveDownOneLine(int nCtlPos=VFCTL_SAME);
  616.  
  617.     BOOL    ScrollHome(BOOL bMaxTop=FALSE);
  618.     BOOL    ScrollEnd(BOOL bMaxBtm=FALSE);
  619.     BOOL    ScrollToTop(long newTop, BOOL bChgCurRow=TRUE);
  620.  
  621.     // ------------------ Mouse/Keyboard Functions -------------
  622.     //        OnLButtonDown();
  623.     BOOL    OnLButtonDownDtl(UINT nFlags, CPoint point);
  624.     void    OnLButtonDownGridHdr(UINT nFlags, CPoint point);
  625.     //        OnLButtonUp();
  626.     //        OnKeyDown();
  627.     //        OnKeyUp();
  628.     //        PreTranslateMessage();    // Grabs Arrow/Tab key Msgs
  629.     void    ProcessTab();            // Process a tab key message
  630.  
  631.  
  632. protected:
  633.     // ------------------- Virtual Functions ---------------------------
  634.     virtual VRow*    InitRow()=0;                        // Create a new detail row
  635.     virtual VRow*    InitRptRow() { return InitRow(); }    // Create a new report detail row
  636.  
  637.     // --- the following functions deal with the Data ---
  638.     virtual    BOOL    OnGetRow(VRow* pRow)=0;            // Gets row for screen
  639.     // virtual    BOOL    OnGetRptRow(VRow* pRow)                    { return TRUE; }
  640.     virtual    BOOL    OnGetRptRow(VRow* pRow)                    { return OnGetRow(pRow); }
  641.     virtual BOOL    OnSaveRow(VRow* pRow)=0;        // Save row from screen
  642.     virtual BOOL    OnAddRow(VRow* pRow)=0;            // Add a data row
  643.     virtual BOOL    OkToAdd(long nRowId)                    { return TRUE; }
  644.     virtual void    OnStartAdd(VRow* pRow)                    {}
  645.     virtual void    OnCurrent(VRow* pRow)                    {}
  646.     virtual void    OnCurrentCtl(VCtl* pCtl)                {}
  647.     virtual BOOL    OnDelete(){ return FALSE; }        // Delete row(s)
  648.     virtual BOOL    OnBeginHelper(VCtl* pCtl, VCtlHelper* pHelper)    { return TRUE; }
  649.     virtual BOOL    OnEndHelper(VCtl* pCtl, VCtlHelper* pHelper)    { return TRUE; }
  650.     virtual BOOL    OnBeginList(VCtl* pCtl, CListBox* pLB)    { return TRUE; }
  651.     virtual BOOL    OnEndList(VCtl* pCtl, CListBox* pLB)    { return TRUE; }
  652.     virtual    void    OnDrawSelector(CDC *pDC, CRect rect, long nRowId);
  653.     virtual    BOOL    OnSelectorClick(long nRowId);
  654.     virtual    BOOL    OnGridRowColor(VRow* pRow, COLORREF &clrRow) { return FALSE; }
  655.     virtual CPalette* GetPalette()                            { return NULL; }
  656.  
  657. public:
  658.     virtual void    OnClick(VRow* pRow, int nId) {};        // Button clicked
  659.     virtual BOOL    OnDblClkHeader(UINT nFlags, CPoint point) { return FALSE; }
  660.     virtual BOOL    OnDblClkFooter(UINT nFlags, CPoint point) { return FALSE; }
  661.     virtual BOOL    OnDblClkDetail(UINT nFlags, CPoint point) { return FALSE; }
  662.     virtual BOOL    OnDblClkRow(long nRowId, UINT nFlags, CPoint point) { return FALSE; }
  663.  
  664. // Operations
  665. public:
  666. // Overrides
  667.     // ClassWizard generated virtual function overrides
  668.     //{{AFX_VIRTUAL(VForm)
  669.     public:
  670.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  671.     //}}AFX_VIRTUAL
  672.  
  673. // Generated message map functions
  674. protected:
  675.     //{{AFX_MSG(VForm)
  676.     afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  677.     afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
  678.     afx_msg void OnSize(UINT nType, int cx, int cy);
  679.     afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
  680.     afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
  681.     afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
  682.     afx_msg void OnPaint();
  683.     afx_msg void OnSetFocus(CWnd *pOldWnd);
  684.     afx_msg void OnKillFocus(CWnd *pNewWnd);
  685.     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
  686.     afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
  687.     afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
  688.     afx_msg void OnMouseMove(UINT nFlags, CPoint point);
  689.     afx_msg void OnCaptureChanged(CWnd* pWnd);
  690.     afx_msg void OnListDblClick();
  691.     afx_msg void OnListSelChange();
  692.     afx_msg int  OnVKeyToItem(UINT nKey, CListBox* pListBox, UINT nIndex);
  693.     afx_msg void OnTimer(UINT nIDEvent);
  694.     afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  695.     afx_msg void OnSysColorChange();
  696.     afx_msg void OnContextMenu(CWnd*, CPoint point);
  697.     //}}AFX_MSG
  698.     DECLARE_MESSAGE_MAP()
  699. };
  700.  
  701. #endif
  702.