⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cgridctrl.h

📁 此次上传的使linux下的文件传输协议
💻 H
📖 第 1 页 / 共 2 页
字号:
#if !defined(AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_)
#define AFX_GRIDCTRL_H__519FA702_722C_11D1_ABBA_00A0243D1382__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "CellRange.h"
#include <afxole.h>
#include "CellID.h"	// Added by ClassView
#include "GridCellImage.h"
#include "GridCellXpButton.h"
#include "GridCell.h"	// Added by ClassView
#include "XpButton.h"	// Added by ClassView

#define GRIDCTRL_CLASSNAME _T("MFCGridCtrl")
#define IDC_INPLACE_EDITCONTROL   8  
#define IDC_INPLACE_COMBOBOXCONTROL   9


#define IsSHIFTpressed() ( (GetKeyState(VK_SHIFT) & (1 << (sizeof(SHORT)*8-1))) != 0   )
#define IsCTRLpressed()  ( (GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT)*8-1))) != 0 )

/*typedef struct _GV_ITEM { 
    int      row,col;     // Row and Column of item
    UINT     mask;        // Mask for use in getting/setting cell data
    UINT     state;       // cell state (focus/hilighted etc)
    UINT     nFormat;     // Format of cell
    CString  szText;      // Text in cell
    int      iImage;      // index of the list view item抯 icon
    COLORREF crBkClr;     // Background colour (or CLR_DEFAULT)
    COLORREF crFgClr;     // Forground colour (or CLR_DEFAULT)
    LPARAM   lParam;      // 32-bit value to associate with item 
    LOGFONT  lfFont;      // Cell font
	int      nCtrlType;   // 控制的类型
} GV_ITEM; */

// Grid line selection
#define GVL_NONE                0
#define GVL_HORZ                1
#define GVL_VERT                2
#define GVL_BOTH                3

// Cell data mask
#define GVIF_TEXT               LVIF_TEXT
#define GVIF_IMAGE              LVIF_IMAGE
#define GVIF_PARAM              LVIF_PARAM
#define GVIF_STATE              LVIF_STATE
#define GVIF_BKCLR              (GVIF_STATE<<1)
#define GVIF_FGCLR              (GVIF_STATE<<2)
#define GVIF_FORMAT             (GVIF_STATE<<3)
#define GVIF_FONT               (GVIF_STATE<<4)
#define GVIF_CTRLTYPE           (GVIF_STATE<<5)

// Cell states
#define GVIS_FOCUSED            0x0001
#define GVIS_SELECTED           0x0002
//#define GVIS_READONLY           0x0004
#define GVIS_MODIFIED           0x0008

#define GVNI_FOCUSED            0x0001
#define GVNI_SELECTED           0x0002
#define GVNI_DROPHILITED        0x0004
//#define GVNI_READONLY           0x0008

#define GVNI_ABOVE              LVNI_ABOVE
#define GVNI_BELOW              LVNI_BELOW
#define GVNI_TOLEFT             LVNI_TOLEFT
#define GVNI_TORIGHT            LVNI_TORIGHT
#define GVNI_ALL                (LVNI_BELOW|LVNI_TORIGHT)

#define GVHT_DATA               0x0000
#define GVHT_TOPLEFT            0x0001
#define GVHT_COLHDR             0x0002
#define GVHT_ROWHDR             0x0004
#define GVHT_COLSIZER           0x0008
#define GVHT_ROWSIZER           0x0010
#define GVHT_LEFT               0x0020
#define GVHT_RIGHT              0x0040
#define GVHT_ABOVE              0x0080
#define GVHT_BELOW              0x0100

typedef struct tagNM_GRIDVIEW { 
    NMHDR hdr; 
    int   iRow; 
    int   iColumn; 
} NM_GRIDVIEW;

typedef struct tagGV_DISPINFO 
{ 
    NMHDR   hdr; 
	int iRow;          //行
	int iCol;          //列
	CString szText;    //字符串
	UINT nLastChar;    //最后的字符
} GV_DISPINFO;

