]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
InsetTabular.cpp: fix #6585 also for wrapped floats - thanks Vincent
[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
24 #include "support/gettext.h"
25
26 #include <ostream>
27
28 using namespace std;
29
30 namespace lyx {
31
32
33 InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
34         : InsetCollapsable(buf), name_(layoutName)
35 {
36         status_= Collapsed;
37 }
38
39
40 InsetFlex::InsetFlex(InsetFlex const & in)
41         : InsetCollapsable(in), name_(in.name_)
42 {}
43
44
45 InsetLayout const & InsetFlex::getLayout() const
46 {
47         DocumentClass const & dc = buffer().params().documentClass();
48         docstring const dname = from_utf8(name_); 
49         if (dc.hasInsetLayout(dname))
50                 return dc.insetLayout(dname);
51         return dc.insetLayout(from_utf8("Flex:" + name_));
52 }
53
54
55 InsetLayout::InsetDecoration InsetFlex::decoration() const
56 {
57         InsetLayout::InsetDecoration const dec = getLayout().decoration();
58         return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
59 }
60
61
62 void InsetFlex::write(ostream & os) const
63 {
64         os << "Flex " <<
65                 (name_.empty() ? "undefined" : name_) << "\n";
66         InsetCollapsable::write(os);
67 }
68
69
70 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
71                 FuncStatus & flag) const
72 {
73         switch (cmd.action()) {
74         case LFUN_INSET_DISSOLVE:
75                 if (!cmd.argument().empty()) {
76                         InsetLayout const & il = getLayout();
77                         InsetLayout::InsetLyXType const type = 
78                                 translateLyXType(to_utf8(cmd.argument()));
79                         if (il.lyxtype() == type) {
80                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
81                                 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
82                         } else
83                                 return false;
84                 }
85                 // fall-through
86         default:
87                 return InsetCollapsable::getStatus(cur, cmd, flag);
88         }
89 }
90
91
92 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
93 {
94         switch (cmd.action()) {
95         case LFUN_INSET_DISSOLVE:
96                 if (!cmd.argument().empty()) {
97                         InsetLayout const & il = getLayout();
98                         InsetLayout::InsetLyXType const type = 
99                                 translateLyXType(to_utf8(cmd.argument()));
100                         
101                         if (il.lyxtype() == type) {
102                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
103                                 InsetCollapsable::doDispatch(cur, temp_cmd);
104                         } else
105                                 cur.undispatched();
106                         break;
107                 }
108                 // fall-through
109         default:
110                 InsetCollapsable::doDispatch(cur, cmd);
111                 break;
112         }
113 }
114
115
116 } // namespace lyx