menu: normalize indentation

This commit is contained in:
Andrzej Rybczak
2012-08-30 20:23:58 +02:00
parent 7e53654492
commit 74f0864824
2 changed files with 625 additions and 623 deletions

View File

@@ -20,7 +20,7 @@
#include "menu.h"
using namespace NCurses;
namespace NCurses {
template <> std::string Menu<std::string>::GetItem(size_t pos)
{
@@ -34,3 +34,5 @@ template <> std::string Menu<std::string>::GetItem(size_t pos)
}
return result;
}
}

View File

@@ -30,13 +30,12 @@
#include "window.h"
#include "strbuffer.h"
namespace NCurses
{
namespace NCurses {
/// List class is an interface for Menu class
///
class List
struct List
{
public:
/// @see Menu::Select()
///
virtual void Select(int pos, bool state) = 0;
@@ -604,9 +603,8 @@ namespace NCurses
/// that if strings are stored, we don't need extra function to convert
/// them to strings by default
template <> std::string Menu<std::string>::GetItem(size_t pos);
}
template <typename T> NCurses::Menu<T>::Menu(size_t startx,
template <typename T> Menu<T>::Menu(size_t startx,
size_t starty,
size_t width,
size_t height,
@@ -628,7 +626,7 @@ template <typename T> NCurses::Menu<T>::Menu(size_t startx,
{
}
template <typename T> NCurses::Menu<T>::Menu(const Menu &m) : Window(m),
template <typename T> Menu<T>::Menu(const Menu &m) : Window(m),
m_item_displayer(m.m_item_displayer),
m_get_string_helper(m.m_get_string_helper),
m_options_ptr(m.m_options_ptr),
@@ -646,18 +644,18 @@ template <typename T> NCurses::Menu<T>::Menu(const Menu &m) : Window(m),
m_options.push_back(new Item(**it));
}
template <typename T> NCurses::Menu<T>::~Menu()
template <typename T> Menu<T>::~Menu()
{
for (auto it = m_options.begin(); it != m_options.end(); ++it)
delete *it;
}
template <typename T> void NCurses::Menu<T>::Reserve(size_t size)
template <typename T> void Menu<T>::Reserve(size_t size)
{
m_options.reserve(size);
}
template <typename T> void NCurses::Menu<T>::ResizeList(size_t size)
template <typename T> void Menu<T>::ResizeList(size_t size)
{
if (size > m_options.size())
{
@@ -674,27 +672,27 @@ template <typename T> void NCurses::Menu<T>::ResizeList(size_t size)
}
}
template <typename T> void NCurses::Menu<T>::AddItem(const T &item, bool is_bold, bool is_static)
template <typename T> void Menu<T>::AddItem(const T &item, bool is_bold, bool is_static)
{
m_options.push_back(new Item(item, is_bold, is_static));
}
template <typename T> void NCurses::Menu<T>::AddSeparator()
template <typename T> void Menu<T>::AddSeparator()
{
m_options.push_back(static_cast<Item *>(0));
}
template <typename T> void NCurses::Menu<T>::InsertItem(size_t pos, const T &item, bool is_bold, bool is_static)
template <typename T> void Menu<T>::InsertItem(size_t pos, const T &item, bool is_bold, bool is_static)
{
m_options.insert(m_options.begin()+pos, new Item(item, is_bold, is_static));
}
template <typename T> void NCurses::Menu<T>::InsertSeparator(size_t pos)
template <typename T> void Menu<T>::InsertSeparator(size_t pos)
{
m_options.insert(m_options.begin()+pos, 0);
}
template <typename T> void NCurses::Menu<T>::DeleteItem(size_t pos)
template <typename T> void Menu<T>::DeleteItem(size_t pos)
{
if (m_options_ptr->empty())
return;
@@ -717,25 +715,25 @@ template <typename T> void NCurses::Menu<T>::DeleteItem(size_t pos)
Window::Clear();
}
template <typename T> void NCurses::Menu<T>::IntoSeparator(size_t pos)
template <typename T> void Menu<T>::IntoSeparator(size_t pos)
{
delete m_options_ptr->at(pos);
(*m_options_ptr)[pos] = 0;
}
template <typename T> void NCurses::Menu<T>::Bold(int pos, bool state)
template <typename T> void Menu<T>::Bold(int pos, bool state)
{
if (!m_options_ptr->at(pos))
return;
(*m_options_ptr)[pos]->isBold = state;
}
template <typename T> void NCurses::Menu<T>::Swap(size_t one, size_t two)
template <typename T> void Menu<T>::Swap(size_t one, size_t two)
{
std::swap(m_options.at(one), m_options.at(two));
}
template <typename T> void NCurses::Menu<T>::Move(size_t from, size_t to)
template <typename T> void Menu<T>::Move(size_t from, size_t to)
{
int diff = from-to;
if (diff > 0)
@@ -750,7 +748,7 @@ template <typename T> void NCurses::Menu<T>::Move(size_t from, size_t to)
}
}
template <typename T> bool NCurses::Menu<T>::Goto(size_t y)
template <typename T> bool Menu<T>::Goto(size_t y)
{
if (!m_options_ptr->at(itsBeginning+y) || m_options_ptr->at(itsBeginning+y)->isStatic)
return false;
@@ -758,7 +756,7 @@ template <typename T> bool NCurses::Menu<T>::Goto(size_t y)
return true;
}
template <typename T> void NCurses::Menu<T>::Refresh()
template <typename T> void Menu<T>::Refresh()
{
if (m_options_ptr->empty())
{
@@ -826,7 +824,7 @@ template <typename T> void NCurses::Menu<T>::Refresh()
Window::Refresh();
}
template <typename T> void NCurses::Menu<T>::Scroll(Where where)
template <typename T> void Menu<T>::Scroll(Where where)
{
if (m_options_ptr->empty())
return;
@@ -940,20 +938,20 @@ template <typename T> void NCurses::Menu<T>::Scroll(Where where)
Highlight(itsHighlight);
}
template <typename T> void NCurses::Menu<T>::Reset()
template <typename T> void Menu<T>::Reset()
{
itsHighlight = 0;
itsBeginning = 0;
}
template <typename T> void NCurses::Menu<T>::ClearFiltered()
template <typename T> void Menu<T>::ClearFiltered()
{
m_filtered_options.clear();
m_filtered_positions.clear();
m_options_ptr = &m_options;
}
template <typename T> void NCurses::Menu<T>::Clear()
template <typename T> void Menu<T>::Clear()
{
for (auto it = m_options.begin(); it != m_options.end(); ++it)
delete *it;
@@ -965,7 +963,7 @@ template <typename T> void NCurses::Menu<T>::Clear()
Window::Clear();
}
template <typename T> bool NCurses::Menu<T>::isBold(int pos)
template <typename T> bool Menu<T>::isBold(int pos)
{
pos = pos == -1 ? itsHighlight : pos;
if (!m_options_ptr->at(pos))
@@ -973,21 +971,21 @@ template <typename T> bool NCurses::Menu<T>::isBold(int pos)
return (*m_options_ptr)[pos]->isBold;
}
template <typename T> void NCurses::Menu<T>::Select(int pos, bool state)
template <typename T> void Menu<T>::Select(int pos, bool state)
{
if (!m_options_ptr->at(pos))
return;
(*m_options_ptr)[pos]->isSelected = state;
}
template <typename T> void NCurses::Menu<T>::Static(int pos, bool state)
template <typename T> void Menu<T>::Static(int pos, bool state)
{
if (!m_options_ptr->at(pos))
return;
(*m_options_ptr)[pos]->isStatic = state;
}
template <typename T> bool NCurses::Menu<T>::isSelected(int pos) const
template <typename T> bool Menu<T>::isSelected(int pos) const
{
pos = pos == -1 ? itsHighlight : pos;
if (!m_options_ptr->at(pos))
@@ -995,7 +993,7 @@ template <typename T> bool NCurses::Menu<T>::isSelected(int pos) const
return (*m_options_ptr)[pos]->isSelected;
}
template <typename T> bool NCurses::Menu<T>::isStatic(int pos) const
template <typename T> bool Menu<T>::isStatic(int pos) const
{
pos = pos == -1 ? itsHighlight : pos;
if (!m_options_ptr->at(pos))
@@ -1003,13 +1001,13 @@ template <typename T> bool NCurses::Menu<T>::isStatic(int pos) const
return (*m_options_ptr)[pos]->isStatic;
}
template <typename T> bool NCurses::Menu<T>::isSeparator(int pos) const
template <typename T> bool Menu<T>::isSeparator(int pos) const
{
pos = pos == -1 ? itsHighlight : pos;
return !m_options_ptr->at(pos);
}
template <typename T> bool NCurses::Menu<T>::hasSelected() const
template <typename T> bool Menu<T>::hasSelected() const
{
for (auto it = m_options_ptr->begin(); it != m_options_ptr->end(); ++it)
if (*it && (*it)->isSelected)
@@ -1017,30 +1015,30 @@ template <typename T> bool NCurses::Menu<T>::hasSelected() const
return false;
}
template <typename T> void NCurses::Menu<T>::GetSelected(std::vector<size_t> &v) const
template <typename T> void Menu<T>::GetSelected(std::vector<size_t> &v) const
{
for (size_t i = 0; i < m_options_ptr->size(); ++i)
if ((*m_options_ptr)[i] && (*m_options_ptr)[i]->isSelected)
v.push_back(i);
}
template <typename T> void NCurses::Menu<T>::Highlight(size_t pos)
template <typename T> void Menu<T>::Highlight(size_t pos)
{
itsHighlight = pos;
itsBeginning = pos-itsHeight/2;
}
template <typename T> size_t NCurses::Menu<T>::Size() const
template <typename T> size_t Menu<T>::Size() const
{
return m_options_ptr->size();
}
template <typename T> size_t NCurses::Menu<T>::Choice() const
template <typename T> size_t Menu<T>::Choice() const
{
return itsHighlight;
}
template <typename T> size_t NCurses::Menu<T>::RealChoice() const
template <typename T> size_t Menu<T>::RealChoice() const
{
size_t result = 0;
for (auto it = m_options_ptr->begin(); it != m_options_ptr->begin()+itsHighlight; ++it)
@@ -1049,7 +1047,7 @@ template <typename T> size_t NCurses::Menu<T>::RealChoice() const
return result;
}
template <typename T> void NCurses::Menu<T>::ReverseSelection(size_t beginning)
template <typename T> void Menu<T>::ReverseSelection(size_t beginning)
{
auto it = m_options_ptr->begin()+beginning;
for (size_t i = beginning; i < Size(); ++i, ++it)
@@ -1057,7 +1055,7 @@ template <typename T> void NCurses::Menu<T>::ReverseSelection(size_t beginning)
(*it)->isSelected = !(*it)->isSelected && !(*it)->isStatic;
}
template <typename T> bool NCurses::Menu<T>::Search(const std::string &constraint, size_t beginning, int flags)
template <typename T> bool Menu<T>::Search(const std::string &constraint, size_t beginning, int flags)
{
m_found_positions.clear();
m_search_constraint.clear();
@@ -1077,7 +1075,7 @@ template <typename T> bool NCurses::Menu<T>::Search(const std::string &constrain
return !m_found_positions.empty();
}
template <typename T> void NCurses::Menu<T>::NextFound(bool wrap)
template <typename T> void Menu<T>::NextFound(bool wrap)
{
if (m_found_positions.empty())
return;
@@ -1088,7 +1086,7 @@ template <typename T> void NCurses::Menu<T>::NextFound(bool wrap)
Highlight(*m_found_positions.begin());
}
template <typename T> void NCurses::Menu<T>::PrevFound(bool wrap)
template <typename T> void Menu<T>::PrevFound(bool wrap)
{
if (m_found_positions.empty())
return;
@@ -1099,7 +1097,7 @@ template <typename T> void NCurses::Menu<T>::PrevFound(bool wrap)
Highlight(*m_found_positions.rbegin());
}
template <typename T> void NCurses::Menu<T>::ApplyFilter(const std::string &filter, size_t beginning, int flags)
template <typename T> void Menu<T>::ApplyFilter(const std::string &filter, size_t beginning, int flags)
{
m_found_positions.clear();
ClearFiltered();
@@ -1129,12 +1127,12 @@ template <typename T> void NCurses::Menu<T>::ApplyFilter(const std::string &filt
Window::Clear();
}
template <typename T> const std::string &NCurses::Menu<T>::GetFilter()
template <typename T> const std::string &Menu<T>::GetFilter()
{
return m_filter;
}
template <typename T> std::string NCurses::Menu<T>::GetItem(size_t pos)
template <typename T> std::string Menu<T>::GetItem(size_t pos)
{
if (m_options_ptr->at(pos) && m_get_string_helper)
return m_get_string_helper((*m_options_ptr)[pos]->Value);
@@ -1142,61 +1140,63 @@ template <typename T> std::string NCurses::Menu<T>::GetItem(size_t pos)
return "";
}
template <typename T> T &NCurses::Menu<T>::Back()
template <typename T> T &Menu<T>::Back()
{
if (!m_options_ptr->back())
FatalError("Menu::Back() has requested separator!");
return m_options_ptr->back()->Value;
}
template <typename T> const T &NCurses::Menu<T>::Back() const
template <typename T> const T &Menu<T>::Back() const
{
if (!m_options_ptr->back())
FatalError("Menu::Back() has requested separator!");
return m_options_ptr->back()->Value;
}
template <typename T> T &NCurses::Menu<T>::Current()
template <typename T> T &Menu<T>::Current()
{
if (!m_options_ptr->at(itsHighlight))
FatalError("Menu::Current() has requested separator!");
return (*m_options_ptr)[itsHighlight]->Value;
}
template <typename T> const T &NCurses::Menu<T>::Current() const
template <typename T> const T &Menu<T>::Current() const
{
if (!m_options_ptr->at(itsHighlight))
FatalError("Menu::Current() const has requested separator!");
return (*m_options_ptr)[itsHighlight]->Value;
}
template <typename T> T &NCurses::Menu<T>::at(size_t pos)
template <typename T> T &Menu<T>::at(size_t pos)
{
if (!m_options_ptr->at(pos))
FatalError("Menu::at() has requested separator!");
return (*m_options_ptr)[pos]->Value;
}
template <typename T> const T &NCurses::Menu<T>::at(size_t pos) const
template <typename T> const T &Menu<T>::at(size_t pos) const
{
if (!m_options->at(pos))
FatalError("Menu::at() const has requested separator!");
return (*m_options_ptr)[pos]->Value;
}
template <typename T> const T &NCurses::Menu<T>::operator[](size_t pos) const
template <typename T> const T &Menu<T>::operator[](size_t pos) const
{
if (!(*m_options_ptr)[pos])
FatalError("Menu::operator[] const has requested separator!");
return (*m_options_ptr)[pos]->Value;
}
template <typename T> T &NCurses::Menu<T>::operator[](size_t pos)
template <typename T> T &Menu<T>::operator[](size_t pos)
{
if (!(*m_options_ptr)[pos])
FatalError("Menu::operator[] has requested separator!");
return (*m_options_ptr)[pos]->Value;
}
}
#endif