finalcut/include/final/fmenulist.h

142 lines
5.2 KiB
C
Raw Normal View History

/************************************************************************
* fmenulist.h - 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/>. *
************************************************************************/
/* Base class
*
*
* 1 *
* FMenuList - - - - FMenuItem
*
* :1
* : *
* - - - - - - - FRadioMenuItem
* :
* :
* : *
* - - - - - - - FCheckMenuItem
*
*/
#ifndef FMENULIST_H
#define FMENULIST_H
#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
#error "Only <final/final.h> can be included directly."
#endif
2017-09-11 03:06:02 +02:00
#include <vector>
#include "final/fmenuitem.h"
#include "final/fwidget.h"
//----------------------------------------------------------------------
// class FMenuList
//----------------------------------------------------------------------
#pragma pack(push)
#pragma pack(1)
class FMenuList
{
2017-09-11 03:06:02 +02:00
public:
// Constructor
explicit FMenuList();
// Destructor
virtual ~FMenuList();
// Accessors
virtual const char* getClassName() const;
uInt getCount() const;
FMenuItem* getItem (int) const;
FMenuItem* getSelectedItem() const;
// Mutators
void enableItem (int);
void disableItem (int);
void setSelectedItem (FMenuItem*);
// Inquiries
bool isSelected (int) const;
bool hasSelectedItem() const;
// Methods
virtual void insert (FMenuItem*);
virtual void remove (FMenuItem*);
void remove (int);
void clear();
void selectFirstItem();
void unselectItem();
protected:
FMenuItem* selected_item;
std::vector<FMenuItem*> item_list;
private:
// Disable copy constructor
FMenuList (const FMenuList&);
// Disable assignment operator (=)
FMenuList& operator = (const FMenuList&);
};
#pragma pack(pop)
// FMenuList inline functions
//----------------------------------------------------------------------
inline const char* FMenuList::getClassName() const
{ return "FMenuList"; }
//----------------------------------------------------------------------
inline uInt FMenuList::getCount() const
{ return uInt(item_list.size()); }
//----------------------------------------------------------------------
inline FMenuItem* FMenuList::getItem (int index) const
{ return ( index > 0 ) ? item_list[uInt(index - 1)] : 0; }
//----------------------------------------------------------------------
inline FMenuItem* FMenuList::getSelectedItem() const
{ return selected_item; }
//----------------------------------------------------------------------
2015-10-29 21:10:50 +01:00
inline void FMenuList::enableItem (int index)
2017-09-15 01:31:02 +02:00
{ item_list[uInt(index - 1)]->setEnable(); }
//----------------------------------------------------------------------
2015-10-29 21:10:50 +01:00
inline void FMenuList::disableItem (int index)
2017-09-15 01:31:02 +02:00
{ item_list[uInt(index - 1)]->unsetEnable(); }
2015-11-07 23:16:09 +01:00
//----------------------------------------------------------------------
2015-11-12 01:33:16 +01:00
inline void FMenuList::setSelectedItem (FMenuItem* menuitem)
{ selected_item = menuitem; }
2015-11-07 23:16:09 +01:00
//----------------------------------------------------------------------
inline bool FMenuList::isSelected(int index) const
{ return ( index > 0 ) ? item_list[uInt(index - 1)]->isSelected() : false; }
2015-11-07 23:16:09 +01:00
//----------------------------------------------------------------------
inline bool FMenuList::hasSelectedItem() const
{ return selected_item; }
#endif // FMENULIST_H