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

  1. // -------------------------------------------------------------------------
  2. // Copyright @ 1997 TCK Software, Incorporated
  3. // All Rights Reserved
  4. // -------------------------------------------------------------------------
  5. #ifndef __VFUTIL_H__
  6. #define __VFUTIL_H__
  7.  
  8. #include <afxTempl.h>
  9. #include <afxdisp.h>        // MFC OLE automation classes
  10.  
  11. #ifdef VF_STATIC
  12.     #undef AFX_EXT_CLASS
  13.     #define AFX_EXT_CLASS
  14. #endif
  15.  
  16. #ifndef COLOR_CUSTOM
  17.     #define COLOR_CUSTOM    -1        // For specifying custom colors
  18. #endif
  19.  
  20. // --- Not actually used yet ---
  21. #ifndef COLOR_DEFAULT
  22.     #define COLOR_DEFAULT    -2        // For specifying the default color
  23. #endif
  24.  
  25. // -------------------------------------------------------------------------
  26. // Utility Functions
  27. // -------------------------------------------------------------------------
  28. AFX_EXT_CLASS CString        VfuGetLastErrorText(DWORD error=0);
  29. AFX_EXT_CLASS void            VfuParseList(LPCTSTR xString, CStringArray &xArray,
  30.                                          _TCHAR xToken=_T(';'));
  31. AFX_EXT_CLASS DROPEFFECT    VfuDoDragDrop(LPCTSTR szText, 
  32.                                           DROPEFFECT dropEffect=DROPEFFECT_COPY,
  33.                                           CLIPFORMAT=CF_TEXT);
  34. AFX_EXT_CLASS BOOL            VfuGetDropText(COleDataObject* pDataObject,
  35.                                            CString &rString, CLIPFORMAT=CF_TEXT);
  36. AFX_EXT_CLASS DROPEFFECT    VfuDoDragDropData(LPVOID pData, int nSize, 
  37.                                           DROPEFFECT dropEffect=DROPEFFECT_COPY,
  38.                                           CLIPFORMAT=CF_TEXT);
  39. AFX_EXT_CLASS BOOL            VfuGetDropData(COleDataObject* pDataObject,
  40.                                            LPVOID pData, int nSize,
  41.                                            CLIPFORMAT=CF_TEXT);
  42. AFX_EXT_CLASS void            VfuDraw3dRect(CDC *pDC, LPCRECT lpRect, COLORREF clrTopLeft,
  43.                                           COLORREF clrBottomRight);
  44.  
  45. // -------------------------------------------------------------------------
  46. // VClipObj makes if easier to add to a clipping region, the revert back
  47. // -------------------------------------------------------------------------
  48. class AFX_EXT_CLASS VClipObj
  49. {
  50. protected:
  51.     CDC*    m_pDC;                // Device context
  52.     BOOL    m_bClipSet;            // Do we have a clip region set by us?
  53.     BOOL    m_bHaveOldRgn;        // Do we have an old clipping region
  54.     HRGN    m_hOldRgn;            // Handle to old clipping region
  55. public:
  56.     VClipObj();                                // Constructor
  57.     VClipObj(CDC *pDC, LPRECT pRect);        // Constructor with args
  58.     ~VClipObj();                            // Destructor
  59.  
  60.     void    Set(CDC *pDC, LPRECT pRect);    // Set the clipping region
  61.     void    Set(CDC *pDC, LPPOINT lpPoints, int nCount, int nMode);
  62.     void    Remove();                        // Remove/Reset clipping region
  63. };
  64.  
  65. // -------------------------------------------------------------------------
  66. // VColor makes if easier to switch between custom and system colors
  67. // within your code.  Just use a VColor!
  68. // -------------------------------------------------------------------------
  69. class AFX_EXT_CLASS VColor : public CObject
  70. {
  71. protected:
  72.     int            m_nColorIdx;        // Id of system color or COLOR_CUSTOM
  73.     COLORREF    m_color;            // Custom color when using COLOR_CUSTOM
  74. public:
  75.     DECLARE_SERIAL(VColor);
  76.     VColor()    { m_nColorIdx = COLOR_CUSTOM; m_color = RGB(0,0,0); }
  77.     ~VColor()    {};                    // Destructor
  78.  
  79.     int        ColorIdx()                { return m_nColorIdx; }
  80.     void    ColorIdx(int nClrIdx)    { m_nColorIdx = nClrIdx; }
  81.     void    CustomRGB(COLORREF clr)    { m_color = clr; }
  82.     void    UseCustomRGB(COLORREF clr)    
  83.             { m_color = clr; m_nColorIdx = COLOR_CUSTOM; }
  84.  
  85.     COLORREF    CustomRGB()            { return m_color; }
  86.     COLORREF    GetRGB()
  87.     { return (m_nColorIdx == COLOR_CUSTOM) ? m_color : GetSysColor(m_nColorIdx); }
  88.  
  89.     void    SetColor(LPCTSTR szString);    // Sets color using the string value
  90.     CString ColorString();            // Returns red;green;blue or WINDOW, etc.
  91.     CString    ColorIdxString()        { return ColorIdxString(m_nColorIdx); }
  92.  
  93.     VColor& operator=(VColor& that);
  94.  
  95.     static CString    ColorIdxString(int nColorIdx);
  96.     static int        StringToColorIdx(LPCTSTR szString);
  97.  
  98. // Implementation
  99. public:
  100.     friend CArchive& AFXAPI operator<<(CArchive& ar, const VColor& color);
  101.     friend CArchive& AFXAPI operator>>(CArchive& ar, VColor& color);
  102.  
  103.     virtual void Serialize(CArchive& ar);
  104. };
  105.  
  106.  
  107. // -------------------------------------------------------------------------
  108. // A font helper object
  109. // -------------------------------------------------------------------------
  110. class AFX_EXT_CLASS VFont
  111. {
  112. public:
  113.     VFont();
  114.     ~VFont();
  115.     // virtual ~VFont();
  116.  
  117.     LOGFONT&    Logfont()        { return m_lf; }
  118.     CFont*        Font()            { return m_pFont; }
  119.     BOOL        SetFont(LOGFONT &lf);
  120.  
  121.     BOOL        operator ==(LOGFONT &lf);
  122.  
  123. protected:
  124.     LOGFONT    m_lf;
  125.     CFont    *m_pFont;                // pointer to the Font
  126. };
  127. typedef CList<VFont, VFont&>        VFontList;
  128.  
  129. // -------------------------------------------------------------------------
  130. // A collection of fonts
  131. // -------------------------------------------------------------------------
  132. class AFX_EXT_CLASS VFonts
  133. {
  134. protected:
  135.     VFontList        m_fontList;            // Font list
  136.  
  137. public:
  138.     VFonts() {};                        // Constructor
  139.  
  140.     CFont*        Get(LOGFONT &lf);
  141.     CFont*        Get(LPCTSTR szFace, int ptSize=100, BOOL bBold=FALSE,
  142.                         BOOL bItalic=FALSE, BOOL bUnderline=FALSE);
  143.     CFont*        GetEx(LPCTSTR szFace, int ptSize=100, int nWeight=0,
  144.                         BOOL bItalic=FALSE, BOOL bUnderline=FALSE);
  145.  
  146.     CFont*        GetOrAdd(LOGFONT &lf);
  147.     CFont*        GetOrAdd(LPCTSTR szFace, int ptSize=100, BOOL bBold=FALSE,
  148.                             BOOL bItalic=FALSE, BOOL bUnderline=FALSE);
  149.     CFont*        GetOrAddEx(LPCTSTR szFace, int ptSize=100, int nWeight=0,
  150.                             BOOL bItalic=FALSE, BOOL bUnderline=FALSE);
  151.  
  152.     BOOL        Remove(LOGFONT &lf);
  153.     BOOL        Remove(LPCTSTR szFace, int ptSize=100, BOOL bBold=FALSE,
  154.                             BOOL bItalic=FALSE, BOOL bUnderline=FALSE);
  155.     BOOL        RemoveEx(LPCTSTR szFace, int ptSize=100, int nWeight=0,
  156.                             BOOL bItalic=FALSE, BOOL bUnderline=FALSE);
  157.  
  158.     void        RemoveAll()            { m_fontList.RemoveAll(); }
  159. };
  160.  
  161.  
  162. #endif
  163.