2002-06-11 16:40:18 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
|
|
|
* \file ControlParagraph.C
|
|
|
|
* Copyright 2002 The LyX Team.
|
|
|
|
* See the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Edwin Leuven <leuven@fee.uva.nl>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ControlParagraph.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2002-08-02 12:28:59 +00:00
|
|
|
#include "ButtonControllerBase.h"
|
2002-06-18 15:44:30 +00:00
|
|
|
#include "ViewBase.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
|
|
|
#include "buffer.h"
|
2002-06-11 16:40:18 +00:00
|
|
|
#include "BufferView.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyxtext.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
#include "ParagraphParameters.h"
|
|
|
|
|
|
|
|
#include "frontends/Dialogs.h"
|
|
|
|
#include "frontends/Liason.h"
|
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
#include "support/LAssert.h"
|
2002-08-14 19:19:47 +00:00
|
|
|
|
2002-08-02 12:28:59 +00:00
|
|
|
#include <boost/bind.hpp>
|
2002-06-11 16:40:18 +00:00
|
|
|
|
|
|
|
using Liason::setMinibuffer;
|
|
|
|
|
|
|
|
|
|
|
|
ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d)
|
|
|
|
: ControlDialogBD(lv, d), pp_(0), ininset_(false)
|
2002-08-02 12:28:59 +00:00
|
|
|
{
|
2002-08-14 19:19:47 +00:00
|
|
|
d_.updateParagraph.connect(
|
|
|
|
boost::bind(&ControlParagraph::changedParagraph, this));
|
2002-08-02 12:28:59 +00:00
|
|
|
}
|
2002-06-11 16:40:18 +00:00
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
|
|
|
ControlParagraph::~ControlParagraph()
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
ParagraphParameters & ControlParagraph::params()
|
|
|
|
{
|
|
|
|
lyx::Assert(pp_.get());
|
|
|
|
return *pp_;
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
bool ControlParagraph::inInset() const
|
|
|
|
{
|
|
|
|
return ininset_;
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
LyXAlignment ControlParagraph::alignPossible() const
|
|
|
|
{
|
|
|
|
return alignpos_;
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
void ControlParagraph::apply()
|
|
|
|
{
|
2002-08-12 20:17:41 +00:00
|
|
|
if (!bufferIsAvailable())
|
2002-06-11 16:40:18 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
view().apply();
|
|
|
|
|
2002-08-12 20:17:41 +00:00
|
|
|
LyXText * text(bufferview()->getLyXText());
|
|
|
|
text->setParagraph(bufferview(),
|
2002-06-11 16:40:18 +00:00
|
|
|
pp_->lineTop(),
|
|
|
|
pp_->lineBottom(),
|
|
|
|
pp_->pagebreakTop(),
|
|
|
|
pp_->pagebreakBottom(),
|
|
|
|
pp_->spaceTop(),
|
|
|
|
pp_->spaceBottom(),
|
|
|
|
pp_->spacing(),
|
|
|
|
pp_->align(),
|
|
|
|
pp_->labelWidthString(),
|
|
|
|
pp_->noindent());
|
|
|
|
|
|
|
|
// Actually apply these settings
|
2002-08-12 20:17:41 +00:00
|
|
|
bufferview()->update(text,
|
|
|
|
BufferView::SELECT |
|
|
|
|
BufferView::FITCUR |
|
|
|
|
BufferView::CHANGE);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-08-12 20:17:41 +00:00
|
|
|
buffer()->markDirty();
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
setMinibuffer(&lv_, _("Paragraph layout set"));
|
|
|
|
}
|
|
|
|
|
2002-06-12 14:27:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
void ControlParagraph::setParams()
|
|
|
|
{
|
|
|
|
if (!pp_.get())
|
|
|
|
pp_.reset(new ParagraphParameters());
|
|
|
|
|
|
|
|
/// get paragraph
|
2002-08-12 20:17:41 +00:00
|
|
|
Paragraph const * par_ = bufferview()->getLyXText()->cursor.par();
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
/// Set the paragraph parameters
|
2002-06-18 15:44:30 +00:00
|
|
|
*pp_ = par_->params();
|
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
/// this needs to be done separately
|
|
|
|
pp_->labelWidthString(par_->getLabelWidthString());
|
2002-06-18 15:44:30 +00:00
|
|
|
|
2002-06-11 16:40:18 +00:00
|
|
|
/// alignment
|
2002-06-24 20:28:12 +00:00
|
|
|
LyXLayout_ptr const & layout = par_->layout();
|
2002-06-11 16:40:18 +00:00
|
|
|
if (pp_->align() == LYX_ALIGN_LAYOUT)
|
2002-06-24 20:28:12 +00:00
|
|
|
pp_->align(layout->align);
|
2002-06-11 16:40:18 +00:00
|
|
|
|
|
|
|
/// is alignment possible
|
2002-06-24 20:28:12 +00:00
|
|
|
alignpos_ = layout->alignpossible;
|
2002-06-11 16:40:18 +00:00
|
|
|
|
|
|
|
/// is paragraph in inset
|
2002-06-18 15:44:30 +00:00
|
|
|
ininset_ = par_->inInset();
|
2002-06-11 16:40:18 +00:00
|
|
|
}
|
2002-08-02 12:28:59 +00:00
|
|
|
|
|
|
|
void ControlParagraph::changedParagraph()
|
|
|
|
{
|
|
|
|
/// get paragraph
|
2002-08-12 20:17:41 +00:00
|
|
|
Paragraph const * p = bufferview()->getLyXText()->cursor.par();
|
2002-08-02 12:28:59 +00:00
|
|
|
|
|
|
|
if (p == 0) // this is wrong as we don't set par_ here! /* || p == par_) */
|
|
|
|
return;
|
|
|
|
|
|
|
|
// For now, don't bother checking if the params are different.
|
|
|
|
// Will the underlying paragraph accept our changes?
|
|
|
|
Inset * const inset = p->inInset();
|
|
|
|
bool const accept = !(inset && inset->forceDefaultParagraphs(inset));
|
|
|
|
bc().valid(accept);
|
|
|
|
}
|