Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.6 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ClusMru.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CRecentClusterList class.
  10. //
  11. // Author:
  12. // David Potter (davidp) May 3, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "ClusMru.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CRecentClusterList
  28. /////////////////////////////////////////////////////////////////////////////
  29. //++
  30. //
  31. // CRecentClusterList::Add
  32. //
  33. // Routine Description:
  34. // Add an item to the list of recently used cluster names.
  35. // Implemented to remove file-ness of base class' method.
  36. //
  37. // Arguments:
  38. // lpszPathName Name of the cluster or server to add.
  39. //
  40. // Return Value:
  41. // None.
  42. //
  43. //--
  44. /////////////////////////////////////////////////////////////////////////////
  45. void CRecentClusterList::Add(LPCTSTR lpszPathName)
  46. {
  47. ASSERT(m_arrNames != NULL);
  48. ASSERT(lpszPathName != NULL);
  49. ASSERT(AfxIsValidString(lpszPathName));
  50. // update the MRU list, if an existing MRU string matches file name
  51. for (int iMRU = 0; iMRU < m_nSize-1; iMRU++)
  52. {
  53. if (lstrcmpi(m_arrNames[iMRU], lpszPathName) == 0)
  54. break; // iMRU will point to matching entry
  55. }
  56. // move MRU strings before this one down
  57. for (; iMRU > 0; iMRU--)
  58. {
  59. ASSERT(iMRU > 0);
  60. ASSERT(iMRU < m_nSize);
  61. m_arrNames[iMRU] = m_arrNames[iMRU-1];
  62. }
  63. // place this one at the beginning
  64. m_arrNames[0] = lpszPathName;
  65. } //*** CRecentClusterList::Add()
  66. /////////////////////////////////////////////////////////////////////////////
  67. //++
  68. //
  69. // CRecentClusterList::GetDisplayName
  70. //
  71. // Routine Description:
  72. // Get the display name of a particular item.
  73. // Implemented to remove file-ness of base class' method.
  74. //
  75. // Arguments:
  76. // strName [OUT] String in which to return the display name.
  77. // nIndex [IN] Index of item in array.
  78. // lpszCurDir [IN] Must be NULL.
  79. // nCurDir [IN] Must be 0.
  80. // bAtLeastName [IN] Not used.
  81. //
  82. // Return Value:
  83. // None.
  84. //
  85. //--
  86. /////////////////////////////////////////////////////////////////////////////
  87. BOOL CRecentClusterList::GetDisplayName(
  88. CString & strName,
  89. int nIndex,
  90. LPCTSTR lpszCurDir,
  91. int nCurDir,
  92. BOOL bAtLeastName
  93. ) const
  94. {
  95. ASSERT(lpszCurDir == NULL);
  96. ASSERT(nCurDir == 0);
  97. if (m_arrNames[nIndex].IsEmpty())
  98. return FALSE;
  99. strName = m_arrNames[nIndex];
  100. return TRUE;
  101. } //*** CRecentClusterList::GetDisplayName()
  102. /////////////////////////////////////////////////////////////////////////////
  103. //++
  104. //
  105. // CRecentClusterList::UpdateMenu
  106. //
  107. // Routine Description:
  108. // Update the menu with the MRU items.
  109. // Implemented to remove file-ness of base class' method and to use
  110. // our version of GetDisplayName, since it isn't virtual.
  111. //
  112. // Arguments:
  113. // pCmdUI [IN OUT] Command routing object.
  114. //
  115. // Return Value:
  116. // None.
  117. //
  118. //--
  119. /////////////////////////////////////////////////////////////////////////////
  120. void CRecentClusterList::UpdateMenu(CCmdUI * pCmdUI)
  121. {
  122. ASSERT(m_arrNames != NULL);
  123. CMenu* pMenu = pCmdUI->m_pMenu;
  124. if (m_strOriginal.IsEmpty() && pMenu != NULL)
  125. pMenu->GetMenuString(pCmdUI->m_nID, m_strOriginal, MF_BYCOMMAND);
  126. if (m_arrNames[0].IsEmpty())
  127. {
  128. // no MRU files
  129. if (!m_strOriginal.IsEmpty())
  130. pCmdUI->SetText(m_strOriginal);
  131. pCmdUI->Enable(FALSE);
  132. return;
  133. }
  134. if (pCmdUI->m_pMenu == NULL)
  135. return;
  136. for (int iMRU = 0; iMRU < m_nSize; iMRU++)
  137. pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID + iMRU, MF_BYCOMMAND);
  138. CString strName;
  139. CString strTemp;
  140. for (iMRU = 0; iMRU < m_nSize; iMRU++)
  141. {
  142. if (!GetDisplayName(strName, iMRU, NULL, 0))
  143. break;
  144. // double up any '&' characters so they are not underlined
  145. LPCTSTR lpszSrc = strName;
  146. LPTSTR lpszDest = strTemp.GetBuffer(strName.GetLength()*2);
  147. while (*lpszSrc != 0)
  148. {
  149. if (*lpszSrc == '&')
  150. *lpszDest++ = '&';
  151. if (_istlead(*lpszSrc))
  152. *lpszDest++ = *lpszSrc++;
  153. *lpszDest++ = *lpszSrc++;
  154. }
  155. *lpszDest = 0;
  156. strTemp.ReleaseBuffer();
  157. // insert mnemonic + the file name
  158. TCHAR buf[10];
  159. wsprintf(buf, _T("&%d "), (iMRU+1+m_nStart) % 10);
  160. pCmdUI->m_pMenu->InsertMenu(pCmdUI->m_nIndex++,
  161. MF_STRING | MF_BYPOSITION, pCmdUI->m_nID++,
  162. CString(buf) + strTemp);
  163. }
  164. // update end menu count
  165. pCmdUI->m_nIndex--; // point to last menu added
  166. pCmdUI->m_nIndexMax = pCmdUI->m_pMenu->GetMenuItemCount();
  167. pCmdUI->m_bEnableChanged = TRUE; // all the added items are enabled
  168. } //*** CRecentFileList::UpdateMenu()