#include "author.h"
#include "buffer.h"
+#include "buffer_funcs.h"
#include "bufferparams.h"
#include "BufferView.h"
#include "cursor.h"
&& align == LYX_ALIGN_BLOCK
&& !par.params().noindent()
// in charstyles, tabulars and ert paragraphs are never indented!
- && (par.ownerCode() != InsetBase::TEXT_CODE
+ && ((par.ownerCode() != InsetBase::TEXT_CODE || isMainText())
&& par.ownerCode() != InsetBase::ERT_CODE
&& par.ownerCode() != InsetBase::CHARSTYLE_CODE)
&& (par.layout() != tclass.defaultLayout()
maxasc += bufparams.getDefSkip().inPixels(*bv());
}
- if (pars_[pit].params().startOfAppendix())
+ if (par.params().startOfAppendix())
maxasc += int(3 * dh);
// This is special code for the chapter, since the label of this
// layout is printed in an extra row
- if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
+ if (layout->counter == "chapter"
+ && !par.params().labelString().empty()) {
labeladdon = int(font_metrics::maxHeight(labelfont)
* layout->spacing.getValue()
* spacing(par));
while (!pars_[next_par].empty() && pars_[next_par].isNewline(0))
pars_[next_par].erase(0);
- updateCounters();
+ updateCounters(cur.buffer());
// This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user!
// the cursor set functions have a special mechanism. When they
// realize, that you left an empty paragraph, they will delete it.
-void LyXText::cursorRightOneWord(LCursor & cur)
+bool LyXText::cursorRightOneWord(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
- if (cur.pos() == cur.lastpos() && cur.pit() != cur.lastpit()) {
- ++cur.pit();
- cur.pos() = 0;
+
+ LCursor old = cur;
+
+ if (old.pos() == old.lastpos() && old.pit() != old.lastpit()) {
+ ++old.pit();
+ old.pos() = 0;
} else {
// Skip through initial nonword stuff.
// Treat floats and insets as words.
- while (cur.pos() != cur.lastpos() && !cur.paragraph().isLetter(cur.pos()))
- ++cur.pos();
+ while (old.pos() != old.lastpos() && !old.paragraph().isLetter(old.pos()))
+ ++old.pos();
// Advance through word.
- while (cur.pos() != cur.lastpos() && cur.paragraph().isLetter(cur.pos()))
- ++cur.pos();
+ while (old.pos() != old.lastpos() && old.paragraph().isLetter(old.pos()))
+ ++old.pos();
}
- setCursor(cur, cur.pit(), cur.pos());
+ return setCursor(cur, old.pit(), old.pos());
}
-void LyXText::cursorLeftOneWord(LCursor & cur)
+bool LyXText::cursorLeftOneWord(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
- if (cur.pos() == 0 && cur.pit() != 0) {
- --cur.pit();
- cur.pos() = cur.lastpos();
+
+ LCursor old = cur;
+
+ if (old.pos() == 0 && old.pit() != 0) {
+ --old.pit();
+ old.pos() = old.lastpos();
} else {
// Skip through initial nonword stuff.
// Treat floats and insets as words.
- while (cur.pos() != 0 && !cur.paragraph().isLetter(cur.pos() - 1))
- --cur.pos();
+ while (old.pos() != 0 && !old.paragraph().isLetter(old.pos() - 1))
+ --old.pos();
// Advance through word.
- while (cur.pos() != 0 && cur.paragraph().isLetter(cur.pos() - 1))
- --cur.pos();
+ while (old.pos() != 0 && old.paragraph().isLetter(old.pos() - 1))
+ --old.pos();
}
- setCursor(cur, cur.pit(), cur.pos());
+ return setCursor(cur, old.pit(), old.pos());
}
--cur.pos();
// the counters may have changed
- updateCounters();
+ updateCounters(cur.buffer());
setCursor(cur, cur.pit(), cur.pos(), false);
}
} else {
}
-void LyXText::redoParagraph(pit_type const pit)
+bool LyXText::redoParagraph(pit_type const pit)
{
// remove rows of paragraph, keep track of height changes
Paragraph & par = pars_[pit];
+ // Add bibitem insets if necessary
+ if (par.layout()->labeltype == LABEL_BIBLIO) {
+ bool hasbibitem(false);
+ if (!par.insetlist.empty()
+ // Insist on it being in pos 0
+ && par.getChar(0) == Paragraph::META_INSET) {
+ InsetBase * inset = par.insetlist.begin()->inset;
+ if (inset->lyxCode() == InsetBase::BIBITEM_CODE)
+ hasbibitem = true;
+ }
+ if (!hasbibitem) {
+ InsetBibitem * inset(new
+ InsetBibitem(InsetCommandParams("bibitem")));
+ par.insertInset(0, static_cast<InsetBase *>(inset));
+ bv()->cursor().posRight();
+ }
+ }
+
// redo insets
InsetList::iterator ii = par.insetlist.begin();
InsetList::iterator iend = par.insetlist.end();
dim.asc += par.rows()[0].ascent();
dim.des -= par.rows()[0].ascent();
+
+ bool const same = dim == par.dim();
+
par.dim() = dim;
//lyxerr << "redoParagraph: " << par.rows().size() << " rows\n";
+
+ return !same;
}
maxwidth_ = mi.base.textwidth;
//lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
// << " maxWidth: " << maxwidth_ << "\nfont: " << mi.base.font << endl;
+ // save the caller's font locally:
+ font_ = mi.base.font;
unsigned int h = 0;
unsigned int w = 0;
pos_type LyXText::x2pos(pit_type pit, int row, int x) const
{
+ BOOST_ASSERT(row < pars_[pit].rows().size());
bool bound = false;
Row const & r = pars_[pit].rows()[row];
return r.pos() + getColumnNearX(pit, r, x, bound);