home *** CD-ROM | disk | FTP | other *** search
- // -------------------------------------------------------------------------
- // Copyright @ 1997 TCK Software, Incorporated
- // All Rights Reserved
- // -------------------------------------------------------------------------
- #ifndef __VCTLBASE_H__
- #define __VCTLBASE_H__
-
- #ifdef VF_STATIC
- #undef AFX_EXT_CLASS
- #define AFX_EXT_CLASS
- #endif
-
- #ifndef COLOR_CUSTOM
- #define COLOR_CUSTOM -1 // For specifying custom colors
- #endif
-
- // Macro for setting a bit in a bitmap
- #ifndef SetBitFlag
- #define SetBitFlag(bitmap, nFlag, boolVal) \
- if(boolVal) bitmap |= nFlag; \
- else bitmap &= ~nFlag;
- #endif
-
- // Virtual Control Styles
- #define VCS_VISIBLE 0x0001 // Is this control visible
- #define VCS_ACCEPTFOCUS 0x0002 // Does this control accept the input focus?
- #define VCS_DISABLED 0x0004 // Is this control enabled, Disabled is Gray
- #define VCS_LOCKED 0x0008 // Is this control locked
- #define VCS_TRANSPARENT 0x0010 // Is the background transparent
- #define VCS_HASFOCUS 0x0020 // Does this control have the focus?
- #define VCS_CLICKABLE 0x0040 // Can user click on control (notify on click)
- #define VCS_WANTENTER 0x0080 // Can control receive enter
- #define VCS_USEHELPER 0x0100 // Does this control use a helper control?
- #define VCS_LISTCTL 0x0200 // Does this control use the Forms List control?
- #define VCS_GRIDMODE 0x0400 // Use this control when in grid mode?
- #define VCS_VERTCENTERTEXT 0x0800 // Vertically Center Text
- #define VCS_BORDER 0x1000 // Does control have a border
- #define VCS_NOINACTIVEBORDER 0x2000 // No border when Inactive
- #define VCS_TIMER 0x4000 // Does control want timer events
-
-
- // Virtual Control Flags
- #define VCF_DELETEBYROW 0x0001 // Should Row delete this Ctl in its destructor
-
- // VForm Control Types
- #define VCTL_BASE 0
- #define VCTL_STATIC 1
- #define VCTL_SMALLEDIT 2
- #define VCTL_BUTTON 3
- #define VCTL_CHECKBOX 4
- #define VCTL_DROPDOWN 5
- #define VCTL_COMBOBOX 6
- #define VCTL_PICTURE 7
- #define VCTL_PICTBUTTON 8
- #define VCTL_PICTCYCLE 9
- #define VCTL_EDIT 10
- #define VCTL_RADIOLIST 11
- #define VCTL_RECTANGLE 12
- #define VCTL_LINE 13
- #define VCTL_ELLIPSE 14
-
- // VForm Rectangle Effects
- #define VEFFECT_FLAT 1 // Flat (normal rectangle)
- #define VEFFECT_NORMAL 2 // Normal (3D Effect)
- #define VEFFECT_SUNKEN 3 // Sunken (1 pixel "deep")
- #define VEFFECT_RAISED 4 // Raised (1 pixel "high")
- #define VEFFECT_SHADOW 5 // Shadow
- #define VEFFECT_ETCHEDRECT 6 // Etched Rectangle
- #define VEFFECT_BUMPEDRECT 7 // Bumped Rectangle
- #define VEFFECT_ETCHEDLINE 8 // Etched Line (bottom only)
- #define VEFFECT_BUMPEDLINE 9 // Bumped Line (bottom only)
- #define VEFFECT_BOXED 10 // 3D Box
-
-
- // VSmallEdit Flags - used internally
- #define VEDIT_MULTILINE 0x0001 // MultiLine Edit
- #define VEDIT_READONLY 0x0002 // ReadOnly
- #define VEDIT_PASSWORD 0x0004 // Password
- #define VEDIT_NUMERIC 0x0010 // Numeric Only
- #define VEDIT_LOWERCASE 0x0020 // Lowercase Only
- #define VEDIT_UPPERCASE 0x0040 // Uppercase Only
- #define VEDIT_SYSBACKWHENACTIVE 0x0080 // System Back Color when active
- #define VEDIT_DOLLARSIGN 0x0100 // Use dollar Signs (only for Numeric)
- #define VEDIT_ADDCOMMAS 0x0200 // Add Commas (only for Numeric)
- #define VEDIT_ALLOWNEGATIVE 0x0400 // Allow Negative Numbers (only for Numeric)
- #define VEDIT_SAVEMASKCHARS 0x0800 // Save Mask Chars (only for Masked Edit)
-
- class VRow;
- class VHeader;
- class VRow;
- class VForm;
- class VBitmap;
-
- #include "VCtlHelp.h" // Helper Class
- #include "VfUtil.h" // Utility Classes
-
- // -------------------------------------------------------------------------
- // VCtl is the base class for all VForm "lightweight" controls
- // -------------------------------------------------------------------------
- class AFX_EXT_CLASS VCtl
- {
- protected:
- int m_nId; // Control Id
- CString m_refId; // String Id of control - for data binding
- CString m_name; // Name of control - for data binding
- CString m_text; // Caption/Text
- CString m_helpText; // Help text for control
- CString m_gridCaption; // Caption of column if used in Grid Mode
- short m_nGridWidth; // Width of column in Grid Mode
- CRect m_rectWin; // Specifies windows rect, within parent
- UINT m_style; // Bitmap of style settings
- BYTE m_nEffect; // Special Effect (applies to SOME controls)
- BYTE m_nEffectDepth; // Special Effect depth (applies to SOME effects)
- BYTE m_nLeftMargin; // Left Margin
- BYTE m_nTextAlign; // Text alignment flags
- UINT m_flags; // Control Flags
- VColor m_vclrBack, m_vclrFore, m_vclrBorder;
- CFont* m_pFont; // pointer to a font
- VRow* m_pRow; // Pointer to parent row
-
- public:
- VCtl();
- VCtl(VRow *pRow, int nId, int x, int y, int cx, int cy);
- VCtl(VRow *pRow, int nId, LPCTSTR szText, int x, int y, int cx, int cy);
- VCtl(VCtl &x) { *this = x; } // Copy Constructor
- virtual ~VCtl() {};
-
- VCtl& operator =(VCtl &x); // Assignment Operator
-
- // --------- Get Member Functions --------------
- int Id() { return m_nId; }
- CString& RefId() { return m_refId; }
- CString& Name() { return m_name; }
- CString& Text() { return m_text; }
- CString& HelpText() { return m_helpText; }
- CString& GridCaption() { return m_gridCaption; }
- int GridWidth() { return m_nGridWidth; }
- int Effect() { return m_nEffect; }
- int EffectDepth() { return m_nEffectDepth; }
- UINT LeftMargin() { return m_nLeftMargin; }
- VRow* Row() { return m_pRow; }
- VForm* Form();
- CRect& Rect() { return m_rectWin; }
- CFont* Font() { return m_pFont; }
-
- virtual int GetWindowText(LPTSTR szText, int nMaxCount);
- virtual void GetWindowText(CString& rString) { rString = m_text; }
- virtual void SetWindowText(LPCTSTR szText) { Text(szText); }
-
- virtual CString& Caption() { return m_text; }
- virtual void Caption(LPCTSTR szText) { Text(szText); }
-
- UINT GetStyle() { return m_style; }
- void SetStyle(UINT nFlags) { m_style = nFlags; }
- UINT GetTextAlign() { return m_nTextAlign; }
- void SetTextAlign(UINT nFlags) { m_nTextAlign = nFlags; }
-
- BOOL IsLive()
- { return(DoesAcceptFocus() && IsVisible() && IsEnabled()); }
-
- BOOL UseHelper() { return (m_style & VCS_USEHELPER); }
- BOOL IsListCtl() { return (m_style & VCS_LISTCTL); }
- BOOL UseInGrid() { return (m_style & VCS_GRIDMODE); }
- BOOL DoesAcceptFocus() { return (m_style & VCS_ACCEPTFOCUS); }
- BOOL IsVisible() { return (m_style & VCS_VISIBLE); }
- BOOL IsEnabled() { return !(m_style & VCS_DISABLED); }
- BOOL IsLocked() { return (m_style & VCS_LOCKED); }
- BOOL HasFocus() { return (m_style & VCS_HASFOCUS); }
- BOOL IsTransparent() { return (m_style & VCS_TRANSPARENT); }
- BOOL IsClickable() { return (m_style & VCS_CLICKABLE); }
- BOOL WantEnter() { return (m_style & VCS_WANTENTER); }
- BOOL UseTimer() { return (m_style & VCS_TIMER); }
- BOOL VertCenterText() { return (m_style & VCS_VERTCENTERTEXT); }
- BOOL HasBorder() { return (m_style & VCS_BORDER); }
- BOOL NoInactiveBorder() { return (m_style & VCS_NOINACTIVEBORDER); }
- VColor& BackVColor() { return m_vclrBack; }
- VColor& ForeVColor() { return m_vclrFore; }
- VColor& BorderVColor() { return m_vclrBorder; }
- COLORREF BackColor() { return m_vclrBack.GetRGB(); }
- COLORREF ForeColor() { return m_vclrFore.GetRGB(); }
- COLORREF BorderColor() { return m_vclrBorder.GetRGB(); }
-
- BOOL DeleteByRow() { return (m_flags & VCF_DELETEBYROW); }
-
- // --------- Set Member Functions --------------
- void Init(VRow *pRow, int nId, int x, int y, int cx, int cy);
- void Init(VRow *pRow, int nId, LPCTSTR szText,
- int x, int y, int cx, int cy);
- void Row(VRow *pVRow) { m_pRow = pVRow; }
- void Id(int nId) { m_nId = nId; }
- void RefId(LPCTSTR szRefId) { m_refId = szRefId; }
- void Name(LPCTSTR szName) { m_name = szName; }
- void Text(LPCTSTR szText) { m_text = szText; }
- void HelpText(LPCTSTR szHelpText) { m_helpText = szHelpText; }
- void GridCaption(LPCTSTR szText) { m_gridCaption = szText; }
- void GridWidth(int nWidth) { m_nGridWidth = nWidth; }
- void Rect(CRect& rRect) { m_rectWin = rRect; }
- void Position(int x, int y, int cx, int cy)
- { m_rectWin = CRect(x, y, x+cx, y+cy); }
- void Effect(BYTE nEffect) { m_nEffect = nEffect; }
- void EffectDepth(int nDepth) { m_nEffectDepth = nDepth; }
- void LeftMargin(UINT nPixels) { m_nLeftMargin = nPixels; }
- void AcceptFocus(BOOL bFlag) { SetBitFlag(m_style, VCS_ACCEPTFOCUS, bFlag); }
- void Visible(BOOL bFlag) { SetBitFlag(m_style, VCS_VISIBLE, bFlag); }
- void SetBorder(BOOL bFlag) { SetBitFlag(m_style, VCS_BORDER, bFlag); }
- void NoInactiveBorder(BOOL bFlag){ SetBitFlag(m_style, VCS_NOINACTIVEBORDER, bFlag); }
- void Disabled(BOOL bFlag) { SetBitFlag(m_style, VCS_DISABLED, bFlag); }
- void Locked(BOOL bFlag) { SetBitFlag(m_style, VCS_LOCKED, bFlag); }
- void Timer(BOOL bFlag) { SetBitFlag(m_style, VCS_TIMER, bFlag); }
- void UseInGrid(BOOL bFlag) { SetBitFlag(m_style, VCS_GRIDMODE, bFlag); }
- void SetTransparent(BOOL bFlag) { SetBitFlag(m_style, VCS_TRANSPARENT, bFlag); }
- void VertCenterText(BOOL bFlag) { SetBitFlag(m_style, VCS_VERTCENTERTEXT, bFlag); }
- void DeleteByRow(BOOL bFlag) { SetBitFlag(m_flags, VCF_DELETEBYROW, bFlag); }
-
- void Disable() { m_style |= VCS_DISABLED; }
- void Enable() { m_style &= ~VCS_DISABLED; }
- void Lock() { m_style |= VCS_LOCKED; }
- void Unlock() { m_style &= ~VCS_LOCKED; }
- void TimerOn() { m_style |= VCS_TIMER; }
- void TimerOff() { m_style &= ~VCS_TIMER; }
-
- void BackColor(VColor &vclr) { m_vclrBack = vclr; }
- void ForeColor(VColor &vclr) { m_vclrFore = vclr; }
- void BorderColor(VColor &vclr) { m_vclrBorder = vclr; }
- void BackColor(COLORREF clr) { m_vclrBack.UseCustomRGB(clr); }
- void ForeColor(COLORREF clr) { m_vclrFore.UseCustomRGB(clr); }
- void BorderColor(COLORREF clr) { m_vclrBorder.UseCustomRGB(clr); }
- void BackColorIdx(int nIdx) { m_vclrBack.ColorIdx(nIdx); }
- void ForeColorIdx(int nIdx) { m_vclrFore.ColorIdx(nIdx); }
- void BorderColorIdx(int nIdx) { m_vclrBorder.ColorIdx(nIdx); }
-
- void Font(CFont* pFont) { m_pFont = pFont; }
-
- // ---------- Only to be called by VForm
- void HasFocus(BOOL bFlag) { SetBitFlag(m_style, VCS_HASFOCUS, bFlag); }
- void FocusOn() { m_style |= VCS_HASFOCUS; }
- void FocusOff() { m_style &= ~VCS_HASFOCUS; }
-
- // --------- Implementation Functions --------------
- void Draw(BOOL bToScreen=TRUE); // Tells VForm to draw control
-
- // --------- Helper Functions -------------
- void DrawEffect(CDC *pDC, LPRECT pRect, int nEffect, int nDepth=1);
- CRect EffectInterior(LPRECT pRect, int nEffect, int nDepth=1);
-
- void DrawBorder(CDC *pDC, CRect rect);
- void DrawRect(CDC *pDC, CRect rect, COLORREF clrBorder, COLORREF clrBack,
- int nWidth=1, BOOL bTransparent=FALSE);
- void DrawFocusRect(CDC *pDC, CRect rect);
- void Draw3dBorder(CDC *pDC, CRect rect, BOOL bIn=TRUE);
- void DrawBoxedRect(CDC *pDC, CRect rect, BOOL nDepth=3);
- void DrawEtchedRect(CDC *pDC, CRect rect, BOOL bEtched=TRUE);
- void DrawEtchedLine(CDC *pDC, CRect rect, BOOL bEtched=TRUE, BOOL bBottom=TRUE);
- void DrawVertEtchedLine(CDC *pDC, CRect rect, BOOL bEtched=TRUE, BOOL bLeft=TRUE);
- void DrawShadowBox(CDC *pDC, CRect rect, int nShadowWidth=1);
- void DrawDownArrow(CDC *pDC, int x, int y, int nWidth, COLORREF clr, BOOL bUp=FALSE);
- void DrawRightArrow(CDC *pDC, int x, int y, int nHeight, COLORREF clr, BOOL bLeft=FALSE);
- void DrawText(CDC *pDC, CRect rect, CRect clipRect, BOOL bNoBkgrnd=FALSE);
- void DrawTextEx(CDC *pDC, CRect rect, BOOL bNoBkgrnd=FALSE, UINT nFormat=0);
- void DrawCtlText(CDC *pDC, LPCTSTR szText, CRect rect, int nFormat, BOOL bReverse=FALSE);
- BOOL LoadBitmapRes(CImageList *pImgList, LPCTSTR szBmpResource,
- BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
- BOOL LoadBitmapRes(CImageList *pImgList, UINT uID,
- BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
- BOOL LoadBitmap(CImageList *pImgList, LPCTSTR szBmpFile,
- BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
- BOOL LoadBitmap(CImageList *pImgList, VBitmap &vBmp,
- BOOL bTransparent, COLORREF clrMask, int nImgWidth=0);
- BOOL HitTest(POINT pt) { return m_rectWin.PtInRect(pt); }
- BOOL IsVfReadOnly();
-
- // ----------- Virtual Events -------------
- virtual int IsA() { return VCTL_BASE; }
- // virtual void OnDraw(CDC *pDC); // Called by VForm
- virtual void OnDraw(CDC *pDC, LPRECT pRect=0, BOOL bGridMode=0);
- virtual BOOL OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags){ return FALSE; }
- virtual BOOL OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) { return FALSE; }
- virtual BOOL OnLButtonDown(UINT nFlags, CPoint pt) { return FALSE; }
- virtual BOOL OnLButtonUp(UINT nFlags, CPoint pt, BOOL bSameCtl)
- { return FALSE; }
- virtual BOOL OnEnterDown() { return FALSE; }
- virtual BOOL OnEnterUp() { return FALSE; }
- virtual BOOL OnTimer() { return FALSE; }
- virtual void OnSysColorChange();
-
- // --------- Example of using Custom Message ----------
- // virtual void OnMessage();
-
- // --------- Virtual Helper Functions ----------
- virtual VCtlHelper* CreateHelper(CWnd *pParent) { return NULL; }
- virtual CRect HelperRect(LPRECT pRect=0, BOOL bGridMode=FALSE)
- { if(pRect) return *pRect; else return m_rectWin; }
- virtual int HelperId() { return -1; }
- virtual BOOL OnBeginHelper(VCtlHelper* pHelper) { return TRUE; }
- virtual BOOL OnEndHelper(VCtlHelper* pHelper) { return TRUE; }
- virtual BOOL IsHelperDirty(VCtlHelper* pHelper) { return FALSE;}
-
- // --------- Overridables ---------------------------
- virtual BOOL OnSetFocus(VCtl *pOldCtl) { return TRUE; }
- virtual BOOL OnKillFocus(VCtl *pNewCtl) { return TRUE; }
- virtual BOOL OnBeginList(CListBox *pListBox) { return TRUE; }
- virtual BOOL OnEndList(CListBox *pListBox) { return TRUE; }
- };
-
- #endif