more IU stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8430 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-02-13 11:05:29 +00:00
parent fcc89010ec
commit 2288d17247
21 changed files with 368 additions and 382 deletions

View File

@ -297,9 +297,9 @@ void BufferView::setCursorFromRow(int row)
buffer()->texrow().getIdFromRow(row, tmpid, tmppos);
if (tmpid == -1)
text()->setCursor(0, 0);
text()->setCursor(cursor(), 0, 0);
else
text()->setCursor(
text()->setCursor(cursor(),
text()->parOffset(buffer()->getParFromID(tmpid).pit()),
tmppos);
}
@ -313,7 +313,7 @@ void BufferView::gotoLabel(string const & label)
it->getLabelList(*buffer(), labels);
if (find(labels.begin(),labels.end(),label) != labels.end()) {
cursor().clearSelection();
text()->setCursor(
text()->setCursor(cursor(),
distance(text()->paragraphs().begin(), it.getPar()),
it.getPos());
cursor().resetAnchor();
@ -330,19 +330,6 @@ void BufferView::hideCursor()
}
bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
{
// Check if the label 'from' appears more than once
vector<string> labels;
buffer()->getLabelList(labels);
if (lyx::count(labels.begin(), labels.end(), from) > 1)
return false;
return pimpl_->ChangeInsets(InsetOld::REF_CODE, from, to);
}
LyXText * BufferView::getLyXText() const
{
return cursor().innerText();
@ -399,7 +386,7 @@ void BufferView::setCursor(ParIterator const & par,
(*positions[i].it)->inset->edit(cur, true);
cur.resetAnchor();
LyXText * lt = par.text(*buffer());
lt->setCursor(lt->parOffset(par.pit()), pos);
lt->setCursor(cur, lt->parOffset(par.pit()), pos);
}
@ -431,7 +418,7 @@ void BufferView::putSelectionAt(PosIterator const & cur,
if (par.inset())
top_y(par.outerPar()->y);
update();
text->setCursor(text->parOffset(cur.pit()), cur.pos());
text->setCursor(cursor(), text->parOffset(cur.pit()), cur.pos());
cursor().updatePos();
if (length) {

View File

@ -154,9 +154,6 @@ public:
/// switch between primary and secondary keymaps for RTL entry
void switchKeyMap();
/// FIXME
bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
/// get the contents of the window system clipboard
std::string const getClipboard() const;
/// fill the window system clipboard

View File

@ -77,6 +77,7 @@ using lyx::support::strToUnsignedInt;
using lyx::support::system_lyxdir;
using std::endl;
using std::istringstream;
using std::make_pair;
using std::min;
using std::string;
@ -413,13 +414,13 @@ void BufferView::Pimpl::resizeCurrentBuffer()
// Mechanism when setting the cursor.
cur.mark() = mark_set;
if (sel) {
text->setCursor(selstartpar, selstartpos);
text->setCursor(cur, selstartpar, selstartpos);
cur.resetAnchor();
text->setCursor(selendpar, selendpos);
text->setCursor(cur, selendpar, selendpos);
cur.setSelection();
text->setCursor(par, pos);
text->setCursor(cur, par, pos);
} else {
text->setCursor(par, pos);
text->setCursor(cur, par, pos);
cur.resetAnchor();
cur.selection() = false;
}
@ -474,11 +475,12 @@ void BufferView::Pimpl::scrollDocView(int value)
int const last = top_y() + workarea().workHeight() - height;
LyXText * text = bv_->text();
int y = text->cursorY(bv_->cursor().cursor_.front());
CursorSlice & cur = bv_->cursor().cursor_.front();
int y = text->cursorY(cur);
if (y < first)
text->setCursorFromCoordinates(0, first);
text->setCursorFromCoordinates(cur, 0, first);
else if (y > last)
text->setCursorFromCoordinates(0, last);
text->setCursorFromCoordinates(cur, 0, last);
owner_->updateLayoutChoice();
}
@ -681,8 +683,10 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
if (par == buffer_->par_iterator_end())
return;
bv_->text()->setCursor(bv_->text()->parOffset(par.pit()),
min(par->size(), saved_positions[i].par_pos));
bv_->text()->setCursor(
bv_->cursor(),
bv_->text()->parOffset(par.pit()),
min(par->size(), saved_positions[i].par_pos));
if (i > 0)
owner_->message(bformat(_("Moved to bookmark %1$s"), tostr(i)));
@ -742,31 +746,28 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const
InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
{
#warning Does not work for mathed
// Ok, this is a little bit too brute force but it
// should work for now. Better infrastructure is coming. (Lgb)
Buffer * b = bv_->buffer();
LyXText * text = bv_->getLyXText();
Buffer::inset_iterator beg = b->inset_iterator_begin();
Buffer::inset_iterator end = b->inset_iterator_end();
Buffer * buf = bv_->buffer();
Buffer::inset_iterator beg = buf->inset_iterator_begin();
Buffer::inset_iterator end = buf->inset_iterator_end();
bool cursor_par_seen = false;
for (; beg != end; ++beg) {
if (beg.getPar() == text->cursorPar()) {
cursor_par_seen = true;
}
if (cursor_par_seen) {
if (beg.getPar() == text->cursorPar()
&& beg.getPos() >= text->cursor().pos()) {
break;
}
if (beg.getPar() != text->cursorPar()) {
break;
}
}
LCursor & cur = bv_->cursor();
ParagraphList::iterator pit = bv_->getLyXText()->getPar(cur.par());
for (; beg != end; ++beg) {
if (beg.getPar() == pit)
cursor_par_seen = true;
if (cursor_par_seen) {
if (beg.getPar() == pit && beg.getPos() >= cur.pos())
break;
if (beg.getPar() != pit)
break;
}
}
if (beg != end) {
// Now find the first inset that matches code.
@ -836,7 +837,7 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm)
void BufferView::Pimpl::trackChanges()
{
Buffer * buf = bv_->buffer();
bool const tracking(buf->params().tracking_changes);
bool const tracking = buf->params().tracking_changes;
if (!tracking) {
ParIterator const end = buf->par_iterator_end();
@ -848,7 +849,7 @@ void BufferView::Pimpl::trackChanges()
buf->undostack().clear();
} else {
update();
bv_->text()->setCursor(0, 0);
bv_->text()->setCursor(bv_->cursor(), 0, 0);
#warning changes FIXME
bool found = lyx::find::findNextChange(bv_);
if (found) {
@ -929,10 +930,18 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
text->setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
lyxerr << "created temp cursor: " << cur << endl;
// Try to dispatch to an non-editable inset near this position
DispatchResult res;
InsetBase * inset = cur.nextInset();
lyxerr << "next inset: " << inset << endl;
if (inset)
res = inset->dispatch(cur, cmd);
// Dispatch to the temp cursor.
// An inset (or LyXText) can assign this to bv->cursor()
// if it wishes to do so.
DispatchResult res = cur.dispatch(cmd);
if (!res.dispatched())
res = cur.dispatch(cmd);
if (fitCursor() || res.update())
update();
@ -1049,10 +1058,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
break;
}
case LFUN_PARAGRAPH_APPLY:
setParagraphParams(*bv_, cmd.argument);
break;
case LFUN_TRACK_CHANGES:
trackChanges();
break;
@ -1124,41 +1129,3 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
return true;
}
bool BufferView::Pimpl::ChangeInsets(InsetBase::Code code,
string const & from, string const & to)
{
bool need_update = false;
CursorSlice cur = bv_->text()->cursor();
ParIterator end = bv_->buffer()->par_iterator_end();
for (ParIterator it = bv_->buffer()->par_iterator_begin();
it != end; ++it) {
bool changed_inset = false;
for (InsetList::iterator it2 = it->insetlist.begin();
it2 != it->insetlist.end(); ++it2) {
if (it2->inset->lyxCode() == code) {
InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
if (inset->getContents() == from) {
inset->setContents(to);
changed_inset = true;
}
}
}
if (changed_inset) {
need_update = true;
// FIXME
// The test it.size() == 1 was needed to prevent crashes.
// How to set the cursor correctly when it.size() > 1 ??
if (it.size() == 1) {
bv_->text()->setCursorIntern(bv_->text()->parOffset(it.pit()), 0);
bv_->text()->redoParagraph(bv_->text()->cursorPar());
}
}
}
bv_->text()->setCursorIntern(cur.par(), cur.pos());
return need_update;
}

View File

@ -139,13 +139,6 @@ private:
/// notify readonly status
void showReadonly(bool);
/**
* Change all insets with the given code's contents to a new
* string. May only be used with InsetCommand-derived insets
* Returns true if a screen update is needed.
*/
bool ChangeInsets(InsetBase::Code code, std::string const & from,
std::string const & to);
///
friend class BufferView;

View File

@ -296,27 +296,6 @@ void ParagraphParameters::write(ostream & os) const
}
void setParagraphParams(BufferView & bv, string const & data)
{
istringstream is(data);
LyXLex lex(0,0);
lex.setStream(is);
ParagraphParameters params;
params.read(lex);
LyXText * text = bv.getLyXText();
text->setParagraph(
params.spacing(),
params.align(),
params.labelWidthString(),
params.noindent());
bv.update();
bv.owner()->message(_("Paragraph layout set"));
}
void params2string(Paragraph const & par, string & data)
{
// A local copy

View File

@ -29,6 +29,7 @@ class Paragraph;
class ParameterStruct;
class Spacing;
///
class ParagraphParameters {
public:
@ -99,10 +100,4 @@ private:
*/
void params2string(Paragraph const & par, std::string & data);
/** Given \param data, an encoding of the ParagraphParameters generated
in the Paragraph dialog, this function sets the current paragraph
appropriately.
*/
void setParagraphParams(BufferView & bv, std::string const & data);
#endif

View File

@ -16,24 +16,19 @@
#include <string>
class BufferView;
class LCursor;
class LyXFont;
class LyXText;
class PosIterator;
namespace bv_funcs {
/** Set \param data using \param font and \param toggle.
* If successful, returns true.
*/
/// Set \param data using \param font and \param toggle. Return success.
bool font2string(LyXFont const & font, bool toggle, std::string & data);
/** Set \param font and \param toggle using \param data.
* If successful, returns true.
*/
/// Set \param font and \param toggle using \param data. Return success.
bool string2font(std::string const & data, LyXFont & font, bool & toggle);
/** Returns the current freefont, encoded as a std::string to be passed to the
* frontends.
*/
@ -49,6 +44,6 @@ enum DEPTH_CHANGE {
/// Returns whether something would be changed by changeDepth
bool changeDepthAllowed(LCursor & cur, LyXText * text, DEPTH_CHANGE);
}; // namespace bv_funcs
} // namespace bv_funcs
#endif

View File

@ -1932,3 +1932,8 @@ void LCursor::replaceWord(string const & replacestring)
t->cursorLeft(*this, true);
}
void LCursor::update()
{
bv().update();
}

View File

@ -287,6 +287,8 @@ public:
void reset();
/// for spellchecking
void replaceWord(std::string const & replacestring);
/// update our view
void update();
/// output
friend std::ostream & operator<<(std::ostream & os, LCursor const & cur);

View File

@ -236,7 +236,7 @@ std::ostream & operator<<(std::ostream & os, CursorSlice const & item)
os << "inset: " << item.inset_
<< " text: " << item.text()
<< " idx: " << item.idx_
// << " par: " << item.par_
<< " par: " << item.par_
<< " pos: " << item.pos_
// << " x: " << item.inset_->x()
// << " y: " << item.inset_->y()

View File

@ -205,9 +205,7 @@ DispatchResult
InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest const & cmd)
{
if (cmd.button() == mouse_button::button3) {
lyxerr << "InsetCollapsable::lfunMouseRelease 0" << endl;
showInsetDialog(&cur.bv());
return DispatchResult(true, true);
}
switch (status_) {
@ -331,16 +329,14 @@ InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_MOUSE_PRESS:
if (status_ == Inlined)
inset.dispatch(cur, cmd);
else if (status_ == Open
&& cmd.y > button_dim.y2)
else if (status_ == Open && cmd.y > button_dim.y2)
inset.dispatch(cur, cmd);
return DispatchResult(true, true);
case LFUN_MOUSE_MOTION:
if (status_ == Inlined)
inset.dispatch(cur, cmd);
else if (status_ == Open
&& cmd.y > button_dim.y2)
else if (status_ == Open && cmd.y > button_dim.y2)
inset.dispatch(cur, cmd);
return DispatchResult(true, true);

View File

@ -85,7 +85,7 @@ public:
///
void setLabel(std::string const & l);
///
virtual void setButtonLabel() {};
virtual void setButtonLabel() {}
///
void setLabelFont(LyXFont & f);
/// Appends \c list with all labels found within this inset.

View File

@ -12,20 +12,26 @@
#include "insetlabel.h"
#include "buffer.h"
#include "BufferView.h"
#include "dispatchresult.h"
#include "funcrequest.h"
#include "InsetList.h"
#include "iterators.h"
#include "lyxtext.h"
#include "paragraph.h"
#include "frontends/LyXView.h"
#include "support/lstrings.h"
#include "support/lyxalgo.h"
#include "support/std_ostream.h"
using lyx::support::escape;
using std::string;
using std::ostream;
using std::vector;
InsetLabel::InsetLabel(InsetCommandParams const & p)
@ -51,6 +57,40 @@ string const InsetLabel::getScreenLabel(Buffer const &) const
}
namespace {
void changeRefsIfUnique(BufferView & bv, string const & from, string const & to)
{
// Check if the label 'from' appears more than once
vector<string> labels;
bv.buffer()->getLabelList(labels);
if (lyx::count(labels.begin(), labels.end(), from) > 1)
return;
InsetBase::Code code = InsetBase::REF_CODE;
ParIterator it = bv.buffer()->par_iterator_begin();
ParIterator end = bv.buffer()->par_iterator_end();
for ( ; it != end; ++it) {
bool changed_inset = false;
for (InsetList::iterator it2 = it->insetlist.begin();
it2 != it->insetlist.end(); ++it2) {
if (it2->inset->lyxCode() == code) {
InsetCommand * inset = static_cast<InsetCommand *>(it2->inset);
if (inset->getContents() == from) {
inset->setContents(to);
//inset->setButtonLabel();
changed_inset = true;
}
}
}
}
}
} // namespace anon
DispatchResult
InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
@ -61,12 +101,10 @@ InsetLabel::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
InsetCommandMailer::string2params("label", cmd.argument, p);
if (p.getCmdName().empty())
return DispatchResult(false);
bool clean = true;
if (p.getContents() != params().getContents())
clean = cur.bv().ChangeRefsIfUnique(params().getContents(),
changeRefsIfUnique(cur.bv(), params().getContents(),
p.getContents());
setParams(p);
cur.bv().update();
return DispatchResult(true, true);
}

View File

@ -40,8 +40,7 @@ InsetRef::InsetRef(InsetRef const & ir)
{}
DispatchResult
InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
DispatchResult InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
{
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
@ -52,6 +51,9 @@ InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
InsetCommandMailer("ref", *this).showDialog(&cur.bv());
return DispatchResult(true, true);
case LFUN_MOUSE_RELEASE:
return DispatchResult(true, true);
default:
return InsetCommand::priv_dispatch(cur, cmd);
}
@ -61,15 +63,15 @@ InsetRef::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
string const InsetRef::getScreenLabel(Buffer const &) const
{
string temp;
for (int i = 0; !types[i].latex_name.empty(); ++ i)
for (int i = 0; !types[i].latex_name.empty(); ++i) {
if (getCmdName() == types[i].latex_name) {
temp = _(types[i].short_gui_name);
break;
}
}
temp += getContents();
if (!isLatex
&& !getOptions().empty()) {
if (!isLatex && !getOptions().empty()) {
temp += "||";
temp += getOptions();
}

View File

@ -12,13 +12,10 @@
#ifndef INSET_REF_H
#define INSET_REF_H
#include "insetcommand.h"
struct LaTeXFeatures;
/** The reference inset
*/
/// The reference inset
class InsetRef : public InsetCommand {
public:
struct type_info {
@ -68,9 +65,7 @@ public:
void validate(LaTeXFeatures & features) const;
protected:
///
virtual
DispatchResult
priv_dispatch(LCursor & cur, FuncRequest const & cmd);
DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
private:
///
bool isLatex;

View File

@ -398,7 +398,7 @@ void InsetTabular::lfunMousePress(LCursor & cur, FuncRequest const & cmd)
cur.idx() = cell;
} else {
tablemode = false;
setPos(cur.bv(), cmd.x, cmd.y);
setPos(cur, cmd.x, cmd.y);
//cur.cursor_ = theTempCursor;
cur.idx() = cell;
}
@ -415,7 +415,7 @@ void InsetTabular::lfunMouseMotion(LCursor & cur, FuncRequest const & cmd)
int const actcell = getCell(cmd.x + xo_, cmd.y + yo_);
lyxerr << "# InsetTabular::lfunMouseMotion cell: " << actcell << endl;
setPos(cur.bv(), cmd.x, cmd.y);
setPos(cur, cmd.x, cmd.y);
if (!hasSelection()) {
setSelection(actcell, actcell);
cur.setSelection();
@ -467,7 +467,7 @@ void InsetTabular::edit(LCursor & cur, int x, int y)
<< &tabular.cell_info[0][0].inset << endl;
finishUndo();
setPos(cur.bv(), x, y);
setPos(cur, x, y);
clearSelection();
finishUndo();
//int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
@ -972,14 +972,12 @@ void InsetTabular::getCursorPos(CursorSlice const & cur, int & x, int & y) const
}
void InsetTabular::setPos(BufferView & bv, int x, int y) const
void InsetTabular::setPos(LCursor & cur, int x, int y) const
{
lyxerr << "# InsetTabular::setPos() cursor: " << bv.cursor() << endl;
//lyxerr << "# InsetTabular::setPos() cursor: " << cur << endl;
int const cell = getCell(x + xo_, y + yo_);
lyxerr << "# InsetTabular::setPos() cell: " << cell << endl;
InsetText const & inset = tabular.getCellInset(cell);
inset.text_.setCursorFromCoordinates(x, y);
#if 0
inset.text_.setCursorFromCoordinates(cur.current(), x, y);
cursory_ = 0;
int actcell = 0;
int actrow = 0;
@ -1005,8 +1003,7 @@ void InsetTabular::setPos(BufferView & bv, int x, int y) const
+ tabular.getAdditionalWidth(actcell);
cursorx_ = lx - tabular.getWidthOfColumn(actcell) + xo_ + 2;
#endif
resetPos(bv.cursor());
resetPos(cur);
}
@ -1024,7 +1021,7 @@ int InsetTabular::getCellXPos(int cell) const
}
void InsetTabular::resetPos(LCursor &) const
void InsetTabular::resetPos(LCursor & cur) const
{
#if 0
#ifdef WITH_WARNINGS

View File

@ -179,7 +179,7 @@ private:
void drawCellSelection(Painter &, int x, int baseline,
int row, int column, int cell) const;
///
void setPos(BufferView &, int x, int y) const;
void setPos(LCursor & cur, int x, int y) const;
///
bool moveRight(LCursor & cur);
///

View File

@ -48,6 +48,11 @@ class VSpace;
/// This class encapsulates the main text data and operations in LyX
class LyXText {
public:
///
typedef lyx::pos_type pos_type;
///
typedef lyx::paroffset_type par_type;
/// constructor
LyXText(BufferView *, bool ininset);
///
@ -56,17 +61,16 @@ public:
/// update y coordinate cache of all paragraphs
void updateParPositions();
///
LyXFont getFont(ParagraphList::iterator pit, lyx::pos_type pos) const;
LyXFont getFont(ParagraphList::iterator pit, pos_type pos) const;
///
LyXFont getLayoutFont(ParagraphList::iterator pit) const;
///
LyXFont getLabelFont(ParagraphList::iterator pit) const;
///
void setCharFont(ParagraphList::iterator pit,
lyx::pos_type pos, LyXFont const & font);
pos_type pos, LyXFont const & font);
void setCharFont(ParagraphList::iterator pit,
lyx::pos_type pos,
LyXFont const & font, bool toggleall);
pos_type pos, LyXFont const & font, bool toggleall);
/// what you expect when pressing <enter> at cursor position
void breakParagraph(LCursor & cur, char keep_layout = 0);
@ -131,7 +135,7 @@ public:
/// returns an iterator pointing to a cursor paragraph
ParagraphList::iterator getPar(CursorSlice const & cursor) const;
///
ParagraphList::iterator getPar(lyx::paroffset_type par) const;
ParagraphList::iterator getPar(par_type par) const;
///
int parOffset(ParagraphList::iterator pit) const;
/// # FIXME: should not be used
@ -149,7 +153,7 @@ public:
/** returns the column near the specified x-coordinate of the row
x is set to the real beginning of this column
*/
lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
pos_type getColumnNearX(ParagraphList::iterator pit,
Row const & row, int & x, bool & boundary) const;
/** Find the word under \c from in the relative location
@ -167,23 +171,21 @@ public:
void rejectChange(LCursor & cur);
/// returns true if par was empty and was removed
bool setCursor(lyx::paroffset_type par, lyx::pos_type pos,
bool setCursor(LCursor & cur, par_type par, pos_type pos,
bool setfont = true, bool boundary = false);
///
void setCursor(CursorSlice &, lyx::paroffset_type par,
lyx::pos_type pos, bool boundary = false);
void setCursor(CursorSlice &, par_type par,
pos_type pos, bool boundary = false);
///
void setCursorIntern(lyx::paroffset_type par, lyx::pos_type pos,
bool setfont = true, bool boundary = false);
void setCursorIntern(LCursor & cur, par_type par,
pos_type pos, bool setfont = true, bool boundary = false);
///
void setCurrentFont();
void setCurrentFont(LCursor & cur);
///
void recUndo(lyx::paroffset_type first, lyx::paroffset_type last) const;
void recUndo(par_type first, par_type last) const;
///
void recUndo(lyx::paroffset_type first) const;
///
void setCursorFromCoordinates(int x, int y);
void recUndo(par_type first) const;
///
void setCursorFromCoordinates(CursorSlice &, int x, int y);
///
@ -237,9 +239,9 @@ public:
/// returns success
bool toggleInset(LCursor & cur);
///
void cutSelection(bool doclear = true, bool realcut = true);
void cutSelection(LCursor & cur, bool doclear = true, bool realcut = true);
///
void copySelection();
void copySelection(LCursor & cur);
///
void pasteSelection(LCursor & cur, size_t sel_index = 0);
@ -248,7 +250,7 @@ public:
last. When a paragraph is broken, the top settings rest, the bottom
settings are given to the new one.
*/
void setParagraph(
void setParagraph(LCursor & cur,
Spacing const & spacing,
LyXAlignment align,
std::string const & labelwidthstring,
@ -260,7 +262,7 @@ public:
* Sets the selection from the current cursor position to length
* characters to the right. No safety checks.
*/
void setSelectionRange(LCursor & cur, lyx::pos_type length);
void setSelectionRange(LCursor & cur, pos_type length);
/// simply replace using the font of the first selected character
void replaceSelectionWithString(LCursor & cur, std::string const & str);
/// replace selection helper
@ -272,13 +274,14 @@ public:
void insertStringAsParagraphs(LCursor & cur, std::string const & str);
/// Find next inset of some specified type.
bool gotoNextInset(std::vector<InsetOld_code> const & codes,
std::string const & contents = std::string());
bool gotoNextInset(LCursor & cur,
std::vector<InsetOld_code> const & codes,
std::string const & contents = std::string());
///
void gotoInset(std::vector<InsetOld_code> const & codes,
bool same_content);
void gotoInset(LCursor & cur,
std::vector<InsetOld_code> const & codes, bool same_content);
///
void gotoInset(InsetOld_code code, bool same_content);
void gotoInset(LCursor & cur, InsetOld_code code, bool same_content);
/// current max text width
int textWidth() const;
@ -289,10 +292,10 @@ public:
InsetBase * checkInsetHit(int x, int y);
///
int singleWidth(ParagraphList::iterator pit, lyx::pos_type pos) const;
int singleWidth(ParagraphList::iterator pit, pos_type pos) const;
///
int singleWidth(ParagraphList::iterator pit,
lyx::pos_type pos, char c, LyXFont const & Font) const;
pos_type pos, char c, LyXFont const & Font) const;
/// return the color of the canvas
LColor_color backgroundColor() const;
@ -303,7 +306,7 @@ public:
* in LaTeX the beginning of the text fits in some cases
* (for example sections) exactly the label-width.
*/
int leftMargin(ParagraphList::iterator pit, lyx::pos_type pos) const;
int leftMargin(ParagraphList::iterator pit, pos_type pos) const;
int leftMargin(ParagraphList::iterator pit) const;
///
int rightMargin(Paragraph const & par) const;
@ -452,9 +455,9 @@ private:
///
void charInserted();
/// set 'number' font property
void number();
void number(LCursor & cur);
/// is the cursor paragraph right-to-left?
bool rtl() const;
bool rtl(LCursor & cur) const;
};
/// return the default height of a row in pixels, considering font zoom

View File

@ -758,6 +758,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
void LyXText::breakParagraph(LCursor & cur, char keep_layout)
{
BOOST_ASSERT(this == cur.text());
// allow only if at start or end, or all previous is new text
Paragraph & cpar = cur.paragraph();
ParagraphList::iterator cpit = getPar(cur.par());
@ -831,18 +832,19 @@ void LyXText::breakParagraph(LCursor & cur, char keep_layout)
// This check is necessary. Otherwise the new empty paragraph will
// be deleted automatically. And it is more friendly for the user!
if (cur.pos() != 0 || isempty)
setCursor(cur.par() + 1, 0);
setCursor(cur, cur.par() + 1, 0);
else
setCursor(cur.par(), 0);
setCursor(cur, cur.par(), 0);
}
// convenience function
void LyXText::redoParagraph(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
cur.clearSelection();
redoParagraph(getPar(cur.par()));
setCursorIntern(cur.par(), cur.pos());
setCursorIntern(cur, cur.par(), cur.pos());
}
@ -850,6 +852,7 @@ void LyXText::redoParagraph(LCursor & cur)
// same Paragraph one to the right and make a rebreak
void LyXText::insertChar(LCursor & cur, char c)
{
BOOST_ASSERT(this == cur.text());
recordUndo(cur, Undo::INSERT);
Paragraph & par = cur.paragraph();
@ -872,10 +875,10 @@ void LyXText::insertChar(LCursor & cur, char c)
getFont(pit, cur.pos()).number() == LyXFont::ON &&
getFont(pit, cur.pos() - 1).number() == LyXFont::ON)
)
number(); // Set current_font.number to OFF
number(cur); // Set current_font.number to OFF
} else if (IsDigit(c) &&
real_current_font.isVisibleRightToLeft()) {
number(); // Set current_font.number to ON
number(cur); // Set current_font.number to ON
if (cur.pos() != 0) {
char const c = par.getChar(cur.pos() - 1);
@ -944,7 +947,7 @@ void LyXText::insertChar(LCursor & cur, char c)
current_font = rawtmpfont;
real_current_font = realtmpfont;
redoParagraph(cur);
setCursor(cur.par(), cur.pos() + 1, false, cur.boundary());
setCursor(cur, cur.par(), cur.pos() + 1, false, cur.boundary());
charInserted();
}
@ -1085,6 +1088,7 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
void LyXText::cursorRightOneWord(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.pos() == cur.lastpos() && cur.par() != cur.lastpar()) {
++cur.par();
cur.pos() = 0;
@ -1097,12 +1101,13 @@ void LyXText::cursorRightOneWord(LCursor & cur)
while (cur.pos() != cur.lastpos() && cur.paragraph().isWord(cur.pos()))
++cur.pos();
}
setCursor(cur.par(), cur.pos());
setCursor(cur, cur.par(), cur.pos());
}
void LyXText::cursorLeftOneWord(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.pos() == 0 && cur.par() != 0) {
--cur.par();
cur.pos() = cur.lastpos();
@ -1115,21 +1120,22 @@ void LyXText::cursorLeftOneWord(LCursor & cur)
while (cur.pos() != 0 && cur.paragraph().isWord(cur.pos() - 1))
--cur.pos();
}
setCursor(cur.par(), cur.pos());
setCursor(cur, cur.par(), cur.pos());
}
void LyXText::selectWord(LCursor & cur, word_location loc)
{
BOOST_ASSERT(this == cur.text());
CursorSlice from = cur.current();
CursorSlice to = cur.current();
getWord(from, to, loc);
if (cur.current() != from)
setCursor(from.par(), from.pos());
setCursor(cur, from.par(), from.pos());
if (to == from)
return;
cur.resetAnchor();
setCursor(to.par(), to.pos());
setCursor(cur, to.par(), to.pos());
cur.setSelection();
}
@ -1138,6 +1144,7 @@ void LyXText::selectWord(LCursor & cur, word_location loc)
// selection is currently set
bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
{
BOOST_ASSERT(this == cur.text());
if (cur.selection())
return false;
selectWord(cur, loc);
@ -1147,6 +1154,7 @@ bool LyXText::selectWordWhenUnderCursor(LCursor & cur, word_location loc)
void LyXText::acceptChange(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (!cur.selection() && cur.lastpos() != 0)
return;
@ -1158,7 +1166,7 @@ void LyXText::acceptChange(LCursor & cur)
finishUndo();
cur.clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
setCursorIntern(cur, startc.par(), 0);
}
#warning handle multi par selection
}
@ -1166,6 +1174,7 @@ void LyXText::acceptChange(LCursor & cur)
void LyXText::rejectChange(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (!cur.selection() && cur.lastpos() != 0)
return;
@ -1177,7 +1186,7 @@ void LyXText::rejectChange(LCursor & cur)
finishUndo();
cur.clearSelection();
redoParagraph(getPar(startc));
setCursorIntern(startc.par(), 0);
setCursorIntern(cur, startc.par(), 0);
}
#warning handle multi par selection
}
@ -1186,6 +1195,7 @@ void LyXText::rejectChange(LCursor & cur)
// Delete from cursor up to the end of the current or next word.
void LyXText::deleteWordForward(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.lastpos() == 0)
cursorRight(cur, true);
else {
@ -1193,7 +1203,7 @@ void LyXText::deleteWordForward(LCursor & cur)
cur.selection() = true;
cursorRightOneWord(cur);
cur.setSelection();
cutSelection(true, false);
cutSelection(cur, true, false);
}
}
@ -1201,6 +1211,7 @@ void LyXText::deleteWordForward(LCursor & cur)
// Delete from cursor to start of current or prior word.
void LyXText::deleteWordBackward(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.lastpos() == 0)
cursorLeft(cur, true);
else {
@ -1208,7 +1219,7 @@ void LyXText::deleteWordBackward(LCursor & cur)
cur.selection() = true;
cursorLeftOneWord(cur);
cur.setSelection();
cutSelection(true, false);
cutSelection(cur, true, false);
}
}
@ -1216,6 +1227,7 @@ void LyXText::deleteWordBackward(LCursor & cur)
// Kill to end of line.
void LyXText::deleteLineForward(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.lastpos() == 0) {
// Paragraph is empty, so we just go to the right
cursorRight(cur, true);
@ -1228,13 +1240,14 @@ void LyXText::deleteLineForward(LCursor & cur)
if (!cur.selection())
deleteWordForward(cur);
else
cutSelection(true, false);
cutSelection(cur, true, false);
}
}
void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
{
BOOST_ASSERT(this == cur.text());
CursorSlice from;
CursorSlice to;
@ -1244,7 +1257,7 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
} else {
from = cursor();
getWord(from, to, lyx::PARTIAL_WORD);
setCursor(to.par(), to.pos() + 1);
setCursor(cur, to.par(), to.pos() + 1);
}
recordUndoSelection(cur);
@ -1284,6 +1297,7 @@ void LyXText::changeCase(LCursor & cur, LyXText::TextCase action)
void LyXText::Delete(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
// this is a very simple implementation
// just move to the right
// if you had success make a backspace
@ -1297,6 +1311,7 @@ void LyXText::Delete(LCursor & cur)
void LyXText::backspace(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.pos() == 0) {
// The cursor is at the beginning of a paragraph, so
// the the backspace will collapse two paragraphs into
@ -1335,7 +1350,7 @@ void LyXText::backspace(LCursor & cur)
// without the dreaded mechanism. (JMarc)
if (cur.par() != 0) {
// steps into the above paragraph.
setCursorIntern(cur.par() - 1,
setCursorIntern(cur, cur.par() - 1,
getPar(cur.par() - 1)->size(),
false);
}
@ -1360,7 +1375,7 @@ void LyXText::backspace(LCursor & cur)
// the counters may have changed
updateCounters();
setCursor(cur.par(), cur.pos(), false);
setCursor(cur, cur.par(), cur.pos(), false);
}
} else {
// this is the code for a normal backspace, not pasting
@ -1370,16 +1385,16 @@ void LyXText::backspace(LCursor & cur)
// not a good idea since it triggers the auto-delete
// mechanism. So we do a cursorLeftIntern()-lite,
// without the dreaded mechanism. (JMarc)
setCursorIntern(cur.par(), cur.pos() - 1,
setCursorIntern(cur, cur.par(), cur.pos() - 1,
false, cur.boundary());
cur.paragraph().erase(cur.pos());
}
if (cur.pos() == cur.lastpos())
setCurrentFont();
setCurrentFont(cur);
redoParagraph(cur);
setCursor(cur.par(), cur.pos(), false, cur.boundary());
setCursor(cur, cur.par(), cur.pos(), false, cur.boundary());
}
@ -1593,9 +1608,9 @@ void LyXText::draw(PainterInfo & pi, int x, int y) const
// only used for inset right now. should also be used for main text
void LyXText::drawSelection(PainterInfo &, int x, int y) const
void LyXText::drawSelection(PainterInfo &, int, int) const
{
lyxerr << "LyXText::drawSelection at " << x << " " << y << endl;
//lyxerr << "LyXText::drawSelection at " << x << " " << y << endl;
}
@ -1856,9 +1871,10 @@ CursorSlice const & LyXText::cursor() const
void LyXText::replaceSelection(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
if (cur.selection()) {
cutSelection(true, false);
bv()->update();
cutSelection(cur, true, false);
cur.update();
}
}
@ -1866,6 +1882,7 @@ void LyXText::replaceSelection(LCursor & cur)
// Returns the current font and depth as a message.
string LyXText::currentState(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
Buffer * buffer = bv()->buffer();
Paragraph const & par = cur.paragraph();
std::ostringstream os;

View File

@ -64,7 +64,6 @@
#include <boost/tuple/tuple.hpp>
using lyx::pos_type;
using lyx::paroffset_type;
using lyx::support::bformat;
using std::endl;
@ -281,6 +280,7 @@ LyXText::setLayout(ParagraphList::iterator start,
// set layout over selection and make a total rebreak of those paragraphs
void LyXText::setLayout(LCursor & cur, string const & layout)
{
BOOST_ASSERT(this == cur.text());
// special handling of new environment insets
BufferParams const & params = bv()->buffer()->params();
LyXLayout_ptr const & lyxlayout = params.getLyXTextClass()[layout];
@ -342,6 +342,7 @@ bool changeDepthAllowed(bv_funcs::DEPTH_CHANGE type,
bool LyXText::changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type)
{
BOOST_ASSERT(this == cur.text());
ParagraphList::iterator beg, end;
getSelectionSpan(cur, *this, beg, end);
int max_depth = 0;
@ -359,6 +360,7 @@ bool LyXText::changeDepthAllowed(LCursor & cur, bv_funcs::DEPTH_CHANGE type)
void LyXText::changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type)
{
BOOST_ASSERT(this == cur.text());
ParagraphList::iterator beg, end;
getSelectionSpan(cur, *this, beg, end);
recordUndoSelection(cur);
@ -386,6 +388,7 @@ void LyXText::changeDepth(LCursor & cur, bv_funcs::DEPTH_CHANGE type)
// set font over selection and make a total rebreak of those paragraphs
void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
{
BOOST_ASSERT(this == cur.text());
// if there is no selection just set the current_font
if (!cur.selection()) {
// Determine basis font
@ -439,33 +442,38 @@ void LyXText::setFont(LCursor & cur, LyXFont const & font, bool toggleall)
void LyXText::cursorHome(LCursor & cur)
{
setCursor(cur.par(), cur.textRow().pos());
BOOST_ASSERT(this == cur.text());
setCursor(cur, cur.par(), cur.textRow().pos());
}
void LyXText::cursorEnd(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
// if not on the last row of the par, put the cursor before
// the final space
pos_type const end = cur.textRow().endpos();
setCursor(cur.par(), end == cur.lastpos() ? end : end - 1);
setCursor(cur, cur.par(), end == cur.lastpos() ? end : end - 1);
}
void LyXText::cursorTop(LCursor &)
void LyXText::cursorTop(LCursor & cur)
{
setCursor(0, 0);
BOOST_ASSERT(this == cur.text());
setCursor(cur, 0, 0);
}
void LyXText::cursorBottom(LCursor & cur)
{
setCursor(cur.lastpar(), boost::prior(paragraphs().end())->size());
BOOST_ASSERT(this == cur.text());
setCursor(cur, cur.lastpar(), boost::prior(paragraphs().end())->size());
}
void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
{
BOOST_ASSERT(this == cur.text());
// If the mask is completely neutral, tell user
if (font == LyXFont(LyXFont::ALL_IGNORE)) {
// Could only happen with user style
@ -498,6 +506,7 @@ void LyXText::toggleFree(LCursor & cur, LyXFont const & font, bool toggleall)
string LyXText::getStringToIndex(LCursor & cur)
{
BOOST_ASSERT(this == cur.text());
// Try implicit word selection
// If there is a change in the language the implicit word selection
// is disabled.
@ -531,10 +540,11 @@ string LyXText::getStringToIndex(LCursor & cur)
// they do not duplicate themself and you cannot play dirty tricks with
// them!
void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
void LyXText::setParagraph(LCursor & cur,
Spacing const & spacing, LyXAlignment align,
string const & labelwidthstring, bool noindent)
{
LCursor & cur = bv()->cursor();
BOOST_ASSERT(cur.text());
// make sure that the depth behind the selection are restored, too
ParagraphList::iterator undopit = undoSpan(getPar(cur.selEnd()));
recUndo(cur.selBegin().par(), parOffset(undopit) - 1);
@ -856,6 +866,7 @@ void LyXText::updateCounters()
void LyXText::insertInset(LCursor & cur, InsetBase * inset)
{
BOOST_ASSERT(this == cur.text());
recordUndo(cur);
freezeUndo();
cur.paragraph().insertInset(cur.pos(), inset);
@ -872,9 +883,9 @@ void LyXText::insertInset(LCursor & cur, InsetBase * inset)
}
void LyXText::cutSelection(bool doclear, bool realcut)
void LyXText::cutSelection(LCursor & cur, bool doclear, bool realcut)
{
LCursor & cur = bv()->cursor();
BOOST_ASSERT(this == cur.text());
// Stuff what we got on the clipboard. Even if there is no selection.
// There is a problem with having the stuffing here in that the
@ -930,9 +941,9 @@ void LyXText::cutSelection(bool doclear, bool realcut)
}
void LyXText::copySelection()
void LyXText::copySelection(LCursor & cur)
{
LCursor & cur = bv()->cursor();
BOOST_ASSERT(this == cur.text());
// stuff the selection onto the X clipboard, from an explicit copy request
bv()->stuffClipboard(cur.selectionAsString(true));
@ -974,17 +985,17 @@ void LyXText::pasteSelection(LCursor & cur, size_t sel_index)
boost::tie(ppp, endpit) =
CutAndPaste::pasteSelection(*bv()->buffer(),
paragraphs(),
cursorPar(), cursor().pos(),
getPar(cur.par()), cur.pos(),
bv()->buffer()->params().textclass,
sel_index, el);
bufferErrors(*bv()->buffer(), el);
bv()->showErrorList(_("Paste"));
redoParagraphs(cursorPar(), endpit);
redoParagraphs(getPar(cur.par()), endpit);
cur.clearSelection();
cur.resetAnchor();
setCursor(parOffset(ppp.first), ppp.second);
setCursor(cur, parOffset(ppp.first), ppp.second);
cur.setSelection();
updateCounters();
}
@ -1022,8 +1033,7 @@ void LyXText::replaceSelectionWithString(LCursor & cur, string const & str)
}
// Cut the selection
cutSelection(true, false);
cutSelection(cur, true, false);
unFreezeUndo();
}
@ -1042,7 +1052,7 @@ void LyXText::insertStringAsLines(LCursor & cur, string const & str)
redoParagraphs(getPar(cur.par()), endpit);
cur.resetAnchor();
setCursor(cur.par(), pos);
setCursor(cur, cur.par(), pos);
cur.setSelection();
}
@ -1074,16 +1084,16 @@ void LyXText::insertStringAsParagraphs(LCursor & cur, string const & str)
}
bool LyXText::setCursor(paroffset_type par, pos_type pos, bool setfont,
bool boundary)
bool LyXText::setCursor(LCursor & cur, par_type par, pos_type pos,
bool setfont, bool boundary)
{
CursorSlice old_cursor = cursor();
setCursorIntern(par, pos, setfont, boundary);
CursorSlice old_cursor = cur.current();
setCursorIntern(cur, par, pos, setfont, boundary);
return deleteEmptyParagraphMechanism(old_cursor);
}
void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
void LyXText::setCursor(CursorSlice & cur, par_type par,
pos_type pos, bool boundary)
{
BOOST_ASSERT(par != int(paragraphs().size()));
@ -1111,7 +1121,7 @@ void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
lyxerr << "dont like 1, pos: " << pos
<< " size: " << para.size()
<< " row.pos():" << row.pos()
<< " paroffset: " << par << endl;
<< " par: " << par << endl;
pos = 0;
cur.pos(0);
BOOST_ASSERT(false);
@ -1125,7 +1135,7 @@ void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
lyxerr << "dont like 3 please report pos:" << pos
<< " size: " << para.size()
<< " row.pos():" << row.pos()
<< " paroffset: " << par << endl;
<< " par: " << par << endl;
pos = row.pos();
cur.pos(pos);
BOOST_ASSERT(false);
@ -1133,35 +1143,35 @@ void LyXText::setCursor(CursorSlice & cur, paroffset_type par,
}
void LyXText::setCursorIntern(paroffset_type par,
pos_type pos, bool setfont, bool boundary)
void LyXText::setCursorIntern(LCursor & cur,
par_type par, pos_type pos, bool setfont, bool boundary)
{
setCursor(cursor(), par, pos, boundary);
bv()->cursor().x_target() = cursorX(cursor());
setCursor(cur.current(), par, pos, boundary);
cur.x_target() = cursorX(cur.current());
if (setfont)
setCurrentFont();
setCurrentFont(cur);
}
void LyXText::setCurrentFont()
void LyXText::setCurrentFont(LCursor & cur)
{
LCursor & cur = bv()->cursor();
BOOST_ASSERT(this == cur.text());
pos_type pos = cur.pos();
ParagraphList::iterator pit = cursorPar();
ParagraphList::iterator pit = getPar(cur.par());
if (cursor().boundary() && pos > 0)
if (cur.boundary() && pos > 0)
--pos;
if (pos > 0) {
if (pos == pit->size())
if (pos == cur.lastpos())
--pos;
else // potentional bug... BUG (Lgb)
if (pit->isSeparator(pos)) {
if (pos > pit->getRow(pos)->pos() &&
if (pos > cur.textRow().pos() &&
bidi.level(pos) % 2 ==
bidi.level(pos - 1) % 2)
--pos;
else if (pos + 1 < pit->size())
else if (pos + 1 < cur.lastpos())
++pos;
}
}
@ -1170,11 +1180,10 @@ void LyXText::setCurrentFont()
current_font = pit->getFontSettings(bufparams, pos);
real_current_font = getFont(pit, pos);
if (cursor().pos() == pit->size() &&
bidi.isBoundary(*bv()->buffer(), *pit, cursor().pos()) &&
!cursor().boundary()) {
Language const * lang =
pit->getParLanguage(bufparams);
if (cur.pos() == cur.lastpos()
&& bidi.isBoundary(*bv()->buffer(), *pit, cur.pos())
&& !cur.boundary()) {
Language const * lang = pit->getParLanguage(bufparams);
current_font.setLanguage(lang);
current_font.setNumber(LyXFont::OFF);
real_current_font.setLanguage(lang);
@ -1288,18 +1297,10 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
}
void LyXText::setCursorFromCoordinates(int x, int y)
{
CursorSlice old_cursor = cursor();
setCursorFromCoordinates(cursor(), x, y);
setCurrentFont();
deleteEmptyParagraphMechanism(old_cursor);
}
// x,y are coordinates relative to this LyXText
void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y)
{
CursorSlice old_cursor = cur;
ParagraphList::iterator pit;
Row const & row = *getRowNearY(y, pit);
bool bound = false;
@ -1308,6 +1309,7 @@ void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y)
cur.par() = parOffset(pit);
cur.pos() = pos;
cur.boundary() = bound;
deleteEmptyParagraphMechanism(old_cursor);
}
@ -1422,16 +1424,16 @@ bool LyXText::cursorLeft(LCursor & cur, bool internal)
{
if (cur.pos() != 0) {
bool boundary = cur.boundary();
setCursor(cur.par(), cur.pos() - 1, true, false);
setCursor(cur, cur.par(), cur.pos() - 1, true, false);
if (!internal && !boundary &&
bidi.isBoundary(*bv()->buffer(), cur.paragraph(), cur.pos() + 1))
setCursor(cur.par(), cur.pos() + 1, true, true);
setCursor(cur, cur.par(), cur.pos() + 1, true, true);
return true;
}
if (cur.par() != 0) {
// steps into the paragraph above
setCursor(cur.par() - 1, boost::prior(cursorPar())->size());
setCursor(cur, cur.par() - 1, boost::prior(cursorPar())->size());
return true;
}
@ -1442,20 +1444,20 @@ bool LyXText::cursorLeft(LCursor & cur, bool internal)
bool LyXText::cursorRight(LCursor & cur, bool internal)
{
if (!internal && cur.boundary()) {
setCursor(cur.par(), cur.pos(), true, false);
setCursor(cur, cur.par(), cur.pos(), true, false);
return true;
}
if (cur.pos() != cur.lastpos()) {
setCursor(cur.par(), cur.pos() + 1, true, false);
setCursor(cur, cur.par(), cur.pos() + 1, true, false);
if (!internal && bidi.isBoundary(*bv()->buffer(), cur.paragraph(),
cur.pos()))
setCursor(cur.par(), cur.pos(), true, true);
setCursor(cur, cur.par(), cur.pos(), true, true);
return true;
}
if (cur.par() != cur.lastpar()) {
setCursor(cur.par() + 1, 0);
setCursor(cur, cur.par() + 1, 0);
return true;
}
@ -1496,18 +1498,18 @@ void LyXText::cursorDown(LCursor & cur, bool selecting)
void LyXText::cursorUpParagraph(LCursor & cur)
{
if (cur.pos() > 0)
setCursor(cur.par(), 0);
setCursor(cur, cur.par(), 0);
else if (cur.par() != 0)
setCursor(cur.par() - 1, 0);
setCursor(cur, cur.par() - 1, 0);
}
void LyXText::cursorDownParagraph(LCursor & cur)
{
if (cur.par() != cur.lastpar())
setCursor(cur.par() + 1, 0);
setCursor(cur, cur.par() + 1, 0);
else
setCursor(cur.par(), cur.lastpos());
setCursor(cur, cur.par(), cur.lastpos());
}
@ -1670,13 +1672,13 @@ ParagraphList & LyXText::paragraphs() const
}
void LyXText::recUndo(paroffset_type first, paroffset_type last) const
void LyXText::recUndo(par_type first, par_type last) const
{
recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
}
void LyXText::recUndo(lyx::paroffset_type par) const
void LyXText::recUndo(par_type par) const
{
recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
}

View File

@ -30,6 +30,7 @@
#include "intl.h"
#include "language.h"
#include "lyxfunc.h"
#include "lyxlex.h"
#include "lyxrc.h"
#include "lyxrow.h"
#include "paragraph.h"
@ -101,10 +102,10 @@ namespace {
text->bidi.isBoundary(*cur.bv().buffer(), par,
cur.pos(),
text->real_current_font))
text->setCursor(cur.par(), cur.pos(),
text->setCursor(cur, cur.par(), cur.pos(),
false, !cur.boundary());
}
cur.bv().update();
cur.update();
}
@ -126,7 +127,8 @@ namespace {
}
void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
void mathDispatch(LCursor & cur, LyXText * text,
FuncRequest const & cmd, bool display)
{
string sel = cur.selectionAsString(false);
lyxerr << "selection is: '" << sel << "'" << endl;
@ -144,7 +146,7 @@ namespace {
} else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise
cur.bv().getLyXText()->cutSelection(true, true);
text->cutSelection(cur, true, true);
if (sel.find("\\newcommand") == string::npos &&
sel.find("\\def") == string::npos)
{
@ -212,12 +214,13 @@ InsetBase * LyXText::checkInsetHit(int x, int y)
}
bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
string const & contents)
bool LyXText::gotoNextInset(LCursor & cur,
vector<InsetOld_code> const & codes, string const & contents)
{
BOOST_ASSERT(this == cur.text());
ParagraphList::iterator end = paragraphs().end();
ParagraphList::iterator pit = cursorPar();
pos_type pos = cursor().pos();
ParagraphList::iterator pit = getPar(cur.par());
pos_type pos = cur.pos();
InsetBase * inset;
do {
@ -239,14 +242,14 @@ bool LyXText::gotoNextInset(vector<InsetOld_code> const & codes,
if (pit == end)
return false;
setCursor(parOffset(pit), pos, false);
setCursor(cur, parOffset(pit), pos, false);
return true;
}
void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
void LyXText::gotoInset(LCursor & cur,
vector<InsetOld_code> const & codes, bool same_content)
{
LCursor & cur = bv()->cursor();
cur.clearSelection();
string contents;
@ -259,12 +262,12 @@ void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
contents = static_cast<InsetCommand const *>(inset)->getContents();
}
if (!gotoNextInset(codes, contents)) {
if (!gotoNextInset(cur, codes, contents)) {
if (cur.pos() || cur.par() != 0) {
CursorSlice tmp = cursor();
CursorSlice tmp = cur.current();
cur.par() = 0;
cur.pos() = 0;
if (!gotoNextInset(codes, contents)) {
if (!gotoNextInset(cur, codes, contents)) {
cursor() = tmp;
cur.message(_("No more insets"));
}
@ -272,14 +275,14 @@ void LyXText::gotoInset(vector<InsetOld_code> const & codes, bool same_content)
cur.message(_("No more insets"));
}
}
cur.bv().update();
cur.update();
cur.resetAnchor();
}
void LyXText::gotoInset(InsetOld_code code, bool same_content)
void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
{
gotoInset(vector<InsetOld_code>(1, code), same_content);
gotoInset(cur, vector<InsetOld_code>(1, code), same_content);
}
@ -290,7 +293,7 @@ void LyXText::cursorPrevious(LCursor & cur)
int x = cur.x_target();
int y = bv()->top_y();
setCursorFromCoordinates(x, y);
setCursorFromCoordinates(cur.current(), x, y);
if (cpar == cur.par() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
@ -310,7 +313,7 @@ void LyXText::cursorNext(LCursor & cur)
int x = cur.x_target();
int y = bv()->top_y() + bv()->workHeight();
setCursorFromCoordinates(x, y);
setCursorFromCoordinates(cur.current(), x, y);
if (cpar == cur.par() && cpos == cur.pos()) {
// we have a row which is taller than the workarea. The
@ -325,49 +328,47 @@ void LyXText::cursorNext(LCursor & cur)
namespace {
void specialChar(LCursor & cur, LyXText * text, BufferView * bv,
InsetSpecialChar::Kind kind)
void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind)
{
bv->update();
text->replaceSelection(cur);
cur.insert(new InsetSpecialChar(kind));
bv->update();
cur.update();
}
void doInsertInset(LCursor & cur, LyXText * text, BufferView * bv,
void doInsertInset(LCursor & cur, LyXText * text,
FuncRequest const & cmd, bool edit, bool pastesel)
{
InsetBase * inset = createInset(bv, cmd);
InsetBase * inset = createInset(&cur.bv(), cmd);
if (!inset)
return;
bool gotsel = false;
if (cur.selection()) {
bv->owner()->dispatch(FuncRequest(LFUN_CUT));
cur.bv().owner()->dispatch(FuncRequest(LFUN_CUT));
gotsel = true;
}
text->insertInset(cur, inset);
if (edit)
inset->edit(cur, true);
if (gotsel && pastesel)
bv->owner()->dispatch(FuncRequest(LFUN_PASTE));
cur.bv().owner()->dispatch(FuncRequest(LFUN_PASTE));
}
} // anon namespace
void LyXText::number()
void LyXText::number(LCursor & cur)
{
LyXFont font(LyXFont::ALL_IGNORE);
font.setNumber(LyXFont::TOGGLE);
toggleAndShow(bv()->cursor(), this, font);
toggleAndShow(cur, this, font);
}
bool LyXText::rtl() const
bool LyXText::rtl(LCursor & cur) const
{
return cursorPar()->isRightToLeftPar(bv()->buffer()->params());
return getPar(cur.par())->isRightToLeftPar(bv()->buffer()->params());
}
@ -403,7 +404,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// we can set the refreshing parameters now
updateCounters();
redoParagraph(cur);
bv->update();
cur.update();
break;
}
@ -428,7 +429,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_WORDRIGHT:
if (!cur.mark())
cur.clearSelection();
if (rtl())
if (rtl(cur))
cursorLeftOneWord(cur);
else
cursorRightOneWord(cur);
@ -438,7 +439,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_WORDLEFT:
if (!cur.mark())
cur.clearSelection();
if (rtl())
if (rtl(cur))
cursorRightOneWord(cur);
else
cursorLeftOneWord(cur);
@ -462,7 +463,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_RIGHTSEL:
if (!cur.selection())
cur.resetAnchor();
if (rtl())
if (rtl(cur))
cursorLeft(cur, true);
else
cursorRight(cur, true);
@ -472,7 +473,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_LEFTSEL:
if (!cur.selection())
cur.resetAnchor();
if (rtl())
if (rtl(cur))
cursorRight(cur, true);
else
cursorLeft(cur, true);
@ -538,7 +539,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_WORDRIGHTSEL:
if (!cur.selection())
cur.resetAnchor();
if (rtl())
if (rtl(cur))
cursorLeftOneWord(cur);
else
cursorRightOneWord(cur);
@ -548,7 +549,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_WORDLEFTSEL:
if (!cur.selection())
cur.resetAnchor();
if (rtl())
if (rtl(cur))
cursorRightOneWord(cur);
else
cursorLeftOneWord(cur);
@ -641,7 +642,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// It is possible to make it a lot faster still
// just comment out the line below...
} else {
cutSelection(true, false);
cutSelection(cur, true, false);
}
moveCursor(cur, false);
bv->owner()->view_state_changed();
@ -657,9 +658,9 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
Delete(cur);
cur.resetAnchor();
} else {
cutSelection(true, false);
cutSelection(cur, true, false);
}
bv->update();
cur.update();
break;
@ -672,11 +673,11 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// just comment out the line below...
}
} else {
cutSelection(true, false);
cutSelection(cur, true, false);
}
bv->owner()->view_state_changed();
bv->switchKeyMap();
bv->update();
cur.update();
break;
case LFUN_BACKSPACE_SKIP:
@ -687,15 +688,15 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
backspace(cur);
//anchor() = cur;
} else {
cutSelection(true, false);
cutSelection(cur, true, false);
}
bv->update();
cur.update();
break;
case LFUN_BREAKPARAGRAPH:
replaceSelection(cur);
breakParagraph(cur, 0);
bv->update();
cur.update();
cur.resetAnchor();
bv->switchKeyMap();
bv->owner()->view_state_changed();
@ -704,7 +705,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
replaceSelection(cur);
breakParagraph(cur, 1);
bv->update();
cur.update();
cur.resetAnchor();
bv->switchKeyMap();
bv->owner()->view_state_changed();
@ -714,18 +715,17 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// When at the beginning of a paragraph, remove
// indentation and add a "defskip" at the top.
// Otherwise, do the same as LFUN_BREAKPARAGRAPH.
#warning look here
replaceSelection(cur);
if (cur.pos() == 0) {
ParagraphParameters & params = cur.paragraph().params();
setParagraph(
setParagraph(cur,
params.spacing(),
params.align(),
params.labelWidthString(), 1);
} else {
breakParagraph(cur, 0);
}
bv->update();
cur.update();
// anchor() = cur;
bv->switchKeyMap();
bv->owner()->view_state_changed();
@ -769,7 +769,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (cur_spacing != new_spacing || cur_value != new_value) {
par.params().spacing(Spacing(new_spacing, new_value));
redoParagraph(cur);
bv->update();
cur.update();
}
break;
}
@ -800,7 +800,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
cur.clearSelection();
if (!toggleInset(cur))
return DispatchResult(false);
bv->update();
cur.update();
bv->switchKeyMap();
break;
@ -808,49 +808,49 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (cur.paragraph().layout()->free_spacing)
insertChar(cur, ' ');
else
doInsertInset(cur, this, bv, cmd, false, false);
doInsertInset(cur, this, cmd, false, false);
moveCursor(cur, false);
break;
case LFUN_HYPHENATION:
specialChar(cur, this, bv, InsetSpecialChar::HYPHENATION);
specialChar(cur, this, InsetSpecialChar::HYPHENATION);
break;
case LFUN_LIGATURE_BREAK:
specialChar(cur, this, bv, InsetSpecialChar::LIGATURE_BREAK);
specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK);
break;
case LFUN_LDOTS:
specialChar(cur, this, bv, InsetSpecialChar::LDOTS);
specialChar(cur, this, InsetSpecialChar::LDOTS);
break;
case LFUN_END_OF_SENTENCE:
specialChar(cur, this, bv, InsetSpecialChar::END_OF_SENTENCE);
specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE);
break;
case LFUN_MENU_SEPARATOR:
specialChar(cur, this, bv, InsetSpecialChar::MENU_SEPARATOR);
specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR);
break;
case LFUN_UPCASE_WORD:
changeCase(cur, LyXText::text_uppercase);
bv->update();
cur.update();
break;
case LFUN_LOWCASE_WORD:
changeCase(cur, LyXText::text_lowercase);
bv->update();
cur.update();
break;
case LFUN_CAPITALIZE_WORD:
changeCase(cur, LyXText::text_capitalization);
bv->update();
cur.update();
break;
case LFUN_TRANSPOSE_CHARS:
recordUndo(cur);
redoParagraph(cur);
bv->update();
cur.update();
break;
case LFUN_PASTE:
@ -862,19 +862,19 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
else
pasteSelection(cur, 0);
cur.clearSelection(); // bug 393
bv->update();
cur.update();
bv->switchKeyMap();
finishUndo();
break;
case LFUN_CUT:
cutSelection(true, true);
cutSelection(cur, true, true);
cur.message(_("Cut"));
bv->update();
cur.update();
break;
case LFUN_COPY:
copySelection();
copySelection(cur);
cur.message(_("Copy"));
break;
@ -910,7 +910,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
lyxerr << "SETXY: Could not parse coordinates in '"
<< cmd.argument << std::endl;
else
setCursorFromCoordinates(x, y);
setCursorFromCoordinates(cur.current(), x, y);
break;
}
@ -980,7 +980,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
current_layout = layout;
setLayout(cur, layout);
bv->owner()->setLayout(layout);
bv->update();
cur.update();
bv->switchKeyMap();
}
break;
@ -994,24 +994,24 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
insertStringAsParagraphs(cur, clip);
else
insertStringAsLines(cur, clip);
bv->update();
cur.update();
}
break;
}
case LFUN_GOTOERROR:
gotoInset(InsetBase::ERROR_CODE, false);
gotoInset(cur, InsetBase::ERROR_CODE, false);
break;
case LFUN_GOTONOTE:
gotoInset(InsetBase::NOTE_CODE, false);
gotoInset(cur, InsetBase::NOTE_CODE, false);
break;
case LFUN_REFERENCE_GOTO: {
vector<InsetOld_code> tmp;
tmp.push_back(InsetBase::LABEL_CODE);
tmp.push_back(InsetBase::REF_CODE);
gotoInset(tmp, true);
gotoInset(cur, tmp, true);
break;
}
@ -1081,7 +1081,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_MOUSE_MOTION: {
// Only use motion with button 1
//if (ev.button() != mouse_button::button1)
//if (cmd.button() != mouse_button::button1)
// return false;
// The test for not selection possible is needed, that
// only motion events are used, where the bottom press
@ -1092,9 +1092,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break;
}
CursorSlice old = cur.current();
#warning
setCursorFromCoordinates(cmd.x, cmd.y);
setCursorFromCoordinates(cur.current(), cmd.x, cmd.y);
// This is to allow jumping over large insets
// FIXME: shouldn't be top-text-specific
@ -1108,7 +1106,6 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
// don't set anchor_
bv->cursor().cursor_ = cur.cursor_;
bv->cursor().setSelection();
break;
}
@ -1209,7 +1206,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
if (lyxrc.auto_region_delete) {
if (cur.selection())
cutSelection(false, false);
cutSelection(cur, false, false);
bv->haveSelection(false);
}
@ -1276,12 +1273,12 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_ENVIRONMENT_INSERT:
// Open the inset, and move the current selection
// inside it.
doInsertInset(cur, this, bv, cmd, true, true);
doInsertInset(cur, this, cmd, true, true);
break;
case LFUN_INDEX_INSERT:
// Just open the inset
doInsertInset(cur, this, bv, cmd, true, false);
doInsertInset(cur, this, cmd, true, false);
break;
case LFUN_INDEX_PRINT:
@ -1290,26 +1287,26 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_INSERT_LINE:
case LFUN_INSERT_PAGEBREAK:
// do nothing fancy
doInsertInset(cur, this, bv, cmd, false, false);
doInsertInset(cur, this, cmd, false, false);
break;
case LFUN_DEPTH_MIN:
changeDepth(cur, bv_funcs::DEC_DEPTH);
bv->update();
cur.update();
break;
case LFUN_DEPTH_PLUS:
changeDepth(cur, bv_funcs::INC_DEPTH);
bv->update();
cur.update();
break;
case LFUN_MATH_DISPLAY:
mathDispatch(cur, cmd, true);
mathDispatch(cur, this, cmd, true);
break;
case LFUN_MATH_IMPORT_SELECTION:
case LFUN_MATH_MODE:
mathDispatch(cur, cmd, false);
mathDispatch(cur, this, cmd, false);
break;
case LFUN_MATH_MACRO:
@ -1443,7 +1440,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_FINISHED_LEFT:
lyxerr << "handle LFUN_FINISHED_LEFT" << endl;
cur.pop(cur.currentDepth());
if (rtl())
if (rtl(cur))
cursorLeft(cur, true);
cur.bv().cursor() = cur;
break;
@ -1451,7 +1448,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_FINISHED_RIGHT:
lyxerr << "handle LFUN_FINISHED_RIGHT" << endl;
cur.pop(cur.currentDepth());
if (!rtl())
if (!rtl(cur))
cursorRight(cur, true);
cur.bv().cursor() = cur;
break;
@ -1532,7 +1529,7 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
}
setLayout(cur, tclass.defaultLayoutName());
setParagraph(Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
setParagraph(cur, Spacing(), LYX_ALIGN_LAYOUT, string(), 0);
cur.insert(new InsetFloatList(cmd.argument));
unFreezeUndo();
} else {
@ -1544,13 +1541,13 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
case LFUN_ACCEPT_CHANGE: {
acceptChange(cur);
bv->update();
cur.update();
break;
}
case LFUN_REJECT_CHANGE: {
rejectChange(cur);
bv->update();
cur.update();
break;
}
@ -1569,6 +1566,25 @@ DispatchResult LyXText::dispatch(LCursor & cur, FuncRequest const & cmd)
break;
}
case LFUN_PARAGRAPH_APPLY: {
// Given data, an encoding of the ParagraphParameters
// generated in the Paragraph dialog, this function sets
// the current paragraph appropriately.
istringstream is(cmd.argument);
LyXLex lex(0, 0);
lex.setStream(is);
ParagraphParameters params;
params.read(lex);
setParagraph(cur,
params.spacing(),
params.align(),
params.labelWidthString(),
params.noindent());
cur.update();
cur.message(_("Paragraph layout set"));
break;
}
default:
return DispatchResult(false);
}