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