#define GVN_COLUMNCLICK         LVN_COLUMNCLICK
#define	GVN_DELETEITEM          LVN_DELETEITEM
#define GVN_SELCHANGING         LVN_BEGINLABELEDIT+1 // LVN_FIRST-4
#define GVN_SELCHANGED          LVN_BEGINLABELEDIT+2 // LVN_FIRST-3
#define GVN_ONLBUTTONUP         LVN_BEGINLABELEDIT+3 // LVN_FIRST-2
#define GVN_ONCLICKXPBUTTON     LVN_BEGINLABELEDIT+4 // LVN_FIRST-2
#define GVN_ONCLICKRADIO        LVN_BEGINLABELEDIT+5 // LVN_FIRST-2
#define GVN_ONCLICKCHECKBOX     LVN_BEGINLABELEDIT+6 // LVN_FIRST-2
#define GVN_ONENDEDIT           LVN_BEGINLABELEDIT+7 
#define GVN_ONENDCOMBOBOX       LVN_BEGINLABELEDIT+8


class CGridImage  //单元格图像类管理
{
public:
	CGridImage()
	{
		pImage=NULL;
	};
	~CGridImage()
	{
		DeleteAllData();
	};

	CArray<CJnImage*,CJnImage*> aryImage;   
	CJnImage* pImage;
	void DeleteAllData()
	{
		for(int i=0;i<aryImage.GetSize();i++)
		{
			pImage=aryImage.GetAt(i);
			if(pImage)
			{
				pImage->Free();
				delete pImage;
			}
			pImage=NULL;
		}
		aryImage.RemoveAll();
	}
};

/*
创建单元格时,需要对列的属性进行查询,列的属性有三种情况:
1,按照第一行(固定行)的单元格属性进行创建
2,按照第一行(非固定行)的单元格属性进行创建
3,按照上一行的单元格属性进行创建
4,按照列的安排属性进行创建
5,默认是文本类型的创建
*/
enum GridCreateCtrlEnum
{
	JnGridCreateText,            //默认是文本类型创建法
	JnGridCreateFromFix1,        //按照列的第一个固定单元格创建
	JnGridCreateFormNoFix1,      //按照列的第一个非固定单元格创建
	JnGridCreateFormPre,         //按照当前行上面一行进行创建
	JnGridCreateFormDefCol,      //按照默认列的属性设置进行创建
};

class CGridColumn : public CObject
{
public:
	CGridColumn()
	{
		m_nOrder=0;       //未排序状态
		m_nWidth=20;
		m_bSort=TRUE;
		m_nType=JnGridChar;
		m_cBkClr = CLR_DEFAULT;
		m_cFgClr = CLR_DEFAULT;
		m_nDefCtrlType=JnCtrlText;
		m_nCreateType=JnGridCreateText;
	}
	int m_nOrder;      //排序次序(0未排序,1正序,2倒序)   //当针对某个列进行排序时,首先自动设置其他列为未排序状态
	int m_nWidth;      //列的宽度
	BOOL m_bSort;      //是否允许双击排序功能
	GridDataTypeEnum m_nType;      //字段类型	
	COLORREF m_cBkClr;           //默认背景颜色
	COLORREF m_cFgClr;           //默认文本颜色
	GridCtrlTypeEnum m_nDefCtrlType;     //默认的单元格控制类型
	GridCreateCtrlEnum m_nCreateType;    //单元格创建的类型
};

class CGridCtrlStatus
{
public:
	CCellID m_Cell;
	int m_nStatus;    //控件的状态
	CGridCtrlStatus()
	{
		m_Cell.col=-1;
		m_Cell.row=-1;
		m_nStatus=-1;
	};
};

struct tagGridRadio
{
	tagGridRadio()
	{
		nGroup=0;
		nCurRow=-1;
		nCurCol=-1;
	};
	CUIntArray aryRow;      //Group中所有Radio的行
	CUIntArray aryCol;      //Group中所有Radio的列
	int nGroup;             //Group的组标志
	int nCurRow;            //当前处于选中状态的Radio的行标志
	int nCurCol;            //当前处于选中状态的Radio的列标志
};

typedef CTypedPtrArray<CObArray, CGridCell*> GRID_ROW;

class CGridCtrl;
void AFXAPI DDX_GridControl(CDataExchange* pDX, int nIDC, CGridCtrl& rControl);

