2006-04-26 13:34:35 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file TocBackend.h
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Jean-Marc Lasgouttes
|
|
|
|
* \author Angus Leeming
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*
|
|
|
|
* TocBackend mainly used in toc.[Ch]
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOC_BACKEND_H
|
|
|
|
#define TOC_BACKEND_H
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "ParIterator.h"
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2006-11-11 00:35:14 +00:00
|
|
|
#include "support/docstream.h"
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
class Buffer;
|
|
|
|
class FuncRequest;
|
|
|
|
|
|
|
|
///
|
|
|
|
/**
|
|
|
|
*/
|
2006-11-13 16:53:49 +00:00
|
|
|
class TocItem
|
2006-04-26 13:34:35 +00:00
|
|
|
{
|
2006-11-13 16:53:49 +00:00
|
|
|
friend class TocBackend;
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
|
|
|
///
|
2006-11-13 16:53:49 +00:00
|
|
|
TocItem(ParConstIterator const & par_it = ParConstIterator(),
|
|
|
|
int d = -1,
|
|
|
|
docstring const & s = docstring());
|
|
|
|
///
|
|
|
|
~TocItem() {}
|
|
|
|
///
|
|
|
|
bool const isValid() const;
|
|
|
|
///
|
|
|
|
int const id() const;
|
|
|
|
///
|
|
|
|
int const depth() const;
|
|
|
|
///
|
|
|
|
docstring const & str() const;
|
|
|
|
///
|
|
|
|
docstring const asString() const;
|
|
|
|
|
|
|
|
/// the action corresponding to the goTo above
|
|
|
|
FuncRequest action() const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Current position of item.
|
|
|
|
ParConstIterator par_it_;
|
|
|
|
|
|
|
|
/// nesting depth
|
|
|
|
int depth_;
|
|
|
|
|
|
|
|
/// Full item string
|
|
|
|
docstring str_;
|
|
|
|
};
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
///
|
|
|
|
typedef std::vector<TocItem> Toc;
|
|
|
|
typedef Toc::const_iterator TocIterator;
|
|
|
|
/// The ToC list.
|
|
|
|
/// A class and no typedef because we want to forward declare it.
|
|
|
|
class TocList : public std::map<std::string, Toc>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class TocBackend
|
|
|
|
{
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
|
|
|
///
|
|
|
|
TocBackend(Buffer const * buffer = NULL): buffer_(buffer) {}
|
|
|
|
///
|
|
|
|
~TocBackend() {}
|
|
|
|
///
|
|
|
|
void setBuffer(Buffer const * buffer)
|
|
|
|
{ buffer_ = buffer; }
|
|
|
|
///
|
|
|
|
void update();
|
2007-03-12 11:23:41 +00:00
|
|
|
///
|
|
|
|
void updateItem(ParConstIterator const & pit);
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2006-11-11 00:35:14 +00:00
|
|
|
TocList const & tocs() const
|
2006-04-26 13:34:35 +00:00
|
|
|
{ return tocs_; }
|
2007-03-16 14:14:55 +00:00
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2006-11-11 00:35:14 +00:00
|
|
|
Toc const & toc(std::string const & type) const;
|
2006-04-26 13:34:35 +00:00
|
|
|
/// Return the first Toc Item before the cursor
|
2006-11-11 00:35:14 +00:00
|
|
|
TocIterator const item(std::string const & type, ParConstIterator const &) const;
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2007-01-18 22:29:50 +00:00
|
|
|
void writePlaintextTocList(std::string const & type, odocstream & os) const;
|
2006-04-26 13:34:35 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///
|
|
|
|
TocList tocs_;
|
|
|
|
///
|
|
|
|
Buffer const * buffer_;
|
|
|
|
|
|
|
|
}; // TocBackend
|
|
|
|
|
|
|
|
inline
|
2006-11-13 16:53:49 +00:00
|
|
|
bool operator==(TocItem const & a, TocItem const & b)
|
2006-04-26 13:34:35 +00:00
|
|
|
{
|
2006-04-26 17:43:03 +00:00
|
|
|
return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
|
2006-04-26 13:34:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inline
|
2006-11-13 16:53:49 +00:00
|
|
|
bool operator!=(TocItem const & a, TocItem const & b)
|
2006-04-26 13:34:35 +00:00
|
|
|
{
|
|
|
|
return !(a == b);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // TOC_BACKEND_H
|