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

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5. #ifndef __VROW_H__
  6. #define __VROW_H__
  7.  
  8. #ifdef VF_STATIC
  9.     #undef AFX_EXT_CLASS
  10.     #define AFX_EXT_CLASS
  11. #endif
  12.  
  13. #include "VCtl.h"
  14. #include "VEdit.h"
  15. #include "afxtempl.h"
  16. #include "VfUtil.h"
  17. #include "VBitmap.h"
  18.  
  19. #define VROW_BG_DEFAULT        0
  20. #define VROW_BG_PAPER        1
  21. #define VROW_BG_FLAT        2
  22. #define VROW_BG_GREENBAR    3
  23. #define VROW_BG_BMP            4
  24.  
  25. #define ROW_CTRLID_OFFSET        100
  26. #define VROW_COLOR_BACKGROUND    1
  27. #define VROW_COLOR_HIGHLIGHT    2
  28. #define VROW_COLOR_HIDDEN        3
  29.  
  30. typedef CArray<VCtl *, VCtl *> VCtlPtrArray;
  31.  
  32. class VForm;
  33. class VMaskEdit;
  34. class VEdit;
  35.  
  36. // -------------------------------------------------------------------------
  37. // Base class for control containers: VHeader, VRow, VFooter
  38. // -------------------------------------------------------------------------
  39. class AFX_EXT_CLASS VCtlContainer
  40. {
  41. protected:
  42.     VCtlPtrArray m_ctl;                    // Array of pointers to controls
  43.     int            m_nCtls;                // how many controls
  44.     BOOL        m_bDeleteByForm;        // True if form should delete this row
  45.     BOOL        m_bChanged;                // True if some data on the row changed
  46.     VForm*        m_pForm;                // pointer to the form
  47.     VColor        m_vclrBack;                // Background Color
  48.     VColor        m_vclrHighlight;        // Highlight Color
  49.     VColor        m_vclrHidden;            // Hidden Color
  50.  
  51. public:
  52.     VCtlContainer();                    // Constructor
  53.     ~VCtlContainer();                    // Destructor
  54.         
  55.     VForm*        Form()                        { return m_pForm; }
  56.     void        SetForm(VForm* x)            { m_pForm = x; }
  57.     void        SetCustomColor(int nVRowClrIdx, COLORREF clr);
  58.     void        SetColor(int nVRowClrIdx, int nIndex);
  59.     int            GetColorIndex(int nVRowClrIdx);
  60.     COLORREF    GetColor(int nVRowClrIdx);
  61.  
  62.     void    BackColor(VColor &vclr)            { m_vclrBack = vclr; }
  63.     void    HighlightColor(VColor &vclr)    { m_vclrHighlight = vclr; }
  64.     void    HiddenColor(VColor &vclr)        { m_vclrHidden = vclr; }
  65.     VColor&    BackVColor()                    { return m_vclrBack; }
  66.     VColor&    HighlightVColor()                { return m_vclrHighlight; }
  67.     VColor&    HiddenVColor()                    { return m_vclrHidden; }
  68.  
  69.     
  70.     void    AddCtl(VCtl *pCtl);            // Adds a control to the container
  71.     VCtl*    AddNamedCtl(VCtl *pCtl);    // Adds a named control to the container
  72.     void    RemoveAllCtls();            // Removes (& deletes) all controls
  73.     void    ResetAllCtls();                // Resets (& deletes) the controls
  74.     int        CtlCount()                        { return m_nCtls; }
  75.  
  76.     void    DeleteByForm(BOOL bFlag)        { m_bDeleteByForm = bFlag; }
  77.     BOOL    DeleteByForm()                    { return m_bDeleteByForm; }
  78.     
  79.     void    Changed()                        { m_bChanged = TRUE; }
  80.     void    Unchanged()                        { m_bChanged = FALSE; }
  81.     BOOL    IsChanged()                        { return m_bChanged; }
  82.  
  83.     int        GetCtlIdxById(int nId);        // Retrieve idx of needed control
  84.     int        GetCtlIdxByName(LPCTSTR szName); 
  85.     int        GetCtlIdx(VCtl *pCtl);        // Retrieve idx of needed control
  86.     int        GetClosestCtlIdx(int idx);    // Retrieve closest control
  87.     int        GetCtlIdx(CPoint xPoint, BOOL bMustBeLive); 
  88.  
  89.     int        GetNextLiveCtlIdx(int nStartIdx=0);    // Retrieve idx of next live control
  90.     int        GetPrevLiveCtlIdx(int nStartIdx);    // Retrieve idx of prev live control
  91.     int        GetFirstLiveCtlIdx()    { return GetNextLiveCtlIdx(0); }
  92.     int        GetLastLiveCtlIdx()        { return GetPrevLiveCtlIdx(m_nCtls - 1); }
  93.  
  94.     VCtl*    GetCtlPtrById(int nId);        // Retrieve pointer to needed control
  95.     VCtl*    GetCtlPtrByName(LPCTSTR szName);
  96.     VCtl*    GetCtlPtr(int idx);            // Retrieve pointer to needed control
  97.     VCtl*    GetClosestCtlPtr(int nId);    // Retrieve closest control
  98.     VCtl*    GetCtlPtr(CPoint xPoint, BOOL bMustBeLive); 
  99.     
  100.     VCtl*    GetNextLiveCtlPtr(int nStartIdx=0);    // Retrieve pointer to needed control
  101.     VCtl*    GetPrevLiveCtlPtr(int nStartIdx);    // Retrieve pointer to needed control
  102.     VCtl*    GetNextLiveCtlPtr(VCtl *pOldCtl);
  103.     VCtl*    GetPrevLiveCtlPtr(VCtl *pOldCtl);
  104.     VCtl*    GetFirstLiveCtlPtr()    { return GetNextLiveCtlPtr(0); }
  105.     VCtl*    GetLastLiveCtlPtr()        { return GetPrevLiveCtlPtr(m_nCtls - 1); }
  106.  
  107.     // --- We dont need any virtual functions, since derived classes are
  108.     // --- always called from that level (we never use a pointer to a VCtlContainer)
  109.     // --- - otherwise, we would make these functions virtual
  110.     void    OnTimer();                    // On Timer Events
  111.     void    OnSysColorChange();
  112.  
  113.     // --- Virtual Functions ---
  114.     // virtual long    RowId()                { return -1; }
  115.     // virtual BOOL    HasFocus()            { return FALSE; }
  116.     // virtual BOOL    IsSelected()        { return FALSE; }    
  117.     // virtual BOOL    IsHidden()            { return FALSE; }
  118.     // virtual void    Draw(BOOL bToScreen=TRUE) {};
  119.     
  120.     // ------- Drawing Routines -----------------
  121.     // virtual void    OnDraw(CDC *pDC) {};    // Draws the Container
  122.     // virtual void    OnTimer();                // On Timer Events
  123.     // virtual void    OnDrawBackground(CDC *pDC, CRect &rect) {};
  124.     // virtual void    OnDrawCtlBackground(CDC *pDC, CRect &rect) {};
  125.     // virtual void    OnDrawHiddenBk(CDC *pDC, CRect &rect) {};
  126. };
  127.  
  128. // -------------------------------------------------------------------------
  129. // Row Class
  130. // -------------------------------------------------------------------------
  131. class AFX_EXT_CLASS VRow : public VCtlContainer
  132. {
  133. protected:
  134.     int        m_nHeight;                // Height of row
  135.     long    m_nRow;                    // row id
  136.  
  137.     int        m_nBackStyle;            // Background Style
  138.     HICON    m_hIcon;                // Icon Handle
  139.     int        m_nIconX, m_nIconY;        // Icon Position
  140.     VBitmap    m_vbitmap;                // For use with bitmap background
  141.     BOOL    m_bBmpLoaded;            // TRUE if BMP file has been loaded
  142.  
  143. public:
  144.     VRow();                            // Constructor
  145.     virtual ~VRow();                // Destructor
  146.         
  147.     long    RowId()                { return m_nRow; }
  148.     void    RowId(long nRowId)    { m_nRow = nRowId; }
  149.  
  150.     int        Height()            { return m_nHeight; }
  151.     void    Height(int nHeight)    { m_nHeight = nHeight; }
  152.  
  153.     BOOL    HasFocus();
  154.     BOOL    IsSelected();
  155.     BOOL    IsHidden();
  156.     void    Draw(BOOL bToScreen=TRUE);
  157.  
  158.     // ------ Drawing Settings -----
  159.     void    SetStyle(int nBackStyle)    { m_nBackStyle = nBackStyle;}
  160.     int        GetStyle()                    { return m_nBackStyle; }
  161.  
  162.     void    SetIcon(HICON hIcon)        { m_hIcon = hIcon;}
  163.     HICON    GetIcon()                    { return m_hIcon; }
  164.     void    SetIconPosition(int x, int y) { m_nIconX = x; m_nIconY = y; }
  165.  
  166.     // If using BMP, derived class must override GetBackBmp or call LoadBitmap
  167.     virtual BOOL        LoadBitmap(LPCTSTR szBmpFile);
  168.     virtual BOOL        LoadBitmapRes(LPCTSTR szBmpResource);
  169.     virtual BOOL        LoadBitmapRes(UINT uID);
  170.     virtual HBITMAP        GetBackBmp();
  171.     virtual CPalette*    GetBackPalette();
  172.     virtual HPALETTE    GetBackPaletteHandle();
  173.  
  174.     void    ResetCtl(VCtl &ctl, BOOL bTp, BOOL bNib, COLORREF clr);
  175.  
  176.     // ------- RowType used for cursor placement with multiple row types -----
  177.     virtual int        RowType()    { return 0; }
  178.     
  179.     // ------- Drawing Routines -----------------
  180.     virtual void    OnDraw(CDC *pDC, CRect &rect);        // Draws the row control
  181.     virtual void    OnDraw(CDC *pDC, CRect &rect, CRect& rectClip);
  182.     virtual void    OnTimer() { VCtlContainer::OnTimer(); }
  183.     virtual void    OnDrawBackground(CDC *pDC, CRect &rect, int nSelWidth=0);
  184.     virtual void    OnDrawCtlBackground(CDC *pDC, CRect &rect);
  185.     virtual void    OnDrawHiddenBk(CDC *pDC, CRect &rect);
  186.  
  187.     virtual void    OnRptDraw(CDC *pDC, CRect &rect);    
  188.     virtual void    OnRptDrawBackground(CDC *pDC, CRect &rect);
  189.     virtual void    SetRptFields(CPrintInfo *pInfo);
  190.  
  191.     virtual void    DrawNormalBG(CDC *pDC, CRect &rect, BOOL bDrawFocus, int nSelWidth); 
  192.     virtual void    DrawFlatBG(CDC *pDC, CRect &rect, BOOL bDrawFocus, int nSelWidth); 
  193.     virtual void    DrawGreenBarBG(CDC *pDC, CRect &rect, BOOL bDrawFocus, int nSelWidth); 
  194.     virtual void    DrawPaperBG(CDC *pDC, CRect &rect, BOOL bDrawFocus, int nSelWidth); 
  195.     virtual void    DrawBmpBG(CDC *pDC, CRect &rect, BOOL bDrawFocus, int nSelWidth); 
  196.  
  197.     // ------- Miscellaneous -----------------
  198.     virtual COLORREF CurBackColor();
  199. };
  200.  
  201. // -------------------------------------------------------------------------
  202. // Header AND Footer Class
  203. // -------------------------------------------------------------------------
  204. class AFX_EXT_CLASS VHeader : public VRow
  205. {
  206. protected:
  207.     BOOL    m_bHighlight;                // Is header Highlighted
  208.  
  209. public:
  210.     VHeader();                            // Constructor
  211.     virtual ~VHeader() {};                // Destructor
  212.  
  213.     BOOL    IsHighlighted()    { return m_bHighlight; }
  214.  
  215.     void    Highlight(BOOL x)    { m_bHighlight = x; }
  216.         
  217.     // ------- Drawing Routines -----------------
  218.     virtual void    OnDraw(CDC *pDC, CRect &rect);        // Draws the row control
  219.     virtual void    OnDraw(CDC *pDC, CRect &rect, CRect& rectClip);
  220.     virtual void    OnDrawBackground(CDC *pDC, CRect &rect, int nSelWidth);
  221.  
  222.     // ------- Miscellaneous -----------------
  223.     virtual COLORREF CurBackColor();
  224. };
  225.  
  226.  
  227. #endif