class CGridCtrl : public CWnd
{
public:
    CGridCtrl(int nRows = 0, int nCols = 0, int nFixedRows = 0, int nFixedCols = 0);
    DECLARE_DYNCREATE(CGridCtrl)

    BOOL Create(const RECT& rect, CWnd* parent, UINT nID,
                DWORD dwStyle = WS_CHILD | WS_BORDER | WS_TABSTOP | WS_VISIBLE);
    BOOL SubclassWindow(HWND hWnd);

// Attributes
public:
    int  GetRowCount() const                    { return m_nRows; }
    int  GetColumnCount() const                 { return m_nCols; }
    int  GetFixedRowCount() const               { return m_nFixedRows; }
    int  GetFixedColumnCount() const            { return m_nFixedCols; }
    BOOL SetRowCount(int nRows = 10);
    BOOL SetColumnCount(int nCols = 10);
    BOOL SetFixedRowCount(int nFixedRows = 1);
    BOOL SetFixedColumnCount(int nFixedCols = 1);

    int  GetRowHeight(int nRow) const;
    BOOL SetRowHeight(int row, int height);
    int  GetColumnWidth(int nCol) const;
    BOOL SetColumnWidth(int col, int width);

    BOOL GetCellOrigin(int nRow, int nCol, LPPOINT p) const;
    BOOL GetCellOrigin(const CCellID& cell, LPPOINT p) const;
    BOOL GetCellRect(int nRow, int nCol, LPRECT pRect) const;
    BOOL GetCellRect(const CCellID& cell, LPRECT pRect) const;

    int  GetFixedRowHeight() const;
    int  GetFixedColumnWidth() const;
    long GetVirtualWidth() const;
    long GetVirtualHeight() const;

    void     SetTextColor(COLORREF clr)           { m_crTextColour = clr;             }
    COLORREF GetTextColor() const                 { return m_crTextColour;            }
    void     SetTextBkColor(COLORREF clr)         { m_crTextBkColour = clr;           }
    COLORREF GetTextBkColor() const               { return m_crTextBkColour;          }
    void     SetBkColor(COLORREF clr)             { m_crBkColour = clr;               }
    COLORREF GetBkColor() const                   { return m_crBkColour;              }
    void     SetFixedTextColor(COLORREF clr)      { m_crFixedTextColour = clr;        }
    COLORREF GetFixedTextColor() const            { return m_crFixedTextColour;       }
    void     SetFixedBkColor(COLORREF clr)        { m_crFixedBkColour = clr;          }
    COLORREF GetFixedBkColor() const              { return m_crFixedBkColour;         } 
    void     SetGridColor(COLORREF clr)           { m_crGridColour = clr;             }
    COLORREF GetGridColor() const                 { return m_crGridColour;            }

    int GetSelectedCount() const                  { return m_SelectedCellMap.GetCount(); }

    CCellID GetFocusCell() const                  { return m_idCurrentCell;           }

    void SetGridLines(int nWhichLines = GVL_BOTH) { m_nGridLines = nWhichLines; 
                                                    if (::IsWindow(GetSafeHwnd())) Invalidate(); }
    int  GetGridLines() const                     { return m_nGridLines;              }

    void SetEditable(BOOL bEditable = TRUE)       { m_bEditable = bEditable;          }

    void SetModified(BOOL bModified = TRUE, int nRow = -1, int nCol = -1);

