anchor_ref_ = int(bar * t.paragraphs().size());
if (anchor_ref_ > int(t.paragraphs().size()) - 1)
anchor_ref_ = int(t.paragraphs().size()) - 1;
- t.redoParagraph(anchor_ref_);
+ t.redoParagraph(*this, anchor_ref_);
int const h = t.getPar(anchor_ref_).height();
offset_ref_ = int((bar * t.paragraphs().size() - anchor_ref_) * h);
}
{
CursorSlice & bot = cursor_.bottom();
pit_type const pit = bot.pit();
- bot.text()->redoParagraph(pit);
+ bot.text()->redoParagraph(*this, pit);
Paragraph const & par = bot.text()->paragraphs()[pit];
anchor_ref_ = pit;
offset_ref_ = bv_funcs::coordOffset(*this, cursor_, cursor_.boundary()).y_
// (if this paragraph contains insets etc., rebreaking will
// recursively descend)
if (!singlepar || pit == cursor_.bottom().pit())
- buftext.redoParagraph(pit);
+ buftext.redoParagraph(*this, pit);
int y0 = buftext.getPar(pit).ascent() - offset_ref_;
// Redo paragraphs above anchor if necessary; again, in Single Par
y1 -= buftext.getPar(pit1).ascent();
--pit1;
if (!singlepar || pit1 == cursor_.bottom().pit())
- buftext.redoParagraph(pit1);
+ buftext.redoParagraph(*this, pit1);
y1 -= buftext.getPar(pit1).descent();
}
y2 += buftext.getPar(pit2).descent();
++pit2;
if (!singlepar || pit2 == cursor_.bottom().pit())
- buftext.redoParagraph(pit2);
+ buftext.redoParagraph(*this, pit2);
y2 += buftext.getPar(pit2).ascent();
}
#include "FontIterator.h"
+#include "buffer.h"
#include "lyxtext.h"
#include "paragraph.h"
namespace lyx {
-FontIterator::FontIterator(LyXText const & text, Paragraph const & par,
- pos_type pos)
- : text_(text), par_(par), pos_(pos),
- font_(text.getFont(par, pos)),
+FontIterator::FontIterator(Buffer const & buffer, LyXText const & text,
+ Paragraph const & par, pos_type pos)
+ : buffer_(buffer), text_(text), par_(par), pos_(pos),
+ font_(text.getFont(buffer, par, pos)),
endspan_(par.fontSpan(pos).last),
bodypos_(par.beginOfBody())
{}
{
++pos_;
if (pos_ > endspan_ || pos_ == bodypos_) {
- font_ = text_.getFont(par_, pos_);
+ font_ = text_.getFont(buffer_, par_, pos_);
endspan_ = par_.fontSpan(pos_).last;
}
return *this;
namespace lyx {
+class Buffer;
class LyXText;
class Paragraph;
{
public:
///
- FontIterator(LyXText const & text, Paragraph const & par, pos_type pos);
+ FontIterator(Buffer const & buffer, LyXText const & text,
+ Paragraph const & par, pos_type pos);
///
LyXFont const & operator*() const;
///
LyXFont * operator->();
private:
+ ///
+ Buffer const & buffer_;
///
LyXText const & text_;
///
if (it == par_iterator_end(buf.inset()))
return false;
-// if (it.lastpit == 0 && LyXText::isMainText())
+// if (it.lastpit == 0 && LyXText::isMainText(buf))
// return false;
switch (it->layout()->labeltype) {
for (size_t rit = 0; rit != rend; ++rit)
y += par.rows()[rit].height();
y += par.rows()[rend].ascent();
- x += dit.bottom().text()->cursorX(dit.bottom(), boundary && dit.depth() == 1);
+ x += dit.bottom().text()->cursorX(*bv.buffer(), dit.bottom(), boundary && dit.depth() == 1);
// FIXME: The following correction should not be there at all.
// The cursor looks much better with the +1, though.
++x;
}
-Point CoordCache::get(LyXText const * text, pit_type pit)
+Point CoordCache::get(LyXText const * text, pit_type pit) const
{
- ParPosCache::iterator const it = pars_.find(text);
+ ParPosCache::const_iterator const it = pars_.find(text);
BOOST_ASSERT(it != pars_.end());
- InnerParPosCache::iterator const posit = it->second.find(pit);
+ InnerParPosCache::const_iterator const posit = it->second.find(pit);
BOOST_ASSERT(posit != it->second.end());
return posit->second;
}
* updates. (x,y) == (0,0) is the upper left screen corner, x increases
* to the right, y increases downwords.
* The cache is built in BufferView::updateMetrics which is called
- * from BufferView::Pimpl::update. The individual points are added
+ * from BufferView::update. The individual points are added
* while we paint them. See for instance paintPar in RowPainter.C.
*/
class CoordCache {
public:
void clear();
- Point get(LyXText const *, pit_type);
+ Point get(LyXText const *, pit_type) const;
/// A map from paragraph index number to screen point
typedef std::map<pit_type, Point> InnerParPosCache;
{
// For now this is good enough. A better solution would be to
// avoid this rebreak by setting cursorX only after drawing
- bottom().text()->redoParagraph(bottom().pit());
+ bottom().text()->redoParagraph(bv(), bottom().pit());
int x;
int y;
getPos(x, y);
}
-int InsetBase::xo(BufferView & bv) const
+int InsetBase::xo(BufferView const & bv) const
{
return bv.coordCache().getInsets().x(this);
}
-int InsetBase::yo(BufferView & bv) const
+int InsetBase::yo(BufferView const & bv) const
{
return bv.coordCache().getInsets().y(this);
}
-bool InsetBase::covers(BufferView & bv, int x, int y) const
+bool InsetBase::covers(BufferView const & bv, int x, int y) const
{
//lyxerr << "InsetBase::covers, x: " << x << " y: " << y
// << " xo: " << xo(bv) << " yo: " << yo()
/// add space for markers
void metricsMarkers2(Dimension & dim, int framesize = 1) const;
/// last drawn position for 'important' insets
- int xo(BufferView & bv) const;
+ int xo(BufferView const & bv) const;
/// last drawn position for 'important' insets
- int yo(BufferView & bv) const;
+ int yo(BufferView const & bv) const;
/// set x/y drawing position cache if available
virtual void setPosCache(PainterInfo const &, int, int) const {}
/// do we cover screen position x/y?
- virtual bool covers(BufferView & bv, int x, int y) const;
+ virtual bool covers(BufferView const & bv, int x, int y) const;
/// get the screen positions of the cursor (see note in cursor.C)
virtual void cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const;
/// should we break lines after this inset?
virtual bool isLineSeparator() const { return false; }
/// should paragraph indendation be ommitted in any case?
- virtual bool neverIndent() const { return false; }
+ virtual bool neverIndent(Buffer const &) const { return false; }
/// dumps content to lyxerr
virtual void dump() const;
/// write inset in .lyx format
///
bool forceDefaultParagraphs(idx_type) const;
///
- bool neverIndent() const { return true; }
+ bool neverIndent(Buffer const &) const { return true; }
///
bool noFontChange() const { return true; }
///
///
virtual bool display() const;
///
- virtual bool neverIndent() const { return true; }
+ virtual bool neverIndent(Buffer const &) const { return true; }
///
virtual InsetBase::Code lyxCode() const;
///
InsetCharStyleParams const & params() const { return params_; }
/// should paragraph indendation be ommitted in any case?
- bool neverIndent() const { return true; }
+ bool neverIndent(Buffer const &) const { return true; }
protected:
InsetCharStyle(InsetCharStyle const &);
///
bool forceDefaultParagraphs(idx_type) const { return true; }
/// should paragraph indendation be ommitted in any case?
- bool neverIndent() const { return true; }
+ bool neverIndent(Buffer const &) const { return true; }
protected:
InsetERT(InsetERT const &);
///
void write(Buffer const & buf, std::ostream & os) const;
/// should paragraph indendation be ommitted in any case?
- virtual bool neverIndent() const { return true; }
+ virtual bool neverIndent(Buffer const &) const { return true; }
protected:
InsetOptArg(InsetOptArg const &);
private:
cur.idx() = tabular.getCellBelow(cur.idx());
cur.pit() = 0;
cur.pos() = cell(cur.idx())->getText(0)->x2pos(
- cur.pit(), 0, cur.targetX());
+ cur.bv(), cur.pit(), 0, cur.targetX());
}
if (sl == cur.top()) {
// we trick it to go to the RIGHT after leaving the
cur.pit() = cur.lastpit();
LyXText const * text = cell(cur.idx())->getText(0);
cur.pos() = text->x2pos(
+ cur.bv(),
cur.pit(),
text->paragraphs().back().rows().size()-1,
cur.targetX());
if (buf.length() <= 0)
return true;
+ Buffer const & buffer = *bv.buffer();
+
col_type cols = 1;
row_type rows = 1;
col_type maxCols = 1;
row_type row = 0;
if (usePaste) {
paste_tabular.reset(
- new LyXTabular(bv.buffer()->params(), rows, maxCols));
+ new LyXTabular(buffer.params(), rows, maxCols));
loctab = paste_tabular.get();
cols = 0;
dirtyTabularStack(true);
// we can only set this if we are not too far right
if (cols < columns) {
shared_ptr<InsetText> inset = loctab->getCellInset(cell);
- inset->setViewCache(&bv);
Paragraph & par = inset->text_.getPar(0);
- LyXFont const font = inset->text_.getFont(par, 0);
+ LyXFont const font = inset->text_.getFont(buffer, par, 0);
inset->setText(buf.substr(op, p - op), font,
- bv.buffer()->params().trackChanges);
+ buffer.params().trackChanges);
++cols;
++cell;
}
// we can only set this if we are not too far right
if (cols < columns) {
shared_ptr<InsetText> inset = tabular.getCellInset(cell);
- inset->setViewCache(&bv);
Paragraph & par = inset->text_.getPar(0);
- LyXFont const font = inset->text_.getFont(par, 0);
+ LyXFont const font = inset->text_.getFont(buffer, par, 0);
inset->setText(buf.substr(op, p - op), font,
- bv.buffer()->params().trackChanges);
+ buffer.params().trackChanges);
}
cols = ocol;
++row;
// check for the last cell if there is no trailing '\n'
if (cell < cells && op < len) {
shared_ptr<InsetText> inset = loctab->getCellInset(cell);
- inset->setViewCache(&bv);
Paragraph & par = inset->text_.getPar(0);
- LyXFont const font = inset->text_.getFont(par, 0);
+ LyXFont const font = inset->text_.getFont(buffer, par, 0);
inset->setText(buf.substr(op, len - op), font,
- bv.buffer()->params().trackChanges);
+ buffer.params().trackChanges);
}
return true;
}
InsetText::InsetText(InsetText const & in)
- : InsetOld(in), text_(in.text_.bv_owner)
+ : InsetOld(in), text_()
{
text_.autoBreakRows_ = in.text_.autoBreakRows_;
drawFrame_ = in.drawFrame_;
void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
{
//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
- setViewCache(mi.base.bv);
mi.base.textwidth -= 2 * border_;
font_ = mi.base.font;
// Hand font through to contained lyxtext:
}
-bool InsetText::covers(BufferView & bv, int x, int y) const
+bool InsetText::covers(BufferView const & bv, int x, int y) const
{
return bv.coordCache().getInsets().has(this)
&& x >= xo(bv)
void InsetText::edit(LCursor & cur, bool left)
{
//lyxerr << "InsetText: edit left/right" << endl;
- setViewCache(&cur.bv());
int const pit = left ? 0 : paragraphs().size() - 1;
int const pos = left ? 0 : paragraphs().back().size();
text_.setCursor(cur.top(), pit, pos);
lyxerr[Debug::ACTION] << BOOST_CURRENT_FUNCTION
<< " [ cmd.action = "
<< cmd.action << ']' << endl;
- setViewCache(&cur.bv());
text_.dispatch(cur, cmd);
}
}
-void InsetText::cursorPos(BufferView const & /*bv*/,
+void InsetText::cursorPos(BufferView const & bv,
CursorSlice const & sl, bool boundary, int & x, int & y) const
{
- x = text_.cursorX(sl, boundary) + border_;
+ x = text_.cursorX(*bv.buffer(), sl, boundary) + border_;
y = text_.cursorY(sl, boundary);
}
}
-void InsetText::setViewCache(BufferView const * bv) const
-{
- if (bv && bv != text_.bv_owner) {
- //lyxerr << "setting view cache from "
- // << text_.bv_owner << " to " << bv << "\n";
- text_.bv_owner = const_cast<BufferView *>(bv);
- }
-}
-
-
void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
{
// There is little we can do here to keep track of changes.
//FIXME: instead of this hack, which only works by chance,
// cells should have their own insetcell type, which returns CELL_CODE!
-bool InsetText::neverIndent() const
+bool InsetText::neverIndent(Buffer const & buffer) const
{
// this is only true for tabular cells
- return !text_.isMainText() && lyxCode() == TEXT_CODE;
+ return !text_.isMainText(buffer) && lyxCode() == TEXT_CODE;
}
/// draw inset selection
void drawSelection(PainterInfo & pi, int x, int y) const;
/// are we inside the area covered by the inset?
- virtual bool covers(BufferView & bv, int x, int y) const;
+ virtual bool covers(BufferView const & bv, int x, int y) const;
///
virtual docstring const editMessage() const;
///
///
void setFrameColor(LColor_color);
///
- void setViewCache(BufferView const * bv) const;
- ///
bool showInsetDialog(BufferView *) const;
///
LyXText * getText(int i) const {
///
bool allowSpellCheck() const { return true; }
/// should paragraph indendation be ommitted in any case?
- bool neverIndent() const;
+ bool neverIndent(Buffer const &) const;
///
InsetText(InsetText const &);
///
if (keyseq->length())
c = 0;
- lyx_view_->view()->getIntl().getTransManager()
- .deadkey(c, get_accent(action).accent, view()->getLyXText());
+ lyx_view_->view()->getIntl().getTransManager().deadkey(
+ c, get_accent(action).accent, view()->getLyXText(), view()->cursor());
// Need to clear, in case the minibuffer calls these
// actions
keyseq->clear();
class LyXText {
public:
/// constructor
- explicit LyXText(BufferView *);
+ explicit LyXText(BufferView * bv = 0);
///
void init(BufferView *);
///
- LyXFont getFont(Paragraph const & par, pos_type pos) const;
+ LyXFont getFont(Buffer const & buffer, Paragraph const & par,
+ pos_type pos) const;
///
- void applyOuterFont(LyXFont &) const;
+ void applyOuterFont(Buffer const & buffer, LyXFont &) const;
///
- LyXFont getLayoutFont(pit_type pit) const;
+ LyXFont getLayoutFont(Buffer const & buffer, pit_type pit) const;
///
- LyXFont getLabelFont(Paragraph const & par) const;
+ LyXFont getLabelFont(Buffer const & buffer,
+ Paragraph const & par) const;
///
- void setCharFont(pit_type pit, pos_type pos, LyXFont const & font);
+ void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
+ LyXFont const & font);
///
- void setCharFont(pit_type pit, pos_type pos, LyXFont const & font,
- bool toggleall);
+ void setCharFont(Buffer const & buffer, pit_type pit, pos_type pos,
+ LyXFont const & font, bool toggleall);
/// what you expect when pressing <enter> at cursor position
void breakParagraph(LCursor & cur, bool keep_layout = false);
/// set layout over selection
- void setLayout(pit_type start, pit_type end,
+ void setLayout(Buffer const & buffer, pit_type start, pit_type end,
std::string const & layout);
///
void setLayout(LCursor & cur, std::string const & layout);
void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
/// rebreaks the given par
- bool redoParagraph(pit_type pit);
+ bool redoParagraph(BufferView &, pit_type pit);
/// returns pos in given par at given x coord
- pos_type x2pos(pit_type pit, int row, int x) const;
+ pos_type x2pos(BufferView const &, pit_type pit, int row, int x) const;
int pos2x(pit_type pit, pos_type pos) const;
///
bool getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & status) const;
- /// access to out BufferView. This should go...
- BufferView * bv() const;
-
/// read-only access to individual paragraph
Paragraph const & getPar(pit_type pit) const { return pars_[pit]; }
/// read-write access to individual paragraph
/** returns row near the specified
* y-coordinate in given paragraph (relative to the screen).
*/
- Row const & getRowNearY(int y, pit_type pit) const;
- pit_type getPitNearY(int y) const;
+ Row const & getRowNearY(BufferView const & bv, int y,
+ pit_type pit) const;
+ pit_type getPitNearY(BufferView const & bv, int y) const;
/** returns the column near the specified x-coordinate of the row
x is set to the real beginning of this column
*/
- pos_type getColumnNearX(pit_type pit,
+ pos_type getColumnNearX(BufferView const & bv, pit_type pit,
Row const & row, int & x, bool & boundary) const;
/** Find the word under \c from in the relative location
void setCurrentFont(LCursor & cur);
///
- void recUndo(pit_type first, pit_type last) const;
+ void recUndo(LCursor & cur, pit_type first, pit_type last) const;
///
- void recUndo(pit_type first) const;
+ void recUndo(LCursor & cur, pit_type first) const;
/// returns true if par was empty and was removed
bool setCursorFromCoordinates(LCursor & cur, int x, int y);
///
int height() const;
/// Returns an inset if inset was hit, or 0 if not.
- InsetBase * checkInsetHit(int x, int y) const;
+ InsetBase * checkInsetHit(BufferView const &, int x, int y) const;
///
- int singleWidth(Paragraph const & par, pos_type pos) const;
+ int singleWidth(Buffer const &, Paragraph const & par,
+ pos_type pos) const;
///
- int singleWidth(Paragraph const & par,
+ int singleWidth(Buffer const &, Paragraph const & par,
pos_type pos, char_type c, LyXFont const & Font) const;
/// return the color of the canvas
* in LaTeX the beginning of the text fits in some cases
* (for example sections) exactly the label-width.
*/
- int leftMargin(pit_type pit, pos_type pos) const;
- int leftMargin(pit_type pit) const;
+ int leftMargin(Buffer const &, pit_type pit, pos_type pos) const;
+ int leftMargin(Buffer const &, pit_type pit) const;
///
- int rightMargin(Paragraph const & par) const;
+ int rightMargin(Buffer const &, Paragraph const & par) const;
/** this calculates the specified parameters. needed when setting
* the cursor and when creating a visible row */
- RowMetrics computeRowMetrics(pit_type pit, Row const & row) const;
+ RowMetrics computeRowMetrics(Buffer const &, pit_type pit,
+ Row const & row) const;
/// access to our paragraphs
ParagraphList const & paragraphs() const { return pars_; }
ParagraphList & paragraphs() { return pars_; }
/// return true if this is the main text
- bool isMainText() const;
+ bool isMainText(Buffer const &) const;
/// return first row of text
Row const & firstRow() const;
bool isFirstRow(pit_type pit, Row const & row) const;
///
- double spacing(Paragraph const & par) const;
+ double spacing(Buffer const & buffer, Paragraph const & par) const;
/// make a suggestion for a label
std::string getPossibleLabel(LCursor & cur) const;
/// is this paragraph right-to-left?
- bool isRTL(Paragraph const & par) const;
+ bool isRTL(Buffer const &, Paragraph const & par) const;
///
bool checkAndActivateInset(LCursor & cur, bool front);
///
int descent() const;
///
- int cursorX(CursorSlice const & cursor, bool boundary) const;
+ int cursorX(Buffer const &, CursorSlice const & cursor,
+ bool boundary) const;
///
int cursorY(CursorSlice const & cursor, bool boundary) const;
///
int background_color_;
- /// only the top-level LyXText has this non-zero
- BufferView * bv_owner;
-
///
mutable Bidi bidi;
///
pit_type undoSpan(pit_type pit);
/// Calculate and set the height of the row
- void setHeightOfRow(pit_type, Row & row);
+ void setHeightOfRow(BufferView const &, pit_type, Row & row);
// fix the cursor `cur' after a characters has been deleted at `where'
// position. Called by deleteEmptyParagraphMechanism
/// sets row.end to the pos value *after* which a row should break.
/// for example, the pos after which isNewLine(pos) == true
- void rowBreakPoint(pit_type pit, Row & row) const;
+ void rowBreakPoint(Buffer const &, pit_type pit, Row & row) const;
/// sets row.width to the minimum space a row needs on the screen in pixel
- void setRowWidth(pit_type pit, Row & row) const;
+ void setRowWidth(Buffer const &, pit_type pit, Row & row) const;
/// the minimum space a manual label needs on the screen in pixels
- int labelFill(Paragraph const & par, Row const & row) const;
+ int labelFill(Buffer const &, Paragraph const & par, Row const & row) const;
/// FIXME
- int labelEnd(pit_type pit) const;
+ int labelEnd(Buffer const &, pit_type pit) const;
///
void charInserted();
}
-int MathArray::dist(BufferView & bv, int x, int y) const
+int MathArray::dist(BufferView const & bv, int x, int y) const
{
int xx = 0;
int yy = 0;
}
-int MathArray::xo(BufferView & bv) const
+int MathArray::xo(BufferView const & bv) const
{
return bv.coordCache().getArrays().x(this);
}
-int MathArray::yo(BufferView & bv) const
+int MathArray::yo(BufferView const & bv) const
{
return bv.coordCache().getArrays().y(this);
}
void touch() const;
/// access to cached x coordinate of last drawing
- int xo(BufferView & bv) const;
+ int xo(BufferView const & bv) const;
/// access to cached y coordinate of last drawing
- int yo(BufferView & bv) const;
+ int yo(BufferView const & bv) const;
/// access to cached x coordinate of mid point of last drawing
- int xm(BufferView & bv) const { return xo(bv) + dim_.wid / 2; }
+ int xm(BufferView const & bv) const { return xo(bv) + dim_.wid / 2; }
/// access to cached y coordinate of mid point of last drawing
- int ym(BufferView & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; }
+ int ym(BufferView const & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; }
/// write access to coordinate;
void setXY(BufferView & bv, int x, int y) const;
/// returns x coordinate of given position in the array
size_type x2pos(int targetx, int glue) const;
/// returns distance of this cell to the point given by x and y
// assumes valid position and size cache
- int dist(BufferView & bv, int x, int y) const;
+ int dist(BufferView const & bv, int x, int y) const;
/// ascent of this cell above the baseline
int ascent() const { return dim_.asc; }
erased_(pi.erased_),
xo_(x), yo_(y), width_(text_.width())
{
- RowMetrics m = text_.computeRowMetrics(pit, row_);
+ RowMetrics m = text_.computeRowMetrics(*bv_.buffer(), pit, row_);
x_ = m.x + xo_;
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo_ << " yo: " << yo_ << endl;
LyXFont const RowPainter::getLabelFont() const
{
- return text_.getLabelFont(par_);
+ return text_.getLabelFont(*bv_.buffer(), par_);
}
int RowPainter::leftMargin() const
{
- return text_.leftMargin(pit_, row_.pos());
+ return text_.leftMargin(*bv_.buffer(), pit_, row_.pos());
}
if (!Encodings::isComposeChar_hebrew(c)) {
if (isPrintableNonspace(c)) {
int const width2 =
- text_.singleWidth(par_, i, c, text_.getFont(par_, i));
+ text_.singleWidth(*bv_.buffer(), par_, i, c,
+ text_.getFont(*bv_.buffer(), par_, i));
// FIXME UNICODE
// This does not work anymore, and non-ascii
// characters in source files are forbidden
if (!Encodings::isComposeChar_arabic(c)) {
if (isPrintableNonspace(c)) {
int const width2 =
- text_.singleWidth(par_, i, c, text_.getFont(par_, i));
+ text_.singleWidth(*bv_.buffer(), par_, i, c,
+ text_.getFont(*bv_.buffer(), par_, i));
dx = (width2 - width) / 2;
}
break;
void RowPainter::paintFromPos(pos_type & vpos)
{
pos_type const pos = text_.bidi.vis2log(vpos);
- LyXFont orig_font = text_.getFont(par_, pos);
+ LyXFont orig_font = text_.getFont(*bv_.buffer(), par_, pos);
double const orig_x = x_;
int const w = nestMargin() / 5;
int x = int(xo_) + w * i;
// only consider the changebar space if we're drawing outermost text
- if (text_.isMainText())
+ if (text_.isMainText(*bv_.buffer()))
x += changebarMargin();
int const starty = yo_ - row_.ascent();
}
}
- bool const is_rtl = text_.isRTL(par_);
+ bool const is_rtl = text_.isRTL(buffer, par_);
bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
//lyxerr << "paintFirst: " << par_.id() << " is_seq: " << is_seq << std::endl;
if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
if (is_rtl)
x = leftMargin();
- x += (width_ - text_.rightMargin(par_) - leftMargin()) / 2;
+ x += (width_ - text_.rightMargin(buffer, par_) - leftMargin()) / 2;
x -= fm.width(str) / 2;
} else if (is_rtl) {
x = width_ - leftMargin() - fm.width(str);
void RowPainter::paintLast()
{
- bool const is_rtl = text_.isRTL(par_);
+ bool const is_rtl = text_.isRTL(*bv_.buffer(), par_);
int const endlabel = getEndLabel(pit_, text_.paragraphs());
// draw an endlabel
docstring const & str = par_.layout()->endlabelstring();
double const x = is_rtl ?
x_ - fm.width(str)
- : - text_.rightMargin(par_) - row_.width();
+ : - text_.rightMargin(*bv_.buffer(), par_) - row_.width();
pain_.text(int(x), yo_, str, font);
break;
}
// Use font span to speed things up, see below
FontSpan font_span;
LyXFont font;
+ Buffer const & buffer = *bv_.buffer();
for (pos_type vpos = row_.pos(); vpos < end; ) {
if (x_ > bv_.workWidth())
// Use font span to speed things up, see above
if (vpos < font_span.first || vpos > font_span.last) {
font_span = par_.fontSpan(vpos);
- font = text_.getFont(par_, vpos);
+ font = text_.getFont(buffer, par_, vpos);
}
- const int width_pos =
- text_.singleWidth(par_, pos, par_.getChar(pos), font);
+ const int width_pos = text_.singleWidth(buffer, par_, pos,
+ par_.getChar(pos), font);
if (x_ + width_pos < 0) {
x_ += width_pos;
// Instrumentation for testing row cache (see also
// 12 lines lower):
- if (text.isMainText())
+ if (text.isMainText(*pi.base.bv->buffer()))
lyxerr[Debug::PAINTING] << "#";
else
lyxerr[Debug::PAINTING] << "[" <<
Painter & pain)
{
BOOST_ASSERT(bv.buffer());
- LyXText & text = bv.buffer()->text();
+ Buffer const & buffer = *bv.buffer();
+ LyXText & text = buffer.text();
bool const select = bv.cursor().selection();
ViewMetricsInfo const & vi = bv.viewMetricsInfo();
// Try viewing the User Guide Mobius figure
if (vi.p1 > 0) {
- text.redoParagraph(vi.p1 - 1);
+ text.redoParagraph(bv, vi.p1 - 1);
bv.coordCache().parPos()[&text][vi.p1 - 1] =
Point(0, vi.y1 - text.getPar(vi.p1 - 1).descent());
}
if (vi.p2 < pit_type(text.paragraphs().size()) - 1) {
- text.redoParagraph(vi.p2 + 1);
+ text.redoParagraph(bv, vi.p2 + 1);
bv.coordCache().parPos()[&text][vi.p2 + 1] =
Point(0, vi.y2 + text.getPar(vi.p2 + 1).ascent());
}
return;
// merge all paragraphs to one
- BufferParams const & bp =
- inset->getText(0)->bv_owner->buffer()->params();
+ BufferParams const & bp = cur.bv().buffer()->params();
while (inset->paragraphs().size() > 1)
mergeParagraph(bp, inset->paragraphs(), 0);
// reset layout
cur.push(*inset);
// undo information has already been recorded
- inset->getText(0)->setLayout(0, cur.lastpit() + 1,
+ inset->getText(0)->setLayout(*cur.bv().buffer(), 0, cur.lastpit() + 1,
bp.getLyXTextClass().defaultLayoutName());
cur.pop();
}
-BufferView * LyXText::bv() const
-{
- BOOST_ASSERT(bv_owner != 0);
- return bv_owner;
-}
-
-
-double LyXText::spacing(Paragraph const & par) const
+double LyXText::spacing(Buffer const & buffer,
+ Paragraph const & par) const
{
if (par.params().spacing().isDefault())
- return bv()->buffer()->params().spacing().getValue();
+ return buffer.params().spacing().getValue();
return par.params().spacing().getValue();
}
}
-int LyXText::singleWidth(Paragraph const & par, pos_type pos) const
+int LyXText::singleWidth(Buffer const & buffer, Paragraph const & par,
+ pos_type pos) const
{
- return singleWidth(par, pos, par.getChar(pos), getFont(par, pos));
+ return singleWidth(buffer, par, pos, par.getChar(pos),
+ getFont(buffer, par, pos));
}
-int LyXText::singleWidth(Paragraph const & par,
+int LyXText::singleWidth(Buffer const & buffer, Paragraph const & par,
pos_type pos, char_type c, LyXFont const & font) const
{
// The most common case is handled first (Asger)
}
-int LyXText::leftMargin(pit_type pit) const
+int LyXText::leftMargin(Buffer const & buffer, pit_type pit) const
{
BOOST_ASSERT(pit >= 0);
BOOST_ASSERT(pit < int(pars_.size()));
- return leftMargin(pit, pars_[pit].size());
+ return leftMargin(buffer, pit, pars_[pit].size());
}
-int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
+int LyXText::leftMargin(Buffer const & buffer,
+ pit_type const pit, pos_type const pos) const
{
BOOST_ASSERT(pit >= 0);
BOOST_ASSERT(pit < int(pars_.size()));
BOOST_ASSERT(pos >= 0);
BOOST_ASSERT(pos <= par.size());
//lyxerr << "LyXText::leftMargin: pit: " << pit << " pos: " << pos << endl;
- BufferParams const & params = bv()->buffer()->params();
- LyXTextClass const & tclass = params.getLyXTextClass();
+ LyXTextClass const & tclass = buffer.params().getLyXTextClass();
LyXLayout_ptr const & layout = par.layout();
string parindent = layout->parindent;
int l_margin = 0;
- if (isMainText())
+ if (isMainText(buffer))
l_margin += changebarMargin();
// FIXME UNICODE
docstring leftm = from_utf8(tclass.leftmargin());
- l_margin += theFontMetrics(params.getFont()).signedWidth(leftm);
+ l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm);
if (par.getDepth() != 0) {
// find the next level paragraph
pit_type newpar = outerHook(pit, pars_);
if (newpar != pit_type(pars_.size())) {
if (pars_[newpar].layout()->isEnvironment()) {
- l_margin = leftMargin(newpar);
+ l_margin = leftMargin(buffer, newpar);
}
if (par.layout() == tclass.defaultLayout()) {
if (pars_[newpar].params().noindent())
&& pit > 0 && pars_[pit - 1].layout()->nextnoindent)
parindent.erase();
- LyXFont const labelfont = getLabelFont(par);
+ LyXFont const labelfont = getLabelFont(buffer, par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
switch (layout->margintype) {
if (!layout->leftmargin.empty()) {
// FIXME UNICODE
docstring leftm = from_utf8(layout->leftmargin);
- l_margin += theFontMetrics(params.getFont()).signedWidth(leftm);
+ l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm);
}
if (!par.getLabelstring().empty()) {
// FIXME UNICODE
case MARGIN_STATIC: {
// FIXME UNICODE
docstring leftm = from_utf8(layout->leftmargin);
- l_margin += theFontMetrics(params.getFont()).signedWidth(leftm)
+ l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm)
* 4 / (par.getDepth() + 4);
break;
}
&& align == LYX_ALIGN_BLOCK
&& !par.params().noindent()
// in some insets, paragraphs are never indented
- && !(par.inInset() && par.inInset()->neverIndent())
+ && !(par.inInset() && par.inInset()->neverIndent(buffer))
// display style insets are always centered, omit indentation
&& !(!par.empty()
&& par.isInset(pos)
&& par.getInset(pos)->display())
&& (par.layout() != tclass.defaultLayout()
- || bv()->buffer()->params().paragraph_separation ==
+ || buffer.params().paragraph_separation ==
BufferParams::PARSEP_INDENT))
{
docstring din = from_utf8(parindent);
- l_margin += theFontMetrics(params.getFont()).signedWidth(din);
+ l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(din);
}
return l_margin;
}
-int LyXText::rightMargin(Paragraph const & par) const
+int LyXText::rightMargin(Buffer const & buffer, Paragraph const & par) const
{
// FIXME: the correct way is to only call rightMargin() only
// within the main LyXText. The following test is thus bogus.
- LyXText const & text = bv()->buffer()->text();
+ LyXText const & text = buffer.text();
// We do not want rightmargins on inner texts.
if (&text != this)
return 0;
- BufferParams const & params = bv()->buffer()->params();
+ BufferParams const & params = buffer.params();
LyXTextClass const & tclass = params.getLyXTextClass();
docstring trmarg = from_utf8(tclass.rightmargin());
docstring lrmarg = from_utf8(par.layout()->rightmargin);
}
-int LyXText::labelEnd(pit_type const pit) const
+int LyXText::labelEnd(Buffer const & buffer, pit_type const pit) const
{
// labelEnd is only needed if the layout fills a flushleft label.
if (pars_[pit].layout()->margintype != MARGIN_MANUAL)
return 0;
// return the beginning of the body
- return leftMargin(pit);
+ return leftMargin(buffer, pit);
}
};
-void LyXText::rowBreakPoint(pit_type const pit, Row & row) const
+void LyXText::rowBreakPoint(Buffer const & buffer, pit_type const pit,
+ Row & row) const
{
Paragraph const & par = pars_[pit];
pos_type const end = par.size();
}
// maximum pixel width of a row
- int width = maxwidth_ - rightMargin(par); // - leftMargin(pit, row);
+ int width = maxwidth_ - rightMargin(buffer, par); // - leftMargin(buffer, pit, row);
if (width < 0) {
row.endpos(end);
return;
// or the end of the par, then choose the possible break
// nearest that.
- int const left = leftMargin(pit, pos);
+ int const left = leftMargin(buffer, pit, pos);
int x = left;
// pixel width since last breakpoint
int chunkwidth = 0;
- FontIterator fi = FontIterator(*this, par, pos);
+ FontIterator fi = FontIterator(buffer, *this, par, pos);
pos_type point = end;
pos_type i = pos;
- FontMetrics const & fm = theFontMetrics(getLabelFont(par));
+ FontMetrics const & fm = theFontMetrics(getLabelFont(buffer, par));
for ( ; i < end; ++i, ++fi) {
char_type const c = par.getChar(i);
- int thiswidth = singleWidth(par, i, c, *fi);
+ int thiswidth = singleWidth(buffer, par, i, c, *fi);
// add the auto-hfill from label end to the body
if (body_pos && i == body_pos) {
docstring lsep = from_utf8(layout->labelsep);
int add = fm.width(lsep);
if (par.isLineSeparator(i - 1))
- add -= singleWidth(par, i - 1);
+ add -= singleWidth(buffer, par, i - 1);
- add = std::max(add, labelEnd(pit) - x);
+ add = std::max(add, labelEnd(buffer, pit) - x);
thiswidth += add;
}
}
-void LyXText::setRowWidth(pit_type const pit, Row & row) const
+void LyXText::setRowWidth(Buffer const & buffer, pit_type const pit, Row & row) const
{
// get the pure distance
pos_type const end = row.endpos();
Paragraph const & par = pars_[pit];
docstring const labelsep = from_utf8(par.layout()->labelsep);
- int w = leftMargin(pit, row.pos());
+ int w = leftMargin(buffer, pit, row.pos());
pos_type const body_pos = par.beginOfBody();
pos_type i = row.pos();
- FontMetrics const & fm = theFontMetrics(getLabelFont(par));
+ FontMetrics const & fm = theFontMetrics(getLabelFont(buffer, par));
if (i < end) {
- FontIterator fi = FontIterator(*this, par, i);
+ FontIterator fi = FontIterator(buffer, *this, par, i);
for ( ; i < end; ++i, ++fi) {
if (body_pos > 0 && i == body_pos) {
w += fm.width(labelsep);
if (par.isLineSeparator(i - 1))
- w -= singleWidth(par, i - 1);
- w = max(w, labelEnd(pit));
+ w -= singleWidth(buffer, par, i - 1);
+ w = max(w, labelEnd(buffer, pit));
}
char_type const c = par.getChar(i);
- w += singleWidth(par, i, c, *fi);
+ w += singleWidth(buffer, par, i, c, *fi);
}
}
if (body_pos > 0 && body_pos >= end) {
w += fm.width(labelsep);
if (end > 0 && par.isLineSeparator(end - 1))
- w -= singleWidth(par, end - 1);
- w = max(w, labelEnd(pit));
+ w -= singleWidth(buffer, par, end - 1);
+ w = max(w, labelEnd(buffer, pit));
}
- row.width(w + rightMargin(par));
+ row.width(w + rightMargin(buffer, par));
}
// returns the minimum space a manual label needs on the screen in pixel
-int LyXText::labelFill(Paragraph const & par, Row const & row) const
+int LyXText::labelFill(Buffer const & buffer, Paragraph const & par,
+ Row const & row) const
{
pos_type last = par.beginOfBody();
int w = 0;
for (pos_type i = row.pos(); i <= last; ++i)
- w += singleWidth(par, i);
+ w += singleWidth(buffer, par, i);
docstring const & label = par.params().labelWidthString();
if (label.empty())
return 0;
- FontMetrics const & fm = theFontMetrics(getLabelFont(par));
+ FontMetrics const & fm = theFontMetrics(getLabelFont(buffer, par));
return max(0, fm.width(label) - w);
}
}
-void LyXText::setHeightOfRow(pit_type const pit, Row & row)
+void LyXText::setHeightOfRow(BufferView const & bv, pit_type const pit,
+ Row & row)
{
Paragraph const & par = pars_[pit];
// get the maximum ascent and the maximum descent
// increase but not decrease the height. Just some point to
// start with so we don't have to do the assignment below too
// often.
- LyXFont font = getFont(par, row.pos());
+ Buffer const & buffer = *bv.buffer();
+ LyXFont font = getFont(buffer, par, row.pos());
LyXFont::FONT_SIZE const tmpsize = font.size();
- font = getLayoutFont(pit);
+ font = getLayoutFont(buffer, pit);
LyXFont::FONT_SIZE const size = font.size();
font.setSize(tmpsize);
- LyXFont labelfont = getLabelFont(par);
+ LyXFont labelfont = getLabelFont(buffer, par);
FontMetrics const & labelfont_metrics = theFontMetrics(labelfont);
FontMetrics const & fontmetrics = theFontMetrics(font);
// these are minimum values
- double const spacing_val = layout->spacing.getValue() * spacing(par);
+ double const spacing_val = layout->spacing.getValue()
+ * spacing(*bv.buffer(), par);
//lyxerr << "spacing_val = " << spacing_val << endl;
int maxasc = int(fontmetrics.maxAscent() * spacing_val);
int maxdesc = int(fontmetrics.maxDescent() * spacing_val);
// is it a top line?
if (row.pos() == 0) {
- BufferParams const & bufparams = bv()->buffer()->params();
+ Buffer const & buffer = *bv.buffer();
+ BufferParams const & bufparams = buffer.params();
// some parksips VERY EASY IMPLEMENTATION
- if (bv()->buffer()->params().paragraph_separation
+ if (bufparams.paragraph_separation
== BufferParams::PARSEP_SKIP
&& pit != 0
&& ((layout->isParagraph() && par.getDepth() == 0)
|| (pars_[pit - 1].layout()->isParagraph()
&& pars_[pit - 1].getDepth() == 0)))
{
- maxasc += bufparams.getDefSkip().inPixels(*bv());
+ maxasc += bufparams.getDefSkip().inPixels(bv);
}
if (par.params().startOfAppendix())
&& !par.params().labelString().empty()) {
labeladdon = int(labelfont_metrics.maxHeight()
* layout->spacing.getValue()
- * spacing(par));
+ * spacing(buffer, par));
}
// special code for the top label
labeladdon = int(
labelfont_metrics.maxHeight()
* layout->spacing.getValue()
- * spacing(par)
+ * spacing(*bv.buffer(), par)
+ (layout->topsep + layout->labelbottomsep) * dh);
}
// FIXME: the correct way is to do the following is to move the
// following code in another method specially tailored for the
// main LyXText. The following test is thus bogus.
- LyXText const & text = bv_owner->buffer()->text();
+ LyXText const & text = buffer.text();
// Top and bottom margin of the document (only at top-level)
if (&text == this) {
if (pit == 0 && row.pos() == 0)
return;
// a layout change may affect also the following paragraph
- recUndo(cur.pit(), undoSpan(cur.pit()) - 1);
+ recUndo(cur, cur.pit(), undoSpan(cur.pit()) - 1);
// Always break behind a space
// It is better to erase the space (Dekel)
recordUndo(cur, Undo::INSERT);
+ Buffer const & buffer = cur.buffer();
Paragraph & par = cur.paragraph();
// try to remove this
pit_type const pit = cur.pit();
!(contains(number_seperators, c) &&
cur.pos() != 0 &&
cur.pos() != cur.lastpos() &&
- getFont(par, cur.pos()).number() == LyXFont::ON &&
- getFont(par, cur.pos() - 1).number() == LyXFont::ON)
+ getFont(buffer, par, cur.pos()).number() == LyXFont::ON &&
+ getFont(buffer, par, cur.pos() - 1).number() == LyXFont::ON)
)
number(cur); // Set current_font.number to OFF
} else if (isDigit(c) &&
|| par.isSeparator(cur.pos() - 2)
|| par.isNewline(cur.pos() - 2))
) {
- setCharFont(pit, cur.pos() - 1, current_font);
+ setCharFont(buffer, pit, cur.pos() - 1, current_font);
} else if (contains(number_seperators, c)
&& cur.pos() >= 2
- && getFont(par, cur.pos() - 2).number() == LyXFont::ON) {
- setCharFont(pit, cur.pos() - 1, current_font);
+ && getFont(buffer, par, cur.pos() - 2).number() == LyXFont::ON) {
+ setCharFont(buffer, pit, cur.pos() - 1, current_font);
}
}
}
}
-RowMetrics
-LyXText::computeRowMetrics(pit_type const pit, Row const & row) const
+RowMetrics LyXText::computeRowMetrics(Buffer const & buffer,
+ pit_type const pit, Row const & row) const
{
RowMetrics result;
Paragraph const & par = pars_[pit];
double w = dim_.wid - row.width();
- bool const is_rtl = isRTL(par);
+ bool const is_rtl = isRTL(buffer, par);
if (is_rtl)
- result.x = rightMargin(par);
+ result.x = rightMargin(buffer, par);
else
- result.x = leftMargin(pit, row.pos());
+ result.x = leftMargin(buffer, pit, row.pos());
// is there a manual margin with a manual label
LyXLayout_ptr const & layout = par.layout();
++nlh;
if (nlh && !par.getLabelWidthString().empty())
- result.label_hfill = labelFill(par, row) / double(nlh);
+ result.label_hfill = labelFill(buffer, par, row) / double(nlh);
}
// are there any hfills in the row?
}
}
- bidi.computeTables(par, *bv()->buffer(), row);
+ bidi.computeTables(par, buffer, row);
if (is_rtl) {
pos_type body_pos = par.beginOfBody();
pos_type end = row.endpos();
&& (body_pos > end || !par.isLineSeparator(body_pos - 1)))
{
docstring const lsep = from_utf8(layout->labelsep);
- result.x += theFontMetrics(getLabelFont(par)).width(lsep);
+ result.x += theFontMetrics(getLabelFont(buffer, par)).width(lsep);
if (body_pos <= end)
result.x += result.label_hfill;
}
bool LyXText::dissolveInset(LCursor & cur) {
BOOST_ASSERT(this == cur.text());
- if (isMainText() || cur.inset().nargs() != 1)
+ if (isMainText(*cur.bv().buffer()) || cur.inset().nargs() != 1)
return false;
recordUndoInset(cur);
}
-bool LyXText::redoParagraph(pit_type const pit)
+bool LyXText::redoParagraph(BufferView & bv, pit_type const pit)
{
// remove rows of paragraph, keep track of height changes
Paragraph & par = pars_[pit];
InsetBibitem(InsetCommandParams("bibitem")));
// FIXME: change tracking (MG)
par.insertInset(0, static_cast<InsetBase *>(inset), Change(Change::INSERTED));
- bv()->cursor().posRight();
+ bv.cursor().posRight();
}
}
// redo insets
// FIXME: We should always use getFont(), see documentation of
// noFontChange() in insetbase.h.
- LyXFont const bufferfont = bv()->buffer()->params().getFont();
+ Buffer const & buffer = *bv.buffer();
+ LyXFont const bufferfont = buffer.params().getFont();
InsetList::iterator ii = par.insetlist.begin();
InsetList::iterator iend = par.insetlist.end();
for (; ii != iend; ++ii) {
Dimension dim;
- int const w = maxwidth_ - leftMargin(pit, ii->pos) - rightMargin(par);
+ int const w = maxwidth_ - leftMargin(buffer, pit, ii->pos)
+ - rightMargin(buffer, par);
LyXFont const & font = ii->inset->noFontChange() ?
bufferfont :
- getFont(par, ii->pos);
- MetricsInfo mi(bv(), font, w);
+ getFont(buffer, par, ii->pos);
+ MetricsInfo mi(&bv, font, w);
ii->inset->metrics(mi, dim);
}
pos_type z = 0;
do {
Row row(z);
- rowBreakPoint(pit, row);
- setRowWidth(pit, row);
- setHeightOfRow(pit, row);
+ rowBreakPoint(buffer, pit, row);
+ setRowWidth(buffer, pit, row);
+ setHeightOfRow(bv, pit, row);
par.rows().push_back(row);
dim.wid = std::max(dim.wid, row.width());
dim.des += row.height();
if (z > 0 && par.isNewline(z - 1)) {
Row row(z - 1);
row.endpos(z - 1);
- setRowWidth(pit, row);
- setHeightOfRow(pit, row);
+ setRowWidth(buffer, pit, row);
+ setHeightOfRow(bv, pit, row);
par.rows().push_back(row);
dim.des += row.height();
}
unsigned int h = 0;
unsigned int w = 0;
for (pit_type pit = 0, n = paragraphs().size(); pit != n; ++pit) {
- redoParagraph(pit);
+ redoParagraph(*mi.base.bv, pit);
Paragraph & par = paragraphs()[pit];
h += par.height();
if (w < par.width())
DocIterator beg = cur.selectionBegin();
DocIterator end = cur.selectionEnd();
+ BufferView & bv = pi.base.bv;
+ Buffer const & buffer = *bv.buffer();
+
// the selection doesn't touch the visible screen
- if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_BELOW
- || bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_ABOVE)
+ if (bv_funcs::status(&bv, beg) == bv_funcs::CUR_BELOW
+ || bv_funcs::status(&bv, end) == bv_funcs::CUR_ABOVE)
return;
Paragraph const & par1 = pars_[beg.pit()];
Row const & row2 = par2.getRow(end.pos(), end.boundary());
int y1,x1,x2;
- if (bv_funcs::status(pi.base.bv, beg) == bv_funcs::CUR_ABOVE) {
+ if (bv_funcs::status(&bv, beg) == bv_funcs::CUR_ABOVE) {
y1 = 0;
x1 = 0;
x2 = 0;
} else {
y1 = bv_funcs::getPos(beg).y_ - row1.ascent();
- int const startx = cursorX(beg.top(), begin.boundary());
- x1 = isRTL(par1) ? startx : 0;
- x2 = isRTL(par1) ? 0 + dim_.wid : startx;
+ int const startx = cursorX(buffer, beg.top(), begin.boundary());
+ if (isRTL(buffer, par1)) {
+ x1 = startx;
+ x2 = 0 + dim_.wid;
+ }
+ else {
+ x1 = 0;
+ x2 = startx;
+ }
}
int y2,X1,X2;
- if (bv_funcs::status(pi.base.bv, end) == bv_funcs::CUR_BELOW) {
- y2 = pi.base.bv->workHeight();
+ if (bv_funcs::status(&bv, end) == bv_funcs::CUR_BELOW) {
+ y2 = bv.workHeight();
X1 = 0;
X2 = 0;
} else {
y2 = bv_funcs::getPos(end).y_ + row2.descent();
- int const endx = cursorX(end.top(), end.boundary());
- X1 = isRTL(par2) ? 0 : endx;
- X2 = isRTL(par2) ? endx : 0 + dim_.wid;
+ int const endx = cursorX(buffer, end.top(), end.boundary());
+ if (isRTL(buffer, par2)) {
+ X1 = 0;
+ X2 = endx;
+ }
+ else {
+ X1 = endx;
+ X2 = 0 + dim_.wid;
+ }
}
lyxerr << " y1: " << y1 << " y2: " << y2
DocIterator beg = cur.selectionBegin();
DocIterator end = cur.selectionEnd();
- BufferView * bv = pi.base.bv;
+ BufferView & bv = *pi.base.bv;
+ Buffer const & buffer = *bv.buffer();
// the selection doesn't touch the visible screen
- if (bv_funcs::status(bv, beg) == bv_funcs::CUR_BELOW
- || bv_funcs::status(bv, end) == bv_funcs::CUR_ABOVE)
+ if (bv_funcs::status(&bv, beg) == bv_funcs::CUR_BELOW
+ || bv_funcs::status(&bv, end) == bv_funcs::CUR_ABOVE)
return;
Paragraph const & par1 = pars_[beg.pit()];
Paragraph const & par2 = pars_[end.pit()];
- bool const above = (bv_funcs::status(bv, beg)
+ bool const above = (bv_funcs::status(&bv, beg)
== bv_funcs::CUR_ABOVE);
- bool const below = (bv_funcs::status(bv, end)
+ bool const below = (bv_funcs::status(&bv, end)
== bv_funcs::CUR_BELOW);
int y1,y2,x1,x2;
if (above) {
x2 = dim_.wid;
} else {
Row const & row1 = par1.getRow(beg.pos(), beg.boundary());
- y1 = bv_funcs::getPos(*bv, beg, beg.boundary()).y_ - row1.ascent();
+ y1 = bv_funcs::getPos(bv, beg, beg.boundary()).y_ - row1.ascent();
y2 = y1 + row1.height();
- int const startx = cursorX(beg.top(), beg.boundary());
- x1 = !isRTL(par1) ? startx : 0;
- x2 = !isRTL(par1) ? 0 + dim_.wid : startx;
+ int const startx = cursorX(buffer, beg.top(), beg.boundary());
+ if (!isRTL(buffer, par1)) {
+ x1 = startx;
+ x2 = 0 + dim_.wid;
+ }
+ else {
+ x1 = 0;
+ x2 = startx;
+ }
}
int Y1,Y2,X1,X2;
if (below) {
- Y1 = bv->workHeight();
- Y2 = bv->workHeight();
+ Y1 = bv.workHeight();
+ Y2 = bv.workHeight();
X1 = 0;
X2 = dim_.wid;
} else {
Row const & row2 = par2.getRow(end.pos(), end.boundary());
- Y1 = bv_funcs::getPos(*bv, end, end.boundary()).y_ - row2.ascent();
+ Y1 = bv_funcs::getPos(bv, end, end.boundary()).y_ - row2.ascent();
Y2 = Y1 + row2.height();
- int const endx = cursorX(end.top(), end.boundary());
- X1 = !isRTL(par2) ? 0 : endx;
- X2 = !isRTL(par2) ? endx : 0 + dim_.wid;
+ int const endx = cursorX(buffer, end.top(), end.boundary());
+ if (!isRTL(buffer, par2)) {
+ X1 = 0;
+ X2 = endx;
+ }
+ else {
+ X1 = endx;
+ X2 = 0 + dim_.wid;
+ }
}
if (!above && !below && &par1.getRow(beg.pos(), beg.boundary())
== &par2.getRow(end.pos(), end.boundary()))
{
// paint only one rectangle
- int const b( !isRTL(par1) ? x + x1 : x + X1 );
- int const w( !isRTL(par1) ? X2 - x1 : x2 - X1 );
+ int const b( !isRTL(*bv.buffer(), par1) ? x + x1 : x + X1 );
+ int const w( !isRTL(*bv.buffer(), par1) ? X2 - x1 : x2 - X1 );
pi.pain.fillRectangle(b, y1, w, y2 - y1, LColor::selection);
return;
}
}
-int LyXText::cursorX(CursorSlice const & sl, bool boundary) const
+int LyXText::cursorX(Buffer const & buffer, CursorSlice const & sl,
+ bool boundary) const
{
pit_type const pit = sl.pit();
Paragraph const & par = pars_[pit];
pos_type cursor_vpos = 0;
- RowMetrics const m = computeRowMetrics(pit, row);
+ RowMetrics const m = computeRowMetrics(buffer, pit, row);
double x = m.x;
pos_type const row_pos = row.pos();
if (end <= row_pos)
cursor_vpos = row_pos;
else if (ppos >= end)
- cursor_vpos = isRTL(par) ? row_pos : end;
+ cursor_vpos = isRTL(buffer, par) ? row_pos : end;
else if (ppos > row_pos && ppos >= end)
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(ppos - 1) % 2 == 0)
// Use font span to speed things up, see below
FontSpan font_span;
LyXFont font;
- FontMetrics const & labelfm = theFontMetrics(getLabelFont(par));
+ FontMetrics const & labelfm = theFontMetrics(
+ getLabelFont(buffer, par));
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
docstring const lsep = from_utf8(par.layout()->labelsep);
x += m.label_hfill + labelfm.width(lsep);
if (par.isLineSeparator(body_pos - 1))
- x -= singleWidth(par, body_pos - 1);
+ x -= singleWidth(buffer, par, body_pos - 1);
}
// Use font span to speed things up, see above
if (pos < font_span.first || pos > font_span.last) {
font_span = par.fontSpan(pos);
- font = getFont(par, pos);
+ font = getFont(buffer, par, pos);
}
- x += singleWidth(par, pos, par.getChar(pos), font);
+ x += singleWidth(buffer, par, pos, par.getChar(pos), font);
if (par.hfillExpansion(row, pos))
x += (pos >= body_pos) ? m.hfill : m.label_hfill;
// see correction above
if (boundary_correction)
- if (getFont(par, ppos).isVisibleRightToLeft())
- x -= singleWidth(par, ppos);
+ if (getFont(buffer, par, ppos).isVisibleRightToLeft())
+ x -= singleWidth(buffer, par, ppos);
else
- x += singleWidth(par, ppos);
+ x += singleWidth(buffer, par, ppos);
// Make sure inside an inset we always count from the left
// edge (bidi!) -- MV
if (sl.pos() < par.size()) {
- font = getFont(par, sl.pos());
+ font = getFont(buffer, par, sl.pos());
if (!boundary && font.isVisibleRightToLeft()
&& par.isInset(sl.pos()))
x -= par.getInset(sl.pos())->width();
// int pos = r.pos();
// for (; currx < x && pos < r.endpos(); ++pos) {
// lastx = currx;
-// currx += singleWidth(par, pos);
+// currx += singleWidth(buffer, par, pos);
// }
// if (abs(lastx - x) < abs(currx - x) && pos != r.pos())
// --pos;
//}
-pos_type LyXText::x2pos(pit_type pit, int row, int x) const
+pos_type LyXText::x2pos(BufferView const & bv, pit_type pit, int row,
+ int x) const
{
BOOST_ASSERT(row < int(pars_[pit].rows().size()));
bool bound = false;
Row const & r = pars_[pit].rows()[row];
- return r.pos() + getColumnNearX(pit, r, x, bound);
+ return r.pos() + getColumnNearX(bv, pit, r, x, bound);
}
bool LyXText::setCursorFromCoordinates(LCursor & cur, int const x, int const y)
{
BOOST_ASSERT(this == cur.text());
- pit_type pit = getPitNearY(y);
+ pit_type pit = getPitNearY(cur.bv(), y);
int yy = cur.bv().coordCache().get(this, pit).y_ - pars_[pit].ascent();
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
bool bound = false;
int xx = x;
- pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
+ pos_type const pos = row.pos() + getColumnNearX(cur.bv(), pit, row,
+ xx, bound);
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
: maxwidth_(bv ? bv->workWidth() : 100),
current_font(LyXFont::ALL_INHERIT),
background_color_(LColor::background),
- bv_owner(bv),
autoBreakRows_(false)
{}
void LyXText::init(BufferView * bv)
{
BOOST_ASSERT(bv);
- bv_owner = bv;
maxwidth_ = bv->workWidth();
dim_.wid = maxwidth_;
dim_.asc = 10;
}
-bool LyXText::isMainText() const
+bool LyXText::isMainText(Buffer const & buffer) const
{
- return &bv()->buffer()->text() == this;
+ return &buffer.text() == this;
}
//takes screen x,y coordinates
-InsetBase * LyXText::checkInsetHit(int x, int y) const
+InsetBase * LyXText::checkInsetHit(BufferView const & bv, int x, int y) const
{
- pit_type pit = getPitNearY(y);
+ pit_type pit = getPitNearY(bv, y);
BOOST_ASSERT(pit != -1);
Paragraph const & par = pars_[pit];
<< BOOST_CURRENT_FUNCTION
<< ": examining inset " << inset << endl;
- if (bv()->coordCache().getInsets().has(inset))
+ if (bv.coordCache().getInsets().has(inset))
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
- << ": xo: " << inset->xo(*bv()) << "..."
- << inset->xo(*bv()) + inset->width()
- << " yo: " << inset->yo(*bv()) - inset->ascent()
+ << ": xo: " << inset->xo(bv) << "..."
+ << inset->xo(bv) + inset->width()
+ << " yo: " << inset->yo(bv) - inset->ascent()
<< "..."
- << inset->yo(*bv()) + inset->descent()
+ << inset->yo(bv) + inset->descent()
<< endl;
else
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< ": inset has no cached position" << endl;
#endif
- if (inset->covers(*bv(), x, y)) {
+ if (inset->covers(bv, x, y)) {
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< ": Hit inset: " << inset << endl;
// The difference is that this one is used for displaying, and thus we
// are allowed to make cosmetic improvements. For instance make footnotes
// smaller. (Asger)
-LyXFont LyXText::getFont(Paragraph const & par, pos_type const pos) const
+LyXFont LyXText::getFont(Buffer const & buffer, Paragraph const & par,
+ pos_type const pos) const
{
BOOST_ASSERT(pos >= 0);
#ifdef WITH_WARNINGS
#warning broken?
#endif
- BufferParams const & params = bv()->buffer()->params();
+ BufferParams const & params = buffer.params();
pos_type const body_pos = par.beginOfBody();
// We specialize the 95% common case:
if (!par.getDepth()) {
LyXFont f = par.getFontSettings(params, pos);
- if (!isMainText())
- applyOuterFont(f);
+ if (!isMainText(buffer))
+ applyOuterFont(buffer, f);
LyXFont lf;
LyXFont rlf;
if (layout->labeltype == LABEL_MANUAL && pos < body_pos) {
LyXFont font = par.getFontSettings(params, pos);
font.realize(layoutfont);
- if (!isMainText())
- applyOuterFont(font);
+ if (!isMainText(buffer))
+ applyOuterFont(buffer, font);
// Find the pit value belonging to paragraph. This will not break
// even if pars_ would not be a vector anymore.
// the pi/mi parameters, and stored locally in a lyxtext in font_.
// This is where the two are integrated in the final fully realized
// font.
-void LyXText::applyOuterFont(LyXFont & font) const {
+void LyXText::applyOuterFont(Buffer const & buffer, LyXFont & font) const {
LyXFont lf(font_);
- lf.reduce(bv()->buffer()->params().getFont());
+ lf.reduce(buffer.params().getFont());
lf.realize(font);
lf.setLanguage(font.language());
font = lf;
}
-LyXFont LyXText::getLayoutFont(pit_type const pit) const
+LyXFont LyXText::getLayoutFont(Buffer const & buffer, pit_type const pit) const
{
LyXLayout_ptr const & layout = pars_[pit].layout();
LyXFont lf = layout->resfont;
// In case the default family has been customized
if (layout->font.family() == LyXFont::INHERIT_FAMILY)
- lf.setFamily(bv()->buffer()->params().getFont().family());
+ lf.setFamily(buffer.params().getFont().family());
return lf;
}
LyXFont font = layout->font;
// Realize with the fonts of lesser depth.
//font.realize(outerFont(pit, paragraphs()));
- font.realize(bv()->buffer()->params().getFont());
+ font.realize(buffer.params().getFont());
return font;
}
-LyXFont LyXText::getLabelFont(Paragraph const & par) const
+LyXFont LyXText::getLabelFont(Buffer const & buffer, Paragraph const & par) const
{
LyXLayout_ptr const & layout = par.layout();
LyXFont lf = layout->reslabelfont;
// In case the default family has been customized
if (layout->labelfont.family() == LyXFont::INHERIT_FAMILY)
- lf.setFamily(bv()->buffer()->params().getFont().family());
+ lf.setFamily(buffer.params().getFont().family());
return lf;
}
LyXFont font = layout->labelfont;
// Realize with the fonts of lesser depth.
- font.realize(bv()->buffer()->params().getFont());
+ font.realize(buffer.params().getFont());
return font;
}
-void LyXText::setCharFont(pit_type pit, pos_type pos, LyXFont const & fnt)
+void LyXText::setCharFont(Buffer const & buffer, pit_type pit,
+ pos_type pos, LyXFont const & fnt)
{
LyXFont font = fnt;
LyXLayout_ptr const & layout = pars_[pit].layout();
// Inside inset, apply the inset's font attributes if any
// (charstyle!)
- if (!isMainText())
+ if (!isMainText(buffer))
layoutfont.realize(font_);
- layoutfont.realize(bv()->buffer()->params().getFont());
+ layoutfont.realize(buffer.params().getFont());
// Now, reduce font against full layout font
font.reduce(layoutfont);
}
-void LyXText::setLayout(pit_type start, pit_type end, string const & layout)
+void LyXText::setLayout(Buffer const & buffer, pit_type start, pit_type end,
+ string const & layout)
{
BOOST_ASSERT(start != end);
- BufferParams const & bufparams = bv()->buffer()->params();
+ BufferParams const & bufparams = buffer.params();
LyXLayout_ptr const & lyxlayout = bufparams.getLyXTextClass()[layout];
for (pit_type pit = start; pit != end; ++pit) {
pit_type start = cur.selBegin().pit();
pit_type end = cur.selEnd().pit() + 1;
pit_type undopit = undoSpan(end - 1);
- recUndo(start, undopit - 1);
- setLayout(start, end, layout);
+ recUndo(cur, start, undopit - 1);
+ setLayout(cur.buffer(), start, end, layout);
updateLabels(cur.buffer());
}
LyXFont layoutfont;
pit_type pit = cur.pit();
if (cur.pos() < pars_[pit].beginOfBody())
- layoutfont = getLabelFont(pars_[pit]);
+ layoutfont = getLabelFont(cur.buffer(), pars_[pit]);
else
- layoutfont = getLayoutFont(pit);
+ layoutfont = getLayoutFont(cur.buffer(), pit);
// Update current font
real_current_font.update(font,
// nested insets.
for (; dit != ditend; dit.forwardPosNoDescend()) {
if (dit.pos() != dit.lastpos()) {
- LyXFont f = getFont(dit.paragraph(), dit.pos());
+ LyXFont f = getFont(cur.buffer(), dit.paragraph(), dit.pos());
f.update(font, params.language, toggleall);
- setCharFont(dit.pit(), dit.pos(), f);
+ setCharFont(cur.buffer(), dit.pit(), dit.pos(), f);
}
}
}
BOOST_ASSERT(cur.text());
// make sure that the depth behind the selection are restored, too
pit_type undopit = undoSpan(cur.selEnd().pit());
- recUndo(cur.selBegin().pit(), undopit - 1);
+ recUndo(cur, cur.selBegin().pit(), undopit - 1);
for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
pit <= end; ++pit) {
BufferParams const & bufparams = cur.buffer().params();
current_font = par.getFontSettings(bufparams, pos);
- real_current_font = getFont(par, pos);
+ real_current_font = getFont(cur.buffer(), par, pos);
if (cur.pos() == cur.lastpos()
&& bidi.isBoundary(cur.buffer(), par, cur.pos())
// x is an absolute screen coord
// returns the column near the specified x-coordinate of the row
// x is set to the real beginning of this column
-pos_type LyXText::getColumnNearX(pit_type const pit,
+pos_type LyXText::getColumnNearX(BufferView const & bv, pit_type const pit,
Row const & row, int & x, bool & boundary) const
{
- int const xo = bv()->coordCache().get(this, pit).x_;
+ Buffer const & buffer = *bv.buffer();
+ int const xo = bv.coordCache().get(this, pit).x_;
x -= xo;
- RowMetrics const r = computeRowMetrics(pit, row);
+ RowMetrics const r = computeRowMetrics(buffer, pit, row);
Paragraph const & par = pars_[pit];
pos_type vc = row.pos();
}
frontend::FontMetrics const & fm
- = theFontMetrics(getLabelFont(par));
+ = theFontMetrics(getLabelFont(buffer, par));
while (vc < end && tmpx <= x) {
c = bidi.vis2log(vc);
docstring const lsep = from_utf8(layout->labelsep);
tmpx += r.label_hfill + fm.width(lsep);
if (par.isLineSeparator(body_pos - 1))
- tmpx -= singleWidth(par, body_pos - 1);
+ tmpx -= singleWidth(buffer, par, body_pos - 1);
}
if (par.hfillExpansion(row, c)) {
- tmpx += singleWidth(par, c);
+ tmpx += singleWidth(buffer, par, c);
if (c >= body_pos)
tmpx += r.hfill;
else
tmpx += r.label_hfill;
} else if (par.isSeparator(c)) {
- tmpx += singleWidth(par, c);
+ tmpx += singleWidth(buffer, par, c);
if (c >= body_pos)
tmpx += r.separator;
} else {
- tmpx += singleWidth(par, c);
+ tmpx += singleWidth(buffer, par, c);
}
++vc;
}
// If lastrow is false, we don't need to compute
// the value of rtl.
- bool const rtl = lastrow ? isRTL(par) : false;
+ bool const rtl = lastrow ? isRTL(buffer, par) : false;
if (lastrow &&
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
(!rtl && !left_side && vc == end && x > tmpx + 5)))
bool const rtl = (bidi.level(c) % 2 == 1);
if (left_side == rtl) {
++c;
- boundary = bidi.isBoundary(*bv()->buffer(), par, c);
+ boundary = bidi.isBoundary(buffer, par, c);
}
}
// Newline inset, air gap below:
if (row.pos() < end && c >= end && par.isNewline(end - 1)) {
if (bidi.level(end -1) % 2 == 0)
- tmpx -= singleWidth(par, end - 1);
+ tmpx -= singleWidth(buffer, par, end - 1);
else
- tmpx += singleWidth(par, end - 1);
+ tmpx += singleWidth(buffer, par, end - 1);
c = end - 1;
}
// y is screen coordinate
-pit_type LyXText::getPitNearY(int y) const
+pit_type LyXText::getPitNearY(BufferView const & bv, int y) const
{
BOOST_ASSERT(!paragraphs().empty());
- BOOST_ASSERT(bv()->coordCache().getParPos().find(this) != bv()->coordCache().getParPos().end());
- CoordCache::InnerParPosCache const & cc = bv()->coordCache().getParPos().find(this)->second;
+ BOOST_ASSERT(bv.coordCache().getParPos().find(this) != bv.coordCache().getParPos().end());
+ CoordCache::InnerParPosCache const & cc = bv.coordCache().getParPos().find(this)->second;
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< ": y: " << y << " cache size: " << cc.size()
}
-Row const & LyXText::getRowNearY(int y, pit_type pit) const
+Row const & LyXText::getRowNearY(BufferView const & bv, int y, pit_type pit) const
{
Paragraph const & par = pars_[pit];
- int yy = bv()->coordCache().get(this, pit).y_ - par.ascent();
+ int yy = bv.coordCache().get(this, pit).y_ - par.ascent();
BOOST_ASSERT(!par.rows().empty());
RowList::const_iterator rit = par.rows().begin();
RowList::const_iterator const rlast = boost::prior(par.rows().end());
{
if (lyxerr.debugging(Debug::WORKAREA)) {
lyxerr << "LyXText::editXY(cur, " << x << ", " << y << ")" << std::endl;
- bv()->coordCache().dump();
+ cur.bv().coordCache().dump();
}
- pit_type pit = getPitNearY(y);
+ pit_type pit = getPitNearY(cur.bv(), y);
BOOST_ASSERT(pit != -1);
- Row const & row = getRowNearY(y, pit);
+ Row const & row = getRowNearY(cur.bv(), y, pit);
bool bound = false;
int xx = x; // is modified by getColumnNearX
- pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
+ pos_type const pos = row.pos() + getColumnNearX(cur.bv(), pit, row, xx, bound);
cur.pit() = pit;
cur.pos() = pos;
cur.boundary(bound);
cur.x_target() = x;
// try to descend into nested insets
- InsetBase * inset = checkInsetHit(x, y);
+ InsetBase * inset = checkInsetHit(cur.bv(), x, y);
//lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl;
if (!inset) {
// Either we deconst editXY or better we move current_font
if (row > 0) {
updateNeeded |= setCursor(cur, cur.pit(),
- x2pos(cur.pit(), row - 1, x));
+ x2pos(cur.bv(), cur.pit(), row - 1, x));
} else if (cur.pit() > 0) {
--cur.pit();
//cannot use 'par' now
updateNeeded |= setCursor(cur, cur.pit(),
- x2pos(cur.pit(), cur.paragraph().rows().size() - 1, x));
+ x2pos(cur.bv(), cur.pit(), cur.paragraph().rows().size() - 1, x));
}
cur.x_target() = x;
if (row + 1 < int(par.rows().size())) {
updateNeeded |= setCursor(cur, cur.pit(),
- x2pos(cur.pit(), row + 1, x));
+ x2pos(cur.bv(), cur.pit(), row + 1, x));
} else if (cur.pit() + 1 < int(paragraphs().size())) {
++cur.pit();
updateNeeded |= setCursor(cur, cur.pit(),
- x2pos(cur.pit(), 0, x));
+ x2pos(cur.bv(), cur.pit(), 0, x));
}
cur.x_target() = x;
}
-void LyXText::recUndo(pit_type first, pit_type last) const
+void LyXText::recUndo(LCursor & cur, pit_type first, pit_type last) const
{
- recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
+ recordUndo(cur, Undo::ATOMIC, first, last);
}
-void LyXText::recUndo(pit_type par) const
+void LyXText::recUndo(LCursor & cur, pit_type par) const
{
- recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
+ recordUndo(cur, Undo::ATOMIC, par, par);
}
}
-bool LyXText::isRTL(Paragraph const & par) const
+bool LyXText::isRTL(Buffer const & buffer, Paragraph const & par) const
{
- return par.isRightToLeftPar(bv()->buffer()->params());
+ return par.isRightToLeftPar(buffer.params());
}
case LFUN_PARAGRAPH_MOVE_DOWN: {
pit_type const pit = cur.pit();
- recUndo(pit, pit + 1);
+ recUndo(cur, pit, pit + 1);
finishUndo();
std::swap(pars_[pit], pars_[pit + 1]);
case LFUN_PARAGRAPH_MOVE_UP: {
pit_type const pit = cur.pit();
- recUndo(pit - 1, pit);
+ recUndo(cur, pit - 1, pit);
finishUndo();
std::swap(pars_[pit], pars_[pit - 1]);
// ensure that we have only one start_of_appendix in this document
for (pit_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
if (pars_[tmp].params().startOfAppendix()) {
- recUndo(tmp);
+ recUndo(cur, tmp);
pars_[tmp].params().startOfAppendix(false);
break;
}
//lyxerr << BOOST_CURRENT_FUNCTION
// << " LFUN_CHAR_FORWARD[SEL]:\n" << cur << endl;
needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_FORWARD_SELECT);
- if (isRTL(cur.paragraph()))
+ if (isRTL(*cur.bv().buffer(), cur.paragraph()))
needsUpdate |= cursorLeft(cur);
else
needsUpdate |= cursorRight(cur);
case LFUN_CHAR_BACKWARD_SELECT:
//lyxerr << "handle LFUN_CHAR_BACKWARD[_SELECT]:\n" << cur << endl;
needsUpdate |= cur.selHandle(cmd.action == LFUN_CHAR_BACKWARD_SELECT);
- if (isRTL(cur.paragraph()))
+ if (isRTL(*cur.bv().buffer(), cur.paragraph()))
needsUpdate |= cursorRight(cur);
else
needsUpdate |= cursorLeft(cur);
case LFUN_WORD_FORWARD:
case LFUN_WORD_FORWARD_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT);
- if (isRTL(cur.paragraph()))
+ if (isRTL(*cur.bv().buffer(), cur.paragraph()))
needsUpdate |= cursorLeftOneWord(cur);
else
needsUpdate |= cursorRightOneWord(cur);
case LFUN_WORD_BACKWARD:
case LFUN_WORD_BACKWARD_SELECT:
needsUpdate |= cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT);
- if (isRTL(cur.paragraph()))
+ if (isRTL(*cur.bv().buffer(), cur.paragraph()))
needsUpdate |= cursorRightOneWord(cur);
else
needsUpdate |= cursorLeftOneWord(cur);
case LFUN_SERVER_GET_XY:
cur.message(from_utf8(
- convert<string>(cursorX(cur.top(), cur.boundary())) + ' '
- + convert<string>(cursorY(cur.top(), cur.boundary()))));
+ convert<string>(cursorX(cur.buffer(), cur.top(), cur.boundary()))
+ + ' ' + convert<string>(cursorY(cur.top(), cur.boundary()))));
break;
case LFUN_SERVER_SET_XY: {
if (!cmd.argument().empty())
// FIXME: Are all these characters encoded in one byte in utf8?
bv->getIntl().getTransManager()
- .translateAndInsert(cmd.argument()[0], this);
+ .translateAndInsert(cmd.argument()[0], this, cur);
break;
case LFUN_FLOAT_LIST: {
break;
case LFUN_INSET_DISSOLVE:
- enable = !isMainText() && cur.inset().nargs() == 1;
+ enable = !isMainText(*cur.bv().buffer()) && cur.inset().nargs() == 1;
break;
case LFUN_CHANGE_ACCEPT:
#include "trans_mgr.h"
+#include "buffer.h"
#include "BufferView.h"
#include "CutAndPaste.h"
#include "cursor.h"
}
-void TransManager::translateAndInsert(char c, LyXText * text)
+void TransManager::translateAndInsert(char c, LyXText * text, LCursor & cur)
{
string res = active_->process(c, *this);
while (res.length() > 0) {
res = split(res, temp, TransState::TOKEN_SEP);
- insert(temp, text);
+ insert(temp, text, cur);
}
}
-void TransManager::insertVerbatim(string const & str, LyXText * text)
+void TransManager::insertVerbatim(string const & str, LyXText * text, LCursor & cur)
{
for (string::size_type i = 0, n = str.size(); i < n; ++i)
- text->insertChar(text->bv()->cursor(), str[i]);
+ text->insertChar(cur, str[i]);
}
-void TransManager::insert(string const & str, LyXText * text)
+void TransManager::insert(string const & str, LyXText * text, LCursor & cur)
{
// Go through the character encoding only if the current
// encoding (chset_->name()) matches the current font_norm
// Could not find an encoding
InsetLatexAccent ins(str);
if (ins.canDisplay()) {
- LCursor & cur = text->bv()->cursor();
cap::replaceSelection(cur);
cur.insert(new InsetLatexAccent(ins));
cur.posRight();
} else {
- insertVerbatim(str, text);
+ insertVerbatim(str, text, cur);
}
return;
}
string const tmp(1, static_cast<char>(enc.second));
- insertVerbatim(tmp, text);
+ insertVerbatim(tmp, text, cur);
}
-void TransManager::deadkey(char c, tex_accent accent, LyXText * t)
+void TransManager::deadkey(char c, tex_accent accent, LyXText * t, LCursor & cur)
{
if (c == 0 && active_ != &default_) {
// A deadkey was pressed that cannot be printed
if (active_->isAccentDefined(accent, i) == true) {
string const res = trans_fsm_
.currentState->deadkey(c, i);
- insert(res, t);
+ insert(res, t, cur);
return;
}
}
i.accent = accent;
i.data.erase();
string res = trans_fsm_.currentState->deadkey(c, i);
- insert(res, t);
+ insert(res, t, cur);
} else {
// Go through the translation
- translateAndInsert(c, t);
+ translateAndInsert(c, t, cur);
}
}
namespace lyx {
+class LCursor;
class LyXText;
class Trans;
///
CharacterSet chset_;
///
- void insert(std::string const &, LyXText *);
+ void insert(std::string const &, LyXText *, LCursor & cur);
///
- void insertVerbatim(std::string const &, LyXText *);
+ void insertVerbatim(std::string const &, LyXText *, LCursor & cur);
public:
///
TransManager();
return trans_fsm_.currentState->backspace();
}
///
- void translateAndInsert(char, LyXText *);
+ void translateAndInsert(char, LyXText *, LCursor &);
///
std::string const deadkey(char, KmodInfo);
///
std::string const normalkey(char);
///
- void deadkey(char, tex_accent, LyXText *);
+ void deadkey(char, tex_accent, LyXText *, LCursor &);
};