////////////////////////////////////////////////////////////////////////////
//
//	Name		:	CSwiListCtrl.h
//
//	Purpose		:	Generic ListCtrl with sorting capabilities
//
//	Written		:	chow	12/2000
//  Revision    :   svuong	09/2009 Stripped down 
//
//	Description	:	Sorts on the ListCtrl's text data or param data
//					WARNING: Do not modify the list ctrl's param data if
//					you plan on using the text data to sort.  Otherwise,
//					unpredicatble behaviour will most likelh occur.
//
//	Copyright (c) 2001 Sierra Wireless Inc. All rights reserved
/////////////////////////////////////////////////////////////////////////////

#if !defined CSWILISTCTRL_H
#define CSWILISTCTRL_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// ListSort.h : header file
//

class CItemEdit;

// Custom Item properties
struct S_ITEMPROP
{
	bool			bReadOnly;	// read only?
	bool			bPassword;	// password masked field?
	bool			bNumeric;	// numeric only input?
	int				iMaxLen;	// maximum string length
};

/////////////////////////////////////////////////////////////////////////////
//
//   Function   :	GetItemProperties
//
//   Description:	Callback function used to retrieve any custom item properties
//
//   Arguments  :	[in]lParam		- itemdata
//					[in]nItem		- item index
//					[in]nSubitem	- subitem index
//					[out]prop		- properties
//
//   Returns:   :	bool if properties retrieved successfully
//
//   Comments   :	none
//
/////////////////////////////////////////////////////////////////////////////
typedef bool (CALLBACK *PFNGETITEMPROP)(LPARAM lParam, int nItem, int iSubItem, S_ITEMPROP& prop);

/////////////////////////////////////////////////////////////////////////////
//
//   Function   :	PopulateEditBox
//
//   Description:	Callback function used to populate a custom in-place
//					edit box
//
//   Arguments  :	[in]lParam1		- itemdata
//					[in]pEdit		- editcontrol
//
//   Returns:   :	none
//
//   Comments   :	This function is called upon primarily to have the
//					edit control populated properly with the default text.
//					ReadOnly, Password, and Numeric properties are already
//					set
//
/////////////////////////////////////////////////////////////////////////////
typedef void (CALLBACK *PFNPOPULATEEDITBOX)(LPARAM lParam1, CEdit* pEdit);


/////////////////////////////////////////////////////////////////////////////
// CSwiListCtrl window

class CSwiListCtrl : public CListCtrl
{
// Construction
public:
	CSwiListCtrl(CDialog  *pParentDlg = NULL, bool bUpdateHeader = true);
	virtual		~CSwiListCtrl();
	void		InitControls();

    void		SetParent (CDialog  *pParentDlg) { m_pParentDlg = pParentDlg;}
    CDialog		*GetParentDlg() const { return m_pParentDlg;}

	////////////////////////////////////////////////////////////////////////////////
	//
	//   Function   :	SetFont
	//
	//   Description:	Set dialog font
	//
	//   Arguments  :	none
	//
	//   Returns:   :	none
	//
	//   Comments   :	none
	//
	////////////////////////////////////////////////////////////////////////////////
	void		SetFont(CFont*	pFont, BOOL	bRedraw = TRUE);

	void		SetGetItemPropFn(PFNGETITEMPROP pFn);
	void		SetEditBoxFn(PFNPOPULATEEDITBOX pFn);
	BOOL		DeleteAllItems();
	void		EditItem(int nItem, int nSubItem);

	afx_msg int		OnCreate(LPCREATESTRUCT lpCreateStruct);

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSwiListCtrl)
	protected:
	virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	//}}AFX_VIRTUAL

	// Generated message map functions
protected:

	int				GetColumnCount();
	virtual void	DrawItem(LPDRAWITEMSTRUCT lpDrawItem);
	void			DrawSubItem(int nSubItem, LPDRAWITEMSTRUCT lpDrawItem, 
								CDC* pDC);
	void			DrawSeparator(CDC* pDC, LPDRAWITEMSTRUCT lpDrawItem); 
	void			UpdateHeader();
	void			DrawEditItem(int nItem, int nSubItem, LPDRAWITEMSTRUCT lpDrawItem, CDC* pDC);
	void			EditItemEdit(int nItem, int nSubItem, S_ITEMPROP& itemProp, LPCRECT pRectItem);
	void			HideEditCtrls();
	int				GetColumnOffset(int iColumn);
	BOOL			GetSubItemRectEx(int iItem, int iSubItem, int nArea, CRect &ref);
	void			SaveColumnWidths();
	void			RestoreColumnWidths();

	CArray<int,int>	m_arrayNoResize;

    CDialog         *m_pParentDlg;		//Parent dialog

	bool			m_bEditCtrls;		// are we using embedded edit controls?

	CSize			m_sizeLast;			// Last size of control

	COLORREF		m_crSepText;		// Separator Text color
	COLORREF		m_crSepBg;			// Separator background color
	UINT			m_nSepFmt;			// Separator format 

	CItemEdit*		m_pEdit;			// pointer to inplace edit ctrl
	PFNGETITEMPROP	m_pFnGetItemProp;	// callback to determine if item is editable
	PFNPOPULATEEDITBOX
					m_pFnPopulateEditbox;	// callback to populate editbox
	int				m_nItemEdit;		// item being edited
	int				m_nSubItemEdit;		// sub item being edited
	CUIntArray		m_arrColWidths;		// column width percentages
	UINT			m_nTextFormat;		// format to draw text

	//{{AFX_MSG(CSwiListCtrl)
	

	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
	afx_msg void OnKeydown(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg BOOL OnItemClick(NMHDR* pNMHDR, LRESULT *pResult);
	afx_msg void OnHdnTrack(NMHDR *pNMHDR, LRESULT *pResult);
	afx_msg void OnHdnEndtrack(NMHDR *pNMHDR, LRESULT *pResult);
};

#endif // CSWILISTCTRL_H
