]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
std:: changes, stupid stuff
[lyx.git] / src / frontends / controllers / ControlParagraph.C
1 /**
2  * \file ControlParagraph.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "ControlParagraph.h"
15 #include "ButtonController.h"
16 #include "funcrequest.h"
17 #include "lyxlex.h"
18 #include "paragraph.h"
19 #include "ParagraphParameters.h"
20 #include "support/std_sstream.h"
21
22
23 using std::istringstream;
24 using std::ostringstream;
25 using std::string;
26
27
28 ControlParagraph::ControlParagraph(Dialog & parent)
29         : Dialog::Controller(parent), ininset_(false)
30 {}
31
32
33 bool ControlParagraph::initialiseParams(string const & data)
34 {
35         istringstream is(data);
36         LyXLex lex(0,0);
37         lex.setStream(is);
38
39         // Set tri-state flag:
40         // action == 0: show dialog
41         // action == 1: update dialog, accept changes
42         // action == 2: update dialog, do not accept changes
43         int action = 0;
44
45         if (lex.isOK()) {
46                 lex.next();
47                 string const token = lex.getString();
48
49                 if (token == "show") {
50                         action = 0;
51                 } else if (token == "update") {
52                         lex.next();
53                         bool const accept = lex.getBool();
54                         action = accept ? 1 : 2;
55                 } else if (!token.empty()) {
56                         // Unrecognised token
57                         return false;
58                 }
59         }
60
61         ParagraphParameters * tmp = new ParagraphParameters;
62         tmp->read(lex);
63
64         // For now, only reset the params on "show".
65         // Don't bother checking if the params are different on "update"
66         if (action == 0) {
67                 params_.reset(tmp);
68         } else {
69                 delete tmp;
70         }
71
72         // Read the rest of the data irrespective of "show" or "update"
73         int nset = 0;
74         while (lex.isOK()) {
75                 lex.next();
76                 string const token = lex.getString();
77
78                 if (token.empty())
79                         continue;
80
81                 int Int = 0;
82                 if (token == "\\alignpossible" ||
83                     token == "\\aligndefault" ||
84                     token == "\\ininset") {
85                         lex.next();
86                         Int = lex.getInteger();
87                 } else {
88                         // Unrecognised token
89                         return false;
90                 }
91
92                 ++nset;
93
94                 if (token == "\\alignpossible") {
95                         alignpossible_ = static_cast<LyXAlignment>(Int);
96                 } else if (token == "\\aligndefault") {
97                         aligndefault_ = static_cast<LyXAlignment>(Int);
98                 } else {
99                         ininset_ = Int;
100                 }
101         }
102         if (nset != 3) {
103                 return false;
104         }
105
106         // If "update", then set the activation status of the button controller
107         if (action > 0) {
108                 bool const accept = action == 1;
109                 dialog().bc().valid(accept);
110         }
111         return true;
112 }
113
114
115 void ControlParagraph::clearParams()
116 {
117         params_.reset();
118 }
119
120
121 void ControlParagraph::dispatchParams()
122 {
123         ostringstream data;
124         params().write(data);
125         FuncRequest const fr(LFUN_PARAGRAPH_APPLY, data.str());
126         kernel().dispatch(fr);
127 }
128
129
130 ParagraphParameters & ControlParagraph::params()
131 {
132         BOOST_ASSERT(params_.get());
133         return *params_;
134 }
135
136
137 ParagraphParameters const & ControlParagraph::params() const
138 {
139         BOOST_ASSERT(params_.get());
140         return *params_;
141 }
142
143
144 bool ControlParagraph::inInset() const
145 {
146         return ininset_;
147 }
148
149
150 LyXAlignment ControlParagraph::alignPossible() const
151 {
152         return alignpossible_;
153 }
154
155
156 LyXAlignment ControlParagraph::alignDefault() const
157 {
158         return aligndefault_;
159 }