2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* 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 Lesser 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 Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-09-11 03:06:02 +02:00
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fmenulist.h"
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2017-10-02 07:32:33 +02:00
|
|
|
|
2015-08-09 23:47:08 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FMenuList
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuList::FMenuList()
|
2016-09-27 00:46:05 +02:00
|
|
|
: selected_item()
|
|
|
|
, item_list()
|
2015-09-22 04:18:20 +02:00
|
|
|
{ }
|
2015-08-09 23:47:08 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FMenuList::~FMenuList() // destructor
|
|
|
|
{
|
|
|
|
// delete all items
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( item_list.empty() )
|
|
|
|
return;
|
2015-08-09 23:47:08 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
std::vector<FMenuItem*>::iterator iter;
|
|
|
|
iter = item_list.begin();
|
|
|
|
|
|
|
|
while ( iter != item_list.end() )
|
|
|
|
{
|
|
|
|
(*iter)->setSuperMenu(0);
|
|
|
|
iter = item_list.erase(iter);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// public methods of FMenuList
|
|
|
|
//----------------------------------------------------------------------
|
2015-09-20 05:44:50 +02:00
|
|
|
void FMenuList::insert (FMenuItem* i)
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
item_list.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;
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
if ( item_list.empty() )
|
2015-08-09 23:47:08 +02:00
|
|
|
return;
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
iter = item_list.begin();
|
2016-07-09 00:01:59 +02:00
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
while ( iter != item_list.end() )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2015-09-20 05:44:50 +02:00
|
|
|
if ( (*iter) == i )
|
2015-08-09 23:47:08 +02:00
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
iter = item_list.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)
|
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
if ( int(getCount()) < pos )
|
2015-08-09 23:47:08 +02:00
|
|
|
return;
|
|
|
|
|
2016-09-27 00:46:05 +02:00
|
|
|
item_list.erase (item_list.begin() + pos - 1);
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FMenuList::clear()
|
|
|
|
{
|
2016-09-27 00:46:05 +02:00
|
|
|
item_list.clear();
|
2015-08-09 23:47:08 +02:00
|
|
|
}
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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);
|
|
|
|
}
|