finalcut/src/fmenulist.cpp

115 lines
2.3 KiB
C++
Raw Normal View History

// File: fmenulist.cpp
// Provides: class FMenuList
#include "fmenulist.h"
//----------------------------------------------------------------------
// class FMenuList
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FMenuList::FMenuList()
2015-11-07 23:16:09 +01:00
: selectedItem()
, itemlist()
2015-09-22 04:18:20 +02:00
{ }
//----------------------------------------------------------------------
FMenuList::~FMenuList() // destructor
{
// delete all items
if ( ! itemlist.empty() )
{
std::vector<FMenuItem*>::iterator iter;
iter = itemlist.begin();
while ( iter != itemlist.end() )
{
(*iter)->setSuperMenu(0);
iter = itemlist.erase(iter);
}
}
}
// public methods of FMenuList
2015-11-07 23:16:09 +01:00
//----------------------------------------------------------------------
void FMenuList::selectFirstItem()
{
std::vector<FMenuItem*>::const_iterator iter, end;
iter = itemlist.begin();
end = itemlist.end();
if ( itemlist.empty() )
return;
if ( hasSelectedItem() )
unselectItem();
while ( iter != end )
{
if ( (*iter)->isEnabled() && ! (*iter)->isSeparator() )
{
// select first enabled item
(*iter)->setSelected();
setSelectedItem(*iter);
break;
}
2015-11-07 23:16:09 +01:00
++iter;
}
}
//----------------------------------------------------------------------
void FMenuList::unselectItem()
{
if ( hasSelectedItem() )
getSelectedItem()->unsetSelected();
2015-11-07 23:16:09 +01:00
setSelectedItem(0);
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FMenuList::insert (FMenuItem* i)
{
2015-09-20 05:44:50 +02:00
itemlist.push_back(i);
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FMenuList::remove (FMenuItem* i)
{
std::vector<FMenuItem*>::iterator iter;
if ( itemlist.empty() )
return;
iter = itemlist.begin();
while ( iter != itemlist.end() )
{
2015-09-20 05:44:50 +02:00
if ( (*iter) == i )
{
iter = itemlist.erase(iter);
2015-09-20 05:44:50 +02:00
i->setSuperMenu(0);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FMenuList::remove (int pos)
{
if ( int(count()) < pos )
return;
itemlist.erase (itemlist.begin()+pos-1);
}
//----------------------------------------------------------------------
void FMenuList::clear()
{
itemlist.clear();
}