]> git.lyx.org Git - lyx.git/blob - src/tex2lyx/context.C
make nesting work in 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_layout(ostream & os)
28 {
29         if (need_layout) {
30                 check_end_layout(os);
31                 
32                 os << "\n\\begin_layout " << layout->name() << "\n\n";
33                 need_layout=false;
34                 need_end_layout = true;
35                 if (!extra_stuff.empty()) {
36                         os << extra_stuff;
37                         extra_stuff.erase();
38                 }
39         }
40 }
41
42
43 void Context::check_end_layout(ostream & os) 
44 {
45         if (need_end_layout) {
46                 os << "\n\\end_layout\n";
47                 need_end_layout = false;
48         }
49 }
50
51
52 void Context::check_deeper(ostream & os)
53 {
54         if (parent_layout->isEnvironment()) {
55                 if (need_end_deeper) {
56                                 // no need to have \end_deeper \begin_deeper
57 // FIXME: This does not work because \par already calls check_end_layout
58                         need_end_deeper = false;
59                 } else {
60                         os << "\n\\begin_deeper \n";
61                         need_end_deeper = true;
62                 }
63         } else
64                 check_end_deeper(os);
65 }
66
67
68 void Context::check_end_deeper(ostream & os) 
69 {
70         if (need_end_deeper) {
71                 os << "\n\\end_deeper \n";
72                 need_end_deeper = false;
73         }
74 }
75
76
77 void Context::dump(ostream & os, string const & desc) const
78 {
79         os << "\n" << desc <<" [";
80         if (need_layout)
81                 os << "need_layout ";
82         if (need_end_layout)
83                 os << "need_end_layout ";
84         if (!extra_stuff.empty())
85                 os << "extrastuff=[" << extra_stuff << "] ";
86         os << "layout=" << layout->name();
87         os << " parent_layout=" << parent_layout->name() << "]" << endl;
88 }