]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/context.C
More 'standard conformant blurb' nonsense.
[lyx.git] / src / tex2lyx / context.C
1 /**
2  * \file context.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Jean-Marc Lasgouttes
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <iostream>
12
13 #include "context.h"
14
15 using std::ostream;
16 using std::endl;
17
18 namespace {
19
20 void begin_layout(ostream & os, LyXLayout_ptr layout)
21 {
22         os << "\n\\begin_layout " << layout->name() << "\n\n";
23 }
24
25
26 void end_layout(ostream & os)
27 {
28         os << "\n\\end_layout\n";
29 }
30
31
32 void begin_deeper(ostream & os)
33 {
34         os << "\n\\begin_deeper \n";
35 }
36
37
38 void end_deeper(ostream & os)
39 {
40         os << "\n\\end_deeper \n";
41 }
42         
43 }
44
45 Context::Context(bool need_layout_,
46                  LyXTextClass const & textclass_,
47                  LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_)
48         : need_layout(need_layout_),
49           need_end_layout(false), need_end_deeper(false),
50           has_item(false), deeper_paragraph(false),
51           textclass(textclass_),
52           layout(layout_), parent_layout(parent_layout_)
53 {
54         if (!layout.get())
55                 layout = textclass.defaultLayout();
56         if (!parent_layout.get())
57                 parent_layout = textclass.defaultLayout();
58 }
59
60
61 void Context::check_layout(ostream & os)
62 {
63         if (need_layout) {
64                 check_end_layout(os);
65
66                 // are we in a list-like environment?
67                 if (layout->isEnvironment()
68                     && layout->latextype != LATEX_ENVIRONMENT) {
69                         if (has_item) {
70                                 if (deeper_paragraph) {
71                                         end_deeper(os);
72                                         deeper_paragraph = false;
73                                 }
74                                 begin_layout(os, layout);
75                                 has_item = false;
76                                 need_layout=false;
77                                 need_end_layout = true;
78                         } else {
79                                 // a standard paragraph in an
80                                 // enumeration. We have to recognize
81                                 // that this may require a begin_deeper.
82                                 if (!deeper_paragraph)
83                                         begin_deeper(os);
84                                 begin_layout(os, textclass.defaultLayout());
85                                 need_layout=false;
86                                 need_end_layout = true;
87                                 deeper_paragraph = true;
88                         }
89                 } else {
90                         begin_layout(os, layout);
91                         need_layout=false;
92                         need_end_layout = true;
93                         if (!extra_stuff.empty()) {
94                                 os << extra_stuff;
95                                 extra_stuff.erase();
96                         }
97                 }
98         }
99 }
100
101
102 void Context::check_end_layout(ostream & os) 
103 {
104         if (need_end_layout) {          
105                 end_layout(os);
106                 need_end_layout = false;
107         }
108 }
109
110
111 void Context::check_deeper(ostream & os)
112 {
113         if (parent_layout->isEnvironment()) {
114                 if (need_end_deeper) {
115                         // no need to have \end_deeper \begin_deeper
116                         need_end_deeper = false;
117                 } else {
118                         begin_deeper(os);
119                         need_end_deeper = true;
120                 }
121         } else
122                 check_end_deeper(os);
123 }
124
125
126 void Context::check_end_deeper(ostream & os) 
127 {
128         if (need_end_deeper) {
129                 end_deeper(os);
130                 need_end_deeper = false;
131         }
132         if (deeper_paragraph) {
133                 end_deeper(os);
134                 deeper_paragraph = false;
135         }
136 }
137
138
139 void Context::dump(ostream & os, string const & desc) const
140 {
141         os << "\n" << desc <<" [";
142         if (need_layout)
143                 os << "need_layout ";
144         if (need_end_layout)
145                 os << "need_end_layout ";
146         if (!extra_stuff.empty())
147                 os << "extrastuff=[" << extra_stuff << "] ";
148         os << "layout=" << layout->name();
149         os << " parent_layout=" << parent_layout->name() << "]" << endl;
150 }