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

// CPACDgNL.hpp : header file
//

#if !defined (__EDACDGNL_HPP__)
#define __EDACDGNL_HPP__

#include "EdAcIRes.h"
//#include "acp_base.h"
//#include "cpadllb.hpp"
#include "EdAcDef.hpp"
/////////////////////////////////////////////////////////////////////////////
// EdActors_EditNameListsDialog dialog

class EdActors_EditorActor;
class CPA_tdoNameList;
class tdoObjectName;
class EdActors_EditNameListsDialog;


//=======================================================================================

typedef struct tdstToolTipData_
{
	UINT uiControlId;
	CWnd *p_oMfcControl;
	const char *pszTipText;
} tdstToolTipData;

//=======================================================================================
#define M_vFillToolTipData(stTTD, uiCI, pCtrl, pszText) \
(stTTD).uiControlId = uiCI;                             \
(stTTD).p_oMfcControl = pCtrl;                          \
(stTTD).pszTipText = pszText

//=======================================================================================
typedef struct tdstListSpecificActions_
{
	void (*fn_vWhenNameAdded)(short, CPA_tdoNameList *);
	void (*fn_vWhenNameRemoved)(short, CPA_tdoNameList *);
} tdstListSpecificActions;

//=======================================================================================
typedef struct tdstCarEditNameListsDialogArgs_
{
	struct
	{
		EdActors_EditorActor *p_oEditorActor;
		CPA_tdoNameList *p_oCurrentNameList;
		const char *p_c_szNameListType;
		const char *p_c_szScriptName;
		BOOL bModelCanSelectANameList;
		BOOL bNoNames;
	} stIn;
	struct
	{
		CPA_tdoNameList *p_oNameListSelectedForModel;
	} stOut;
} tdstCarEditNameListsDialogArgs;

//=======================================================================================
class tdoDummyName
{
public:
	tdoDummyName(tdoObjectName *_p_oObjectName, short _wIndex);
	tdoDummyName(CString _csName, tdeShareMode _eShareMode);
	void m_vSetName(CString _csName) { m_csName = _csName; }
	CString m_csGetName(void) { return m_csName; }
	CString m_csGetInitName(void) { return m_p_oAssociatedName ? m_p_oAssociatedName->GetName() : m_csName; }
	tdeShareMode m_eGetShareMode() { return m_eShareMode; }
	tdeShareMode m_eGetInitShareMode() { return m_p_oAssociatedName ? m_p_oAssociatedName->m_eGetShareMode() : m_eShareMode; }
	void m_vSetShareMode(tdeShareMode _eShareMode) { m_eShareMode = _eShareMode; }
	BOOL m_bWasHereOnInit() { return m_p_oAssociatedName != NULL; }
	tdoObjectName *m_p_oGetAssociatedName() { return m_p_oAssociatedName; }
	short m_wGetInitIndex() { return m_wInitIndex; }
	BOOL m_bNameChanged() { return m_csName != m_csGetInitName(); }
	BOOL m_bShareModeChanged() { return m_eShareMode != m_eGetInitShareMode(); }

private:
	tdeShareMode m_eShareMode;
	short m_wInitIndex;
	CString m_csName;
	tdoObjectName *m_p_oAssociatedName;
};

//=======================================================================================
//this is a fake name list
class tdoDummyNameList
{
public:
	tdoDummyNameList(CPA_tdoNameList *_p_oNameList);
	tdoDummyNameList(CString _csName);
	~tdoDummyNameList();
	tdoDummyName *m_p_oAddName(CString _csName, tdeShareMode _eShareMode);
	BOOL m_bRemoveName(CString _csName);
	BOOL m_bRestoreName(CString _csName);
	BOOL m_bRenameName(CString _csOldName, CString _csNewName);
	BOOL m_bReshareName(CString _csName, tdeShareMode _eShareMode);
	void m_vSetName(CString _csName) { m_csName = _csName; }
	CString m_csGetName(void) { return m_csName; }
	CString m_csGetInitName(void) { return m_p_oAssociatedList ? m_p_oAssociatedList->GetName() : m_csName; }
	BOOL m_bNameExists(CString _csName);
	BOOL m_bWasHereOnInit() { return m_p_oAssociatedList != NULL; }
	void m_vInvalidateDeletedNames();
	void m_vValidateActiveNames(EdActors_EditNameListsDialog *_p_oDialog);
	CPA_tdoNameList *m_p_oGetAssociatedList() { return m_p_oAssociatedList; }
	void m_vFillControls(CListBox *_p_oListBox, CEdit *_p_oCurEdit);
	BOOL m_bNameChanged() { return m_csName != m_csGetInitName(); }
	void m_vSetAssociatedList(CPA_tdoNameList *_p_oNameList, BOOL _bAreYouSure = FALSE);

private:
	BOOL m_bAddName(tdoObjectName *_p_oObjectName);
	tdoDummyName *m_p_oFindActiveName(CString _csName);
	tdoDummyName *m_p_oFindDeletedName(CString _csName);
	CString m_csName;
	CPA_tdoNameList *m_p_oAssociatedList;
	CPA_List<tdoDummyName> m_clNames, m_clDeletedNames;
};

