merge CursorItem and MathPos

remove cached x and y values from Cursor
some tabular fixes


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8251 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-12-15 11:36:19 +00:00
parent 1ebd651ad6
commit a97ed20502
27 changed files with 486 additions and 434 deletions

View File

@ -469,9 +469,9 @@ void BufferView::Pimpl::scrollDocView(int value)
int const last = top_y() + workarea().workHeight() - height; int const last = top_y() + workarea().workHeight() - height;
LyXText * text = bv_->text(); LyXText * text = bv_->text();
if (text->cursor.y() < first) if (text->cursorY() < first)
text->setCursorFromCoordinates(0, first); text->setCursorFromCoordinates(0, first);
else if (text->cursor.y() > last) else if (text->cursorY() > last)
text->setCursorFromCoordinates(0, last); text->setCursorFromCoordinates(0, last);
owner_->updateLayoutChoice(); owner_->updateLayoutChoice();
@ -713,7 +713,7 @@ void BufferView::Pimpl::center()
text->clearSelection(); text->clearSelection();
int const half_height = workarea().workHeight() / 2; int const half_height = workarea().workHeight() / 2;
int new_y = std::max(0, text->cursor.y() - half_height); int new_y = std::max(0, text->cursorY() - half_height);
// FIXME: look at this comment again ... // FIXME: look at this comment again ...
// This updates top_y() but means the fitCursor() call // This updates top_y() but means the fitCursor() call

View File

@ -1,3 +1,19 @@
2003-12-15 André Pönitz <poenitz@gmx.net>
* cursor_slice.[Ch]: new class to cover texted and mathed's cursor slices
* Makefile.am:
* BufferView_pimpl.C:
* cursor.[Ch]:
* lyxcursor.[Ch]:
* rowpainter.[Ch]:
* lyxtext.h:
* text.C:
* text2.C:
* text3.C: adjust
2003-12-15 Angus Leeming <leeming@lyx.org> 2003-12-15 Angus Leeming <leeming@lyx.org>
* metricsinfo.C (ColorChanger): use LColor::getFromLyXName rather * metricsinfo.C (ColorChanger): use LColor::getFromLyXName rather
@ -5,7 +21,7 @@
2003-12-14 Angus Leeming <leeming@lyx.org> 2003-12-14 Angus Leeming <leeming@lyx.org>
BranchList.[Ch]: minimize the API. * BranchList.[Ch]: minimize the API.
(Branch::getBranch, getColor): now return a 'const &'. (Branch::getBranch, getColor): now return a 'const &'.
(Branch::setSelected) now returns a bool set to true if the (Branch::setSelected) now returns a bool set to true if the
selection status changes. selection status changes.

View File

@ -136,6 +136,8 @@ lyx_SOURCES = \
counters.h \ counters.h \
cursor.C \ cursor.C \
cursor.h \ cursor.h \
cursor_slice.C \
cursor_slice.h \
debug.C \ debug.C \
debug.h \ debug.h \
dimension.C \ dimension.C \

View File

