diff --git a/src/menu.h b/src/menu.h index 92fe5950..6b1cea50 100644 --- a/src/menu.h +++ b/src/menu.h @@ -29,48 +29,133 @@ namespace NCurses { + /// List class is an interface for Menu class + /// class List { public: + /// Exception class, thrown by various functions + /// that return references to items on the list + /// if requested item is separator + /// @see Menu::Back() + /// @see Menu::Current() + /// @see Menu::at() + /// @see Menu::operator[] + /// class InvalidItem { }; - List() { } - virtual ~List() { } + /// @see Menu::Select() + /// + virtual void Select(int pos, bool state) = 0; - virtual void Select(int, bool) = 0; - virtual void Static(int, bool) = 0; + /// @see Menu::Static() + /// + virtual void Static(int pos, bool state) = 0; + + /// @see Menu::Empty() + /// virtual bool Empty() const = 0; - virtual bool isSelected(int = -1) const = 0; - virtual bool isStatic(int = -1) const = 0; + + /// @see Menu::isSelected() + /// + virtual bool isSelected(int pos = -1) const = 0; + + /// @see Menu::isStatic() + /// + virtual bool isStatic(int pos = -1) const = 0; + + /// @see Menu::hasSelected() + /// virtual bool hasSelected() const = 0; - virtual void GetSelected(std::vector &) const = 0; - virtual void Highlight(size_t) = 0; + + /// @see Menu::GetSelected() + /// + virtual void GetSelected(std::vector &v) const = 0; + + /// @see Menu::Highlight() + /// + virtual void Highlight(size_t pos) = 0; + + /// @see Menu::Size() + /// virtual size_t Size() const = 0; + + /// @see Menu::Choice() + /// virtual size_t Choice() const = 0; + + /// @see Menu::RealChoice() + /// virtual size_t RealChoice() const = 0; + /// Selects current position + /// void SelectCurrent(); - void ReverseSelection(size_t = 0); + + /// Reverses selection of all items in list + /// @param beginning beginning of range that has to be reversed + /// + void ReverseSelection(size_t beginning = 0); + + /// Deselects all items in list + /// @return true if there was at least one selected items, false otherwise + /// bool Deselect(); - virtual bool Search(const std::string &, size_t = 0, int = 0) = 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; - virtual void NextFound(bool) = 0; - virtual void PrevFound(bool) = 0; - virtual void ApplyFilter(const std::string &, size_t = 0, int = 0) = 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; - virtual std::string GetOption(size_t) = 0; + /// @see Menu::GetOption() + /// + virtual std::string GetOption(size_t pos) = 0; + + /// @see Menu::isFiltered() + /// virtual bool isFiltered() = 0; }; + /// This template class is generic menu, that has holds + /// any values that are std::vector compatible. + /// template class Menu : public Window, public List { - typedef void (*ItemDisplayer) (const T &, void *, Menu *); - typedef std::string (*GetStringFunction) (const T &, void *); + /// 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) { } @@ -83,6 +168,9 @@ namespace NCurses bool isStatic; }; + /// Functor that wraps around the functor passed to Sort() + /// to fit to internal container structure + /// template class InternalSorting { Comparison cmp; @@ -98,61 +186,260 @@ namespace NCurses typedef typename std::vector