#pragma once #include "PropertyGridCombo.h" #include "PropertyGridInPlaceEdit.h" #include #include #include using namespace std; // CPropertyGrid #define WM_PG_ITEMCHANGED WM_USER+486 typedef UINT HSECTION; typedef UINT HITEM; class ICustomItem; class CPropertyGrid : public CWnd { DECLARE_DYNAMIC(CPropertyGrid) public: // display mode //显示模式; enum EDisplayMode { DM_CATEGORIZED = 0, //分类; DM_ALPHABETICAL, //按字母排序; DM_NOSORT //无排序; }; // editing //编辑; enum EEditMode { EM_CUSTOM = 0, //自定义; EM_INPLACE, //就地编辑; EM_DROPDOWN, //下拉; EM_MODAL, //模态(对话框); EM_IMMEDIATE //即时; }; // 项类型; enum EItemType { IT_CUSTOM = 0, //自定义; IT_STRING, //字符串; IT_TEXT, //文本; IT_INTEGER, //整型; IT_DOUBLE, //双精度; IT_COMBO, //下拉框; IT_BOOLEAN, //布尔; IT_DATE, //日期; IT_DATETIME, //日期时间; IT_FILE, //文件; IT_FOLDER, //目录; IT_COLOR, //颜色; IT_FONT, //字体; IT_CHECK //复选框; }; public: CPropertyGrid(); virtual ~CPropertyGrid(); // customization // 定制的接口; bool GetShadeTitles(); // 获取标题阴影状态; void SetShadeTitles(bool shade_titles); // 设置标题是否有阴影; bool GetDrawLines(); // 获取行格线状态; void SetDrawLines(bool draw_lines); // 设置是否有行格线; bool GetDrawGutter(); // 获取列格线状态; void SetDrawGutter(bool draw_gutter); // 设置是否有列格线; bool GetFocusDisabled(); // 获取焦点状态; void SetFocusDisabled(bool focus_disabled); // 设置是否有焦点; bool GetBoldModified(); // 获取黑体状态; void SetBoldModified(bool bold_modified); // 设置是否黑体字体; bool GetBoldEditables(); // 获取黑体编辑状态; void SetBoldEditables(bool bold_editables); // 设置是否黑体编辑; // gutter width int GetGutterWidth(); // 获取列格线宽度; void SetGutterWidth(int gutter_width); // 设置列格线宽度; // custom colors void SetTextColor(COLORREF clrText); void SetTitleColor(COLORREF clrText); void SetBackColor(COLORREF clrBack); void SetShadeColor(COLORREF clrShade); void SetFocusColor(COLORREF clrFocus); void SetHiliteColor(COLORREF clrHilite); void SetEditableColor(COLORREF clrEditable); void SetDisabledColor(COLORREF clrDisabled); // localization void SetTrueFalseStrings(string strTrue, string strFalse); void SetOkCancelStrings(string strOk, string strCancel); void SetDateTimeStrings(string strDate, string strTime); void SetUndefinedString(string strUndefined); void SetEmptyString(string strEmpty); // add a section HSECTION AddSection(string title, bool collapsed = false, HSECTION after = -1); // add items HITEM AddCustomItem(HSECTION, string name, ICustomItem* pItem, bool editable = true, HITEM after = -1); HITEM AddStringItem(HSECTION section, string name, string value, bool editable = true, HITEM after = -1); HITEM AddTextItem(HSECTION section, string name, string value, bool editable = true, HITEM after = -1); HITEM AddIntegerItem(HSECTION section, string name, int value, string format = "", bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddDoubleItem(HSECTION section, string name, double value, string format = "", bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddComboItem(HSECTION section, string name, const vector& values, int cur, bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddBoolItem(HSECTION section, string name, bool value, bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddDateItem(HSECTION section, string name, COleDateTime value, string format = "", bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddDateTimeItem(HSECTION section, string name, COleDateTime value, string format = "", bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddFileItem(HSECTION section, string name, string value, string filter = "", bool editable = true, HITEM after = -1); HITEM AddFolderItem(HSECTION section, string name, string value, string title = "", bool editable = true, HITEM after = -1); HITEM AddColorItem(HSECTION section, string name, COLORREF value, bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddFontItem(HSECTION section, string name, LOGFONT value, bool editable = true, bool undefined = false, HITEM after = -1); HITEM AddCheckItem(HSECTION section, string name, bool value, bool editable = true, bool undefined = false, HITEM after = -1); // contents void ResetContents(); bool RemoveSection(HSECTION hs); bool RemoveItem(HITEM item); void ValidateChanges(); // status int GetNumSections(); int GetSectionSize(HSECTION hs); // get item value bool GetItemValue(HITEM item, string& strValue) const; bool GetItemValue(HITEM item, int& nValue) const; bool GetItemValue(HITEM item, double& dValue) const; bool GetItemValue(HITEM item, bool& bValue) const; bool GetItemValue(HITEM item, COleDateTime& dtValue) const; bool GetItemValue(HITEM item, COLORREF& clrValue) const; bool GetItemValue(HITEM item, LOGFONT& lfValue) const; // set item value bool SetItemValue(HITEM item, const string strValue); bool SetItemValue(HITEM item, const int nValue); bool SetItemValue(HITEM item, const double nValue); bool SetItemValue(HITEM item, const bool bValue); bool SetItemValue(HITEM item, const COleDateTime dtValue); bool SetItemValue(HITEM item, const COLORREF clrValue); bool SetItemValue(HITEM item, const LOGFONT lfValue); // for custom items int GetTextMargin(); CFont* GetFontNormal(); CFont* GetFontBold(); // appearance stuff void SetDisplayMode(EDisplayMode display_mode); void ExpandAll(bool expand); void ExpandSection(HSECTION hs, bool expand); bool IsSectionCollapsed(HSECTION hs); protected: class CItem // 一个项所具有的特性; { public: HITEM m_id; // 项ID; bool m_editable; // 项可编辑否; bool m_undefined; // 项是否定义; EItemType m_type; // 项类型; string m_name; // 项名称; vector m_options; // 项字符操作; /****以下是项框内当前所能表示的值;****/ int m_nValue; // 项的整型表示值; double m_dValue; // 项的双精度表示值; string m_strValue; // 项的字符表示内容; bool m_bValue; // 项是否有值; COleDateTime m_dtValue; // 项的时间表示内容; COLORREF m_clrValue; // 项的颜色表示; LOGFONT m_lfValue; // 项的字体表示; ICustomItem* m_pCustom; // 项的用户定义表示; /****以下是项框内过去所能表示的值;****/ bool m_undefined_old; // 是否被定义; int m_nValue_old; // 旧的整型值; double m_dValue_old; // 旧的浮点值; string m_strValue_old; // 旧的字符内容; bool m_bValue_old; // 过去是否有值; COleDateTime m_dtValue_old; // 旧的时间值; COLORREF m_clrValue_old; // 旧的颜色值; LOGFONT m_lfValue_old; // 旧的字体值; // 该项只有二列;(可自行添加列数) CRect m_rcName; // 项列之一:名称框; CRect m_rcValue; // 项列之一:值框; bool operator==(const HITEM& item) const; bool operator==(const string& name) const; void ValidateChanges(); }; friend bool item_alpha_sort(vector::iterator it1, vector::iterator it2); // 一个段的特性; class CSection { public: HSECTION m_id; // 段ID; string m_title; // 段名; bool m_collapsed; // 是否收缩; vector m_items; // 所包含的项; CRect m_rcSign; // 段标识框(段名框在其内?); CRect m_rcTitle; // 段名框; bool operator==(const HSECTION& section) const; }; // 一个控件所包含的段; vector m_sections; HSECTION m_focused_section; // 焦点所在的段的ID; HITEM m_focused_item; // 焦点所在的项的ID; EDisplayMode m_display_mode; // 显示模式; // 以下为显示模式开关; bool m_shade_titles; // 是否显示标题边框阴影; bool m_draw_lines; // 是否显示行分格线; bool m_draw_gutter; // 是否显示列分格线; bool m_focus_disabled; // 是否禁用焦点; bool m_bold_modified; // 是否可修改; bool m_bold_editables; // 是否可编辑; int m_gutter_width; // 列分格线宽; bool m_resizing_gutter; // 是否再生列分格线; CPoint m_ptLast; // 最后的点; CFont m_fntNormal; // 正常字体; CFont m_fntBold; // 粗体; int m_line_height; // 行为动作开关; CRect m_rect_button; // 按钮框; CWnd* m_control; // 控件; bool m_button_pushed; // 按钮是否按下; bool m_button_depressed; // 按钮是否按住; bool m_value_clicked; // 值是否单击; bool m_custom_tracking; // 下拉框是否变动; HSECTION m_section_id; // 当前段ID; HITEM m_item_id; // 当前项ID; string m_strTrue; string m_strFalse; string m_strOk; string m_strCancel; string m_strDate; string m_strTime; string m_strUndefined; string m_strEmpty; COLORREF m_clrText; // 文本颜色; COLORREF m_clrTitle; // 标题颜色; COLORREF m_clrBack; // 背景颜色; COLORREF m_clrShade; // 阴影颜色; COLORREF m_clrFocus; // 焦点选中时颜色; COLORREF m_clrHilite; // 隐藏时颜色; COLORREF m_clrEditable; // 可编辑时颜色; COLORREF m_clrDisabled; // 不可编辑时颜色; protected: DECLARE_MESSAGE_MAP() // init control void InitControl(); // 初始化该控件; // drawing void DrawItem(CDC& dc, int w, int x, int y, vector::iterator& it); // item management CSection* FindSection(HSECTION hs) const; // 通过ID查找; CItem* FindItem(HITEM hi) const; // 通过ID查找; HITEM AddItem(HSECTION hs, EItemType type, string name, void* pValue, bool editable, bool undefined, HITEM after); // scrolling stuff CScrollBar m_scrollbar; bool m_scroll_enabled; int GetScrollOffset(); void RecalcLayout(); // editing EEditMode GetEditMode(CItem& item); void DeleteEditControl(); void EditFocusedItem(); // movement in list void MoveForward(HSECTION& focused_section, HITEM& focused_item); // keyboard void FocusNextItem(); void FocusPrevItem(); CRect AdjustCheckBoxRect(CRect* rc); protected: virtual void PreSubclassWindow(); public: afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnDestroy(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnPaint(); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nHitTest, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); afx_msg LRESULT OnComboSelChanged(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnEditChanged(WPARAM wParam, LPARAM lParam); afx_msg LRESULT OnDateChanged(WPARAM wParam, LPARAM lParam); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg UINT OnGetDlgCode(); afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); };