/*************************************************************************** * Copyright (C) 2008-2009 by Andrzej Rybczak * * electricityispower@gmail.com * * * * This program 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 2 of the License, or * * (at your option) any later version. * * * * This program 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, write to the * * Free Software Foundation, Inc., * * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef _MENU_H #define _MENU_H #include #include #include "window.h" #include "strbuffer.h" namespace NCurses { class List { public: class InvalidItem { }; List() { } virtual ~List() { } virtual void Select(int, bool) = 0; virtual void Static(int, bool) = 0; virtual bool Empty() const = 0; virtual bool isSelected(int = -1) const = 0; virtual bool isStatic(int = -1) const = 0; virtual bool hasSelected() const = 0; virtual void GetSelected(std::vector &) const = 0; virtual void Highlight(size_t) = 0; virtual size_t Size() const = 0; virtual size_t Choice() const = 0; virtual size_t RealChoice() const = 0; void SelectCurrent(); void ReverseSelection(size_t = 0); bool Deselect(); virtual bool Search(const std::string &, size_t = 0, int = 0) = 0; virtual const std::string &GetSearchConstraint() = 0; virtual void NextFound(bool) = 0; virtual void PrevFound(bool) = 0; virtual void ApplyFilter(const std::string &, size_t = 0, int = 0) = 0; virtual const std::string &GetFilter() = 0; virtual std::string GetOption(size_t) = 0; virtual bool isFiltered() = 0; }; template class Menu : public Window, public List { typedef void (*ItemDisplayer) (const T &, void *, Menu *); typedef std::string (*GetStringFunction) (const T &, void *); struct Option { Option() : isBold(0), isSelected(0), isStatic(0) { } Option(const T &t, bool is_bold, bool is_static) : Item(t), isBold(is_bold), isSelected(0), isStatic(is_static) { } T Item; bool isBold; bool isSelected; bool isStatic; }; template class InternalSorting { Comparison cmp; public: bool operator()(Option *a, Option *b) { return cmp(a->Item, b->Item); } }; typedef typename std::vector