finalcut/src/fmenulist.cpp

136 lines
3.8 KiB
C++
Raw Normal View History

/************************************************************************
* fmenulist.cpp - Menu item container base class *
* *
* This file is part of the Final Cut widget toolkit *
* *
* Copyright 2015-2017 Markus Gans *
* *
* The Final Cut is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* The Final Cut is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
************************************************************************/
2017-09-11 03:06:02 +02:00
#include <vector>
#include "final/fmenulist.h"
//----------------------------------------------------------------------
// class FMenuList
//----------------------------------------------------------------------
// constructor and destructor
//----------------------------------------------------------------------
FMenuList::FMenuList()
: selected_item()
, item_list()
2015-09-22 04:18:20 +02:00
{ }
//----------------------------------------------------------------------
FMenuList::~FMenuList() // destructor
{
// delete all items
if ( item_list.empty() )
return;
std::vector<FMenuItem*>::iterator iter;
iter = item_list.begin();
while ( iter != item_list.end() )
{
(*iter)->setSuperMenu(0);
iter = item_list.erase(iter);
}
}
// public methods of FMenuList
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FMenuList::insert (FMenuItem* i)
{
item_list.push_back(i);
}
//----------------------------------------------------------------------
2015-09-20 05:44:50 +02:00
void FMenuList::remove (FMenuItem* i)
{
std::vector<FMenuItem*>::iterator iter;
if ( item_list.empty() )
return;
iter = item_list.begin();
while ( iter != item_list.end() )
{
2015-09-20 05:44:50 +02:00
if ( (*iter) == i )
{
iter = item_list.erase(iter);
2015-09-20 05:44:50 +02:00
i->setSuperMenu(0);
break;
}
else
++iter;
}
}
//----------------------------------------------------------------------
void FMenuList::remove (int pos)
{
if ( int(getCount()) < pos )
return;
item_list.erase (item_list.begin() + pos - 1);
}
//----------------------------------------------------------------------
void FMenuList::clear()
{
item_list.clear();
}
//----------------------------------------------------------------------
void FMenuList::selectFirstItem()
{
std::vector<FMenuItem*>::const_iterator iter, end;
iter = item_list.begin();
end = item_list.end();
if ( item_list.empty() )
return;
if ( hasSelectedItem() )
unselectItem();
while ( iter != end )
{
if ( (*iter)->isEnabled() && ! (*iter)->isSeparator() )
{
// select first enabled item
(*iter)->setSelected();
setSelectedItem(*iter);
break;
}
++iter;
}
}
//----------------------------------------------------------------------
void FMenuList::unselectItem()
{
if ( hasSelectedItem() )
getSelectedItem()->unsetSelected();
setSelectedItem(0);
}