3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Jean-Marc Lasgouttes
8 * Full author contact details are available in file CREDITS.
15 #include "support/lstrings.h"
25 void begin_layout(ostream & os, LyXLayout_ptr layout)
27 os << "\n\\begin_layout " << layout->name() << "\n";
31 void end_layout(ostream & os)
33 os << "\n\\end_layout\n";
37 void begin_deeper(ostream & os)
39 os << "\n\\begin_deeper";
43 void end_deeper(ostream & os)
45 os << "\n\\end_deeper";
50 Context::Context(bool need_layout_,
51 LyXTextClass const & textclass_,
52 LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_,
54 : need_layout(need_layout_),
55 need_end_layout(false), need_end_deeper(false),
56 has_item(false), deeper_paragraph(false),
57 textclass(textclass_),
58 layout(layout_), parent_layout(parent_layout_),
62 layout = textclass.defaultLayout();
63 if (!parent_layout.get())
64 parent_layout = textclass.defaultLayout();
68 void Context::check_layout(ostream & os)
73 // are we in a list-like environment?
74 if (layout->isEnvironment()
75 && layout->latextype != LATEX_ENVIRONMENT) {
76 // A list-like environment
78 // a new item. If we had a standard
79 // paragraph before, we have to end it.
80 if (deeper_paragraph) {
82 deeper_paragraph = false;
84 begin_layout(os, layout);
87 need_end_layout = true;
89 // a standard paragraph in an
90 // enumeration. We have to recognize
91 // that this may require a begin_deeper.
92 if (!deeper_paragraph)
94 begin_layout(os, textclass.defaultLayout());
96 need_end_layout = true;
97 deeper_paragraph = true;
100 // No list-like environment
101 begin_layout(os, layout);
103 need_end_layout = true;
105 if (!extra_stuff.empty()) {
114 void Context::check_end_layout(ostream & os)
116 if (need_end_layout) {
118 need_end_layout = false;
123 void Context::check_deeper(ostream & os)
125 if (parent_layout->isEnvironment()) {
126 // We start a nested environment.
127 // We need to increase the depth.
128 if (need_end_deeper) {
129 // no need to have \end_deeper \begin_deeper
130 need_end_deeper = false;
133 need_end_deeper = true;
136 check_end_deeper(os);
140 void Context::check_end_deeper(ostream & os)
142 if (need_end_deeper) {
144 need_end_deeper = false;
146 if (deeper_paragraph) {
148 deeper_paragraph = false;
153 void Context::set_item()
160 void Context::new_paragraph(ostream & os)
162 check_end_layout(os);
167 void Context::add_extra_stuff(std::string const & stuff)
169 if (!lyx::support::contains(extra_stuff, stuff))
170 extra_stuff += stuff;
174 void Context::dump(ostream & os, string const & desc) const
176 os << "\n" << desc <<" [";
178 os << "need_layout ";
180 os << "need_end_layout ";
182 os << "need_end_deeper ";
185 if (deeper_paragraph)
186 os << "deeper_paragraph ";
187 if (!extra_stuff.empty())
188 os << "extrastuff=[" << extra_stuff << "] ";
189 os << "layout=" << layout->name();
190 os << " parent_layout=" << parent_layout->name() << "]" << endl;