    BOOL GetModified() const                      { return m_bModified;               }
    void SetListMode(BOOL bEnableListMode = TRUE) { m_bListMode = bEnableListMode;    }
    BOOL GetListMode() const                      { return m_bListMode;               }
    void EnableSelection(BOOL bEnable = TRUE)     { ResetSelectedRange(); m_bEnableSelection = bEnable; ResetSelectedRange(); }
    BOOL IsSelectable() const                     { return m_bEnableSelection;        }
    void SetRowResize(BOOL bResize = TRUE)        { m_bAllowRowResize = bResize;      }
    BOOL GetRowResize() const                     { return m_bAllowRowResize;         }
    void SetColumnResize(BOOL bResize = TRUE)     { m_bAllowColumnResize = bResize;   }
    BOOL GetColumnResize() const                  { return m_bAllowColumnResize;      }
    void SetHeaderSort(BOOL bSortOnClick = TRUE)  { m_bSortOnClick = bSortOnClick;    }
    BOOL GetHeaderSort() const                    { return m_bSortOnClick;            }
    void SetHandleTabKey(BOOL bHandleTab = TRUE)  { m_bHandleTabKey = bHandleTab;     }
    BOOL GetHandleTabKey() const                  { return m_bHandleTabKey;           }
    void SetDoubleBuffering(BOOL bBuffer = TRUE)  { m_bDoubleBuffer = bBuffer;        }
    BOOL GetDoubleBuffering() const               { return m_bDoubleBuffer;           }
//    BOOL   SetItem(const GV_ITEM* pItem);
//    BOOL   GetItem(GV_ITEM* pItem);
    BOOL   SetItemText(int nRow, int nCol, LPCTSTR str);
    virtual CString GetItemText(int nRow, int nCol);
    BOOL   SetItemData(int nRow, int nCol, LPARAM lParam);
    LPARAM GetItemData(int nRow, int nCol) const;
    BOOL   SetItemState(int nRow, int nCol, UINT state);
    UINT   GetItemState(int nRow, int nCol) const;
    BOOL   SetItemFormat(int nRow, int nCol, GridDrawTextTypeEnum nFormat);
    GridDrawTextTypeEnum   GetItemFormat(int nRow, int nCol) const;
	BOOL   SetItemBkColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
	COLORREF GetItemBkColour(int nRow, int nCol) const;
	BOOL   SetItemFgColour(int nRow, int nCol, COLORREF cr = CLR_DEFAULT);
	COLORREF GetItemFgColour(int nRow, int nCol) const;
	BOOL SetItemFont(int nRow, int nCol, LOGFONT* lf);
	LOGFONT* GetItemFont(int nRow, int nCol) const;

// Operations
public:
    int  InsertColumn(LPCTSTR strHeading, GridDrawTextTypeEnum nFormat = JnDrawTextVCenLeft, int nColumn = -1);
    int  InsertRow(LPCTSTR strHeading, int nRow = -1);
    BOOL DeleteColumn(int nColumn);
    BOOL DeleteRow(int nRow);
    BOOL DeleteNonFixedRows();
    BOOL DeleteAllItems();

    BOOL AutoSizeRow(int nRow);
    BOOL AutoSizeColumn(int nCol);
    void AutoSizeRows();
    void AutoSizeColumns();
    void AutoSize();
    void ExpandColumnsToFit();
    void ExpandRowsToFit();
    void ExpandToFit();

    CSize GetTextExtent(LPCTSTR str, BOOL bUseSelectedFont = TRUE);
    void EnsureVisible(CCellID &cell);
    void EnsureVisible(int nRow, int nCol);
    BOOL IsCellVisible(int nRow, int nCol) const;
    BOOL IsCellVisible(CCellID cell) const;

    // SetRedraw stops/starts redraws on things like changing the # rows/columns
    // and autosizing, but not for user-intervention such as resizes
    void SetRedraw(BOOL bAllowDraw, BOOL bResetScrollBars = FALSE);
    BOOL RedrawCell(int nRow, int nCol, CDC* pDC = NULL);
    BOOL RedrawCell(const CCellID& cell, CDC* pDC = NULL);
    BOOL RedrawRow(int row);
    BOOL RedrawColumn(int col);


    CCellRange GetCellRange() const;
    CCellRange GetSelectedCellRange() const;
    void SetSelectedRange(const CCellRange& Range, BOOL bForceRepaint = FALSE);
    void SetSelectedRange(int nMinRow, int nMinCol, int nMaxRow, int nMaxCol,
                          BOOL bForceRepaint = FALSE);
    BOOL IsValid(int nRow, int nCol) const;
    BOOL IsValid(const CCellID& cell) const;
    BOOL IsValid(const CCellRange& range) const;

    // Clipboard and cut n' paste operations



    CCellID GetNextItem(CCellID& cell, int nFlags) const;

    BOOL SortTextItems(int nCol, BOOL bAscending);
    BOOL SortDate(int nCol, BOOL bAscending);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -