]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlParagraph.C
You've had enough time for that ol' review and I've made sure that things
[lyx.git] / src / frontends / controllers / ControlParagraph.C
1 // -*- C++ -*-
2 /**
3  * \file ControlParagraph.C
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Edwin Leuven
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS
11  */
12
13 #include <config.h>
14
15 #include "ControlParagraph.h"
16 #include "ButtonController.h"
17 #include "funcrequest.h"
18 #include "lyxlex.h"
19 #include "ParagraphParameters.h"
20 #include "support/LAssert.h"
21 #include "Lsstream.h"
22
23
24 ControlParagraph::ControlParagraph(Dialog & parent)
25         : Dialog::Controller(parent), ininset_(false)
26 {}
27
28
29 void ControlParagraph::initialiseParams(string const & data)
30 {
31         istringstream is(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 {
52                         // Unrecognised token
53                         lyx::Assert(0);
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                 int Int = 0;
75                 if (token == "\\alignpossible" ||
76                     token == "\\aligndefault" ||
77                     token == "\\ininset") {
78                         lex.next();
79                         Int = lex.getInteger();
80                 } else {
81                         // Unrecognised token
82                         break;
83                 }
84                     
85                 ++nset;
86
87                 if (token == "\\alignpossible") {
88                         alignpossible_ = static_cast<LyXAlignment>(Int);
89                 } else if (token == "\\aligndefault") {
90                         aligndefault_ = static_cast<LyXAlignment>(Int);
91                 } else {
92                         ininset_ = Int;
93                 }
94         }
95         lyx::Assert(nset == 3);
96
97         // If "update", then set the activation status of the button controller
98         if (action > 0) {
99                 bool const accept = action == 1;
100                 dialog().bc().valid(accept);
101         }
102 }
103
104
105 void ControlParagraph::clearParams()
106 {
107         params_.reset();
108 }
109
110
111 void ControlParagraph::dispatchParams()
112 {
113         ostringstream data;
114         params().write(data);
115         FuncRequest const fr(LFUN_PARAGRAPH_APPLY, data.str());
116         kernel().dispatch(fr);
117 }
118
119
120 ParagraphParameters & ControlParagraph::params()
121 {
122         lyx::Assert(params_.get());
123         return *params_;
124 }
125
126
127 ParagraphParameters const & ControlParagraph::params() const
128 {
129         lyx::Assert(params_.get());
130         return *params_;
131 }
132
133
134 bool ControlParagraph::inInset() const
135 {
136         return ininset_;
137 }
138
139
140 LyXAlignment ControlParagraph::alignPossible() const
141 {
142         return alignpossible_;
143 }
144
145
146 LyXAlignment ControlParagraph::alignDefault() const
147 {
148         return aligndefault_;
149 }