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 \n";
43 void end_deeper(ostream & os)
45 os << "\n\\end_deeper \n";
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) {
77 if (deeper_paragraph) {
79 deeper_paragraph = false;
81 begin_layout(os, layout);
84 need_end_layout = true;
86 // a standard paragraph in an
87 // enumeration. We have to recognize
88 // that this may require a begin_deeper.
89 if (!deeper_paragraph)
91 begin_layout(os, textclass.defaultLayout());
93 need_end_layout = true;
94 deeper_paragraph = true;
97 begin_layout(os, layout);
99 need_end_layout = true;
101 if (!extra_stuff.empty()) {
110 void Context::check_end_layout(ostream & os)
112 if (need_end_layout) {
114 need_end_layout = false;
119 void Context::check_deeper(ostream & os)
121 if (parent_layout->isEnvironment()) {
122 if (need_end_deeper) {
123 // no need to have \end_deeper \begin_deeper
124 need_end_deeper = false;
127 need_end_deeper = true;
130 check_end_deeper(os);
134 void Context::check_end_deeper(ostream & os)
136 if (need_end_deeper) {
138 need_end_deeper = false;
140 if (deeper_paragraph) {
142 deeper_paragraph = false;
147 void Context::set_item()
154 void Context::new_paragraph(ostream & os)
156 check_end_layout(os);
161 void Context::add_extra_stuff(std::string const & stuff)
163 if (!lyx::support::contains(extra_stuff, stuff))
164 extra_stuff += stuff;
168 void Context::dump(ostream & os, string const & desc) const
170 os << "\n" << desc <<" [";
172 os << "need_layout ";
174 os << "need_end_layout ";
176 os << "need_end_deeper ";
179 if (deeper_paragraph)
180 os << "deeper_paragraph ";
181 if (!extra_stuff.empty())
182 os << "extrastuff=[" << extra_stuff << "] ";
183 os << "layout=" << layout->name();
184 os << " parent_layout=" << parent_layout->name() << "]" << endl;