put classes related to ncurses into NCurses namespace
This commit is contained in:
@@ -20,6 +20,8 @@
|
|||||||
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
|
||||||
|
using namespace NCurses;
|
||||||
|
|
||||||
void List::SelectCurrent()
|
void List::SelectCurrent()
|
||||||
{
|
{
|
||||||
if (Empty())
|
if (Empty())
|
||||||
|
|||||||
326
src/menu.h
326
src/menu.h
@@ -25,154 +25,156 @@
|
|||||||
#include "strbuffer.h"
|
#include "strbuffer.h"
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
|
||||||
class List
|
namespace NCurses
|
||||||
{
|
{
|
||||||
public:
|
class List
|
||||||
|
|
||||||
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<size_t> &) 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 void ApplyFilter(const std::string &, size_t = 0, bool = 0) = 0;
|
|
||||||
virtual const std::string &GetFilter() = 0;
|
|
||||||
virtual std::string GetOption(size_t) = 0;
|
|
||||||
|
|
||||||
virtual bool isFiltered() = 0;
|
|
||||||
//virtual void ShowAll() = 0;
|
|
||||||
//virtual void ShowFiltered() = 0;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class T> class Menu : public Window, public List
|
|
||||||
{
|
|
||||||
typedef void (*ItemDisplayer) (const T &, void *, Menu<T> *);
|
|
||||||
typedef std::string (*GetStringFunction) (const T &, void *);
|
|
||||||
|
|
||||||
struct Option
|
|
||||||
{
|
{
|
||||||
Option() : isBold(0), isSelected(0), isStatic(0) { }
|
public:
|
||||||
Option(const T &t, bool is_bold, bool is_static) :
|
|
||||||
Item(t), isBold(is_bold), isSelected(0), isStatic(is_static) { }
|
|
||||||
|
|
||||||
T Item;
|
class InvalidItem { };
|
||||||
bool isBold;
|
|
||||||
bool isSelected;
|
List() { }
|
||||||
bool isStatic;
|
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<size_t> &) 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 void ApplyFilter(const std::string &, size_t = 0, bool = 0) = 0;
|
||||||
|
virtual const std::string &GetFilter() = 0;
|
||||||
|
virtual std::string GetOption(size_t) = 0;
|
||||||
|
|
||||||
|
virtual bool isFiltered() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef typename std::vector<Option *>::iterator option_iterator;
|
template <class T> class Menu : public Window, public List
|
||||||
typedef typename std::vector<Option *>::const_iterator option_const_iterator;
|
{
|
||||||
|
typedef void (*ItemDisplayer) (const T &, void *, Menu<T> *);
|
||||||
|
typedef std::string (*GetStringFunction) (const T &, void *);
|
||||||
|
|
||||||
public:
|
struct Option
|
||||||
Menu(size_t, size_t, size_t, size_t, const std::string &, Color, Border);
|
{
|
||||||
Menu(const Menu &);
|
Option() : isBold(0), isSelected(0), isStatic(0) { }
|
||||||
virtual ~Menu();
|
Option(const T &t, bool is_bold, bool is_static) :
|
||||||
|
Item(t), isBold(is_bold), isSelected(0), isStatic(is_static) { }
|
||||||
|
|
||||||
void SetItemDisplayer(ItemDisplayer ptr) { itsItemDisplayer = ptr; }
|
T Item;
|
||||||
void SetItemDisplayerUserData(void *data) { itsItemDisplayerUserdata = data; }
|
bool isBold;
|
||||||
|
bool isSelected;
|
||||||
|
bool isStatic;
|
||||||
|
};
|
||||||
|
|
||||||
void SetGetStringFunction(GetStringFunction f) { itsGetStringFunction = f; }
|
typedef typename std::vector<Option *>::iterator option_iterator;
|
||||||
void SetGetStringFunctionUserData(void *data) { itsGetStringFunctionUserData = data; }
|
typedef typename std::vector<Option *>::const_iterator option_const_iterator;
|
||||||
|
|
||||||
void Reserve(size_t size);
|
public:
|
||||||
void ResizeBuffer(size_t size);
|
Menu(size_t, size_t, size_t, size_t, const std::string &, Color, Border);
|
||||||
void AddOption(const T &item, bool is_bold = 0, bool is_static = 0);
|
Menu(const Menu &);
|
||||||
void AddSeparator();
|
virtual ~Menu();
|
||||||
void InsertOption(size_t pos, const T &Item, bool is_bold = 0, bool is_static = 0);
|
|
||||||
void InsertSeparator(size_t pos);
|
|
||||||
void DeleteOption(size_t pos);
|
|
||||||
void IntoSeparator(size_t pos);
|
|
||||||
void Swap(size_t, size_t);
|
|
||||||
|
|
||||||
bool isBold(int id = -1);
|
void SetItemDisplayer(ItemDisplayer ptr) { itsItemDisplayer = ptr; }
|
||||||
void BoldOption(int, bool);
|
void SetItemDisplayerUserData(void *data) { itsItemDisplayerUserdata = data; }
|
||||||
|
|
||||||
virtual void Select(int id, bool value);
|
void SetGetStringFunction(GetStringFunction f) { itsGetStringFunction = f; }
|
||||||
virtual void Static(int id, bool value);
|
void SetGetStringFunctionUserData(void *data) { itsGetStringFunctionUserData = data; }
|
||||||
virtual bool isSelected(int id = -1) const;
|
|
||||||
virtual bool isStatic(int id = -1) const;
|
|
||||||
virtual bool hasSelected() const;
|
|
||||||
virtual void GetSelected(std::vector<size_t> &v) const;
|
|
||||||
virtual void Highlight(size_t);
|
|
||||||
virtual size_t Size() const;
|
|
||||||
virtual size_t Choice() const;
|
|
||||||
virtual size_t RealChoice() const;
|
|
||||||
|
|
||||||
virtual void ApplyFilter(const std::string &filter, size_t beginning = 0, bool case_sensitive = 0);
|
void Reserve(size_t size);
|
||||||
virtual const std::string &GetFilter();
|
void ResizeBuffer(size_t size);
|
||||||
virtual std::string GetOption(size_t pos);
|
void AddOption(const T &item, bool is_bold = 0, bool is_static = 0);
|
||||||
|
void AddSeparator();
|
||||||
|
void InsertOption(size_t pos, const T &Item, bool is_bold = 0, bool is_static = 0);
|
||||||
|
void InsertSeparator(size_t pos);
|
||||||
|
void DeleteOption(size_t pos);
|
||||||
|
void IntoSeparator(size_t pos);
|
||||||
|
void Swap(size_t, size_t);
|
||||||
|
|
||||||
virtual bool isFiltered() { return itsOptionsPtr == &itsFilteredOptions; }
|
bool isBold(int id = -1);
|
||||||
|
void BoldOption(int, bool);
|
||||||
|
|
||||||
void ShowAll() { itsOptionsPtr = &itsOptions; }
|
virtual void Select(int id, bool value);
|
||||||
void ShowFiltered() { itsOptionsPtr = &itsFilteredOptions; }
|
virtual void Static(int id, bool value);
|
||||||
|
virtual bool isSelected(int id = -1) const;
|
||||||
|
virtual bool isStatic(int id = -1) const;
|
||||||
|
virtual bool hasSelected() const;
|
||||||
|
virtual void GetSelected(std::vector<size_t> &v) const;
|
||||||
|
virtual void Highlight(size_t);
|
||||||
|
virtual size_t Size() const;
|
||||||
|
virtual size_t Choice() const;
|
||||||
|
virtual size_t RealChoice() const;
|
||||||
|
|
||||||
virtual void Refresh();
|
virtual void ApplyFilter(const std::string &filter, size_t beginning = 0, bool case_sensitive = 0);
|
||||||
virtual void Scroll(Where);
|
virtual const std::string &GetFilter();
|
||||||
virtual void Reset();
|
virtual std::string GetOption(size_t pos);
|
||||||
virtual void Clear(bool clrscr = 1);
|
|
||||||
|
|
||||||
void SetSelectPrefix(Buffer *b) { itsSelectedPrefix = b; }
|
virtual bool isFiltered() { return itsOptionsPtr == &itsFilteredOptions; }
|
||||||
void SetSelectSuffix(Buffer *b) { itsSelectedSuffix = b; }
|
|
||||||
|
|
||||||
void HighlightColor(Color col) { itsHighlightColor = col; }
|
void ShowAll() { itsOptionsPtr = &itsOptions; }
|
||||||
void Highlighting(bool hl) { highlightEnabled = hl; }
|
void ShowFiltered() { itsOptionsPtr = &itsFilteredOptions; }
|
||||||
|
|
||||||
virtual bool Empty() const { return itsOptionsPtr->empty(); }
|
virtual void Refresh();
|
||||||
|
virtual void Scroll(Where);
|
||||||
|
virtual void Reset();
|
||||||
|
virtual void Clear(bool clrscr = 1);
|
||||||
|
|
||||||
T &Back();
|
void SetSelectPrefix(Buffer *b) { itsSelectedPrefix = b; }
|
||||||
const T &Back() const;
|
void SetSelectSuffix(Buffer *b) { itsSelectedSuffix = b; }
|
||||||
T &Current();
|
|
||||||
const T &Current() const;
|
|
||||||
T &at(size_t i);
|
|
||||||
const T &at(size_t i) const;
|
|
||||||
const T &operator[](size_t i) const;
|
|
||||||
T &operator[](size_t i);
|
|
||||||
|
|
||||||
virtual Menu<T> *Clone() const { return new Menu<T>(*this); }
|
void HighlightColor(Color col) { itsHighlightColor = col; }
|
||||||
virtual Menu<T> *EmptyClone() const;
|
void Highlighting(bool hl) { highlightEnabled = hl; }
|
||||||
|
|
||||||
protected:
|
virtual bool Empty() const { return itsOptionsPtr->empty(); }
|
||||||
ItemDisplayer itsItemDisplayer;
|
|
||||||
void *itsItemDisplayerUserdata;
|
|
||||||
GetStringFunction itsGetStringFunction;
|
|
||||||
void *itsGetStringFunctionUserData;
|
|
||||||
|
|
||||||
std::string itsFilter;
|
T &Back();
|
||||||
|
const T &Back() const;
|
||||||
|
T &Current();
|
||||||
|
const T &Current() const;
|
||||||
|
T &at(size_t i);
|
||||||
|
const T &at(size_t i) const;
|
||||||
|
const T &operator[](size_t i) const;
|
||||||
|
T &operator[](size_t i);
|
||||||
|
|
||||||
std::vector<Option *> *itsOptionsPtr;
|
virtual Menu<T> *Clone() const { return new Menu<T>(*this); }
|
||||||
std::vector<Option *> itsOptions;
|
virtual Menu<T> *EmptyClone() const;
|
||||||
std::vector<Option *> itsFilteredOptions;
|
|
||||||
std::vector<size_t> itsFilteredRealPositions;
|
|
||||||
|
|
||||||
int itsBeginning;
|
protected:
|
||||||
int itsHighlight;
|
ItemDisplayer itsItemDisplayer;
|
||||||
|
void *itsItemDisplayerUserdata;
|
||||||
|
GetStringFunction itsGetStringFunction;
|
||||||
|
void *itsGetStringFunctionUserData;
|
||||||
|
|
||||||
Color itsHighlightColor;
|
std::string itsFilter;
|
||||||
bool highlightEnabled;
|
|
||||||
|
|
||||||
Buffer *itsSelectedPrefix;
|
std::vector<Option *> *itsOptionsPtr;
|
||||||
Buffer *itsSelectedSuffix;
|
std::vector<Option *> itsOptions;
|
||||||
};
|
std::vector<Option *> itsFilteredOptions;
|
||||||
|
std::vector<size_t> itsFilteredRealPositions;
|
||||||
|
|
||||||
template <class T> Menu<T>::Menu(size_t startx,
|
int itsBeginning;
|
||||||
|
int itsHighlight;
|
||||||
|
|
||||||
|
Color itsHighlightColor;
|
||||||
|
bool highlightEnabled;
|
||||||
|
|
||||||
|
Buffer *itsSelectedPrefix;
|
||||||
|
Buffer *itsSelectedSuffix;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <> std::string Menu<std::string>::GetOption(size_t pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <class T> NCurses::Menu<T>::Menu(size_t startx,
|
||||||
size_t starty,
|
size_t starty,
|
||||||
size_t width,
|
size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
@@ -194,7 +196,7 @@ template <class T> Menu<T>::Menu(size_t startx,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> Menu<T>::Menu(const Menu &m) : Window(m)
|
template <class T> NCurses::Menu<T>::Menu(const Menu &m) : Window(m)
|
||||||
{
|
{
|
||||||
itsOptions = m.itsOptions;
|
itsOptions = m.itsOptions;
|
||||||
itsItemDisplayer = m.itsItemDisplayer;
|
itsItemDisplayer = m.itsItemDisplayer;
|
||||||
@@ -205,18 +207,18 @@ template <class T> Menu<T>::Menu(const Menu &m) : Window(m)
|
|||||||
highlightEnabled = m.highlightEnabled;
|
highlightEnabled = m.highlightEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> Menu<T>::~Menu()
|
template <class T> NCurses::Menu<T>::~Menu()
|
||||||
{
|
{
|
||||||
for (option_iterator it = itsOptions.begin(); it != itsOptions.end(); it++)
|
for (option_iterator it = itsOptions.begin(); it != itsOptions.end(); it++)
|
||||||
delete *it;
|
delete *it;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Reserve(size_t size)
|
template <class T> void NCurses::Menu<T>::Reserve(size_t size)
|
||||||
{
|
{
|
||||||
itsOptions.reserve(size);
|
itsOptions.reserve(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::ResizeBuffer(size_t size)
|
template <class T> void NCurses::Menu<T>::ResizeBuffer(size_t size)
|
||||||
{
|
{
|
||||||
itsOptions.resize(size);
|
itsOptions.resize(size);
|
||||||
for (size_t i = 0; i < size; i++)
|
for (size_t i = 0; i < size; i++)
|
||||||
@@ -224,27 +226,27 @@ template <class T> void Menu<T>::ResizeBuffer(size_t size)
|
|||||||
itsOptions[i] = new Option();
|
itsOptions[i] = new Option();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::AddOption(const T &item, bool is_bold, bool is_static)
|
template <class T> void NCurses::Menu<T>::AddOption(const T &item, bool is_bold, bool is_static)
|
||||||
{
|
{
|
||||||
itsOptions.push_back(new Option(item, is_bold, is_static));
|
itsOptions.push_back(new Option(item, is_bold, is_static));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::AddSeparator()
|
template <class T> void NCurses::Menu<T>::AddSeparator()
|
||||||
{
|
{
|
||||||
itsOptions.push_back(0);
|
itsOptions.push_back(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::InsertOption(size_t pos, const T &item, bool is_bold, bool is_static)
|
template <class T> void NCurses::Menu<T>::InsertOption(size_t pos, const T &item, bool is_bold, bool is_static)
|
||||||
{
|
{
|
||||||
itsOptions.insert(itsOptions.begin()+pos, new Option(item, is_bold, is_static));
|
itsOptions.insert(itsOptions.begin()+pos, new Option(item, is_bold, is_static));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::InsertSeparator(size_t pos)
|
template <class T> void NCurses::Menu<T>::InsertSeparator(size_t pos)
|
||||||
{
|
{
|
||||||
itsOptions.insert(itsOptions.begin()+pos, 0);
|
itsOptions.insert(itsOptions.begin()+pos, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::DeleteOption(size_t pos)
|
template <class T> void NCurses::Menu<T>::DeleteOption(size_t pos)
|
||||||
{
|
{
|
||||||
if (itsOptions.empty())
|
if (itsOptions.empty())
|
||||||
return;
|
return;
|
||||||
@@ -266,13 +268,13 @@ template <class T> void Menu<T>::DeleteOption(size_t pos)
|
|||||||
Window::Clear();
|
Window::Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::IntoSeparator(size_t pos)
|
template <class T> void NCurses::Menu<T>::IntoSeparator(size_t pos)
|
||||||
{
|
{
|
||||||
delete itsOptions.at(pos);
|
delete itsOptions.at(pos);
|
||||||
itsOptions[pos] = 0;
|
itsOptions[pos] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::BoldOption(int index, bool bold)
|
template <class T> void NCurses::Menu<T>::BoldOption(int index, bool bold)
|
||||||
{
|
{
|
||||||
if (!itsOptions.at(index))
|
if (!itsOptions.at(index))
|
||||||
return;
|
return;
|
||||||
@@ -280,12 +282,12 @@ template <class T> void Menu<T>::BoldOption(int index, bool bold)
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
void Menu<T>::Swap(size_t one, size_t two)
|
void NCurses::Menu<T>::Swap(size_t one, size_t two)
|
||||||
{
|
{
|
||||||
std::swap(itsOptions.at(one), itsOptions.at(two));
|
std::swap(itsOptions.at(one), itsOptions.at(two));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Refresh()
|
template <class T> void NCurses::Menu<T>::Refresh()
|
||||||
{
|
{
|
||||||
if (itsOptionsPtr->empty())
|
if (itsOptionsPtr->empty())
|
||||||
{
|
{
|
||||||
@@ -348,7 +350,7 @@ template <class T> void Menu<T>::Refresh()
|
|||||||
Window::Refresh();
|
Window::Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Scroll(Where where)
|
template <class T> void NCurses::Menu<T>::Scroll(Where where)
|
||||||
{
|
{
|
||||||
if (itsOptionsPtr->empty())
|
if (itsOptionsPtr->empty())
|
||||||
return;
|
return;
|
||||||
@@ -454,13 +456,13 @@ template <class T> void Menu<T>::Scroll(Where where)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Reset()
|
template <class T> void NCurses::Menu<T>::Reset()
|
||||||
{
|
{
|
||||||
itsHighlight = 0;
|
itsHighlight = 0;
|
||||||
itsBeginning = 0;
|
itsBeginning = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Clear(bool clrscr)
|
template <class T> void NCurses::Menu<T>::Clear(bool clrscr)
|
||||||
{
|
{
|
||||||
for (option_iterator it = itsOptions.begin(); it != itsOptions.end(); it++)
|
for (option_iterator it = itsOptions.begin(); it != itsOptions.end(); it++)
|
||||||
delete *it;
|
delete *it;
|
||||||
@@ -473,7 +475,7 @@ template <class T> void Menu<T>::Clear(bool clrscr)
|
|||||||
Window::Clear();
|
Window::Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool Menu<T>::isBold(int id)
|
template <class T> bool NCurses::Menu<T>::isBold(int id)
|
||||||
{
|
{
|
||||||
id = id == -1 ? itsHighlight : id;
|
id = id == -1 ? itsHighlight : id;
|
||||||
if (!itsOptionsPtr->at(id))
|
if (!itsOptionsPtr->at(id))
|
||||||
@@ -481,21 +483,21 @@ template <class T> bool Menu<T>::isBold(int id)
|
|||||||
return (*itsOptionsPtr)[id]->isBold;
|
return (*itsOptionsPtr)[id]->isBold;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Select(int id, bool value)
|
template <class T> void NCurses::Menu<T>::Select(int id, bool value)
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(id))
|
if (!itsOptionsPtr->at(id))
|
||||||
return;
|
return;
|
||||||
(*itsOptionsPtr)[id]->isSelected = value;
|
(*itsOptionsPtr)[id]->isSelected = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Static(int id, bool value)
|
template <class T> void NCurses::Menu<T>::Static(int id, bool value)
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(id))
|
if (!itsOptionsPtr->at(id))
|
||||||
return;
|
return;
|
||||||
(*itsOptionsPtr)[id]->isStatic = value;
|
(*itsOptionsPtr)[id]->isStatic = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool Menu<T>::isSelected(int id) const
|
template <class T> bool NCurses::Menu<T>::isSelected(int id) const
|
||||||
{
|
{
|
||||||
id = id == -1 ? itsHighlight : id;
|
id = id == -1 ? itsHighlight : id;
|
||||||
if (!itsOptionsPtr->at(id))
|
if (!itsOptionsPtr->at(id))
|
||||||
@@ -503,7 +505,7 @@ template <class T> bool Menu<T>::isSelected(int id) const
|
|||||||
return (*itsOptionsPtr)[id]->isSelected;
|
return (*itsOptionsPtr)[id]->isSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool Menu<T>::isStatic(int id) const
|
template <class T> bool NCurses::Menu<T>::isStatic(int id) const
|
||||||
{
|
{
|
||||||
id = id == -1 ? itsHighlight : id;
|
id = id == -1 ? itsHighlight : id;
|
||||||
if (!itsOptionsPtr->at(id))
|
if (!itsOptionsPtr->at(id))
|
||||||
@@ -511,7 +513,7 @@ template <class T> bool Menu<T>::isStatic(int id) const
|
|||||||
return (*itsOptionsPtr)[id]->isStatic;
|
return (*itsOptionsPtr)[id]->isStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> bool Menu<T>::hasSelected() const
|
template <class T> bool NCurses::Menu<T>::hasSelected() const
|
||||||
{
|
{
|
||||||
for (option_const_iterator it = itsOptionsPtr->begin(); it != itsOptionsPtr->end(); it++)
|
for (option_const_iterator it = itsOptionsPtr->begin(); it != itsOptionsPtr->end(); it++)
|
||||||
if (*it && (*it)->isSelected)
|
if (*it && (*it)->isSelected)
|
||||||
@@ -519,30 +521,30 @@ template <class T> bool Menu<T>::hasSelected() const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::GetSelected(std::vector<size_t> &v) const
|
template <class T> void NCurses::Menu<T>::GetSelected(std::vector<size_t> &v) const
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < itsOptionsPtr->size(); i++)
|
for (size_t i = 0; i < itsOptionsPtr->size(); i++)
|
||||||
if ((*itsOptionsPtr)[i]->isSelected)
|
if ((*itsOptionsPtr)[i]->isSelected)
|
||||||
v.push_back(i);
|
v.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::Highlight(size_t pos)
|
template <class T> void NCurses::Menu<T>::Highlight(size_t pos)
|
||||||
{
|
{
|
||||||
itsHighlight = pos;
|
itsHighlight = pos;
|
||||||
itsBeginning = pos-itsHeight/2;
|
itsBeginning = pos-itsHeight/2;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> size_t Menu<T>::Size() const
|
template <class T> size_t NCurses::Menu<T>::Size() const
|
||||||
{
|
{
|
||||||
return itsOptionsPtr->size();
|
return itsOptionsPtr->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> size_t Menu<T>::Choice() const
|
template <class T> size_t NCurses::Menu<T>::Choice() const
|
||||||
{
|
{
|
||||||
return itsHighlight;
|
return itsHighlight;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> size_t Menu<T>::RealChoice() const
|
template <class T> size_t NCurses::Menu<T>::RealChoice() const
|
||||||
{
|
{
|
||||||
size_t result = 0;
|
size_t result = 0;
|
||||||
for (option_const_iterator it = itsOptionsPtr->begin(); it != itsOptionsPtr->begin()+itsHighlight; it++)
|
for (option_const_iterator it = itsOptionsPtr->begin(); it != itsOptionsPtr->begin()+itsHighlight; it++)
|
||||||
@@ -551,7 +553,7 @@ template <class T> size_t Menu<T>::RealChoice() const
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> void Menu<T>::ApplyFilter(const std::string &filter, size_t beginning, bool case_sensitive)
|
template <class T> void NCurses::Menu<T>::ApplyFilter(const std::string &filter, size_t beginning, bool case_sensitive)
|
||||||
{
|
{
|
||||||
if (filter == itsFilter)
|
if (filter == itsFilter)
|
||||||
return;
|
return;
|
||||||
@@ -585,12 +587,12 @@ template <class T> void Menu<T>::ApplyFilter(const std::string &filter, size_t b
|
|||||||
Window::Clear();
|
Window::Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> const std::string &Menu<T>::GetFilter()
|
template <class T> const std::string &NCurses::Menu<T>::GetFilter()
|
||||||
{
|
{
|
||||||
return itsFilter;
|
return itsFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> std::string Menu<T>::GetOption(size_t pos)
|
template <class T> std::string NCurses::Menu<T>::GetOption(size_t pos)
|
||||||
{
|
{
|
||||||
if (itsOptionsPtr->at(pos) && itsGetStringFunction)
|
if (itsOptionsPtr->at(pos) && itsGetStringFunction)
|
||||||
return itsGetStringFunction((*itsOptionsPtr)[pos]->Item, itsGetStringFunctionUserData);
|
return itsGetStringFunction((*itsOptionsPtr)[pos]->Item, itsGetStringFunctionUserData);
|
||||||
@@ -598,67 +600,65 @@ template <class T> std::string Menu<T>::GetOption(size_t pos)
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
template <> std::string Menu<std::string>::GetOption(size_t pos);
|
template <class T> T &NCurses::Menu<T>::Back()
|
||||||
|
|
||||||
template <class T> T &Menu<T>::Back()
|
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->back())
|
if (!itsOptionsPtr->back())
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return itsOptionsPtr->back()->Item;
|
return itsOptionsPtr->back()->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> const T &Menu<T>::Back() const
|
template <class T> const T &NCurses::Menu<T>::Back() const
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->back())
|
if (!itsOptionsPtr->back())
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return itsOptionsPtr->back()->Item;
|
return itsOptionsPtr->back()->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> T &Menu<T>::Current()
|
template <class T> T &NCurses::Menu<T>::Current()
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(itsHighlight))
|
if (!itsOptionsPtr->at(itsHighlight))
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return (*itsOptionsPtr)[itsHighlight]->Item;
|
return (*itsOptionsPtr)[itsHighlight]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> const T &Menu<T>::Current() const
|
template <class T> const T &NCurses::Menu<T>::Current() const
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(itsHighlight))
|
if (!itsOptionsPtr->at(itsHighlight))
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return (*itsOptionsPtr)[itsHighlight]->Item;
|
return (*itsOptionsPtr)[itsHighlight]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> T &Menu<T>::at(size_t i)
|
template <class T> T &NCurses::Menu<T>::at(size_t i)
|
||||||
{
|
{
|
||||||
if (!itsOptionsPtr->at(i))
|
if (!itsOptionsPtr->at(i))
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return (*itsOptionsPtr)[i]->Item;
|
return (*itsOptionsPtr)[i]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> const T &Menu<T>::at(size_t i) const
|
template <class T> const T &NCurses::Menu<T>::at(size_t i) const
|
||||||
{
|
{
|
||||||
if (!itsOptions->at(i))
|
if (!itsOptions->at(i))
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return (*itsOptionsPtr)[i]->Item;
|
return (*itsOptionsPtr)[i]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> const T &Menu<T>::operator[](size_t i) const
|
template <class T> const T &NCurses::Menu<T>::operator[](size_t i) const
|
||||||
{
|
{
|
||||||
if (!(*itsOptionsPtr)[i])
|
if (!(*itsOptionsPtr)[i])
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return (*itsOptionsPtr)[i]->Item;
|
return (*itsOptionsPtr)[i]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> T &Menu<T>::operator[](size_t i)
|
template <class T> T &NCurses::Menu<T>::operator[](size_t i)
|
||||||
{
|
{
|
||||||
if (!(*itsOptionsPtr)[i])
|
if (!(*itsOptionsPtr)[i])
|
||||||
throw InvalidItem();
|
throw InvalidItem();
|
||||||
return (*itsOptionsPtr)[i]->Item;
|
return (*itsOptionsPtr)[i]->Item;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T> Menu<T> *Menu<T>::EmptyClone() const
|
template <class T> NCurses::Menu<T> *NCurses::Menu<T>::EmptyClone() const
|
||||||
{
|
{
|
||||||
return new Menu<T>(GetStartX(), GetStartY(), GetWidth(), GetHeight(), itsTitle, itsBaseColor, itsBorder);
|
return new NCurses::Menu<T>(GetStartX(), GetStartY(), GetWidth(), GetHeight(), itsTitle, itsBaseColor, itsBorder);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
40
src/misc.cpp
40
src/misc.cpp
@@ -76,52 +76,52 @@ std::string IntoStr(mpd_TagItems tag) // this is only for left column's title in
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IntoStr(Color color)
|
std::string IntoStr(NCurses::Color color)
|
||||||
{
|
{
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
if (color == clDefault)
|
if (color == NCurses::clDefault)
|
||||||
result = "default";
|
result = "default";
|
||||||
else if (color == clBlack)
|
else if (color == NCurses::clBlack)
|
||||||
result = "black";
|
result = "black";
|
||||||
else if (color == clRed)
|
else if (color == NCurses::clRed)
|
||||||
result = "red";
|
result = "red";
|
||||||
else if (color == clGreen)
|
else if (color == NCurses::clGreen)
|
||||||
result = "green";
|
result = "green";
|
||||||
else if (color == clYellow)
|
else if (color == NCurses::clYellow)
|
||||||
result = "yellow";
|
result = "yellow";
|
||||||
else if (color == clBlue)
|
else if (color == NCurses::clBlue)
|
||||||
result = "blue";
|
result = "blue";
|
||||||
else if (color == clMagenta)
|
else if (color == NCurses::clMagenta)
|
||||||
result = "magenta";
|
result = "magenta";
|
||||||
else if (color == clCyan)
|
else if (color == NCurses::clCyan)
|
||||||
result = "cyan";
|
result = "cyan";
|
||||||
else if (color == clWhite)
|
else if (color == NCurses::clWhite)
|
||||||
result = "white";
|
result = "white";
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
Color IntoColor(const std::string &color)
|
NCurses::Color IntoColor(const std::string &color)
|
||||||
{
|
{
|
||||||
Color result = clDefault;
|
NCurses::Color result = NCurses::clDefault;
|
||||||
|
|
||||||
if (color == "black")
|
if (color == "black")
|
||||||
result = clBlack;
|
result = NCurses::clBlack;
|
||||||
else if (color == "red")
|
else if (color == "red")
|
||||||
result = clRed;
|
result = NCurses::clRed;
|
||||||
else if (color == "green")
|
else if (color == "green")
|
||||||
result = clGreen;
|
result = NCurses::clGreen;
|
||||||
else if (color == "yellow")
|
else if (color == "yellow")
|
||||||
result = clYellow;
|
result = NCurses::clYellow;
|
||||||
else if (color == "blue")
|
else if (color == "blue")
|
||||||
result = clBlue;
|
result = NCurses::clBlue;
|
||||||
else if (color == "magenta")
|
else if (color == "magenta")
|
||||||
result = clMagenta;
|
result = NCurses::clMagenta;
|
||||||
else if (color == "cyan")
|
else if (color == "cyan")
|
||||||
result = clCyan;
|
result = NCurses::clCyan;
|
||||||
else if (color == "white")
|
else if (color == "white")
|
||||||
result = clWhite;
|
result = NCurses::clWhite;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,9 +34,9 @@ std::string IntoStr(int);
|
|||||||
|
|
||||||
std::string IntoStr(mpd_TagItems);
|
std::string IntoStr(mpd_TagItems);
|
||||||
|
|
||||||
std::string IntoStr(Color);
|
std::string IntoStr(NCurses::Color);
|
||||||
|
|
||||||
Color IntoColor(const std::string &);
|
NCurses::Color IntoColor(const std::string &);
|
||||||
|
|
||||||
mpd_TagItems IntoTagItem(char);
|
mpd_TagItems IntoTagItem(char);
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,8 @@
|
|||||||
vFoundPositions.clear(); \
|
vFoundPositions.clear(); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
using namespace NCurses;
|
||||||
|
|
||||||
typedef std::pair<std::string, std::string> string_pair;
|
typedef std::pair<std::string, std::string> string_pair;
|
||||||
|
|
||||||
const int ncmpcpp_window_timeout = 500;
|
const int ncmpcpp_window_timeout = 500;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "scrollpad.h"
|
#include "scrollpad.h"
|
||||||
|
|
||||||
|
using namespace NCurses;
|
||||||
using std::string;
|
using std::string;
|
||||||
|
|
||||||
Scrollpad::Scrollpad(size_t startx,
|
Scrollpad::Scrollpad(size_t startx,
|
||||||
|
|||||||
@@ -24,49 +24,52 @@
|
|||||||
#include "window.h"
|
#include "window.h"
|
||||||
#include "strbuffer.h"
|
#include "strbuffer.h"
|
||||||
|
|
||||||
class Scrollpad: public Window
|
namespace NCurses
|
||||||
{
|
{
|
||||||
public:
|
class Scrollpad: public Window
|
||||||
Scrollpad(size_t, size_t, size_t, size_t, const std::string &, Color, Border);
|
{
|
||||||
Scrollpad(const Scrollpad &);
|
public:
|
||||||
virtual ~Scrollpad() { }
|
Scrollpad(size_t, size_t, size_t, size_t, const std::string &, Color, Border);
|
||||||
|
Scrollpad(const Scrollpad &);
|
||||||
|
virtual ~Scrollpad() { }
|
||||||
|
|
||||||
void Flush();
|
void Flush();
|
||||||
void SetFormatting(short, const std::basic_string<my_char_t> &, short, bool for_each = 1);
|
void SetFormatting(short, const std::basic_string<my_char_t> &, short, bool for_each = 1);
|
||||||
std::basic_string<my_char_t> Content() { return itsBuffer.Str(); }
|
std::basic_string<my_char_t> Content() { return itsBuffer.Str(); }
|
||||||
|
|
||||||
virtual void Refresh();
|
virtual void Refresh();
|
||||||
virtual void Scroll(Where);
|
virtual void Scroll(Where);
|
||||||
|
|
||||||
virtual void Resize(size_t, size_t);
|
virtual void Resize(size_t, size_t);
|
||||||
virtual void Clear(bool = 1);
|
virtual void Clear(bool = 1);
|
||||||
|
|
||||||
template <class T> Scrollpad &operator<<(const T &t)
|
template <class T> Scrollpad &operator<<(const T &t)
|
||||||
{
|
{
|
||||||
itsBuffer << t;
|
itsBuffer << t;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scrollpad &operator<<(std::ostream &(*os)(std::ostream &));
|
Scrollpad &operator<<(std::ostream &(*os)(std::ostream &));
|
||||||
|
|
||||||
# ifdef _UTF8
|
# ifdef _UTF8
|
||||||
void SetFormatting(short vb, const std::string &s, short ve, bool for_each = 1) { SetFormatting(vb, ToWString(s), ve, for_each); }
|
void SetFormatting(short vb, const std::string &s, short ve, bool for_each = 1) { SetFormatting(vb, ToWString(s), ve, for_each); }
|
||||||
Scrollpad &operator<<(const char *s);
|
Scrollpad &operator<<(const char *s);
|
||||||
Scrollpad &operator<<(const std::string &s);
|
Scrollpad &operator<<(const std::string &s);
|
||||||
# endif // _UTF8
|
# endif // _UTF8
|
||||||
|
|
||||||
virtual Scrollpad *Clone() const { return new Scrollpad(*this); }
|
virtual Scrollpad *Clone() const { return new Scrollpad(*this); }
|
||||||
virtual Scrollpad *EmptyClone() const;
|
virtual Scrollpad *EmptyClone() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Recreate();
|
virtual void Recreate();
|
||||||
|
|
||||||
basic_buffer<my_char_t> itsBuffer;
|
basic_buffer<my_char_t> itsBuffer;
|
||||||
|
|
||||||
int itsBeginning;
|
int itsBeginning;
|
||||||
|
|
||||||
size_t itsRealHeight;
|
size_t itsRealHeight;
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
105
src/strbuffer.h
105
src/strbuffer.h
@@ -26,54 +26,57 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
template <class C> class basic_buffer
|
namespace NCurses
|
||||||
{
|
{
|
||||||
struct FormatPos
|
template <class C> class basic_buffer
|
||||||
{
|
{
|
||||||
size_t Position;
|
struct FormatPos
|
||||||
short Value;
|
|
||||||
|
|
||||||
bool operator<(const FormatPos &f)
|
|
||||||
{
|
{
|
||||||
return Position < f.Position;
|
size_t Position;
|
||||||
}
|
short Value;
|
||||||
|
|
||||||
|
bool operator<(const FormatPos &f)
|
||||||
|
{
|
||||||
|
return Position < f.Position;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::basic_ostringstream<C> itsString;
|
||||||
|
std::list<FormatPos> itsFormat;
|
||||||
|
std::basic_string<C> *itsTempString;
|
||||||
|
|
||||||
|
public:
|
||||||
|
basic_buffer() : itsTempString(0) { }
|
||||||
|
|
||||||
|
std::basic_string<C> Str() const;
|
||||||
|
void SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each = 1);
|
||||||
|
void SetTemp(std::basic_string<C> *);
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
template <class T> basic_buffer<C> &operator<<(const T &t)
|
||||||
|
{
|
||||||
|
itsString << t;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
basic_buffer<C> &operator<<(std::ostream &(*os)(std::ostream &));
|
||||||
|
basic_buffer<C> &operator<<(const Color &color);
|
||||||
|
basic_buffer<C> &operator<<(const Format &f);
|
||||||
|
basic_buffer<C> &operator<<(const basic_buffer<C> &buf);
|
||||||
|
|
||||||
|
friend Window &operator<< <>(Window &, const basic_buffer<C> &);
|
||||||
};
|
};
|
||||||
|
|
||||||
std::basic_ostringstream<C> itsString;
|
typedef basic_buffer<char> Buffer;
|
||||||
std::list<FormatPos> itsFormat;
|
typedef basic_buffer<wchar_t> WBuffer;
|
||||||
std::basic_string<C> *itsTempString;
|
}
|
||||||
|
|
||||||
public:
|
template <class C> std::basic_string<C> NCurses::basic_buffer<C>::Str() const
|
||||||
basic_buffer() : itsTempString(0) { }
|
|
||||||
|
|
||||||
std::basic_string<C> Str() const;
|
|
||||||
void SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each = 1);
|
|
||||||
void SetTemp(std::basic_string<C> *);
|
|
||||||
void Clear();
|
|
||||||
|
|
||||||
template <class T> basic_buffer<C> &operator<<(const T &t)
|
|
||||||
{
|
|
||||||
itsString << t;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
basic_buffer<C> &operator<<(std::ostream &(*os)(std::ostream &));
|
|
||||||
basic_buffer<C> &operator<<(const Color &color);
|
|
||||||
basic_buffer<C> &operator<<(const Format &f);
|
|
||||||
basic_buffer<C> &operator<<(const basic_buffer<C> &buf);
|
|
||||||
|
|
||||||
friend Window &operator<< <>(Window &, const basic_buffer<C> &);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef basic_buffer<char> Buffer;
|
|
||||||
typedef basic_buffer<wchar_t> WBuffer;
|
|
||||||
|
|
||||||
template <class C> std::basic_string<C> basic_buffer<C>::Str() const
|
|
||||||
{
|
{
|
||||||
return itsString.str();
|
return itsString.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> void basic_buffer<C>::SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each)
|
template <class C> void NCurses::basic_buffer<C>::SetFormatting(short vb, const std::basic_string<C> &s, short ve, bool for_each)
|
||||||
{
|
{
|
||||||
std::basic_string<C> base = itsString.str();
|
std::basic_string<C> base = itsString.str();
|
||||||
FormatPos fp;
|
FormatPos fp;
|
||||||
@@ -92,24 +95,24 @@ template <class C> void basic_buffer<C>::SetFormatting(short vb, const std::basi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> void basic_buffer<C>::SetTemp(std::basic_string<C> *tmp)
|
template <class C> void NCurses::basic_buffer<C>::SetTemp(std::basic_string<C> *tmp)
|
||||||
{
|
{
|
||||||
itsTempString = tmp;
|
itsTempString = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> void basic_buffer<C>::Clear()
|
template <class C> void NCurses::basic_buffer<C>::Clear()
|
||||||
{
|
{
|
||||||
itsString.str(std::basic_string<C>());
|
itsString.str(std::basic_string<C>());
|
||||||
itsFormat.clear();
|
itsFormat.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> basic_buffer<C> &basic_buffer<C>::operator<<(std::ostream &(*os)(std::ostream&))
|
template <class C> NCurses::basic_buffer<C> &NCurses::basic_buffer<C>::operator<<(std::ostream &(*os)(std::ostream&))
|
||||||
{
|
{
|
||||||
itsString << os;
|
itsString << os;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> basic_buffer<C> &basic_buffer<C>::operator<<(const Color &color)
|
template <class C> NCurses::basic_buffer<C> &NCurses::basic_buffer<C>::operator<<(const Color &color)
|
||||||
{
|
{
|
||||||
FormatPos f;
|
FormatPos f;
|
||||||
f.Position = itsString.str().length();
|
f.Position = itsString.str().length();
|
||||||
@@ -118,24 +121,24 @@ template <class C> basic_buffer<C> &basic_buffer<C>::operator<<(const Color &col
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> basic_buffer<C> &basic_buffer<C>::operator<<(const Format &f)
|
template <class C> NCurses::basic_buffer<C> &NCurses::basic_buffer<C>::operator<<(const Format &f)
|
||||||
{
|
{
|
||||||
return operator<<(Color(f));
|
return operator<<(Color(f));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> basic_buffer<C> &basic_buffer<C>::operator<<(const basic_buffer<C> &buf)
|
template <class C> NCurses::basic_buffer<C> &NCurses::basic_buffer<C>::operator<<(const NCurses::basic_buffer<C> &buf)
|
||||||
{
|
{
|
||||||
size_t len = itsString.str().length();
|
size_t len = itsString.str().length();
|
||||||
itsString << buf.itsString.str();
|
itsString << buf.itsString.str();
|
||||||
std::list<FormatPos> tmp = buf.itsFormat;
|
std::list<FormatPos> tmp = buf.itsFormat;
|
||||||
if (len)
|
if (len)
|
||||||
for (typename std::list<typename basic_buffer<C>::FormatPos>::iterator it = tmp.begin(); it != tmp.end(); it++)
|
for (typename std::list<typename NCurses::basic_buffer<C>::FormatPos>::iterator it = tmp.begin(); it != tmp.end(); it++)
|
||||||
it->Position += len;
|
it->Position += len;
|
||||||
itsFormat.merge(tmp);
|
itsFormat.merge(tmp);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class C> Window &operator<<(Window &w, const basic_buffer<C> &buf)
|
template <class C> NCurses::Window &operator<<(NCurses::Window &w, const NCurses::basic_buffer<C> &buf)
|
||||||
{
|
{
|
||||||
const std::basic_string<C> &s = buf.itsTempString ? *buf.itsTempString : buf.itsString.str();
|
const std::basic_string<C> &s = buf.itsTempString ? *buf.itsTempString : buf.itsString.str();
|
||||||
if (buf.itsFormat.empty())
|
if (buf.itsFormat.empty())
|
||||||
@@ -145,8 +148,8 @@ template <class C> Window &operator<<(Window &w, const basic_buffer<C> &buf)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::basic_string<C> tmp;
|
std::basic_string<C> tmp;
|
||||||
typename std::list<typename basic_buffer<C>::FormatPos>::const_iterator b = buf.itsFormat.begin();
|
typename std::list<typename NCurses::basic_buffer<C>::FormatPos>::const_iterator b = buf.itsFormat.begin();
|
||||||
typename std::list<typename basic_buffer<C>::FormatPos>::const_iterator e = buf.itsFormat.end();
|
typename std::list<typename NCurses::basic_buffer<C>::FormatPos>::const_iterator e = buf.itsFormat.end();
|
||||||
for (size_t i = 0; i < s.length() || b != e; i++)
|
for (size_t i = 0; i < s.length() || b != e; i++)
|
||||||
{
|
{
|
||||||
while (b != e && i == b->Position)
|
while (b != e && i == b->Position)
|
||||||
@@ -156,10 +159,10 @@ template <class C> Window &operator<<(Window &w, const basic_buffer<C> &buf)
|
|||||||
w << tmp;
|
w << tmp;
|
||||||
tmp.clear();
|
tmp.clear();
|
||||||
}
|
}
|
||||||
if (b->Value < fmtNone)
|
if (b->Value < NCurses::fmtNone)
|
||||||
w << Color(b->Value);
|
w << NCurses::Color(b->Value);
|
||||||
else
|
else
|
||||||
w << Format(b->Value);
|
w << NCurses::Format(b->Value);
|
||||||
b++;
|
b++;
|
||||||
}
|
}
|
||||||
if (i < s.length())
|
if (i < s.length())
|
||||||
|
|||||||
@@ -23,10 +23,12 @@
|
|||||||
|
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
|
using namespace NCurses;
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::wstring;
|
using std::wstring;
|
||||||
|
|
||||||
void InitScreen(bool enable_colors)
|
void NCurses::InitScreen(bool enable_colors)
|
||||||
{
|
{
|
||||||
setlocale(LC_ALL, "");
|
setlocale(LC_ALL, "");
|
||||||
initscr();
|
initscr();
|
||||||
@@ -44,7 +46,7 @@ void InitScreen(bool enable_colors)
|
|||||||
curs_set(0);
|
curs_set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DestroyScreen()
|
void NCurses::DestroyScreen()
|
||||||
{
|
{
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
endwin();
|
endwin();
|
||||||
|
|||||||
211
src/window.h
211
src/window.h
@@ -41,140 +41,143 @@
|
|||||||
# define TO_WSTRING(x) x
|
# define TO_WSTRING(x) x
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum Color { clDefault, clBlack, clRed, clGreen, clYellow, clBlue, clMagenta, clCyan, clWhite, clEnd };
|
|
||||||
enum Format { fmtNone = 100, fmtBold, fmtBoldEnd, fmtReverse, fmtReverseEnd, fmtAltCharset, fmtAltCharsetEnd };
|
|
||||||
enum Border { brNone, brBlack, brRed, brGreen, brYellow, brBlue, brMagenta, brCyan, brWhite };
|
|
||||||
enum Where { wUp, wDown, wPageUp, wPageDown, wHome, wEnd };
|
|
||||||
|
|
||||||
typedef void (*GetStringHelper)(const std::wstring &);
|
|
||||||
|
|
||||||
void InitScreen(bool);
|
|
||||||
void DestroyScreen();
|
|
||||||
|
|
||||||
struct Colors
|
|
||||||
{
|
|
||||||
Colors(Color one, Color two = clDefault) : fg(one), bg(two) { }
|
|
||||||
Color fg;
|
|
||||||
Color bg;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct XY
|
|
||||||
{
|
|
||||||
XY(int xx, int yy) : x(xx), y(yy) { }
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
};
|
|
||||||
|
|
||||||
char *ToString(const wchar_t *);
|
char *ToString(const wchar_t *);
|
||||||
wchar_t *ToWString(const char *);
|
wchar_t *ToWString(const char *);
|
||||||
std::string ToString(const std::wstring &);
|
std::string ToString(const std::wstring &);
|
||||||
std::wstring ToWString(const std::string &);
|
std::wstring ToWString(const std::string &);
|
||||||
|
|
||||||
class Window
|
namespace NCurses
|
||||||
{
|
{
|
||||||
public:
|
enum Color { clDefault, clBlack, clRed, clGreen, clYellow, clBlue, clMagenta, clCyan, clWhite, clEnd };
|
||||||
Window(size_t, size_t, size_t, size_t, const std::string &, Color, Border);
|
enum Format { fmtNone = 100, fmtBold, fmtBoldEnd, fmtReverse, fmtReverseEnd, fmtAltCharset, fmtAltCharsetEnd };
|
||||||
Window(const Window &);
|
enum Border { brNone, brBlack, brRed, brGreen, brYellow, brBlue, brMagenta, brCyan, brWhite };
|
||||||
virtual ~Window();
|
enum Where { wUp, wDown, wPageUp, wPageDown, wHome, wEnd };
|
||||||
|
|
||||||
WINDOW *Raw() const { return itsWindow; }
|
typedef void (*GetStringHelper)(const std::wstring &);
|
||||||
|
|
||||||
size_t GetWidth() const;
|
void InitScreen(bool);
|
||||||
size_t GetHeight() const;
|
void DestroyScreen();
|
||||||
size_t GetStartX() const;
|
|
||||||
size_t GetStartY() const;
|
|
||||||
|
|
||||||
const std::string &GetTitle() const;
|
struct Colors
|
||||||
Color GetColor() const;
|
{
|
||||||
Border GetBorder() const;
|
Colors(Color one, Color two = clDefault) : fg(one), bg(two) { }
|
||||||
std::string GetString(const std::string &, size_t = -1, size_t = 0, bool = 0) const;
|
Color fg;
|
||||||
std::string GetString(size_t length = -1, size_t width = 0, bool encrypted = 0) const { return GetString("", length, width, encrypted); }
|
Color bg;
|
||||||
void GetXY(int &, int &);
|
};
|
||||||
void GotoXY(int, int);
|
|
||||||
const int &X() const;
|
|
||||||
const int &Y() const;
|
|
||||||
|
|
||||||
void SetGetStringHelper(GetStringHelper helper) { itsGetStringHelper = helper; }
|
struct XY
|
||||||
void SetColor(Color, Color = clDefault);
|
{
|
||||||
void SetBaseColor(Color, Color = clDefault);
|
XY(int xx, int yy) : x(xx), y(yy) { }
|
||||||
void SetBorder(Border);
|
int x;
|
||||||
void SetTimeout(int);
|
int y;
|
||||||
void SetTitle(const std::string &);
|
};
|
||||||
|
|
||||||
void Hide(char = 32) const;
|
class Window
|
||||||
void Bold(bool) const;
|
{
|
||||||
void Reverse(bool) const;
|
public:
|
||||||
void AltCharset(bool) const;
|
Window(size_t, size_t, size_t, size_t, const std::string &, Color, Border);
|
||||||
|
Window(const Window &);
|
||||||
|
virtual ~Window();
|
||||||
|
|
||||||
void Display();
|
WINDOW *Raw() const { return itsWindow; }
|
||||||
virtual void Refresh();
|
|
||||||
|
|
||||||
virtual void MoveTo(size_t, size_t);
|
size_t GetWidth() const;
|
||||||
virtual void Resize(size_t, size_t);
|
size_t GetHeight() const;
|
||||||
virtual void Clear(bool = 1);
|
size_t GetStartX() const;
|
||||||
|
size_t GetStartY() const;
|
||||||
|
|
||||||
void ReadKey(int &) const;
|
const std::string &GetTitle() const;
|
||||||
void ReadKey() const;
|
Color GetColor() const;
|
||||||
|
Border GetBorder() const;
|
||||||
|
std::string GetString(const std::string &, size_t = -1, size_t = 0, bool = 0) const;
|
||||||
|
std::string GetString(size_t length = -1, size_t width = 0, bool encrypted = 0) const { return GetString("", length, width, encrypted); }
|
||||||
|
void GetXY(int &, int &);
|
||||||
|
void GotoXY(int, int);
|
||||||
|
const int &X() const;
|
||||||
|
const int &Y() const;
|
||||||
|
|
||||||
//void Write(bool, const char *, ...) const;
|
void SetGetStringHelper(GetStringHelper helper) { itsGetStringHelper = helper; }
|
||||||
//void WriteXY(int, int, bool, const char *, ...) const;
|
void SetColor(Color, Color = clDefault);
|
||||||
|
void SetBaseColor(Color, Color = clDefault);
|
||||||
|
void SetBorder(Border);
|
||||||
|
void SetTimeout(int);
|
||||||
|
void SetTitle(const std::string &);
|
||||||
|
|
||||||
void Scrollable(bool) const;
|
void Hide(char = 32) const;
|
||||||
virtual void Scroll(Where);
|
void Bold(bool) const;
|
||||||
|
void Reverse(bool) const;
|
||||||
|
void AltCharset(bool) const;
|
||||||
|
|
||||||
Window &operator<<(int (*)(WINDOW *));
|
void Display();
|
||||||
Window &operator<<(const Colors &);
|
virtual void Refresh();
|
||||||
Window &operator<<(const Color &);
|
|
||||||
Window &operator<<(const Format &);
|
|
||||||
Window &operator<<(const XY &);
|
|
||||||
Window &operator<<(const char *);
|
|
||||||
Window &operator<<(const char &);
|
|
||||||
Window &operator<<(const wchar_t *);
|
|
||||||
Window &operator<<(const wchar_t &);
|
|
||||||
Window &operator<<(const int &);
|
|
||||||
Window &operator<<(const double &);
|
|
||||||
Window &operator<<(const size_t &);
|
|
||||||
|
|
||||||
Window &operator<<(const std::string &);
|
virtual void MoveTo(size_t, size_t);
|
||||||
Window &operator<<(const std::wstring &);
|
virtual void Resize(size_t, size_t);
|
||||||
|
virtual void Clear(bool = 1);
|
||||||
|
|
||||||
virtual Window *Clone() const { return new Window(*this); }
|
void ReadKey(int &) const;
|
||||||
virtual Window *EmptyClone() const;
|
void ReadKey() const;
|
||||||
|
|
||||||
static size_t Length(const std::wstring &);
|
//void Write(bool, const char *, ...) const;
|
||||||
|
//void WriteXY(int, int, bool, const char *, ...) const;
|
||||||
|
|
||||||
protected:
|
void Scrollable(bool) const;
|
||||||
|
virtual void Scroll(Where);
|
||||||
|
|
||||||
class BadSize { };
|
Window &operator<<(int (*)(WINDOW *));
|
||||||
|
Window &operator<<(const Colors &);
|
||||||
|
Window &operator<<(const Color &);
|
||||||
|
Window &operator<<(const Format &);
|
||||||
|
Window &operator<<(const XY &);
|
||||||
|
Window &operator<<(const char *);
|
||||||
|
Window &operator<<(const char &);
|
||||||
|
Window &operator<<(const wchar_t *);
|
||||||
|
Window &operator<<(const wchar_t &);
|
||||||
|
Window &operator<<(const int &);
|
||||||
|
Window &operator<<(const double &);
|
||||||
|
Window &operator<<(const size_t &);
|
||||||
|
|
||||||
void ShowBorder() const;
|
Window &operator<<(const std::string &);
|
||||||
void AdjustDimensions(size_t &, size_t &);
|
Window &operator<<(const std::wstring &);
|
||||||
|
|
||||||
virtual void Recreate();
|
virtual Window *Clone() const { return new Window(*this); }
|
||||||
|
virtual Window *EmptyClone() const;
|
||||||
|
|
||||||
WINDOW *itsWindow;
|
static size_t Length(const std::wstring &);
|
||||||
WINDOW *itsWinBorder;
|
|
||||||
|
|
||||||
GetStringHelper itsGetStringHelper;
|
protected:
|
||||||
|
|
||||||
size_t itsStartX;
|
class BadSize { };
|
||||||
size_t itsStartY;
|
|
||||||
size_t itsWidth;
|
|
||||||
size_t itsHeight;
|
|
||||||
|
|
||||||
int itsWindowTimeout;
|
void ShowBorder() const;
|
||||||
int itsX;
|
void AdjustDimensions(size_t &, size_t &);
|
||||||
int itsY;
|
|
||||||
|
|
||||||
std::string itsTitle;
|
virtual void Recreate();
|
||||||
std::stack<Colors> itsColors;
|
|
||||||
|
|
||||||
Color itsColor;
|
WINDOW *itsWindow;
|
||||||
Color itsBaseColor;
|
WINDOW *itsWinBorder;
|
||||||
Color itsBgColor;
|
|
||||||
Color itsBaseBgColor;
|
|
||||||
|
|
||||||
Border itsBorder;
|
GetStringHelper itsGetStringHelper;
|
||||||
};
|
|
||||||
|
size_t itsStartX;
|
||||||
|
size_t itsStartY;
|
||||||
|
size_t itsWidth;
|
||||||
|
size_t itsHeight;
|
||||||
|
|
||||||
|
int itsWindowTimeout;
|
||||||
|
int itsX;
|
||||||
|
int itsY;
|
||||||
|
|
||||||
|
std::string itsTitle;
|
||||||
|
std::stack<Colors> itsColors;
|
||||||
|
|
||||||
|
Color itsColor;
|
||||||
|
Color itsBaseColor;
|
||||||
|
Color itsBgColor;
|
||||||
|
Color itsBaseBgColor;
|
||||||
|
|
||||||
|
Border itsBorder;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user