3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Martin Vermeer
9 * Full author contact details are available in file CREDITS.
14 #include "InsetList.h"
17 #include "bufferparams.h"
18 #include "BufferView.h"
21 #include "insets/insetbranch.h"
26 using std::lower_bound;
27 using std::upper_bound;
33 /// used by lower_bound and upper_bound
35 int operator()(InsetList::InsetTable const & a,
36 InsetList::InsetTable const & b) const
45 InsetList::~InsetList()
47 // If we begin storing a shared_ptr in the List
48 // this code can be removed. (Lgb)
49 List::iterator it = list.begin();
50 List::iterator end = list.end();
51 for (; it != end; ++it) {
57 InsetList::iterator InsetList::begin()
63 InsetList::iterator InsetList::end()
69 InsetList::const_iterator InsetList::begin() const
75 InsetList::const_iterator InsetList::end() const
82 InsetList::insetIterator(pos_type pos)
84 InsetTable search_elem(pos, 0);
85 List::iterator it = lower_bound(list.begin(),
87 search_elem, MatchIt());
92 void InsetList::insert(InsetOld * inset, lyx::pos_type pos)
94 InsetTable search_elem(pos, 0);
95 List::iterator end = list.end();
96 List::iterator it = lower_bound(list.begin(),
98 search_elem, MatchIt());
99 if (it != end && it->pos == pos) {
100 lyxerr << "ERROR (InsetList::insert): "
101 << "There is an inset in position: " << pos << endl;
103 list.insert(it, InsetTable(pos, inset));
108 void InsetList::erase(pos_type pos)
110 InsetTable search_elem(pos, 0);
111 List::iterator end = list.end();
113 lower_bound(list.begin(),
115 search_elem, MatchIt());
116 if (it != end && it->pos == pos) {
123 InsetOld * InsetList::release(pos_type pos)
125 InsetTable search_elem(pos, 0);
126 List::iterator end = list.end();
128 lower_bound(list.begin(),
130 search_elem, MatchIt());
131 if (it != end && it->pos == pos) {
132 InsetOld * tmp = it->inset;
140 InsetOld * InsetList::get(pos_type pos) const
142 InsetTable search_elem(pos, 0);
143 List::const_iterator end = list.end();
144 List::const_iterator it =
145 lower_bound(list.begin(),
147 search_elem, MatchIt());
148 if (it != end && it->pos == pos)
154 void InsetList::increasePosAfterPos(pos_type pos)
156 InsetTable search_elem(pos, 0);
157 List::iterator end = list.end();
158 List::iterator it = lower_bound(list.begin(),
160 search_elem, MatchIt());
161 for (; it != end; ++it) {
167 void InsetList::decreasePosAfterPos(pos_type pos)
169 InsetTable search_elem(pos, 0);
170 List::iterator end = list.end();
171 List::iterator it = upper_bound(list.begin(),
173 search_elem, MatchIt());
174 for (; it != end; ++it) {
180 void InsetList::deleteInsetsLyXText(BufferView * bv)
182 List::iterator it = list.begin();
183 List::iterator end = list.end();
184 for (; it != end; ++it) {
185 if (it->inset && it->inset->isTextInset()) {
186 static_cast<UpdatableInset*>
187 (it->inset)->deleteLyXText(bv, true);
193 void InsetList::insetsOpenCloseBranch(BufferView * bv)
195 BufferParams bp = bv->buffer()->params();
196 List::iterator it = list.begin();
197 List::iterator end = list.end();
198 for (; it != end; ++it) {
199 if (it->inset && it->inset->lyxCode() == InsetOld::BRANCH_CODE) {
200 InsetBranch * inset = static_cast<InsetBranch *>(it->inset);
201 if (bp.branchlist().selected(inset->params().branch)) {