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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TOC_BACKEND_H
|
|
|
|
#define TOC_BACKEND_H
|
|
|
|
|
2008-05-13 08:23:44 +00:00
|
|
|
#include "DocIterator.h"
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/strfwd.h"
|
2006-11-11 00:35:14 +00:00
|
|
|
|
2008-02-09 09:08:59 +00:00
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
2006-11-11 00:35:14 +00:00
|
|
|
|
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
|
|
|
{
|
2008-06-12 15:31:10 +00:00
|
|
|
friend class Toc;
|
2006-11-13 16:53:49 +00:00
|
|
|
friend class TocBackend;
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
2007-06-12 12:29:19 +00:00
|
|
|
/// Default constructor for STL containers.
|
2008-11-17 11:46:07 +00:00
|
|
|
TocItem() : dit_(0) {}
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-05-13 08:23:44 +00:00
|
|
|
TocItem(DocIterator const & dit,
|
2007-06-12 12:29:19 +00:00
|
|
|
int depth,
|
2010-04-26 00:43:08 +00:00
|
|
|
docstring const & s,
|
|
|
|
docstring const & t = docstring()
|
2007-05-16 16:43:14 +00:00
|
|
|
);
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
|
|
|
~TocItem() {}
|
|
|
|
///
|
2007-09-16 10:36:57 +00:00
|
|
|
int id() const;
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
2007-09-16 10:36:57 +00:00
|
|
|
int depth() const;
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
|
|
|
docstring const & str() const;
|
|
|
|
///
|
2010-04-26 00:43:08 +00:00
|
|
|
docstring const & tooltip() const;
|
|
|
|
///
|
2006-11-13 16:53:49 +00:00
|
|
|
docstring const asString() const;
|
2009-04-09 18:42:59 +00:00
|
|
|
///
|
|
|
|
DocIterator const & dit() const;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
/// the action corresponding to the goTo above
|
|
|
|
FuncRequest action() const;
|
2007-05-28 22:27:45 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
protected:
|
|
|
|
/// Current position of item.
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator dit_;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
/// nesting depth
|
|
|
|
int depth_;
|
|
|
|
|
|
|
|
/// Full item string
|
|
|
|
docstring str_;
|
2010-04-26 00:43:08 +00:00
|
|
|
|
|
|
|
/// The tooltip string
|
|
|
|
docstring tooltip_;
|
2006-11-13 16:53:49 +00:00
|
|
|
};
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
///
|
2008-06-12 16:46:46 +00:00
|
|
|
class Toc : public std::vector<TocItem>
|
|
|
|
{
|
2008-06-12 15:31:10 +00:00
|
|
|
public:
|
|
|
|
typedef std::vector<TocItem>::const_iterator const_iterator;
|
2008-09-30 12:34:36 +00:00
|
|
|
typedef std::vector<TocItem>::iterator iterator;
|
2008-06-12 16:46:46 +00:00
|
|
|
const_iterator item(DocIterator const & dit) const;
|
2008-09-30 11:06:34 +00:00
|
|
|
/// Look for a TocItem given its depth and string.
|
|
|
|
/// \return The first matching item.
|
|
|
|
/// \retval end() if no item was found.
|
2008-09-30 12:34:36 +00:00
|
|
|
iterator item(int depth, docstring const & str);
|
2008-06-12 15:31:10 +00:00
|
|
|
};
|
2008-03-08 10:08:10 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
typedef Toc::const_iterator TocIterator;
|
2007-11-01 22:17:22 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
/// The ToC list.
|
|
|
|
/// A class and no typedef because we want to forward declare it.
|
2007-11-01 22:17:22 +00:00
|
|
|
class TocList : public std::map<std::string, Toc> {};
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class TocBackend
|
|
|
|
{
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
|
|
|
///
|
2008-02-27 22:33:10 +00:00
|
|
|
TocBackend(Buffer const * buffer) : buffer_(buffer) {}
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-02-09 09:08:59 +00:00
|
|
|
void setBuffer(Buffer const * buffer) { buffer_ = buffer; }
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
|
|
|
void update();
|
2008-09-26 10:37:24 +00:00
|
|
|
/// \return true if the item was updated.
|
|
|
|
bool updateItem(DocIterator const & pit);
|
2007-03-12 11:23:41 +00:00
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-02-09 09:08:59 +00:00
|
|
|
TocList const & tocs() const { return tocs_; }
|
2008-02-15 10:13:32 +00:00
|
|
|
TocList & tocs() { 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;
|
2008-02-15 10:13:32 +00:00
|
|
|
Toc & toc(std::string const & type);
|
2008-02-09 09:08:59 +00:00
|
|
|
|
2008-02-15 10:13:32 +00:00
|
|
|
/// Return the first Toc Item before the cursor
|
2008-02-09 09:08:59 +00:00
|
|
|
TocIterator item(
|
2007-05-17 19:19:37 +00:00
|
|
|
std::string const & type, ///< Type of Toc.
|
2008-05-13 08:23:44 +00:00
|
|
|
DocIterator const & dit ///< The cursor location in the document.
|
2008-02-09 09:08:59 +00:00
|
|
|
) const;
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2008-02-09 09:08:59 +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:
|
2007-05-28 22:27:45 +00:00
|
|
|
///
|
2006-04-26 13:34:35 +00:00
|
|
|
TocList tocs_;
|
|
|
|
///
|
|
|
|
Buffer const * buffer_;
|
|
|
|
}; // TocBackend
|
|
|
|
|
2008-02-09 09:08:59 +00:00
|
|
|
inline 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-09 09:08:59 +00:00
|
|
|
inline 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
|