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