@ -32,27 +32,6 @@ using std::vector;
using std::endl; using std::endl;
std::ostream & operator<<(std::ostream & os, CursorItem const & item)
{
os << " inset: " << item.inset_
<< " code: " << item.inset_->lyxCode()
<< " text: " << item.text()
<< " idx: " << item.idx_
// << " par: " << item.par_
// << " pos: " << item.pos_
<< " x: " << item.inset_->x()
<< " y: " << item.inset_->y()
;
return os;
}
LyXText * CursorItem::text() const
{
return inset_->getText(0);
}
std::ostream & operator<<(std::ostream & os, LCursor const & cursor) std::ostream & operator<<(std::ostream & os, LCursor const & cursor)
{ {
os << "\n"; os << "\n";
@ -73,7 +52,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
FuncRequest cmd = cmd0; FuncRequest cmd = cmd0;
for (int i = data_.size() - 1; i >= 0; --i) { for (int i = data_.size() - 1; i >= 0; --i) {
CursorItem const & citem = data_[i]; CursorSlice const & citem = data_[i];
lyxerr << "trying to dispatch to inset " << citem.inset_ << endl; lyxerr << "trying to dispatch to inset " << citem.inset_ << endl;
DispatchResult res = citem.inset_->dispatch(cmd); DispatchResult res = citem.inset_->dispatch(cmd);
if (res.dispatched()) { if (res.dispatched()) {
@ -121,7 +100,7 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
void LCursor::push(UpdatableInset * inset) void LCursor::push(UpdatableInset * inset)
{ {
lyxerr << "LCursor::push() inset: " << inset << endl; lyxerr << "LCursor::push() inset: " << inset << endl;
data_.push_back(CursorItem(inset)); data_.push_back(CursorSlice(inset));
updatePos(); updatePos();
} }
@ -149,7 +128,7 @@ void LCursor::pop()
UpdatableInset * LCursor::innerInset() const UpdatableInset * LCursor::innerInset() const
{ {
return data_.empty() ? 0 : data_.back().inset_; return data_.empty() ? 0 : data_.back().asUpdatableInset();
} }
@ -189,8 +168,8 @@ void LCursor::getDim(int & asc, int & desc) const
void LCursor::getPos(int & x, int & y) const void LCursor::getPos(int & x, int & y) const
{ {
if (data_.empty()) { if (data_.empty()) {
x = bv_->text()->cursor.x(); x = bv_->text()->cursorX();
y = bv_->text()->cursor.y(); y = bv_->text()->cursorY();
// y -= bv_->top_y(); // y -= bv_->top_y();
} else { } else {
// Would be nice to clean this up to make some understandable sense... // Would be nice to clean this up to make some understandable sense...
@ -202,7 +181,6 @@ void LCursor::getPos(int & x, int & y) const
// inset->draw() is not called: this doesn't update // inset->draw() is not called: this doesn't update
// inset.top_baseline, so getCursor() returns an old value. // inset.top_baseline, so getCursor() returns an old value.
// Ugly as you like. // Ugly as you like.
//inset->getCursorPos(bv_, x, y);
inset->getCursorPos(x, y); inset->getCursorPos(x, y);
x += inset->x(); x += inset->x();
y += cached_y_; y += cached_y_;
@ -213,8 +191,8 @@ void LCursor::getPos(int & x, int & y) const
UpdatableInset * LCursor::innerInsetOfType(int code) const UpdatableInset * LCursor::innerInsetOfType(int code) const
{ {
for (int i = data_.size() - 1; i >= 0; --i) for (int i = data_.size() - 1; i >= 0; --i)
if (data_[i].inset_->lyxCode() == code) if (data_[i].asUpdatableInset()->lyxCode() == code)
return data_[i].inset_; return data_[i].asUpdatableInset();
return 0; return 0;
} }

View File

@ -13,6 +13,7 @@
#define CURSOR_H #define CURSOR_H
#include "textcursor.h" #include "textcursor.h"
#include "cursor_slice.h"
#include "support/types.h" #include "support/types.h"
@ -31,29 +32,6 @@ class InsetTabular;
* The cursor class describes the position of a cursor within a document. * The cursor class describes the position of a cursor within a document.
*/ */
class CursorItem {
public:
///
CursorItem() : inset_(0), idx_(0), par_(0), pos_(0) {}
///
explicit CursorItem(UpdatableInset * inset)
: inset_(inset), idx_(0), par_(0), pos_(0)
{}
///
LyXText * text() const;
///
friend std::ostream & operator<<(std::ostream &, CursorItem const &);
public:
///
UpdatableInset * inset_;
///
int idx_;
///
int par_;
///
int pos_;
};
class LCursor { class LCursor {
public: public:
@ -85,7 +63,7 @@ public:
friend std::ostream & operator<<(std::ostream &, LCursor const &); friend std::ostream & operator<<(std::ostream &, LCursor const &);
public: public:
/// mainly used as stack, but wee need random access /// mainly used as stack, but wee need random access
std::vector<CursorItem> data_; std::vector<CursorSlice> data_;
/// ///
BufferView * bv_; BufferView * bv_;
private: private:

133
src/cursor_slice.C Normal file
View File

@ -0,0 +1,133 @@
/**
* \file cursor_slice.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "cursor_slice.h"
#include "debug.h"
#include "mathed/math_inset.h"
#include "insets/updatableinset.h"
#include <boost/assert.hpp>
using std::endl;
CursorSlice::CursorSlice()
: inset_(0), idx_(0), par_(0), pos_(0)
{}
CursorSlice::CursorSlice(InsetBase * p)
: inset_(p), idx_(0), par_(0), pos_(0)
{
///BOOST_ASSERT(inset_);
}
MathInset * CursorSlice::asMathInset() const
{
return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
}
UpdatableInset * CursorSlice::asUpdatableInset() const
{
return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
}
MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
{
BOOST_ASSERT(inset_);
return asMathInset()->cell(idx);
}
MathArray & CursorSlice::cell() const
{
BOOST_ASSERT(inset_);
return asMathInset()->cell(idx_);
}
void CursorSlice::getPos(int & x, int & y) const
{
asMathInset()->getPos(idx_, pos_, x, y);
}
void CursorSlice::setPos(int pos)
{
pos_ = pos;
}
LyXText * CursorSlice::text() const
{
return asUpdatableInset()->getText(idx_);
}
bool operator==(CursorSlice const & p, CursorSlice const & q)
{
return p.inset_ == q.inset_
&& p.idx_ == q.idx_
&& p.par_ == q.par_
&& p.pos_ == q.pos_;
}
bool operator!=(CursorSlice const & p, CursorSlice const & q)
{
return p.inset_ != q.inset_
|| p.idx_ != q.idx_
|| p.par_ != q.par_
|| p.pos_ != q.pos_;
}
bool operator<(CursorSlice const & p, CursorSlice const & q)
{
if (p.inset_ != q.inset_) {
lyxerr << "can't compare cursor and anchor in different insets\n"
<< "p: " << p << '\n' << "q: " << q << endl;
return true;
}
if (p.idx_ != q.idx_)
return p.idx_ < q.idx_;
if (p.par_ != q.par_)
return p.par_ < q.par_;
return p.pos_ < q.pos_;
}
//std::ostream & operator<<(std::ostream & os, CursorSlice const & p)
//{
// os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
// return os;
//}
std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
{
os << " inset: " << item.inset_
// << " text: " << item.text()
<< " idx: " << item.idx_
// << " par: " << item.par_
// << " pos: " << item.pos_
// << " x: " << item.inset_->x()
// << " y: " << item.inset_->y()
;
return os;
}

88
src/cursor_slice.h Normal file
View File

@ -0,0 +1,88 @@
// -*- C++ -*-
/**
* \file cursor_slice.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#ifndef CURSORSLICE_H
#define CURSORSLICE_H
#include <iosfwd>
#include <cstddef>
class InsetBase;
class UpdatableInset;
class MathInset;
class LyXText;
class MathArray;
/// This encapsulates a single slice of a document iterator as used e.g.
/// for cursors.
// After IU, the distinction of MathInset and UpdatableInset as well as
// that of MathArray and LyXText should vanish. They are conceptually the
// same (now...)
class CursorSlice {
public:
/// type for cell number in inset
typedef size_t idx_type;
/// type for paragraph numbers positions within a cell
typedef size_t par_type;
/// type for cursor positions within a cell
typedef size_t pos_type;
///
CursorSlice();
///
explicit CursorSlice(InsetBase *);
///
/// texted specific stuff
///
///
LyXText * text() const;
///
UpdatableInset * asUpdatableInset() const;
///
/// mathed specific stuff
///
/// returns cell corresponding to this position
MathArray & cell() const;
/// returns cell corresponding to this position
MathArray & cell(idx_type idx) const;
/// gets screen position of the thing
void getPos(int & x, int & y) const;
/// set position
void setPos(int pos);
///
MathInset * asMathInset() const;
///
friend std::ostream & operator<<(std::ostream &, CursorSlice const &);
public:
/// pointer to an inset
InsetBase * inset_;
/// cell index of a position in this inset
idx_type idx_;
/// paragraph in this cell (used by texted)
par_type par_;
/// position in this cell
pos_type pos_;
};
/// test for equality
bool operator==(CursorSlice const &, CursorSlice const &);
/// test for inequality
bool operator!=(CursorSlice const &, CursorSlice const &);
/// test for order
bool operator<(CursorSlice const &, CursorSlice const &);
#endif

View File

@ -1,3 +1,9 @@
2003-12-15 André Pönitz <poenitz@gmx.net>
* insettabular.[Ch]:
* insettext.C: adjust to changed name in CursorItem -> CursorSlice
2003-12-12 Angus Leeming <leeming@lyx.org> 2003-12-12 Angus Leeming <leeming@lyx.org>
* insetbranch.C (c-tor): takes an InsetBranchParams arg rather than * insetbranch.C (c-tor): takes an InsetBranchParams arg rather than

View File

@ -161,7 +161,6 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
tabular.setOwner(this); tabular.setOwner(this);
actrow = 0; actrow = 0;
actcell = 0; actcell = 0;
locked_cell = -1;
clearSelection(); clearSelection();
in_reset_pos = 0; in_reset_pos = 0;
} }
@ -175,7 +174,6 @@ InsetTabular::InsetTabular(InsetTabular const & tab)
actrow = 0; actrow = 0;
actcell = 0; actcell = 0;
clearSelection(); clearSelection();
locked_cell = -1;
in_reset_pos = 0; in_reset_pos = 0;
} }
@ -350,7 +348,7 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
void InsetTabular::drawCellSelection(Painter & pain, int x, int y, void InsetTabular::drawCellSelection(Painter & pain, int x, int y,
int row, int column, int cell) const int row, int column, int cell) const
{ {
if (locked_cell != -1) if (actcell != -1)
return; return;
BOOST_ASSERT(hasSelection()); BOOST_ASSERT(hasSelection());
@ -407,7 +405,7 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl; lyxerr << "# InsetTabular::lfunMousePress cell: " << cell << endl;
if (cell == -1) { if (cell == -1) {
bv->cursor() = theTempCursor; bv->cursor() = theTempCursor;
bv->cursor().data_.push_back(CursorItem(this)); bv->cursor().data_.push_back(CursorSlice(this));
bv->cursor().data_.back().idx_ = cell; bv->cursor().data_.back().idx_ = cell;
} else { } else {
setPos(bv, cmd.x, cmd.y); setPos(bv, cmd.x, cmd.y);
@ -415,7 +413,7 @@ void InsetTabular::lfunMousePress(FuncRequest const & cmd)
bv->cursor() = theTempCursor; bv->cursor() = theTempCursor;
bv->cursor().data_.back().idx_ = cell; bv->cursor().data_.back().idx_ = cell;
} }
locked_cell = cell; actcell = cell;
lyxerr << bv->cursor() << endl; lyxerr << bv->cursor() << endl;
if (cmd.button() == mouse_button::button2) if (cmd.button() == mouse_button::button2)
@ -467,7 +465,6 @@ void InsetTabular::edit(BufferView * bv, bool left)
bv->fitCursor(); bv->fitCursor();
bv->cursor().push(this); bv->cursor().push(this);
bv->cursor().data_.back().idx_ = actcell; bv->cursor().data_.back().idx_ = actcell;
locked_cell = actcell;
lyxerr << bv->cursor() << endl; lyxerr << bv->cursor() << endl;
} }
@ -484,7 +481,7 @@ void InsetTabular::edit(BufferView * bv, int x, int y)
int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell); int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
bv->cursor().push(this); bv->cursor().push(this);
if (x > xx) if (x > xx)
activateCellInset(bv, x - xx, y - cursory_, false); activateCellInset(bv, actcell, x - xx, y - cursory_);
} }
@ -516,40 +513,47 @@ InsetTabular::priv_dispatch(FuncRequest const & cmd,
break; break;
} }
int cell = bv->cursor().data_.back().idx_; int cell = bv->cursor().data_.back().idx_;
if (cell != -1) { if (cell != -1) {
if (cell != actcell) {
lyxerr << "## ERROR ## InsetTabular::priv_dispatch: actcell: "
<< actcell << " and cell " << cell << " should be the same "
<< "here" << endl;
}
lyxerr << "# InsetTabular::dispatch 1: " << cmd << endl; lyxerr << "# InsetTabular::dispatch 1: " << cmd << endl;
result = tabular.getCellInset(cell).dispatch(cmd, idx, pos); result = tabular.getCellInset(cell).dispatch(cmd, idx, pos);
switch (result.val()) { switch (result.val()) {
case LFUN_FINISHED_LEFT: case FINISHED:
lyxerr << "handle LFUN_FINISHED_LEFT, act: " << actcell << endl; lyxerr << "# handle FINISHED_LEFT, act: " << actcell << endl;
if (movePrevCell(bv, false)) if (movePrevCell(bv, false))
result = DispatchResult(true, true); result = DispatchResult(true, true);
else else
result = DispatchResult(false, FINISHED); result = DispatchResult(false, FINISHED);
break; break;
case LFUN_FINISHED_RIGHT: case FINISHED_RIGHT:
lyxerr << "handle LFUN_FINISHED_RIGHT, act: " << actcell << endl; lyxerr << "# handle FINISHED_RIGHT, act: " << actcell << endl;
if (moveNextCell(bv, false)) if (moveNextCell(bv, false))
result = DispatchResult(true, true); result = DispatchResult(true, true);
else else
result = DispatchResult(false, FINISHED_RIGHT); result = DispatchResult(false, FINISHED_RIGHT);
break; break;
case LFUN_FINISHED_UP: case FINISHED_UP:
lyxerr << "handle LFUN_FINISHED_UP, act: " << actcell << endl; lyxerr << "# handle FINISHED_UP, act: " << actcell << endl;
result = moveUp(bv, true); result = moveUp(bv, true);
break; break;
case LFUN_FINISHED_DOWN: case FINISHED_DOWN:
lyxerr << "handle LFUN_FINISHED_DOWN, act: " << actcell << endl; lyxerr << "# handle FINISHED_DOWN, act: " << actcell << endl;
result = moveDown(bv, true); result = moveDown(bv, true);
break; break;
default: default:
lyxerr << "# don't handle dispatch in act: " << actcell << endl;
break; break;
} }
@ -966,12 +970,14 @@ void InsetTabular::calculate_dimensions_of_cells(MetricsInfo & mi) const
void InsetTabular::getCursorPos(int & x, int & y) const void InsetTabular::getCursorPos(int & x, int & y) const
{ {
if (locked_cell == -1) { if (actcell == -1) {
x = TEXT_TO_INSET_OFFSET + cursorx_ - xo_; x = TEXT_TO_INSET_OFFSET + cursorx_ - xo_;
y = TEXT_TO_INSET_OFFSET + cursory_; y = TEXT_TO_INSET_OFFSET + cursory_;
} else { } else {
tabular.getCellInset(locked_cell).getCursorPos(x, y); InsetText const & inset = tabular.getCellInset(actcell);
x = TEXT_TO_INSET_OFFSET; inset.getCursorPos(x, y);
x += inset.x() - xo_;
y += inset.y() - yo_;
} }
} }
@ -1079,7 +1085,7 @@ DispatchResult InsetTabular::moveRight(BufferView * bv, bool lock)
if (!moved) if (!moved)
return DispatchResult(false, FINISHED_RIGHT); return DispatchResult(false, FINISHED_RIGHT);
if (lock) { if (lock) {
activateCellInset(bv, 0, 0, false); activateCellInset(bv, actcell, false);
return DispatchResult(true, true); return DispatchResult(true, true);
} }
resetPos(bv); resetPos(bv);
@ -1094,7 +1100,7 @@ DispatchResult InsetTabular::moveLeft(BufferView * bv, bool lock)
return DispatchResult(false, FINISHED); return DispatchResult(false, FINISHED);
// behind the inset // behind the inset
if (lock) { if (lock) {
activateCellInset(bv, 0, 0, true); activateCellInset(bv, actcell, true);
return DispatchResult(true, true); return DispatchResult(true, true);
} }
resetPos(bv); resetPos(bv);
@ -1110,7 +1116,7 @@ DispatchResult InsetTabular::moveUp(BufferView * bv, bool lock)
return DispatchResult(false, FINISHED_UP); return DispatchResult(false, FINISHED_UP);
resetPos(bv); resetPos(bv);
if (lock) if (lock)
activateCellInset(bv, bv->x_target(), 0, false); activateCellInset(bv, actcell, bv->x_target(), 0);
return DispatchResult(true, true); return DispatchResult(true, true);
} }
@ -1123,13 +1129,14 @@ DispatchResult InsetTabular::moveDown(BufferView * bv, bool lock)
return DispatchResult(false, FINISHED_DOWN); return DispatchResult(false, FINISHED_DOWN);
resetPos(bv); resetPos(bv);
if (lock) if (lock)
activateCellInset(bv, bv->x_target(), 0, false); activateCellInset(bv, actcell, bv->x_target());
return DispatchResult(true, true); return DispatchResult(true, true);
} }
bool InsetTabular::moveNextCell(BufferView * bv, bool lock) bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
{ {
lyxerr << "InsetTabular::moveNextCell 1 actcell: " << actcell << endl;
if (isRightToLeft(bv)) { if (isRightToLeft(bv)) {
if (tabular.isFirstCellInRow(actcell)) { if (tabular.isFirstCellInRow(actcell)) {
int row = tabular.row_of_cell(actcell); int row = tabular.row_of_cell(actcell);
@ -1138,7 +1145,7 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
actcell = tabular.getLastCellInRow(row); actcell = tabular.getLastCellInRow(row);
actcell = tabular.getCellBelow(actcell); actcell = tabular.getCellBelow(actcell);
} else { } else {
if (!actcell) if (actcell == 0)
return false; return false;
--actcell; --actcell;
} }
@ -1147,10 +1154,11 @@ bool InsetTabular::moveNextCell(BufferView * bv, bool lock)
return false; return false;
++actcell; ++actcell;
} }
lyxerr << "InsetTabular::moveNextCell 2 actcell: " << actcell << endl;
if (lock) { if (lock) {
bool rtl = tabular.getCellInset(actcell).paragraphs().begin()-> bool rtl = tabular.getCellInset(actcell).paragraphs().begin()->
isRightToLeftPar(bv->buffer()->params()); isRightToLeftPar(bv->buffer()->params());
activateCellInset(bv, 0, 0, !rtl); activateCellInset(bv, actcell, !rtl);
} }
resetPos(bv); resetPos(bv);
return true; return true;
@ -1183,7 +1191,7 @@ bool InsetTabular::movePrevCell(BufferView * bv, bool lock)
if (lock) { if (lock) {
bool rtl = tabular.getCellInset(actcell).paragraphs().begin()-> bool rtl = tabular.getCellInset(actcell).paragraphs().begin()->
isRightToLeftPar(bv->buffer()->params()); isRightToLeftPar(bv->buffer()->params());
activateCellInset(bv, 0, 0, !rtl); activateCellInset(bv, actcell, !rtl);
} }
lyxerr << "move prevcell 3" << endl; lyxerr << "move prevcell 3" << endl;
resetPos(bv); resetPos(bv);
@ -1569,21 +1577,25 @@ void InsetTabular::tabularFeatures(BufferView * bv,
} }
void InsetTabular::activateCellInset(BufferView * bv, int x, int y, bool behind) void InsetTabular::activateCellInset(BufferView * bv, int cell, int x, int y)
{ {
UpdatableInset & inset = tabular.getCellInset(actcell); actcell = cell;
if (behind) { tabular.getCellInset(actcell).edit(bv, x, y);
#warning metrics?
x = inset.x() + inset.width();
y = inset.descent();
}
inset.edit(bv, x, y);
bv->cursor().data_.back().idx_ = actcell; bv->cursor().data_.back().idx_ = actcell;
locked_cell = actcell;
updateLocal(bv); updateLocal(bv);
} }
void InsetTabular::activateCellInset(BufferView * bv, int cell, bool behind)
{
actcell = cell;
tabular.getCellInset(actcell).edit(bv, behind);
bv->cursor().data_.back().idx_ = actcell;
updateLocal(bv);
}
bool InsetTabular::showInsetDialog(BufferView * bv) const bool InsetTabular::showInsetDialog(BufferView * bv) const
{ {
InsetTabularMailer(*this).showDialog(bv); InsetTabularMailer(*this).showDialog(bv);

View File

@ -207,7 +207,9 @@ private:
has_selection = true; has_selection = true;
} }
/// ///
void activateCellInset(BufferView *, int x, int y, bool behind); void activateCellInset(BufferView *, int cell, int x, int y);
///
void activateCellInset(BufferView *, int cell, bool behind);
/// ///
bool hasPasteBuffer() const; bool hasPasteBuffer() const;
/// ///
@ -237,8 +239,6 @@ private:
mutable int sel_cell_start; mutable int sel_cell_start;
/// the ending cell selection nr /// the ending cell selection nr
mutable int sel_cell_end; mutable int sel_cell_end;
/// -1: no cell, >= 0 cell
mutable int locked_cell;
/// ///
mutable int actcell; mutable int actcell;
/// ///

View File

@ -305,8 +305,8 @@ void InsetText::edit(BufferView * bv, int x, int y)
DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd, DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
idx_type &, pos_type &) idx_type &, pos_type &)
{ {
lyxerr << "InsetText::priv_dispatch (begin), act: " //lyxerr << "InsetText::priv_dispatch (begin), act: "
<< cmd.action << " " << endl; // << cmd.action << " " << endl;
BufferView * bv = cmd.view(); BufferView * bv = cmd.view();
setViewCache(bv); setViewCache(bv);
@ -335,7 +335,7 @@ DispatchResult InsetText::priv_dispatch(FuncRequest const & cmd,
text_.setFont(font, false); text_.setFont(font, false);
} }
lyxerr << "InsetText::priv_dispatch (end)" << endl; //lyxerr << "InsetText::priv_dispatch (end)" << endl;
return result; return result;
} }
@ -388,8 +388,8 @@ void InsetText::validate(LaTeXFeatures & features) const
void InsetText::getCursorPos(int & x, int & y) const void InsetText::getCursorPos(int & x, int & y) const
{ {
x = text_.cursor.x() + TEXT_TO_INSET_OFFSET; x = text_.cursorX() + TEXT_TO_INSET_OFFSET;
y = text_.cursor.y() - dim_.asc + TEXT_TO_INSET_OFFSET; y = text_.cursorY() - dim_.asc + TEXT_TO_INSET_OFFSET;
} }

View File

@ -17,7 +17,7 @@
LyXCursor::LyXCursor() LyXCursor::LyXCursor()
: par_(0), pos_(0), boundary_(false), x_(0), y_(0) : par_(0), pos_(0), boundary_(false)
{} {}
@ -33,9 +33,9 @@ lyx::paroffset_type LyXCursor::par() const
} }
void LyXCursor::pos(lyx::pos_type p) void LyXCursor::pos(lyx::pos_type pos)
{ {
pos_ = p; pos_ = pos;
} }
@ -45,9 +45,9 @@ lyx::pos_type LyXCursor::pos() const
} }
void LyXCursor::boundary(bool b) void LyXCursor::boundary(bool boundary)
{ {
boundary_ = b; boundary_ = boundary;
} }
@ -57,30 +57,6 @@ bool LyXCursor::boundary() const
} }
void LyXCursor::x(int n)
{
x_ = n;
}
int LyXCursor::x() const
{
return x_;
}
void LyXCursor::y(int i)
{
y_ = i;
}
int LyXCursor::y() const
{
return y_;
}
bool operator==(LyXCursor const & a, LyXCursor const & b) bool operator==(LyXCursor const & a, LyXCursor const & b)
{ {
return a.par() == b.par() return a.par() == b.par()

View File

@ -41,14 +41,6 @@ public:
void boundary(bool b); void boundary(bool b);
/// FIXME /// FIXME
bool boundary() const; bool boundary() const;
/// set the x position in pixels
void x(int i);
/// return the x position in pixels
int x() const;
/// set the y position in pixels
void y(int i);
/// return the y position in pixels
int y() const;
private: private:
/// The paragraph the cursor is in. /// The paragraph the cursor is in.
@ -71,10 +63,6 @@ private:
* the user. * the user.
*/ */
bool boundary_; bool boundary_;
/// the pixel x position
int x_;
/// the pixel y position
int y_;
}; };
/// ///

View File

@ -399,6 +399,14 @@ public:
int ascent() const; int ascent() const;
/// ///
int descent() const; int descent() const;
///
int cursorX() const;
///
int cursorY() const;
///
int cursorX(LyXCursor const & cursor) const;
///
int cursorY(LyXCursor const & cursor) const;
public: public:
/// ///
@ -437,10 +445,6 @@ public:
private: private:
/// rebreaks the given par /// rebreaks the given par
void redoParagraphInternal(ParagraphList::iterator pit); void redoParagraphInternal(ParagraphList::iterator pit);
///
float getCursorX(ParagraphList::iterator pit,
Row const & row, lyx::pos_type pos, bool boundary) const;
/// used in setlayout /// used in setlayout
void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par); void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);

View File

@ -1,3 +1,12 @@
2003-12-15 André Pönitz <poenitz@gmx.net>
* math_pos.[Ch]: remove (it's now cursor_slice.[Ch])
* Makefile.am:
* math_cursor.[Ch]:
* math_iterator.[Ch]: adjust
2003-11-21 Michael Schmitt <michael.schmitt@teststep.org> 2003-11-21 Michael Schmitt <michael.schmitt@teststep.org>
* formulabase.C (getCursorDim): squash unused variable * formulabase.C (getCursorDim): squash unused variable

View File

@ -120,8 +120,6 @@ libmathed_la_SOURCES = \
math_parinset.h \ math_parinset.h \
math_parser.C \ math_parser.C \
math_parser.h \ math_parser.h \
math_pos.C \
math_pos.h \
math_replace.h \ math_replace.h \
math_rootinset.C \ math_rootinset.C \
math_rootinset.h \ math_rootinset.h \

View File

@ -69,7 +69,7 @@ MathCursor::~MathCursor()
void MathCursor::push(MathAtom & t) void MathCursor::push(MathAtom & t)
{ {
Cursor_.push_back(CursorPos(t.nucleus())); Cursor_.push_back(CursorSlice(t.nucleus()));
} }
@ -140,7 +140,7 @@ bool MathCursor::popRight()
bool MathCursor::isInside(MathInset const * p) const bool MathCursor::isInside(MathInset const * p) const
{ {
for (unsigned i = 0; i < depth(); ++i) for (unsigned i = 0; i < depth(); ++i)
if (Cursor_[i].inset_ == p) if (Cursor_[i].asMathInset() == p)
return true; return true;
return false; return false;
} }
@ -158,7 +158,7 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const
// we can't move into anything new during selection // we can't move into anything new during selection
if (depth() == Anchor_.size()) if (depth() == Anchor_.size())
return false; return false;
if (t.operator->() != Anchor_[depth()].inset_) if (t.operator->() != Anchor_[depth()].asMathInset())
return false; return false;
} }
return true; return true;
@ -254,7 +254,7 @@ bool positionable
// anchor might be deeper, should have same path then // anchor might be deeper, should have same path then
for (MathIterator::size_type i = 0; i < cursor.size(); ++i) for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
if (cursor[i].inset_ != anchor[i].inset_) if (cursor[i].asMathInset() != anchor[i].asMathInset())
return false; return false;
// position should be ok. // position should be ok.
@ -625,10 +625,10 @@ void MathCursor::drawSelection(PainterInfo & pi) const
{ {
if (!selection_) if (!selection_)
return; return;
CursorPos i1; CursorSlice i1;
CursorPos i2; CursorSlice i2;
getSelection(i1, i2); getSelection(i1, i2);
i1.inset_->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_); i1.asMathInset()->drawSelection(pi, i1.idx_, i1.pos_, i2.idx_, i2.pos_);
} }
@ -659,7 +659,7 @@ int MathCursor::targetX() const
MathInset * MathCursor::inset() const MathInset * MathCursor::inset() const
{ {
return cursor().inset_; return cursor().asMathInset();
} }
@ -741,7 +741,7 @@ bool MathCursor::selection() const
MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
{ {
for (MathInset::difference_type i = depth() - 1; i >= 0; --i) { for (MathInset::difference_type i = depth() - 1; i >= 0; --i) {
MathGridInset * p = Cursor_[i].inset_->asGridInset(); MathGridInset * p = Cursor_[i].asMathInset()->asGridInset();
if (p) { if (p) {
idx = Cursor_[i].idx_; idx = Cursor_[i].idx_;
return p; return p;
@ -753,21 +753,21 @@ MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const
void MathCursor::popToHere(MathInset const * p) void MathCursor::popToHere(MathInset const * p)
{ {
while (depth() && Cursor_.back().inset_ != p) while (depth() && Cursor_.back().asMathInset() != p)
Cursor_.pop_back(); Cursor_.pop_back();
} }
void MathCursor::popToEnclosingGrid() void MathCursor::popToEnclosingGrid()
{ {
while (depth() && !Cursor_.back().inset_->asGridInset()) while (depth() && !Cursor_.back().asMathInset()->asGridInset())
Cursor_.pop_back(); Cursor_.pop_back();
} }
void MathCursor::popToEnclosingHull() void MathCursor::popToEnclosingHull()
{ {
while (depth() && !Cursor_.back().inset_->asHullInset()) while (depth() && !Cursor_.back().asMathInset()->asHullInset())
Cursor_.pop_back(); Cursor_.pop_back();
} }
@ -910,9 +910,9 @@ char MathCursor::halign() const
} }
void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const void MathCursor::getSelection(CursorSlice & i1, CursorSlice & i2) const
{ {
CursorPos anc = normalAnchor(); CursorSlice anc = normalAnchor();
if (anc < cursor()) { if (anc < cursor()) {
i1 = anc; i1 = anc;
i2 = cursor(); i2 = cursor();
@ -923,14 +923,14 @@ void MathCursor::getSelection(CursorPos & i1, CursorPos & i2) const
} }
CursorPos & MathCursor::cursor() CursorSlice & MathCursor::cursor()
{ {
BOOST_ASSERT(depth()); BOOST_ASSERT(depth());
return Cursor_.back(); return Cursor_.back();
} }
CursorPos const & MathCursor::cursor() const CursorSlice const & MathCursor::cursor() const
{ {
BOOST_ASSERT(depth()); BOOST_ASSERT(depth());
return Cursor_.back(); return Cursor_.back();
@ -1312,7 +1312,7 @@ string MathCursor::info() const
ostringstream os; ostringstream os;
os << "Math editor mode. "; os << "Math editor mode. ";
for (int i = 0, n = depth(); i < n; ++i) { for (int i = 0, n = depth(); i < n; ++i) {
Cursor_[i].inset_->infoize(os); Cursor_[i].asMathInset()->infoize(os);
os << " "; os << " ";
} }
if (hasPrevAtom()) if (hasPrevAtom())
@ -1332,11 +1332,11 @@ unsigned MathCursor::depth() const
namespace { namespace {
void region(CursorPos const & i1, CursorPos const & i2, void region(CursorSlice const & i1, CursorSlice const & i2,
MathInset::row_type & r1, MathInset::row_type & r2, MathInset::row_type & r1, MathInset::row_type & r2,
MathInset::col_type & c1, MathInset::col_type & c2) MathInset::col_type & c1, MathInset::col_type & c2)
{ {
MathInset * p = i1.inset_; MathInset * p = i1.asMathInset();
c1 = p->col(i1.idx_); c1 = p->col(i1.idx_);
c2 = p->col(i2.idx_); c2 = p->col(i2.idx_);
if (c1 > c2) if (c1 > c2)
@ -1355,8 +1355,8 @@ string MathCursor::grabSelection() const
if (!selection_) if (!selection_)
return string(); return string();
CursorPos i1; CursorSlice i1;
CursorPos i2; CursorSlice i2;
getSelection(i1, i2); getSelection(i1, i2);
if (i1.idx_ == i2.idx_) { if (i1.idx_ == i2.idx_) {
@ -1375,7 +1375,7 @@ string MathCursor::grabSelection() const
for (col_type col = c1; col <= c2; ++col) { for (col_type col = c1; col <= c2; ++col) {
if (col > c1) if (col > c1)
data += '&'; data += '&';
data += asString(i1.inset_->cell(i1.inset_->index(row, col))); data += asString(i1.asMathInset()->cell(i1.asMathInset()->index(row, col)));
} }
} }
return data; return data;
@ -1384,13 +1384,13 @@ string MathCursor::grabSelection() const
void MathCursor::eraseSelection() void MathCursor::eraseSelection()
{ {
CursorPos i1; CursorSlice i1;
CursorPos i2; CursorSlice i2;
getSelection(i1, i2); getSelection(i1, i2);
if (i1.idx_ == i2.idx_) if (i1.idx_ == i2.idx_)
i1.cell().erase(i1.pos_, i2.pos_); i1.cell().erase(i1.pos_, i2.pos_);
else { else {
MathInset * p = i1.inset_; MathInset * p = i1.asMathInset();
row_type r1, r2; row_type r1, r2;
col_type c1, c2; col_type c1, c2;
region(i1, i2, r1, r2, c1, c2); region(i1, i2, r1, r2, c1, c2);
@ -1413,7 +1413,7 @@ string MathCursor::grabAndEraseSelection()
} }
CursorPos MathCursor::normalAnchor() const CursorSlice MathCursor::normalAnchor() const
{ {
if (Anchor_.size() < depth()) { if (Anchor_.size() < depth()) {
Anchor_ = Cursor_; Anchor_ = Cursor_;
@ -1421,7 +1421,7 @@ CursorPos MathCursor::normalAnchor() const
} }
//lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth()); //lyx::BOOST_ASSERT(Anchor_.size() >= cursor.depth());
// use Anchor on the same level as Cursor // use Anchor on the same level as Cursor
CursorPos normal = Anchor_[depth() - 1]; CursorSlice normal = Anchor_[depth() - 1];
if (depth() < Anchor_.size() && !(normal < cursor())) { if (depth() < Anchor_.size() && !(normal < cursor())) {
// anchor is behind cursor -> move anchor behind the inset // anchor is behind cursor -> move anchor behind the inset
++normal.pos_; ++normal.pos_;
@ -1439,7 +1439,7 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd)
case LFUN_MOUSE_MOTION: case LFUN_MOUSE_MOTION:
case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_RELEASE:
case LFUN_MOUSE_DOUBLE: { case LFUN_MOUSE_DOUBLE: {
CursorPos & pos = Cursor_.back(); CursorSlice & pos = Cursor_.back();
int x = 0; int x = 0;
int y = 0; int y = 0;
getPos(x, y); getPos(x, y);
@ -1461,9 +1461,9 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd)
} }
for (int i = Cursor_.size() - 1; i >= 0; --i) { for (int i = Cursor_.size() - 1; i >= 0; --i) {
CursorPos & pos = Cursor_[i]; CursorSlice & pos = Cursor_[i];
DispatchResult const res = DispatchResult const res =
pos.inset_->dispatch(cmd, pos.idx_, pos.pos_); pos.asMathInset()->dispatch(cmd, pos.idx_, pos.pos_);
if (res.dispatched()) { if (res.dispatched()) {
if (res.val() == FINISHED) { if (res.val() == FINISHED) {
Cursor_.shrink(i + 1); Cursor_.shrink(i + 1);
@ -1479,7 +1479,7 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd)
MathInset::mode_type MathCursor::currentMode() const MathInset::mode_type MathCursor::currentMode() const
{ {
for (int i = Cursor_.size() - 1; i >= 0; --i) { for (int i = Cursor_.size() - 1; i >= 0; --i) {
MathInset::mode_type res = Cursor_[i].inset_->currentMode(); MathInset::mode_type res = Cursor_[i].asMathInset()->currentMode();
if (res != MathInset::UNDECIDED_MODE) if (res != MathInset::UNDECIDED_MODE)
return res; return res;
} }

View File

@ -13,8 +13,8 @@
#ifndef MATH_CURSOR #ifndef MATH_CURSOR
#define MATH_CURSOR #define MATH_CURSOR
#include "math_inset.h" #include "math_inset.h"
#include "math_data.h"
#include "math_iterator.h" #include "math_iterator.h"
#include <string> #include <string>
@ -30,7 +30,7 @@ class MathUnknownInset;
[Have a look at math_inset.h first] [Have a look at math_inset.h first]
The MathCursor is different from the kind of cursor used in the Outer The MathCursor is different from the kind of cursor used in the Outer
World. It contains a stack of CursorPos, each of which is made World. It contains a stack of CursorSlice, each of which is made
up of a inset pointer, an index and a position offset, marking a path from up of a inset pointer, an index and a position offset, marking a path from
this formula's MathHullInset to the current position. this formula's MathHullInset to the current position.
@ -207,14 +207,14 @@ public:
MathAtom & nextAtom(); MathAtom & nextAtom();
/// returns the selection /// returns the selection
void getSelection(CursorPos &, CursorPos &) const; void getSelection(CursorSlice &, CursorSlice &) const;
/// returns the normalized anchor of the selection /// returns the normalized anchor of the selection
CursorPos normalAnchor() const; CursorSlice normalAnchor() const;
/// reference to the last item of the path, i.e. "The Cursor" /// reference to the last item of the path, i.e. "The Cursor"
CursorPos & cursor(); CursorSlice & cursor();
/// reference to the last item of the path, i.e. "The Cursor" /// reference to the last item of the path, i.e. "The Cursor"
CursorPos const & cursor() const; CursorSlice const & cursor() const;
/// how deep are we nested? /// how deep are we nested?
unsigned depth() const; unsigned depth() const;
/// describe the situation /// describe the situation

View File

@ -12,6 +12,7 @@
#include "math_iterator.h" #include "math_iterator.h"
#include "math_inset.h" #include "math_inset.h"
#include "math_data.h"
#include <boost/assert.hpp> #include <boost/assert.hpp>
@ -28,20 +29,20 @@ MathIterator::MathIterator(MathInset * p)
MathInset const * MathIterator::inset() const MathInset const * MathIterator::inset() const
{ {
return back().inset_; return back().asMathInset();
} }
MathInset * MathIterator::inset() MathInset * MathIterator::inset()
{ {
return back().inset_; return back().asMathInset();
} }
MathArray const & MathIterator::cell() const MathArray const & MathIterator::cell() const
{ {
CursorPos const & top = back(); CursorSlice const & top = back();
return top.inset_->cell(top.idx_); return top.asMathInset()->cell(top.idx_);
} }
@ -49,7 +50,7 @@ MathArray const & MathIterator::cell() const
void MathIterator::push(MathInset * p) void MathIterator::push(MathInset * p)
{ {
//lyxerr << "push: " << p << endl; //lyxerr << "push: " << p << endl;
push_back(CursorPos(p)); push_back(CursorSlice(p));
} }
@ -61,13 +62,13 @@ void MathIterator::pop()
} }
CursorPos const & MathIterator::operator*() const CursorSlice const & MathIterator::operator*() const
{ {
return back(); return back();
} }
CursorPos const & MathIterator::operator->() const CursorSlice const & MathIterator::operator->() const
{ {
return back(); return back();
} }
@ -75,16 +76,16 @@ CursorPos const & MathIterator::operator->() const
void MathIterator::goEnd() void MathIterator::goEnd()
{ {
CursorPos & top = back(); CursorSlice & top = back();
top.idx_ = top.inset_->nargs() - 1; top.idx_ = top.asMathInset()->nargs() - 1;
top.pos_ = cell().size(); top.pos_ = cell().size();
} }
void MathIterator::operator++() void MathIterator::operator++()
{ {
CursorPos & top = back(); CursorSlice & top = back();
MathArray & ar = top.inset_->cell(top.idx_); MathArray & ar = top.asMathInset()->cell(top.idx_);
// move into the current inset if possible // move into the current inset if possible
// it is impossible for pos() == size()! // it is impossible for pos() == size()!
@ -104,10 +105,10 @@ void MathIterator::operator++()
} }
// otherwise try to move on one cell if possible // otherwise try to move on one cell if possible
while (top.idx_ + 1 < top.inset_->nargs()) { while (top.idx_ + 1 < top.asMathInset()->nargs()) {
// idx() == nargs() is _not_ valid! // idx() == nargs() is _not_ valid!
++top.idx_; ++top.idx_;
if (top.inset_->validCell(top.idx_)) { if (top.asMathInset()->validCell(top.idx_)) {
top.pos_ = 0; top.pos_ = 0;
return; return;
} }

View File

@ -12,17 +12,17 @@
#ifndef MATH_ITERATOR_H #ifndef MATH_ITERATOR_H
#define MATH_ITERATOR_H #define MATH_ITERATOR_H
#include "math_pos.h" #include "cursor_slice.h"
#include <vector> #include <vector>
// this is used for traversing math insets // this is used for traversing math insets
class MathIterator : private std::vector<CursorPos> { class MathIterator : private std::vector<CursorSlice> {
public: public:
// re-use inherited stuff // re-use inherited stuff
typedef std::vector<CursorPos> base_type; typedef std::vector<CursorSlice> base_type;
using base_type::clear; using base_type::clear;
using base_type::size; using base_type::size;
using base_type::push_back; using base_type::push_back;
@ -43,9 +43,9 @@ public:
/// start with given inset /// start with given inset
explicit MathIterator(MathInset * p); explicit MathIterator(MathInset * p);
/// ///
CursorPos const & operator*() const; CursorSlice const & operator*() const;
/// ///
CursorPos const & operator->() const; CursorSlice const & operator->() const;
/// move on one step /// move on one step
void operator++(); void operator++();
/// move on several steps /// move on several steps

View File

@ -1,90 +0,0 @@
/**
* \file math_pos.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "math_pos.h"
#include "math_inset.h"
#include "debug.h"
#include <boost/assert.hpp>
using std::endl;
CursorPos::CursorPos()
: inset_(0), idx_(0), pos_(0)
{}
CursorPos::CursorPos(MathInset * p)
: inset_(p), idx_(0), pos_(0)
{
BOOST_ASSERT(inset_);
}
MathArray & CursorPos::cell(MathArray::idx_type idx) const
{
BOOST_ASSERT(inset_);
return inset_->cell(idx);
}
MathArray & CursorPos::cell() const
{
BOOST_ASSERT(inset_);
return inset_->cell(idx_);
}
void CursorPos::getPos(int & x, int & y) const
{
inset_->getPos(idx_, pos_, x, y);
}
void CursorPos::setPos(MathArray::pos_type pos)
{
pos_ = pos;
}
std::ostream & operator<<(std::ostream & os, CursorPos const & p)
{
os << "(par: " << p.inset_ << " idx: " << p.idx_ << " pos: " << p.pos_ << ')';
return os;
}
bool operator==(CursorPos const & p, CursorPos const & q)
{
return p.inset_ == q.inset_ && p.idx_ == q.idx_ && p.pos_ == q.pos_;
}
bool operator!=(CursorPos const & p, CursorPos const & q)
{
return p.inset_ != q.inset_ || p.idx_ != q.idx_ || p.pos_ != q.pos_;
}
bool operator<(CursorPos const & p, CursorPos const & q)
{
if (p.inset_ != q.inset_) {
lyxerr << "can't compare cursor and anchor in different insets\n"
<< "p: " << p << '\n' << "q: " << q << endl;
return true;
}
if (p.idx_ != q.idx_)
return p.idx_ < q.idx_;
return p.pos_ < q.pos_;
}

View File

@ -1,55 +0,0 @@
// -*- C++ -*-
/**
* \file math_pos.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author André Pönitz
*
* Full author contact details are available in file CREDITS.
*/
#ifndef MATH_POS_H
#define MATH_POS_H
#include <iosfwd>
#include "math_data.h"
/// Description of a position
class CursorPos {
public:
///
CursorPos();
///
explicit CursorPos(MathInset *);
/// returns cell corresponding to this position
MathArray & cell() const;
/// returns cell corresponding to this position
MathArray & cell(MathArray::idx_type idx) const;
/// gets screen position of the thing
void getPos(int & x, int & y) const;
/// set position
void setPos(MathArray::pos_type pos);
public:
/// pointer to an inset
MathInset * inset_;
/// cell index of a position in this inset
MathArray::idx_type idx_;
/// position in this cell
MathArray::pos_type pos_;
};
/// test for equality
bool operator==(CursorPos const &, CursorPos const &);
/// test for inequality
bool operator!=(CursorPos const &, CursorPos const &);
/// test for order
bool operator<(CursorPos const &, CursorPos const &);
/// output
std::ostream & operator<<(std::ostream &, CursorPos const &);
#endif

View File

@ -391,10 +391,10 @@ void RowPainter::paintSelection()
bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params()); bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
// the current selection // the current selection
int const startx = text_.selStart().x(); int const startx = text_.cursorX(text_.selStart());
int const endx = text_.selEnd().x(); int const endx = text_.cursorX(text_.selEnd());
int const starty = text_.selStart().y(); int const starty = text_.cursorY(text_.selStart());
int const endy = text_.selEnd().y(); int const endy = text_.cursorY(text_.selEnd());
ParagraphList::iterator startpit = text_.getPar(text_.selStart()); ParagraphList::iterator startpit = text_.getPar(text_.selStart());
ParagraphList::iterator endpit = text_.getPar(text_.selEnd()); ParagraphList::iterator endpit = text_.getPar(text_.selEnd());
RowList::iterator startrow = startpit->getRow(text_.selStart().pos()); RowList::iterator startrow = startpit->getRow(text_.selStart().pos());
@ -888,7 +888,7 @@ int paintText(BufferView const & bv)
} }
void paintTextInset(BufferView const & bv, LyXText const & text, int xo, int yo) void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo)
{ {
paintPars(bv, text, text.paragraphs().begin(), xo, yo, 0); paintPars(*pi.base.bv, text, text.paragraphs().begin(), xo, yo, 0);
} }

View File

@ -15,11 +15,12 @@
class LyXText; class LyXText;
class BufferView; class BufferView;
class PainterInfo;
/// paint the rows of the main text, return last drawn y value /// paint the rows of the main text, return last drawn y value
int paintText(BufferView const & bv); int paintText(BufferView const & bv);
/// paint the rows of a text inset /// paint the rows of a text inset
void paintTextInset(BufferView const & bv, LyXText const & text, int x, int y); void paintTextInset(LyXText const & text, PainterInfo & pi, int x, int y);
#endif // ROWPAINTER_H #endif // ROWPAINTER_H

View File

@ -1628,11 +1628,11 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
// only used for inset right now. should also be used for main text // only used for inset right now. should also be used for main text
void LyXText::draw(PainterInfo &, int x, int y) const void LyXText::draw(PainterInfo & pi, int x, int y) const
{ {
xo_ = x; xo_ = x;
yo_ = y; yo_ = y;
paintTextInset(*bv(), *this, x, y); paintTextInset(*this, pi, x, y);
} }
@ -1855,3 +1855,82 @@ int LyXText::descent() const
return height - firstRow()->ascent_of_text(); return height - firstRow()->ascent_of_text();
} }
int LyXText::cursorX() const
{
return cursorX(cursor);
}
int LyXText::cursorY() const
{
return cursorY(cursor);
}
int LyXText::cursorX(LyXCursor const & cur) const
{
ParagraphList::iterator pit = getPar(cur);
Row const & row = *pit->getRow(cur.pos());
pos_type pos = cur.pos();
pos_type cursor_vpos = 0;
double x = row.x();
double fill_separator = row.fill_separator();
double fill_hfill = row.fill_hfill();
double fill_label_hfill = row.fill_label_hfill();
pos_type const row_pos = row.pos();
pos_type const end = row.endpos();
if (end <= row_pos)
cursor_vpos = row_pos;
else if (pos >= end)
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
? row_pos : end;
else if (pos > row_pos && pos >= end)
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
else
// Place cursor before char at (logical) position pos
cursor_vpos = (bidi.level(pos) % 2 == 0)
? bidi.log2vis(pos) : bidi.log2vis(pos) + 1;
pos_type body_pos = pit->beginOfBody();
if (body_pos > 0 &&
(body_pos > end || !pit->isLineSeparator(body_pos - 1)))
body_pos = 0;
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill
+ font_metrics::width(pit->layout()->labelsep,
getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1);
}
if (hfillExpansion(*pit, row, pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
x += fill_hfill;
else
x += fill_label_hfill;
} else if (pit->isSeparator(pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
x += fill_separator;
} else
x += singleWidth(pit, pos);
}
return int(x);
}
int LyXText::cursorY(LyXCursor const & cur) const
{
Paragraph & par = *getPar(cur);
Row & row = *par.getRow(cur.pos());
return par.y + row.y_offset() + row.baseline();
}

View File

@ -1198,14 +1198,6 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
ParagraphList::iterator pit = getPar(par); ParagraphList::iterator pit = getPar(par);
Row const & row = *pit->getRow(pos); Row const & row = *pit->getRow(pos);
int y = pit->y + row.y_offset();
// y is now the beginning of the cursor row
y += row.baseline();
// y is now the cursor baseline
cur.y(y);
pos_type const end = row.endpos(); pos_type const end = row.endpos();
// None of these should happen, but we're scaredy-cats // None of these should happen, but we're scaredy-cats
@ -1237,65 +1229,6 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
cur.pos(pos); cur.pos(pos);
BOOST_ASSERT(false); BOOST_ASSERT(false);
} }
// now get the cursors x position
cur.x(int(getCursorX(pit, row, pos, boundary)));
}
float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
pos_type pos, bool boundary) const
{
pos_type cursor_vpos = 0;
double x = row.x();
double fill_separator = row.fill_separator();
double fill_hfill = row.fill_hfill();
double fill_label_hfill = row.fill_label_hfill();
pos_type const row_pos = row.pos();
pos_type const end = row.endpos();
if (end <= row_pos)
cursor_vpos = row_pos;
else if (pos >= end && !boundary)
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
? row_pos : end;
else if (pos > row_pos && (pos >= end || boundary))
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
else
// Place cursor before char at (logical) position pos
cursor_vpos = (bidi.level(pos) % 2 == 0)
? bidi.log2vis(pos) : bidi.log2vis(pos) + 1;
pos_type body_pos = pit->beginOfBody();
if (body_pos > 0 &&
(body_pos > end || !pit->isLineSeparator(body_pos - 1)))
body_pos = 0;
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
x += fill_label_hfill
+ font_metrics::width(pit->layout()->labelsep,
getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1);
}
if (hfillExpansion(*pit, row, pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
x += fill_hfill;
else
x += fill_label_hfill;
} else if (pit->isSeparator(pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
x += fill_separator;
} else
x += singleWidth(pit, pos);
}
return x;
} }
@ -1303,7 +1236,7 @@ void LyXText::setCursorIntern(paroffset_type par,
pos_type pos, bool setfont, bool boundary) pos_type pos, bool setfont, bool boundary)
{ {
setCursor(cursor, par, pos, boundary); setCursor(cursor, par, pos, boundary);
bv()->x_target(cursor.x() + xo_); bv()->x_target(cursorX() + xo_);
if (setfont) if (setfont)
setCurrentFont(); setCurrentFont();
} }
@ -1460,21 +1393,16 @@ void LyXText::setCursorFromCoordinates(int x, int y)
deleteEmptyParagraphMechanism(old_cursor); deleteEmptyParagraphMechanism(old_cursor);
} }
// x,y are coordinates relative to this LyXText // x,y are coordinates relative to this LyXText
void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y) void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
{ {
// Get the row first.
ParagraphList::iterator pit; ParagraphList::iterator pit;
Row const & row = *getRowNearY(y, pit); Row const & row = *getRowNearY(y, pit);
y = pit->y + row.y_offset();
bool bound = false; bool bound = false;
pos_type const column = getColumnNearX(pit, row, x, bound); pos_type const column = getColumnNearX(pit, row, x, bound);
cur.par(parOffset(pit)); cur.par(parOffset(pit));
cur.pos(row.pos() + column); cur.pos(row.pos() + column);
cur.x(x);
cur.y(y + row.baseline());
cur.boundary(bound); cur.boundary(bound);
} }
@ -1607,7 +1535,7 @@ void LyXText::cursorUp(bool selecting)
{ {
Row const & row = *cursorRow(); Row const & row = *cursorRow();
int x = bv()->x_target() - xo_; int x = bv()->x_target() - xo_;
int y = cursor.y() - row.baseline() - 1; int y = cursorY() - row.baseline() - 1;
setCursorFromCoordinates(x, y); setCursorFromCoordinates(x, y);
if (!selecting) { if (!selecting) {
@ -1623,7 +1551,7 @@ void LyXText::cursorDown(bool selecting)
{ {
Row const & row = *cursorRow(); Row const & row = *cursorRow();
int x = bv()->x_target() - xo_; int x = bv()->x_target() - xo_;
int y = cursor.y() - row.baseline() + row.height() + 1; int y = cursorY() - row.baseline() + row.height() + 1;
setCursorFromCoordinates(x, y); setCursorFromCoordinates(x, y);
if (!selecting) { if (!selecting) {

View File

@ -1015,7 +1015,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
break; break;
case LFUN_GETXY: case LFUN_GETXY:
cmd.message(tostr(cursor.x()) + ' ' + tostr(cursor.y())); cmd.message(tostr(cursorX()) + ' ' + tostr(cursorY()));
break; break;
case LFUN_SETXY: { case LFUN_SETXY: {
@ -1274,7 +1274,7 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
setCursorFromCoordinates(cmd.x, cmd.y); setCursorFromCoordinates(cmd.x, cmd.y);
selection.cursor = cursor; selection.cursor = cursor;
finishUndo(); finishUndo();
bv->x_target(cursor.x() + xo_); bv->x_target(cursorX() + xo_);
if (bv->fitCursor()) if (bv->fitCursor())
selection_possible = false; selection_possible = false;