/**$F
// File: CFlatHeaderCtrl.h
// Version: 3.0.2
//
// Author: Maarten Hoeben
// E-mail: hoeben@nwn.com
//
// Specification of the CFlatHeaderCtrl and associated classes.
//
// This code may be used in compiled form in any way you desire. This
// file may be redistributed unmodified by any means PROVIDING it is
// not sold for profit without the authors written consent, and
// providing that this notice and the authors name and all copyright
// notices remains intact.
//
// An email letting me know how you are using it would be nice as well.
//
// This file is provided "as is" with no expressed or implied warranty.
// The author accepts no liability for any damage/loss of business that
// this product may cause.
//
*/
#if !defined(AFX_FLATHEADERCTRL_H__2162BEB4_A882_11D2_B18A_B294B34D6940__INCLUDED_)
#define AFX_FLATHEADERCTRL_H__2162BEB4_A882_11D2_B18A_B294B34D6940__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define IsShiftDown() ((GetKeyState(VK_SHIFT) & (1 << (sizeof(SHORT) * 8 - 1))) != 0)
#define IsCtrlDown() ((GetKeyState(VK_CONTROL) & (1 << (sizeof(SHORT) * 8 - 1))) != 0)
// FlatHeaderCtrl.h : header file
//
#ifndef COLOR_MENUHILIGHT
#define COLOR_MENUHILIGHT 29
#endif
#include <afxtempl.h>
#include <tchar.h>
#define FLATHEADER_TEXT_MAX 80
#define FLATHEADER_TT_MAGIC - 13111971
// CFlatHeaderCtrl window
class CFlatHeaderCtrl;
class CFHDragWnd;
class CFHDropWnd;
// FlatHeader properties
#define FH_PROPERTY_SPACING 1
#define FH_PROPERTY_ARROW 2
#define FH_PROPERTY_STATICBORDER 3
#define FH_PROPERTY_DONTDROPCURSOR 4
#define FH_PROPERTY_DROPTARGET 5
#define FH_PROPERTY_ENABLETOOLTIPS 6
#define FH_PROPERTY_ENABLEAUTOSIZE 7
// FlatHeader drop result
#define FHDR_DROPPED - 1
#define FHDR_ONHEADER 0
#define FHDR_ONTARGET 1
#define FHDR_PERSISTENT 2
// Extended header styles
#define HDF_EX_AUTOWIDTH 0x0001
#define HDF_EX_INCLUDESORT 0x0002
#define HDF_EX_FIXEDWIDTH 0x0004
#define HDF_EX_TOOLTIP 0x0008
#define HDF_EX_PERSISTENT 0x0010
#define HDF_EX_NODIVIDER 0x0020
#define HDF_EX_HASDATE 0x0040
#define HDF_EX_FIXITEM (HDF_EX_FIXEDWIDTH | HDF_EX_NODIVIDER)
#define FHDR_MIN_COL_WIDTH 10
#define MAXWIDTH(x) (x > 0 ? x : 16384)
#define MINWIDTH(x) (x < FHDR_MIN_COL_WIDTH ? FHDR_MIN_COL_WIDTH : x)
typedef struct _HDITEMEX
{
UINT nStyle;
INT iMinWidth;
INT iMaxWidth;
CString strToolTip;
_HDITEMEX()
:
nStyle(0),
iMinWidth(0),
iMaxWidth(0)
{
};
}
HDITEMEX, FAR * LPHDITEMEX;
class CFlatHeaderCtrl :
public CHeaderCtrl
{
friend class CFHDragWnd;
DECLARE_DYNCREATE(CFlatHeaderCtrl)
// Construction
public:
CFlatHeaderCtrl();
// Attributes
public:
BOOL ModifyProperty(WPARAM wParam, LPARAM lParam);
BOOL GetItemEx(INT iPos, HDITEMEX *phditemex) const;
BOOL SetItemEx(INT iPos, HDITEMEX *phditemex);
UINT GetItemExStyle(INT iPos);
BOOL SetItemExStyle(INT iPos, UINT nStyle);
INT GetItemWidth(LPHDITEM lphdi, BOOL bIncludeSort = FALSE);
INT GetPreviousVariableWidthItem(INT iItem);
void SetSortColumn(INT iPos, BOOL bSortAscending);
INT GetSortColumn(BOOL *pbSortAscending = NULL);
INT GetDropResult();
INT GetWidth();
INT GetMinWidth();
INT GetHeight();
void SetHeight(INT iHeight);
BOOL IsAutoSize();
// Operations
public:
void AutoSizeItems();
void SameWidth(CFlatHeaderCtrl *FlatHeaderCtrl, int iColumn = -1);
LRESULT ItemChanging(NMHDR *pNMHDR);
// Overrides
public:
virtual ~CFlatHeaderCtrl();
virtual void DrawItem(LPDRAWITEMSTRUCT);
virtual void DrawItem(CDC *pDC, CRect rect, LPHDITEM lphdi, BOOL bSort, BOOL bSortAscending);
virtual int OnToolHitTest(CPoint point, TOOLINFO *pTI) const;
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFlatHeaderCtrl)
//}}AFX_VIRTUAL
// Implementation
protected:
BOOL m_bDoubleBuffer;
INT m_iSpacing;
SIZE m_sizeImage;
SIZE m_sizeArrow;
BOOL m_bStaticBorder;
UINT m_nDontDropCursor;
HWND m_hDropTarget;
CRect m_rcDropTarget;
INT m_iDropResult;
INT m_iHotIndex;
BOOL m_bHotMove;
INT m_iHotOrder;
BOOL m_bHotItemResizable;
HDHITTESTINFO m_hdhtiHotItem;
HDITEM m_hdiHotItem;
HDITEMEX m_hdieHotItem;
TCHAR m_szHotItemText[FLATHEADER_TEXT_MAX];
BOOL m_bAutoSize;
BOOL m_bAutoSizing;
BOOL m_bResizing;
BOOL m_bFixWidth;
BOOL m_LButtonUp;
INT iResizing;
CPoint m_ptMovePoint;
CPoint m_ptDownPoint;
INT m_iHotDivider;
COLORREF m_crHotDivider;
CFHDropWnd *m_pDropWnd;
BOOL m_bButtonDownOnItem;
BOOL m_bDragging;
CFHDragWnd *m_pDragWnd;
UINT m_nClickFlags;
CPoint m_ptClickPoint;
BOOL m_bSortAscending;
INT m_iSortColumn;
CArray<HDITEMEX, HDITEMEX> m_arrayHdrItemEx;
COLORREF m_cr3DHighLight;
COLORREF m_cr3DShadow;
COLORREF m_cr3DFace;
COLORREF m_crText;
COLORREF m_ColorMenu;
COLORREF m_crMenuText;
COLORREF m_ColorMenuHilight;
CFont m_font;
INT m_iHeight;
void ReOrder();
void AutoSizeItemsImpl(INT iItem = -1, INT iTotalWidth = 0);
void DrawCtrl(CDC *pDC);
INT DrawImage(CDC *pDC, CRect rect, LPHDITEM hdi, BOOL bRight);
INT DrawBitmap
(
CDC *pDC,
CRect rect,
LPHDITEM hdi,
CBitmap *pBitmap,
BITMAP *pBitmapInfo,
BOOL bRight
);
INT DrawText(CDC *pDC, CRect rect, LPHDITEM lphdi);
INT DrawArrow(CDC *pDC, CRect rect, BOOL bSortAscending, BOOL bRight);
// Generated message map functions
protected:
//{{AFX_MSG(CFlatHeaderCtrl)
afx_msg LRESULT OnInsertItem(WPARAM wparam, LPARAM lparam);
afx_msg LRESULT OnDeleteItem(WPARAM wparam, LPARAM lparam);
afx_msg LRESULT OnSetImageList(WPARAM wparam, LPARAM lparam);
afx_msg LRESULT OnSetHotDivider(WPARAM wparam, LPARAM lparam);
afx_msg LRESULT OnLayout(WPARAM wparam, LPARAM lparam);
afx_msg UINT OnNcHitTest(CPoint point);
afx_msg BOOL OnSetCursor(CWnd *pWnd, UINT nHitTest, UINT message);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
afx_msg void OnPaint();
afx_msg void OnSysColorChange();
afx_msg BOOL OnEraseBkgnd(CDC *pDC);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnCancelMode();
//}}AFX_MSG
afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnGetFont(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
BOOL OnToolTipNotify(UINT nId, NMHDR *pNMHDR, LRESULT *pResult);
public:
afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnHdnTrack(NMHDR *pNMHDR, LRESULT *pResult);
};
// CFHDragWnd window
#define FHDRAGWND_CLASSNAME _T("MFCFHDragWnd")
class CFHDragWnd :
public CWnd
{
// Construction
public:
CFHDragWnd();
// Attributes
public:
// Operations
public:
// Overrrides
protected:
// Drawing
virtual void OnDraw(CDC *pDC);
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFHDragWnd)
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFHDragWnd();
virtual BOOL Create(CRect rect, CFlatHeaderCtrl *pFlatHeaderCtrl, INT iItem, LPHDITEM lphdiItem);
protected:
CFlatHeaderCtrl *m_pFlatHeaderCtrl;
INT m_iItem;
LPHDITEM m_lphdiItem;
// Generated message map functions
protected:
//{{AFX_MSG(CFHDragWnd)
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC *pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
// CFHDropWnd window
#define FHDROPWND_CLASSNAME _T("MFCFHDropWnd")
class CFHDropWnd :
public CWnd
{
// Construction
public:
CFHDropWnd(COLORREF crColor);
// Attributes
public:
// Operations
public:
void SetWindowPos(INT x, INT y);
// Overrrides
protected:
// Drawing ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CFHDropWnd)
protected:
virtual void PostNcDestroy();
//}}AFX_VIRTUAL
// Implementation
public:
virtual ~CFHDropWnd();
virtual BOOL Create(INT iHeight);
protected:
CBrush m_brush;
CRgn m_rgn;
INT m_iHeight;
// Generated message map functions
protected:
//{{AFX_MSG(CFHDropWnd)
afx_msg BOOL OnEraseBkgnd(CDC *pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before
// the previous line.
#endif // !defined(AFX_FLATHEADERCTRL_H__2162BEB4_A882_11D2_B18A_B294B34D6940__INCLUDED_)