]> git.lyx.org Git - lyx.git/blob - src/TocBackend.h
* Painter.h:
[lyx.git] / src / TocBackend.h
1 // -*- C++ -*-
2 /**
3  * \file TocBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  *
13  * TocBackend mainly used in toc.[Ch]
14  */
15
16 #ifndef TOC_BACKEND_H
17 #define TOC_BACKEND_H
18
19 #include <map>
20 #include <iosfwd>
21 #include <vector>
22 #include <string>
23
24 #include "pariterator.h"
25
26 namespace lyx {
27
28 class Buffer;
29 class LyXView;
30 class Paragraph;
31 class FuncRequest;
32 class LCursor;
33
34 ///
35 /**
36 */
37 class TocBackend
38 {
39 public:
40         ///
41         /**
42         */
43         class Item
44         {
45                 friend class TocBackend;
46                 friend bool operator==(Item const & a, Item const & b);
47
48         public:
49                 ///
50                 Item(
51                         ParConstIterator const & par_it = ParConstIterator(),
52                         int d = -1,
53                         docstring const & s = docstring());
54                 ///
55                 ~Item() {}
56                 ///
57                 bool const isValid() const;
58                 ///
59                 int const id() const;
60                 ///
61                 int const depth() const;
62                 ///
63                 docstring const & str() const;
64                 ///
65                 docstring const asString() const;
66                 /// set cursor in LyXView to this Item
67                 void goTo(LyXView & lv_) const;
68                 /// the action corresponding to the goTo above
69                 FuncRequest action() const;
70                 
71         protected:
72                 /// Current position of item.
73                 ParConstIterator par_it_;
74
75                 /// nesting depth
76                 int depth_;
77
78                 /// Full item string
79                 docstring str_;
80         };
81
82         ///
83         typedef std::vector<Item> Toc;
84         typedef std::vector<Item>::const_iterator TocIterator;
85         ///
86         typedef std::map<std::string, Toc> TocList;
87
88 public:
89         ///
90         TocBackend(Buffer const * buffer = NULL): buffer_(buffer) {}
91         ///
92         ~TocBackend() {}
93         ///
94         void setBuffer(Buffer const * buffer)
95         { buffer_ = buffer; }
96         ///
97         bool addType(std::string const & type);
98         ///
99         void update();
100         ///
101         TocList const & tocs()
102         { return tocs_; }
103         ///
104         std::vector<std::string> const & types()
105         { return types_; }
106         ///
107         Toc const & toc(std::string const & type);
108         /// Return the first Toc Item before the cursor
109         TocIterator const item(std::string const & type, ParConstIterator const &);
110
111         void asciiTocList(std::string const & type, odocstream & os) const;
112
113 private:
114         /// 
115         TocList tocs_;
116         ///
117         std::vector<std::string> types_;
118         ///
119         Buffer const * buffer_;
120
121 }; // TocBackend
122
123 inline
124 bool operator==(TocBackend::Item const & a, TocBackend::Item const & b)
125 {
126         return a.id() == b.id() && a.str() == b.str() && a.depth() == b.depth();
127 }
128
129
130 inline
131 bool operator!=(TocBackend::Item const & a, TocBackend::Item const & b)
132 {
133         return !(a == b);
134 }
135
136
137 } // namespace lyx
138
139 #endif // TOC_BACKEND_H