]> git.lyx.org Git - lyx.git/blob - src/bufferview_funcs.C
split LyXFunc::getStatus() into inset specific chunks
[lyx.git] / src / bufferview_funcs.C
1 /**
2  * \file bufferview_funcs.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  * \author Angus Leeming
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #include <config.h>
15
16 #include "bufferview_funcs.h"
17
18 #include "author.h"
19 #include "buffer.h"
20 #include "bufferparams.h"
21 #include "BufferView.h"
22 #include "cursor.h"
23 #include "gettext.h"
24 #include "language.h"
25 #include "LColor.h"
26 #include "lyxlex.h"
27 #include "lyxrow.h"
28 #include "paragraph.h"
29 #include "ParagraphParameters.h"
30 #include "iterators.h"
31
32 #include "frontends/Alert.h"
33 #include "frontends/LyXView.h"
34
35 #include "insets/insettext.h"
36
37 #include "support/tostr.h"
38 #include "support/std_sstream.h"
39
40 using lyx::support::bformat;
41
42 using std::istringstream;
43 using std::ostringstream;
44 using std::string;
45
46
47 namespace bv_funcs {
48
49 // Set data using font and toggle
50 // If successful, returns true
51 bool font2string(LyXFont const & font, bool toggle, string & data)
52 {
53         string lang = "ignore";
54         if (font.language())
55                 lang = font.language()->lang();
56
57         ostringstream os;
58         os << "family " << font.family() << '\n'
59            << "series " << font.series() << '\n'
60            << "shape " << font.shape() << '\n'
61            << "size " << font.size() << '\n'
62            << "emph " << font.emph() << '\n'
63            << "underbar " << font.underbar() << '\n'
64            << "noun " << font.noun() << '\n'
65            << "number " << font.number() << '\n'
66            << "color " << font.color() << '\n'
67            << "language " << lang << '\n'
68            << "toggleall " << tostr(toggle);
69         data = os.str();
70         return true;
71 }
72
73
74 // Set font and toggle using data
75 // If successful, returns true
76 bool string2font(string const & data, LyXFont & font, bool & toggle)
77 {
78         istringstream is(data);
79         LyXLex lex(0,0);
80         lex.setStream(is);
81
82         int nset = 0;
83         while (lex.isOK()) {
84                 string token;
85                 if (lex.next())
86                         token = lex.getString();
87
88                 if (token.empty() || !lex.next())
89                         break;
90
91                 if (token == "family") {
92                         int const next = lex.getInteger();
93                         font.setFamily(LyXFont::FONT_FAMILY(next));
94
95                 } else if (token == "series") {
96                         int const next = lex.getInteger();
97                         font.setSeries(LyXFont::FONT_SERIES(next));
98
99                 } else if (token == "shape") {
100                         int const next = lex.getInteger();
101                         font.setShape(LyXFont::FONT_SHAPE(next));
102
103                 } else if (token == "size") {
104                         int const next = lex.getInteger();
105                         font.setSize(LyXFont::FONT_SIZE(next));
106
107                 } else if (token == "emph" || token == "underbar" ||
108                            token == "noun" || token == "number") {
109
110                         int const next = lex.getInteger();
111                         LyXFont::FONT_MISC_STATE const misc =
112                                 LyXFont::FONT_MISC_STATE(next);
113
114                         if (token == "emph")
115                             font.setEmph(misc);
116                         else if (token == "underbar")
117                                 font.setUnderbar(misc);
118                         else if (token == "noun")
119                                 font.setNoun(misc);
120                         else if (token == "number")
121                                 font.setNumber(misc);
122
123                 } else if (token == "color") {
124                         int const next = lex.getInteger();
125                         font.setColor(LColor::color(next));
126
127                 } else if (token == "language") {
128                         string const next = lex.getString();
129                         if (next == "ignore")
130                                 font.setLanguage(ignore_language);
131                         else
132                                 font.setLanguage(languages.getLanguage(next));
133
134                 } else if (token == "toggleall") {
135                         toggle = lex.getBool();
136
137                 } else {
138                         // Unrecognised token
139                         break;
140                 }
141
142                 ++nset;
143         }
144         return (nset > 0);
145 }
146
147 } // namespace bv_funcs