From 2bdaf96dfbcb95931a21ca7377f3dc24e3f5ea8d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 8 Apr 2004 15:03:33 +0000 Subject: [PATCH] the Paragraph::inInset() changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8632 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Bidi.C | 4 +- src/ChangeLog | 14 ++++++ src/CutAndPaste.C | 14 +++--- src/ParagraphParameters.C | 4 +- src/buffer.C | 3 +- src/cursor.C | 9 ++++ src/cursor.h | 5 ++- src/frontends/qt2/QGraphics.C | 11 ++--- src/insets/insetbase.C | 8 ++++ src/insets/insetbranch.C | 3 +- src/insets/insetexternal.C | 5 ++- src/insets/insetfloat.C | 4 +- src/insets/insetgraphics.C | 2 +- src/insets/insetinclude.C | 2 +- src/insets/insettabular.C | 6 +-- src/insets/insettext.C | 2 +- src/insets/insettext.h | 4 +- src/mathed/math_mathmlstream.C | 1 + src/mathed/math_mathmlstream.h | 2 +- src/mathed/math_mboxinset.C | 19 ++++++-- src/mathed/math_nestinset.C | 11 ++--- src/output_latex.C | 9 ++-- src/outputparams.h | 29 +++++++------ src/paragraph.C | 79 ++++++++++++++++------------------ src/paragraph.h | 10 ++++- src/text.C | 45 ++++++++++--------- src/text2.C | 31 +++++++------ src/text3.C | 12 +++--- 28 files changed, 197 insertions(+), 151 deletions(-) diff --git a/src/Bidi.C b/src/Bidi.C index e469270558..db4775449b 100644 --- a/src/Bidi.C +++ b/src/Bidi.C @@ -17,7 +17,6 @@ #include "lyxrc.h" #include "paragraph.h" -#include "insets/updatableinset.h" using lyx::pos_type; @@ -60,8 +59,7 @@ void Bidi::computeTables(Paragraph const & par, return; } - InsetOld * inset = par.inInset(); - if (inset && inset->lyxCode() == InsetOld::ERT_CODE) { + if (par.ownerCode() == InsetBase::ERT_CODE) { start_ = -1; return; } diff --git a/src/ChangeLog b/src/ChangeLog index ac5df78442..967af69f7f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -62,6 +62,20 @@ * lyxfunc.C (dispatch): output lyxrc.write("preferences", false). +2004-04-07 André Pönitz + + * cursor.[Ch] (selClear, adjust): remove math + + * cursor_slice.C: more agressive assert + + * lyxfunc.C: + * BufferView_pimpl.C: rework mouse event dispatch + + * dociterator.C: + * paragraph.C: + * text2.C: + * text3.C: adjust + 2004-04-05 André Pönitz * cursor.[Ch] (valign, halign...): remove unneeded functions diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 8202bb0ed4..0cd4a1a334 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -416,7 +416,7 @@ void cutSelection(LCursor & cur, bool doclear, bool realcut) int endpos = cur.selEnd().pos(); - BufferParams const & bufparams = cur.bv().buffer()->params(); + BufferParams const & bufparams = cur.buffer().params(); boost::tie(endpit, endpos) = realcut ? cutSelection(bufparams, text->paragraphs(), @@ -470,7 +470,7 @@ void copySelection(LCursor & cur) ++pos; copySelection(pars, par, cur.selEnd().par(), - pos, cur.selEnd().pos(), cur.bv().buffer()->params().textclass); + pos, cur.selEnd().pos(), cur.buffer().params().textclass); } @@ -490,13 +490,13 @@ void pasteSelection(LCursor & cur, size_t sel_index) ErrorList el; boost::tie(ppp, endpit) = - pasteSelection(*cur.bv().buffer(), + pasteSelection(cur.buffer(), text->paragraphs(), cur.par(), cur.pos(), - cur.bv().buffer()->params().textclass, + cur.buffer().params().textclass, sel_index, el); - bufferErrors(*cur.bv().buffer(), el); - text->bv()->showErrorList(_("Paste")); + bufferErrors(cur.buffer(), el); + cur.bv().showErrorList(_("Paste")); text->redoParagraphs(cur.par(), endpit); @@ -531,7 +531,7 @@ void replaceSelectionWithString(LCursor & cur, string const & str) // Get font setting before we cut pos_type pos = cur.selEnd().pos(); LyXFont const font = text->getPar(cur.selBegin().par()). - getFontSettings(cur.bv().buffer()->params(), cur.selBegin().pos()); + getFontSettings(cur.buffer().params(), cur.selBegin().pos()); // Insert the new string string::const_iterator cit = str.begin(); diff --git a/src/ParagraphParameters.C b/src/ParagraphParameters.C index 9f7343d5a1..7f4ecfcdb9 100644 --- a/src/ParagraphParameters.C +++ b/src/ParagraphParameters.C @@ -281,8 +281,8 @@ void params2string(Paragraph const & par, string & data) /// set default alignment os << "\\aligndefault " << layout->align << '\n'; - /// is paragraph in inset - os << "\\ininset " << (par.inInset()?1:0) << '\n'; + /// paragraph is always in inset. This is redundant. + os << "\\ininset " << 1 << '\n'; data = os.str(); } diff --git a/src/buffer.C b/src/buffer.C index 293b134b48..d16d74ed22 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -456,8 +456,7 @@ void Buffer::insertStringAsLines(ParagraphList & pars, pars[par].checkInsertChar(font); // insert the string, don't insert doublespace bool space_inserted = true; - bool autobreakrows = !pars[par].inInset() || - static_cast(pars[par].inInset())->getAutoBreakRows(); + bool autobreakrows = pars[par].autoBreakRows(); for (string::const_iterator cit = str.begin(); cit != str.end(); ++cit) { if (*cit == '\n') { diff --git a/src/cursor.C b/src/cursor.C index 4642a2ee3a..8ca2bd906c 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -172,10 +172,19 @@ bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status) BufferView & LCursor::bv() const { + BOOST_ASSERT(bv_); return *bv_; } +Buffer & LCursor::buffer() const +{ + BOOST_ASSERT(bv_); + BOOST_ASSERT(bv_->buffer()); + return *bv_->buffer(); +} + + void LCursor::pop() { BOOST_ASSERT(size() >= 1); diff --git a/src/cursor.h b/src/cursor.h index 6a60cbcd12..16ae747aa5 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -18,6 +18,7 @@ #include #include +class Buffer; class BufferView; class FuncStatus; class FuncRequest; @@ -146,6 +147,8 @@ public: void resetAnchor(); /// access to owning BufferView BufferView & bv() const; + /// access to owning Buffer + Buffer & buffer() const; /// get some interesting description of top position void info(std::ostream & os) const; /// are we in math mode (2), text mode (1) or unsure (0)? @@ -155,8 +158,6 @@ public: void reset(InsetBase &); /// for spellchecking void replaceWord(std::string const & replacestring); - /// update our view - void update(); /// the event was not (yet) dispatched void undispatched(); /// the event was already dispatched diff --git a/src/frontends/qt2/QGraphics.C b/src/frontends/qt2/QGraphics.C index 7b691f6cff..57613355b9 100644 --- a/src/frontends/qt2/QGraphics.C +++ b/src/frontends/qt2/QGraphics.C @@ -349,11 +349,11 @@ void QGraphics::apply() if (!dialog_->displayCB->isChecked()) igp.display = lyx::graphics::NoDisplay; - string value(fromqstr(dialog_->width->text())); + string value = fromqstr(dialog_->width->text()); if (dialog_->widthUnit->currentItem() > 0) { // width/height combination - int const unitNo = getUnitNo(unit_name_gui, - fromqstr(dialog_->widthUnit->currentText())); + QString const text = dialog_->widthUnit->currentText(); + int const unitNo = getUnitNo(unit_name_gui, fromqstr(text)); igp.width = LyXLength(value + unit_name_ltx[unitNo]); igp.scale = 0.0; } else { @@ -362,8 +362,8 @@ void QGraphics::apply() igp.width = LyXLength(); } value = fromqstr(dialog_->height->text()); - int const unitNo = getUnitNo(unit_name_gui, - fromqstr(dialog_->heightUnit->currentText())); + QString text = dialog_->heightUnit->currentText(); + int const unitNo = getUnitNo(unit_name_gui, fromqstr(text)); igp.height = LyXLength(value + unit_name_ltx[unitNo]); igp.keepAspectRatio = dialog_->aspectratio->isChecked(); @@ -373,6 +373,7 @@ void QGraphics::apply() igp.lyxscale = strToInt(fromqstr(dialog_->displayscale->text())); igp.rotateAngle = strToDbl(fromqstr(dialog_->angle->text())); +#warning Guess what happens if the user enters '1e30' here? while (igp.rotateAngle < -360.0) igp.rotateAngle += 360.0; while (igp.rotateAngle > 360.0) diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 45d957ab34..d08c3459c2 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -27,6 +27,7 @@ #include + namespace { struct InsetName { @@ -36,8 +37,10 @@ struct InsetName { InsetBase::Code code; }; + typedef std::map TranslatorMap; + TranslatorMap const build_translator() { InsetName const insetnames[] = { @@ -285,6 +288,11 @@ bool InsetBase::editing(BufferView * bv) const bool InsetBase::covers(int x, int y) const { + //lyxerr << "InsetBase::covers, x: " << x << " y: " << y + // << " xo: " << xo() << " yo: " << yo() + // << " x1: " << xo() << " x2: " << xo() + width() + // << " y1: " << yo() - ascent() << " y2: " << yo() + descent() + // << std::endl; return x >= xo() && x <= xo() + width() && y >= yo() - ascent() diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index a8909d5a07..ac64ed5dc3 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -13,7 +13,6 @@ #include "insetbranch.h" #include "buffer.h" -#include "BufferView.h" #include "bufferparams.h" #include "BranchList.h" #include "cursor.h" @@ -162,7 +161,7 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd) } else if (cmd.argument == "assign" || cmd.argument.empty()) { BranchList const & branchlist = - cur.bv().buffer()->params().branchlist(); + cur.buffer().params().branchlist(); if (isBranchSelected(branchlist)) { if (status() != Open) setStatus(Open); diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index d4e1796402..5dd6895c4d 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -447,7 +447,7 @@ void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd) switch (cmd.action) { case LFUN_EXTERNAL_EDIT: { - Buffer const & buffer = *cur.bv().buffer(); + Buffer const & buffer = cur.buffer(); InsetExternalParams p; InsetExternalMailer::string2params(cmd.argument, buffer, p); external::editExternal(p, buffer); @@ -455,10 +455,11 @@ void InsetExternal::priv_dispatch(LCursor & cur, FuncRequest & cmd) } case LFUN_INSET_MODIFY: { - Buffer const & buffer = *cur.bv().buffer(); + Buffer const & buffer = cur.buffer(); InsetExternalParams p; InsetExternalMailer::string2params(cmd.argument, buffer, p); setParams(p, buffer); +#warning is this needed? cur.bv().update(); break; } diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index 9f2aa8d9fd..41da3b33a9 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -163,8 +163,8 @@ void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd) params_.placement = params.placement; params_.wide = params.wide; params_.sideways = params.sideways; - wide(params_.wide, cur.bv().buffer()->params()); - sideways(params_.sideways, cur.bv().buffer()->params()); + wide(params_.wide, cur.buffer().params()); + sideways(params_.sideways, cur.buffer().params()); cur.bv().update(); break; } diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 730ddc4202..020f7de958 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -191,7 +191,7 @@ void InsetGraphics::priv_dispatch(LCursor & cur, FuncRequest & cmd) { switch (cmd.action) { case LFUN_INSET_MODIFY: { - Buffer const & buffer = *cur.bv().buffer(); + Buffer const & buffer = cur.buffer(); InsetGraphicsParams p; InsetGraphicsMailer::string2params(cmd.argument, buffer, p); if (!p.filename.empty()) { diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 62a9ee0212..675f80e795 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -125,7 +125,7 @@ void InsetInclude::priv_dispatch(LCursor & cur, FuncRequest & cmd) InsetCommandParams p; InsetIncludeMailer::string2params(cmd.argument, p); if (!p.getCmdName().empty()) { - set(p, *cur.bv().buffer()); + set(p, cur.buffer()); cur.bv().update(); } break; diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 063d329c0e..983be07164 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -631,7 +631,7 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd) maxCols = max(cols, maxCols); paste_tabular.reset( - new LyXTabular(cur.bv().buffer()->params(), rows, maxCols)); + new LyXTabular(cur.buffer().params(), rows, maxCols)); string::size_type op = 0; int cell = 0; @@ -1500,7 +1500,7 @@ bool InsetTabular::copySelection(LCursor & cur) ostringstream os; OutputParams const runparams; - paste_tabular->plaintext(*cur.bv().buffer(), os, runparams, 0, true, '\t'); + paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t'); cur.bv().stuffClipboard(os.str()); return true; } @@ -1544,7 +1544,7 @@ void InsetTabular::cutSelection(LCursor & cur) if (!cur.selection()) return; - bool const track = cur.bv().buffer()->params().tracking_changes; + bool const track = cur.buffer().params().tracking_changes; int rs, re, cs, ce; getSelection(cur, rs, re, cs, ce); for (int i = rs; i <= re; ++i) diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 139e4e8884..735c96e2fb 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -249,7 +249,7 @@ void InsetText::updateLocal(LCursor & cur) } cur.clearSelection(); - mergeParagraph(cur.bv().buffer()->params(), paragraphs(), 0); + mergeParagraph(cur.buffer().params(), paragraphs(), 0); } } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 907fc179a8..87e1153bc3 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -81,10 +81,10 @@ public: OutputParams const &) const; /// int linuxdoc(Buffer const &, std::ostream &, - OutputParams const &) const ; + OutputParams const &) const; /// int docbook(Buffer const &, std::ostream &, - OutputParams const &) const ; + OutputParams const &) const; /// void validate(LaTeXFeatures & features) const; /// diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index 88495f63cf..9f538ab799 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -30,6 +30,7 @@ namespace { } + WriteStream::WriteStream(ostream & os, bool fragile, bool latex) : os_(os), fragile_(fragile), firstitem_(false), latex_(latex), pendingspace_(false), line_(0) diff --git a/src/mathed/math_mathmlstream.h b/src/mathed/math_mathmlstream.h index 1a4ee55e73..6e60ff6c64 100644 --- a/src/mathed/math_mathmlstream.h +++ b/src/mathed/math_mathmlstream.h @@ -34,7 +34,7 @@ public: /// WriteStream(std::ostream & os, bool fragile, bool latex); /// - explicit WriteStream(std::ostream & os_); + explicit WriteStream(std::ostream & os); /// ~WriteStream(); /// diff --git a/src/mathed/math_mboxinset.C b/src/mathed/math_mboxinset.C index 11ed0a7968..083860cfa3 100644 --- a/src/mathed/math_mboxinset.C +++ b/src/mathed/math_mboxinset.C @@ -20,6 +20,7 @@ #include "debug.h" #include "metricsinfo.h" #include "output_latex.h" +#include "outputparams.h" #include "paragraph.h" #include "texrow.h" @@ -59,11 +60,21 @@ void MathMBoxInset::draw(PainterInfo & pi, int x, int y) const } -void MathMBoxInset::write(WriteStream & os) const +void MathMBoxInset::write(WriteStream & ws) const { - os << "\\mbox{\n"; - text_.write(*bv_->buffer(), os.os()); - os << "}"; + if (ws.latex()) { + ws << "\\mbox{\n"; + TexRow texrow; + OutputParams runparams; + latexParagraphs(*bv_->buffer(), text_.paragraphs(), + ws.os(), texrow, runparams); + ws.addlines(texrow.rows()); + ws << "}"; + } else { + ws << "\\mbox{\n"; + text_.write(*bv_->buffer(), ws.os()); + ws << "}"; + } } diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 4fc2f94a3d..9c6552c43f 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -313,16 +313,17 @@ int MathNestInset::latex(Buffer const &, std::ostream & os, void MathNestInset::notifyCursorLeaves(LCursor & cur) { -/* +#warning look here +#if 0 MathArray & ar = cur.cell(); // remove base-only "scripts" for (pos_type i = 0; i + 1 < size(); ++i) { MathScriptInset * p = operator[](i).nucleus()->asScriptInset(); - if (p && p->cell(0).empty() && p->cell(1).empty()) { + if (p && p->nargs() == 1) { MathArray ar = p->nuc(); erase(i); insert(i, ar); - mathcursor->adjust(i, ar.size() - 1); + cur.adjust(i, ar.size() - 1); } } @@ -333,10 +334,10 @@ void MathNestInset::notifyCursorLeaves(LCursor & cur) if (p && q && p->name() == q->name()) { p->cell(0).append(q->cell(0)); erase(i + 1); - mathcursor->adjust(i, -1); + cur.adjust(i, -1); } } -*/ +#endif } diff --git a/src/output_latex.C b/src/output_latex.C index 5863c127f0..7b645ce9a0 100644 --- a/src/output_latex.C +++ b/src/output_latex.C @@ -214,8 +214,6 @@ TeXOnePar(Buffer const & buf, lyxerr[Debug::LATEX] << "TeXOnePar... " << &*pit << " '" << everypar << "'" << endl; BufferParams const & bparams = buf.params(); - - InsetOld const * in = pit->inInset(); bool further_blank_line = false; LyXLayout_ptr style; @@ -223,7 +221,7 @@ TeXOnePar(Buffer const & buf, // length (all in one row) if that is true then we don't allow // any special options in the paragraph and also we don't allow // any environment other then "Standard" to be valid! - if (in == 0 || !in->forceDefaultParagraphs(in)) { + if (!pit->forceDefaultParagraphs()) { style = pit->layout(); if (pit->params().startOfAppendix()) { @@ -383,7 +381,7 @@ paragraphs); } } - if (in == 0 || !in->forceDefaultParagraphs(in)) { + if (!pit->forceDefaultParagraphs()) { further_blank_line = false; if (further_blank_line) { @@ -447,12 +445,11 @@ void latexParagraphs(Buffer const & buf, // if only_body while (par != endpar) { - InsetOld * in = par->inInset(); // well we have to check if we are in an inset with unlimited // length (all in one row) if that is true then we don't allow // any special options in the paragraph and also we don't allow // any environment other then "Standard" to be valid! - if (in == 0 || !in->forceDefaultParagraphs(in)) { + if (!par->forceDefaultParagraphs()) { LyXLayout_ptr const & layout = par->layout(); if (layout->intitle) { diff --git a/src/outputparams.h b/src/outputparams.h index d3fa4b2f0a..8071f2454e 100644 --- a/src/outputparams.h +++ b/src/outputparams.h @@ -14,21 +14,24 @@ #include "support/types.h" + struct OutputParams { - enum FLAVOR { - LATEX, - PDFLATEX - }; + // + enum FLAVOR { + LATEX, + PDFLATEX + }; - OutputParams() : flavor(LATEX), nice(false), - moving_arg(false), free_spacing(false), - use_babel(false), mixed_content(false), - linelen(0) {} + OutputParams() + : flavor(LATEX), nice(false), moving_arg(false), + free_spacing(false), use_babel(false), + mixed_content(false), linelen(0) + {} /** The latex that we export depends occasionally on what is to compile the file. */ - FLAVOR flavor; + FLAVOR flavor; /** Are we to write a 'nice' LaTeX file or not. This esentially seems to mean whether InsetInclude, InsetGraphics @@ -49,17 +52,17 @@ struct OutputParams { bool free_spacing; /** This var is set by the return value from BufferParams::writeLaTeX - */ + */ bool use_babel; /** Used for docbook to see if inside a region of mixed content. In that case all the white spaces are significant and can not appear at the begin or end. - */ + */ bool mixed_content; - /** Line lenght to use with ascii export. - */ + /** Line length to use with ascii export. + */ lyx::size_type linelen; }; diff --git a/src/paragraph.C b/src/paragraph.C index 804e3221bd..a1c64793ef 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -306,10 +306,7 @@ void Paragraph::insertInset(pos_type pos, InsetBase * inset, bool Paragraph::insetAllowed(InsetOld_code code) { - //lyxerr << "Paragraph::InsertInsetAllowed" << endl; - if (pimpl_->inset_owner) - return pimpl_->inset_owner->insetAllowed(code); - return true; + return pimpl_->inset_owner->insetAllowed(code); } @@ -716,19 +713,26 @@ InsetBibitem * Paragraph::bibitem() const } +bool Paragraph::forceDefaultParagraphs() const +{ + return inInset()->forceDefaultParagraphs(inInset()); +} + + +bool Paragraph::autoBreakRows() const +{ + return static_cast(inInset())->getAutoBreakRows(); +} + + namespace { // paragraphs inside floats need different alignment tags to avoid // unwanted space -bool noTrivlistCentering(UpdatableInset const * inset) +bool noTrivlistCentering(InsetBase::Code code) { - if (inset) { - InsetBase::Code const code = inset->lyxCode(); - return code == InsetBase::FLOAT_CODE || - code == InsetBase::WRAP_CODE; - } - return false; + return code == InsetBase::FLOAT_CODE || code == InsetBase::WRAP_CODE; } @@ -745,10 +749,10 @@ string correction(string const & orig) string const corrected_env(string const & suffix, string const & env, - UpdatableInset const * inset) + InsetBase::Code code) { string output = suffix + "{"; - if (noTrivlistCentering(inset)) + if (noTrivlistCentering(code)) output += correction(env); else output += env; @@ -793,27 +797,25 @@ int Paragraph::startTeXParParams(BufferParams const & bparams, break; case LYX_ALIGN_LEFT: { string output; - UpdatableInset const * const inset = pimpl_->inset_owner; if (getParLanguage(bparams)->babel() != "hebrew") - output = corrected_env("\\begin", "flushleft", inset); + output = corrected_env("\\begin", "flushleft", ownerCode()); else - output = corrected_env("\\begin", "flushright", inset); + output = corrected_env("\\begin", "flushright", ownerCode()); os << output; column += output.size(); break; } case LYX_ALIGN_RIGHT: { string output; - UpdatableInset const * const inset = pimpl_->inset_owner; if (getParLanguage(bparams)->babel() != "hebrew") - output = corrected_env("\\begin", "flushright", inset); + output = corrected_env("\\begin", "flushright", ownerCode()); else - output = corrected_env("\\begin", "flushleft", inset); + output = corrected_env("\\begin", "flushleft", ownerCode()); os << output; column += output.size(); break; } case LYX_ALIGN_CENTER: { string output; - output = corrected_env("\\begin", "center", pimpl_->inset_owner); + output = corrected_env("\\begin", "center", ownerCode()); os << output; column += output.size(); break; @@ -854,27 +856,25 @@ int Paragraph::endTeXParParams(BufferParams const & bparams, break; case LYX_ALIGN_LEFT: { string output; - UpdatableInset const * const inset = pimpl_->inset_owner; if (getParLanguage(bparams)->babel() != "hebrew") - output = corrected_env("\\par\\end", "flushleft", inset); + output = corrected_env("\\par\\end", "flushleft", ownerCode()); else - output = corrected_env("\\par\\end", "flushright", inset); + output = corrected_env("\\par\\end", "flushright", ownerCode()); os << output; column += output.size(); break; } case LYX_ALIGN_RIGHT: { string output; - UpdatableInset const * const inset = pimpl_->inset_owner; if (getParLanguage(bparams)->babel() != "hebrew") - output = corrected_env("\\par\\end", "flushright", inset); + output = corrected_env("\\par\\end", "flushright", ownerCode()); else - output = corrected_env("\\par\\end", "flushleft", inset); + output = corrected_env("\\par\\end", "flushleft", ownerCode()); os << output; column += output.size(); break; } case LYX_ALIGN_CENTER: { string output; - output = corrected_env("\\par\\end", "center", pimpl_->inset_owner); + output = corrected_env("\\par\\end", "center", ownerCode()); os << output; column += output.size(); break; @@ -902,8 +902,7 @@ bool Paragraph::simpleTeXOnePar(Buffer const & buf, // length (all in one row) if that is true then we don't allow // any special options in the paragraph and also we don't allow // any environment other then "Standard" to be valid! - bool asdefault = - (inInset() && inInset()->forceDefaultParagraphs(inInset())); + bool asdefault = forceDefaultParagraphs(); if (asdefault) { style = bparams.getLyXTextClass().defaultLayout(); @@ -1537,7 +1536,7 @@ bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const { return lyxrc.rtl_support && getParLanguage(bparams)->RightToLeft() - && !(inInset() && inInset()->lyxCode() == InsetBase::ERT_CODE); + && ownerCode() != InsetBase::ERT_CODE; } @@ -1746,11 +1745,6 @@ int Paragraph::id() const LyXLayout_ptr const & Paragraph::layout() const { -/* - InsetBase * inset = inInset(); - if (inset && inset->lyxCode() == InsetBase::ENVIRONMENT_CODE) - return static_cast(inset)->layout(); -*/ return layout_; } @@ -1767,6 +1761,13 @@ UpdatableInset * Paragraph::inInset() const } +InsetBase::Code Paragraph::ownerCode() const +{ + return pimpl_->inset_owner + ? pimpl_->inset_owner->lyxCode() : InsetBase::NO_CODE; +} + + void Paragraph::clearContents() { text_.clear(); @@ -1798,9 +1799,7 @@ bool Paragraph::isFreeSpacing() const // for now we just need this, later should we need this in some // other way we can always add a function to InsetBase too. - if (pimpl_->inset_owner) - return pimpl_->inset_owner->lyxCode() == InsetBase::ERT_CODE; - return false; + return ownerCode() == InsetBase::ERT_CODE; } @@ -1808,9 +1807,7 @@ bool Paragraph::allowEmpty() const { if (layout()->keepempty) return true; - if (pimpl_->inset_owner) - return pimpl_->inset_owner->lyxCode() == InsetBase::ERT_CODE; - return false; + return ownerCode() == InsetBase::ERT_CODE; } diff --git a/src/paragraph.h b/src/paragraph.h index 6c54e00482..2d25f20d2d 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -21,6 +21,8 @@ #include "lyxlayout_ptr_fwd.h" #include "RowList_fwd.h" +#include "insets/insetbase.h" // only for InsetBase::Code + #include "support/types.h" #include @@ -139,10 +141,16 @@ public: /// void makeSameLayout(Paragraph const & par); + /// + void setInsetOwner(UpdatableInset * inset); /// UpdatableInset * inInset() const; /// - void setInsetOwner(UpdatableInset * inset); + InsetBase::Code ownerCode() const; + /// + bool autoBreakRows() const; + /// + bool forceDefaultParagraphs() const; /// lyx::pos_type size() const { return text_.size(); } diff --git a/src/text.C b/src/text.C index 4557c2feb3..9821af99e9 100644 --- a/src/text.C +++ b/src/text.C @@ -408,18 +408,18 @@ BufferView * LyXText::bv() } -double LyXText::spacing(Paragraph const & par) const +BufferView * LyXText::bv() const { - if (par.params().spacing().isDefault()) - return bv()->buffer()->params().spacing().getValue(); - return par.params().spacing().getValue(); + BOOST_ASSERT(bv_owner != 0); + return bv_owner; } -BufferView * LyXText::bv() const +double LyXText::spacing(Paragraph const & par) const { - BOOST_ASSERT(bv_owner != 0); - return bv_owner; + if (par.params().spacing().isDefault()) + return bv()->buffer()->params().spacing().getValue(); + return par.params().spacing().getValue(); } @@ -648,9 +648,8 @@ int LyXText::leftMargin(par_type pit, pos_type pos) const && align == LYX_ALIGN_BLOCK && !pars_[pit].params().noindent() // in tabulars and ert paragraphs are never indented! - && (!pars_[pit].inInset() - || (pars_[pit].inInset()->lyxCode() != InsetOld::TABULAR_CODE - && pars_[pit].inInset()->lyxCode() != InsetOld::ERT_CODE)) + && (pars_[pit].ownerCode() != InsetOld::TABULAR_CODE + && pars_[pit].ownerCode() != InsetOld::ERT_CODE) && (pars_[pit].layout() != tclass.defaultLayout() || bv()->buffer()->params().paragraph_separation == BufferParams::PARSEP_INDENT)) @@ -1062,8 +1061,7 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout) && cpar.isChangeEdited(0, cur.pos())) return; - LyXTextClass const & tclass = - bv()->buffer()->params().getLyXTextClass(); + LyXTextClass const & tclass = cur.buffer().params().getLyXTextClass(); LyXLayout_ptr const & layout = cpar.layout(); // this is only allowed, if the current paragraph is not empty @@ -1091,7 +1089,7 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout) // paragraph before or behind and we should react on that one // but we can fix this in 1.3.0 (Jug 20020509) bool const isempty = cpar.allowEmpty() && cpar.empty(); - ::breakParagraph(bv()->buffer()->params(), paragraphs(), cpit, + ::breakParagraph(cur.buffer().params(), paragraphs(), cpit, cur.pos(), keep_layout); cpit = cur.par(); @@ -1652,7 +1650,7 @@ void LyXText::backspace(LCursor & cur) // layout. I think it is a real bug of all other // word processors to allow it. It confuses the user. // Correction: Pasting is always allowed with standard-layout - Buffer & buf = *bv()->buffer(); + Buffer & buf = cur.buffer(); BufferParams const & bufparams = buf.params(); LyXTextClass const & tclass = bufparams.getLyXTextClass(); par_type const cpit = cur.par(); @@ -2096,17 +2094,17 @@ int LyXText::cursorY(CursorSlice const & cur) const string LyXText::currentState(LCursor & cur) { BOOST_ASSERT(this == cur.text()); - Buffer * buffer = bv()->buffer(); + Buffer & buf = cur.buffer(); Paragraph const & par = cur.paragraph(); std::ostringstream os; - bool const show_change = buffer->params().tracking_changes + bool const show_change = buf.params().tracking_changes && cur.pos() != cur.lastpos() && par.lookupChange(cur.pos()) != Change::UNCHANGED; if (show_change) { Change change = par.lookupChangeFull(cur.pos()); - Author const & a = buffer->params().authors().get(change.author); + Author const & a = buf.params().authors().get(change.author); os << _("Change: ") << a.name(); if (!a.email().empty()) os << " (" << a.email() << ")"; @@ -2118,13 +2116,13 @@ string LyXText::currentState(LCursor & cur) // I think we should only show changes from the default // font. (Asger) LyXFont font = real_current_font; - font.reduce(buffer->params().getLyXTextClass().defaultfont()); + font.reduce(buf.params().getLyXTextClass().defaultfont()); // avoid _(...) re-entrance problem - string const s = font.stateText(&buffer->params()); + string const s = font.stateText(&buf.params()); os << bformat(_("Font: %1$s"), s); - // os << bformat(_("Font: %1$s"), font.stateText(&buffer->params)); + // os << bformat(_("Font: %1$s"), font.stateText(&buf.params)); // The paragraph depth int depth = cur.paragraph().getDepth(); @@ -2155,11 +2153,12 @@ string LyXText::currentState(LCursor & cur) } } #ifdef DEVEL_VERSION - os << _(", Paragraph: ") << par.id(); + os << _(", Inset: ") << &cur.inset(); + os << _(", Paragraph: ") << cur.par(); + os << _(", Id: ") << par.id(); os << _(", Position: ") << cur.pos(); Row & row = cur.textRow(); os << bformat(_(", Row b:%1$d e:%2$d"), row.pos(), row.endpos()); - os << _(", Inset: ") << par.inInset(); #endif return os.str(); } @@ -2187,7 +2186,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const if (layout->latextype == LATEX_PARAGRAPH || lyxrc.label_init_length < 0) text.erase(); - string par_text = pars_[pit].asString(*cur.bv().buffer(), false); + string par_text = pars_[pit].asString(cur.buffer(), false); for (int i = 0; i < lyxrc.label_init_length; ++i) { if (par_text.empty()) break; diff --git a/src/text2.C b/src/text2.C index 4f3244cec6..426cb90be0 100644 --- a/src/text2.C +++ b/src/text2.C @@ -280,18 +280,19 @@ void LyXText::setLayout(LCursor & cur, string const & layout) { BOOST_ASSERT(this == cur.text()); // special handling of new environment insets - BufferParams const & params = bv()->buffer()->params(); + BufferView & bv = cur.bv(); + BufferParams const & params = bv.buffer()->params(); LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout]; if (lyxlayout->is_environment) { // move everything in a new environment inset lyxerr << "setting layout " << layout << endl; - bv()->owner()->dispatch(FuncRequest(LFUN_HOME)); - bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL)); - bv()->owner()->dispatch(FuncRequest(LFUN_CUT)); + bv.owner()->dispatch(FuncRequest(LFUN_HOME)); + bv.owner()->dispatch(FuncRequest(LFUN_ENDSEL)); + bv.owner()->dispatch(FuncRequest(LFUN_CUT)); InsetBase * inset = new InsetEnvironment(params, layout); insertInset(cur, inset); //inset->edit(cur, true); - //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE)); + //bv.owner()->dispatch(FuncRequest(LFUN_PASTE)); return; } @@ -396,7 +397,7 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) // Update current font real_current_font.update(font, - bv()->buffer()->params().language, + cur.buffer().params().language, toggleall); // Reduce to implicit settings @@ -419,7 +420,7 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall) lyxerr << "pos: " << pos << " posend: " << posend << endl; - BufferParams const & params = bv()->buffer()->params(); + BufferParams const & params = cur.buffer().params(); // Don't use forwardChar here as posend might have // pos() == lastpos() and forwardChar would miss it. @@ -775,10 +776,8 @@ void LyXText::setCounter(Buffer const & buf, par_type pit) par_type tmppit = pit; InsetBase * in = 0; bool isOK = false; - while (tmppit != end && pars_[tmppit].inInset() - // the single '=' is intended below - && (in = pars_[tmppit].inInset())) - { + while (tmppit != end) { + in = pars_[tmppit].inInset(); if (in->lyxCode() == InsetBase::FLOAT_CODE || in->lyxCode() == InsetBase::WRAP_CODE) { isOK = true; @@ -872,7 +871,7 @@ void LyXText::insertStringAsLines(LCursor & cur, string const & str) // only to be sure, should not be neccessary cur.clearSelection(); - bv()->buffer()->insertStringAsLines(pars_, pit, pos, current_font, str); + cur.buffer().insertStringAsLines(pars_, pit, pos, current_font, str); redoParagraphs(cur.par(), endpit); cur.resetAnchor(); @@ -1001,12 +1000,12 @@ void LyXText::setCurrentFont(LCursor & cur) } } - BufferParams const & bufparams = bv()->buffer()->params(); + BufferParams const & bufparams = cur.buffer().params(); current_font = pars_[pit].getFontSettings(bufparams, pos); real_current_font = getFont(pit, pos); if (cur.pos() == cur.lastpos() - && bidi.isBoundary(*bv()->buffer(), pars_[pit], cur.pos()) + && bidi.isBoundary(cur.buffer(), pars_[pit], cur.pos()) && !cur.boundary()) { Language const * lang = pars_[pit].getParLanguage(bufparams); current_font.setLanguage(lang); @@ -1186,7 +1185,7 @@ void LyXText::cursorLeft(LCursor & cur) setCursor(cur, cur.par(), cur.pos() - 1, true, false); if (!checkAndActivateInset(cur, false)) { if (false && !boundary && - bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1)) + bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos() + 1)) setCursor(cur, cur.par(), cur.pos() + 1, true, true); } return; @@ -1209,7 +1208,7 @@ void LyXText::cursorRight(LCursor & cur) if (cur.pos() != cur.lastpos()) { if (!checkAndActivateInset(cur, true)) { setCursor(cur, cur.par(), cur.pos() + 1, true, false); - if (false && bidi.isBoundary(*bv()->buffer(), cur.paragraph(), + if (false && bidi.isBoundary(cur.buffer(), cur.paragraph(), cur.pos())) setCursor(cur, cur.par(), cur.pos(), true, true); } diff --git a/src/text3.C b/src/text3.C index 7fb5790022..a2f7b01560 100644 --- a/src/text3.C +++ b/src/text3.C @@ -102,9 +102,9 @@ namespace { if (font.language() != ignore_language || font.number() != LyXFont::IGNORE) { Paragraph & par = cur.paragraph(); - text->bidi.computeTables(par, *cur.bv().buffer(), cur.textRow()); + text->bidi.computeTables(par, cur.buffer(), cur.textRow()); if (cur.boundary() != - text->bidi.isBoundary(*cur.bv().buffer(), par, + text->bidi.isBoundary(cur.buffer(), par, cur.pos(), text->real_current_font)) text->setCursor(cur, cur.par(), cur.pos(), @@ -294,7 +294,7 @@ void LyXText::cursorPrevious(LCursor & cur) lyx::par_type cpar = cur.par(); int x = cur.x_target(); - int y = bv()->top_y(); + int y = cur.bv().top_y(); setCursorFromCoordinates(cur, x, y); if (cpar == cur.par() && cpos == cur.pos()) { @@ -303,7 +303,7 @@ void LyXText::cursorPrevious(LCursor & cur) cursorUp(cur); } - bv()->updateScrollbar(); + cur.bv().updateScrollbar(); finishUndo(); } @@ -314,7 +314,7 @@ void LyXText::cursorNext(LCursor & cur) lyx::par_type cpar = cur.par(); int x = cur.x_target(); - int y = bv()->top_y() + bv()->workHeight(); + int y = cur.bv().top_y() + cur.bv().workHeight(); setCursorFromCoordinates(cur, x, y); if (cpar == cur.par() && cpos == cur.pos()) { @@ -323,7 +323,7 @@ void LyXText::cursorNext(LCursor & cur) cursorDown(cur); } - bv()->updateScrollbar(); + cur.bv().updateScrollbar(); finishUndo(); } -- 2.39.2