-// -*- C++ -*-
/**
* \file ControlParagraph.C
- * Copyright 2002 The LyX Team.
- * See the file COPYING.
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
*
- * \author Edwin Leuven <leuven@fee.uva.nl>
+ * \author Edwin Leuven
+ * \author Angus Leeming
+ *
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "ControlParagraph.h"
-#include "ViewBase.h"
+#include "ButtonController.h"
+#include "funcrequest.h"
+#include "lyxlex.h"
#include "ParagraphParameters.h"
-#include "Liason.h"
-#include "LyXView.h"
-#include "BufferView.h"
-#include "gettext.h"
-#include "buffer.h"
-#include "lyxtext.h"
-#include "lyxtextclasslist.h"
#include "support/LAssert.h"
+#include "support/std_sstream.h"
-using Liason::setMinibuffer;
-
-
-ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
- : ControlDialogBD(lv, d), pp_(0), ininset_(false)
-{}
-
+using namespace lyx::support;
-ControlParagraph::~ControlParagraph()
+ControlParagraph::ControlParagraph(Dialog & parent)
+ : Dialog::Controller(parent), ininset_(false)
{}
-ParagraphParameters & ControlParagraph::params()
+bool ControlParagraph::initialiseParams(string const & data)
{
- lyx::Assert(pp_.get());
- return *pp_;
+ istringstream is(STRCONV(data));
+ 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;
+
+ 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;
+ } else if (!token.empty()) {
+ // Unrecognised token
+ return false;
+ }
+ }
+
+ 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();
+
+ if (token.empty())
+ continue;
+
+ int Int = 0;
+ if (token == "\\alignpossible" ||
+ token == "\\aligndefault" ||
+ token == "\\ininset") {
+ lex.next();
+ Int = lex.getInteger();
+ } else {
+ // Unrecognised token
+ return false;
+ }
+
+ ++nset;
+
+ if (token == "\\alignpossible") {
+ alignpossible_ = static_cast<LyXAlignment>(Int);
+ } else if (token == "\\aligndefault") {
+ aligndefault_ = static_cast<LyXAlignment>(Int);
+ } else {
+ ininset_ = Int;
+ }
+ }
+ if (nset != 3) {
+ return false;
+ }
+
+ // If "update", then set the activation status of the button controller
+ if (action > 0) {
+ bool const accept = action == 1;
+ dialog().bc().valid(accept);
+ }
+ return true;
}
-bool ControlParagraph::inInset() const
+void ControlParagraph::clearParams()
{
- return ininset_;
+ params_.reset();
}
-LyXAlignment ControlParagraph::alignPossible() const
+void ControlParagraph::dispatchParams()
{
- return alignpos_;
+ ostringstream data;
+ params().write(data);
+ FuncRequest const fr(LFUN_PARAGRAPH_APPLY, STRCONV(data.str()));
+ kernel().dispatch(fr);
}
-void ControlParagraph::apply()
+ParagraphParameters & ControlParagraph::params()
{
- if (!lv_.view()->available())
- return;
-
- view().apply();
-
- LyXText * text(lv_.view()->getLyXText());
- text->setParagraph(lv_.view(),
- pp_->lineTop(),
- pp_->lineBottom(),
- pp_->pagebreakTop(),
- pp_->pagebreakBottom(),
- pp_->spaceTop(),
- pp_->spaceBottom(),
- pp_->spacing(),
- pp_->align(),
- pp_->labelWidthString(),
- pp_->noindent());
-
- // Actually apply these settings
- lv_.view()->update(text,
- BufferView::SELECT |
- BufferView::FITCUR |
- BufferView::CHANGE);
-
- lv_.buffer()->markDirty();
-
- setMinibuffer(&lv_, _("Paragraph layout set"));
+ Assert(params_.get());
+ return *params_;
}
-void ControlParagraph::setParams()
+ParagraphParameters const & ControlParagraph::params() const
{
- if (!pp_.get())
- pp_.reset(new ParagraphParameters());
+ Assert(params_.get());
+ return *params_;
+}
- /// get paragraph
- Paragraph const * par_ = lv_.view()->getLyXText()->cursor.par();
- /// Set the paragraph parameters
- *pp_ = par_->params();
+bool ControlParagraph::inInset() const
+{
+ return ininset_;
+}
- /// this needs to be done separately
- pp_->labelWidthString(par_->getLabelWidthString());
- /// alignment
- LyXTextClass const & tclass =
- textclasslist[lv_.view()->buffer()->params.textclass];
- if (pp_->align() == LYX_ALIGN_LAYOUT)
- pp_->align(tclass[par_->layout()].align);
+LyXAlignment ControlParagraph::alignPossible() const
+{
+ return alignpossible_;
+}
- /// is alignment possible
- alignpos_ = tclass[par_->layout()].alignpossible;
- /// is paragraph in inset
- ininset_ = par_->inInset();
+LyXAlignment ControlParagraph::alignDefault() const
+{
+ return aligndefault_;
}