LRESULT BackstagePageRecent::OnRecentFileListRClick(WPARAM, LPARAM lParam)
{
   if ((CXTPControl*) lParam != mRecentFileListBox.GetGallery())
      return FALSE;
   CXTPControlGalleryItem* pItem = mRecentFileListBox.GetGallery()->GetItem(mRecentFileListBox.GetGallery()->GetSelectedItem());
   if (!pItem)
      return FALSE;
   CXTPRecentFileList* pRecentFileList = theApp.GetRecentFileList(); //- theApp = same as AfxGetApp()->GetRecentFileList
   CXTPRecentFileListItem* pRecentFileListItem = NULL; 
   int nSelectedIndex = 0; 
   // The recent file list in CXTPRecentFileListBox is currently protected. This loop is for finding which CXTPRecentFileListItem was clicked.
   for (int nIndex = 0; nIndex < pRecentFileList->m_nSize; ++nIndex)
   {
      CXTPRecentFileListItem* pTmpItem = dynamic_cast<CXTPRecentFileListItem*>(pRecentFileList->GetItem(nIndex));
      if (!pTmpItem)
         break;
      if (pItem->GetData() == (DWORD_PTR) pTmpItem)
      {
         pRecentFileListItem = pTmpItem;
         nSelectedIndex = nIndex;
         break;
      }
   }
   if (pRecentFileListItem)
   {
      CMenu oMenu;
      VERIFY(oMenu.CreatePopupMenu());
      oMenu.AppendMenu(MF_STRING, 1, _T("&Open"));
      oMenu.AppendMenu(MF_STRING, 2, _T("&Copy path to clipboard"));
      if (!pRecentFileListItem->IsPinned())
         oMenu.AppendMenu(MF_STRING, 3, _T("&Pin to list"));
      else
         oMenu.AppendMenu(MF_STRING, 3, _T("&Unpin from list"));
      oMenu.AppendMenu(MF_STRING, 4, _T("&Remove from list"));
      oMenu.AppendMenu(MF_STRING, 5, _T("Cl&ear unpinned documents"));
      CPoint pos;
      GetCursorPos(&pos);
      int nMenuResult = UmMenu::TrackPopupMenu(&oMenu, 
         TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTALIGN |TPM_RIGHTBUTTON, 
         pos.x, pos.y, this, NULL);
      switch (nMenuResult)
      {
      case 1:
	 // -- Add code to close the backstage page and open the file
         break;
      case 2:
	 // -- Add code to copy to clipboard
         break;
      case 3:
         pRecentFileListItem->SetPinned(!pRecentFileListItem->IsPinned());
         pRecentFileList->WriteList();
         mRecentFileListBox.BuildItems();
         break;
      case 4:
         pRecentFileList->Remove(nSelectedIndex);
         pRecentFileList->WriteList();
         //OnSetActive(); // -- Add code to hide the list if it is empty here
         break;     
      case 5:
         for (int nIndex = pRecentFileList->GetCount(); nIndex >= 0; --nIndex)
         {
            CXTPRecentFileListItem* pTmpItem = dynamic_cast<CXTPRecentFileListItem*>(pRecentFileList->GetItem(nIndex));
            if (!pTmpItem)
               continue;
            if (!pTmpItem->IsPinned())
               pRecentFileList->Remove(nIndex);
         }
         pRecentFileList->WriteList();
         OnSetActive(); // -- Add code to hide the list if it is empty here
         break;
      default:
         return FALSE;
      }
      return TRUE; 
   }
   return FALSE;
}