#if !defined(AFX_SELECTPECIPIENTSDLG_H__E085F68F_C886_4076_BDB9_DD3C5BE0376B__INCLUDED_)
#define AFX_SELECTPECIPIENTSDLG_H__E085F68F_C886_4076_BDB9_DD3C5BE0376B__INCLUDED_

#if _MSC_VER > 1000
//	int CALLBACK CompareTreeItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
#pragma once
	int CALLBACK CompareListItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
#endif // _MSC_VER > 1000
// SelectPecipientsDlg.h : header file
//

#include "resource.h"
#include "apl_gui.h"
#include "aplNetStepData.h"
#include "ResizableDialog.h"

class CaplAPI;

#define CR_ICON_PERSON			0
#define CR_ICON_ORGANIZATION	1
#define CR_ICON_OFFICIAL		2

bool spdStrInclude(const CString &s1, const CString &s2, CaplInstance *inst, CaplAPI *api);
HTREEITEM find_item_forw(CTreeCtrl *tree,CString &val,HTREEITEM from, CaplAPI *api);
HTREEITEM find_item_back(CTreeCtrl *tree,CString &val,HTREEITEM from, CaplAPI *api);
HTREEITEM find_last_item(CTreeCtrl *tree);

/////////////////////////////////////////////////////////////////////////////
// CSelectRecipientsDlg dialog

class CaplOrgStructHelper;

class CSelectRecipientsDlg : public CResizableDialog
{
	CaplOrgStructHelper *m_helper;  // реализует новый алгоритм построения дерева


	class CItemChilds
	{
	public:
		CItemChilds(){m_inst= 0;m_bRoot=true;m_bMyGroup=false;}
		CaplInstance* m_inst;
		aplExtent m_childs;
		bool m_bRoot;
		bool m_bMyGroup;
	};

// Construction
public:
	CSelectRecipientsDlg(CWnd* pParent = NULL);   // standard constructor
	~CSelectRecipientsDlg();

	CString m_sTitle;
	CaplAPI *m_api;

	bool m_bShowPerWG;
	bool m_bTraverseTree;
	bool m_bSingleSelect;	//режим выбора одного объекта
	bool m_bExpand;
	long m_mode;			//какие объекты выбираем

	CaplInstance* m_curPerson;
	aplExtent m_resExt;
	aplExtent m_poExt;
	CaplInstance* m_inst;
	
protected:
	CImageList m_imageListTree;
	CImageList m_imageListList;

	HTREEITEM m_allGroups;
	HTREEITEM m_myGroups;
	bool m_bDblCl;
	bool m_bResized;
	aplExtent m_sirchResult;
	bool m_bRound1;

	void FillTreeForSingleSelection();
	void FillRecipientsList();
	void FillTree(aplExtent &RootItems);

	void AddItem(HTREEITEM item, bool bAddAll);
	static int CALLBACK CompareTreeItems(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);

public:
// Dialog Data
	//{{AFX_DATA(CSelectRecipientsDlg)
	enum { IDD = IDD_RECIPIENTS_SELECT_DIALOG };
	CaplButton	m_btnFBegin;
	CaplButton	m_btnFBack;
	CaplButton	m_btnFForward;
	CEdit	m_edFindStr;
	CButton	m_mainStatic;
	CStatic	m_poStatic;
	CListCtrl	m_listCtrl;
	CTreeCtrl	m_treeCtrl;
	CaplButton	m_cancelBtn;
	CaplButton	m_okBtn;
	CaplButton	m_deleteBtn;
	CaplButton	m_addBtn;
	CaplButton	m_findBtn;
	CString	m_sTreeTitle;
	//}}AFX_DATA

	void SetAnchors();
	
// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSelectRecipientsDlg)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual void CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType = adjustBorder);
	//}}AFX_VIRTUAL

	void TreeContextMenu(HTREEITEM hitem,POINT point);

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CSelectRecipientsDlg)
	virtual void OnOK();
	virtual void OnCancel();
	afx_msg void OnAddButton();
	afx_msg void OnDeleteButton();
	virtual BOOL OnInitDialog();
	afx_msg void OnItemexpandedPersonOrgTree(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnRecFindButton();
	afx_msg void OnDblclkPersonOrgTree(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnItemexpandingPersonOrgTree(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnSelchangedPersonOrgTree(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnFindForward();
	afx_msg void OnFindBack();
	afx_msg void OnButton4Beg();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SELECTPECIPIENTSDLG_H__E085F68F_C886_4076_BDB9_DD3C5BE0376B__INCLUDED_)
