// PrhHistFindLink.cpp : _xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgFiBfLiDfGiDiHiDjD_xHqqkZx_ _xZkqqHx_iDhEiDeAiDeDiDiL_xHqqkZx_
//

#include "stdafx.h"
#include "DynamicDraw.h"
#include "DynamicDrawView.h"	// For g_pView.
#include "HistViewDoc.h"		// For FFHistViewDoc().
#include "HistViewFrame.h"		// For FFHistViewFrame().
#include "ObjLabel.h"			// For FCObjLabel.
#include "DlgHistFindResults.h"	// For CFCDlgHistFindResults.
#include "HiProject.h"			// For FCHiProject.
#include "PrhHistFindLink.h"	// This header.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKjFnLjBlGjGlM_xHqqkZx_ -----
static const wchar_t* REG_PRH_HIST_FIND_LINK = L"CFCPrhHistFindLink";

/////////////////////////////////////////////////////////////////////////////
// CFCPrhHistFindLink _xZkqqHx_iDfPiDeDiDeBiDiNiDeP_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::CFCPrhHistFindLink
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pWndResult	:_xZkqqHx_iMjPiNpFiMiLiJmKjFfMiOkGiDhAiDgMiDiLiCpAiOhHjCoIiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.16 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
//----- 05.11.02 Fukushiro M. _xZkqqHx_jFmPiNfIjBeP_xHqqkZx_ ()-----
//CFCPrhHistFindLink::CFCPrhHistFindLink (CFCDlgHistFindResults* pWndResult /*=NULL*/)
//				: BASE_CLASS(pWndResult)
//----- 05.11.02 Fukushiro M. _xZkqqHx_jFmPiNfIiMoD_xHqqkZx_ ()-----
CFCPrhHistFindLink::CFCPrhHistFindLink ()
				: BASE_CLASS()
//----- 05.11.02 Fukushiro M. _xZkqqHx_jFmPiNfIiPeJ_xHqqkZx_ ()-----
{
	//{{AFX_DATA_INIT(CFCPrhHistFindLink)
	m_bFindCreateLink = FALSE;
	m_bFindDeleteLink = FALSE;
	m_bFindCreateInterLink = FALSE;
	m_bFindDeleteInterLink = FALSE;
	//}}AFX_DATA_INIT
} // CFCPrhHistFindLink::CFCPrhHistFindLink.

