From 4b2c271e23b97a863e748a270ba8f912134ac014 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 1 Dec 2003 13:35:49 +0000 Subject: [PATCH] * buffer.[Ch]: * lyxtext.h: move ParagraphList member to LyXText rename LyXText::ownerParagraphs to LyXText::paragraph * CutAndPaste.C: * bufferview_funcs.C: * iterators.[Ch]: * lyx_cb.C: * paragraph.C: * rowpainter.C: * tabular.C: * text.C: * text2.C: * text3.C: adjust * lyxfunc.C: move LFUN_INSET_TOGGLE handling to insets. * undo.C: fix cursor positioning * insetbase.h: whitespace * inset.[Ch]: remove latexTextWidth make setBackgroundColor virtual * insettext.[Ch]: move ParagraphList member to LyXText * insetcollapsable.[Ch]: handle LFUN_INSET_TOGGLE * insetcharstyle.C: * insetenv.C: * insetert.[Ch]: * insetfloat.[Ch]: * insetminipage.[Ch]: * insettabular.C: * insetwrap.[Ch]: adjust paragraphs and background color handling, git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8166 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 4 +- src/ChangeLog | 22 ++++++ src/CutAndPaste.C | 3 +- src/buffer.C | 11 +-- src/bufferview_funcs.C | 2 +- src/insets/ChangeLog | 20 +++++ src/insets/inset.C | 42 ++--------- src/insets/inset.h | 10 +-- src/insets/insetbase.h | 3 +- src/insets/insetcharstyle.C | 4 +- src/insets/insetcollapsable.C | 38 +++++----- src/insets/insetcollapsable.h | 2 + src/insets/insetenv.C | 2 +- src/insets/insetert.C | 45 +++++------- src/insets/insetert.h | 2 - src/insets/insetfloat.C | 19 ++--- src/insets/insetfloat.h | 2 - src/insets/insetminipage.C | 10 +-- src/insets/insetminipage.h | 2 - src/insets/insettabular.C | 10 +-- src/insets/insettext.C | 134 +++++++++++++++++----------------- src/insets/insettext.h | 5 +- src/insets/insetwrap.C | 18 ++--- src/insets/insetwrap.h | 9 +-- src/iterators.C | 8 +- src/iterators.h | 3 +- src/lyx_cb.C | 2 +- src/lyxfunc.C | 11 +-- src/lyxtext.h | 15 ++-- src/paragraph.C | 25 +++---- src/rowpainter.C | 10 +-- src/tabular.C | 28 +++---- src/text.C | 87 +++++++++++----------- src/text2.C | 118 ++++++++++++++---------------- src/text3.C | 17 +++-- src/undo.C | 51 ++++++------- 36 files changed, 358 insertions(+), 436 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 97def2dfae..227e8992bf 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -308,7 +308,7 @@ void BufferView::gotoLabel(string const & label) if (find(labels.begin(),labels.end(),label) != labels.end()) { text()->clearSelection(); text()->setCursor( - std::distance(text()->ownerParagraphs().begin(), it.getPar()), + std::distance(text()->paragraphs().begin(), it.getPar()), it.getPos()); text()->selection.cursor = text()->cursor; update(); @@ -413,7 +413,7 @@ Encoding const * BufferView::getEncoding() const return t->cursorPar()->getFont( buffer()->params(), t->cursor.pos(), - outerFont(t->cursorPar(), t->ownerParagraphs()) + outerFont(t->cursorPar(), t->paragraphs()) ).language()->encoding(); } diff --git a/src/ChangeLog b/src/ChangeLog index 102ddac1f3..8308bbacee 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,25 @@ + +2003-12-01 André Pönitz + + * buffer.[Ch]: + * lyxtext.h: move ParagraphList member to LyXText + rename LyXText::ownerParagraphs to LyXText::paragraph + + * CutAndPaste.C: + * bufferview_funcs.C: + * iterators.[Ch]: + * lyx_cb.C: + * paragraph.C: + * rowpainter.C: + * tabular.C: + * text.C: + * text2.C: + * text3.C: adjust + + * lyxfunc.C: move LFUN_INSET_TOGGLE handling to insets. + + * undo.C: fix cursor positioning + 2003-12-01 John Levon * BufferView_pimpl.C: fix a crash on exit with diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 776600b22b..c3aab6fe7f 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -182,12 +182,11 @@ bool CutAndPaste::copySelection(ParagraphList::iterator startpit, BOOST_ASSERT(0 <= end && end <= endpit->size()); BOOST_ASSERT(startpit != endpit || start <= end); - ParagraphList paragraphs; // Clone the paragraphs within the selection. ParagraphList::iterator postend = boost::next(endpit); - paragraphs.assign(startpit, postend); + ParagraphList paragraphs(startpit, postend); for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges()); // Cut out the end of the last paragraph. diff --git a/src/buffer.C b/src/buffer.C index 0485be21db..96d5cc2519 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -146,7 +146,6 @@ struct Buffer::Impl limited_stack undostack; limited_stack redostack; BufferParams params; - ParagraphList paragraphs; LyXVC lyxvc; string temppath; bool nicefile; @@ -190,7 +189,7 @@ Buffer::Impl::Impl(Buffer & parent, string const & file, bool readonly_) : nicefile(true), lyx_clean(true), bak_clean(true), unnamed(false), read_only(readonly_), filename(file), filepath(OnlyPath(file)), file_fully_loaded(false), - text(0, 0, 0, paragraphs) + text(0, 0) { lyxvc.buffer(&parent); if (readonly_ || lyxrc.use_tempdir) @@ -218,8 +217,6 @@ Buffer::~Buffer() bformat(_("Could not remove the temporary directory %1$s"), temppath())); } - paragraphs().clear(); - // Remove any previewed LaTeX snippets associated with this buffer. lyx::graphics::Previews::get().removeLoader(*this); } @@ -269,13 +266,13 @@ BufferParams const & Buffer::params() const ParagraphList & Buffer::paragraphs() { - return pimpl_->paragraphs; + return pimpl_->text.paragraphs(); } ParagraphList const & Buffer::paragraphs() const { - return pimpl_->paragraphs; + return pimpl_->text.paragraphs(); } @@ -527,7 +524,7 @@ int Buffer::readParagraph(LyXLex & lex, string const & token, // needed to insert the selection void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos, - LyXFont const & fn,string const & str) + LyXFont const & fn, string const & str) { LyXLayout_ptr const & layout = par->layout(); diff --git a/src/bufferview_funcs.C b/src/bufferview_funcs.C index c80dff5927..b7b19a533a 100644 --- a/src/bufferview_funcs.C +++ b/src/bufferview_funcs.C @@ -288,7 +288,7 @@ void put_selection_at(BufferView * bv, PosIterator const & cur, bv->getLyXText()->clearSelection(); - LyXText * text = par.text(bv); + LyXText * text = par.text(*bv->buffer()); par.lockPath(bv); //hack for the chicken and egg problem if (par.inset()) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index dcfae763db..c9abe1fe38 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,23 @@ + +2003-12-01 André Pönitz + + * insetbase.h: whitespace + + * inset.[Ch]: remove latexTextWidth + make setBackgroundColor virtual + + * insettext.[Ch]: move ParagraphList member to LyXText + + * insetcollapsable.[Ch]: handle LFUN_INSET_TOGGLE + + * insetcharstyle.C: + * insetenv.C: + * insetert.[Ch]: + * insetfloat.[Ch]: + * insetminipage.[Ch]: + * insettabular.C: + * insetwrap.[Ch]: adjust paragraphs and background color handling, + 2003-11-28 Angus Leeming * insetvspace.[Ch] (d-tor, priv_dispatch): new member functions, diff --git a/src/insets/inset.C b/src/insets/inset.C index cd9b7a2756..88affad075 100644 --- a/src/insets/inset.C +++ b/src/insets/inset.C @@ -26,15 +26,16 @@ using std::string; InsetOld::InsetOld() : InsetBase(), - xo_(0), yo_(0), scx(0), owner_(0), - background_color_(LColor::inherit) + xo_(0), yo_(0), scx(0), owner_(0), + //background_color_(LColor::inherit) + background_color_(LColor::background) {} InsetOld::InsetOld(InsetOld const & in) : InsetBase(), - xo_(0), yo_(0), scx(0), owner_(0), - name_(in.name_), background_color_(in.background_color_) + xo_(0), yo_(0), scx(0), owner_(0), name_(in.name_), + background_color_(in.background_color_) {} @@ -56,18 +57,6 @@ bool InsetOld::autoDelete() const } -#if 0 -LyXFont const InsetOld::convertFont(LyXFont const & font) const -{ -#if 1 - return font; -#else - return LyXFont(font); -#endif -} -#endif - - string const InsetOld::editMessage() const { return _("Opened inset"); @@ -82,13 +71,7 @@ void InsetOld::setBackgroundColor(LColor_color color) LColor_color InsetOld::backgroundColor() const { - if (background_color_ == LColor::inherit) { - if (owner()) - return owner()->backgroundColor(); - else - return LColor::background; - } else - return LColor::color(background_color_); + return LColor::color(background_color_); } @@ -99,13 +82,6 @@ bool InsetOld::forceDefaultParagraphs(InsetOld const * inset) const return false; } -int InsetOld::latexTextWidth(BufferView * bv) const -{ - if (owner()) - return (owner()->latexTextWidth(bv)); - return bv->workWidth(); -} - int InsetOld::ascent() const { @@ -131,12 +107,6 @@ bool InsetOld::insetAllowed(InsetOld * in) const } -bool InsetOld::checkInsertChar(LyXFont &) -{ - return false; -} - - int InsetOld::scroll(bool recursive) const { if (!recursive || !owner_) diff --git a/src/insets/inset.h b/src/insets/inset.h index 7ac536035f..dd2e63cd1b 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -213,7 +213,7 @@ public: /// UpdatableInset * owner() const { return owner_; } /// - void setBackgroundColor(LColor_color); + virtual void setBackgroundColor(LColor_color); /// LColor_color backgroundColor() const; /// @@ -238,9 +238,6 @@ public: virtual void open() {} /// close the inset virtual void close() const {} - /// check if the font of the char we want inserting is correct - /// and modify it if it is not. - virtual bool checkInsertChar(LyXFont &); // should this inset be handled like a normal charater virtual bool isChar() const { return false; } // is this equivalent to a letter? @@ -261,11 +258,6 @@ public: virtual bool noFontChange() const { return false; } // virtual void getDrawFont(LyXFont &) const {} - /* needed for widths which are % of something - returns the value of \textwidth in this inset. Most of the - time this is the width of the workarea, but if there is a - minipage somewhere, it will be the width of this minipage */ - virtual int latexTextWidth(BufferView *) const; /// mark the inset contents as erased (for change tracking) virtual void markErased() {} diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 5b84726c4b..235da4b0a9 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -50,8 +50,7 @@ public: DispatchResult dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); // the real dispatcher - DispatchResult - dispatch(FuncRequest const & cmd); + DispatchResult dispatch(FuncRequest const & cmd); /// cursor enters virtual void edit(BufferView * bv, bool left); diff --git a/src/insets/insetcharstyle.C b/src/insets/insetcharstyle.C index 26d5409cd8..e80300ab9c 100644 --- a/src/insets/insetcharstyle.C +++ b/src/insets/insetcharstyle.C @@ -126,8 +126,8 @@ namespace { int outputVerbatim(std::ostream & os, InsetText inset) { int lines = 0; - ParagraphList::iterator par = inset.paragraphs.begin(); - ParagraphList::iterator end = inset.paragraphs.end(); + ParagraphList::iterator par = inset.paragraphs().begin(); + ParagraphList::iterator end = inset.paragraphs().end(); while (par != end) { lyx::pos_type siz = par->size(); for (lyx::pos_type i = 0; i < siz; ++i) { diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 604f8f6cf6..4f5662ba9e 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -149,7 +149,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const xo_ = x; yo_ = y; - if (!isOpen()) { + if (collapsed_) { draw_collapsed(pi, x, y); return; } @@ -171,7 +171,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const { - // by default, we are not inlined-drawing + // by default we don't draw inline draw(pi, x, y, false); } @@ -274,16 +274,13 @@ void InsetCollapsable::edit(BufferView * bv, int x, int y) lyxerr << "InsetCollapsable: edit xy" << endl; if (collapsed_) { collapsed_ = false; - // set this only here as it should be recollapsed only if - // it was already collapsed! - inset.edit(bv, x, y); } else { if (y <= button_dim.y2) - inset.edit(bv, x, 0); + y = 0; else - inset.edit(bv, x, ascent() + y - height_collapsed() + inset.ascent()); + y += inset.ascent() - height_collapsed(); } - + inset.edit(bv, x, y); bv->cursor().push(this); } @@ -311,6 +308,11 @@ InsetCollapsable::priv_dispatch(FuncRequest const & cmd, idx_type &, pos_type &) return lfunMouseRelease(cmd); return DispatchResult(true, true); + case LFUN_INSET_TOGGLE: + if (!inset.text_.toggleInset()) + close(); + return DispatchResult(true, true); + default: return inset.dispatch(adjustCommand(cmd)); } @@ -326,7 +328,7 @@ void InsetCollapsable::validate(LaTeXFeatures & features) const void InsetCollapsable::getCursorPos(int & x, int & y) const { - inset.getCursorPos(x , y); + inset.getCursorPos(x, y); y += - ascent() + height_collapsed() + inset.ascent(); } @@ -369,18 +371,12 @@ LyXText * InsetCollapsable::getText(int i) const void InsetCollapsable::open() { - if (!collapsed_) - return; - collapsed_ = false; } void InsetCollapsable::close() const { - if (collapsed_) - return; - collapsed_ = true; } @@ -420,6 +416,7 @@ void InsetCollapsable::setLabelFont(LyXFont & f) labelfont_ = f; } + #if 0 void InsetCollapsable::setAutoCollapse(bool f) { @@ -427,13 +424,14 @@ void InsetCollapsable::setAutoCollapse(bool f) } #endif -void InsetCollapsable::scroll(BufferView *bv, float sx) const + +void InsetCollapsable::scroll(BufferView * bv, float sx) const { UpdatableInset::scroll(bv, sx); } -void InsetCollapsable::scroll(BufferView *bv, int offset) const +void InsetCollapsable::scroll(BufferView * bv, int offset) const { UpdatableInset::scroll(bv, offset); } @@ -450,3 +448,9 @@ Box const & InsetCollapsable::buttonDim() const return button_dim; } + +void InsetCollapsable::setBackgroundColor(LColor_color color) +{ + InsetOld::setBackgroundColor(color); + inset.setBackgroundColor(color); +} diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index 61be4dae7a..dbffd9c662 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -110,6 +110,8 @@ public: void markErased(); /// void addPreview(lyx::graphics::PreviewLoader &) const; + /// + void setBackgroundColor(LColor_color); protected: /// diff --git a/src/insets/insetenv.C b/src/insets/insetenv.C index 92529d5690..6898757a0c 100644 --- a/src/insets/insetenv.C +++ b/src/insets/insetenv.C @@ -71,7 +71,7 @@ int InsetEnvironment::latex(Buffer const & buf, ostream & os, { os << layout_->latexheader; TexRow texrow; - latexParagraphs(buf, paragraphs, os, texrow, runparams, + latexParagraphs(buf, paragraphs(), os, texrow, runparams, layout_->latexparagraph); os << layout_->latexfooter; return texrow.rows(); diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 5c5a8b3e7f..a23fc5be78 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -94,7 +94,7 @@ InsetERT::InsetERT(BufferParams const & bp, string::const_iterator end = contents.end(); pos_type pos = 0; for (; cit != end; ++cit) { - inset.paragraphs.begin()->insertChar(pos++, *cit, font); + inset.paragraphs().begin()->insertChar(pos++, *cit, font); } // the init has to be after the initialization of the paragraph // because of the label settings (draw_label for ert insets). @@ -142,8 +142,8 @@ void InsetERT::read(Buffer const & buf, LyXLex & lex) font.setFamily(LyXFont::TYPEWRITER_FAMILY); font.setColor(LColor::latex); - ParagraphList::iterator pit = inset.paragraphs.begin(); - ParagraphList::iterator pend = inset.paragraphs.end(); + ParagraphList::iterator pit = inset.paragraphs().begin(); + ParagraphList::iterator pend = inset.paragraphs().end(); for (; pit != pend; ++pit) { pos_type siz = pit->size(); for (pos_type i = 0; i < siz; ++i) { @@ -182,8 +182,8 @@ void InsetERT::write(Buffer const & buf, ostream & os) const //inset.writeParagraphData(buf, os); string const layout(buf.params().getLyXTextClass().defaultLayoutName()); - ParagraphList::iterator par = inset.paragraphs.begin(); - ParagraphList::iterator end = inset.paragraphs.end(); + ParagraphList::iterator par = inset.paragraphs().begin(); + ParagraphList::iterator end = inset.paragraphs().end(); for (; par != end; ++par) { os << "\n\\begin_layout " << layout << "\n"; pos_type siz = par->size(); @@ -296,8 +296,8 @@ void InsetERT::lfunMouseMotion(FuncRequest const & cmd) int InsetERT::latex(Buffer const &, ostream & os, OutputParams const &) const { - ParagraphList::iterator par = inset.paragraphs.begin(); - ParagraphList::iterator end = inset.paragraphs.end(); + ParagraphList::iterator par = inset.paragraphs().begin(); + ParagraphList::iterator end = inset.paragraphs().end(); int lines = 0; while (par != end) { @@ -335,8 +335,8 @@ int InsetERT::plaintext(Buffer const &, ostream &, int InsetERT::linuxdoc(Buffer const &, ostream & os, OutputParams const &)const { - ParagraphList::iterator par = inset.paragraphs.begin(); - ParagraphList::iterator end = inset.paragraphs.end(); + ParagraphList::iterator par = inset.paragraphs().begin(); + ParagraphList::iterator end = inset.paragraphs().end(); int lines = 0; while (par != end) { @@ -363,8 +363,8 @@ int InsetERT::linuxdoc(Buffer const &, ostream & os, int InsetERT::docbook(Buffer const &, ostream & os, OutputParams const &) const { - ParagraphList::iterator par = inset.paragraphs.begin(); - ParagraphList::iterator end = inset.paragraphs.end(); + ParagraphList::iterator par = inset.paragraphs().begin(); + ParagraphList::iterator end = inset.paragraphs().end(); int lines = 0; while (par != end) { @@ -405,7 +405,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) { BufferView * bv = cmd.view(); - if (inset.paragraphs.begin()->empty()) + if (inset.paragraphs().begin()->empty()) setLatexFont(bv); switch (cmd.action) { @@ -431,7 +431,7 @@ InsetERT::priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos) return DispatchResult(true, true); case LFUN_LAYOUT: - bv->owner()->setLayout(inset.paragraphs.begin()->layout()->name()); + bv->owner()->setLayout(inset.paragraphs().begin()->layout()->name()); return DispatchResult(true); case LFUN_BREAKPARAGRAPH: @@ -455,17 +455,17 @@ string const InsetERT::getNewLabel() const { string la; pos_type const max_length = 15; - pos_type const p_siz = inset.paragraphs.begin()->size(); + pos_type const p_siz = inset.paragraphs().begin()->size(); pos_type const n = min(max_length, p_siz); pos_type i = 0; pos_type j = 0; for( ; i < n && j < p_siz; ++j) { - if (inset.paragraphs.begin()->isInset(j)) + if (inset.paragraphs().begin()->isInset(j)) continue; - la += inset.paragraphs.begin()->getChar(j); + la += inset.paragraphs().begin()->getChar(j); ++i; } - if (inset.paragraphs.size() > 1 || (i > 0 && j < p_siz)) { + if (inset.paragraphs().size() > 1 || (i > 0 && j < p_siz)) { la += "..."; } if (la.empty()) { @@ -481,17 +481,6 @@ void InsetERT::setButtonLabel() const } -bool InsetERT::checkInsertChar(LyXFont & /* font */) -{ -#ifdef SET_HARD_FONT - LyXFont font(LyXFont::ALL_INHERIT, latex_language); - font.setFamily(LyXFont::TYPEWRITER_FAMILY); - font.setColor(LColor::latex); -#endif - return true; -} - - void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const { setButtonLabel(); diff --git a/src/insets/insetert.h b/src/insets/insetert.h index a49d5e470f..cce282325e 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -77,8 +77,6 @@ public: /// void validate(LaTeXFeatures &) const {} /// - bool checkInsertChar(LyXFont &); - /// // these are needed here because of the label/inlined functionallity /// bool isOpen() const { return status_ == Open || status_ == Inlined; } diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index e5149398a2..aa45ba6d3c 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -145,15 +145,10 @@ InsetFloat::InsetFloat(BufferParams const & bp, string const & type) setInsetName(type); LyXTextClass const & tclass = bp.getLyXTextClass(); if (tclass.hasLayout(caplayout)) - inset.paragraphs.begin()->layout(tclass[caplayout]); + inset.paragraphs().begin()->layout(tclass[caplayout]); } -InsetFloat::InsetFloat(InsetFloat const & in) - : InsetCollapsable(in), params_(in.params_) -{} - - InsetFloat::~InsetFloat() { InsetFloatMailer(*this).hideDialog(); @@ -363,11 +358,9 @@ int InsetFloat::docbook(Buffer const & buf, ostream & os, bool InsetFloat::insetAllowed(InsetOld::Code code) const { - if (code == InsetOld::FLOAT_CODE) - return false; - if (code == InsetOld::FOOT_CODE || code == InsetOld::MARGIN_CODE) - return false; - return true; + return code != InsetOld::FLOAT_CODE + && code != InsetOld::FOOT_CODE + && code != InsetOld::MARGIN_CODE; } @@ -391,8 +384,8 @@ void InsetFloat::wide(bool w, BufferParams const & bp) void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const { - ParIterator pit(inset.paragraphs.begin(), inset.paragraphs); - ParIterator end(inset.paragraphs.end(), inset.paragraphs); + ParIterator pit(inset.paragraphs().begin(), inset.paragraphs()); + ParIterator end(inset.paragraphs().end(), inset.paragraphs()); // Find a caption layout in one of the (child inset's) pars for (; pit != end; ++pit) { diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index c2d83abc36..d7a045cf10 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -41,8 +41,6 @@ public: /// InsetFloat(BufferParams const &, std::string const &); /// - InsetFloat(InsetFloat const &); - /// ~InsetFloat(); /// void write(Buffer const & buf, std::ostream & os) const; diff --git a/src/insets/insetminipage.C b/src/insets/insetminipage.C index d3ef8008e5..eaf4b00bc5 100644 --- a/src/insets/insetminipage.C +++ b/src/insets/insetminipage.C @@ -281,16 +281,8 @@ bool InsetMinipage::showInsetDialog(BufferView * bv) const } -int InsetMinipage::latexTextWidth(BufferView * bv) const -{ - return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv)); -} - - InsetMinipage::Params::Params() - : pos(center), - inner_pos(inner_center), - width(100, LyXLength::PCW) + : pos(center), inner_pos(inner_center), width(100, LyXLength::PCW) {} diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 828d885bca..536768e2ea 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -83,8 +83,6 @@ public: /// bool showInsetDialog(BufferView *) const; /// - int latexTextWidth(BufferView *) const; - /// void params(Params const & p) { params_ = p; } /// Params const & params() const { return params_; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index c0b0dc6848..5121c2305a 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -1160,7 +1160,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock) ++actcell; } if (lock) { - bool rtl = tabular.getCellInset(actcell).paragraphs.begin()-> + bool rtl = tabular.getCellInset(actcell).paragraphs().begin()-> isRightToLeftPar(bv->buffer()->params()); activateCellInset(bv, 0, 0, !rtl); } @@ -1193,7 +1193,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock) } lyxerr << "move prevcell 2" << endl; if (lock) { - bool rtl = tabular.getCellInset(actcell).paragraphs.begin()-> + bool rtl = tabular.getCellInset(actcell).paragraphs().begin()-> isRightToLeftPar(bv->buffer()->params()); activateCellInset(bv, 0, 0, !rtl); } @@ -2082,7 +2082,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, if (cols < columns) { InsetText & inset = loctab->getCellInset(cell); LyXFont const font = inset.text_. - getFont(inset.paragraphs.begin(), 0); + getFont(inset.paragraphs().begin(), 0); inset.setText(buf.substr(op, p - op), font); ++cols; ++cell; @@ -2093,7 +2093,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, if (cols < columns) { InsetText & inset = tabular.getCellInset(cell); LyXFont const font = inset.text_. - getFont(inset.paragraphs.begin(), 0); + getFont(inset.paragraphs().begin(), 0); inset.setText(buf.substr(op, p - op), font); } cols = ocol; @@ -2108,7 +2108,7 @@ bool InsetTabular::insertAsciiString(BufferView * bv, string const & buf, // check for the last cell if there is no trailing '\n' if (cell < cells && op < len) { InsetText & inset = loctab->getCellInset(cell); - LyXFont const font = inset.text_.getFont(inset.paragraphs.begin(), 0); + LyXFont const font = inset.text_.getFont(inset.paragraphs().begin(), 0); inset.setText(buf.substr(op, len - op), font); } diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 238c5f6862..b1b61522ea 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -71,23 +71,19 @@ using std::vector; InsetText::InsetText(BufferParams const & bp) - : UpdatableInset(), - paragraphs(1), - autoBreakRows_(false), - drawFrame_(NEVER), - frame_color_(LColor::insetframe), - text_(0, this, true, paragraphs) -{ - paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout()); + : autoBreakRows_(false), drawFrame_(NEVER), + frame_color_(LColor::insetframe), text_(0, true) +{ + paragraphs().push_back(Paragraph()); + paragraphs().begin()->layout(bp.getLyXTextClass().defaultLayout()); if (bp.tracking_changes) - paragraphs.begin()->trackChanges(); + paragraphs().begin()->trackChanges(); init(); } InsetText::InsetText(InsetText const & in) - : UpdatableInset(in), - text_(in.text_.bv_owner, this, true, paragraphs) + : UpdatableInset(in), text_(in.text_.bv_owner, true) { // this is ugly... operator=(in); @@ -97,22 +93,21 @@ InsetText::InsetText(InsetText const & in) void InsetText::operator=(InsetText const & in) { UpdatableInset::operator=(in); - paragraphs = in.paragraphs; autoBreakRows_ = in.autoBreakRows_; drawFrame_ = in.drawFrame_; frame_color_ = in.frame_color_; - text_ = LyXText(in.text_.bv_owner, this, true, paragraphs); + text_ = LyXText(in.text_.bv_owner, true); + text_.paragraphs() = in.text_.paragraphs(); init(); } void InsetText::init() { - ParagraphList::iterator pit = paragraphs.begin(); - ParagraphList::iterator end = paragraphs.end(); + ParagraphList::iterator pit = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); for (; pit != end; ++pit) pit->setInsetOwner(this); - text_.paragraphs_ = ¶graphs; old_par = -1; in_insetAllowed = false; } @@ -120,21 +115,22 @@ void InsetText::init() void InsetText::clear(bool just_mark_erased) { + ParagraphList & pars = paragraphs(); if (just_mark_erased) { - ParagraphList::iterator it = paragraphs.begin(); - ParagraphList::iterator end = paragraphs.end(); + ParagraphList::iterator it = pars.begin(); + ParagraphList::iterator end = pars.end(); for (; it != end; ++it) it->markErased(); return; } // This is a gross hack... - LyXLayout_ptr old_layout = paragraphs.begin()->layout(); + LyXLayout_ptr old_layout = pars.begin()->layout(); - paragraphs.clear(); - paragraphs.push_back(Paragraph()); - paragraphs.begin()->setInsetOwner(this); - paragraphs.begin()->layout(old_layout); + pars.clear(); + pars.push_back(Paragraph()); + pars.begin()->setInsetOwner(this); + pars.begin()->layout(old_layout); } @@ -153,8 +149,8 @@ void InsetText::write(Buffer const & buf, ostream & os) const void InsetText::writeParagraphData(Buffer const & buf, ostream & os) const { - ParagraphList::const_iterator it = paragraphs.begin(); - ParagraphList::const_iterator end = paragraphs.end(); + ParagraphList::const_iterator it = paragraphs().begin(); + ParagraphList::const_iterator end = paragraphs().end(); Paragraph::depth_type dth = 0; for (; it != end; ++it) { it->write(buf, os, buf.params(), dth); @@ -171,12 +167,12 @@ void InsetText::read(Buffer const & buf, LyXLex & lex) #warning John, look here. Doesnt make much sense. if (buf.params().tracking_changes) - paragraphs.begin()->trackChanges(); + paragraphs().begin()->trackChanges(); // delete the initial paragraph - Paragraph oldpar = *paragraphs.begin(); - paragraphs.clear(); - ParagraphList::iterator pit = paragraphs.begin(); + Paragraph oldpar = *paragraphs().begin(); + paragraphs().clear(); + ParagraphList::iterator pit = paragraphs().begin(); while (lex.isOK()) { lex.nextToken(); @@ -193,11 +189,11 @@ void InsetText::read(Buffer const & buf, LyXLex & lex) } // FIXME: ugly. - const_cast(buf).readParagraph(lex, token, paragraphs, pit, depth); + const_cast(buf).readParagraph(lex, token, paragraphs(), pit, depth); } - pit = paragraphs.begin(); - ParagraphList::iterator const end = paragraphs.end(); + pit = paragraphs().begin(); + ParagraphList::iterator const end = paragraphs().end(); for (; pit != end; ++pit) pit->setInsetOwner(this); @@ -208,8 +204,8 @@ void InsetText::read(Buffer const & buf, LyXLex & lex) // sanity check // ensure we have at least one par. - if (paragraphs.empty()) - paragraphs.push_back(oldpar); + if (paragraphs().empty()) + paragraphs().push_back(oldpar); } @@ -270,7 +266,7 @@ void InsetText::updateLocal(BufferView * bv) if (!bv) return; - if (!autoBreakRows_ && paragraphs.size() > 1) + if (!autoBreakRows_ && paragraphs().size() > 1) collapseParagraphs(bv); if (!text_.selection.set()) @@ -294,8 +290,8 @@ string const InsetText::editMessage() const void InsetText::sanitizeEmptyText(BufferView * bv) { - if (paragraphs.size() == 1 - && paragraphs.begin()->empty() + if (paragraphs().size() == 1 + && paragraphs().begin()->empty() && bv->getParentLanguage(this) != text_.current_font.language()) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); @@ -317,7 +313,7 @@ void InsetText::edit(BufferView * bv, bool left) if (left) text_.setCursorIntern(0, 0); else - text_.setCursor(paragraphs.size() - 1, paragraphs.back().size()); + text_.setCursor(paragraphs().size() - 1, paragraphs().back().size()); sanitizeEmptyText(bv); updateLocal(bv); @@ -352,7 +348,7 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, DispatchResult result; result.dispatched(true); - bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1; + bool was_empty = paragraphs().begin()->empty() && paragraphs().size() == 1; switch (cmd.action) { case LFUN_MOUSE_PRESS: @@ -366,8 +362,8 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, // If the action has deleted all text in the inset, we need // to change the language to the language of the surronding // text. - if (!was_empty && paragraphs.begin()->empty() && - paragraphs.size() == 1) { + if (!was_empty && paragraphs().begin()->empty() && + paragraphs().size() == 1) { LyXFont font(LyXFont::ALL_IGNORE); font.setLanguage(bv->getParentLanguage(this)); text_.setFont(font, false); @@ -382,7 +378,7 @@ int InsetText::latex(Buffer const & buf, ostream & os, OutputParams const & runparams) const { TexRow texrow; - latexParagraphs(buf, paragraphs, os, texrow, runparams); + latexParagraphs(buf, paragraphs(), os, texrow, runparams); return texrow.rows(); } @@ -390,8 +386,8 @@ int InsetText::latex(Buffer const & buf, ostream & os, int InsetText::plaintext(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - ParagraphList::const_iterator beg = paragraphs.begin(); - ParagraphList::const_iterator end = paragraphs.end(); + ParagraphList::const_iterator beg = paragraphs().begin(); + ParagraphList::const_iterator end = paragraphs().end(); ParagraphList::const_iterator it = beg; for (; it != end; ++it) asciiParagraph(buf, *it, os, runparams, it == beg); @@ -404,7 +400,7 @@ int InsetText::plaintext(Buffer const & buf, ostream & os, int InsetText::linuxdoc(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - linuxdocParagraphs(buf, paragraphs, os, runparams); + linuxdocParagraphs(buf, paragraphs(), os, runparams); return 0; } @@ -412,14 +408,14 @@ int InsetText::linuxdoc(Buffer const & buf, ostream & os, int InsetText::docbook(Buffer const & buf, ostream & os, OutputParams const & runparams) const { - docbookParagraphs(buf, paragraphs, os, runparams); + docbookParagraphs(buf, paragraphs(), os, runparams); return 0; } void InsetText::validate(LaTeXFeatures & features) const { - for_each(paragraphs.begin(), paragraphs.end(), + for_each(paragraphs().begin(), paragraphs().end(), boost::bind(&Paragraph::validate, _1, boost::ref(features))); } @@ -467,8 +463,8 @@ bool InsetText::showInsetDialog(BufferView *) const void InsetText::getLabelList(Buffer const & buffer, std::vector & list) const { - ParagraphList::const_iterator pit = paragraphs.begin(); - ParagraphList::const_iterator pend = paragraphs.end(); + ParagraphList::const_iterator pit = paragraphs().begin(); + ParagraphList::const_iterator pend = paragraphs().end(); for (; pit != pend; ++pit) { InsetList::const_iterator beg = pit->insetlist.begin(); InsetList::const_iterator end = pit->insetlist.end(); @@ -480,8 +476,8 @@ void InsetText::getLabelList(Buffer const & buffer, void InsetText::markNew(bool track_changes) { - ParagraphList::iterator pit = paragraphs.begin(); - ParagraphList::iterator end = paragraphs.end(); + ParagraphList::iterator pit = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); for (; pit != end; ++pit) { if (track_changes) { pit->trackChanges(); @@ -497,7 +493,7 @@ void InsetText::setText(string const & data, LyXFont const & font) { clear(false); for (unsigned int i = 0; i < data.length(); ++i) - paragraphs.begin()->insertChar(i, data[i], font); + paragraphs().begin()->insertChar(i, data[i], font); } @@ -541,8 +537,8 @@ void InsetText::setViewCache(BufferView const * bv) const void InsetText::removeNewlines() { - ParagraphList::iterator it = paragraphs.begin(); - ParagraphList::iterator end = paragraphs.end(); + ParagraphList::iterator it = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); for (; it != end; ++it) for (int i = 0; i < it->size(); ++i) if (it->isNewline(i)) @@ -576,7 +572,7 @@ void InsetText::clearInset(Painter & pain, int x, int y) const ParagraphList * InsetText::getParagraphs(int i) const { - return (i == 0) ? const_cast(¶graphs) : 0; + return (i == 0) ? const_cast(¶graphs()) : 0; } @@ -586,16 +582,10 @@ LyXText * InsetText::getText(int i) const } -bool InsetText::checkInsertChar(LyXFont & font) -{ - return owner() ? owner()->checkInsertChar(font) : true; -} - - void InsetText::collapseParagraphs(BufferView * bv) { - while (paragraphs.size() > 1) { - ParagraphList::iterator const first = paragraphs.begin(); + while (paragraphs().size() > 1) { + ParagraphList::iterator const first = paragraphs().begin(); ParagraphList::iterator second = first; ++second; size_t const first_par_size = first->size(); @@ -618,7 +608,7 @@ void InsetText::collapseParagraphs(BufferView * bv) } } - mergeParagraph(bv->buffer()->params(), paragraphs, first); + mergeParagraph(bv->buffer()->params(), paragraphs(), first); } } @@ -636,20 +626,20 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist) // And it probably does. You have to take a look at this John. (Lgb) #warning John, have a look here. (Lgb) ParagraphList::iterator pit = plist.begin(); - ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit); + ParagraphList::iterator ins = paragraphs().insert(paragraphs().end(), *pit); ++pit; - mergeParagraph(buffer->params(), paragraphs, boost::prior(ins)); + mergeParagraph(buffer->params(), paragraphs(), boost::prior(ins)); ParagraphList::iterator pend = plist.end(); for (; pit != pend; ++pit) - paragraphs.push_back(*pit); + paragraphs().push_back(*pit); } void InsetText::addPreview(PreviewLoader & loader) const { - ParagraphList::const_iterator pit = paragraphs.begin(); - ParagraphList::const_iterator pend = paragraphs.end(); + ParagraphList::const_iterator pit = paragraphs().begin(); + ParagraphList::const_iterator pend = paragraphs().end(); for (; pit != pend; ++pit) { InsetList::const_iterator it = pit->insetlist.begin(); @@ -658,3 +648,9 @@ void InsetText::addPreview(PreviewLoader & loader) const it->inset->addPreview(loader); } } + + +ParagraphList & InsetText::paragraphs() const +{ + return const_cast(text_.paragraphs()); +} diff --git a/src/insets/insettext.h b/src/insets/insettext.h index e561188c5e..8085e615e3 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -142,8 +142,6 @@ public: */ void markNew(bool track_changes = false); - /// - bool checkInsertChar(LyXFont &); /// void getDrawFont(LyXFont &) const; /// append text onto the existing text @@ -160,7 +158,8 @@ public: /// int numParagraphs() const { return 1; } /// - mutable ParagraphList paragraphs; + ParagraphList & paragraphs() const; + private: /// DispatchResult diff --git a/src/insets/insetwrap.C b/src/insets/insetwrap.C index b1c32be963..6040f3779b 100644 --- a/src/insets/insetwrap.C +++ b/src/insets/insetwrap.C @@ -69,7 +69,7 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type) setInsetName(type); LyXTextClass const & tclass = bp.getLyXTextClass(); if (tclass.hasLayout(caplayout)) - inset.paragraphs.begin()->layout(tclass[caplayout]); + inset.paragraphs().begin()->layout(tclass[caplayout]); } @@ -218,18 +218,10 @@ bool InsetWrap::insetAllowed(InsetOld::Code code) const } -int InsetWrap::latexTextWidth(BufferView * bv) const -{ - return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv)); -} - - bool InsetWrap::showInsetDialog(BufferView * bv) const { - if (!inset.showInsetDialog(bv)) { - InsetWrap * tmp = const_cast(this); - InsetWrapMailer(*tmp).showDialog(bv); - } + if (!inset.showInsetDialog(bv)) + InsetWrapMailer(const_cast(*this)).showDialog(bv); return true; } @@ -237,8 +229,8 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const void InsetWrap::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const { // Now find the caption in the float... - ParagraphList::iterator tmp = inset.paragraphs.begin(); - ParagraphList::iterator end = inset.paragraphs.end(); + ParagraphList::iterator tmp = inset.paragraphs().begin(); + ParagraphList::iterator end = inset.paragraphs().end(); for (; tmp != end; ++tmp) { if (tmp->layout()->name() == caplayout) { diff --git a/src/insets/insetwrap.h b/src/insets/insetwrap.h index fc4513916b..7525d45838 100644 --- a/src/insets/insetwrap.h +++ b/src/insets/insetwrap.h @@ -9,9 +9,8 @@ * Full author contact details are available in file CREDITS. */ -#ifndef InsetWrap_H -#define InsetWrap_H - +#ifndef INSETWRAP_H +#define INSETWRAP_H #include "insetcollapsable.h" #include "toc.h" @@ -64,9 +63,7 @@ public: /// void addToToc(lyx::toc::TocList &, Buffer const &) const; /// - bool showInsetDialog(BufferView *) const; - /// - int latexTextWidth(BufferView *) const; + bool showInsetDialog(BufferView *) const; /// InsetWrapParams const & params() const { return params_; } protected: diff --git a/src/iterators.C b/src/iterators.C index b295e876bd..3cb674f559 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -15,6 +15,7 @@ #include "paragraph.h" #include "PosIterator.h" #include "cursor.h" +#include "buffer.h" #include "BufferView.h" #include "dispatchresult.h" @@ -149,11 +150,11 @@ ParIterator & ParIterator::operator++() } -LyXText * ParIterator::text(BufferView * bv) const +LyXText * ParIterator::text(Buffer & buf) const { //lyxerr << "positions.size: " << pimpl_->positions.size() << std::endl; if (pimpl_->positions.size() <= 1) - return bv->text(); + return &buf.text(); ParPosition const & pos = pimpl_->positions[pimpl_->positions.size() - 2]; return (*pos.it)->inset->getText(*pos.index); @@ -355,7 +356,8 @@ PosIterator ParIterator::asPosIterator(lyx::pos_type pos) const for (int i = 0; i < last; ++i) { ParPosition & pp = pimpl_->positions[i]; p.stack_.push_back( - PosIteratorItem(const_cast(pp.plist), pp.pit, (*pp.it)->pos, *pp.index + 1)); + PosIteratorItem(const_cast(pp.plist), + pp.pit, (*pp.it)->pos, *pp.index + 1)); } ParPosition const & pp = pimpl_->positions[last]; p.stack_.push_back( diff --git a/src/iterators.h b/src/iterators.h index bb3288ce8a..7d0e0cc410 100644 --- a/src/iterators.h +++ b/src/iterators.h @@ -20,6 +20,7 @@ class LyXText; class InsetOld; class Cursor; +class Buffer; class BufferView; class PosIterator; @@ -49,7 +50,7 @@ public: /// ParagraphList & plist() const; /// returns 'innermost' LyXText - LyXText * text(BufferView *) const; + LyXText * text(Buffer &) const; /// returns innermost inset InsetOld * inset() const; /// returns index of cell in innermost inset diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 875281607d..bf31a58e88 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -428,7 +428,7 @@ string getContentsOfAsciiFile(BufferView * bv, string const & f, bool asParagrap string const getPossibleLabel(BufferView const & bv) { ParagraphList::iterator pit = bv.getLyXText()->cursorPar(); - ParagraphList & plist = bv.getLyXText()->ownerParagraphs(); + ParagraphList & plist = bv.getLyXText()->paragraphs(); LyXLayout_ptr layout = pit->layout(); diff --git a/src/lyxfunc.C b/src/lyxfunc.C index a36538cb1a..51fe3b7ae6 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -459,15 +459,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & ev) const disable = !buf->params().tracking_changes; break; - case LFUN_INSET_TOGGLE: { - LyXText * lt = view()->getLyXText(); - disable = !(isEditableInset(lt->getInset()) - || (lt->inset_owner - && lt->inset_owner->owner() - && lt->inset_owner->owner()->isOpen())); - break; - } - case LFUN_INSET_SETTINGS: { disable = true; UpdatableInset * inset = view()->cursor().innerInset(); @@ -1166,7 +1157,7 @@ void LyXFunc::dispatch(FuncRequest const & func, bool verbose) } par.lockPath(view()); - LyXText * lt = par.text(view()); + LyXText * lt = par.text(*view()->buffer()); // Set the cursor lt->setCursor(par.pit(), 0); diff --git a/src/lyxtext.h b/src/lyxtext.h index a32331a35c..bf27dc44f9 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -30,7 +30,6 @@ class BufferParams; class BufferView; class Dimension; class LColor_color; -class InsetText; class LyXCursor; class MetricsInfo; class Paragraph; @@ -53,7 +52,7 @@ class LyXText : public TextCursor { // Public Functions public: /// Constructor - LyXText(BufferView *, InsetText *, bool ininset, ParagraphList & plist); + LyXText(BufferView *, bool ininset); /// void init(BufferView *); @@ -131,7 +130,7 @@ public: /// draw text (only used for insets) void draw(PainterInfo & pi, int x, int y) const; - /// + /// try to handle that request DispatchResult dispatch(FuncRequest const & cmd); BufferView * bv(); @@ -252,8 +251,8 @@ public: /// Change the case of the word at cursor position. void changeCase(TextCase action); - /// - void toggleInset(); + /// returns success + bool toggleInset(); /// void cutSelection(bool doclear = true, bool realcut = true); /// @@ -334,7 +333,7 @@ public: // // special owner functions /// - ParagraphList & ownerParagraphs() const; + ParagraphList & paragraphs() const; /// return true if this is owned by an inset. bool isInInset() const; @@ -405,7 +404,7 @@ public: /// our buffer's default layout font LyXFont defaultfont_; /// - InsetText * inset_owner; + int background_color_; /// only the top-level LyXText has this non-zero BufferView * bv_owner; @@ -415,7 +414,7 @@ public: /// bool in_inset_; /// - ParagraphList * paragraphs_; + ParagraphList paragraphs_; /// absolute document pixel coordinates of this LyXText mutable int xo_; diff --git a/src/paragraph.C b/src/paragraph.C index 7263822554..9dce9f546e 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -271,10 +271,8 @@ void Paragraph::insert(pos_type start, string const & str, } -bool Paragraph::checkInsertChar(LyXFont & font) +bool Paragraph::checkInsertChar(LyXFont &) { - if (pimpl_->inset_owner) - return pimpl_->inset_owner->checkInsertChar(font); return true; } @@ -593,9 +591,7 @@ int Paragraph::stripLeadingSpaces() bool Paragraph::hasSameLayout(Paragraph const & par) const { - return - par.layout() == layout() && - params().sameLayout(par.params()); + return par.layout() == layout() && params().sameLayout(par.params()); } @@ -718,8 +714,8 @@ InsetBibitem * Paragraph::bibitem() const namespace { -/* paragraphs inside floats need different alignment tags to avoid -unwanted space */ +// paragraphs inside floats need different alignment tags to avoid +// unwanted space bool noTrivlistCentering(UpdatableInset const * inset) { @@ -1278,8 +1274,7 @@ void Paragraph::simpleLinuxDocOnePar(Buffer const & buf, if (c == Paragraph::META_INSET) { - InsetOld const * inset = getInset(i); - inset->linuxdoc(buf, os, runparams); + getInset(i)->linuxdoc(buf, os, runparams); font_old = font; continue; } @@ -1296,8 +1291,7 @@ void Paragraph::simpleLinuxDocOnePar(Buffer const & buf, if (ws && !isFreeSpacing()) { // in freespacing mode, spaces are // non-breaking characters - if (desc_on) {// if char is ' ' then... - + if (desc_on) { // if char is ' ' then... ++char_line_count; sgmlLineBreak(os, char_line_count, 6); os << ""; @@ -1338,10 +1332,11 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf, bool emph_flag = false; LyXLayout_ptr const & style = layout(); - LyXLayout_ptr const & defaultstyle - = buf.params().getLyXTextClass().defaultLayout(); + LyXLayout_ptr const & defaultstyle = + buf.params().getLyXTextClass().defaultLayout(); - LyXFont font_old = (style->labeltype == LABEL_MANUAL ? style->labelfont : style->font); + LyXFont font_old = + style->labeltype == LABEL_MANUAL ? style->labelfont : style->font; int char_line_count = depth; bool label_closed = true; diff --git a/src/rowpainter.C b/src/rowpainter.C index 1df7256337..ae59e2e7f9 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -599,7 +599,7 @@ void RowPainter::paintFirst() LyXLayout_ptr const & layout = pit_->layout(); if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) { - if (pit_ != text_.ownerParagraphs().begin()) { + if (pit_ != text_.paragraphs().begin()) { if (layout->latextype == LATEX_PARAGRAPH && !pit_->getDepth()) { y_top += buffer.params().getDefSkip().inPixels(bv_); @@ -618,7 +618,7 @@ void RowPainter::paintFirst() int const ww = bv_.workWidth(); bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params()); - bool const is_seq = isFirstInSequence(pit_, text_.ownerParagraphs()); + bool const is_seq = isFirstInSequence(pit_, text_.paragraphs()); //lyxerr << "paintFirst: " << pit_->id() << " is_seq: " << is_seq << std::endl; // should we print a label? @@ -712,7 +712,7 @@ void RowPainter::paintLast() { int const ww = bv_.workWidth(); bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params()); - int const endlabel = getEndLabel(pit_, text_.ownerParagraphs()); + int const endlabel = getEndLabel(pit_, text_.paragraphs()); // draw an endlabel switch (endlabel) { @@ -860,7 +860,7 @@ int paintPars(BufferView const & bv, LyXText const & text, int const y2 = bv.painter().paperHeight(); y -= bv.top_y(); - ParagraphList::iterator end = text.ownerParagraphs().end(); + ParagraphList::iterator end = text.paragraphs().end(); for ( ; pit != end; ++pit) { RowList::iterator row = pit->rows.begin(); @@ -890,5 +890,5 @@ int paintText(BufferView const & bv) void paintTextInset(BufferView const & bv, LyXText const & text, int xo, int yo) { - paintPars(bv, text, text.ownerParagraphs().begin(), xo, yo, 0); + paintPars(bv, text, text.paragraphs().begin(), xo, yo, 0); } diff --git a/src/tabular.C b/src/tabular.C index 33a81a2ff2..2294c231a5 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -241,9 +241,7 @@ bool getTokenValue(string const & str, const char * token, int & num) bool getTokenValue(string const & str, const char * token, LyXAlignment & num) { string tmp; - if (!getTokenValue(str, token, tmp)) - return false; - return string2type(tmp, num); + return getTokenValue(str, token, tmp) && string2type(tmp, num); } @@ -251,9 +249,7 @@ bool getTokenValue(string const & str, const char * token, LyXTabular::VAlignment & num) { string tmp; - if (!getTokenValue(str, token, tmp)) - return false; - return string2type(tmp, num); + return getTokenValue(str, token, tmp) && string2type(tmp, num); } @@ -261,9 +257,7 @@ bool getTokenValue(string const & str, const char * token, LyXTabular::BoxType & num) { string tmp; - if (!getTokenValue(str, token, tmp)) - return false; - return string2type(tmp, num); + return getTokenValue(str, token, tmp) && string2type(tmp, num); } @@ -273,9 +267,7 @@ bool getTokenValue(string const & str, const char * token, bool & flag) // not in the file-format. flag = false; string tmp; - if (!getTokenValue(str, token, tmp)) - return false; - return string2type(tmp, flag); + return getTokenValue(str, token, tmp) && string2type(tmp, flag); } @@ -285,9 +277,7 @@ bool getTokenValue(string const & str, const char * token, LyXLength & len) // in the file format. len = LyXLength(); string tmp; - if (!getTokenValue(str, token, tmp)) - return false; - return isValidLength(tmp, &len); + return getTokenValue(str, token, tmp) && isValidLength(tmp, &len); } @@ -1397,7 +1387,7 @@ void LyXTabular::setMultiColumn(Buffer * buffer, int cell, int number) for (int i = 1; i < number; ++i) { cellstruct & cs1 = cellinfo_of_cell(cell + i); cs1.multicolumn = CELL_PART_OF_MULTICOLUMN; - cs.inset.appendParagraphs(buffer, cs1.inset.paragraphs); + cs.inset.appendParagraphs(buffer, cs1.inset.paragraphs()); cs1.inset.clear(false); } set_row_column_number_info(); @@ -2018,8 +2008,8 @@ int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf, ret += TeXCellPreamble(os, cell); InsetText & inset = getCellInset(cell); - bool rtl = inset.paragraphs.begin()->isRightToLeftPar(bufferparams) && - !inset.paragraphs.begin()->empty() && getPWidth(cell).zero(); + bool rtl = inset.paragraphs().begin()->isRightToLeftPar(bufferparams) && + !inset.paragraphs().begin()->empty() && getPWidth(cell).zero(); if (rtl) os << "\\R{"; @@ -2601,7 +2591,7 @@ void LyXTabular::getLabelList(Buffer const & buffer, LyXTabular::BoxType LyXTabular::useParbox(int cell) const { - ParagraphList const & parlist = getCellInset(cell).paragraphs; + ParagraphList const & parlist = getCellInset(cell).paragraphs(); ParagraphList::const_iterator cit = parlist.begin(); ParagraphList::const_iterator end = parlist.end(); diff --git a/src/text.C b/src/text.C index d2ef15453b..624ff48e86 100644 --- a/src/text.C +++ b/src/text.C @@ -108,8 +108,8 @@ BufferView * LyXText::bv() const void LyXText::updateParPositions() { - ParagraphList::iterator pit = ownerParagraphs().begin(); - ParagraphList::iterator end = ownerParagraphs().end(); + ParagraphList::iterator pit = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); for (height = 0; pit != end; ++pit) { pit->y = height; height += pit->height; @@ -192,9 +192,9 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const if (pit->getDepth() == 0) { if (pit->layout() == tclass.defaultLayout()) { // find the previous same level paragraph - if (pit != ownerParagraphs().begin()) { + if (pit != paragraphs().begin()) { ParagraphList::iterator newpit = - depthHook(pit, ownerParagraphs(), pit->getDepth()); + depthHook(pit, paragraphs(), pit->getDepth()); if (newpit == pit && newpit->layout()->nextnoindent) parindent.erase(); } @@ -202,16 +202,16 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const } else { // find the next level paragraph ParagraphList::iterator newpar = - outerHook(pit, ownerParagraphs()); + outerHook(pit, paragraphs()); // Make a corresponding row. Need to call leftMargin() // to check whether it is a sufficent paragraph. - if (newpar != ownerParagraphs().end() + if (newpar != paragraphs().end() && newpar->layout()->isEnvironment()) { x = leftMargin(newpar); } - if (newpar != ownerParagraphs().end() + if (newpar != paragraphs().end() && pit->layout() == tclass.defaultLayout()) { if (newpar->params().noindent()) parindent.erase(); @@ -266,7 +266,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const // theorems (JMarc) || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(pit, ownerParagraphs()))) { + && !isFirstInSequence(pit, paragraphs()))) { x += font_metrics::signedWidth(layout->leftmargin, labelfont); } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT @@ -298,11 +298,8 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const } } - if (!pit->params().leftIndent().zero()) { - int const tw = inset_owner ? - inset_owner->latexTextWidth(bv()) : textWidth(); - x += pit->params().leftIndent().inPixels(tw); - } + if (!pit->params().leftIndent().zero()) + x += pit->params().leftIndent().inPixels(textWidth()); LyXAlignment align; @@ -318,7 +315,7 @@ int LyXText::leftMargin(ParagraphList::iterator pit, pos_type pos) const || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT || (layout->labeltype == LABEL_STATIC && layout->latextype == LATEX_ENVIRONMENT - && !isFirstInSequence(pit, ownerParagraphs()))) + && !isFirstInSequence(pit, paragraphs()))) && align == LYX_ALIGN_BLOCK && !pit->params().noindent() // in tabulars and ert paragraphs are never indented! @@ -578,9 +575,7 @@ int LyXText::labelFill(ParagraphList::iterator pit, Row const & row) const LColor_color LyXText::backgroundColor() const { - if (inset_owner) - return inset_owner->backgroundColor(); - return LColor::background; + return LColor_color(LColor::color(background_color_)); } @@ -649,7 +644,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row) // some parksips VERY EASY IMPLEMENTATION if (bv()->buffer()->params().paragraph_separation == BufferParams::PARSEP_SKIP - && pit != ownerParagraphs().begin() + && pit != paragraphs().begin() && ((layout->isParagraph() && pit->getDepth() == 0) || (boost::prior(pit)->layout()->isParagraph() && boost::prior(pit)->getDepth() == 0))) @@ -671,7 +666,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row) if ((layout->labeltype == LABEL_TOP_ENVIRONMENT || layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) - && isFirstInSequence(pit, ownerParagraphs()) + && isFirstInSequence(pit, paragraphs()) && !pit->getLabelstring().empty()) { labeladdon = int( @@ -686,22 +681,22 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row) // environment. ParagraphList::iterator prev = - depthHook(pit, ownerParagraphs(), pit->getDepth()); + depthHook(pit, paragraphs(), pit->getDepth()); if (prev != pit && prev->layout() == layout && prev->getDepth() == pit->getDepth() && prev->getLabelWidthString() == pit->getLabelWidthString()) { layoutasc = layout->itemsep * dh; - } else if (pit != ownerParagraphs().begin() || row.pos() != 0) { + } else if (pit != paragraphs().begin() || row.pos() != 0) { if (layout->topsep > 0) layoutasc = layout->topsep * dh; } - prev = outerHook(pit, ownerParagraphs()); - if (prev != ownerParagraphs().end()) { + prev = outerHook(pit, paragraphs()); + if (prev != paragraphs().end()) { maxasc += int(prev->layout()->parsep * dh); - } else if (pit != ownerParagraphs().begin()) { + } else if (pit != paragraphs().begin()) { ParagraphList::iterator prior_pit = boost::prior(pit); if (prior_pit->getDepth() != 0 || prior_pit->layout() == layout) { @@ -716,14 +711,14 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row) // a section, or between the items of a itemize or enumerate // environment ParagraphList::iterator nextpit = boost::next(pit); - if (nextpit != ownerParagraphs().end()) { + if (nextpit != paragraphs().end()) { ParagraphList::iterator cpit = pit; double usual = 0; double unusual = 0; if (cpit->getDepth() > nextpit->getDepth()) { usual = cpit->layout()->bottomsep * dh; - cpit = depthHook(cpit, ownerParagraphs(), nextpit->getDepth()); + cpit = depthHook(cpit, paragraphs(), nextpit->getDepth()); if (cpit->layout() != nextpit->layout() || nextpit->getLabelWidthString() != cpit->getLabelWidthString()) { @@ -1242,7 +1237,7 @@ void LyXText::changeCase(LyXText::TextCase action) pos_type pos = from.pos(); int par = from.par(); - while (par != int(ownerParagraphs().size()) && + while (par != int(paragraphs().size()) && (pos != to.pos() || par != to.par())) { ParagraphList::iterator pit = getPar(par); if (pos == pit->size()) { @@ -1400,8 +1395,8 @@ ParagraphList::iterator LyXText::getPar(LyXCursor const & cur) const ParagraphList::iterator LyXText::getPar(int par) const { BOOST_ASSERT(par >= 0); - BOOST_ASSERT(par < int(ownerParagraphs().size())); - ParagraphList::iterator pit = ownerParagraphs().begin(); + BOOST_ASSERT(par < int(paragraphs().size())); + ParagraphList::iterator pit = paragraphs().begin(); std::advance(pit, par); return pit; } @@ -1413,8 +1408,8 @@ LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const //lyxerr << "getRowNearY: y " << y << endl; #if 1 ParagraphList::iterator const - pend = boost::prior(ownerParagraphs().end()); - pit = ownerParagraphs().begin(); + pend = boost::prior(paragraphs().end()); + pit = paragraphs().begin(); while (int(pit->y + pit->height) < y && pit != pend) ++pit; @@ -1426,7 +1421,7 @@ LyXText::getRowNearY(int y, ParagraphList::iterator & pit) const return rit; #else - pit = boost::prior(ownerParagraphs().end()); + pit = boost::prior(paragraphs().end()); RowList::iterator rit = lastRow(); RowList::iterator rbegin = firstRow(); @@ -1447,13 +1442,13 @@ int LyXText::getDepth() const RowList::iterator LyXText::firstRow() const { - return ownerParagraphs().front().rows.begin(); + return paragraphs().front().rows.begin(); } ParagraphList::iterator LyXText::firstPar() const { - return ownerParagraphs().begin(); + return paragraphs().begin(); } @@ -1471,13 +1466,13 @@ ParagraphList::iterator LyXText::lastPar() const RowList::iterator LyXText::endRow() const { - return ownerParagraphs().back().rows.end(); + return paragraphs().back().rows.end(); } ParagraphList::iterator LyXText::endPar() const { - return ownerParagraphs().end(); + return paragraphs().end(); } @@ -1487,7 +1482,7 @@ void LyXText::nextRow(ParagraphList::iterator & pit, ++rit; if (rit == pit->rows.end()) { ++pit; - if (pit == ownerParagraphs().end()) + if (pit == paragraphs().end()) --pit; else rit = pit->rows.begin(); @@ -1501,7 +1496,7 @@ void LyXText::previousRow(ParagraphList::iterator & pit, if (rit != pit->rows.begin()) --rit; else { - BOOST_ASSERT(pit != ownerParagraphs().begin()); + BOOST_ASSERT(pit != paragraphs().begin()); --pit; rit = boost::prior(pit->rows.end()); } @@ -1540,7 +1535,7 @@ string LyXText::selectionAsString(Buffer const & buffer, bool label) const int LyXText::parOffset(ParagraphList::iterator pit) const { - return std::distance(ownerParagraphs().begin(), pit); + return std::distance(paragraphs().begin(), pit); } @@ -1603,7 +1598,7 @@ void LyXText::redoParagraph(ParagraphList::iterator pit) void LyXText::fullRebreak() { - redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); + redoParagraphs(paragraphs().begin(), paragraphs().end()); redoCursor(); selection.cursor = cursor; } @@ -1618,9 +1613,9 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) // << " textWidth: " << textWidth() << "\nfont: " << mi.base.font << endl; // Rebuild row cache. This recomputes height as well. - redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); + redoParagraphs(paragraphs().begin(), paragraphs().end()); - width = maxParagraphWidth(ownerParagraphs()); + width = maxParagraphWidth(paragraphs()); // final dimension dim.asc = firstRow()->ascent_of_text(); @@ -1641,13 +1636,13 @@ void LyXText::draw(PainterInfo & pi, int x, int y) const bool LyXText::isLastRow(ParagraphList::iterator pit, Row const & row) const { return row.endpos() >= pit->size() - && boost::next(pit) == ownerParagraphs().end(); + && boost::next(pit) == paragraphs().end(); } bool LyXText::isFirstRow(ParagraphList::iterator pit, Row const & row) const { - return row.pos() == 0 && pit == ownerParagraphs().begin(); + return row.pos() == 0 && pit == paragraphs().begin(); } @@ -1671,7 +1666,7 @@ void LyXText::cursorLeftOneWord(LyXCursor & cursor) pit->isHfill(pos - 1))) { --pos; } else if (!pos) { - if (pit != ownerParagraphs().begin()) { + if (pit != paragraphs().begin()) { --pit; pos = pit->size(); } @@ -1692,7 +1687,7 @@ void LyXText::cursorRightOneWord(LyXCursor & cursor) pos_type pos = cursor.pos(); if (pos == pit->size() && - boost::next(pit) != ownerParagraphs().end()) { + boost::next(pit) != paragraphs().end()) { ++pit; pos = 0; } else { diff --git a/src/text2.C b/src/text2.C index f85342d4a1..ff3e4746cc 100644 --- a/src/text2.C +++ b/src/text2.C @@ -37,6 +37,7 @@ #include "funcrequest.h" #include "gettext.h" #include "language.h" +#include "LColor.h" #include "lyxrc.h" #include "lyxrow.h" #include "lyxrow_funcs.h" @@ -71,11 +72,10 @@ using std::ostringstream; using std::string; -LyXText::LyXText(BufferView * bv, InsetText * inset, bool in_inset, - ParagraphList & paragraphs) +LyXText::LyXText(BufferView * bv, bool in_inset) : height(0), width(0), textwidth_(bv ? bv->workWidth() : 100), - inset_owner(inset), bv_owner(bv), - in_inset_(in_inset), paragraphs_(¶graphs), xo_(0), yo_(0) + background_color_(LColor::background), + bv_owner(bv), in_inset_(in_inset), xo_(0), yo_(0) {} @@ -83,8 +83,8 @@ void LyXText::init(BufferView * bview) { bv_owner = bview; - ParagraphList::iterator const beg = ownerParagraphs().begin(); - ParagraphList::iterator const end = ownerParagraphs().end(); + ParagraphList::iterator const beg = paragraphs().begin(); + ParagraphList::iterator const end = paragraphs().end(); for (ParagraphList::iterator pit = beg; pit != end; ++pit) pit->rows.clear(); @@ -140,7 +140,7 @@ LyXFont LyXText::getFont(ParagraphList::iterator pit, pos_type pos) const pit->inInset()->getDrawFont(font); // Realize with the fonts of lesser depth. - //font.realize(outerFont(pit, ownerParagraphs())); + //font.realize(outerFont(pit, paragraphs())); font.realize(defaultfont_); return font; @@ -156,7 +156,7 @@ LyXFont LyXText::getLayoutFont(ParagraphList::iterator pit) const LyXFont font = layout->font; // Realize with the fonts of lesser depth. - //font.realize(outerFont(pit, ownerParagraphs())); + //font.realize(outerFont(pit, paragraphs())); font.realize(defaultfont_); return font; @@ -172,7 +172,7 @@ LyXFont LyXText::getLabelFont(ParagraphList::iterator pit) const LyXFont font = layout->labelfont; // Realize with the fonts of lesser depth. - font.realize(outerFont(pit, ownerParagraphs())); + font.realize(outerFont(pit, paragraphs())); font.realize(defaultfont_); return font; @@ -197,10 +197,10 @@ void LyXText::setCharFont( if (pit->getDepth()) { ParagraphList::iterator tp = pit; while (!layoutfont.resolved() && - tp != ownerParagraphs().end() && + tp != paragraphs().end() && tp->getDepth()) { - tp = outerHook(tp, ownerParagraphs()); - if (tp != ownerParagraphs().end()) + tp = outerHook(tp, paragraphs()); + if (tp != paragraphs().end()) layoutfont.realize(tp->layout()->font); } } @@ -226,21 +226,12 @@ InsetOld * LyXText::getInset() const } -void LyXText::toggleInset() +bool LyXText::toggleInset() { InsetOld * inset = getInset(); // is there an editable inset at cursor position? - if (!isEditableInset(inset)) { - // No, try to see if we are inside a collapsable inset - if (inset_owner && inset_owner->owner() - && inset_owner->owner()->isOpen()) { - finishUndo(); - inset_owner->owner()->close(); - bv()->getLyXText()->cursorRight(true); - bv()->updateParagraphDialog(); - } - return; - } + if (!isEditableInset(inset)) + return false; //bv()->owner()->message(inset->editMessage()); // do we want to keep this?? (JMarc) @@ -251,6 +242,7 @@ void LyXText::toggleInset() inset->close(); else inset->open(); + return true; } @@ -283,7 +275,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur, { ParagraphList::iterator endpit = boost::next(getPar(send_cur)); ParagraphList::iterator undoendpit = endpit; - ParagraphList::iterator pars_end = ownerParagraphs().end(); + ParagraphList::iterator pars_end = paragraphs().end(); if (endpit != pars_end && endpit->getDepth()) { while (endpit != pars_end && endpit->getDepth()) { @@ -312,7 +304,7 @@ LyXText::setLayout(LyXCursor & cur, LyXCursor & sstart_cur, makeFontEntriesLayoutSpecific(bufparams, *pit); if (lyxlayout->margintype == MARGIN_MANUAL) pit->setLabelWidthString(lyxlayout->labelstring()); - cur.par(std::distance(ownerParagraphs().begin(), pit)); + cur.par(std::distance(paragraphs().begin(), pit)); ++pit; } while (pit != epit); @@ -391,7 +383,7 @@ bool LyXText::changeDepthAllowed(bv_funcs::DEPTH_CHANGE type) ParagraphList::iterator beg, end; getSelectionSpan(*this, beg, end); int max_depth = 0; - if (beg != ownerParagraphs().begin()) + if (beg != paragraphs().begin()) max_depth = boost::prior(beg)->getMaxDepthAfter(); for (ParagraphList::iterator pit = beg; pit != end; ++pit) { @@ -411,7 +403,7 @@ void LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type) recUndo(parOffset(beg), parOffset(end) - 1); int max_depth = 0; - if (beg != ownerParagraphs().begin()) + if (beg != paragraphs().begin()) max_depth = boost::prior(beg)->getMaxDepthAfter(); for (ParagraphList::iterator pit = beg; pit != end; ++pit) { @@ -464,8 +456,8 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) ParagraphList::iterator beg = getPar(selection.start.par()); ParagraphList::iterator end = getPar(selection.end.par()); - PosIterator pos(&ownerParagraphs(), beg, selection.start.pos()); - PosIterator posend(&ownerParagraphs(), end, selection.end.pos()); + PosIterator pos(¶graphs(), beg, selection.start.pos()); + PosIterator posend(¶graphs(), end, selection.end.pos()); BufferParams const & params = bv()->buffer()->params(); @@ -524,14 +516,14 @@ void LyXText::cursorEnd() void LyXText::cursorTop() { - setCursor(ownerParagraphs().begin(), 0); + setCursor(paragraphs().begin(), 0); } void LyXText::cursorBottom() { ParagraphList::iterator lastpit = - boost::prior(ownerParagraphs().end()); + boost::prior(paragraphs().end()); setCursor(lastpit, lastpit->size()); } @@ -599,7 +591,7 @@ string LyXText::getStringToIndex() } -// the DTP switches for paragraphs. LyX will store them in the first +// the DTP switches for paragraphs(). LyX will store them in the first // physical paragraph. When a paragraph is broken, the top settings rest, // the bottom settings are given to the new one. So I can make sure, // they do not duplicate themself and you cannot play dirty tricks with @@ -615,7 +607,7 @@ void LyXText::setParagraph( // make sure that the depth behind the selection are restored, too ParagraphList::iterator endpit = boost::next(getPar(selection.end)); ParagraphList::iterator undoendpit = endpit; - ParagraphList::iterator pars_end = ownerParagraphs().end(); + ParagraphList::iterator pars_end = paragraphs().end(); if (endpit != pars_end && endpit->getDepth()) { while (endpit != pars_end && endpit->getDepth()) { @@ -765,7 +757,7 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit) BufferParams const & bufparams = buf.params(); LyXTextClass const & textclass = bufparams.getLyXTextClass(); LyXLayout_ptr const & layout = pit->layout(); - ParagraphList::iterator first_pit = ownerParagraphs().begin(); + ParagraphList::iterator first_pit = paragraphs().begin(); Counters & counters = textclass.counters(); // Always reset @@ -866,7 +858,7 @@ void LyXText::setCounter(Buffer const & buf, ParagraphList::iterator pit) // the caption hack: if (layout->labeltype == LABEL_SENSITIVE) { - ParagraphList::iterator end = ownerParagraphs().end(); + ParagraphList::iterator end = paragraphs().end(); ParagraphList::iterator tmppit = pit; InsetOld * in = 0; bool isOK = false; @@ -923,8 +915,8 @@ void LyXText::updateCounters() bool update_pos = false; - ParagraphList::iterator beg = ownerParagraphs().begin(); - ParagraphList::iterator end = ownerParagraphs().end(); + ParagraphList::iterator beg = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); for (ParagraphList::iterator pit = beg; pit != end; ++pit) { string const oldLabel = pit->params().labelString(); size_t maxdepth = 0; @@ -992,7 +984,7 @@ void LyXText::cutSelection(bool doclear, bool realcut) // make sure that the depth behind the selection are restored, too ParagraphList::iterator endpit = boost::next(getPar(selection.end.par())); ParagraphList::iterator undoendpit = endpit; - ParagraphList::iterator pars_end = ownerParagraphs().end(); + ParagraphList::iterator pars_end = paragraphs().end(); if (endpit != pars_end && endpit->getDepth()) { while (endpit != pars_end && endpit->getDepth()) { @@ -1012,13 +1004,13 @@ void LyXText::cutSelection(bool doclear, bool realcut) BufferParams const & bufparams = bv()->buffer()->params(); boost::tie(endpit, endpos) = realcut ? CutAndPaste::cutSelection(bufparams, - ownerParagraphs(), + paragraphs(), getPar(selection.start.par()), endpit, selection.start.pos(), endpos, bufparams.textclass, doclear) : CutAndPaste::eraseSelection(bufparams, - ownerParagraphs(), + paragraphs(), getPar(selection.start.par()), endpit, selection.start.pos(), endpos, doclear); @@ -1083,7 +1075,7 @@ void LyXText::pasteSelection(size_t sel_index) boost::tie(ppp, endpit) = CutAndPaste::pasteSelection(*bv()->buffer(), - ownerParagraphs(), + paragraphs(), cursorPar(), cursor.pos(), bv()->buffer()->params().textclass, sel_index, el); @@ -1168,8 +1160,8 @@ void LyXText::insertStringAsLines(string const & str) } -// turns double-CR to single CR, others where converted into one -// blank. Then InsertStringAsLines is called +// turn double CR to single CR, others are converted into one +// blank. Then insertStringAsLines is called void LyXText::insertStringAsParagraphs(string const & str) { string linestr(str); @@ -1180,7 +1172,7 @@ void LyXText::insertStringAsParagraphs(string const & str) if (linestr[i] == '\n') { if (newline_inserted) { // we know that \r will be ignored by - // InsertStringA. Of course, it is a dirty + // insertStringAsLines. Of course, it is a dirty // trick, but it works... linestr[i - 1] = '\r'; linestr[i] = '\n'; @@ -1202,7 +1194,8 @@ void LyXText::setCursor(ParagraphList::iterator pit, pos_type pos) } -bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, bool boundary) +bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont, + bool boundary) { LyXCursor old_cursor = cursor; setCursorIntern(par, pos, setfont, boundary); @@ -1228,14 +1221,14 @@ void LyXText::redoCursor() void LyXText::setCursor(LyXCursor & cur, paroffset_type par, pos_type pos, bool boundary) { - BOOST_ASSERT(par != int(ownerParagraphs().size())); + BOOST_ASSERT(par != int(paragraphs().size())); cur.par(par); cur.pos(pos); cur.boundary(boundary); // no rows, no fun... - if (ownerParagraphs().begin()->rows.empty()) + if (paragraphs().begin()->rows.empty()) return; // get the cursor y position in text @@ -1413,8 +1406,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit, double last_tmpx = tmpx; if (body_pos > 0 && - (body_pos > end || - !pit->isLineSeparator(body_pos - 1))) + (body_pos > end || !pit->isLineSeparator(body_pos - 1))) body_pos = 0; // check for empty row @@ -1557,7 +1549,7 @@ DispatchResult LyXText::moveLeft() DispatchResult LyXText::moveRightIntern(bool front, bool activate_inset, bool selecting) { ParagraphList::iterator c_par = cursorPar(); - if (boost::next(c_par) == ownerParagraphs().end() + if (boost::next(c_par) == paragraphs().end() && cursor.pos() >= c_par->size()) return DispatchResult(false, FINISHED_RIGHT); if (activate_inset && checkAndActivateInset(front)) @@ -1639,7 +1631,7 @@ bool LyXText::cursorRight(bool internal) return true; } - if (cursor.par() + 1 != int(ownerParagraphs().size())) { + if (cursor.par() + 1 != int(paragraphs().size())) { setCursor(cursor.par() + 1, 0); return true; } @@ -1685,7 +1677,7 @@ void LyXText::cursorUpParagraph() ParagraphList::iterator cpit = cursorPar(); if (cursor.pos() > 0) setCursor(cpit, 0); - else if (cpit != ownerParagraphs().begin()) + else if (cpit != paragraphs().begin()) setCursor(boost::prior(cpit), 0); } @@ -1695,7 +1687,7 @@ void LyXText::cursorDownParagraph() ParagraphList::iterator pit = cursorPar(); ParagraphList::iterator next_pit = boost::next(pit); - if (next_pit != ownerParagraphs().end()) + if (next_pit != paragraphs().end()) setCursor(next_pit, 0); else setCursor(pit, pit->size()); @@ -1747,7 +1739,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) Copy and Paste to hopefully do some sensible things. There are still some small problems that can lead to double spaces stored in the document file or space at - the beginning of paragraphs. This happens if you have + the beginning of paragraphs(). This happens if you have the cursor between to spaces and then save. Or if you cut and paste and the selection have a space at the beginning and then save right after the paste. I am @@ -1794,7 +1786,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) } // don't delete anything if this is the ONLY paragraph! - if (ownerParagraphs().size() == 1) + if (paragraphs().size() == 1) return false; // Do not delete empty paragraphs with keepempty set. @@ -1824,7 +1816,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) cursor = old_cursor; // that undo can restore the right cursor position ParagraphList::iterator endpit = boost::next(old_pit); - while (endpit != ownerParagraphs().end() && endpit->getDepth()) + while (endpit != paragraphs().end() && endpit->getDepth()) ++endpit; recUndo(parOffset(old_pit), parOffset(endpit) - 1); @@ -1833,7 +1825,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) // cache cursor pit ParagraphList::iterator tmppit = cursorPar(); // delete old par - ownerParagraphs().erase(old_pit); + paragraphs().erase(old_pit); // update cursor par offset cursor.par(parOffset(tmppit)); redoParagraph(); @@ -1860,9 +1852,9 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor) } -ParagraphList & LyXText::ownerParagraphs() const +ParagraphList & LyXText::paragraphs() const { - return *paragraphs_; + return const_cast(paragraphs_); } @@ -1880,13 +1872,11 @@ void LyXText::recUndo(lyx::paroffset_type par) const bool LyXText::isInInset() const { - // Sub-level has non-null bv owner and non-null inset owner. - return inset_owner != 0; + return in_inset_; } int defaultRowHeight() { - LyXFont const font(LyXFont::ALL_SANE); - return int(font_metrics::maxHeight(font) * 1.2); + return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) * 1.2); } diff --git a/src/text3.C b/src/text3.C index a4fc9b0b25..8bc6b3d053 100644 --- a/src/text3.C +++ b/src/text3.C @@ -258,7 +258,7 @@ InsetOld * LyXText::checkInsetHit(int x, int y) ParagraphList::iterator pit; ParagraphList::iterator end; - getParsInRange(ownerParagraphs(), + getParsInRange(paragraphs(), bv()->top_y() - yo_, bv()->top_y() - yo_ + bv()->workHeight(), pit, end); @@ -293,7 +293,7 @@ InsetOld * LyXText::checkInsetHit(int x, int y) bool LyXText::gotoNextInset(vector const & codes, string const & contents) { - ParagraphList::iterator end = ownerParagraphs().end(); + ParagraphList::iterator end = paragraphs().end(); ParagraphList::iterator pit = cursorPar(); pos_type pos = cursor.pos(); @@ -337,7 +337,7 @@ void LyXText::gotoInset(vector const & codes, } if (!gotoNextInset(codes, contents)) { - if (cursor.pos() || cursorPar() != ownerParagraphs().begin()) { + if (cursor.pos() || cursorPar() != paragraphs().begin()) { LyXCursor tmp = cursor; cursor.par(0); cursor.pos(0); @@ -467,8 +467,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) bool start = !pit->params().startOfAppendix(); // ensure that we have only one start_of_appendix in this document - ParagraphList::iterator tmp = ownerParagraphs().begin(); - ParagraphList::iterator end = ownerParagraphs().end(); + ParagraphList::iterator tmp = paragraphs().begin(); + ParagraphList::iterator end = paragraphs().end(); for (; tmp != end; ++tmp) { if (tmp->params().startOfAppendix()) { @@ -889,7 +889,8 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) case LFUN_INSET_TOGGLE: clearSelection(); - toggleInset(); + if (!toggleInset()) + return DispatchResult(false); bv->update(); bv->switchKeyMap(); break; @@ -996,14 +997,14 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd) break; case LFUN_BEGINNINGBUFSEL: - if (inset_owner) + if (in_inset_) return DispatchResult(false); cursorTop(); finishChange(bv, true); break; case LFUN_ENDBUFSEL: - if (inset_owner) + if (in_inset_) return DispatchResult(false); cursorBottom(); finishChange(bv, true); diff --git a/src/undo.C b/src/undo.C index 90ca31c65b..820a12732b 100644 --- a/src/undo.C +++ b/src/undo.C @@ -61,15 +61,14 @@ std::ostream & operator<<(std::ostream & os, Undo const & undo) // translates LyXText pointer into offset count from document begin -ParIterator text2pit(BufferView * bv, LyXText * text, int & tcount) +ParIterator text2pit(Buffer & buf, LyXText * text, int & tcount) { tcount = 0; - Buffer * buf = text->bv()->buffer(); - ParIterator pit = buf->par_iterator_begin(); - ParIterator end = buf->par_iterator_end(); + ParIterator pit = buf.par_iterator_begin(); + ParIterator end = buf.par_iterator_end(); for ( ; pit != end; ++pit, ++tcount) - if (pit.text(bv) == text) + if (pit.text(buf) == text) return pit; lyxerr << "undo: should not happen" << std::endl; return end; @@ -77,11 +76,10 @@ ParIterator text2pit(BufferView * bv, LyXText * text, int & tcount) // translates offset from buffer begin to ParIterator -ParIterator num2pit(BufferView * bv, int num) +ParIterator num2pit(Buffer & buf, int num) { - Buffer * buf = bv->buffer(); - ParIterator pit = buf->par_iterator_begin(); - ParIterator end = buf->par_iterator_end(); + ParIterator pit = buf.par_iterator_begin(); + ParIterator end = buf.par_iterator_end(); for ( ; num && pit != end; ++pit, --num) ; @@ -92,7 +90,7 @@ ParIterator num2pit(BufferView * bv, int num) // don't crash early... lyxerr << "undo: num2pit: num: " << num << std::endl; BOOST_ASSERT(false); - return buf->par_iterator_begin(); + return buf.par_iterator_begin(); } @@ -100,19 +98,19 @@ void recordUndo(Undo::undo_kind kind, LyXText * text, paroffset_type first_par, paroffset_type last_par, limited_stack & stack) { - Buffer * buf = text->bv()->buffer(); + Buffer & buf = *text->bv()->buffer(); - int const end_par = text->ownerParagraphs().size() - last_par; + int const end_par = text->paragraphs().size() - last_par; // Undo::ATOMIC are always recorded (no overlapping there). // overlapping only with insert and delete inside one paragraph: // nobody wants all removed character appear one by one when undoing. if (!undo_finished && kind != Undo::ATOMIC) { // Check whether storing is needed. - if (!buf->undostack().empty() - && buf->undostack().top().kind == kind - && buf->undostack().top().first_par == first_par - && buf->undostack().top().end_par == end_par) { + if (!buf.undostack().empty() + && buf.undostack().top().kind == kind + && buf.undostack().top().first_par == first_par + && buf.undostack().top().end_par == end_par) { // No additonal undo recording needed - // effectively, we combine undo recordings to one. return; @@ -121,7 +119,7 @@ void recordUndo(Undo::undo_kind kind, // make and push the Undo entry int textnum; - ParIterator pit = text2pit(text->bv(), text, textnum); + ParIterator pit = text2pit(buf, text, textnum); stack.push(Undo(kind, textnum, pit.index(), first_par, end_par, text->cursor.par(), text->cursor.pos())); lyxerr << "undo record: " << stack.top() << std::endl; @@ -129,7 +127,7 @@ void recordUndo(Undo::undo_kind kind, // record the relevant paragraphs ParagraphList & undo_pars = stack.top().pars; - ParagraphList & plist = text->ownerParagraphs(); + ParagraphList & plist = text->paragraphs(); ParagraphList::iterator first = plist.begin(); advance(first, first_par); ParagraphList::iterator last = plist.begin(); @@ -147,10 +145,11 @@ void recordUndo(Undo::undo_kind kind, // returns false if no undo possible bool performUndoOrRedo(BufferView * bv, Undo const & undo) { + Buffer & buf = *bv->buffer(); lyxerr << "undo, performing: " << undo << std::endl; - ParIterator pit = num2pit(bv, undo.text); - LyXText * text = pit.text(bv); - ParagraphList & plist = text->ownerParagraphs(); + ParIterator pit = num2pit(buf, undo.text); + LyXText * text = pit.text(buf); + ParagraphList & plist = text->paragraphs(); // remove new stuff between first and last { @@ -171,7 +170,7 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) } // set cursor - lyxerr << "undo, text: " << undo.text + lyxerr << "undo, text: " << undo.text << " inset: " << pit.inset() << " index: " << undo.index << " par: " << undo.cursor_par @@ -188,9 +187,10 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) text->updateCounters(); // rebreak the entire lyxtext - bv->text()->fullRebreak(); + buf.text().fullRebreak(); pit.lockPath(bv); + text->setCursor(undo.cursor_par, undo.cursor_pos); finishUndo(); return true; @@ -201,6 +201,7 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) bool textUndoOrRedo(BufferView * bv, limited_stack & stack, limited_stack & otherstack) { + Buffer & buf = *bv->buffer(); if (stack.empty()) { // nothing to do finishUndo(); @@ -214,7 +215,7 @@ bool textUndoOrRedo(BufferView * bv, if (!undo_frozen) { otherstack.push(undo); otherstack.top().pars.clear(); - ParIterator pit = num2pit(bv, undo.text); + ParIterator pit = num2pit(buf, undo.text); ParagraphList & plist = pit.plist(); if (undo.first_par + undo.end_par <= int(plist.size())) { ParagraphList::iterator first = plist.begin(); @@ -223,7 +224,7 @@ bool textUndoOrRedo(BufferView * bv, advance(last, plist.size() - undo.end_par + 1); otherstack.top().pars.insert(otherstack.top().pars.begin(), first, last); } - LyXText * text = pit.text(bv); + LyXText * text = pit.text(buf); otherstack.top().cursor_pos = text->cursor.pos(); otherstack.top().cursor_par = text->cursor.par(); lyxerr << " undo other: " << otherstack.top() << std::endl; -- 2.39.2