]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
2fd3a21037b31e8e4a8ebf7accb633b7e6894667
[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 docstring InsetFlex::name() const
46
47         return from_utf8("Flex:" + name_); 
48 }
49
50
51 InsetLayout::InsetDecoration InsetFlex::decoration() const
52 {
53         InsetLayout::InsetDecoration const dec = getLayout().decoration();
54         return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
55 }
56
57
58 void InsetFlex::write(ostream & os) const
59 {
60         os << "Flex " <<
61                 (name_.empty() ? "undefined" : name_) << "\n";
62         InsetCollapsable::write(os);
63 }
64
65
66 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
67                 FuncStatus & flag) const
68 {
69         switch (cmd.action()) {
70         case LFUN_INSET_DISSOLVE:
71                 if (!cmd.argument().empty()) {
72                         InsetLayout const & il = getLayout();
73                         InsetLayout::InsetLyXType const type = 
74                                 translateLyXType(to_utf8(cmd.argument()));
75                         if (il.lyxtype() == type) {
76                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
77                                 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
78                         } else
79                                 return false;
80                 }
81                 // fall-through
82         default:
83                 return InsetCollapsable::getStatus(cur, cmd, flag);
84         }
85 }
86
87
88 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
89 {
90         switch (cmd.action()) {
91         case LFUN_INSET_DISSOLVE:
92                 if (!cmd.argument().empty()) {
93                         InsetLayout const & il = getLayout();
94                         InsetLayout::InsetLyXType const type = 
95                                 translateLyXType(to_utf8(cmd.argument()));
96                         
97                         if (il.lyxtype() == type) {
98                                 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
99                                 InsetCollapsable::doDispatch(cur, temp_cmd);
100                         } else
101                                 cur.undispatched();
102                         break;
103                 }
104                 // fall-through
105         default:
106                 InsetCollapsable::doDispatch(cur, cmd);
107                 break;
108         }
109 }
110
111
112 } // namespace lyx