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
|
2015-09-01 16:08:35 +00:00
|
|
|
* \author Guillaume Munch
|
2006-04-26 13:34:35 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2015-09-27 06:05:00 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "OutputEnums.h"
|
2016-01-08 19:06:50 +00:00
|
|
|
#include "Toc.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
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
#include <stack>
|
2008-02-09 09:08:59 +00:00
|
|
|
|
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;
|
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
|
|
|
|
/* FIXME: toc types are currently identified by strings. It cannot be converted
|
|
|
|
* into an enum because of the user-configurable indexing categories and
|
|
|
|
* the user-definable float types provided by layout files.
|
|
|
|
*
|
|
|
|
* I leave this for documentation purposes for the moment.
|
|
|
|
*
|
|
|
|
enum TocType {
|
|
|
|
TABLE_OF_CONTENTS,//"tableofcontents"
|
|
|
|
CHILD,//"child"
|
|
|
|
GRAPHICS,//"graphics"
|
|
|
|
NOTE,//"note"
|
|
|
|
BRANCH,//"branch"
|
|
|
|
CHANGE,//"change"
|
|
|
|
LABEL,//"label"
|
|
|
|
CITATION,//"citation"
|
|
|
|
EQUATION,//"equation"
|
|
|
|
FOOTNOTE,//"footnote"
|
|
|
|
MARGINAL_NOTE,//"marginalnote"
|
|
|
|
INDEX,//"index", "index:<user-str>" (from interface)
|
|
|
|
NOMENCL,//"nomencl"
|
|
|
|
LISTING,//"listings"
|
|
|
|
FLOAT,//"figure", "table", "algorithm", user-defined (from layout?)
|
2015-10-02 18:44:36 +00:00
|
|
|
MATH_MACRO,//"math-macro"
|
2015-10-04 18:48:31 +00:00
|
|
|
EXTERNAL,//"external"
|
2015-09-01 16:08:35 +00:00
|
|
|
SENSELESS,//"senseless"
|
|
|
|
TOC_TYPE_COUNT
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
|
|
|
/**
|
|
|
|
*/
|
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;
|
2015-09-27 06:05:00 +00:00
|
|
|
friend class TocBuilder;
|
2006-11-13 16:53:49 +00:00
|
|
|
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
2007-06-12 12:29:19 +00:00
|
|
|
/// Default constructor for STL containers.
|
2015-09-13 17:47:21 +00:00
|
|
|
TocItem() : dit_(0), depth_(0), output_(false) {}
|
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,
|
2014-02-24 15:40:57 +00:00
|
|
|
bool output_active,
|
2015-09-27 06:05:00 +00:00
|
|
|
docstring const & t = docstring(),
|
|
|
|
FuncRequest action = FuncRequest(LFUN_UNKNOWN_ACTION)
|
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
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
int depth() const { return depth_; }
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
docstring const & str() const { return str_; }
|
|
|
|
///
|
|
|
|
void str(docstring const & s) { str_ = s; }
|
2006-11-13 16:53:49 +00:00
|
|
|
///
|
2010-04-26 00:43:08 +00:00
|
|
|
docstring const & tooltip() const;
|
2015-09-27 06:05:00 +00:00
|
|
|
/// String for display, e.g. it has a mark if output is inactive
|
2006-11-13 16:53:49 +00:00
|
|
|
docstring const asString() const;
|
2009-04-09 18:42:59 +00:00
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
DocIterator const & dit() const { return dit_; }
|
2013-03-08 21:18:26 +00:00
|
|
|
///
|
|
|
|
bool isOutput() const { return output_; }
|
2015-09-27 06:05:00 +00:00
|
|
|
///
|
|
|
|
void setAction(FuncRequest a) { action_ = a; }
|
|
|
|
/// custom action, or the default one (paragraph-goto) if not customised
|
2006-11-13 16:53:49 +00:00
|
|
|
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_;
|
2015-09-27 06:05:00 +00:00
|
|
|
|
|
|
|
private:
|
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_;
|
2013-03-08 21:18:26 +00:00
|
|
|
/// Is this item in a note, inactive branch, etc?
|
|
|
|
bool output_;
|
2015-09-27 06:05:00 +00:00
|
|
|
/// Custom action
|
|
|
|
FuncRequest action_;
|
2006-11-13 16:53:49 +00:00
|
|
|
};
|
2006-04-26 13:34:35 +00:00
|
|
|
|
2006-11-13 16:53:49 +00:00
|
|
|
|
2015-09-01 16:08:35 +00:00
|
|
|
/// Caption-enabled TOC builders
|
|
|
|
class TocBuilder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TocBuilder(shared_ptr<Toc> const toc);
|
|
|
|
/// When entering a float
|
|
|
|
void pushItem(DocIterator const & dit, docstring const & s,
|
|
|
|
bool output_active, bool is_captioned = false);
|
|
|
|
/// When encountering a caption
|
|
|
|
void captionItem(DocIterator const & dit, docstring const & s,
|
|
|
|
bool output_active);
|
|
|
|
/// When exiting a float
|
|
|
|
void pop();
|
|
|
|
private:
|
|
|
|
TocBuilder(){}
|
|
|
|
///
|
|
|
|
struct frame {
|
2015-09-20 17:24:45 +00:00
|
|
|
Toc::size_type pos;
|
2015-09-01 16:08:35 +00:00
|
|
|
bool is_captioned;
|
|
|
|
};
|
|
|
|
///
|
|
|
|
shared_ptr<Toc> const toc_;
|
|
|
|
///
|
|
|
|
std::stack<frame> stack_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
class TocBuilderStore
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TocBuilderStore() {};
|
|
|
|
///
|
|
|
|
shared_ptr<TocBuilder> get(std::string const & type, shared_ptr<Toc> toc);
|
|
|
|
///
|
|
|
|
void clear() { map_.clear(); };
|
|
|
|
private:
|
|
|
|
typedef std::map<std::string, shared_ptr<TocBuilder> > map_t;
|
|
|
|
map_t map_;
|
|
|
|
};
|
2006-11-13 16:53:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
class TocBackend
|
|
|
|
{
|
2006-04-26 13:34:35 +00:00
|
|
|
public:
|
2016-01-08 19:06:50 +00:00
|
|
|
static Toc::const_iterator findItem(Toc const & toc,
|
|
|
|
DocIterator const & dit);
|
|
|
|
/// Look for a TocItem given its depth and string.
|
|
|
|
/// \return The first matching item.
|
|
|
|
/// \retval end() if no item was found.
|
|
|
|
static Toc::iterator findItem(Toc & toc, int depth, docstring const & str);
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
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
|
|
|
///
|
2015-09-27 06:05:00 +00:00
|
|
|
void update(bool output_active, UpdateType utype);
|
2008-09-26 10:37:24 +00:00
|
|
|
/// \return true if the item was updated.
|
|
|
|
bool updateItem(DocIterator const & pit);
|
2006-04-26 13:34:35 +00:00
|
|
|
///
|
2008-02-09 09:08:59 +00:00
|
|
|
TocList const & tocs() const { return tocs_; }
|
2015-09-01 16:08:35 +00:00
|
|
|
/// never null
|
|
|
|
shared_ptr<Toc const> toc(std::string const & type) const;
|
|
|
|
shared_ptr<Toc> toc(std::string const & type);
|
|
|
|
/// nevel null
|
|
|
|
shared_ptr<TocBuilder> builder(std::string const & type);
|
2008-02-15 10:13:32 +00:00
|
|
|
/// Return the first Toc Item before the cursor
|
2016-01-08 19:06:50 +00:00
|
|
|
Toc::const_iterator 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
|
|
|
///
|
2013-03-08 19:52:18 +00:00
|
|
|
void writePlaintextTocList(std::string const & type,
|
|
|
|
odocstringstream & os, size_t max_length) const;
|
2015-11-03 16:47:25 +00:00
|
|
|
///
|
|
|
|
docstring outlinerName(std::string const & type) 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_;
|
|
|
|
///
|
2015-09-01 16:08:35 +00:00
|
|
|
TocBuilderStore builders_;
|
|
|
|
///
|
2006-04-26 13:34:35 +00:00
|
|
|
Buffer const * buffer_;
|
|
|
|
}; // TocBackend
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // TOC_BACKEND_H
|