From ef2290cf5e29a6bd1b5e8b83ff3b616a805a5543 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 26 Aug 2003 10:33:59 +0000 Subject: [PATCH] Martin's fullRow patch git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7605 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 15 ++++--- src/ChangeLog | 9 ++++ src/insets/ChangeLog | 19 +++++++++ src/insets/inset.h | 8 ---- src/insets/insetbibtex.C | 15 +++++++ src/insets/insetbibtex.h | 7 +++- src/insets/insetbranch.C | 13 ------ src/insets/insetbranch.h | 4 -- src/insets/insetcollapsable.h | 2 - src/insets/insetert.C | 5 +++ src/insets/insetert.h | 4 +- src/insets/insetfloatlist.C | 16 +++++++ src/insets/insetfloatlist.h | 9 +++- src/insets/insetfootlike.C | 10 +++++ src/insets/insetfootlike.h | 2 + src/insets/insetinclude.C | 15 ++++--- src/insets/insetinclude.h | 4 +- src/insets/insetindex.C | 16 +++++++ src/insets/insetindex.h | 11 +++-- src/insets/insetminipage.h | 2 - src/insets/insetnote.C | 19 +++++++-- src/insets/insetnote.h | 2 + src/insets/insettext.C | 3 +- src/insets/insettheorem.C | 15 +++++++ src/insets/insettheorem.h | 7 +++- src/insets/insettoc.C | 15 +++++++ src/insets/insettoc.h | 10 ++++- src/lyxrow_funcs.C | 20 --------- src/lyxtext.h | 6 +-- src/text.C | 72 +++++++------------------------- src/text2.C | 78 ++++++++++------------------------- 31 files changed, 231 insertions(+), 202 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index dff8b01a8d..20645f567e 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -504,16 +504,15 @@ void BufferView::Pimpl::scrollDocView(int value) if (!lyxrc.cursor_follows_scrollbar) return; - LyXText * vbt = bv_->text; - int const height = defaultRowHeight(); - int const first = static_cast((bv_->text->top_y() + height)); - int const last = static_cast((bv_->text->top_y() + workarea().workHeight() - height)); + int const first = int((bv_->text->top_y() + height)); + int const last = int((bv_->text->top_y() + workarea().workHeight() - height)); - if (vbt->cursor.y() < first) - vbt->setCursorFromCoordinates(0, first); - else if (vbt->cursor.y() > last) - vbt->setCursorFromCoordinates(0, last); + LyXText * text = bv_->text; + if (text->cursor.y() < first) + text->setCursorFromCoordinates(0, first); + else if (text->cursor.y() > last) + text->setCursorFromCoordinates(0, last); owner_->updateLayoutChoice(); } diff --git a/src/ChangeLog b/src/ChangeLog index 1cac600253..ac3cd42758 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ + +2003-08-25 Martin Vermeer + + * lyxrow_funcs.C: + * lyxtext.h: + * text.C: + * text2.C: eliminates the needFullRow/display() stuff + altogether, putting the logic in metrics/draw in the insets. + 2003-08-25 Alfredo Braunstein * text2.C (redoParagraphInternal, redoParagraphs): diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 9907a26789..e71634b9b1 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,22 @@ +2003-08-25 Martin Vermeer + + * insets/inset.h: + * insets/insetbibtex.[Ch]: + * insets/insetbranch.[Ch]: + * insets/insetcollapsable.h: + * insets/insetert.[Ch]: + * insets/insetfloatlist.[Ch]: + * insets/insetfootlike.[Ch]: + * insets/insetinclude.[Ch]: + * insets/insetindex.[Ch]: + * insets/insetindex.h: + * insets/insetminipage.h: + * insets/insetnote.[Ch]: + * insets/insettext.C: + * insets/insettheorem.[Ch]: + * insets/insettoc.[Ch]: eliminates the needFullRow/display() stuff + altogether, putting the logic in metrics/draw in the insets.=20 + Draws short single row insets with more or less realistic metrics. 2003-08-19 André Pönitz diff --git a/src/insets/inset.h b/src/insets/inset.h index 1dbc931765..9d0313462a 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -198,14 +198,6 @@ public: /// returns true to override begin and end inset in file virtual bool directWrite() const; - /// Returns true if the inset should be centered alone - virtual bool display() const { return false; } - /// Changes the display state of the inset - virtual void display(bool) {} - /// - /// returns true if this inset needs a row on it's own - /// - virtual bool needFullRow() const { return false; } /// void setInsetName(string const & s) { name_ = s; } /// diff --git a/src/insets/insetbibtex.C b/src/insets/insetbibtex.C index d6c823f5a1..8603d09d38 100644 --- a/src/insets/insetbibtex.C +++ b/src/insets/insetbibtex.C @@ -11,6 +11,7 @@ #include #include "insetbibtex.h" +#include "metricsinfo.h" #include "buffer.h" #include "BufferView.h" #include "debug.h" @@ -53,6 +54,20 @@ std::auto_ptr InsetBibtex::clone() const return std::auto_ptr(new InsetBibtex(*this)); } +void InsetBibtex::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCommand::metrics(mi, dim); + center_indent_ = (mi.base.textwidth - dim.wid) / 2; + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + +void InsetBibtex::draw(PainterInfo & pi, int x, int y) const +{ + InsetCommand::draw(pi, x + center_indent_, y); +} + dispatch_result InsetBibtex::localDispatch(FuncRequest const & cmd) { diff --git a/src/insets/insetbibtex.h b/src/insets/insetbibtex.h index 8d99ec8c71..c5ac7ba795 100644 --- a/src/insets/insetbibtex.h +++ b/src/insets/insetbibtex.h @@ -26,6 +26,10 @@ public: ~InsetBibtex(); /// std::auto_ptr clone() const; + /// + void metrics(MetricsInfo &, Dimension &) const; + /// + void draw(PainterInfo & pi, int x, int y) const; /// small wrapper for the time being virtual dispatch_result localDispatch(FuncRequest const & cmd); /// @@ -46,8 +50,9 @@ public: bool addDatabase(string const &); /// bool delDatabase(string const &); +private: /// - bool display() const { return true; } + mutable unsigned int center_indent_; }; #endif // INSET_BIBTEX_H diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index 55a95200a6..d044120455 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -109,19 +109,6 @@ void InsetBranch::setButtonLabel() } -void InsetBranch::metrics(MetricsInfo & mi, Dimension & dim) const -{ - InsetCollapsable::metrics(mi, dim); - dim_ = dim; -} - - -void InsetBranch::draw(PainterInfo & pi, int x, int y) const -{ - InsetCollapsable::draw(pi, x, y); -} - - bool InsetBranch::showInsetDialog(BufferView * bv) const { InsetBranchMailer("branch", const_cast(*this)).showDialog(bv); diff --git a/src/insets/insetbranch.h b/src/insets/insetbranch.h index 84c6d84df9..6b0526d62a 100644 --- a/src/insets/insetbranch.h +++ b/src/insets/insetbranch.h @@ -54,10 +54,6 @@ public: /// void setButtonLabel(); /// - void metrics(MetricsInfo & mi, Dimension & dim) const; - /// - void draw(PainterInfo & pi, int x, int y) const; - /// bool showInsetDialog(BufferView *) const; /// dispatch_result localDispatch(FuncRequest const &); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index cc9bacb6ca..f67f441127 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -66,8 +66,6 @@ public: /// void insetUnlock(BufferView *); /// - bool needFullRow() const { return isOpen(); } - /// bool lockInsetInInset(BufferView *, UpdatableInset *); /// bool unlockInsetInInset(BufferView *, UpdatableInset *, diff --git a/src/insets/insetert.C b/src/insets/insetert.C index a4dba61437..0628ad540a 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -12,6 +12,7 @@ #include "insetert.h" #include "insettext.h" +#include "metricsinfo.h" #include "buffer.h" #include "BufferView.h" @@ -555,6 +556,10 @@ void InsetERT::metrics(MetricsInfo & mi, Dimension & dim) const inset.metrics(mi, dim); else InsetCollapsable::metrics(mi, dim); + // Make it stand out on its own as it is code, not part of running + // text: + if (isOpen() && !inlined()) + dim.wid = mi.base.textwidth; dim_ = dim; } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index bbdaf84883..064455d0a6 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -80,9 +80,7 @@ public: /// bool checkInsertChar(LyXFont &); /// - // this are needed here because of the label/inlined functionallity - /// - bool needFullRow() const { return status_ == Open; } + // these are needed here because of the label/inlined functionallity /// bool isOpen() const { return status_ == Open || status_ == Inlined; } /// diff --git a/src/insets/insetfloatlist.C b/src/insets/insetfloatlist.C index 926768bfbe..8d3c16fec3 100644 --- a/src/insets/insetfloatlist.C +++ b/src/insets/insetfloatlist.C @@ -12,6 +12,7 @@ #include "insetfloatlist.h" #include "FloatList.h" +#include "metricsinfo.h" #include "LaTeXFeatures.h" #include "lyxlex.h" #include "BufferView.h" @@ -97,6 +98,21 @@ void InsetFloatList::read(Buffer const * buf, LyXLex & lex) } +void InsetFloatList::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCommand::metrics(mi, dim); + center_indent_ = (mi.base.textwidth - dim.wid) / 2; + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + +void InsetFloatList::draw(PainterInfo & pi, int x, int y) const +{ + InsetCommand::draw(pi, x + center_indent_, y); +} + + dispatch_result InsetFloatList::localDispatch(FuncRequest const & cmd) { switch (cmd.action) { diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index 27b98a0b7d..04b6a17544 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -30,14 +30,16 @@ public: return std::auto_ptr(new InsetFloatList(getCmdName())); } /// + void metrics(MetricsInfo &, Dimension &) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// dispatch_result localDispatch(FuncRequest const & cmd); /// string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// - bool display() const { return true; } - /// InsetOld::Code lyxCode() const; /// void write(Buffer const *, std::ostream &) const; @@ -54,6 +56,9 @@ public: int ascii(Buffer const *, std::ostream &, int linelen) const; /// void validate(LaTeXFeatures & features) const; +private: + /// + mutable unsigned int center_indent_; }; #endif diff --git a/src/insets/insetfootlike.C b/src/insets/insetfootlike.C index 13889aa865..5829adc652 100644 --- a/src/insets/insetfootlike.C +++ b/src/insets/insetfootlike.C @@ -11,6 +11,7 @@ #include #include "insetfootlike.h" +#include "metricsinfo.h" #include "lyxfont.h" #include "buffer.h" #include "lyxtext.h" @@ -42,6 +43,15 @@ InsetFootlike::InsetFootlike(InsetFootlike const & in) } +void InsetFootlike::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCollapsable::metrics(mi, dim); + if (isOpen()) + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + void InsetFootlike::write(Buffer const * buf, ostream & os) const { os << getInsetName() << "\n"; diff --git a/src/insets/insetfootlike.h b/src/insets/insetfootlike.h index b135f91403..36f7bcf06a 100644 --- a/src/insets/insetfootlike.h +++ b/src/insets/insetfootlike.h @@ -24,6 +24,8 @@ public: /// InsetFootlike(InsetFootlike const &); /// + void metrics(MetricsInfo &, Dimension &) const; + /// void write(Buffer const * buf, std::ostream & os) const; /// bool insetAllowed(InsetOld::Code) const; diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 376ad5e44e..7ffd3d3504 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -242,12 +242,6 @@ void InsetInclude::read(Buffer const *, LyXLex & lex) } -bool InsetInclude::display() const -{ - return !(params_.flag == INPUT); -} - - string const InsetInclude::getScreenLabel(Buffer const *) const { string temp; @@ -530,6 +524,11 @@ void InsetInclude::metrics(MetricsInfo & mi, Dimension & dim) const } button_.metrics(mi, dim); } + if (params_.flag == INPUT) + center_indent_ = 0; + else + center_indent_ = (mi.base.textwidth - dim.wid) / 2; + dim.wid = mi.base.textwidth; dim_ = dim; } @@ -538,14 +537,14 @@ void InsetInclude::draw(PainterInfo & pi, int x, int y) const { cache(pi.base.bv); if (!preview_->previewReady()) { - button_.draw(pi, x, y); + button_.draw(pi, x + center_indent_, y); return; } if (!preview_->monitoring()) preview_->startMonitoring(); - pi.pain.image(x, y - dim_.asc, dim_.wid, dim_.height(), + pi.pain.image(x + center_indent_, y - dim_.asc, dim_.wid, dim_.height(), *(preview_->pimage()->image())); } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 0dddec7726..3f55c76d55 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -102,9 +102,6 @@ public: /// void validate(LaTeXFeatures &) const; - /// take up a whole row if we're not type INPUT - bool display() const; - /// return true if the file is or got loaded. bool loadIfNeeded() const; @@ -135,6 +132,7 @@ private: /// cache mutable bool set_label_; mutable ButtonRenderer button_; + mutable unsigned int center_indent_; }; diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index bf8a73f1c2..111a83800e 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -11,6 +11,7 @@ #include "insetindex.h" +#include "metricsinfo.h" #include "BufferView.h" #include "funcrequest.h" #include "frontends/LyXView.h" @@ -44,6 +45,21 @@ string const InsetIndex::getScreenLabel(Buffer const *) const } +void InsetPrintIndex::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCommand::metrics(mi, dim); + center_indent_ = (mi.base.textwidth - dim.wid) / 2; + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + +void InsetPrintIndex::draw(PainterInfo & pi, int x, int y) const +{ + InsetCommand::draw(pi, x + center_indent_, y); +} + + dispatch_result InsetIndex::localDispatch(FuncRequest const & cmd) { switch (cmd.action) { diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index bb77ef6e1d..cef3b995cc 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -59,13 +59,18 @@ public: /// EDITABLE editable() const { return NOT_EDITABLE; } /// - bool display() const { return true; } - /// InsetOld::Code lyxCode() const; /// string const getScreenLabel(Buffer const *) const; /// - virtual bool needFullRow() const { return true; } + //virtual bool needFullRow() const { return true; } + /// + void metrics(MetricsInfo &, Dimension &) const; + /// + void draw(PainterInfo & pi, int x, int y) const; +private: + /// + mutable unsigned int center_indent_; }; #endif diff --git a/src/insets/insetminipage.h b/src/insets/insetminipage.h index 1c1661cf5f..07a65cc1f1 100644 --- a/src/insets/insetminipage.h +++ b/src/insets/insetminipage.h @@ -78,8 +78,6 @@ public: string const editMessage() const; /// bool insetAllowed(InsetOld::Code) const; - /// - bool needFullRow() const { return false; } /** returns true if, when outputing LaTeX, font changes should be closed before generating this inset. This is needed for insets that may contain several paragraphs */ diff --git a/src/insets/insetnote.C b/src/insets/insetnote.C index d2f8f07dad..68b329d0dc 100644 --- a/src/insets/insetnote.C +++ b/src/insets/insetnote.C @@ -15,6 +15,7 @@ #include "Lsstream.h" #include "insetnote.h" +#include "metricsinfo.h" #include "gettext.h" #include "lyxfont.h" #include "language.h" @@ -110,6 +111,18 @@ void InsetNote::setButtonLabel() } +void InsetNote::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCollapsable::metrics(mi, dim); + // Contrary to Greyedout, these cannot be construed as part of the + // running text: make them stand on their own + if (params_.type == "Note" || params_.type == "Comment") + if (!collapsed_) + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + bool InsetNote::showInsetDialog(BufferView * bv) const { InsetNoteMailer("note", const_cast(*this)).showDialog(bv); @@ -172,11 +185,11 @@ int InsetNote::latex(Buffer const * buf, ostream & os, if (pt == "Comment") { os << "%\n\\end{comment}\n"; - i += 3; + i += 4; } else if (pt == "Greyedout") { os << "%\n\\end{lyxgreyedout}\n"; - i += 2; - } + i += 4; + } return i; } diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index cbf7878e7f..2c7c0473a4 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -53,6 +53,8 @@ public: void setButtonLabel(); /// dispatch_result InsetNote::localDispatch(FuncRequest const &); + /// + void metrics(MetricsInfo &, Dimension &) const; /// show the note dialog bool showInsetDialog(BufferView * bv) const; /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 61f03d2238..b88b744f87 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -247,7 +247,7 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const int InsetText::textWidth() const { - return textwidth_; + return textwidth_; } @@ -663,6 +663,7 @@ InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd) if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) { text_.setCursorFromCoordinates(cmd.x - drawTextXOffset, cmd.y + dim_.asc); + text_.cursor.x(text_.cursor.x()); text_.cursor.x_fix(text_.cursor.x()); } } diff --git a/src/insets/insettheorem.C b/src/insets/insettheorem.C index 4198fc6ecf..acf98c508d 100644 --- a/src/insets/insettheorem.C +++ b/src/insets/insettheorem.C @@ -12,6 +12,7 @@ #include "insettheorem.h" +#include "metricsinfo.h" #include "gettext.h" #include "lyxfont.h" #include "BufferView.h" @@ -64,6 +65,20 @@ InsetBase * InsetTheorem::clone() const return result; } +void InsetTheorem::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCollapsable::metrics(mi, dim); + center_indent_ = (mi.base.textwidth - dim.wid) / 2; + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + +void InsetTOC::draw(PainterInfo & pi, int x, int y) const +{ + InsetCollapsable::draw(pi, x + center_indent_, y); +} + string const InsetTheorem::editMessage() const { diff --git a/src/insets/insettheorem.h b/src/insets/insettheorem.h index 5d6cd53416..f4d2d3ed73 100644 --- a/src/insets/insettheorem.h +++ b/src/insets/insettheorem.h @@ -29,12 +29,17 @@ public: /// Inset::Code lyxCode() const { return Inset::THEOREM_CODE; } /// - bool display() const { return true; } + void metrics(MetricsInfo &, Dimension &) const; + /// + void draw(PainterInfo & pi, int x, int y) const; /// int latex(Buffer const *, std::ostream &, LatexRunParams const &) const; /// string const editMessage() const; +private: + /// + mutable unsigned int center_indent_; }; #endif diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index bc3b4f9a7b..8c8f732c58 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -54,6 +54,21 @@ InsetOld::Code InsetTOC::lyxCode() const } +void InsetTOC::metrics(MetricsInfo & mi, Dimension & dim) const +{ + InsetCommand::metrics(mi, dim); + center_indent_ = (mi.base.textwidth - dim.wid) / 2; + dim.wid = mi.base.textwidth; + dim_ = dim; +} + + +void InsetTOC::draw(PainterInfo & pi, int x, int y) const +{ + InsetCommand::draw(pi, x + center_indent_, y); +} + + dispatch_result InsetTOC::localDispatch(FuncRequest const & cmd) { switch (cmd.action) { diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 016b10b21d..465c6cf5a8 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -14,6 +14,7 @@ #include "insetcommand.h" +#include "metricsinfo.h" /** Used to insert table of contents */ @@ -28,14 +29,16 @@ public: return std::auto_ptr(new InsetTOC(params())); } /// + void metrics(MetricsInfo &, Dimension &) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// dispatch_result localDispatch(FuncRequest const & cmd); /// string const getScreenLabel(Buffer const *) const; /// EDITABLE editable() const { return IS_EDITABLE; } /// - bool display() const { return true; } - /// InsetOld::Code lyxCode() const; /// int ascii(Buffer const *, std::ostream &, int linelen) const; @@ -43,6 +46,9 @@ public: int linuxdoc(Buffer const *, std::ostream &) const; /// int docbook(Buffer const *, std::ostream &, bool mixcont) const; +private: + /// + mutable unsigned int center_indent_; }; #endif diff --git a/src/lyxrow_funcs.C b/src/lyxrow_funcs.C index c4716fba3c..9dacc2aa21 100644 --- a/src/lyxrow_funcs.C +++ b/src/lyxrow_funcs.C @@ -64,23 +64,6 @@ pos_type lastPos(Paragraph const & par, RowList::iterator rit) } -namespace { - -bool nextRowIsAllInset(Paragraph const & par, pos_type last) -{ - if (last + 1 >= par.size()) - return false; - - if (!par.isInset(last + 1)) - return false; - - InsetOld const * i = par.getInset(last + 1); - return i->needFullRow() || i->display(); -} - -} // anon namespace - - pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit) { pos_type const last = lastPos(par, rit); @@ -89,9 +72,6 @@ pos_type lastPrintablePos(Paragraph const & par, RowList::iterator rit) if (isParEnd(par, rit)) return last; - if (!nextRowIsAllInset(par, last) && par.isSeparator(last)) - return last - 1; - return last; } diff --git a/src/lyxtext.h b/src/lyxtext.h index f3d4305e1e..827f768aea 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -127,7 +127,7 @@ public: void setFont(LyXFont const &, bool toggleall = false); /// rebreaks all paragaphs between the given pars. - void redoParagraphs(ParagraphList::iterator begin, + int redoParagraphs(ParagraphList::iterator begin, ParagraphList::iterator end); /// rebreaks the given par void redoParagraph(ParagraphList::iterator pit); @@ -135,8 +135,8 @@ public: /// rebreaks the cursor par void redoParagraph(); private: - /// rebreaks the given par - void redoParagraphInternal(ParagraphList::iterator pit); + /// rebreaks the given par, return max row width + int redoParagraphInternal(ParagraphList::iterator pit); public: /// diff --git a/src/text.C b/src/text.C index 36ea605fe8..2eeb91d546 100644 --- a/src/text.C +++ b/src/text.C @@ -69,6 +69,8 @@ extern int const CHANGEBAR_MARGIN = 10; /// left margin extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN; + + int bibitemMaxWidth(BufferView *, LyXFont const &); @@ -443,15 +445,7 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par, int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const -{ - InsetOld * ins; - - if (row.pos() < pit->size()) - if (pit->getChar(row.pos()) == Paragraph::META_INSET && - (ins = pit->getInset(row.pos())) && - (ins->needFullRow() || ins->display())) - return LEFT_MARGIN; - +{ LyXTextClass const & tclass = bv()->buffer()->params.getLyXTextClass(); LyXLayout_ptr const & layout = pit->layout(); @@ -628,14 +622,6 @@ int LyXText::leftMargin(ParagraphList::iterator pit, Row const & row) const int LyXText::rightMargin(ParagraphList::iterator pit, Buffer const & buf, Row const & row) const { - InsetOld * ins; - - if (row.pos() < pit->size()) - if ((pit->getChar(row.pos()) == Paragraph::META_INSET) && - (ins = pit->getInset(row.pos())) && - (ins->needFullRow() || ins->display())) - return PAPER_MARGIN; - LyXTextClass const & tclass = buf.params.getLyXTextClass(); LyXLayout_ptr const & layout = pit->layout(); @@ -683,7 +669,8 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, Row const & row) const { // maximum pixel width of a row. - int width = workWidth() - rightMargin(pit, *bv()->buffer(), row); + int width = workWidth() + - rightMargin(pit, *bv()->buffer(), row); // inset->textWidth() returns -1 via workWidth(), // but why ? @@ -712,7 +699,6 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, // pixel width since last breakpoint int chunkwidth = 0; - bool fullrow = false; pos_type i = pos; @@ -751,14 +737,12 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, chunkwidth += thiswidth; InsetOld * in = pit->isInset(i) ? pit->getInset(i) : 0; - fullrow = in && (in->display() || in->needFullRow()); // break before a character that will fall off // the right of the row if (x >= width) { - // if no break before or we are at an inset - // that will take up a row, break here - if (point == last || fullrow || chunkwidth >= (width - left)) { + // if no break before, break here + if (point == last || chunkwidth >= (width - left)) { if (pos < i) point = i - 1; else @@ -776,24 +760,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, continue; } - if (!fullrow) - continue; - - // full row insets start at a new row - if (i == pos) { - if (pos < last - 1) { - point = i; - if (pit->isLineSeparator(i + 1)) - ++point; - } else { - // to avoid extra rows - point = last; - } - } else { - point = i - 1; - } - - return point; + continue; } if (point == last && x >= width) { @@ -808,7 +775,7 @@ pos_type LyXText::rowBreakPoint(ParagraphList::iterator pit, // manual labels cannot be broken in LaTeX. But we // want to make our on-screen rendering of footnotes // etc. still break - if (!fullrow && body_pos && point < body_pos) + if (body_pos && point < body_pos) point = body_pos - 1; return point; @@ -1502,15 +1469,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, } else { align = pit->params().align(); } - - // center displayed insets InsetOld * inset = 0; - if (rit->pos() < pit->size() - && pit->isInset(rit->pos()) - && (inset = pit->getInset(rit->pos())) - && (inset->display())) // || (inset->scroll() < 0))) - align = (inset->lyxCode() == InsetOld::MATHMACRO_CODE) - ? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER; // ERT insets should always be LEFT ALIGNED on screen inset = pit->inInset(); if (inset && inset->owner() && @@ -1521,18 +1480,15 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, switch (align) { case LYX_ALIGN_BLOCK: - { + { int const ns = numberOfSeparators(*pit, rit); - RowList::iterator next_row = boost::next(rit); + RowList::iterator next_row = boost::next(rit); if (ns && next_row != pit->rows.end() - && !pit->isNewline(next_row->pos() - 1) - && !(pit->isInset(next_row->pos()) - && pit->getInset(next_row->pos()) - && pit->getInset(next_row->pos())->display()) + && !pit->isNewline(next_row->pos() - 1) ) { - fill_separator = w / ns; - } else if (is_rtl) { + fill_separator = w / ns; + } else if (is_rtl) { x += w; } break; diff --git a/src/text2.C b/src/text2.C index 080eed5201..6b9387d368 100644 --- a/src/text2.C +++ b/src/text2.C @@ -544,7 +544,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall) } -void LyXText::redoParagraphInternal(ParagraphList::iterator pit) +int LyXText::redoParagraphInternal(ParagraphList::iterator pit) { RowList::iterator rit = pit->rows.begin(); RowList::iterator end = pit->rows.end(); @@ -571,26 +571,35 @@ void LyXText::redoParagraphInternal(ParagraphList::iterator pit) pit->rows.push_back(row); } - // set height and fill of rows + int par_width = 0; + // set height and fill and width of rows + int const ww = workWidth(); for (rit = pit->rows.begin(); rit != end; ++rit) { - rit->fill(fill(pit, rit, workWidth())); + int const f = fill(pit, rit, ww); + int const w = ww - f; + par_width = std::max(par_width, w); + rit->fill(f); + rit->width(w); prepareToPrint(pit, rit); setHeightOfRow(pit, rit); height += rit->height(); } //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n"; + return par_width; } -// rebreaks all paragraphs between the specified pars -// This function is needed after SetLayout and SetFont etc. -void LyXText::redoParagraphs(ParagraphList::iterator start, +int LyXText::redoParagraphs(ParagraphList::iterator start, ParagraphList::iterator end) { - for ( ; start != end; ++start) - redoParagraphInternal(start); + int pars_width = 0; + for ( ; start != end; ++start) { + int par_width = redoParagraphInternal(start); + pars_width = std::max(par_width, pars_width); + } updateRowPositions(); + return pars_width; } @@ -620,7 +629,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) ///height = 0; //anchor_y_ = 0; - redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); + width = redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); // final dimension dim.asc = firstRow()->ascent_of_text(); @@ -1356,16 +1365,6 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit, // same paragraph and there is a previous row then put the cursor on // the end of the previous row cur.iy(y + row->baseline()); - if (row != pit->rows.begin() - && pos - && pos < pit->size() - && pit->getChar(pos) == Paragraph::META_INSET) { - InsetOld * ins = pit->getInset(pos); - if (ins && (ins->needFullRow() || ins->display())) { - --row; - y -= row->height(); - } - } // y is now the beginning of the cursor row y += row->baseline(); @@ -1632,33 +1631,6 @@ void LyXText::setCursorFromCoordinates(int x, int y) } -namespace { - - /** - * return true if the cursor given is at the end of a row, - * and the next row is filled by an inset that spans an entire - * row. - */ - bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur) - { - RowList::iterator row = lt.getRow(cur); - RowList::iterator next = boost::next(row); - - if (next == cur.par()->rows.end() || next->pos() != cur.pos()) - return false; - - if (cur.pos() == cur.par()->size() || !cur.par()->isInset(cur.pos())) - return false; - - InsetOld const * inset = cur.par()->getInset(cur.pos()); - if (inset->needFullRow() || inset->display()) - return true; - - return false; - } -} - - void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) { // Get the row first. @@ -1673,17 +1645,9 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) cur.x(x); cur.y(y + rit->baseline()); - if (beforeFullRowInset(*this, cur)) { - pos_type const last = lastPrintablePos(*pit, rit); - RowList::iterator next_rit = rit; - ParagraphList::iterator next_pit = pit; - nextRow(next_pit, next_rit); - cur.ix(int(getCursorX(pit, next_rit, cur.pos(), last, bound))); - cur.iy(y + rit->height() + next_rit->baseline()); - } else { - cur.iy(cur.y()); - cur.ix(cur.x()); - } + cur.iy(cur.y()); + cur.ix(cur.x()); + cur.boundary(bound); } -- 2.39.2