2002-06-11 16:40:18 +00:00
|
|
|
/**
|
|
|
|
* \file ControlParagraph.C
|
2002-09-05 15:14:23 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-06-11 16:40:18 +00:00
|
|
|
*
|
2002-10-20 01:48:28 +00:00
|
|
|
* \author Edwin Leuven
|
2003-03-13 13:56:25 +00:00
|
|
|
* \author Angus Leeming
|
2002-09-05 14:10:50 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-06-11 16:40:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "ControlParagraph.h"
|
2003-03-10 03:13:28 +00:00
|
|
|
#include "ButtonController.h"
|
2003-03-13 13:56:25 +00:00
|
|
|
#include "funcrequest.h"
|
|
|
|
#include "lyxlex.h"
|
2003-09-06 12:36:58 +00:00
|
|
|
#include "paragraph.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "ParagraphParameters.h"
|
2003-09-05 17:23:11 +00:00
|
|
|
#include "support/std_sstream.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2003-09-05 18:02:24 +00:00
|
|
|
using std::istringstream;
|
|
|
|
using std::ostringstream;
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
ControlParagraph::ControlParagraph(Dialog & parent)
|
|
|
|
: Dialog::Controller(parent), ininset_(false)
|
2002-08-15 17:48:53 +00:00
|
|
|
{}
|
2002-06-11 16:40:18 +00:00
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2003-03-14 00:20:42 +00:00
|
|
|
bool ControlParagraph::initialiseParams(string const & data)
|
2002-06-11 16:40:18 +00:00
|
|
|
{
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream is(data);
|
2003-03-13 13:56:25 +00:00
|
|
|
LyXLex lex(0,0);
|
|
|
|
lex.setStream(is);
|
|
|
|
|
|
|
|
// Set tri-state flag:
|
|
|
|
// action == 0: show dialog
|
|
|
|
// action == 1: update dialog, accept changes
|
|
|
|
// action == 2: update dialog, do not accept changes
|
|
|
|
int action = 0;
|
2003-03-14 00:20:42 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
|
|
|
if (token == "show") {
|
|
|
|
action = 0;
|
|
|
|
} else if (token == "update") {
|
|
|
|
lex.next();
|
|
|
|
bool const accept = lex.getBool();
|
|
|
|
action = accept ? 1 : 2;
|
2003-03-18 21:26:52 +00:00
|
|
|
} else if (!token.empty()) {
|
2003-03-13 13:56:25 +00:00
|
|
|
// Unrecognised token
|
2003-03-14 00:20:42 +00:00
|
|
|
return false;
|
2003-03-13 13:56:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ParagraphParameters * tmp = new ParagraphParameters;
|
|
|
|
tmp->read(lex);
|
|
|
|
|
|
|
|
// For now, only reset the params on "show".
|
|
|
|
// Don't bother checking if the params are different on "update"
|
|
|
|
if (action == 0) {
|
|
|
|
params_.reset(tmp);
|
|
|
|
} else {
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read the rest of the data irrespective of "show" or "update"
|
|
|
|
int nset = 0;
|
|
|
|
while (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
|
2003-03-18 21:26:52 +00:00
|
|
|
if (token.empty())
|
|
|
|
continue;
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
int Int = 0;
|
|
|
|
if (token == "\\alignpossible" ||
|
|
|
|
token == "\\aligndefault" ||
|
|
|
|
token == "\\ininset") {
|
|
|
|
lex.next();
|
|
|
|
Int = lex.getInteger();
|
|
|
|
} else {
|
|
|
|
// Unrecognised token
|
2003-03-14 00:20:42 +00:00
|
|
|
return false;
|
2003-03-13 13:56:25 +00:00
|
|
|
}
|
2003-03-14 00:20:42 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
++nset;
|
|
|
|
|
|
|
|
if (token == "\\alignpossible") {
|
|
|
|
alignpossible_ = static_cast<LyXAlignment>(Int);
|
|
|
|
} else if (token == "\\aligndefault") {
|
|
|
|
aligndefault_ = static_cast<LyXAlignment>(Int);
|
|
|
|
} else {
|
|
|
|
ininset_ = Int;
|
|
|
|
}
|
|
|
|
}
|
2003-03-18 21:26:52 +00:00
|
|
|
if (nset != 3) {
|
2003-03-14 00:20:42 +00:00
|
|
|
return false;
|
2003-03-18 21:26:52 +00:00
|
|
|
}
|
2003-03-13 13:56:25 +00:00
|
|
|
|
|
|
|
// If "update", then set the activation status of the button controller
|
|
|
|
if (action > 0) {
|
|
|
|
bool const accept = action == 1;
|
|
|
|
dialog().bc().valid(accept);
|
|
|
|
}
|
2003-03-14 00:20:42 +00:00
|
|
|
return true;
|
2002-06-11 16:40:18 +00:00
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
void ControlParagraph::clearParams()
|
2002-06-11 16:40:18 +00:00
|
|
|
{
|
2003-03-13 13:56:25 +00:00
|
|
|
params_.reset();
|
2002-06-11 16:40:18 +00:00
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
void ControlParagraph::dispatchParams()
|
2002-06-11 16:40:18 +00:00
|
|
|
{
|
2003-03-13 13:56:25 +00:00
|
|
|
ostringstream data;
|
|
|
|
params().write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
FuncRequest const fr(LFUN_PARAGRAPH_APPLY, data.str());
|
2003-03-13 13:56:25 +00:00
|
|
|
kernel().dispatch(fr);
|
2002-10-30 13:57:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
ParagraphParameters & ControlParagraph::params()
|
2002-10-30 13:57:01 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(params_.get());
|
2003-03-13 13:56:25 +00:00
|
|
|
return *params_;
|
2002-06-11 16:40:18 +00:00
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
ParagraphParameters const & ControlParagraph::params() const
|
2002-06-11 16:40:18 +00:00
|
|
|
{
|
2003-09-09 17:25:35 +00:00
|
|
|
BOOST_ASSERT(params_.get());
|
2003-03-13 13:56:25 +00:00
|
|
|
return *params_;
|
2002-06-11 16:40:18 +00:00
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
bool ControlParagraph::inInset() const
|
2002-06-11 16:40:18 +00:00
|
|
|
{
|
2003-03-13 13:56:25 +00:00
|
|
|
return ininset_;
|
2002-06-11 16:40:18 +00:00
|
|
|
}
|
2002-08-02 12:28:59 +00:00
|
|
|
|
2002-10-21 17:38:09 +00:00
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
LyXAlignment ControlParagraph::alignPossible() const
|
2002-08-02 12:28:59 +00:00
|
|
|
{
|
2003-03-13 13:56:25 +00:00
|
|
|
return alignpossible_;
|
|
|
|
}
|
2002-08-02 12:28:59 +00:00
|
|
|
|
|
|
|
|
2003-03-13 13:56:25 +00:00
|
|
|
LyXAlignment ControlParagraph::alignDefault() const
|
|
|
|
{
|
|
|
|
return aligndefault_;
|
2002-08-02 12:28:59 +00:00
|
|
|
}
|