2015-09-25 21:37:19 +02:00
|
|
|
// File: fmenulist.cpp
|
|
|
|
// Provides: class FMenuList
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
#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
|
|
|
{ }
|
2015-08-09 23:47:08 +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;
|
|
|
|
}
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuList::unselectItem()
|
|
|
|
{
|
|
|
|
if ( hasSelectedItem() )
|
|
|
|
getSelectedItem()->unsetSelected();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-11-07 23:16:09 +01:00
|
|
|
setSelectedItem(0);
|
|
|
|
}
|
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FMenuList::insert (FMenuItem* i)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-09-20 05:44:50 +02:00
|
|
|
itemlist.push_back(i);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FMenuList::remove (FMenuItem* i)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
std::vector<FMenuItem*>::iterator iter;
|
|
|
|
|
|
|
|
if ( itemlist.empty() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
iter = itemlist.begin();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
while ( iter != itemlist.end() )
|
|
|
|
{
|
2015-09-20 05:44:50 +02:00
|
|
|
if ( (*iter) == i )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
|
|
|
iter = itemlist.erase(iter);
|
2015-09-20 05:44:50 +02:00
|
|
|
i->setSuperMenu(0);
|
2015-08-09 23:47:08 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
++iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuList::remove (int pos)
|
|
|
|
{
|
|
|
|
if ( int(count()) < pos )
|
|
|
|
return;
|
|
|
|
|
|
|
|
itemlist.erase (itemlist.begin()+pos-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuList::clear()
|
|
|
|
{
|
|
|
|
itemlist.clear();
|
|
|
|
}
|