#include "stdafx.h"
#include "UtilStr.h"		// For StrNewCpy.
#include "OtherAppList.h"	// This header.

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

//----- 99.12.20 Fukushiro M. _xZkqqHx_iNoNiPjMiOgO_xHqqkZx_ ()-----
////////////////////////////////////////////////////////////////////////////////
//// FCWinTitleRec_xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgHiBeC_xHqqkZx_
//
//FCWinTitleRec::FCWinTitleRec (HWND hwnd, const _TCHAR* tcp)
//{
//	hwndApp = hwnd;
//	atpTitle = TCHARAuto(StrNewCpy(tcp));
//}
//
//FCWinTitleRec::operator = (const FCWinTitleRec& rec)
//{
//	hwndApp = rec.hwndApp;
//	atpTitle = rec.atpTitle;
//}
//----- 99.12.20 Fukushiro M. _xZkqqHx_iNoNiPjMiPeJ_xHqqkZx_ ()-----

//////////////////////////////////////////////////////////////////////////////
// FCOtherAppList_xZkqqHx_iDeDiDjDiDhGiDiKiDiBiDjDiDgHiBeC_xHqqkZx_

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCOtherAppList::FCOtherAppList
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDfCiDjDiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.03.18 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCOtherAppList::FCOtherAppList ()
{
	// _xZkqqHx_iMlLiNnNiDiBiDgKiDiFiBfLiCmJjDgPjIfOiClDiCoKiCmEiCkCiCoJjAjEiBeCiDgGiDhEiDeIiDiLiDgHiCmNiCfAiBeC_xHqqkZx_
	m_nSize = 1;
} // FCOtherAppList::FCOtherAppList.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCOtherAppList::~FCOtherAppList
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDgGiDfIiDgHiDiJiDeOiDfOiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.03.18 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
FCOtherAppList::~FCOtherAppList ()
{
	// _xZkqqHx_iDeJiDjDiDiBiDiCiDiKiDgPiDgCiDhEiDeAiCpAiJpAjFpKiBeC_xHqqkZx_
	m_vWinTitle.clear();
} // FCOtherAppList::~FCOtherAppList.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCOtherAppList::UpdateMenu
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iDiBiDgKiDiFiBfLiCmMiDeBiDgCiDhGiDgGiBfLiDgHiPiIjHjNiCpAiNhDiCkEiBeC_xHqqkZx_OnUpdateXXXX_xZkqqHx_iKnGjAjEiCkJiCoHiOmAiNhDiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	pCmdUI	:_xZkqqHx_iDeBiDgCiDhGiDgGiBfLiDgHiClHiCoJiDiBiDgKiDiFiBfLiNiAjGnKiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_jDgPjIfOiClDiCoKiCmEiCkCiCoJiDiKiDfIiDgHiCkKiCkAiCoJiCkJiCmHiCkEiCkJiCpAjClCiCnHiBeBiDiKiDfIiDgHiCkKiCkAiCoJiPoKiNiHiCmN_xHqqkZx_
 *			_xZkqqHx_iClLiCoKiCpAiDiBiDgKiDiFiBfLiPoDiCmJjDgPjIfOiClFiCmEiCoEiCkNiBeC_xHqqkZx_
 *			MFC/FILELIST.CPP_xZkqqHx_iCmM_xHqqkZx_UpdateMenu_xZkqqHx_iKnGjAjEiCpAiOfBiPmGiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.03.18 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCOtherAppList::UpdateMenu (CCmdUI* pCmdUI)
{
	CMenu* pMenu = pCmdUI->m_pMenu;
	// _xZkqqHx_iDiBiDgKiDiFiBfLjGhLjHiIiCmMiDgFiDeMiDfIiDgH_xHqqkZx_("_xZkqqHx_jBlMiCmMiDeFiDeCiDjDiDgIiDeF_xHqqkZx_")_xZkqqHx_iCpAiOoGjDlOiBeC_xHqqkZx_
	if (m_strOriginal.IsEmpty() && pMenu != NULL)
		FFGetMenuString(pMenu, pCmdUI->m_nID, m_strOriginal, MF_BYCOMMAND);
	// _xZkqqHx_iDiKiDfIiDgHiCpAjDmHiCnNiNjOiCnOiBeC_xHqqkZx_
	ReadList();
	// _xZkqqHx_iDiKiDfIiDgHiCkKjGlDiCkCiPoKiNiHiBeC_xHqqkZx_
	if (m_vWinTitle.empty())
	{
		// _xZkqqHx_jGhLjHiIiCmMiDgFiDeMiDfIiDgHiCpAjAnNjCoIiBeC_xHqqkZx_
		if (!m_strOriginal.IsEmpty()) pCmdUI->SetText(WStrToTStr(m_strOriginal));
		pCmdUI->Enable(FALSE);
		return;
	}
	// _xZkqqHx_iDiBiDgKiDiFiBfLiCkKjGlDiCkCiPoKiNiHiCmNjFjMiLeBiBeC_xHqqkZx_
	if (pMenu == NULL) return;
	// _xZkqqHx_iDiBiDgKiDiFiBfLiCmJjDgPjIfOiClDiCoKiCkCiCoJ_xHqqkZx_MRH_xZkqqHx_iCpAiNoNiPjMiBeC_xHqqkZx_
	int iOAP;
	for (iOAP = 0; iOAP < m_nSize; iOAP++)
		pMenu->DeleteMenu(pCmdUI->m_nID + iOAP, MF_BYCOMMAND);
	m_nSize = m_vWinTitle.size();

	HWND	hwnd;
	WString	strTitle;
	for (iOAP = 0; iOAP < m_nSize; iOAP++)
	{
		// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFiPoOjFpBiCpAiOoGjDlOiBeC_xHqqkZx_
		Get(hwnd, strTitle, iOAP);
		// &_xZkqqHx_iLeMiNiGiCpA_xHqqkZx_&&_xZkqqHx_iCnGjFmPiKlHiBeCiDiBiDgKiDiFiBfLjFfMiOkGjHhAiBeC_xHqqkZx_
		strTitle.Replace(L"&", L"&&");
		WString strMenu;
		int	iNum = iOAP + 1;
		if (9 < iNum) iNum = 0;
		strMenu.Format(L"&%d %s", iNum, strTitle.c_str());
		// _xZkqqHx_iDiBiDgKiDiFiBfLiCmJjCmHiJmBiBeC_xHqqkZx_
		pMenu->InsertMenu(pCmdUI->m_nIndex++,
						MF_STRING | MF_BYPOSITION, pCmdUI->m_nID++,
						WStrToTStr(strMenu));
	}
	// update end menu count
	pCmdUI->m_nIndex--; // point to last menu added
	pCmdUI->m_nIndexMax = pMenu->GetMenuItemCount();

	pCmdUI->m_bEnableChanged = TRUE;    // all the added items are enabled
} // FCOtherAppList::UpdateMenu.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCOtherAppList::Get
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iOhHjCoIiClDiCoKiClNiDeDiDjDiDgGiDgCiDeOiDfIiCmMiDeFiDeCiDjDiDgIiDeFiPoOjFpBiCpAiOoGjDlOiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iIpIjAjE_xHqqkZx_>	hwndFrame	:_xZkqqHx_iDeBiDhGiDiKiCmMiDiBiDeDiDjDiDeFiDeCiDjDiDgIiDeFiDgOiDjDiDgIiDiLiCpAjFnEiClHiBeC_xHqqkZx_
			strTitle	:_xZkqqHx_iDeBiDhGiDiKiCmMiDeFiDeCiDjDiDgIiDeFiDfOiDeDiDgHiDiLjFlGiOjKjHpBiCpAjFnEiClHiBeC_xHqqkZx_
 *			nIndex		:_xZkqqHx_iDeDiDjDiDgGiDgCiDeOiDfIiCpAiOhHjCoIiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_iJpAjAoA_xHqqkZx_>	_xZkqqHx_iDeDiDjDiDgGiDgCiDeOiDfIiCmNiBeBiDiBiDgKiDiFiBfLiPoDiCmMiBhFjBlMiCmMiDeFiDeCiDjDiDgIiDeFiBhGiCmMiCfAjEnEiCkK_xHqqkZx_
 *			_xZkqqHx_iCePiCmFiCkAiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.03.18 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCOtherAppList::Get (HWND& hwndFrame, WString& strTitle, short nIndex) const
{
	hwndFrame = m_vWinTitle[nIndex].hwndApp;
	strTitle  = m_vWinTitle[nIndex].atpTitle.get();
} // FCOtherAppList::Get.

