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

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5. #ifndef __VCTLBASE_H__
  6. #define __VCTLBASE_H__
  7.  
  8. #ifdef VF_STATIC
  9.     #undef AFX_EXT_CLASS
  10.     #define AFX_EXT_CLASS
  11. #endif
  12.  
  13. #ifndef COLOR_CUSTOM
  14.     #define COLOR_CUSTOM    -1    // For specifying custom colors
  15. #endif
  16.  
  17. // Macro for setting a bit in a bitmap
  18. #ifndef SetBitFlag
  19. #define SetBitFlag(bitmap, nFlag, boolVal) \
  20.                     if(boolVal)    bitmap |= nFlag; \
  21.                     else        bitmap &= ~nFlag;
  22. #endif
  23.  
  24. // Virtual Control Styles
  25. #define VCS_VISIBLE            0x0001    // Is this control visible
  26. #define VCS_ACCEPTFOCUS        0x0002    // Does this control accept the input focus?
  27. #define VCS_DISABLED        0x0004    // Is this control enabled, Disabled is Gray
  28. #define VCS_LOCKED            0x0008    // Is this control locked
  29. #define VCS_TRANSPARENT        0x0010    // Is the background transparent
  30. #define VCS_HASFOCUS        0x0020    // Does this control have the focus?
  31. #define VCS_CLICKABLE        0x0040    // Can user click on control (notify on click)
  32. #define VCS_WANTENTER        0x0080    // Can control receive enter
  33. #define VCS_USEHELPER        0x0100    // Does this control use a helper control?
  34. #define VCS_LISTCTL            0x0200    // Does this control use the Forms List control?
  35. #define VCS_GRIDMODE        0x0400    // Use this control when in grid mode?
  36. #define VCS_VERTCENTERTEXT    0x0800    // Vertically Center Text
  37. #define VCS_BORDER            0x1000    // Does control have a border
  38. #define VCS_NOINACTIVEBORDER    0x2000    // No border when Inactive
  39. #define VCS_TIMER            0x4000    // Does control want timer events
  40.  
  41.  
  42. // Virtual Control Flags
  43. #define VCF_DELETEBYROW        0x0001    // Should Row delete this Ctl in its destructor
  44.  
  45. // VForm Control Types
  46. #define VCTL_BASE        0
  47. #define VCTL_STATIC        1
  48. #define VCTL_SMALLEDIT    2
  49. #define VCTL_BUTTON        3
  50. #define VCTL_CHECKBOX    4
  51. #define VCTL_DROPDOWN    5
  52. #define VCTL_COMBOBOX    6
  53. #define VCTL_PICTURE    7
  54. #define VCTL_PICTBUTTON    8
  55. #define VCTL_PICTCYCLE    9
  56. #define VCTL_EDIT        10
  57. #define VCTL_RADIOLIST    11
  58. #define VCTL_RECTANGLE    12
  59. #define VCTL_LINE        13
  60. #define VCTL_ELLIPSE    14
  61.  
  62. // VForm Rectangle Effects
  63. #define VEFFECT_FLAT        1    // Flat (normal rectangle)
  64. #define VEFFECT_NORMAL        2    // Normal (3D Effect)
  65. #define VEFFECT_SUNKEN        3    // Sunken (1 pixel "deep")
  66. #define VEFFECT_RAISED        4    // Raised (1 pixel "high")
  67. #define VEFFECT_SHADOW        5    // Shadow
  68. #define VEFFECT_ETCHEDRECT    6    // Etched Rectangle
  69. #define VEFFECT_BUMPEDRECT    7    // Bumped Rectangle
  70. #define VEFFECT_ETCHEDLINE    8    // Etched Line (bottom only)
  71. #define VEFFECT_BUMPEDLINE    9    // Bumped Line (bottom only)
  72. #define VEFFECT_BOXED        10    // 3D Box
  73.  
  74.  
  75. // VSmallEdit Flags - used internally
  76. #define VEDIT_MULTILINE            0x0001    // MultiLine Edit
  77. #define VEDIT_READONLY            0x0002    // ReadOnly
  78. #define VEDIT_PASSWORD            0x0004    // Password
  79. #define VEDIT_NUMERIC            0x0010    // Numeric Only
  80. #define VEDIT_LOWERCASE            0x0020    // Lowercase Only
  81. #define VEDIT_UPPERCASE            0x0040    // Uppercase Only
  82. #define VEDIT_SYSBACKWHENACTIVE    0x0080    // System Back Color when active
  83. #define VEDIT_DOLLARSIGN        0x0100    // Use dollar Signs (only for Numeric)
  84. #define VEDIT_ADDCOMMAS            0x0200    // Add Commas (only for Numeric)
  85. #define VEDIT_ALLOWNEGATIVE        0x0400    // Allow Negative Numbers (only for Numeric)
  86. #define VEDIT_SAVEMASKCHARS        0x0800    // Save Mask Chars (only for Masked Edit)
  87.  
  88. class VRow;
  89. class VHeader;
  90. class VRow;
  91. class VForm;
  92. class VBitmap;
  93.  
  94. #include "VCtlHelp.h"                // Helper Class
  95. #include "VfUtil.h"                    // Utility Classes
  96.  
  97. // -------------------------------------------------------------------------
  98. //    VCtl is the base class for all VForm "lightweight" controls
  99. // -------------------------------------------------------------------------
  100. class AFX_EXT_CLASS VCtl
  101. {
  102. protected:
  103.     int            m_nId;                // Control Id
  104.     CString        m_refId;            // String Id of control    - for data binding
  105.     CString        m_name;                // Name of control - for data binding
  106.     CString        m_text;                // Caption/Text
  107.     CString        m_helpText;            // Help text for control
  108.     CString        m_gridCaption;        // Caption of column if used in Grid Mode
  109.     short        m_nGridWidth;        // Width of column in Grid Mode
  110.     CRect        m_rectWin;            // Specifies windows rect, within parent
  111.     UINT        m_style;            // Bitmap of style settings
  112.     BYTE        m_nEffect;            // Special Effect (applies to SOME controls)
  113.     BYTE        m_nEffectDepth;        // Special Effect depth (applies to SOME effects)
  114.     BYTE        m_nLeftMargin;        // Left Margin
  115.     BYTE        m_nTextAlign;        // Text alignment flags
  116.     UINT        m_flags;            // Control Flags
  117.     VColor        m_vclrBack, m_vclrFore, m_vclrBorder;
  118.     CFont*        m_pFont;            // pointer to a font
  119.     VRow*        m_pRow;                // Pointer to parent row
  120.  
  121. public:
  122.     VCtl();
  123.     VCtl(VRow *pRow, int nId, int x, int y, int cx, int cy);
  124.     VCtl(VRow *pRow, int nId, LPCTSTR szText, int x, int y, int cx, int cy);
  125.     VCtl(VCtl &x) { *this = x; }                // Copy Constructor
  126.     virtual ~VCtl() {};
  127.  
  128.     VCtl&    operator =(VCtl &x);                // Assignment Operator
  129.  
  130.     // --------- Get Member Functions --------------
  131.     int        Id()                { return m_nId; }
  132.     CString& RefId()            { return m_refId; }
  133.     CString& Name()                { return m_name; }
  134.     CString& Text()                { return m_text; }
  135.     CString& HelpText()            { return m_helpText; }
  136.     CString& GridCaption()        { return m_gridCaption; }
  137.     int        GridWidth()            { return m_nGridWidth; }
  138.     int        Effect()            { return m_nEffect; }
  139.     int        EffectDepth()        { return m_nEffectDepth; }
  140.     UINT    LeftMargin()        { return m_nLeftMargin; }
  141.     VRow*    Row()                { return m_pRow; }
  142.     VForm*    Form();
  143.     CRect&    Rect()                { return m_rectWin; }
  144.     CFont*    Font()                { return m_pFont; }
  145.  
  146.     virtual int        GetWindowText(LPTSTR szText, int nMaxCount);
  147.     virtual void    GetWindowText(CString& rString) { rString = m_text; }
  148.     virtual void    SetWindowText(LPCTSTR szText)    { Text(szText); }
  149.  
  150.     virtual CString& Caption()                        { return m_text; }
  151.     virtual void    Caption(LPCTSTR szText)            { Text(szText); }
  152.  
  153.     UINT    GetStyle()                    { return m_style; }
  154.     void    SetStyle(UINT nFlags)        { m_style = nFlags; }
  155.     UINT    GetTextAlign()                { return m_nTextAlign; }
  156.     void    SetTextAlign(UINT nFlags)    { m_nTextAlign = nFlags; }
  157.  
  158.     BOOL    IsLive()            
  159.     { return(DoesAcceptFocus() && IsVisible() && IsEnabled()); }
  160.  
  161.     BOOL    UseHelper()            { return (m_style & VCS_USEHELPER); }
  162.     BOOL    IsListCtl()            { return (m_style & VCS_LISTCTL); }
  163.     BOOL    UseInGrid()            { return (m_style & VCS_GRIDMODE); }
  164.     BOOL    DoesAcceptFocus()    { return (m_style & VCS_ACCEPTFOCUS); }
  165.     BOOL    IsVisible()            { return (m_style & VCS_VISIBLE); }
  166.     BOOL    IsEnabled()            { return !(m_style & VCS_DISABLED); }
  167.     BOOL    IsLocked()            { return (m_style & VCS_LOCKED); }
  168.     BOOL    HasFocus()            { return (m_style & VCS_HASFOCUS); }
  169.     BOOL    IsTransparent()        { return (m_style & VCS_TRANSPARENT); }
  170.     BOOL    IsClickable()        { return (m_style & VCS_CLICKABLE); }
  171.     BOOL    WantEnter()            { return (m_style & VCS_WANTENTER); }
  172.     BOOL    UseTimer()            { return (m_style & VCS_TIMER); }
  173.     BOOL    VertCenterText()    { return (m_style & VCS_VERTCENTERTEXT); }
  174.     BOOL    HasBorder()            { return (m_style & VCS_BORDER); }
  175.     BOOL    NoInactiveBorder()    { return (m_style & VCS_NOINACTIVEBORDER); }
  176.     VColor&    BackVColor()        { return m_vclrBack; }
  177.     VColor&    ForeVColor()        { return m_vclrFore; }
  178.     VColor&    BorderVColor()        { return m_vclrBorder; }
  179.     COLORREF    BackColor()        { return m_vclrBack.GetRGB(); }
  180.     COLORREF    ForeColor()        { return m_vclrFore.GetRGB(); }
  181.     COLORREF    BorderColor()    { return m_vclrBorder.GetRGB(); }
  182.  
  183.     BOOL    DeleteByRow()        { return (m_flags & VCF_DELETEBYROW); }
  184.  
  185.     // --------- Set Member Functions --------------
  186.     void    Init(VRow *pRow, int nId, int x, int y, int cx, int cy);
  187.     void    Init(VRow *pRow, int nId, LPCTSTR szText,
  188.                     int x, int y, int cx, int cy);
  189.     void    Row(VRow *pVRow)                { m_pRow = pVRow; }
  190.     void    Id(int nId)                        { m_nId = nId; }
  191.     void    RefId(LPCTSTR szRefId)            { m_refId = szRefId; }
  192.     void    Name(LPCTSTR szName)            { m_name = szName; }
  193.     void    Text(LPCTSTR szText)            { m_text = szText; }
  194.     void    HelpText(LPCTSTR szHelpText)    { m_helpText = szHelpText; }
  195.     void    GridCaption(LPCTSTR szText)        { m_gridCaption = szText; }
  196.     void    GridWidth(int nWidth)            { m_nGridWidth = nWidth; }
  197.     void    Rect(CRect& rRect)                { m_rectWin = rRect; }
  198.     void    Position(int x, int y, int cx, int cy)
  199.                 { m_rectWin = CRect(x, y, x+cx, y+cy); }
  200.     void    Effect(BYTE nEffect)            { m_nEffect = nEffect; }
  201.     void    EffectDepth(int nDepth)            { m_nEffectDepth = nDepth; }
  202.     void    LeftMargin(UINT nPixels)        { m_nLeftMargin = nPixels; }
  203.     void    AcceptFocus(BOOL bFlag)        { SetBitFlag(m_style, VCS_ACCEPTFOCUS, bFlag); }
  204.     void    Visible(BOOL bFlag)            { SetBitFlag(m_style, VCS_VISIBLE, bFlag); }
  205.     void    SetBorder(BOOL bFlag)        { SetBitFlag(m_style, VCS_BORDER, bFlag); }
  206.     void    NoInactiveBorder(BOOL bFlag){ SetBitFlag(m_style, VCS_NOINACTIVEBORDER, bFlag); }
  207.     void    Disabled(BOOL bFlag)        { SetBitFlag(m_style, VCS_DISABLED, bFlag); }
  208.     void    Locked(BOOL bFlag)            { SetBitFlag(m_style, VCS_LOCKED, bFlag); }
  209.     void    Timer(BOOL bFlag)            { SetBitFlag(m_style, VCS_TIMER, bFlag); }
  210.     void    UseInGrid(BOOL bFlag)        { SetBitFlag(m_style, VCS_GRIDMODE, bFlag); }
  211.     void    SetTransparent(BOOL bFlag)    { SetBitFlag(m_style, VCS_TRANSPARENT, bFlag); }
  212.     void    VertCenterText(BOOL bFlag)    { SetBitFlag(m_style, VCS_VERTCENTERTEXT, bFlag); }
  213.     void    DeleteByRow(BOOL bFlag)        { SetBitFlag(m_flags, VCF_DELETEBYROW, bFlag); }
  214.  
  215.     void    Disable()                    { m_style |= VCS_DISABLED; }
  216.     void    Enable()                    { m_style &= ~VCS_DISABLED; }
  217.     void    Lock()                        { m_style |= VCS_LOCKED; }
  218.     void    Unlock()                    { m_style &= ~VCS_LOCKED; }
  219.     void    TimerOn()                    { m_style |= VCS_TIMER; }
  220.     void    TimerOff()                    { m_style &= ~VCS_TIMER; }
  221.  
  222.     void    BackColor(VColor &vclr)        { m_vclrBack = vclr; }
  223.     void    ForeColor(VColor &vclr)        { m_vclrFore = vclr; }
  224.     void    BorderColor(VColor &vclr)    { m_vclrBorder = vclr; }
  225.     void    BackColor(COLORREF clr)        { m_vclrBack.UseCustomRGB(clr); }
  226.     void    ForeColor(COLORREF clr)        { m_vclrFore.UseCustomRGB(clr); }
  227.     void    BorderColor(COLORREF clr)    { m_vclrBorder.UseCustomRGB(clr); }
  228.     void    BackColorIdx(int nIdx)        { m_vclrBack.ColorIdx(nIdx); }
  229.     void    ForeColorIdx(int nIdx)        { m_vclrFore.ColorIdx(nIdx); }
  230.     void    BorderColorIdx(int nIdx)    { m_vclrBorder.ColorIdx(nIdx); }
  231.  
  232.     void    Font(CFont* pFont)            { m_pFont = pFont; }
  233.  
  234.     // ---------- Only to be called by VForm
  235.     void    HasFocus(BOOL bFlag)        { SetBitFlag(m_style, VCS_HASFOCUS, bFlag); }
  236.     void    FocusOn()                    { m_style |= VCS_HASFOCUS; }
  237.     void    FocusOff()                    { m_style &= ~VCS_HASFOCUS; }
  238.  
  239.     // --------- Implementation Functions --------------
  240.     void    Draw(BOOL bToScreen=TRUE);        // Tells VForm to draw control
  241.  
  242.     // --------- Helper Functions -------------
  243.     void    DrawEffect(CDC *pDC, LPRECT pRect, int nEffect, int nDepth=1);
  244.     CRect    EffectInterior(LPRECT pRect, int nEffect, int nDepth=1);
  245.  
  246.     void    DrawBorder(CDC *pDC, CRect rect);
  247.     void    DrawRect(CDC *pDC, CRect rect, COLORREF clrBorder, COLORREF clrBack,
  248.                 int nWidth=1, BOOL bTransparent=FALSE);
  249.     void    DrawFocusRect(CDC *pDC, CRect rect);
  250.     void    Draw3dBorder(CDC *pDC, CRect rect, BOOL bIn=TRUE);
  251.     void    DrawBoxedRect(CDC *pDC, CRect rect, BOOL nDepth=3);
  252.     void    DrawEtchedRect(CDC *pDC, CRect rect, BOOL bEtched=TRUE);
  253.     void    DrawEtchedLine(CDC *pDC, CRect rect, BOOL bEtched=TRUE, BOOL bBottom=TRUE);
  254.     void    DrawVertEtchedLine(CDC *pDC, CRect rect, BOOL bEtched=TRUE, BOOL bLeft=TRUE);
  255.     void    DrawShadowBox(CDC *pDC, CRect rect, int nShadowWidth=1);
  256.     void    DrawDownArrow(CDC *pDC, int x, int y, int nWidth, COLORREF clr, BOOL bUp=FALSE);
  257.     void    DrawRightArrow(CDC *pDC, int x, int y, int nHeight, COLORREF clr, BOOL bLeft=FALSE);
  258.     void    DrawText(CDC *pDC, CRect rect, CRect clipRect, BOOL bNoBkgrnd=FALSE);
  259.     void    DrawTextEx(CDC *pDC, CRect rect, BOOL bNoBkgrnd=FALSE, UINT nFormat=0);
  260.     void    DrawCtlText(CDC *pDC, LPCTSTR szText, CRect rect, int nFormat, BOOL bReverse=FALSE);
  261.     BOOL    LoadBitmapRes(CImageList *pImgList, LPCTSTR szBmpResource, 
  262.                           BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
  263.     BOOL    LoadBitmapRes(CImageList *pImgList, UINT uID, 
  264.                           BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
  265.     BOOL    LoadBitmap(CImageList *pImgList, LPCTSTR szBmpFile, 
  266.                           BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
  267.     BOOL    LoadBitmap(CImageList *pImgList, VBitmap &vBmp, 
  268.                           BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
  269.     BOOL    HitTest(POINT pt)            { return m_rectWin.PtInRect(pt); }
  270.     BOOL    IsVfReadOnly();                
  271.  
  272.     // ----------- Virtual Events -------------
  273.     virtual int        IsA()                                    { return VCTL_BASE; }
  274.     // virtual void    OnDraw(CDC *pDC);                        // Called by VForm
  275.     virtual void    OnDraw(CDC *pDC, LPRECT pRect=0, BOOL bGridMode=0);
  276.     virtual BOOL    OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){ return FALSE; }
  277.     virtual BOOL    OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)    { return FALSE; }
  278.     virtual BOOL    OnLButtonDown(UINT nFlags, CPoint pt)    { return FALSE; }
  279.     virtual BOOL    OnLButtonUp(UINT nFlags, CPoint pt, BOOL bSameCtl)
  280.                                                             { return FALSE; }
  281.     virtual BOOL    OnEnterDown()                            { return FALSE; }
  282.     virtual BOOL    OnEnterUp()                                { return FALSE; }
  283.     virtual BOOL    OnTimer()                                { return FALSE; }
  284.     virtual void    OnSysColorChange(); 
  285.  
  286.     // --------- Example of using Custom Message ----------
  287.     // virtual void OnMessage(); 
  288.  
  289.     // --------- Virtual Helper Functions ----------
  290.     virtual VCtlHelper*    CreateHelper(CWnd *pParent)        { return NULL; }
  291.     virtual CRect    HelperRect(LPRECT pRect=0, BOOL bGridMode=FALSE)
  292.     { if(pRect) return *pRect; else return m_rectWin; }
  293.     virtual int        HelperId()                            { return -1; }
  294.     virtual BOOL    OnBeginHelper(VCtlHelper* pHelper)    { return TRUE; }
  295.     virtual BOOL    OnEndHelper(VCtlHelper* pHelper)    { return TRUE; }
  296.     virtual BOOL    IsHelperDirty(VCtlHelper* pHelper)    { return FALSE;}
  297.  
  298.     // --------- Overridables ---------------------------
  299.     virtual BOOL OnSetFocus(VCtl *pOldCtl)            { return TRUE; }
  300.     virtual BOOL OnKillFocus(VCtl *pNewCtl)            { return TRUE; }
  301.     virtual BOOL OnBeginList(CListBox *pListBox)    { return TRUE; }
  302.     virtual BOOL OnEndList(CListBox *pListBox)        { return TRUE; }
  303. };
  304.  
  305. #endif