]> git.lyx.org Git - lyx.git/blob - src/LayoutModuleList.h
Avoid full metrics computation with Update:FitCursor
[lyx.git] / src / LayoutModuleList.h
1 // -*- C++ -*-
2 /**
3  * \file LayoutModuleList.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Richard Kimberly Heck
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LAYOUTMODULELIST_H
13 #define LAYOUTMODULELIST_H
14
15 #include <list>
16 #include <string>
17
18 namespace lyx {
19
20 class LayoutFile;
21
22 /**
23         Represents a list of modules, such as might be associated with
24         a particular document. Provides methods for adding modules, checking
25         if a module can be added, and, importantly, adapting the list to a
26         new DocumentClass.
27 */
28 class LayoutModuleList {
29 public:
30         ///
31         typedef std::list<std::string>::const_iterator const_iterator;
32         ///
33         typedef std::list<std::string>::iterator iterator;
34         ///
35         iterator begin() { return lml_.begin(); }
36         ///
37         iterator end() { return lml_.end(); }
38         ///
39         const_iterator begin() const { return lml_.begin(); }
40         ///
41         const_iterator end() const { return lml_.end(); }
42         ///
43         void clear() { lml_.clear(); }
44         ///
45         bool empty() const { return lml_.empty(); }
46         ///
47         iterator erase(iterator pos) { return lml_.erase(pos); }
48         ///
49         iterator insert(iterator pos, std::string const & str)
50                 { return lml_.insert(pos, str); }
51         ///
52         void push_back(std::string const & str) { lml_.push_back(str); }
53         ///
54         size_t size() const { return lml_.size(); }
55         /// This is needed in GuiDocument. It seems better than an
56         /// implicit conversion.
57         std::list<std::string> const & list() const { return lml_; }
58         /// List of modules as a comma-separated string
59         std::string asString() const;
60         /// Checks to make sure module's requriements are satisfied, that it does
61         /// not conflict with already-present modules, isn't already loaded, etc.
62         bool moduleCanBeAdded(std::string const & modName,
63                         LayoutFile const * const lay) const;
64         /// Like !moduleCanBeAdded(), but does not check requirements
65         bool moduleConflicts(std::string const & modName,
66                         LayoutFile const * const lay) const;
67         /// If the user changes the base class for a given document, then the
68         /// associated module list has to be updated. This just calls
69         /// (i)   removeBadModules()
70         /// (ii)  addDefaultModules()
71         /// (iii) checkModuleConsistency()
72         /// in that order, for which see below.
73         /// \param lay The new base class.
74         /// \param removedModules Modules the user explicitly removed and so
75         /// which should not be included.
76         /// \return true if no changes had to be made, false if some did have
77         /// to be made.
78         bool adaptToBaseClass(LayoutFile const * const lay,
79                         std::list<std::string> const & removedModules);
80         ///
81         bool operator==(LayoutModuleList const & other) const {
82                 return lml_ == other.lml_;
83         }
84         ///
85         bool operator!=(LayoutModuleList const & other) const {
86                 return !operator==(other);
87         }
88 private:
89         /// Removes modules excluded by, provided by, etc, the base class.
90         /// \param lay The document class against which to check.
91         /// \return true, if modules were consistent, false if changes had
92         /// to be made.
93         bool removeBadModules(LayoutFile const * const lay);
94         /// Adds default modules, if they're addable.
95         /// \param lay The base class from which to get default modules.
96         /// \param removedModules Modules the user has explicitly removed.
97         void addDefaultModules(LayoutFile const * const lay,
98                         std::list<std::string> removedModules);
99         /// Checks for consistency among modules: makes sure requirements
100         /// are met, no modules exclude one another, etc, and resolves any
101         /// such conflicts, leaving us with a consistent collection.
102         /// \param lay The base class against which to check.
103         /// \return true if modules were consistent, false if changes had
104         /// to be made.
105         bool checkModuleConsistency(LayoutFile const * const lay);
106         ///
107         std::list<std::string> lml_;
108 };
109 } // namespace lyx
110 #endif