/*************************************************************************
 * <_xZkqqHx_iKnGjAjE_xHqqkZx_>	FCOtherAppList::ReadList
 *
 * <_xZkqqHx_iLeAjEfM_xHqqkZx_>	_xZkqqHx_iLeOjDkOjCiGiCmMiDeBiDhGiDiKiCmMiDeFiDeCiDjDiDgIiDeFiDiKiDfIiDgHiCpAiOoGjDlOiClHiCoJiBeC_xHqqkZx_
 *
 * <_xZkqqHx_jHjKjHpA_xHqqkZx_>	99.03.18 Fukushiro M. _xZkqqHx_iNoMjAkM_xHqqkZx_
 *************************************************************************/
void FCOtherAppList::ReadList ()
{
	//----- _xZkqqHx_iDeJiDjDiDiBiDiCiDiKiDgPiDgCiDhEiDeAiCpAiJpAjFpK_xHqqkZx_ -----
	m_vWinTitle.clear();
	// _xZkqqHx_iDeFiDeCiDjDiDgIiDeFjHpBiLjDiBeC_xHqqkZx_
	::EnumWinTitle(m_vWinTitle);
	// _xZkqqHx_iDfEiDeDiDfJiDgAiDeGiDgCiDeOiBeC_xHqqkZx_
	if (MAX_OTHER_APP <= m_vWinTitle.size())
		m_vWinTitle.resize(MAX_OTHER_APP);
} // FCOtherAppList::ReadList.
