]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/context.C
architectural changes to tex2lyx
[lyx.git] / src / tex2lyx / context.C
1 /** A small helper function
2     \author Jean-Marc Lasgouttes (2003)
3  */
4
5 #include <iostream>
6
7 #include "context.h"
8
9 using std::ostream;
10 using std::endl;
11
12 Context::Context(bool need_layout_,
13                  LyXTextClass const & textclass_,
14                  LyXLayout_ptr layout_, LyXLayout_ptr parent_layout_)
15         : need_layout(need_layout_),
16           need_end_layout(false), need_end_deeper(false),
17           textclass(textclass_),
18           layout(layout_), parent_layout(parent_layout_)
19 {
20         if (!layout.get())
21                 layout = textclass.defaultLayout();
22         if (!parent_layout.get())
23                 parent_layout = textclass.defaultLayout();
24 }
25
26
27 void Context::check_end_layout(ostream & os) 
28 {
29         if (need_end_layout) {
30                 os << "\n\\end_layout\n";
31                 need_end_layout = false;
32         }
33         if (need_end_deeper) {
34                 os << "\n\\end_deeper\n";
35                 need_end_deeper = false;
36         }
37 }
38
39
40 void Context::check_layout(ostream & os)
41 {
42         if (need_layout) {
43                 if (parent_layout->isEnvironment()) {
44                         if (need_end_deeper) {
45                                 // no need to have \end_deeper \begin_deeper
46 // FIXME: This does not work because \par already calls check_end_layout
47                                 need_end_deeper = false;
48                                 check_end_layout(os);
49                         } else {
50                                 check_end_layout(os);
51                                 os << "\n\\begin_deeper\n";
52                                 need_end_deeper = true;
53                         }
54                 } else 
55                         check_end_layout(os);
56                 
57                 os << "\n\\begin_layout " << layout->name() << "\n\n";
58                 need_end_layout = true;
59                 need_layout=false;
60                 if (!extra_stuff.empty()) {
61                         os << extra_stuff;
62                         extra_stuff.erase();
63                 }
64         }
65 }
66
67
68 void Context::dump(ostream & os, string const & desc) const
69 {
70         os << desc <<" [";
71         if (need_layout)
72                 os << "need_layout ";
73         if (need_end_layout)
74                 os << "need_end_layout ";
75         if (!extra_stuff.empty())
76                 os << "extrastuff=[" << extra_stuff << "] ";
77         os << "layout=" << layout->name();
78         os << " parent_layout=" << parent_layout->name() << "]" << endl;
79 }