]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
further xetex disambiguation: use the flavor where the flavor is apt.
[lyx.git] / src / insets / InsetFlex.cpp
1 /**
2  * \file InsetFlex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "InsetFlex.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "Cursor.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
22 #include "Lexer.h"
23 #include "TextClass.h"
24
25 #include "support/gettext.h"
26
27 #include <ostream>
28
29 using namespace std;
30
31 namespace lyx {
32
33
34 InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
35         : InsetCollapsable(buf), name_(layoutName)
36 {
37         status_= Collapsed;
38 }
39
40
41 InsetFlex::InsetFlex(InsetFlex const & in)
42         : InsetCollapsable(in), name_(in.name_)
43 {}
44
45
46 InsetLayout const & InsetFlex::getLayout() const
47 {
48         DocumentClass const & dc = buffer().params().documentClass();
49         docstring const dname = from_utf8(name_); 
50         if (dc.hasInsetLayout(dname))
51                 return dc.insetLayout(dname);
52         return dc.insetLayout(from_utf8("Flex:" + name_));
53 }
54
55
56 InsetLayout::InsetDecoration InsetFlex::decoration() const
57 {
58         InsetLayout::InsetDecoration const dec = getLayout().decoration();
59         return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
60 }
61
62
63 void InsetFlex::write(ostream & os) const
64 {
65         os << "Flex " <<
66                 (name_.empty() ? "undefined" : name_) << "\n";
67         InsetCollapsable::write(os);
68 }
69
70
71 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
72                 FuncStatus & flag) const
73 {
74         switch (cmd.action()) {
75         case LFUN_INSET_DISSOLVE:
76                 if (!cmd.argument().empty()) {
77                         InsetLayout const & il = getLayout();
78                         InsetLayout::InsetLyXType const type = 
79                                 translateLyXType(to_utf8(cmd.argument()));
80                         if (il.lyxtype() == type) {
81                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
82                                 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
83                         } else
84                                 return false;
85                 }
86                 // fall-through
87         default:
88                 return InsetCollapsable::getStatus(cur, cmd, flag);
89         }
90 }
91
92
93 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
94 {
95         switch (cmd.action()) {
96         case LFUN_INSET_DISSOLVE:
97                 if (!cmd.argument().empty()) {
98                         InsetLayout const & il = getLayout();
99                         InsetLayout::InsetLyXType const type = 
100                                 translateLyXType(to_utf8(cmd.argument()));
101                         
102                         if (il.lyxtype() == type) {
103                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
104                                 InsetCollapsable::doDispatch(cur, temp_cmd);
105                         } else
106                                 cur.undispatched();
107                         break;
108                 }
109                 // fall-through
110         default:
111                 InsetCollapsable::doDispatch(cur, cmd);
112                 break;
113         }
114 }
115
116
117 } // namespace lyx