#include "Bidi.h"
#include "BufferView.h"
-#include "bufferview_funcs.h"
#include "Buffer.h"
#include "Cursor.h"
#include "CoordCache.h"
#include "Paragraph.h"
#include "paragraph_funcs.h"
#include "ParIterator.h"
+#include "TextMetrics.h"
#include "insets/InsetTabular.h"
#include "insets/InsetText.h"
#include "mathed/InsetMathScript.h"
#include "mathed/MacroTable.h"
-#include "support/limited_stack.h"
-
#include <boost/assert.hpp>
#include <boost/bind.hpp>
#include <boost/current_function.hpp>
int xo;
int yo;
Inset const * inset = &it.inset();
- std::map<Inset const *, Point> const & data =
+ std::map<Inset const *, Geometry> const & data =
c.bv().coordCache().getInsets().getData();
- std::map<Inset const *, Point>::const_iterator I = data.find(inset);
+ std::map<Inset const *, Geometry>::const_iterator I = data.find(inset);
// FIXME: in the case where the inset is not in the cache, this
// means that no part of it is visible on screen. In this case
return it;
}
- Point o = I->second;
+ Point o = I->second.pos;
inset->cursorPos(c.bv(), it.top(), c.boundary(), xo, yo);
// Convert to absolute
xo += o.x_;
}
+ /*
/// moves position closest to (x, y) in given box
bool bruteFind(Cursor & cursor,
int x, int y, int xlow, int xhigh, int ylow, int yhigh)
for ( ; it != et; it.forwardPos(true)) {
// avoid invalid nesting when selecting
if (!cursor.selection() || positionable(it, cursor.anchor_)) {
- Point p = bv_funcs::getPos(bv, it, false);
+ Point p = bv.getPos(it, false);
int xo = p.x_;
int yo = p.y_;
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
return false;
}
+ */
/// moves position closest to (x, y) in given box
for ( ; it != et; it.forwardPos()) {
// avoid invalid nesting when selecting
- if (bv_funcs::status(&bv, it) == bv_funcs::CUR_INSIDE
+ if (bv.cursorStatus(it) == CUR_INSIDE
&& (!cur.selection() || positionable(it, cur.anchor_))) {
- Point p = bv_funcs::getPos(bv, it, false);
+ Point p = bv.getPos(it, false);
int xo = p.x_;
int yo = p.y_;
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
odocstringstream ods;
ods << '\n';
// only add blank line if we're not in an ERT or Listings inset
- if (par.ownerCode() != Inset::ERT_CODE
- && par.ownerCode() != Inset::LISTINGS_CODE)
+ if (par.ownerCode() != ERT_CODE
+ && par.ownerCode() != LISTINGS_CODE)
ods << '\n';
return ods.str();
}
// bv functions are not yet available!
Cursor::Cursor(BufferView & bv)
: DocIterator(), bv_(&bv), anchor_(), x_target_(-1), textTargetOffset_(0),
- selection_(false), mark_(false), logicalpos_(false)
+ selection_(false), mark_(false), logicalpos_(false), current_font(Font::ALL_INHERIT)
{}
void Cursor::getPos(int & x, int & y) const
{
- Point p = bv_funcs::getPos(bv(), *this, boundary());
+ Point p = bv().getPos(*this, boundary());
x = p.x_;
y = p.y_;
}
}
-void Cursor::setScreenPos(int x, int y)
+void Cursor::setScreenPos(int x, int /*y*/)
{
setTargetX(x);
- bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
+ //bruteFind(*this, x, y, 0, bv().workWidth(), 0, bv().workHeight());
}
// with and without selection are handled differently
if (!selection()) {
- int yo = bv_funcs::getPos(bv(), *this, boundary()).y_;
+ int yo = bv().getPos(*this, boundary()).y_;
Cursor old = *this;
// To next/previous row
if (up)
Font Cursor::getFont() const
{
- // The logic here should more or less match to the Text::setCurrentFont
+ // The logic here should more or less match to the Cursor::setCurrentFont
// logic, i.e. the cursor height should give a hint what will happen
// if a character is entered.
// on space? Take the font before (only for RTL boundary stay)
if (pos > 0) {
+ TextMetrics const & tm = bv().textMetrics(&text);
if (pos == sl.lastpos()
- || (par.isSeparator(pos) &&
- !text.isRTLBoundary(buffer(), par, pos)))
+ || (par.isSeparator(pos)
+ && !tm.isRTLBoundary(sl.pit(), pos)))
--pos;
}
}
+void Cursor::setCurrentFont()
+{
+ CursorSlice const & cs = innerTextSlice();
+ Paragraph const & par = cs.paragraph();
+ pos_type cpit = cs.pit();
+ pos_type cpos = cs.pos();
+ Text const & ctext = *cs.text();
+ TextMetrics const & tm = bv().textMetrics(&ctext);
+
+ // are we behind previous char in fact? -> go to that char
+ if (cpos > 0 && boundary())
+ --cpos;
+
+ // find position to take the font from
+ if (cpos != 0) {
+ // paragraph end? -> font of last char
+ if (cpos == lastpos())
+ --cpos;
+ // on space? -> look at the words in front of space
+ else if (cpos > 0 && par.isSeparator(cpos)) {
+ // abc| def -> font of c
+ // abc |[WERBEH], i.e. boundary==true -> font of c
+ // abc [WERBEH]| def, font of the space
+ if (!tm.isRTLBoundary(cpit, cpos))
+ --cpos;
+ }
+ }
+
+ // get font
+ BufferParams const & bufparams = buffer().params();
+ current_font = par.getFontSettings(bufparams, cpos);
+ real_current_font = tm.getDisplayFont(cpit, cpos);
+
+ // special case for paragraph end
+ if (cs.pos() == lastpos()
+ && tm.isRTLBoundary(cpit, cs.pos())
+ && !boundary()) {
+ Language const * lang = par.getParLanguage(bufparams);
+ current_font.setLanguage(lang);
+ current_font.setNumber(Font::OFF);
+ real_current_font.setLanguage(lang);
+ real_current_font.setNumber(Font::OFF);
+ }
+}
+
+
+bool Cursor::textUndo()
+{
+ DocIterator dit = *this;
+ // Undo::textUndo() will modify dit.
+ if (!bv_->buffer().undo().textUndo(dit))
+ return false;
+ // Set cursor
+ setCursor(dit);
+ selection() = false;
+ resetAnchor();
+ fixIfBroken();
+ return true;
+}
+
+
+bool Cursor::textRedo()
+{
+ DocIterator dit = *this;
+ // Undo::textRedo() will modify dit.
+ if (!bv_->buffer().undo().textRedo(dit))
+ return false;
+ // Set cursor
+ setCursor(dit);
+ selection() = false;
+ resetAnchor();
+ fixIfBroken();
+ return true;
+}
+
+
+void Cursor::finishUndo()
+{
+ bv_->buffer().undo().finishUndo();
+}
+
+
+void Cursor::recordUndo(UndoKind kind, pit_type from, pit_type to)
+{
+ bv_->buffer().undo().recordUndo(*this, kind, from, to);
+}
+
+
+void Cursor::recordUndo(UndoKind kind, pit_type from)
+{
+ bv_->buffer().undo().recordUndo(*this, kind, from);
+}
+
+
+void Cursor::recordUndo(UndoKind kind)
+{
+ bv_->buffer().undo().recordUndo(*this, kind);
+}
+
+
+void Cursor::recordUndoInset(UndoKind kind)
+{
+ bv_->buffer().undo().recordUndoInset(*this, kind);
+}
+
+
+void Cursor::recordUndoFullDocument()
+{
+ bv_->buffer().undo().recordUndoFullDocument(*this);
+}
+
+
+void Cursor::recordUndoSelection()
+{
+ bv_->buffer().undo().recordUndo(*this, ATOMIC_UNDO,
+ selBegin().pit(), selEnd().pit());
+}
+
+
} // namespace lyx