//=======================================================================================
class tdoListModifHandler
{
public:
	tdoListModifHandler(CString _csNameListType, CPA_Family *_p_oFamily);
	~tdoListModifHandler();
	tdoDummyNameList *m_p_oAcceptListAdd(CString _csName);
	BOOL m_bAcceptListDelete(CString _csName);
	BOOL m_bAcceptListRename(CString _csOldName, CString _csNewName);
	tdoDummyName *m_p_oAcceptNameAdd(CString _csListName, CString _csName, tdeShareMode _eShareMode);
	BOOL m_bAcceptNameDelete(CString _csListName, CString _csName);
	BOOL m_bAcceptNameRename(CString _csListName, CString _csOldName, CString _csNewName);
	BOOL m_bAcceptNameReshare(CString _csListName, CString _csName, tdeShareMode _eShareMode);
	void m_vPerformAllModifs();
	void m_vModifsAreAccepted(EdActors_EditNameListsDialog *_p_oDialog) { m_p_oDialog = _p_oDialog; }
	BOOL m_bModifsAreAccepted() { return m_p_oDialog != NULL; }
	BOOL m_bListExists(CString _csName);
	BOOL m_bNameExists(CString _csName);
	void m_vFillControls(CListBox *_p_oListBox, CEdit *_p_oCurEdit, tdoDummyNameList *_p_oCurrentSelectedList);
	tdoDummyNameList *m_p_oGetListforNameList(CPA_tdoNameList *_p_oNameList);

private:
	CString m_csNameListType;
	CPA_Family *m_p_oFamily;
	tdoDummyNameList *m_p_oFindActiveNameList(CString _csName);
	tdoDummyNameList *m_p_oFindDeletedNameList(CString _csName);
	CPA_List<tdoDummyNameList> m_clLists, m_clDeletedLists;
	EdActors_EditNameListsDialog *m_p_oDialog;
	BOOL m_bModelCanSelectAnotherList;
};

//=======================================================================================
//=======================================================================================
class EdActors_EditNameListsDialog : public CDialog
{
// Construction
public:
	~EdActors_EditNameListsDialog();
	EdActors_EditNameListsDialog(tdstCarEditNameListsDialogArgs *, CWnd *pParent = NULL);   // standard constructor
	tdstCarEditNameListsDialogArgs *m_p_stArgs;
	tdoDummyNameList *m_p_oCurrentSelectedList, *m_p_oListSelectedForModel;

// Dialog Data
	//{{AFX_DATA(EdActors_EditNameListsDialog)
	enum { IDD = IDD_CAR_DIALOG_EDIT_NAMELISTS };
	//}}AFX_DATA


	// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(EdActors_EditNameListsDialog)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    virtual void OnDestroy();
	//}}AFX_VIRTUAL

private:
	enum
	{
		E_em_None,
		E_em_NameListSelect,
		E_em_NameListEdit
	} m_eEditMode;
	//if this is set, the message comes from an internal modification...
	BOOL m_bAutodispatch;
	BOOL m_bUserEditedAList;
	CToolTipCtrl *m_poToolTip;
	HICON m_hIconCommon, m_hIconShared, m_hIconVirge, m_hIconChecked;
	BOOL m_bIconClickedInListBox(CPoint oPoint);
	tdoListModifHandler *m_p_oListModifHandler;
  CWnd *m_p_oDefaultButton;
// Implementation
protected:
	tdstToolTipData m_a13_stToopTipData[13];
	CEdit *m_p_oNameEdit;
	CStatic *m_p_oEditGroupTitle, *m_p_oItemListTitle;
	CButton *m_p_oAddButton, *m_p_oRenameButton, *m_p_oDeleteButton;
	CButton *m_p_oCommonRadioButton, *m_p_oSharedRadioButton, *m_p_oVirgeRadioButton;
  CButton *m_p_oSwapEditModeButton, *m_p_oOkButton, *m_p_oCancelButton;
	CListBox *m_p_oItemListBox;

	void m_vSelectNameList(CPA_tdoNameList *_p_oNameList);
	void m_vSetRadioShareMode(tdeShareMode _eShareMode);
	tdeShareMode m_eGetRadioShareMode();
  void m_vSetDefaultButton(CButton *_p_oButton);
	virtual BOOL PreTranslateMessage(MSG* pMsg);

	// Generated message map functions
	//{{AFX_MSG(EdActors_EditNameListsDialog)
	afx_msg BOOL m_bGetToolTipText(UINT, NMHDR *, LRESULT *);
	afx_msg void OnEnlSwapEditModeButtonClicked();
	afx_msg void OnEnlShareModeRadioButtonClicked();
	afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg void OnEnlListBoxSelChange();
	afx_msg void OnEnlNameEditChange();
	afx_msg void OnEnlAddButtonClicked();
	afx_msg void OnEnlDeleteButtonClicked();
	afx_msg void OnEnlRenameButtonClicked();
	afx_msg void OnEnlDefaultButtonClicked();
	//}}AFX_MSG
	virtual BOOL OnInitDialog();
	virtual void OnOK();
	DECLARE_MESSAGE_MAP()
};

#define M_vRegisterControl(memberpointer, type, id, tooltiprank, tooltiptext)        \
	memberpointer = (type) GetDlgItem(id);                                             \
	m_poToolTip->AddTool(memberpointer, LPSTR_TEXTCALLBACK);                           \
	M_vFillToolTipData(m_a13_stToopTipData[tooltiprank], id, memberpointer, tooltiptext)

#define M_vFakeMessage(message) ((void) ( m_bAutodispatch = FALSE, (message)(), m_bAutodispatch = TRUE ))

#endif /* __EDACDGNL_HPP__ */ //bbb 03/04/97
//bbb 02/04/97 }
