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_)
53 : need_layout(need_layout_),
54 need_end_layout(false), need_end_deeper(false),
55 has_item(false), deeper_paragraph(false),
56 textclass(textclass_),
57 layout(layout_), parent_layout(parent_layout_)
60 layout = textclass.defaultLayout();
61 if (!parent_layout.get())
62 parent_layout = textclass.defaultLayout();
66 void Context::check_layout(ostream & os)
71 // are we in a list-like environment?
72 if (layout->isEnvironment()
73 && layout->latextype != LATEX_ENVIRONMENT) {
75 if (deeper_paragraph) {
77 deeper_paragraph = false;
79 begin_layout(os, layout);
82 need_end_layout = true;
84 // a standard paragraph in an
85 // enumeration. We have to recognize
86 // that this may require a begin_deeper.
87 if (!deeper_paragraph)
89 begin_layout(os, textclass.defaultLayout());
91 need_end_layout = true;
92 deeper_paragraph = true;
95 begin_layout(os, layout);
97 need_end_layout = true;
99 if (!extra_stuff.empty()) {
108 void Context::check_end_layout(ostream & os)
110 if (need_end_layout) {
112 need_end_layout = false;
117 void Context::check_deeper(ostream & os)
119 if (parent_layout->isEnvironment()) {
120 if (need_end_deeper) {
121 // no need to have \end_deeper \begin_deeper
122 need_end_deeper = false;
125 need_end_deeper = true;
128 check_end_deeper(os);
132 void Context::check_end_deeper(ostream & os)
134 if (need_end_deeper) {
136 need_end_deeper = false;
138 if (deeper_paragraph) {
140 deeper_paragraph = false;
145 void Context::set_item()
152 void Context::new_paragraph(ostream & os)
154 check_end_layout(os);
159 void Context::add_extra_stuff(std::string const & stuff)
161 if (!lyx::support::contains(extra_stuff, stuff))
162 extra_stuff += stuff;
166 void Context::dump(ostream & os, string const & desc) const
168 os << "\n" << desc <<" [";
170 os << "need_layout ";
172 os << "need_end_layout ";
174 os << "need_end_deeper ";
177 if (deeper_paragraph)
178 os << "deeper_paragraph ";
179 if (!extra_stuff.empty())
180 os << "extrastuff=[" << extra_stuff << "] ";
181 os << "layout=" << layout->name();
182 os << " parent_layout=" << parent_layout->name() << "]" << endl;