void CFCPrhHistFindLink::DoDataExchange(CDataExchange* pDX)
{
	BASE_CLASS::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFCPrhHistFindLink)
	DDX_Check(pDX, IDC_HFD_LNK_CHK_FIND_CREATE_LINK, m_bFindCreateLink);
	DDX_Check(pDX, IDC_HFD_LNK_CHK_FIND_DELETE_LINK, m_bFindDeleteLink);
	DDX_Check(pDX, IDC_HFD_LNK_CHK_FIND_CREATE_INTER_LINK, m_bFindCreateInterLink);
	DDX_Check(pDX, IDC_HFD_LNK_CHK_FIND_DELETE_INTER_LINK, m_bFindDeleteInterLink);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFCPrhHistFindLink, BASE_CLASS)
	//{{AFX_MSG_MAP(CFCPrhHistFindLink)
		// _xZkqqHx_iDiBiDiC_xHqqkZx_ - ClassWizard _xZkqqHx_iCmNiClBiCmMiImKjChFiCmJiDhNiDgCiDhDiDjDiDePjHhAiCmMiDhNiDeOiDiNiCpAjCmHiJmBiCnMiClNiCmNiNoNiPjMiClFiCnMiClHiBeC_xHqqkZx_
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFCPrhHistFindLink _xZkqqHx_iDiGiBfLiDfFiKnGjAjEiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::OnSetActive
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhJiBfLiDfHiCkKiDeBiDeOiDgFiDeCiDhFiCmJiCmIiCoJiCmGiCkLiCmJiMmEiCnBiPgPiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.16 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCPrhHistFindLink::OnSetActive ()
{
	// Superclass_xZkqqHx_iOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnSetActive();
	//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCkJiCoHiPpDiLlFiCpAiOoGjDlOiClHiCoJ_xHqqkZx_ -----
	g_pReg->LoadRegBinary(	GetRegName(),
							L"m_bFindCreateLink",
							(BYTE*)&m_bFindCreateLink,
							sizeof(m_bFindCreateLink));
	g_pReg->LoadRegBinary(	GetRegName(),
							L"m_bFindDeleteLink",
							(BYTE*)&m_bFindDeleteLink,
							sizeof(m_bFindDeleteLink));
	g_pReg->LoadRegBinary(	GetRegName(),
							L"m_bFindCreateInterLink",
							(BYTE*)&m_bFindCreateInterLink,
							sizeof(m_bFindCreateInterLink));
	g_pReg->LoadRegBinary(	GetRegName(),
							L"m_bFindDeleteInterLink",
							(BYTE*)&m_bFindDeleteInterLink,
							sizeof(m_bFindDeleteInterLink));
} // CFCPrhHistFindLink::OnSetActive.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::OnKillActive
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDhJiBfLiDfHiCkKiDeBiDeOiDgFiDeCiDhFiCmFiCmIiCkNiCmIiCoJiCmGiCkLiCmJiMmEiCnBiPgPiClDiCoKiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.16 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCPrhHistFindLink::OnKillActive ()
{
	//----- _xZkqqHx_iDiMiDfHiDfIiDgHiDiKiCmJiPpDiLlFiCpAjFnLjBlGiClHiCoJ_xHqqkZx_ -----
	g_pReg->SaveRegBinary(	GetRegName(),
							L"m_bFindCreateLink",
							(BYTE*)&m_bFindCreateLink,
							sizeof(m_bFindCreateLink));
	g_pReg->SaveRegBinary(	GetRegName(),
							L"m_bFindDeleteLink",
							(BYTE*)&m_bFindDeleteLink,
							sizeof(m_bFindDeleteLink));
	g_pReg->SaveRegBinary(	GetRegName(),
							L"m_bFindCreateInterLink",
							(BYTE*)&m_bFindCreateInterLink,
							sizeof(m_bFindCreateInterLink));
	g_pReg->SaveRegBinary(	GetRegName(),
							L"m_bFindDeleteInterLink",
							(BYTE*)&m_bFindDeleteInterLink,
							sizeof(m_bFindDeleteInterLink));
	// Superclass_xZkqqHx_iOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::OnKillActive();
} // CFCPrhHistFindLink::OnKillActive.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::GetRegName
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiMiDfHiDfIiDgHiDiKjDgPjIfOiClHiCoJiClNiCnPiCmMjDgPjIfOjGlMiCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_iDiMiDfHiDfIiDgHiDiKjDgPjIfOiClHiCoJiClNiCnPiCmMjDgPjIfOjGlMiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	06.02.21 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
const wchar_t* CFCPrhHistFindLink::GetRegName () const
{
	return REG_PRH_HIST_FIND_LINK;
} // CFCPrhHistFindLink::GetRegName.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::IsConsistent
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDgHiDiNiBfLiDiLjAnNjCoIjCgMiCmMjGlFiPiCjAkLiCmMiDgAiDeGiDgCiDeOiCpAiNhDiCkEiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jFnEjCgM_xHqqkZx_>	_xZkqqHx_jGlDjGlFiPiCiCmMiPoKiNiHiCmN_xHqqkZx_ TRUE_xZkqqHx_iBeBjGlFiPiCiCmMiPoKiNiHiCmN_xHqqkZx_ FALSE _xZkqqHx_iCpAjFnEiClHiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.23 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
BOOL CFCPrhHistFindLink::IsConsistent ()
{
//----- 06.02.21 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
//	// m_bTbcSrhSearchAllDocument_xZkqqHx_iBgJjBfDjFlGiPjBiMjPiNpFiBgKiCmMjCgMiCpAjFnLjBlGiClFiBeB_xHqqkZx_FALSE_xZkqqHx_iCpAiOhHjCoIiClHiCoJiBeC_xHqqkZx_
//	// _xZkqqHx_iPoDjFpLiBeBiJlKjFpLiMjPiNpFiCkKjFhDiJmCiCmGiCmIiCoHiCmIiCkCiCoGiCkEiCmJiClHiCoJiClNiCnPiBeC_xHqqkZx_
//	const FCAutoBackup<BOOL> backupSearchAllDocument(m_bTbcSrhSearchAllDocument, FALSE);
//----- 06.02.21 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----
	// Superclass_xZkqqHx_iOmAiNhDiBeC_xHqqkZx_
	if (!BASE_CLASS::IsConsistent()) return FALSE;

	// _xZkqqHx_jFjEjFgJiCkKjBeJjBpAiClDiCoKiCmEiCkCiCmIiCkCiPoKiNiHiCmN_xHqqkZx_ FALSE_xZkqqHx_iBeC_xHqqkZx_
	if (g_pView->SelectObjVector().empty())
	{
		// IDS_ERR_MSG_OBJECT_NOT_SET = "_xZkqqHx_jFjEjFgJiCkKjBeJjBpAiClDiCoKiCmEiCkCiCnMiClJiCpB_xHqqkZx_"
		FFErrorBox(IDS_ERR_MSG_OBJECT_NOT_SET);
		return FALSE;
	}

	if (!m_bFindCreateLink && !m_bFindDeleteLink &&
		!m_bFindCreateInterLink && !m_bFindDeleteInterLink)
	//----- _xZkqqHx_iMjPiNpFjBmOiPnLiCkKjAnNjCoIiClDiCoKiCmEiCkCiCmIiCkCiPoKiNiH_xHqqkZx_ -----
	{
		// IDS_ERR_MSG_SEARCH_TARGET_NOT_SPECIFIED = "_xZkqqHx_iMjPiNpFjBmOiPnLiCkKiOhHjCoIiClDiCoKiCmEiCkCiCnMiClJiCpB_xHqqkZx_"
		FFErrorBox(IDS_ERR_MSG_SEARCH_TARGET_NOT_SPECIFIED);
		return FALSE;
	}

	return TRUE;
} // CFCPrhHistFindLink::IsConsistent.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::UpdateActivate
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iKgFiDfCiDjDiDgHiDiNiBfLiDiLiCmMjHeMiMpIiBeFjGlDiMpIiCpAjAnNjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.23 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCPrhHistFindLink::UpdateActivate ()
{
	// m_bTbcSrhSearchAllDocument_xZkqqHx_iBgJjBfDjFlGiPjBiMjPiNpFiBgKiCmMjCgMiCpAjFnLjBlGiClFiBeB_xHqqkZx_FALSE_xZkqqHx_iCpAiOhHjCoIiClHiCoJiBeC_xHqqkZx_
	// _xZkqqHx_iPoDjFpLiBeBiJlKjFpLiMjPiNpFiCkKjFhDiJmCiCmGiCmIiCoHiCmIiCkCiCoGiCkEiCmJiClHiCoJiClNiCnPiBeC_xHqqkZx_
	const FCAutoBackup<BOOL> backupSearchAllDocument(m_bTbcSrhSearchAllDocument, FALSE);
	// Superclass_xZkqqHx_iOmAiNhDiBeC_xHqqkZx_
	BASE_CLASS::UpdateActivate();
	// _xZkqqHx_jBfDjFlGiPjBiCpAiMjPiNpFiCmNjFhDiJmCiBeC_xHqqkZx_
	GetDlgItem(IDC_HFD_TBC_SRH_CHK_SEARCH_ALL_DOCUMENT)->EnableWindow(FALSE);
} // CFCPrhHistFindLink::UpdateActivate.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	CFCPrhHistFindLink::DoFind
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iMjPiNpFiCpAiOmAiNhDiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	04.12.23 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void CFCPrhHistFindLink::DoFind ()
{
	// CFCDlgHistFindResults_xZkqqHx_iCkJiCoH_xHqqkZx_HistoryFind_xZkqqHx_iCpAiOoGjDlOiBeC_xHqqkZx_
	FCHistoryFind& hf = FFHistViewFrame()->GetHtreeFindResults()->GetHistoryFind();
//----- 06.02.22 Fukushiro M. _xZkqqHx_jCmHiJmBiOgO_xHqqkZx_ ()-----
	// _xZkqqHx_iDhGiDiNiDfHiDeGiDeOiDgHiCkKjFmCiClGiCmEiCkCiCoJiPoKiNiHiCmNiDeHiDiJiBfLiBeCiOmAiNnLiCmNiMmEiCmOiCoKiCmIiCkCiCmNiClIiBeC_xHqqkZx_
	if (!g_pProject->IsProjectOpened())
		FFThrowMiscUnknown();
	long lDocumentId = FFHistViewDoc()->GetIsDocumentOpened() ? FFHistViewDoc()->GetDocumentId() : -1;
	flint fliNextSessionIndex = FFHistViewDoc()->GetIsDocumentOpened() ? FFHistViewDoc()->GetNextSessionIndex() : -1;
//----- 06.02.22 Fukushiro M. _xZkqqHx_jCmHiJmBiPeJ_xHqqkZx_ ()-----

	//----- _xZkqqHx_jBeJjBpAjCiGiCmMjFjEjFgJiCkJiCoHiBeBjFjEjFgJ_xHqqkZx_ID_xZkqqHx_iPfHiNiHiCpAiNoMjAkM_xHqqkZx_ -----
	if (m_bTbcLblNarrowByLabel)
	//----- _xZkqqHx_iDiJiDhIiDiLiNgJiCoIiNjOiCnNiMjPiNpFiCkKiCkAiCoJiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iMlLiNnNiCmMjFlGiPjBiCmMjFjEjFgJ_xHqqkZx_ID->_xZkqqHx_iDiJiDhIiDiLiDgFiBfLiDhFiDiLiCpAiNoMjAkMiBeC_xHqqkZx_
		ObjIdToWStringMap mpLabelIdToString;
		GetLabelIdToStringMap(mpLabelIdToString);

		// _xZkqqHx_iDfCiDjDiDhLiDhLiDgCiDeOiDfIjCiGiCmMiDiKiDfIiDgHiPiIjHjNiBeC_xHqqkZx_
		UpdateComboStr();
		// _xZkqqHx_iMjPiNpFiPiIjHjNiBeC_xHqqkZx_
		hf.FindLink(g_pProject->GetFilePathH(),
					g_pView->SelectObjVector(),
					mpLabelIdToString,
					m_wstrTbcLblFindString,
					m_bTbcLblMultiWord,
					m_bTbcLblRegexp,
					m_bTbcLblAsUppercase,
					GetNarrowTimeFrom(),
					GetNarrowTimeUntil(),
					GetNarrowUserId(),
					m_bTbcSrhSearchBefore,
					m_bTbcSrhSearchHigher,
					m_bTbcSrhSearchBeforeBranch,
					m_bTbcSrhSearchAfter,
					m_bTbcSrhSearchAfterBranch,
					lDocumentId,
					fliNextSessionIndex,
					m_bFindCreateLink,
					m_bFindDeleteLink,
					m_bFindCreateInterLink,
					m_bFindDeleteInterLink);
	} else
	//----- _xZkqqHx_iDiJiDhIiDiLiNgJiCoIiNjOiCnNiMjPiNpFiCkKjGlDiCkCiPoKiNiH_xHqqkZx_ -----
	{
		// _xZkqqHx_iMjPiNpFiPiIjHjNiBeC_xHqqkZx_
		hf.FindLink(g_pProject->GetFilePathH(),
					g_pView->SelectObjVector(),
					ObjIdToWStringMap(),
					NULL,
					FALSE,
					FALSE,
					FALSE,
					GetNarrowTimeFrom(),
					GetNarrowTimeUntil(),
					GetNarrowUserId(),
					m_bTbcSrhSearchBefore,
					m_bTbcSrhSearchHigher,
					m_bTbcSrhSearchBeforeBranch,
					m_bTbcSrhSearchAfter,
					m_bTbcSrhSearchAfterBranch,
					lDocumentId,
					fliNextSessionIndex,
					m_bFindCreateLink,
					m_bFindDeleteLink,
					m_bFindCreateInterLink,
					m_bFindDeleteInterLink);
	}
} // CFCPrhHistFindLink::DoFind.

/////////////////////////////////////////////////////////////////////////////
// CFCPrhHistFindLink _xZkqqHx_iDiBiDgCiDfKiBfLiDfH_xHqqkZx_ _xZkqqHx_iDgOiDjDiDgIiDiJ_xHqqkZx_
