/*************************************************************************** * Copyright (C) 2008-2012 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 #include "error.h" #include "window.h" #include "strbuffer.h" namespace NCurses { /// List class is an interface for Menu class /// class List { public: /// @see Menu::Select() /// virtual void Select(int pos, bool state) = 0; /// @see Menu::isSelected() /// virtual bool isSelected(int pos = -1) const = 0; /// @see Menu::hasSelected() /// virtual bool hasSelected() const = 0; /// @see Menu::GetSelected() /// virtual void GetSelected(std::vector &v) const = 0; /// Highlights given position /// @param pos position to be highlighted /// virtual void Highlight(size_t pos) = 0; /// @return currently highlighted position /// virtual size_t Choice() const = 0; /// @see Menu::Empty() /// virtual bool Empty() const = 0; /// @see Menu::Size() /// virtual size_t Size() const = 0; /// @see Menu::Search() /// virtual bool Search(const std::string &constraint, size_t beginning = 0, int flags = 0) = 0; /// @see Menu::GetSearchConstraint() /// virtual const std::string &GetSearchConstraint() = 0; /// @see Menu::NextFound() /// virtual void NextFound(bool wrap) = 0; /// @see Menu::PrevFound() /// virtual void PrevFound(bool wrap) = 0; /// @see Menu::ApplyFilter() /// virtual void ApplyFilter(const std::string &filter, size_t beginning = 0, int flags = 0) = 0; /// @see Menu::GetFilter() /// virtual const std::string &GetFilter() = 0; /// @see Menu::isFiltered() /// virtual bool isFiltered() = 0; }; /// This template class is generic menu capable of /// holding any std::vector compatible values. /// template class Menu : public Window, public List { /// Function helper prototype used to display each option on the screen. /// If not set by SetItemDisplayer(), menu won't display anything. /// @see SetItemDisplayer() /// typedef void (*ItemDisplayer)(const T &, void *, Menu *); /// Function helper prototype used for converting items to strings. /// If not set by SetGetStringFunction(), searching and filtering /// won't work (note that Menu doesn't need this) /// @see SetGetStringFunction() /// typedef std::string (*GetStringFunction)(const T &, void *); /// Struct that holds each item in the list and its attributes /// 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; }; /// Functor that wraps around the functor passed to Sort() /// to fit to internal container structure /// template class InternalSorting { Comparison cmp; public: bool operator()(Option *a, Option *b) { return cmp(a->Item, b->Item); } }; typedef typename std::vector