- // MenuItemList.cpp: implementation of the CMenuItemList class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MenuItemList.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CMenuItemList::CMenuItemList()
- {
- m_nCount=0;
- m_pLastItem= NULL;
- m_pHead=NULL;
- m_pTail=NULL;
- }
- CMenuItemList::~CMenuItemList()
- {
- if( m_nCount !=0 )
- RemoveAllItems();
- }
- void CMenuItemList::Add(MenuItem mItem)
- {
- MenuItem * pItem=new MenuItem;
- pItem->m_iIndex =m_nCount +1;
- pItem->m_strMenuText = mItem.m_strMenuText ;
- pItem->m_iID = mItem.m_iID ;
- // pItem->m_MenuStyle =mItem.m_MenuStyle ;
- pItem->m_iImageID =mItem.m_iImageID ;
- pItem->m_pLastItem = m_pLastItem;
- if (NULL== m_pLastItem ) // the head
- m_pHead=pItem;
- else
- m_pLastItem->m_pNextItem = pItem;
- m_pLastItem = pItem;
- m_pTail=pItem;
- m_nCount++;
- }
- void CMenuItemList::Remove( unsigned int nIndex)
- {
- }
- CString CMenuItemList::FindItemTextByID( unsigned int nID)
- {
- MenuItem * pItem;
- pItem=m_pHead;
- CString str1;
- str1="";
- while(pItem->m_pNextItem != NULL)
- {
- if(nID == pItem->m_iID )
- return pItem->m_strMenuText ;
- if( pItem->m_pNextItem == NULL ) break;
- pItem= pItem->m_pNextItem ;
- }
- return str1;
- }
- void CMenuItemList::RemoveAllItems()
- {
- while( m_nCount) RemoveTail();
- }
- void CMenuItemList::RemoveTail()
- {
- if( m_nCount == 0) return;
- MenuItem * pNewTail=NULL;
- if ( m_pTail != m_pHead)
- {
- pNewTail= m_pTail->m_pLastItem ;
- pNewTail->m_pNextItem =NULL;
- }
- delete m_pTail;
- m_pTail=pNewTail;
- pNewTail=NULL;
- m_nCount--;
- }
- unsigned int CMenuItemList::FindItemIndexByID(unsigned int nID)
- {
- MenuItem * pItem;
- pItem=m_pHead;
- while(pItem->m_pNextItem != NULL)
- {
- if(nID == pItem->m_iID )
- return pItem->m_iIndex ;
- if( pItem->m_pNextItem == NULL ) break;
- pItem= pItem->m_pNextItem ;
- }
- return 0;
- }
- int CMenuItemList::FindItemImageByID(unsigned int nID)
- {
- MenuItem * pItem;
- pItem=m_pHead;
- while(pItem->m_pNextItem != NULL)
- {
- if(nID == pItem->m_iID )
- return pItem->m_iImageID ;
- if( pItem->m_pNextItem == NULL ) break;
- pItem= pItem->m_pNextItem ;
- }
- return -1;
- }