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