HexEdit/NavManager.cpp
// Adds navigation points to end of passed menu.
// If forward is true then forward nav pts are added else backward nav pts are used.

Adds navigation points to end of passed menu.
If forward is true then forward nav pts are added else backward nav pts are used.
Adds navigation points to end of passed menu . If forward is true then forward nav pts are added else backward nav pts are used .
void CNavManager::AddItems(CMFCPopupMenu* pMenuPopup, bool forward, UINT first, int max_items)
{
	ASSERT( forward || pos_  >= 0);        
	ASSERT(!forward || pos_ < int(v_.size()) - 1);          
	CMenu *submenu = NULL;
	int menu_items = 0;           
	CHexEditView *pview = NULL;   
	CHexEditDoc *pdoc = NULL;     
	CString pname;                
	for (int ii = 0, curr = (forward ? pos_ + 1 : pos_ );
		 ii < max_items && ((forward && curr < int(v_.size())) || (!forward && curr >= 0));
		 ++ii, (forward ? ++curr : curr--) )
	{
		if (v_[curr].pview_ != pview)
		{
			if (submenu != NULL)
			{
				CString ss;
				ASSERT(pview != NULL && pdoc != NULL);
				if (is_open_view(pdoc, pview))
					pview->GetFrame()->GetWindowText(ss);
				else if (!pname.IsEmpty())
					ss = pname;
				else
					ss = "Closed file";         
				pMenuPopup->InsertItem(CMFCToolBarMenuButton(-1, submenu->GetSafeHmenu(), -1, ss));
				delete submenu;
				submenu = NULL;
			}
			submenu = new CMenu;
			submenu->CreatePopupMenu();
			pview = v_[curr].pview_;
			pdoc = v_[curr].pdoc_;
			pname = v_[curr].fname_;
			menu_items = 0;                     
		}
		if (menu_items < 50)
		{
			UINT flags = MF_ENABLED;
			if (!forward && ii == 0 && pos_offset() == -1)
				flags |= MF_CHECKED;
#if 0  
			if (total_items >= max_items)
				break;                     
			submenu->AppendMenu(flags, first + total_items, v_[curr].desc_);
			MENUITEMINFO mii;
			memset(&mii, '\0', sizeof(mii));
			mii.cbSize = sizeof(mii);
			mii.fMask = MIIM_DATA;
			mii.dwItemData = ii;
			submenu->SetMenuItemInfo(first + total_items, &mii);
			++total_items;
#else
			submenu->AppendMenu(flags, first + ii, v_[curr].desc_);
#endif
			++menu_items;                       
		}
	}
	ASSERT(submenu != NULL && pview != NULL);   
	if (submenu != NULL)
	{
		CString ss;
		if (is_open_view(pdoc, pview))
			pview->GetFrame()->GetWindowText(ss);
		else if (!pname.IsEmpty())
			ss = pname;
		else
			ss = "Closed file";
		pMenuPopup->InsertItem(CMFCToolBarMenuButton(-1, submenu->GetSafeHmenu(), -1, ss));
		delete submenu;
		submenu = NULL;
	}
}
void CNavManager :: AddItems ( CMFCPopupMenu * pMenuPopup , bool forward , UINT first , int max_items ) { ASSERT ( forward || pos_ >= 0 ) ; ASSERT ( ! forward || pos_ < int ( v_ . size ( ) ) - 1 ) ; CMenu * submenu = NULL ; int menu_items = 0 ; CHexEditView * pview = NULL ; CHexEditDoc * pdoc = NULL ; CString pname ; for ( int ii = 0 , curr = ( forward ? pos_ + 1 : pos_ ) ; ii < max_items && ( ( forward && curr < int ( v_ . size ( ) ) ) || ( ! forward && curr >= 0 ) ) ; ++ ii , ( forward ? ++ curr : curr -- ) ) { if ( v_ [ curr ] . pview_ != pview ) { if ( submenu != NULL ) { CString ss ; ASSERT ( pview != NULL && pdoc != NULL ) ; if ( is_open_view ( pdoc , pview ) ) pview -> GetFrame ( ) -> GetWindowText ( ss ) ; else if ( ! pname . IsEmpty ( ) ) ss = pname ; else ss = " " ; pMenuPopup -> InsertItem ( CMFCToolBarMenuButton ( -1 , submenu -> GetSafeHmenu ( ) , -1 , ss ) ) ; delete submenu ; submenu = NULL ; } submenu = new CMenu ; submenu -> CreatePopupMenu ( ) ; pview = v_ [ curr ] . pview_ ; pdoc = v_ [ curr ] . pdoc_ ; pname = v_ [ curr ] . fname_ ; menu_items = 0 ; } if ( menu_items < 50 ) { UINT flags = MF_ENABLED ; if ( ! forward && ii == 0 && pos_offset ( ) == -1 ) flags |= MF_CHECKED ; #if 0 if ( total_items >= max_items ) break ; submenu -> AppendMenu ( flags , first + total_items , v_ [ curr ] . desc_ ) ; MENUITEMINFO mii ; memset ( & mii , ' \0 ' , sizeof ( mii ) ) ; mii . cbSize = sizeof ( mii ) ; mii . fMask = MIIM_DATA ; mii . dwItemData = ii ; submenu -> SetMenuItemInfo ( first + total_items , & mii ) ; ++ total_items ; #else submenu -> AppendMenu ( flags , first + ii , v_ [ curr ] . desc_ ) ; #endif ++ menu_items ; } } ASSERT ( submenu != NULL && pview != NULL ) ; if ( submenu != NULL ) { CString ss ; if ( is_open_view ( pdoc , pview ) ) pview -> GetFrame ( ) -> GetWindowText ( ss ) ; else if ( ! pname . IsEmpty ( ) ) ss = pname ; else ss = " " ; pMenuPopup -> InsertItem ( CMFCToolBarMenuButton ( -1 , submenu -> GetSafeHmenu ( ) , -1 , ss ) ) ; delete submenu ; submenu = NULL ; } }
Adds navigation points to end of passed menu.
Adds navigation points to end of passed menu .
/* + pos_offset() */ // Can only show backward pts if there are any
 // Can only show forward pts if there are any
 // Create a sub-menu for each window here.  Note that this items appear on time order
 // so the same window may appear more than once in the lists (but not consecutively).
 // Items added so far to current sub-menu
 // Previous view
 // Previous doc
 // Previous file name
 /* + pos_offset() */ // Check if we need to start a new sub-menu
 // save current submenu and start a new one
 // Closed without saving to disk?
 // Starting new sub-menu
 // Only add max 50 items per sub-menu
 // Can we make this work???
 // Note: We tried saving nav point in menu item data rather than adding index to "first" to
 // get the menu item ID (command ID) to save IDs but by the time the command is received (see
 // CMainFrame::OnNavBack/Forw) the menu is already gone.
 // Check if we have run out of items (reserved command IDs)
 // out of command ids
 // Save nav point index in menu item data so we know which nav pt is selected by the menu item
 // Track how many items are in this sub-menu
 // This should not be NULL since there must be at least one item
