the stuff from the sneak preview:

For one, it still contains a few things that are already in CVS (the
'brown paperbag' changes).

Secondly, this changes the ParagraphList to a std::vector but does not
yet take full advantage of it except removing LyXText::parOffset() and
similar.

I had an extensive talk with my profiler and we are happy nevertheless.

This also moves almost all Cut&Paste specific stuff from text.C to
CutAndPaste.C. Much smaller interface now... Namespace CutAndPaste is
now  lyx::cap::. Was inconsistent with the rest....

Make ParagraphList a proper class. We'll need this later for a
specialized erase/insert.

Remove some unneeded prototypes and function declarations

Use ParameterStruct directly instead of ShareContainer<ParameterStruct>

Inline a few accesses to CursorSlice members as suggested by the profiler.

Fix commandline conversion crash reported by Kayvan.

Replace PosIterator by DocumentIterator. The latter can also iterate
through math and nested text in math...

Remove math specific hack from Documentiterator

Derive InsetCollapsable from InsetText instead of using an InsetText
member. This give us the opportunity to get rid of the InsetOld::owner_
backpointer.

Cosmetics in CutAndPaste.C and cursor.C. Fix nasty crash (popping slices
off an empty selection anchor). Add a few asserts.

Remove all 'manual' update calls. We do now one per user interaction which
is completely sufficient.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8527 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-03-25 09:16:36 +00:00
parent 4e9ea80fb5
commit 0d43ba149a
88 changed files with 2545 additions and 3234 deletions

View File

@ -61,8 +61,7 @@ void Bidi::computeTables(Paragraph const & par,
} }
InsetOld * inset = par.inInset(); InsetOld * inset = par.inInset();
if (inset && inset->owner() && if (inset && inset->lyxCode() == InsetOld::ERT_CODE) {
inset->owner()->lyxCode() == InsetOld::ERT_CODE) {
start_ = -1; start_ = -1;
return; return;
} }

View File

@ -20,6 +20,7 @@
#include "bufferlist.h" #include "bufferlist.h"
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView_pimpl.h" #include "BufferView_pimpl.h"
#include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
#include "funcrequest.h" #include "funcrequest.h"
#include "gettext.h" #include "gettext.h"
@ -30,7 +31,6 @@
#include "lyxtextclass.h" #include "lyxtextclass.h"
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "PosIterator.h"
#include "texrow.h" #include "texrow.h"
#include "undo.h" #include "undo.h"
#include "WordLangTuple.h" #include "WordLangTuple.h"
@ -51,6 +51,8 @@
using lyx::support::bformat; using lyx::support::bformat;
using lyx::support::MakeAbsPath; using lyx::support::MakeAbsPath;
using lyx::cap::setSelectionRange;
using std::distance; using std::distance;
using std::find; using std::find;
using std::string; using std::string;
@ -268,8 +270,7 @@ bool BufferView::insertLyXFile(string const & filen)
text()->breakParagraph(cursor()); text()->breakParagraph(cursor());
BOOST_ASSERT(cursor().inTexted()); BOOST_ASSERT(cursor().inTexted());
LyXText * text = cursor().text(); bool res = buffer()->readFile(fname, cursor().par());
bool res = buffer()->readFile(fname, text->getPar(cursor().par()));
resize(); resize();
return res; return res;
} }
@ -302,8 +303,7 @@ void BufferView::setCursorFromRow(int row)
if (tmpid == -1) if (tmpid == -1)
text()->setCursor(cursor(), 0, 0); text()->setCursor(cursor(), 0, 0);
else else
text()->setCursor(cursor(), text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(),
text()->parOffset(buffer()->getParFromID(tmpid).pit()),
tmppos); tmppos);
} }
@ -316,9 +316,7 @@ void BufferView::gotoLabel(string const & label)
it->getLabelList(*buffer(), labels); it->getLabelList(*buffer(), labels);
if (find(labels.begin(),labels.end(),label) != labels.end()) { if (find(labels.begin(),labels.end(),label) != labels.end()) {
cursor().clearSelection(); cursor().clearSelection();
text()->setCursor(cursor(), text()->setCursor(cursor(), it.getPar(), it.getPos());
distance(text()->paragraphs().begin(), it.getPar()),
it.getPos());
cursor().resetAnchor(); cursor().resetAnchor();
update(); update();
return; return;
@ -376,8 +374,7 @@ void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos)
for (int i = 0; i < last; ++i) for (int i = 0; i < last; ++i)
(*positions[i].it)->inset->edit(cur, true); (*positions[i].it)->inset->edit(cur, true);
cur.resetAnchor(); cur.resetAnchor();
LyXText & text = *par.text(*buffer()); par.text(*buffer())->setCursor(cur, par.pit(), pos);
text.setCursor(cur, text.parOffset(par.pit()), pos);
} }
@ -395,7 +392,7 @@ this is solved in putSelectionAt with:
Ab. Ab.
*/ */
void BufferView::putSelectionAt(PosIterator const & cur, void BufferView::putSelectionAt(DocumentIterator const & cur,
int length, bool backwards) int length, bool backwards)
{ {
ParIterator par(cur); ParIterator par(cur);
@ -407,22 +404,18 @@ void BufferView::putSelectionAt(PosIterator const & cur,
// hack for the chicken and egg problem // hack for the chicken and egg problem
if (par.inset()) if (par.inset())
top_y(par.outerPar()->y); top_y(text->getPar(par.outerPar()).y);
update(); update();
text->setCursor(cursor(), text->parOffset(cur.pit()), cur.pos()); text->setCursor(cursor(), cur.par(), cur.pos());
cursor().updatePos(); cursor().updatePos();
if (length) { if (length) {
text->setSelectionRange(cursor(), length); setSelectionRange(cursor(), length);
cursor().setSelection(); cursor().setSelection();
if (backwards) { if (backwards) {
#if 0 DocumentIterator const it = cursor();
swap(cursor().cursor_, cursor().anchor_);
#else
DocumentIterator it = cursor();
cursor().setCursor(cursor().anchor_, false); cursor().setCursor(cursor().anchor_, false);
cursor().anchor_ = it; cursor().anchor_ = it;
#endif
} }
} }

View File

@ -23,6 +23,7 @@
class Buffer; class Buffer;
class Change; class Change;
class DocumentIterator;
class Encoding; class Encoding;
class ErrorList; class ErrorList;
class FuncRequest; class FuncRequest;
@ -35,7 +36,6 @@ class LyXScreen;
class LyXView; class LyXView;
class Painter; class Painter;
class ParIterator; class ParIterator;
class PosIterator;
class TeXErrors; class TeXErrors;
class UpdatableInset; class UpdatableInset;
@ -173,7 +173,8 @@ public:
/// ///
void setCursor(ParIterator const & par, lyx::pos_type pos); void setCursor(ParIterator const & par, lyx::pos_type pos);
/// ///
void putSelectionAt(PosIterator const & cur, int length, bool backwards); void putSelectionAt(DocumentIterator const & cur,
int length, bool backwards);
private: private:
/// ///

View File

@ -334,7 +334,7 @@ void BufferView::Pimpl::setBuffer(Buffer * b)
// hidden. This should go here because some dialogs (eg ToC) // hidden. This should go here because some dialogs (eg ToC)
// require bv_->text. // require bv_->text.
owner_->getDialogs().updateBufferDependent(true); owner_->getDialogs().updateBufferDependent(true);
owner_->setLayout(bv_->text()->getPar(0)->layout()->name()); owner_->setLayout(bv_->text()->getPar(0).layout()->name());
} else { } else {
lyxerr[Debug::INFO] << " No Buffer!" << endl; lyxerr[Debug::INFO] << " No Buffer!" << endl;
// we are closing the buffer, use the first buffer as current // we are closing the buffer, use the first buffer as current
@ -377,21 +377,15 @@ void BufferView::Pimpl::redoCurrentBuffer()
void BufferView::Pimpl::resizeCurrentBuffer() void BufferView::Pimpl::resizeCurrentBuffer()
{ {
lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl; lyxerr[Debug::INFO] << "resizeCurrentBuffer" << endl;
owner_->busy(true); owner_->busy(true);
owner_->message(_("Formatting document...")); owner_->message(_("Formatting document..."));
LyXText * text = bv_->text(); LyXText * text = bv_->text();
lyxerr << "### resizeCurrentBuffer: text " << text << endl;
if (!text) if (!text)
return; return;
// save the cursor mangled in init
LCursor cur = bv_->cursor();
text->init(bv_); text->init(bv_);
update(); update();
bv_->cursor() = cur;
bv_->cursor().updatePos(); bv_->cursor().updatePos();
fitCursor(); fitCursor();
@ -570,8 +564,7 @@ void BufferView::Pimpl::update()
// check needed to survive LyX startup // check needed to survive LyX startup
if (buffer_) { if (buffer_) {
// update all 'visible' paragraphs // update all 'visible' paragraphs
ParagraphList::iterator beg; lyx::par_type beg, end;
ParagraphList::iterator end;
getParsInRange(buffer_->paragraphs(), getParsInRange(buffer_->paragraphs(),
top_y(), top_y() + workarea().workHeight(), top_y(), top_y() + workarea().workHeight(),
beg, end); beg, end);
@ -618,8 +611,8 @@ Change const BufferView::Pimpl::getCurrentChange()
if (!cur.selection()) if (!cur.selection())
return Change(Change::UNCHANGED); return Change(Change::UNCHANGED);
return text->getPar(cur.selBegin()) return text->getPar(cur.selBegin().par()).
->lookupChangeFull(cur.selBegin().pos()); lookupChangeFull(cur.selBegin().pos());
} }
@ -661,9 +654,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
if (par == buffer_->par_iterator_end()) if (par == buffer_->par_iterator_end())
return; return;
bv_->text()->setCursor( bv_->text()->setCursor(bv_->cursor(), par.pit(),
bv_->cursor(),
bv_->text()->parOffset(par.pit()),
min(par->size(), saved_positions[i].par_pos)); min(par->size(), saved_positions[i].par_pos));
if (i > 0) if (i > 0)
@ -735,7 +726,10 @@ InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
bool cursor_par_seen = false; bool cursor_par_seen = false;
LCursor & cur = bv_->cursor(); LCursor & cur = bv_->cursor();
ParagraphList::iterator pit = bv_->getLyXText()->getPar(cur.par()); #warning FIXME
#if 0
LyXText * = bv_->getLyXText();
ParagraphList::iterator pit = text->getPar(cur.par());
for (; beg != end; ++beg) { for (; beg != end; ++beg) {
if (beg.getPar() == pit) if (beg.getPar() == pit)
@ -754,6 +748,7 @@ InsetBase * BufferView::Pimpl::getInsetByCode(InsetBase::Code code)
return &(*beg); return &(*beg);
} }
} }
#endif
return 0; return 0;
} }
@ -847,97 +842,78 @@ void BufferView::Pimpl::trackChanges()
bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0)
{ {
// // this is only called for mouse related events including
// this is only called for mouse related events (including // LFUN_FILE_OPEN generated by drag-and-drop.
// LFUN_FILE_OPEN generated by drag-and-drop)
//
FuncRequest cmd = cmd0; FuncRequest cmd = cmd0;
// handle drag&deop
if (cmd.action == LFUN_FILE_OPEN) {
owner_->dispatch(cmd);
return true;
}
cmd.y += bv_->top_y(); cmd.y += bv_->top_y();
//lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl; //lyxerr << "*** workAreaDispatch: request: " << cmd << std::endl;
LCursor cur(*bv_); LCursor cur(*bv_);
cur.push(bv_->buffer()->inset()); cur.push(bv_->buffer()->inset());
cur.resetAnchor(); cur.resetAnchor();
cur.selection() = bv_->cursor().selection(); cur.selection() = bv_->cursor().selection();
switch (cmd.action) {
#if 0 // Doesn't go through lyxfunc, so we need to update
case LFUN_MOUSE_MOTION: { // the layout choice etc. ourselves
if (!available())
return false;
FuncRequest cmd1 = cmd;
DispatchResult res = cur.inset().dispatch(cur, cmd);
if (fitCursor() || res.update()) {
update();
cur.updatePos();
}
return true;
}
#else
case LFUN_MOUSE_MOTION:
#endif
case LFUN_MOUSE_PRESS: // e.g. Qt mouse press when no buffer
case LFUN_MOUSE_RELEASE: if (!available())
case LFUN_MOUSE_DOUBLE: return false;
case LFUN_MOUSE_TRIPLE: {
// We pass those directly to the Bufferview, since
// otherwise selection handling breaks down
// Doesn't go through lyxfunc, so we need to update screen().hideCursor();
// the layout choice etc. ourselves
// e.g. Qt mouse press when no buffer // either the inset under the cursor or the
if (!available()) // surrounding LyXText will handle this event.
return false;
screen().hideCursor(); // built temporary path to inset
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y);
lyxerr << "hit inset at tip: " << inset << endl;
lyxerr << "created temp cursor:\n" << cur << endl;
// either the inset under the cursor or the // Try to dispatch to an non-editable inset near this position
// surrounding LyXText will handle this event. // via the temp cursor. If the inset wishes to change the real
// cursor it has to do so explicitly by using
// cur.bv().cursor() = cur; (or similar)'
DispatchResult res;
if (inset)
inset->dispatch(cur, cmd);
// built temporary path to inset // Now dispatch to the real cursor. Any change to the cursor
InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y); // is immediate.
lyxerr << "hit inset at tip: " << inset << endl; if (!res.dispatched())
lyxerr << "created temp cursor:\n" << cur << endl; res = cur.dispatch(cmd);
// Try to dispatch to an non-editable inset near this position // If the request was dispatched the temp cursor should have been
DispatchResult res; // in a way to be used as new 'real' cursor.
if (inset) if (res.dispatched())
inset->dispatch(cur, cmd); bv_->cursor() = cur;
// Dispatch to the temp cursor. // Redraw if requested or necessary.
// An inset (or LyXText) can assign this to bv->cursor() if (res.update())
// if it wishes to do so. update();
if (!res.dispatched()) if (fitCursor())
res = cur.dispatch(cmd); update();
if (fitCursor() || res.update()) // see workAreaKeyPress
update(); cursor_timeout.restart();
screen().showCursor(*bv_);
// see workAreaKeyPress // skip these when selecting
cursor_timeout.restart(); if (cmd.action != LFUN_MOUSE_MOTION) {
screen().showCursor(*bv_); owner_->updateLayoutChoice();
owner_->updateToolbar();
// skip these when selecting
if (cmd.action != LFUN_MOUSE_MOTION) {
owner_->updateLayoutChoice();
owner_->updateToolbar();
}
// slight hack: this is only called currently when we
// clicked somewhere, so we force through the display
// of the new status here.
owner_->clearMessage();
return true;
} }
case LFUN_FILE_OPEN: // slight hack: this is only called currently when we
owner_->dispatch(cmd); // clicked somewhere, so we force through the display
return true; // of the new status here.
owner_->clearMessage();
default:
BOOST_ASSERT(false);
}
return true; return true;
} }

View File

@ -1,3 +1,83 @@
2004-03-25 André Pönitz <poenitz@gmx.net>
* Makefile.am:
* iterators.[Ch]:
* PosIterator.[Ch]: drop PosIterator, replaced by DocumentIterator
* ParagraphList_fwd.h: change ParagraphList to a std::vector
* CutAndPaste.[Ch]: simpler interface by moving some stuff from
text*.C over here. Rename namespace CutAndPaste to lyx::cap
* ParameterStruct.h: merge with ParagraphParameters
* lyxtext.h: remove LyXText::parOffset() and getPar()
* text3.C: Remove all 'manual' update calls. We do now one per user
interaction which is completely sufficient.
* Bidi.C:
* BufferView.[Ch]:
* BufferView_pimpl.C:
* FontIterator.[Ch]:
* MenuBackend.C:
* ParagraphParameters.[Ch]:
* buffer.C:
* buffer.h:
* bufferlist.C:
* cursor.[Ch]:
* cursor_slice.[Ch]:
* dociterator.[Ch]:
* errorlist.[Ch]:
* factory.C:
* lfuns.h:
* lyxfind.C:
* lyxfunc.C:
* output_docbook.[Ch]:
* output_latex.[Ch]:
* output_linuxdoc.[Ch]:
* output_plaintext.[Ch]:
* paragraph.[Ch]:
* paragraph_funcs.[Ch]:
* paragraph_pimpl.[Ch]:
* rowpainter.C:
* tabular.[Ch]:
* text.C:
* text2.C:
* toc.C:
* undo.[Ch]: adjust
* frontends/controllers/ControlDocument.C:
* frontends/controllers/ControlErrorList.C:
* frontends/controllers/ControlSpellchecker.C:
* insets/inset.C:
* insets/inset.h:
* insets/insetbase.h:
* insets/insetbibitem.C:
* insets/insetbox.C:
* insets/insetbranch.C:
* insets/insetcaption.C:
* insets/insetcharstyle.C:
* insets/insetcharstyle.h:
* insets/insetcollapsable.C:
* insets/insetcollapsable.h:
* insets/insetert.C:
* insets/insetfloat.C:
* insets/insetfoot.C:
* insets/insetmarginal.C:
* insets/insetnote.C:
* insets/insetoptarg.C:
* insets/insettabular.C:
* insets/insettext.C:
* insets/insettext.h:
* insets/insetwrap.C:
* mathed/math_mboxinset.C:
* mathed/math_nestinset.C:
* mathed/math_scriptinset.C:
* mathed/math_scriptinset.h:
* support/types.h:
2004-03-24 Angus Leeming <leeming@lyx.org> 2004-03-24 Angus Leeming <leeming@lyx.org>
* BufferView_pimpl.C (cursorToggle): use the cursor toggle to * BufferView_pimpl.C (cursorToggle): use the cursor toggle to

View File

@ -15,20 +15,29 @@
#include "CutAndPaste.h" #include "CutAndPaste.h"
#include "buffer.h" #include "buffer.h"
#include "buffer_funcs.h"
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView.h"
#include "cursor.h"
#include "errorlist.h" #include "errorlist.h"
#include "gettext.h" #include "gettext.h"
#include "iterators.h" #include "iterators.h"
#include "lyxtext.h"
#include "lyxtextclasslist.h" #include "lyxtextclasslist.h"
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "ParagraphList_fwd.h"
#include "undo.h"
#include "insets/insettabular.h" #include "insets/insettabular.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include <boost/tuple/tuple.hpp>
using lyx::pos_type; using lyx::pos_type;
using lyx::par_type;
using lyx::textclass_type; using lyx::textclass_type;
using lyx::support::bformat; using lyx::support::bformat;
@ -40,17 +49,65 @@ using std::vector;
using std::string; using std::string;
typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
namespace { namespace {
typedef std::pair<lyx::par_type, int> PitPosPair;
typedef limited_stack<pair<ParagraphList, textclass_type> > CutStack;
CutStack cuts(10); CutStack cuts(10);
struct resetOwnerAndChanges : public std::unary_function<Paragraph, void> {
void operator()(Paragraph & p) const {
p.cleanChanges();
p.setInsetOwner(0);
}
};
} // namespace anon } // namespace anon
std::vector<string> const namespace lyx {
CutAndPaste::availableSelections(Buffer const & buffer) namespace cap {
int SwitchLayoutsBetweenClasses(textclass_type c1, textclass_type c2,
ParagraphList & pars, ErrorList & errorlist)
{
BOOST_ASSERT(!pars.empty());
int ret = 0;
if (c1 == c2)
return ret;
LyXTextClass const & tclass1 = textclasslist[c1];
LyXTextClass const & tclass2 = textclasslist[c2];
ParIterator end = ParIterator(pars.size(), pars);
for (ParIterator it = ParIterator(0, pars); it != end; ++it) {
string const name = it->layout()->name();
bool hasLayout = tclass2.hasLayout(name);
if (hasLayout)
it->layout(tclass2[name]);
else
it->layout(tclass2.defaultLayout());
if (!hasLayout && name != tclass1.defaultLayoutName()) {
++ret;
string const s = bformat(
_("Layout had to be changed from\n%1$s to %2$s\n"
"because of class conversion from\n%3$s to %4$s"),
name, it->layout()->name(), tclass1.name(), tclass2.name());
// To warn the user that something had to be done.
errorlist.push_back(ErrorItem("Changed Layout", s,
it->id(), 0,
it->size()));
}
}
return ret;
}
std::vector<string> const availableSelections(Buffer const & buffer)
{ {
vector<string> selList; vector<string> selList;
@ -78,55 +135,40 @@ CutAndPaste::availableSelections(Buffer const & buffer)
} }
PitPosPair CutAndPaste::cutSelection(BufferParams const & params, PitPosPair eraseSelection(BufferParams const & params, ParagraphList & pars,
ParagraphList & pars, par_type startpit, par_type endpit,
ParagraphList::iterator startpit, int startpos, int endpos, bool doclear)
ParagraphList::iterator endpit,
int startpos, int endpos,
textclass_type tc, bool doclear)
{ {
copySelection(startpit, endpit, startpos, endpos, tc); if (startpit == pars.size() || (startpos > pars[startpit].size()))
return eraseSelection(params, pars, startpit, endpit, startpos,
endpos, doclear);
}
PitPosPair CutAndPaste::eraseSelection(BufferParams const & params,
ParagraphList & pars,
ParagraphList::iterator startpit,
ParagraphList::iterator endpit,
int startpos, int endpos, bool doclear)
{
if (startpit == pars.end() || (startpos > startpit->size()))
return PitPosPair(endpit, endpos); return PitPosPair(endpit, endpos);
if (endpit == pars.end() || startpit == endpit) { if (endpit == pars.size() || startpit == endpit) {
endpos -= startpit->erase(startpos, endpos); endpos -= pars[startpit].erase(startpos, endpos);
return PitPosPair(endpit, endpos); return PitPosPair(endpit, endpos);
} }
// clear end/begin fragments of the first/last par in selection // clear end/begin fragments of the first/last par in selection
bool all_erased = true; bool all_erased = true;
startpit->erase(startpos, startpit->size()); pars[startpit].erase(startpos, pars[startpit].size());
if (startpit->size() != startpos) if (pars[startpit].size() != startpos)
all_erased = false; all_erased = false;
endpos -= endpit->erase(0, endpos); endpos -= pars[endpit].erase(0, endpos);
if (endpos != 0) if (endpos != 0)
all_erased = false; all_erased = false;
// Loop through the deleted pars if any, erasing as needed // Loop through the deleted pars if any, erasing as needed
ParagraphList::iterator pit = boost::next(startpit); par_type pit = startpit + 1;
while (pit != endpit && pit != pars.end()) { while (pit != endpit && pit != pars.size()) {
ParagraphList::iterator const next = boost::next(pit); par_type const next = pit + 1;
// "erase" the contents of the par // "erase" the contents of the par
pit->erase(0, pit->size()); pars[pit].erase(0, pars[pit].size());
if (!pit->size()) { if (!pars[pit].size()) {
// remove the par if it's now empty // remove the par if it's now empty
pars.erase(pit); pars.erase(pars.begin() + pit);
} else } else
all_erased = false; all_erased = false;
pit = next; pit = next;
@ -141,17 +183,17 @@ PitPosPair CutAndPaste::eraseSelection(BufferParams const & params,
} }
#endif #endif
if (boost::next(startpit) == pars.end()) if (startpit + 1 == pars.size())
return PitPosPair(endpit, endpos); return PitPosPair(endpit, endpos);
if (doclear) { if (doclear) {
boost::next(startpit)->stripLeadingSpaces(); pars[startpit + 1].stripLeadingSpaces();
} }
// paste the paragraphs again, if possible // paste the paragraphs again, if possible
if (all_erased && if (all_erased &&
(startpit->hasSameLayout(*boost::next(startpit)) || (pars[startpit].hasSameLayout(pars[startpit + 1]) ||
boost::next(startpit)->empty())) { pars[startpit + 1].empty())) {
mergeParagraph(params, pars, startpit); mergeParagraph(params, pars, startpit);
// this because endpar gets deleted here! // this because endpar gets deleted here!
endpit = startpit; endpit = startpit;
@ -163,30 +205,16 @@ PitPosPair CutAndPaste::eraseSelection(BufferParams const & params,
} }
namespace { bool copySelection(ParagraphList & pars,
par_type startpit, par_type endpit,
struct resetOwnerAndChanges : public std::unary_function<Paragraph, void> { int start, int end, textclass_type tc)
void operator()(Paragraph & p) const {
p.cleanChanges();
p.setInsetOwner(0);
}
};
} // anon namespace
bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
ParagraphList::iterator endpit,
int start, int end, textclass_type tc)
{ {
BOOST_ASSERT(0 <= start && start <= startpit->size()); BOOST_ASSERT(0 <= start && start <= pars[startpit].size());
BOOST_ASSERT(0 <= end && end <= endpit->size()); BOOST_ASSERT(0 <= end && end <= pars[endpit].size());
BOOST_ASSERT(startpit != endpit || start <= end); BOOST_ASSERT(startpit != endpit || start <= end);
// Clone the paragraphs within the selection. // Clone the paragraphs within the selection.
ParagraphList::iterator postend = boost::next(endpit); ParagraphList paragraphs(pars.begin() + startpit, pars.begin() + endpit + 1);
ParagraphList paragraphs(startpit, postend);
for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges()); for_each(paragraphs.begin(), paragraphs.end(), resetOwnerAndChanges());
// Cut out the end of the last paragraph. // Cut out the end of the last paragraph.
@ -203,46 +231,43 @@ bool CutAndPaste::copySelection(ParagraphList::iterator startpit,
} }
pair<PitPosPair, ParagraphList::iterator> PitPosPair cutSelection(BufferParams const & params, ParagraphList & pars,
CutAndPaste::pasteSelection(Buffer const & buffer, par_type startpit, par_type endpit,
ParagraphList & pars, int startpos, int endpos, textclass_type tc, bool doclear)
ParagraphList::iterator pit, int pos,
textclass_type tc,
ErrorList & errorlist)
{ {
return pasteSelection(buffer, pars, pit, pos, tc, 0, errorlist); copySelection(pars, startpit, endpit, startpos, endpos, tc);
return eraseSelection(params, pars, startpit, endpit, startpos,
endpos, doclear);
} }
pair<PitPosPair, ParagraphList::iterator> pair<PitPosPair, par_type>
CutAndPaste::pasteSelection(Buffer const & buffer, pasteSelection(Buffer const & buffer, ParagraphList & pars,
ParagraphList & pars, par_type pit, int pos,
ParagraphList::iterator pit, int pos, textclass_type tc, size_t cut_index, ErrorList & errorlist)
textclass_type tc, size_t cut_index,
ErrorList & errorlist)
{ {
if (!checkPastePossible()) if (!checkPastePossible())
return make_pair(PitPosPair(pit, pos), pit); return make_pair(PitPosPair(pit, pos), pit);
BOOST_ASSERT (pos <= pit->size()); BOOST_ASSERT (pos <= pars[pit].size());
// Make a copy of the CaP paragraphs. // Make a copy of the CaP paragraphs.
ParagraphList simple_cut_clone = cuts[cut_index].first; ParagraphList insertion = cuts[cut_index].first;
textclass_type const textclass = cuts[cut_index].second; textclass_type const textclass = cuts[cut_index].second;
// Now remove all out of the pars which is NOT allowed in the // Now remove all out of the pars which is NOT allowed in the
// new environment and set also another font if that is required. // new environment and set also another font if that is required.
// Make sure there is no class difference. // Make sure there is no class difference.
SwitchLayoutsBetweenClasses(textclass, tc, simple_cut_clone, SwitchLayoutsBetweenClasses(textclass, tc, insertion,
errorlist); errorlist);
ParagraphList::iterator tmpbuf = simple_cut_clone.begin(); ParagraphList::iterator tmpbuf = insertion.begin();
int depth_delta = pit->params().depth() - tmpbuf->params().depth(); int depth_delta = pars[pit].params().depth() - tmpbuf->params().depth();
Paragraph::depth_type max_depth = pit->getMaxDepthAfter(); Paragraph::depth_type max_depth = pars[pit].getMaxDepthAfter();
for (; tmpbuf != simple_cut_clone.end(); ++tmpbuf) { for (; tmpbuf != insertion.end(); ++tmpbuf) {
// If we have a negative jump so that the depth would // If we have a negative jump so that the depth would
// go below 0 depth then we have to redo the delta to // go below 0 depth then we have to redo the delta to
// this new max depth level so that subsequent // this new max depth level so that subsequent
@ -258,28 +283,26 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
// Only set this from the 2nd on as the 2nd depends // Only set this from the 2nd on as the 2nd depends
// for maxDepth still on pit. // for maxDepth still on pit.
if (tmpbuf != simple_cut_clone.begin()) if (tmpbuf != insertion.begin())
max_depth = tmpbuf->getMaxDepthAfter(); max_depth = tmpbuf->getMaxDepthAfter();
// Set the inset owner of this paragraph. // Set the inset owner of this paragraph.
tmpbuf->setInsetOwner(pit->inInset()); tmpbuf->setInsetOwner(pars[pit].inInset());
for (pos_type i = 0; i < tmpbuf->size(); ++i) { for (pos_type i = 0; i < tmpbuf->size(); ++i) {
if (tmpbuf->getChar(i) == Paragraph::META_INSET) { if (tmpbuf->getChar(i) == Paragraph::META_INSET) {
if (!pit->insetAllowed(tmpbuf->getInset(i)->lyxCode())) if (!pars[pit].insetAllowed(tmpbuf->getInset(i)->lyxCode()))
tmpbuf->erase(i--); tmpbuf->erase(i--);
} }
} }
} }
// Make the buf exactly the same layout than // Make the buf exactly the same layout as the cursor paragraph.
// the cursor paragraph. insertion.begin()->makeSameLayout(pars[pit]);
simple_cut_clone.begin()->makeSameLayout(*pit);
// Prepare the paragraphs and insets for insertion // Prepare the paragraphs and insets for insertion.
// A couple of insets store buffer references so need // A couple of insets store buffer references so need updating.
// updating ParIterator fpit(0, insertion);
ParIterator fpit(simple_cut_clone.begin(), simple_cut_clone); ParIterator fend(insertion.size(), insertion);
ParIterator fend(simple_cut_clone.end(), simple_cut_clone);
for (; fpit != fend; ++fpit) { for (; fpit != fend; ++fpit) {
InsetList::iterator lit = fpit->insetlist.begin(); InsetList::iterator lit = fpit->insetlist.begin();
@ -299,103 +322,242 @@ CutAndPaste::pasteSelection(Buffer const & buffer,
} }
} }
bool paste_the_end = false; // Split the paragraph for inserting the buf if necessary.
bool did_split = false;
// Open the paragraph for inserting the buf if (pars[pit].size() || pit + 1 == pars.size()) {
// if necessary. breakParagraphConservative(buffer.params(), pars, pit, pos);
if (pit->size() > pos || boost::next(pit) == pars.end()) { did_split = true;
breakParagraphConservative(buffer.params(),
pars, pit, pos);
paste_the_end = true;
} }
// Set the end for redoing later.
ParagraphList::iterator endpit = boost::next(boost::next(pit));
// Paste it! // Paste it!
pars.insert(pars.begin() + pit + 1, insertion.begin(), insertion.end());
ParagraphList::iterator past_pit = boost::next(pit); par_type last_paste = pit + insertion.size();
pars.splice(past_pit, simple_cut_clone);
ParagraphList::iterator last_paste = boost::prior(past_pit);
// If we only inserted one paragraph. // If we only inserted one paragraph.
if (boost::next(pit) == last_paste) if (insertion.size() == 1)
last_paste = pit; last_paste = pit;
mergeParagraph(buffer.params(), pars, pit); mergeParagraph(buffer.params(), pars, pit);
// Store the new cursor position. // Store the new cursor position.
pit = last_paste; pit = last_paste;
pos = last_paste->size(); pos = pars[last_paste].size();
// Maybe some pasting. // Maybe some pasting.
if (boost::next(last_paste) != pars.end() && if (did_split && last_paste + 1 != pars.size()) {
paste_the_end) { if (pars[last_paste + 1].hasSameLayout(pars[last_paste])) {
if (boost::next(last_paste)->hasSameLayout(*last_paste)) { mergeParagraph(buffer.params(), pars, last_paste);
mergeParagraph(buffer.params(), pars, } else if (pars[last_paste + 1].empty()) {
last_paste); pars[last_paste + 1].makeSameLayout(pars[last_paste]);
} else if (boost::next(last_paste)->empty()) { mergeParagraph(buffer.params(), pars, last_paste);
boost::next(last_paste)->makeSameLayout(*last_paste); } else if (pars[last_paste].empty()) {
mergeParagraph(buffer.params(), pars, pars[last_paste].makeSameLayout(pars[last_paste]);
last_paste); mergeParagraph(buffer.params(), pars, last_paste);
} else if (last_paste->empty()) {
last_paste->makeSameLayout(*boost::next(last_paste));
mergeParagraph(buffer.params(), pars,
last_paste);
} else } else
boost::next(last_paste)->stripLeadingSpaces(); pars[last_paste + 1].stripLeadingSpaces();
} }
return make_pair(PitPosPair(pit, pos), endpit); return make_pair(PitPosPair(pit, pos), pit + insertion.size() + 1);
} }
int CutAndPaste::nrOfParagraphs() pair<PitPosPair, par_type>
pasteSelection(Buffer const & buffer, ParagraphList & pars,
par_type pit, int pos, textclass_type tc, ErrorList & errorlist)
{
return pasteSelection(buffer, pars, pit, pos, tc, 0, errorlist);
}
int nrOfParagraphs()
{ {
return cuts.empty() ? 0 : cuts[0].first.size(); return cuts.empty() ? 0 : cuts[0].first.size();
} }
int CutAndPaste::SwitchLayoutsBetweenClasses(textclass_type c1, bool checkPastePossible()
textclass_type c2,
ParagraphList & pars,
ErrorList & errorlist)
{
BOOST_ASSERT(!pars.empty());
int ret = 0;
if (c1 == c2)
return ret;
LyXTextClass const & tclass1 = textclasslist[c1];
LyXTextClass const & tclass2 = textclasslist[c2];
ParIterator end = ParIterator(pars.end(), pars);
for (ParIterator it = ParIterator(pars.begin(), pars); it != end; ++it) {
string const name = it->layout()->name();
bool hasLayout = tclass2.hasLayout(name);
if (hasLayout)
it->layout(tclass2[name]);
else
it->layout(tclass2.defaultLayout());
if (!hasLayout && name != tclass1.defaultLayoutName()) {
++ret;
string const s = bformat(
_("Layout had to be changed from\n%1$s to %2$s\n"
"because of class conversion from\n%3$s to %4$s"),
name, it->layout()->name(), tclass1.name(), tclass2.name());
// To warn the user that something had to be done.
errorlist.push_back(ErrorItem("Changed Layout", s,
it->id(), 0,
it->size()));
}
}
return ret;
}
bool CutAndPaste::checkPastePossible()
{ {
return !cuts.empty() && !cuts[0].first.empty(); return !cuts.empty() && !cuts[0].first.empty();
} }
void cutSelection(LCursor & cur, bool doclear, bool realcut)
{
LyXText * text = cur.text();
BOOST_ASSERT(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
// larger the selection the slower LyX will get. This can be
// solved by running the line below only when the selection has
// finished. The solution used currently just works, to make it
// faster we need to be more clever and probably also have more
// calls to stuffClipboard. (Lgb)
cur.bv().stuffClipboard(cur.selectionAsString(true));
// This doesn't make sense, if there is no selection
if (!cur.selection())
return;
// OK, we have a selection. This is always between cur.selBegin()
// and cur.selEnd()
// make sure that the depth behind the selection are restored, too
recordUndoSelection(cur);
par_type begpit = cur.selBegin().par();
par_type endpit = cur.selEnd().par();
int endpos = cur.selEnd().pos();
BufferParams const & bufparams = cur.bv().buffer()->params();
boost::tie(endpit, endpos) = realcut ?
cutSelection(bufparams,
text->paragraphs(),
begpit, endpit,
cur.selBegin().pos(), endpos,
bufparams.textclass,
doclear)
: eraseSelection(bufparams,
text->paragraphs(),
begpit, endpit,
cur.selBegin().pos(), endpos,
doclear);
// sometimes necessary
if (doclear)
text->paragraphs()[begpit].stripLeadingSpaces();
text->redoParagraphs(begpit, begpit + 1);
// cutSelection can invalidate the cursor so we need to set
// it anew. (Lgb)
// we prefer the end for when tracking changes
cur.pos() = endpos;
cur.par() = endpit;
// need a valid cursor. (Lgb)
cur.clearSelection();
text->updateCounters();
}
void copySelection(LCursor & cur)
{
LyXText * text = cur.text();
BOOST_ASSERT(text);
// stuff the selection onto the X clipboard, from an explicit copy request
cur.bv().stuffClipboard(cur.selectionAsString(true));
// this doesn't make sense, if there is no selection
if (!cur.selection())
return;
// ok we have a selection. This is always between cur.selBegin()
// and sel_end cursor
// copy behind a space if there is one
ParagraphList & pars = text->paragraphs();
pos_type pos = cur.selBegin().pos();
par_type par = cur.selBegin().par();
while (pos < pars[par].size()
&& pars[par].isLineSeparator(pos)
&& (par != cur.selEnd().par() || pos < cur.selEnd().pos()))
++pos;
copySelection(pars, par, cur.selEnd().par(),
pos, cur.selEnd().pos(), cur.bv().buffer()->params().textclass);
}
void pasteSelection(LCursor & cur, size_t sel_index)
{
LyXText * text = cur.text();
BOOST_ASSERT(text);
// this does not make sense, if there is nothing to paste
if (!checkPastePossible())
return;
recordUndo(cur);
par_type endpit;
PitPosPair ppp;
ErrorList el;
boost::tie(ppp, endpit) =
pasteSelection(*cur.bv().buffer(),
text->paragraphs(),
cur.par(), cur.pos(),
cur.bv().buffer()->params().textclass,
sel_index, el);
bufferErrors(*cur.bv().buffer(), el);
text->bv()->showErrorList(_("Paste"));
text->redoParagraphs(cur.par(), endpit);
cur.clearSelection();
cur.resetAnchor();
text->setCursor(cur, ppp.first, ppp.second);
cur.setSelection();
text->updateCounters();
}
void setSelectionRange(LCursor & cur, pos_type length)
{
LyXText * text = cur.text();
BOOST_ASSERT(text);
if (!length)
return;
cur.resetAnchor();
while (length--)
text->cursorRight(cur);
cur.setSelection();
}
// simple replacing. The font of the first selected character is used
void replaceSelectionWithString(LCursor & cur, string const & str)
{
LyXText * text = cur.text();
BOOST_ASSERT(text);
recordUndo(cur);
// Get font setting before we cut
pos_type pos = cur.selEnd().pos();
LyXFont const font = text->getPar(cur.selBegin().par()).
getFontSettings(cur.bv().buffer()->params(), cur.selBegin().pos());
// Insert the new string
string::const_iterator cit = str.begin();
string::const_iterator end = str.end();
for (; cit != end; ++cit, ++pos)
text->getPar(cur.selEnd().par()).insertChar(pos, (*cit), font);
// Cut the selection
cutSelection(cur, true, false);
}
void replaceSelection(LCursor & cur)
{
if (cur.selection())
cutSelection(cur, true, false);
}
// only used by the spellchecker
void replaceWord(LCursor & cur, string const & replacestring)
{
LyXText * text = cur.text();
BOOST_ASSERT(text);
replaceSelectionWithString(cur, replacestring);
setSelectionRange(cur, replacestring.length());
// Go back so that replacement string is also spellchecked
for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
text->cursorLeft(cur);
}
} // namespace cap
} // namespace lyx

View File

@ -14,60 +14,45 @@
#ifndef CUTANDPASTE_H #ifndef CUTANDPASTE_H
#define CUTANDPASTE_H #define CUTANDPASTE_H
#include "ParagraphList_fwd.h"
#include "support/types.h" #include "support/types.h"
#include <string> #include <string>
#include <vector> #include <vector>
class Buffer; class Buffer;
class BufferParams;
class ErrorList; class ErrorList;
class LyXTextClass; class LyXTextClass;
class Paragraph; class LCursor;
class ParagraphList;
/// ///
namespace CutAndPaste { namespace lyx {
namespace cap {
/// ///
std::vector<std::string> const availableSelections(Buffer const & buffer); std::vector<std::string> const availableSelections(Buffer const & buffer);
/// ///
PitPosPair cutSelection(BufferParams const & params, void cutSelection(LCursor & cur, bool doclear, bool realcut);
ParagraphList & pars,
ParagraphList::iterator startpit, /**
ParagraphList::iterator endpit, * Sets the selection from the current cursor position to length
int start, int end, lyx::textclass_type tc, * characters to the right. No safety checks.
bool doclear = false); */
/// void setSelectionRange(LCursor & cur, lyx::pos_type length);
PitPosPair eraseSelection(BufferParams const & params, /// simply replace using the font of the first selected character
ParagraphList & pars, void replaceSelectionWithString(LCursor & cur, std::string const & str);
ParagraphList::iterator startpit, /// replace selection helper
ParagraphList::iterator endpit, void replaceSelection(LCursor & cur);
int start, int end, bool doclear = false);
///
bool copySelection(ParagraphList::iterator startpit,
ParagraphList::iterator endpit,
int start, int end, lyx::textclass_type tc);
///
std::pair<PitPosPair, ParagraphList::iterator>
pasteSelection(Buffer const & buffer,
ParagraphList & pars,
ParagraphList::iterator pit, int pos,
lyx::textclass_type tc, ErrorList &);
/// ///
std::pair<PitPosPair, ParagraphList::iterator> void cutSelection(LCursor & cur, bool doclear = true, bool realcut = true);
pasteSelection(Buffer const & buffer,
ParagraphList & pars,
ParagraphList::iterator pit, int pos,
lyx::textclass_type tc,
size_t cuts_indexm, ErrorList &);
/// ///
int nrOfParagraphs(); void copySelection(LCursor & cur);
///
void pasteSelection(LCursor & cur, size_t sel_index = 0);
/** Needed to switch between different classes this works /** Needed to switch between different classes. This works
for a list of paragraphs beginning with the specified par for a list of paragraphs beginning with the specified par
return value is the number of wrong conversions. return value is the number of wrong conversions.
*/ */
@ -78,6 +63,10 @@ int SwitchLayoutsBetweenClasses(lyx::textclass_type c1,
/// ///
bool checkPastePossible(); bool checkPastePossible();
} // end of CutAndPaste // only used by the spellchecker
void replaceWord(LCursor & cur, std::string const & replacestring);
} // namespace cap
} // namespce lyx
#endif #endif

View File

@ -12,24 +12,24 @@
#include <config.h> #include <config.h>
#include "lyxtext.h"
#include "FontIterator.h" #include "FontIterator.h"
#include "lyxtext.h"
#include "paragraph.h" #include "paragraph.h"
FontIterator::FontIterator(LyXText const & text, ParagraphList::iterator pit, FontIterator::FontIterator(LyXText const & text, lyx::par_type pit,
lyx::pos_type pos) lyx::pos_type pos)
: text_(text), pit_(pit), pos_(pos), : text_(text), pit_(pit), pos_(pos),
font_(text.getFont(pit, pos)), font_(text.getFont(pit, pos)),
endspan_(pit->getEndPosOfFontSpan(pos)), endspan_(text.getPar(pit).getEndPosOfFontSpan(pos)),
bodypos_(pit->beginOfBody()) bodypos_(text.getPar(pit).beginOfBody())
{} {}
LyXFont FontIterator::operator*() const LyXFont FontIterator::operator*() const
{ {
return font_; return font_;
} }
@ -44,7 +44,7 @@ FontIterator & FontIterator::operator++()
++pos_; ++pos_;
if (pos_ > endspan_ || pos_ == bodypos_) { if (pos_ > endspan_ || pos_ == bodypos_) {
font_ = text_.getFont(pit_, pos_); font_ = text_.getFont(pit_, pos_);
endspan_ = pit_->getEndPosOfFontSpan(pos_); endspan_ = text_.getPar(pit_).getEndPosOfFontSpan(pos_);
} }
return *this; return *this;
} }

View File

@ -20,31 +20,38 @@
#ifndef FONTITERATOR_H #ifndef FONTITERATOR_H
#define FONTITERATOR_H #define FONTITERATOR_H
#include "lyxfont.h" #include "lyxfont.h"
#include "ParagraphList_fwd.h"
#include "support/types.h" #include "support/types.h"
class LyXText; class LyXText;
class FontIterator : std::iterator<std::forward_iterator_tag, LyXFont> class FontIterator : std::iterator<std::forward_iterator_tag, LyXFont>
{ {
public: public:
FontIterator(LyXText const & text, ParagraphList::iterator pit, ///
lyx::pos_type pos); FontIterator(LyXText const & text, lyx::par_type pit, lyx::pos_type pos);
///
LyXFont operator*() const; LyXFont operator*() const;
///
FontIterator & operator++(); FontIterator & operator++();
///
LyXFont * operator->(); LyXFont * operator->();
private: private:
///
LyXText const & text_; LyXText const & text_;
ParagraphList::iterator pit_; ///
lyx::par_type pit_;
///
lyx::pos_type pos_; lyx::pos_type pos_;
///
LyXFont font_; LyXFont font_;
///
lyx::pos_type endspan_; lyx::pos_type endspan_;
///
lyx::pos_type bodypos_; lyx::pos_type bodypos_;
}; };
#endif //FONTITERATOR_H #endif // FONTITERATOR_H

View File

@ -96,7 +96,6 @@ lyx_SOURCES = \
ParagraphList_fwd.h \ ParagraphList_fwd.h \
ParagraphParameters.C \ ParagraphParameters.C \
ParagraphParameters.h \ ParagraphParameters.h \
ParameterStruct.h \
PrinterParams.C \ PrinterParams.C \
PrinterParams.h \ PrinterParams.h \
RowList_fwd.h \ RowList_fwd.h \
@ -242,8 +241,6 @@ lyx_SOURCES = \
paragraph_funcs.h \ paragraph_funcs.h \
paragraph_pimpl.C \ paragraph_pimpl.C \
paragraph_pimpl.h \ paragraph_pimpl.h \
PosIterator.h \
PosIterator.C \
SpellBase.h \ SpellBase.h \
ispell.C \ ispell.C \
ispell.h \ ispell.h \

View File

@ -684,11 +684,11 @@ void expandPasteRecent(Menu & tomenu, LyXView const * view)
if (!view || !view->buffer()) if (!view || !view->buffer())
return; return;
vector<string> const selL = vector<string> const sel =
CutAndPaste::availableSelections(*view->buffer()); lyx::cap::availableSelections(*view->buffer());
vector<string>::const_iterator cit = selL.begin(); vector<string>::const_iterator cit = sel.begin();
vector<string>::const_iterator end = selL.end(); vector<string>::const_iterator end = sel.end();
for (unsigned int index = 0; cit != end; ++cit, ++index) { for (unsigned int index = 0; cit != end; ++cit, ++index) {
tomenu.add(MenuItem(MenuItem::Command, *cit, tomenu.add(MenuItem(MenuItem::Command, *cit,

View File

@ -12,13 +12,22 @@
#ifndef PARAGRAPH_LIST_FWD_H #ifndef PARAGRAPH_LIST_FWD_H
#define PARAGRAPH_LIST_FWD_H #define PARAGRAPH_LIST_FWD_H
#include <list> #include <vector>
#include <utility>
class Paragraph; class Paragraph;
typedef std::list<Paragraph> ParagraphList; class ParagraphList : public std::vector<Paragraph>
{
typedef std::pair<ParagraphList::iterator, int> PitPosPair; public:
///
typedef std::vector<Paragraph> base_type;
///
ParagraphList();
///
template <class Iter>
ParagraphList(Iter beg, Iter end)
: base_type(beg, end)
{}
};
#endif #endif

View File

@ -23,7 +23,6 @@
#include "lyxlex.h" #include "lyxlex.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "paragraph.h" #include "paragraph.h"
#include "ParameterStruct.h"
#include "tex-strings.h" #include "tex-strings.h"
#include "frontends/LyXView.h" #include "frontends/LyXView.h"
@ -39,169 +38,133 @@ using std::ostringstream;
using std::string; using std::string;
// Initialize static member var.
ShareContainer<ParameterStruct> ParagraphParameters::container;
ParagraphParameters::ParagraphParameters() ParagraphParameters::ParagraphParameters()
{ : noindent_(false),
ParameterStruct tmp; start_of_appendix_(false), appendix_(false),
set_from_struct(tmp); align_(LYX_ALIGN_LAYOUT), depth_(0)
} {}
void ParagraphParameters::clear() void ParagraphParameters::clear()
{ {
ParameterStruct tmp(*param); operator=(ParagraphParameters());
tmp.spacing.set(Spacing::Default);
tmp.align = LYX_ALIGN_LAYOUT;
tmp.depth = 0;
tmp.noindent = false;
tmp.labelstring.erase();
tmp.labelwidthstring.erase();
tmp.start_of_appendix = false;
set_from_struct(tmp);
} }
ParagraphParameters::depth_type ParagraphParameters::depth() const ParagraphParameters::depth_type ParagraphParameters::depth() const
{ {
return param->depth; return depth_;
} }
bool ParagraphParameters::sameLayout(ParagraphParameters const & pp) const bool ParagraphParameters::sameLayout(ParagraphParameters const & pp) const
{ {
return param->align == pp.param->align && return align_ == pp.align_
param->spacing == pp.param->spacing && && spacing_ == pp.spacing_
param->noindent == pp.param->noindent && && noindent_ == pp.noindent_
param->depth == pp.param->depth; && depth_ == pp.depth_;
}
void ParagraphParameters::set_from_struct(ParameterStruct const & ps)
{
// get new param from container with tmp as template
param = container.get(ps);
} }
Spacing const & ParagraphParameters::spacing() const Spacing const & ParagraphParameters::spacing() const
{ {
return param->spacing; return spacing_;
} }
void ParagraphParameters::spacing(Spacing const & s) void ParagraphParameters::spacing(Spacing const & s)
{ {
ParameterStruct tmp(*param); spacing_ = s;
tmp.spacing = s;
set_from_struct(tmp);
} }
bool ParagraphParameters::noindent() const bool ParagraphParameters::noindent() const
{ {
return param->noindent; return noindent_;
} }
void ParagraphParameters::noindent(bool ni) void ParagraphParameters::noindent(bool ni)
{ {
ParameterStruct tmp(*param); noindent_ = ni;
tmp.noindent = ni;
set_from_struct(tmp);
} }
LyXAlignment ParagraphParameters::align() const LyXAlignment ParagraphParameters::align() const
{ {
return param->align; return align_;
} }
void ParagraphParameters::align(LyXAlignment la) void ParagraphParameters::align(LyXAlignment la)
{ {
ParameterStruct tmp(*param); align_ = la;
tmp.align = la;
set_from_struct(tmp);
} }
void ParagraphParameters::depth(depth_type d) void ParagraphParameters::depth(depth_type d)
{ {
ParameterStruct tmp(*param); depth_ = d;
tmp.depth = d;
set_from_struct(tmp);
} }
bool ParagraphParameters::startOfAppendix() const bool ParagraphParameters::startOfAppendix() const
{ {
return param->start_of_appendix; return start_of_appendix_;
} }
void ParagraphParameters::startOfAppendix(bool soa) void ParagraphParameters::startOfAppendix(bool soa)
{ {
ParameterStruct tmp(*param); start_of_appendix_ = soa;
tmp.start_of_appendix = soa;
set_from_struct(tmp);
} }
bool ParagraphParameters::appendix() const bool ParagraphParameters::appendix() const
{ {
return param->appendix; return appendix_;
} }
void ParagraphParameters::appendix(bool a) void ParagraphParameters::appendix(bool a)
{ {
ParameterStruct tmp(*param); appendix_ = a;
tmp.appendix = a;
set_from_struct(tmp);
} }
string const & ParagraphParameters::labelString() const string const & ParagraphParameters::labelString() const
{ {
return param->labelstring; return labelstring_;
} }
void ParagraphParameters::labelString(string const & ls) void ParagraphParameters::labelString(string const & ls)
{ {
ParameterStruct tmp(*param); labelstring_ = ls;
tmp.labelstring = ls;
set_from_struct(tmp);
} }
string const & ParagraphParameters::labelWidthString() const string const & ParagraphParameters::labelWidthString() const
{ {
return param->labelwidthstring; return labelwidthstring_;
} }
void ParagraphParameters::labelWidthString(string const & lws) void ParagraphParameters::labelWidthString(string const & lws)
{ {
ParameterStruct tmp(*param); labelwidthstring_ = lws;
tmp.labelwidthstring = lws;
set_from_struct(tmp);
} }
LyXLength const & ParagraphParameters::leftIndent() const LyXLength const & ParagraphParameters::leftIndent() const
{ {
return param->leftindent; return leftindent_;
} }
void ParagraphParameters::leftIndent(LyXLength const & li) void ParagraphParameters::leftIndent(LyXLength const & li)
{ {
ParameterStruct tmp(*param); leftindent_ = li;
tmp.leftindent = li;
set_from_struct(tmp);
} }
@ -323,3 +286,22 @@ void params2string(Paragraph const & par, string & data)
data = os.str(); data = os.str();
} }
/*
bool operator==(ParagraphParameeters const & ps1,
ParagraphParameeters const & ps2)
{
return
ps1.spacing == ps2.spacing
&& ps1.noindent == ps2.noindent
&& ps1.align == ps2.align
&& ps1.depth == ps2.depth
&& ps1.start_of_appendix == ps2.start_of_appendix
&& ps1.appendix == ps2.appendix
&& ps1.labelstring == ps2.labelstring
&& ps1.labelwidthstring == ps2.labelwidthstring
&& ps1.leftindent == ps2.leftindent;
}
*/

View File

@ -15,7 +15,8 @@
#define PARAGRAPHPARAMETERS_H #define PARAGRAPHPARAMETERS_H
#include "layout.h" #include "layout.h"
#include "ShareContainer.h" #include "lyxlength.h"
#include "Spacing.h"
#include "support/types.h" #include "support/types.h"
@ -26,7 +27,6 @@ class BufferView;
class LyXLength; class LyXLength;
class LyXLex; class LyXLex;
class Paragraph; class Paragraph;
class ParameterStruct;
class Spacing; class Spacing;
@ -84,16 +84,32 @@ public:
/// write out the parameters to a stream /// write out the parameters to a stream
void write(std::ostream & os) const; void write(std::ostream & os) const;
//friend bool operator==(ParameterStruct const & ps1,
//ParameterStruct const & ps2);
private: private:
/// ///
void set_from_struct(ParameterStruct const &); Spacing spacing_;
/// ///
boost::shared_ptr<ParameterStruct> param; bool noindent_;
/// ///
static ShareContainer<ParameterStruct> container; bool start_of_appendix_;
///
bool appendix_;
///
LyXAlignment align_;
///
depth_type depth_;
///
std::string labelstring_;
///
std::string labelwidthstring_;
///
LyXLength leftindent_;
}; };
/** Generate a string \param data from \param par's ParagraphParameters. /** Generate a string \param data from \param par's ParagraphParameters.
The function also generates some additional info needed by the The function also generates some additional info needed by the
Paragraph dialog. Paragraph dialog.

View File

@ -1,73 +0,0 @@
// -*- C++ -*-
/**
* \file ParameterStruct.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
*
* Full author contact details are available in file CREDITS.
*/
#ifndef PARAMETERSTRUCT_H
#define PARAMETERSTRUCT_H
#include "layout.h"
#include "lyxlength.h"
#include "Spacing.h"
#include "support/types.h"
///
struct ParameterStruct {
///
typedef lyx::depth_type depth_type;
///
ParameterStruct();
///
Spacing spacing;
///
bool noindent;
///
LyXAlignment align;
///
depth_type depth;
///
bool start_of_appendix;
///
bool appendix;
///
std::string labelstring;
///
std::string labelwidthstring;
///
LyXLength leftindent;
};
inline
ParameterStruct::ParameterStruct()
: noindent(false),
align(LYX_ALIGN_BLOCK), depth(0), start_of_appendix(false),
appendix(false)
{}
inline
bool operator==(ParameterStruct const & ps1,
ParameterStruct const & ps2)
{
return
ps1.spacing == ps2.spacing
&& ps1.noindent == ps2.noindent
&& ps1.align == ps2.align
&& ps1.depth == ps2.depth
&& ps1.start_of_appendix == ps2.start_of_appendix
&& ps1.appendix == ps2.appendix
&& ps1.labelstring == ps2.labelstring
&& ps1.labelwidthstring == ps2.labelwidthstring
&& ps1.leftindent == ps2.leftindent;
}
#endif

View File

@ -1,173 +0,0 @@
/* \file PosIterator.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alfredo Braunstein
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "PosIterator.h"
#include "buffer.h"
#include "BufferView.h"
#include "cursor.h"
#include "iterators.h"
#include "lyxtext.h"
#include "paragraph.h"
#include "insets/insettext.h"
#include "insets/updatableinset.h"
#include "insets/inset.h"
#include <boost/next_prior.hpp>
using boost::prior;
PosIterator::PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
lyx::pos_type pos)
{
stack_.push_back(PosIteratorItem(pl, pit, pos));
}
PosIterator::PosIterator(BufferView & bv)
{
LCursor & cur = bv.cursor();
BOOST_ASSERT(cur.inTexted());
LyXText * text = cur.text();
lyx::pos_type pos = cur.pos();
ParagraphList::iterator pit = text->getPar(cur.par());
ParIterator par = bv.buffer()->par_iterator_begin();
ParIterator end = bv.buffer()->par_iterator_end();
for (; par != end; ++par) {
if (par.pit() == pit)
break;
}
setFrom(par, pos);
}
PosIterator::PosIterator(ParIterator const & par, lyx::pos_type pos)
{
setFrom(par, pos);
}
void PosIterator::setFrom(ParIterator const & par, lyx::pos_type pos)
{
BOOST_ASSERT(par.size() > 0);
ParIterator::PosHolder const & ph = par.positions();
int const last = par.size() - 1;
for (int i = 0; i < last; ++i) {
ParPosition const & pp = ph[i];
stack_.push_back(
PosIteratorItem(const_cast<ParagraphList *>(pp.plist),
pp.pit, (*pp.it)->pos, *pp.index + 1));
}
ParPosition const & pp = ph[last];
stack_.push_back(
PosIteratorItem(const_cast<ParagraphList *>(pp.plist), pp.pit, pos, 0));
}
PosIterator & PosIterator::operator++()
{
BOOST_ASSERT(!stack_.empty());
while (true) {
PosIteratorItem & p = stack_.back();
if (p.pos < p.pit->size()) {
if (InsetBase * inset = p.pit->getInset(p.pos)) {
if (LyXText * text = inset->getText(p.index)) {
ParagraphList & pl = text->paragraphs();
p.index++;
stack_.push_back(PosIteratorItem(&pl, pl.begin(), 0));
return *this;
}
}
p.index = 0;
++p.pos;
} else {
++p.pit;
p.pos = 0;
}
if (p.pit != p.pl->end() || stack_.size() == 1)
return *this;
stack_.pop_back();
}
return *this;
}
PosIterator & PosIterator::operator--()
{
BOOST_ASSERT(!stack_.empty());
// try to go one position backwards: if on the start of the
// ParagraphList, pops an item
PosIteratorItem & p = stack_.back();
if (p.pos > 0) {
--p.pos;
InsetBase * inset = p.pit->getInset(p.pos);
if (inset)
p.index = inset->nargs();
} else {
if (p.pit == p.pl->begin()) {
if (stack_.size() == 1)
return *this;
stack_.pop_back();
--stack_.back().index;
} else {
--p.pit;
p.pos = p.pit->size();
}
}
// try to push an item if there is some left unexplored
PosIteratorItem & q = stack_.back();
if (q.pos < q.pit->size()) {
InsetBase * inset = q.pit->getInset(q.pos);
if (inset && q.index > 0) {
LyXText * text = inset->getText(q.index - 1);
BOOST_ASSERT(text);
ParagraphList & pl = text->paragraphs();
stack_.push_back(PosIteratorItem(&pl, prior(pl.end()), pl.back().size()));
}
}
return *this;
}
bool operator==(PosIterator const & lhs, PosIterator const & rhs)
{
PosIteratorItem const & li = lhs.stack_.back();
PosIteratorItem const & ri = rhs.stack_.back();
return (li.pl == ri.pl && li.pit == ri.pit &&
(li.pit == li.pl->end() || li.pos == ri.pos));
}
bool PosIterator::at_end() const
{
return pos() == pit()->size();
}
InsetBase * PosIterator::inset() const
{
if (stack_.size() == 1)
return 0;
PosIteratorItem const & pi = stack_[stack_.size() - 2];
return pi.pit->getInset(pi.pos);
}

View File

@ -1,75 +0,0 @@
// -*- C++ -*-
/* \file PosIterator.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Alfredo Braunstein
*
* Full author contact details are available in file CREDITS.
*/
#ifndef POSITERATOR_H
#define POSITERATOR_H
#include "ParagraphList_fwd.h"
#include "iterators.h"
#include "support/types.h"
#include <vector>
class BufferView;
struct PosIteratorItem {
PosIteratorItem(ParagraphList * pl,
ParagraphList::iterator pit,
lyx::pos_type pos,
int index = 0)
: pl(pl), pit(pit), pos(pos), index(index) {};
ParagraphList * pl;
ParagraphList::iterator pit;
lyx::pos_type pos;
int index;
};
class PosIterator : public std::iterator<
std::bidirectional_iterator_tag,
ParagraphList::value_type> {
public:
// Creates a singular.
PosIterator() {};
PosIterator(BufferView & bv);
PosIterator(ParagraphList * pl, ParagraphList::iterator pit,
lyx::pos_type pos);
PosIterator(ParIterator const & par, lyx::pos_type pos);
PosIterator & operator++();
PosIterator & operator--();
friend bool operator==(PosIterator const &, PosIterator const &);
ParagraphList::iterator pit() const { return stack_.back().pit; }
lyx::pos_type pos() const { return stack_.back().pos; }
bool at_end() const;
InsetBase * inset() const;
friend ParIterator::ParIterator(PosIterator const &);
private:
void setFrom(ParIterator const & par, lyx::pos_type pos);
// This is conceptually a stack,
// but we need random access sometimes.
std::vector<PosIteratorItem> stack_;
};
bool operator==(PosIterator const &, PosIterator const &);
inline
bool operator!=(PosIterator const & lhs, PosIterator const & rhs)
{
return !(lhs == rhs);
}
#endif

View File

@ -43,7 +43,6 @@
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "PosIterator.h"
#include "sgml.h" #include "sgml.h"
#include "texrow.h" #include "texrow.h"
#include "undo.h" #include "undo.h"
@ -76,10 +75,8 @@
#include <utime.h> #include <utime.h>
#ifdef HAVE_LOCALE
#endif
using lyx::pos_type; using lyx::pos_type;
using lyx::par_type;
using lyx::support::AddName; using lyx::support::AddName;
using lyx::support::atoi; using lyx::support::atoi;
@ -202,7 +199,6 @@ Buffer::Buffer(string const & file, bool ronly)
: pimpl_(new Impl(*this, file, ronly)) : pimpl_(new Impl(*this, file, ronly))
{ {
lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl; lyxerr[Debug::INFO] << "Buffer::Buffer()" << endl;
lyxerr << "Buffer::Buffer()" << endl;
} }
@ -426,8 +422,6 @@ int Buffer::readHeader(LyXLex & lex)
// Returns false if "\end_document" is not read (Asger) // Returns false if "\end_document" is not read (Asger)
bool Buffer::readBody(LyXLex & lex) bool Buffer::readBody(LyXLex & lex)
{ {
bool the_end_read = false;
if (paragraphs().empty()) { if (paragraphs().empty()) {
readHeader(lex); readHeader(lex);
if (!params().getLyXTextClass().load()) { if (!params().getLyXTextClass().load()) {
@ -446,30 +440,28 @@ bool Buffer::readBody(LyXLex & lex)
tmpbuf.readHeader(lex); tmpbuf.readHeader(lex);
} }
if (text().read(*this, lex)) return text().read(*this, lex);
the_end_read = true;
return the_end_read;
} }
// needed to insert the selection // needed to insert the selection
void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos, void Buffer::insertStringAsLines(ParagraphList & pars,
LyXFont const & fn, string const & str) par_type & par, pos_type & pos,
LyXFont const & fn, string const & str)
{ {
LyXLayout_ptr const & layout = par->layout(); LyXLayout_ptr const & layout = pars[par].layout();
LyXFont font = fn; LyXFont font = fn;
par->checkInsertChar(font); pars[par].checkInsertChar(font);
// insert the string, don't insert doublespace // insert the string, don't insert doublespace
bool space_inserted = true; bool space_inserted = true;
bool autobreakrows = !par->inInset() || bool autobreakrows = !pars[par].inInset() ||
static_cast<InsetText *>(par->inInset())->getAutoBreakRows(); static_cast<InsetText *>(pars[par].inInset())->getAutoBreakRows();
for(string::const_iterator cit = str.begin(); for(string::const_iterator cit = str.begin();
cit != str.end(); ++cit) { cit != str.end(); ++cit) {
if (*cit == '\n') { if (*cit == '\n') {
if (autobreakrows && (!par->empty() || par->allowEmpty())) { if (autobreakrows && (!pars[par].empty() || pars[par].allowEmpty())) {
breakParagraph(params(), paragraphs(), par, pos, breakParagraph(params(), paragraphs(), par, pos,
layout->isEnvironment()); layout->isEnvironment());
++par; ++par;
@ -480,18 +472,18 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
} }
// do not insert consecutive spaces if !free_spacing // do not insert consecutive spaces if !free_spacing
} else if ((*cit == ' ' || *cit == '\t') && } else if ((*cit == ' ' || *cit == '\t') &&
space_inserted && !par->isFreeSpacing()) { space_inserted && !pars[par].isFreeSpacing()) {
continue; continue;
} else if (*cit == '\t') { } else if (*cit == '\t') {
if (!par->isFreeSpacing()) { if (!pars[par].isFreeSpacing()) {
// tabs are like spaces here // tabs are like spaces here
par->insertChar(pos, ' ', font); pars[par].insertChar(pos, ' ', font);
++pos; ++pos;
space_inserted = true; space_inserted = true;
} else { } else {
const pos_type n = 8 - pos % 8; const pos_type n = 8 - pos % 8;
for (pos_type i = 0; i < n; ++i) { for (pos_type i = 0; i < n; ++i) {
par->insertChar(pos, ' ', font); pars[par].insertChar(pos, ' ', font);
++pos; ++pos;
} }
space_inserted = true; space_inserted = true;
@ -501,7 +493,7 @@ void Buffer::insertStringAsLines(ParagraphList::iterator & par, pos_type & pos,
continue; continue;
} else { } else {
// just insert the character // just insert the character
par->insertChar(pos, *cit, font); pars[par].insertChar(pos, *cit, font);
++pos; ++pos;
space_inserted = (*cit == ' '); space_inserted = (*cit == ' ');
} }
@ -520,7 +512,7 @@ bool Buffer::readFile(string const & filename)
// remove dummy empty par // remove dummy empty par
paragraphs().clear(); paragraphs().clear();
bool ret = readFile(filename, paragraphs().end()); bool ret = readFile(filename, paragraphs().size());
// After we have read a file, we must ensure that the buffer // After we have read a file, we must ensure that the buffer
// language is set and used in the gui. // language is set and used in the gui.
@ -531,7 +523,7 @@ bool Buffer::readFile(string const & filename)
} }
bool Buffer::readFile(string const & filename, ParagraphList::iterator pit) bool Buffer::readFile(string const & filename, par_type pit)
{ {
LyXLex lex(0, 0); LyXLex lex(0, 0);
lex.setFile(filename); lex.setFile(filename);
@ -551,8 +543,7 @@ void Buffer::fully_loaded(bool value)
} }
bool Buffer::readFile(LyXLex & lex, string const & filename, bool Buffer::readFile(LyXLex & lex, string const & filename, par_type pit)
ParagraphList::iterator pit)
{ {
BOOST_ASSERT(!filename.empty()); BOOST_ASSERT(!filename.empty());
@ -1300,9 +1291,9 @@ bool Buffer::isMultiLingual() const
void Buffer::inset_iterator::setParagraph() void Buffer::inset_iterator::setParagraph()
{ {
while (pit != pend) { while (pit != pars_->size()) {
it = pit->insetlist.begin(); it = (*pars_)[pit].insetlist.begin();
if (it != pit->insetlist.end()) if (it != (*pars_)[pit].insetlist.end())
return; return;
++pit; ++pit;
} }
@ -1349,41 +1340,27 @@ bool Buffer::hasParWithID(int id) const
} }
PosIterator Buffer::pos_iterator_begin()
{
return PosIterator(&paragraphs(), paragraphs().begin(), 0);
}
PosIterator Buffer::pos_iterator_end()
{
return PosIterator(&paragraphs(), paragraphs().end(), 0);
}
ParIterator Buffer::par_iterator_begin() ParIterator Buffer::par_iterator_begin()
{ {
return ParIterator(paragraphs().begin(), paragraphs()); return ParIterator(0, paragraphs());
} }
ParIterator Buffer::par_iterator_end() ParIterator Buffer::par_iterator_end()
{ {
return ParIterator(paragraphs().end(), paragraphs()); return ParIterator(paragraphs().size(), paragraphs());
} }
ParConstIterator Buffer::par_iterator_begin() const ParConstIterator Buffer::par_iterator_begin() const
{ {
ParagraphList const & pars = paragraphs(); return ParConstIterator(0, paragraphs());
return ParConstIterator(const_cast<ParagraphList&>(pars).begin(), pars);
} }
ParConstIterator Buffer::par_iterator_end() const ParConstIterator Buffer::par_iterator_end() const
{ {
ParagraphList const & pars = paragraphs(); return ParConstIterator(paragraphs().size(), paragraphs());
return ParConstIterator(const_cast<ParagraphList&>(pars).end(), pars);
} }
@ -1486,13 +1463,8 @@ void Buffer::setParentName(string const & name)
} }
Buffer::inset_iterator::inset_iterator() Buffer::inset_iterator::inset_iterator(ParagraphList & pars, base_type p)
: pit(), pend() : pit(p), pars_(&pars)
{}
Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
: pit(p), pend(e)
{ {
setParagraph(); setParagraph();
} }
@ -1500,35 +1472,35 @@ Buffer::inset_iterator::inset_iterator(base_type p, base_type e)
Buffer::inset_iterator Buffer::inset_iterator_begin() Buffer::inset_iterator Buffer::inset_iterator_begin()
{ {
return inset_iterator(paragraphs().begin(), paragraphs().end()); return inset_iterator(paragraphs(), 0);
} }
Buffer::inset_iterator Buffer::inset_iterator_end() Buffer::inset_iterator Buffer::inset_iterator_end()
{ {
return inset_iterator(paragraphs().end(), paragraphs().end()); return inset_iterator(paragraphs(), paragraphs().size());
} }
Buffer::inset_iterator Buffer::inset_const_iterator_begin() const Buffer::inset_iterator Buffer::inset_const_iterator_begin() const
{ {
ParagraphList & pars = const_cast<ParagraphList&>(paragraphs()); ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
return inset_iterator(pars.begin(), pars.end()); return inset_iterator(pars, 0);
} }
Buffer::inset_iterator Buffer::inset_const_iterator_end() const Buffer::inset_iterator Buffer::inset_const_iterator_end() const
{ {
ParagraphList & pars = const_cast<ParagraphList&>(paragraphs()); ParagraphList & pars = const_cast<ParagraphList&>(paragraphs());
return inset_iterator(pars.end(), pars.end()); return inset_iterator(pars, pars.size());
} }
Buffer::inset_iterator & Buffer::inset_iterator::operator++() Buffer::inset_iterator & Buffer::inset_iterator::operator++()
{ {
if (pit != pend) { if (pit != pars_->size()) {
++it; ++it;
if (it == pit->insetlist.end()) { if (it == (*pars_)[pit].insetlist.end()) {
++pit; ++pit;
setParagraph(); setParagraph();
} }
@ -1557,7 +1529,7 @@ Buffer::inset_iterator::pointer Buffer::inset_iterator::operator->()
} }
ParagraphList::iterator Buffer::inset_iterator::getPar() const lyx::par_type Buffer::inset_iterator::getPar() const
{ {
return pit; return pit;
} }
@ -1572,8 +1544,7 @@ lyx::pos_type Buffer::inset_iterator::getPos() const
bool operator==(Buffer::inset_iterator const & iter1, bool operator==(Buffer::inset_iterator const & iter1,
Buffer::inset_iterator const & iter2) Buffer::inset_iterator const & iter2)
{ {
return iter1.pit == iter2.pit return iter1.pit == iter2.pit && iter1.it == iter2.it;
&& (iter1.pit == iter1.pend || iter1.it == iter2.it);
} }

View File

@ -13,7 +13,6 @@
#define BUFFER_H #define BUFFER_H
#include "InsetList.h" #include "InsetList.h"
#include "ParagraphList_fwd.h"
#include "support/limited_stack.h" #include "support/limited_stack.h"
#include "support/types.h" #include "support/types.h"
@ -42,9 +41,9 @@ class LaTeXFeatures;
class Language; class Language;
class Messages; class Messages;
class OutputParams; class OutputParams;
class ParIterator; class ParagraphList;
class PosIterator;
class ParConstIterator; class ParConstIterator;
class ParIterator;
class TeXErrors; class TeXErrors;
class TexRow; class TexRow;
class Undo; class Undo;
@ -87,7 +86,7 @@ public:
/// load a new file /// load a new file
bool readFile(std::string const & filename); bool readFile(std::string const & filename);
bool readFile(std::string const & filename, ParagraphList::iterator pit); bool readFile(std::string const & filename, lyx::par_type pit);
/// read the header, returns number of unknown tokens /// read the header, returns number of unknown tokens
int readHeader(LyXLex & lex); int readHeader(LyXLex & lex);
@ -99,8 +98,9 @@ public:
bool readBody(LyXLex &); bool readBody(LyXLex &);
/// ///
void insertStringAsLines(ParagraphList::iterator &, lyx::pos_type &, void insertStringAsLines(ParagraphList & plist,
LyXFont const &, std::string const &); lyx::par_type &, lyx::pos_type &,
LyXFont const &, std::string const &);
/// ///
ParIterator getParFromID(int id) const; ParIterator getParFromID(int id) const;
/// do we have a paragraph with this id? /// do we have a paragraph with this id?
@ -288,14 +288,10 @@ public:
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef InsetBase * pointer; typedef InsetBase * pointer;
typedef InsetBase & reference; typedef InsetBase & reference;
typedef ParagraphList::iterator base_type; typedef lyx::par_type base_type;
/// ///
inset_iterator(); inset_iterator(ParagraphList & pars, base_type p);
///
inset_iterator(base_type p, base_type e);
///
inset_iterator(base_type p, lyx::pos_type pos, base_type e);
/// prefix ++ /// prefix ++
inset_iterator & operator++(); inset_iterator & operator++();
@ -307,7 +303,7 @@ public:
pointer operator->(); pointer operator->();
/// ///
ParagraphList::iterator getPar() const; lyx::par_type getPar() const;
/// ///
lyx::pos_type getPos() const; lyx::pos_type getPos() const;
/// ///
@ -318,11 +314,11 @@ public:
/// ///
void setParagraph(); void setParagraph();
/// ///
ParagraphList::iterator pit; lyx::par_type pit;
///
ParagraphList::iterator pend;
/// ///
InsetList::iterator it; InsetList::iterator it;
public:
ParagraphList * pars_;
}; };
/// return an iterator to all *top-level* insets in the buffer /// return an iterator to all *top-level* insets in the buffer
@ -337,10 +333,6 @@ public:
/// return the const end of all *top-level* insets in the buffer /// return the const end of all *top-level* insets in the buffer
inset_iterator inset_const_iterator_end() const; inset_iterator inset_const_iterator_end() const;
///
PosIterator pos_iterator_begin();
///
PosIterator pos_iterator_end();
/// ///
ParIterator par_iterator_begin(); ParIterator par_iterator_begin();
/// ///
@ -369,7 +361,7 @@ private:
\return \c false if method fails. \return \c false if method fails.
*/ */
bool readFile(LyXLex &, std::string const & filename, bool readFile(LyXLex &, std::string const & filename,
ParagraphList::iterator pit); lyx::par_type pit);
bool do_writeFile(std::ostream & ofs) const; bool do_writeFile(std::ostream & ofs) const;

View File

@ -22,6 +22,7 @@
#include "lyx_main.h" #include "lyx_main.h"
#include "output_latex.h" #include "output_latex.h"
#include "paragraph.h" #include "paragraph.h"
#include "ParagraphList_fwd.h"
#include "frontends/Alert.h" #include "frontends/Alert.h"

View File

@ -15,6 +15,7 @@
#include "BufferView.h" #include "BufferView.h"
#include "buffer.h" #include "buffer.h"
#include "cursor.h" #include "cursor.h"
#include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "encoding.h" #include "encoding.h"
@ -45,6 +46,8 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
using lyx::par_type;
using std::string; using std::string;
using std::vector; using std::vector;
using std::endl; using std::endl;
@ -91,7 +94,6 @@ void LCursor::reset(InsetBase & inset)
clear(); clear();
push_back(CursorSlice(inset)); push_back(CursorSlice(inset));
anchor_.clear(); anchor_.clear();
anchor_.push_back(CursorSlice(inset));
cached_y_ = 0; cached_y_ = 0;
clearTargetX(); clearTargetX();
selection_ = false; selection_ = false;
@ -109,10 +111,10 @@ void LCursor::setCursor(DocumentIterator const & cur, bool sel)
DispatchResult LCursor::dispatch(FuncRequest const & cmd0) DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
{ {
lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
if (empty()) if (empty())
return DispatchResult(); return DispatchResult();
//lyxerr << "\nLCursor::dispatch: cmd: " << cmd0 << endl << *this << endl;
FuncRequest cmd = cmd0; FuncRequest cmd = cmd0;
LCursor safe = *this; LCursor safe = *this;
@ -133,15 +135,21 @@ DispatchResult LCursor::dispatch(FuncRequest const & cmd0)
} }
// it completely to get a 'bomb early' behaviour in case this // it completely to get a 'bomb early' behaviour in case this
// object will be used again. // object will be used again.
if (!disp_.dispatched()) if (!disp_.dispatched()) {
lyxerr << "RESTORING OLD CURSOR!" << endl;
operator=(safe); operator=(safe);
}
return disp_; return disp_;
} }
bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status) bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
{ {
// This is, of course, a mess. Better create a new doc iterator and use
// this in Inset::getStatus. This might require an additional
// BufferView * arg, though (which should be avoided)
LCursor safe = *this; LCursor safe = *this;
bool res = false;
for ( ; size(); pop()) { for ( ; size(); pop()) {
//lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl; //lyxerr << "\nLCursor::getStatus: cmd: " << cmd << endl << *this << endl;
BOOST_ASSERT(pos() <= lastpos()); BOOST_ASSERT(pos() <= lastpos());
@ -152,11 +160,13 @@ bool LCursor::getStatus(FuncRequest const & cmd, FuncStatus & status)
// a definitive decision on whether it want to handle the // a definitive decision on whether it want to handle the
// request or not. The result of this decision is put into // request or not. The result of this decision is put into
// the 'status' parameter. // the 'status' parameter.
if (inset().getStatus(*this, cmd, status)) if (inset().getStatus(*this, cmd, status)) {
res = true;
break; break;
}
} }
operator=(safe); operator=(safe);
return true; return res;
} }
@ -170,7 +180,6 @@ void LCursor::pop()
{ {
BOOST_ASSERT(size() >= 1); BOOST_ASSERT(size() >= 1);
pop_back(); pop_back();
anchor_.pop_back();
} }
@ -306,12 +315,14 @@ bool LCursor::posRight()
CursorSlice & LCursor::anchor() CursorSlice & LCursor::anchor()
{ {
BOOST_ASSERT(!anchor_.empty());
return anchor_.back(); return anchor_.back();
} }
CursorSlice const & LCursor::anchor() const CursorSlice const & LCursor::anchor() const
{ {
BOOST_ASSERT(!anchor_.empty());
return anchor_.back(); return anchor_.back();
} }
@ -324,15 +335,6 @@ CursorSlice const & LCursor::selBegin() const
} }
CursorSlice & LCursor::selBegin()
{
if (!selection())
return back();
// can't use std::min as this returns a const ref
return anchor() < back() ? anchor() : back();
}
CursorSlice const & LCursor::selEnd() const CursorSlice const & LCursor::selEnd() const
{ {
if (!selection()) if (!selection())
@ -341,12 +343,19 @@ CursorSlice const & LCursor::selEnd() const
} }
CursorSlice & LCursor::selEnd() DocumentIterator LCursor::selectionBegin() const
{ {
if (!selection()) if (!selection())
return back(); return *this;
// can't use std::min as this returns a const ref return anchor() < back() ? anchor_ : *this;
return anchor() > back() ? anchor() : back(); }
DocumentIterator LCursor::selectionEnd() const
{
if (!selection())
return *this;
return anchor() > back() ? anchor_ : *this;
} }
@ -551,9 +560,19 @@ void LCursor::selClearOrDel()
std::ostream & operator<<(std::ostream & os, LCursor const & cur) std::ostream & operator<<(std::ostream & os, LCursor const & cur)
{ {
for (size_t i = 0, n = cur.size(); i != n; ++i) for (size_t i = 0, n = cur.size(); i != n; ++i) {
os << " " << cur.operator[](i) << " | " << cur.anchor_[i] << "\n"; os << " " << cur.operator[](i) << " | ";
os << " selection: " << cur.selection_ << endl; if (i < cur.anchor_.size())
os << cur.anchor_[i];
else
os << "-------------------------------";
os << "\n";
}
for (size_t i = cur.size(), n = cur.anchor_.size(); i < n; ++i) {
os << "------------------------------- | " << cur.anchor_[i] << "\n";
}
os << " selection: " << cur.selection_
<< " x_target: " << cur.x_target_ << endl;
return os; return os;
} }
@ -602,7 +621,7 @@ bool LCursor::openable(MathAtom const & t) const
return true; return true;
// 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 (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset())) if (!ptr_cmp(t.nucleus(), &anchor_[depth()].inset()))
return false; return false;
@ -1092,8 +1111,7 @@ bool LCursor::goUpDown(bool up)
bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh) bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{ {
BOOST_ASSERT(!empty()); BOOST_ASSERT(!empty());
ParagraphList::iterator beg; par_type beg, end;
ParagraphList::iterator end;
CursorSlice bottom = operator[](0); CursorSlice bottom = operator[](0);
LyXText * text = bottom.text(); LyXText * text = bottom.text();
BOOST_ASSERT(text); BOOST_ASSERT(text);
@ -1101,11 +1119,11 @@ bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
DocumentIterator it(bv().buffer()->inset()); DocumentIterator it(bv().buffer()->inset());
DocumentIterator et; DocumentIterator et;
lyxerr << "x: " << x << " y: " << y << endl; //lyxerr << "x: " << x << " y: " << y << endl;
lyxerr << "xlow: " << xlow << " ylow: " << ylow << endl; //lyxerr << "xlow: " << xlow << " ylow: " << ylow << endl;
lyxerr << "xhigh: " << xhigh << " yhigh: " << yhigh << endl; //lyxerr << "xhigh: " << xhigh << " yhigh: " << yhigh << endl;
it.par() = text->parOffset(beg); it.par() = beg;
//et.par() = text->parOffset(end); //et.par() = text->parOffset(end);
double best_dist = 10e10; double best_dist = 10e10;
@ -1119,11 +1137,11 @@ bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
cur.inset().getCursorPos(cur, xo, yo); cur.inset().getCursorPos(cur, xo, yo);
if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
lyxerr << "xo: " << xo << " yo: " << yo << " d: " << d << endl; //lyxerr << "xo: " << xo << " yo: " << yo << " d: " << d << endl;
// '<=' in order to take the last possible position // '<=' in order to take the last possible position
// this is important for clicking behind \sum in e.g. '\sum_i a' // this is important for clicking behind \sum in e.g. '\sum_i a'
if (d <= best_dist) { if (d <= best_dist) {
lyxerr << "*" << endl; //lyxerr << "*" << endl;
best_dist = d; best_dist = d;
best_cursor = it; best_cursor = it;
} }
@ -1131,7 +1149,7 @@ bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
} }
} }
lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl; //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
if (best_dist < 1e10) if (best_dist < 1e10)
setCursor(best_cursor, false); setCursor(best_cursor, false);
return best_dist < 1e10; return best_dist < 1e10;
@ -1238,27 +1256,29 @@ string LCursor::selectionAsString(bool label) const
if (inTexted()) { if (inTexted()) {
Buffer const & buffer = *bv().buffer(); Buffer const & buffer = *bv().buffer();
ParagraphList & pars = text()->paragraphs();
// should be const ... // should be const ...
ParagraphList::iterator startpit = text()->getPar(selBegin()); par_type startpit = selBegin().par();
ParagraphList::iterator endpit = text()->getPar(selEnd()); par_type endpit = selEnd().par();
size_t const startpos = selBegin().pos(); size_t const startpos = selBegin().pos();
size_t const endpos = selEnd().pos(); size_t const endpos = selEnd().pos();
if (startpit == endpit) if (startpit == endpit)
return startpit->asString(buffer, startpos, endpos, label); return pars[startpit].asString(buffer, startpos, endpos, label);
// First paragraph in selection // First paragraph in selection
string result = string result = pars[startpit].
startpit->asString(buffer, startpos, startpit->size(), label) + "\n\n"; asString(buffer, startpos, pars[startpit].size(), label) + "\n\n";
// The paragraphs in between (if any) // The paragraphs in between (if any)
ParagraphList::iterator pit = startpit; for (par_type pit = startpit + 1; pit != endpit; ++pit) {
for (++pit; pit != endpit; ++pit) Paragraph & par = pars[pit];
result += pit->asString(buffer, 0, pit->size(), label) + "\n\n"; result += par.asString(buffer, 0, par.size(), label) + "\n\n";
}
// Last paragraph in selection // Last paragraph in selection
result += endpit->asString(buffer, 0, endpos, label); result += pars[endpit].asString(buffer, 0, endpos, label);
return result; return result;
} }
@ -1283,27 +1303,6 @@ string LCursor::currentState()
} }
// only used by the spellchecker
void LCursor::replaceWord(string const & replacestring)
{
LyXText * t = text();
BOOST_ASSERT(t);
t->replaceSelectionWithString(*this, replacestring);
t->setSelectionRange(*this, replacestring.length());
// Go back so that replacement string is also spellchecked
for (string::size_type i = 0; i < replacestring.length() + 1; ++i)
t->cursorLeft(*this);
}
void LCursor::update()
{
bv().update();
}
string LCursor::getPossibleLabel() string LCursor::getPossibleLabel()
{ {
return inMathed() ? "eq:" : text()->getPossibleLabel(*this); return inMathed() ? "eq:" : text()->getPossibleLabel(*this);
@ -1324,9 +1323,8 @@ Encoding const * LCursor::getEncoding() const
break; break;
CursorSlice const & sl = operator[](s); CursorSlice const & sl = operator[](s);
LyXText & text = *sl.text(); LyXText & text = *sl.text();
ParagraphList::iterator pit = text.getPar(sl.par()); LyXFont font = text.getPar(sl.par()).getFont(
LyXFont font = pit->getFont( bv().buffer()->params(), sl.pos(), outerFont(sl.par(), text.paragraphs()));
bv().buffer()->params(), sl.pos(), outerFont(pit, text.paragraphs()));
return font.language()->encoding(); return font.language()->encoding();
} }

View File

@ -73,13 +73,13 @@ public:
/// ///
void clearSelection(); void clearSelection();
/// access start of selection /// access start of selection
CursorSlice & selBegin();
/// access start of selection
CursorSlice const & selBegin() const; CursorSlice const & selBegin() const;
/// access end of selection /// access end of selection
CursorSlice & selEnd();
/// access end of selection
CursorSlice const & selEnd() const; CursorSlice const & selEnd() const;
/// access start of selection
DocumentIterator selectionBegin() const;
/// access start of selection
DocumentIterator selectionEnd() const;
/// ///
std::string grabSelection(); std::string grabSelection();
/// ///

View File

@ -62,42 +62,6 @@ size_t CursorSlice::ncols() const
} }
CursorSlice::idx_type CursorSlice::idx() const
{
return idx_;
}
CursorSlice::idx_type & CursorSlice::idx()
{
return idx_;
}
CursorSlice::par_type CursorSlice::par() const
{
return par_;
}
CursorSlice::par_type & CursorSlice::par()
{
return par_;
}
CursorSlice::pos_type CursorSlice::pos() const
{
return pos_;
}
CursorSlice::pos_type & CursorSlice::pos()
{
return pos_;
}
CursorSlice::pos_type CursorSlice::lastpos() const CursorSlice::pos_type CursorSlice::lastpos() const
{ {
BOOST_ASSERT(inset_); BOOST_ASSERT(inset_);
@ -105,18 +69,6 @@ CursorSlice::pos_type CursorSlice::lastpos() const
} }
bool CursorSlice::boundary() const
{
return boundary_;
}
bool & CursorSlice::boundary()
{
return boundary_;
}
CursorSlice::row_type CursorSlice::row() const CursorSlice::row_type CursorSlice::row() const
{ {
BOOST_ASSERT(asMathInset()); BOOST_ASSERT(asMathInset());
@ -163,7 +115,7 @@ Paragraph & CursorSlice::paragraph()
{ {
// access to the main lyx text must be handled in the cursor // access to the main lyx text must be handled in the cursor
BOOST_ASSERT(text()); BOOST_ASSERT(text());
return *text()->getPar(par_); return text()->getPar(par_);
} }
@ -171,7 +123,7 @@ Paragraph const & CursorSlice::paragraph() const
{ {
// access to the main lyx text must be handled in the cursor // access to the main lyx text must be handled in the cursor
BOOST_ASSERT(text()); BOOST_ASSERT(text());
return *text()->getPar(par_); return text()->getPar(par_);
} }

View File

@ -17,8 +17,6 @@
#ifndef CURSORSLICE_H #ifndef CURSORSLICE_H
#define CURSORSLICE_H #define CURSORSLICE_H
#include "ParagraphList_fwd.h"
#include "support/types.h" #include "support/types.h"
#include <cstddef> #include <cstddef>
@ -45,7 +43,7 @@ public:
/// type for cell number in inset /// type for cell number in inset
typedef size_t idx_type; typedef size_t idx_type;
/// type for paragraph numbers positions within a cell /// type for paragraph numbers positions within a cell
typedef lyx::paroffset_type par_type; typedef lyx::par_type par_type;
/// type for cursor positions within a cell /// type for cursor positions within a cell
typedef lyx::pos_type pos_type; typedef lyx::pos_type pos_type;
/// type for row indices /// type for row indices
@ -61,23 +59,23 @@ public:
/// the current inset /// the current inset
InsetBase & inset() const { return *inset_; } InsetBase & inset() const { return *inset_; }
/// return the cell this cursor is in /// return the cell this cursor is in
idx_type idx() const; idx_type idx() const { return idx_; }
/// return the cell this cursor is in /// return the cell this cursor is in
idx_type & idx(); idx_type & idx() { return idx_; }
/// return the last cell in this inset /// return the last cell in this inset
idx_type lastidx() const { return nargs() - 1; } idx_type lastidx() const { return nargs() - 1; }
/// return the paragraph this cursor is in /// return the paragraph this cursor is in
par_type par() const; par_type par() const { return par_; }
/// set the paragraph this cursor is in /// set the paragraph this cursor is in
par_type & par(); par_type & par() { return par_; }
/// increments the paragraph this cursor is in /// increments the paragraph this cursor is in
void incrementPar(); void incrementPar();
/// increments the paragraph this cursor is in /// increments the paragraph this cursor is in
void decrementPar(); void decrementPar();
/// return the position within the paragraph /// return the position within the paragraph
pos_type pos() const; pos_type pos() const { return pos_; }
/// return the position within the paragraph /// return the position within the paragraph
pos_type & pos(); pos_type & pos() { return pos_; }
/// return the last position within the paragraph /// return the last position within the paragraph
pos_type lastpos() const; pos_type lastpos() const;
/// return the number of embedded cells /// return the number of embedded cells
@ -95,9 +93,9 @@ public:
/// texted specific stuff /// texted specific stuff
/// ///
/// see comment for the member /// see comment for the member
bool boundary() const; bool boundary() const { return boundary_; }
/// see comment for the member /// see comment for the member
bool & boundary(); bool & boundary() { return boundary_; }
/// ///
LyXText * text() const; LyXText * text() const;
/// ///

View File

@ -11,6 +11,8 @@
#include <boost/assert.hpp> #include <boost/assert.hpp>
using std::endl;
DocumentIterator::DocumentIterator() DocumentIterator::DocumentIterator()
{} {}
@ -24,6 +26,7 @@ DocumentIterator::DocumentIterator(InsetBase & inset)
InsetBase * DocumentIterator::nextInset() InsetBase * DocumentIterator::nextInset()
{ {
BOOST_ASSERT(!empty());
if (pos() == lastpos()) if (pos() == lastpos())
return 0; return 0;
if (inMathed()) if (inMathed())
@ -34,6 +37,7 @@ InsetBase * DocumentIterator::nextInset()
InsetBase * DocumentIterator::prevInset() InsetBase * DocumentIterator::prevInset()
{ {
BOOST_ASSERT(!empty());
if (pos() == 0) if (pos() == 0)
return 0; return 0;
if (inMathed()) if (inMathed())
@ -44,6 +48,7 @@ InsetBase * DocumentIterator::prevInset()
InsetBase const * DocumentIterator::prevInset() const InsetBase const * DocumentIterator::prevInset() const
{ {
BOOST_ASSERT(!empty());
if (pos() == 0) if (pos() == 0)
return 0; return 0;
if (inMathed()) if (inMathed())
@ -54,6 +59,7 @@ InsetBase const * DocumentIterator::prevInset() const
MathAtom const & DocumentIterator::prevAtom() const MathAtom const & DocumentIterator::prevAtom() const
{ {
BOOST_ASSERT(!empty());
BOOST_ASSERT(pos() > 0); BOOST_ASSERT(pos() > 0);
return cell()[pos() - 1]; return cell()[pos() - 1];
} }
@ -61,6 +67,7 @@ MathAtom const & DocumentIterator::prevAtom() const
MathAtom & DocumentIterator::prevAtom() MathAtom & DocumentIterator::prevAtom()
{ {
BOOST_ASSERT(!empty());
BOOST_ASSERT(pos() > 0); BOOST_ASSERT(pos() > 0);
return cell()[pos() - 1]; return cell()[pos() - 1];
} }
@ -68,6 +75,7 @@ MathAtom & DocumentIterator::prevAtom()
MathAtom const & DocumentIterator::nextAtom() const MathAtom const & DocumentIterator::nextAtom() const
{ {
BOOST_ASSERT(!empty());
BOOST_ASSERT(pos() < lastpos()); BOOST_ASSERT(pos() < lastpos());
return cell()[pos()]; return cell()[pos()];
} }
@ -75,6 +83,7 @@ MathAtom const & DocumentIterator::nextAtom() const
MathAtom & DocumentIterator::nextAtom() MathAtom & DocumentIterator::nextAtom()
{ {
BOOST_ASSERT(!empty());
BOOST_ASSERT(pos() < lastpos()); BOOST_ASSERT(pos() < lastpos());
return cell()[pos()]; return cell()[pos()];
} }
@ -82,6 +91,7 @@ MathAtom & DocumentIterator::nextAtom()
LyXText * DocumentIterator::text() const LyXText * DocumentIterator::text() const
{ {
BOOST_ASSERT(!empty());
return top().text(); return top().text();
} }
@ -225,11 +235,15 @@ InsetBase * DocumentIterator::innerInsetOfType(int code) const
void DocumentIterator::forwardPos() void DocumentIterator::forwardPos()
{ {
CursorSlice & top = back(); CursorSlice & top = back();
//lyxerr << "XXX\n" << *this << std::endl; //lyxerr << "XXX\n" << *this << endl;
// this is used twice and shows up in the profiler!
pos_type const lastp = lastpos();
// move into an inset to the right if possible // move into an inset to the right if possible
InsetBase * n = 0; InsetBase * n = 0;
if (top.pos() != lastpos()) {
if (top.pos() != lastp) {
// this is impossible for pos() == size() // this is impossible for pos() == size()
if (inMathed()) { if (inMathed()) {
n = (top.cell().begin() + top.pos())->nucleus(); n = (top.cell().begin() + top.pos())->nucleus();
@ -240,56 +254,65 @@ void DocumentIterator::forwardPos()
} }
if (n && n->isActive()) { if (n && n->isActive()) {
//lyxerr << "... descend" << std::endl; //lyxerr << "... descend" << endl;
push_back(CursorSlice(*n)); push_back(CursorSlice(*n));
return; return;
} }
// otherwise move on one cell back if possible // otherwise move on one position if possible
if (top.pos() < lastpos()) { if (top.pos() < lastp) {
//lyxerr << "... next pos" << std::endl; //lyxerr << "... next pos" << endl;
++top.pos(); ++top.pos();
return; return;
} }
//lyxerr << "... no next pos" << std::endl; //lyxerr << "... no next pos" << endl;
// otherwise move on one cell back if possible // otherwise move on one paragraph if possible
if (top.par() < lastpar()) { if (top.par() < lastpar()) {
//lyxerr << "... next par" << std::endl; //lyxerr << "... next par" << endl;
++top.par(); ++top.par();
top.pos() = 0; top.pos() = 0;
return; return;
} }
//lyxerr << "... no next par" << std::endl; //lyxerr << "... no next par" << endl;
// otherwise try to move on one cell if possible // otherwise try to move on one cell if possible
// [stupid hack for necessary for MathScriptInset] if (top.idx() < lastidx()) {
while (top.idx() < lastidx()) { //lyxerr << "... next idx" << endl;
//lyxerr << "... next idx" << std::endl;
++top.idx(); ++top.idx();
top.par() = 0; top.par() = 0;
top.pos() = 0; top.pos() = 0;
if (top.inset().validCell(top.idx())) { return;
//lyxerr << " ... ok" << std::endl;
return;
}
} }
//lyxerr << "... no next idx" << std::endl; //lyxerr << "... no next idx" << endl;
// otherwise leave inset an jump over inset as a whole // otherwise leave inset and jump over inset as a whole
pop_back(); pop_back();
// 'top' is invalid now... // 'top' is invalid now...
if (size()) if (size())
++back().pos(); ++back().pos();
//else }
// lyxerr << "... no slice left" << std::endl;
void DocumentIterator::forwardChar()
{
forwardPos();
while (size() != 0 && pos() == lastpos())
forwardPos();
}
void DocumentIterator::backwardChar()
{
lyxerr << "not implemented" << endl;
BOOST_ASSERT(false);
} }
void DocumentIterator::forwardPar() void DocumentIterator::forwardPar()
{ {
CursorSlice & top = back(); CursorSlice & top = back();
lyxerr << "XXX " << *this << std::endl; lyxerr << "XXX " << *this << endl;
// move into an inset to the right if possible // move into an inset to the right if possible
InsetBase * n = 0; InsetBase * n = 0;
@ -304,38 +327,34 @@ void DocumentIterator::forwardPar()
} }
if (n && n->isActive()) { if (n && n->isActive()) {
lyxerr << "... descend" << std::endl; lyxerr << "... descend" << endl;
push_back(CursorSlice(*n)); push_back(CursorSlice(*n));
return; return;
} }
// otherwise move on one cell back if possible // otherwise move on one cell back if possible
if (top.pos() < lastpos()) { if (top.pos() < lastpos()) {
lyxerr << "... next pos" << std::endl; lyxerr << "... next pos" << endl;
++top.pos(); ++top.pos();
return; return;
} }
// otherwise move on one cell back if possible // otherwise move on one cell back if possible
if (top.par() < lastpar()) { if (top.par() < lastpar()) {
lyxerr << "... next par" << std::endl; lyxerr << "... next par" << endl;
++top.par(); ++top.par();
top.pos() = 0; top.pos() = 0;
return; return;
} }
// otherwise try to move on one cell if possible // otherwise try to move on one cell if possible
// [stupid hack for necessary for MathScriptInset]
while (top.idx() < top.lastidx()) { while (top.idx() < top.lastidx()) {
lyxerr << "... next idx" lyxerr << "... next idx"
<< " was: " << top.idx() << " max: " << top.lastidx() << std::endl; << " was: " << top.idx() << " max: " << top.lastidx() << endl;
++top.idx(); ++top.idx();
top.par() = 0; top.par() = 0;
top.pos() = 0; top.pos() = 0;
if (top.inset().validCell(top.idx())) { return;
lyxerr << " ... ok" << std::endl;
return;
}
} }
// otherwise leave inset an jump over inset as a whole // otherwise leave inset an jump over inset as a whole
@ -369,7 +388,7 @@ DocumentIterator
StableDocumentIterator::asDocumentIterator(InsetBase * inset) const StableDocumentIterator::asDocumentIterator(InsetBase * inset) const
{ {
// this function re-creates the cache of inset pointers // this function re-creates the cache of inset pointers
//lyxerr << "converting:\n" << *this << std::endl; //lyxerr << "converting:\n" << *this << endl;
DocumentIterator dit; DocumentIterator dit;
for (size_t i = 0, n = data_.size(); i != n; ++i) { for (size_t i = 0, n = data_.size(); i != n; ++i) {
dit.push_back(data_[i]); dit.push_back(data_[i]);
@ -377,7 +396,7 @@ StableDocumentIterator::asDocumentIterator(InsetBase * inset) const
if (i + 1 != n) if (i + 1 != n)
inset = dit.nextInset(); inset = dit.nextInset();
} }
//lyxerr << "convert:\n" << *this << " to:\n" << dit << std::endl; //lyxerr << "convert:\n" << *this << " to:\n" << dit << endl;
return dit; return dit;
} }

View File

@ -61,6 +61,10 @@ public:
CursorSlice & top() { return back(); } CursorSlice & top() { return back(); }
/// access to tip /// access to tip
CursorSlice const & top() const { return back(); } CursorSlice const & top() const { return back(); }
/// access to outermost slice
CursorSlice & bottom() { return front(); }
/// access to outermost slicetip
CursorSlice const & bottom() const { return front(); }
/// how many nested insets do we have? /// how many nested insets do we have?
size_t depth() const { return size(); } size_t depth() const { return size(); }
/// the containing inset /// the containing inset
@ -155,14 +159,27 @@ public:
// //
// elementary moving // elementary moving
// //
/// move on one position /// move on one logical position
void forwardPos(); void forwardPos();
/// move on one physical character or inset
void forwardChar();
/// move on one paragraph /// move on one paragraph
void forwardPar(); void forwardPar();
/// move on one cell /// move on one cell
void forwardIdx(); void forwardIdx();
/// move on one inset /// move on one inset
void forwardInset(); void forwardInset();
/// move backward one logical position
void backwardPos();
/// move backward one physical character or inset
void backwardChar();
/// move backward one paragraph
void backwardPar();
/// move backward one cell
void backwardIdx();
/// move backward one inset
void backwardInset();
/// output /// output
friend std::ostream & friend std::ostream &
operator<<(std::ostream & os, DocumentIterator const & cur); operator<<(std::ostream & os, DocumentIterator const & cur);

View File

@ -24,5 +24,5 @@ ErrorItem::ErrorItem(string const & error_, string const & description_,
ErrorItem::ErrorItem() ErrorItem::ErrorItem()
: par_id(-1), pos_start(0), pos_end(0) : par_id(-1), pos_start(0), pos_end(0)
{} {}

View File

@ -31,6 +31,7 @@ struct ErrorItem {
ErrorItem(); ErrorItem();
}; };
class ErrorList : private std::vector<ErrorItem> class ErrorList : private std::vector<ErrorItem>
{ {
public: public:
@ -46,6 +47,4 @@ public:
using std::vector<ErrorItem>::const_iterator; using std::vector<ErrorItem>::const_iterator;
}; };
#endif #endif

View File

@ -185,7 +185,6 @@ InsetBase * createInset(BufferView * bv, FuncRequest const & cmd)
UpdatableInset * up = bv->cursor().inset().asUpdatableInset(); UpdatableInset * up = bv->cursor().inset().asUpdatableInset();
if (!up) { if (!up) {
auto_ptr<InsetCaption> inset(new InsetCaption(params)); auto_ptr<InsetCaption> inset(new InsetCaption(params));
inset->setOwner(up);
inset->setAutoBreakRows(true); inset->setAutoBreakRows(true);
inset->setDrawFrame(InsetText::LOCKED); inset->setDrawFrame(InsetText::LOCKED);
inset->setFrameColor(LColor::captionframe); inset->setFrameColor(LColor::captionframe);

View File

@ -154,7 +154,7 @@ void ControlDocument::classApply()
lv_.message(_("Converting document to new document class...")); lv_.message(_("Converting document to new document class..."));
ErrorList el; ErrorList el;
CutAndPaste::SwitchLayoutsBetweenClasses(old_class, new_class, lyx::cap::SwitchLayoutsBetweenClasses(old_class, new_class,
lv_.buffer()->paragraphs(), lv_.buffer()->paragraphs(),
el); el);
bufferErrors(*buffer(), el); bufferErrors(*buffer(), el);

View File

@ -17,8 +17,6 @@
#include "iterators.h" #include "iterators.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "paragraph.h" #include "paragraph.h"
#include "PosIterator.h"
using std::endl; using std::endl;
using std::string; using std::string;
@ -73,6 +71,9 @@ void ControlErrorList::goTo(int item)
lyx::pos_type const range = end - start; lyx::pos_type const range = end - start;
// Now make the selection. // Now make the selection.
#warning FIXME (goto error)
#if 0
PosIterator const pos(pit, start); PosIterator const pos(pit, start);
kernel().bufferview()->putSelectionAt(pos, range, false); kernel().bufferview()->putSelectionAt(pos, range, false);
#endif
} }

View File

@ -17,11 +17,11 @@
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView.h" #include "BufferView.h"
#include "cursor.h" #include "cursor.h"
#include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
#include "gettext.h" #include "gettext.h"
#include "language.h" #include "language.h"
#include "lyxrc.h" #include "lyxrc.h"
#include "PosIterator.h"
#include "paragraph.h" #include "paragraph.h"
#include "ispell.h" #include "ispell.h"
@ -149,41 +149,40 @@ void ControlSpellchecker::endSession()
namespace { namespace {
bool isLetter(DocumentIterator const & cur)
bool isLetter(PosIterator & cur)
{ {
return !cur.at_end() return !cur.empty()
&& cur.pit()->isLetter(cur.pos()) && cur.paragraph().isLetter(cur.pos())
&& !isDeletedText(*cur.pit(), cur.pos()) && !isDeletedText(cur.paragraph(), cur.pos());
&& (!cur.inset() || cur.inset()->allowSpellCheck()); //&& (!cur.nextInset() || cur.nextInset()->allowSpellCheck());
} }
WordLangTuple nextWord(PosIterator & cur, PosIterator const & end, WordLangTuple nextWord(DocumentIterator & cur, ptrdiff_t & progress,
PosIterator::difference_type & progress, BufferParams & bp)
BufferParams & bp)
{ {
// skip until we have real text (will jump paragraphs) // skip until we have real text (will jump paragraphs)
for (; cur != end && !isLetter(cur); ++cur, ++progress); for (; cur.size() && !isLetter(cur); cur.forwardChar());
++progress;
if (cur == end) // hit end
if (cur.empty())
return WordLangTuple(string(), string()); return WordLangTuple(string(), string());
string lang_code = cur.pit()->getFontSettings(bp, cur.pos()).language()->code(); string lang_code = cur.paragraph().
getFontSettings(bp, cur.pos()).language()->code();
string str; string str;
// and find the end of the word (insets like optional hyphens // and find the end of the word (insets like optional hyphens
// and ligature break are part of a word) // and ligature break are part of a word)
for (; cur != end && isLetter(cur); ++cur, ++progress) { for (; cur.size() && isLetter(cur); cur.forwardChar(), ++progress) {
if (!cur.pit()->isInset(cur.pos())) if (!cur.paragraph().isInset(cur.pos()))
str += cur.pit()->getChar(cur.pos()); str += cur.paragraph().getChar(cur.pos());
} }
return WordLangTuple(str, lang_code); return WordLangTuple(str, lang_code);
} }
} // namespace anon
} //namespace anon
@ -193,18 +192,25 @@ void ControlSpellchecker::check()
SpellBase::Result res = SpellBase::OK; SpellBase::Result res = SpellBase::OK;
PosIterator cur(*bufferview()); DocumentIterator cur = bufferview()->cursor();
PosIterator const beg = buffer()->pos_iterator_begin();
PosIterator const end = buffer()->pos_iterator_end();
PosIterator::difference_type start = distance(beg, cur); // a rough estimate should be sufficient:
PosIterator::difference_type const total = start + distance(cur, end); //DocumentIterator::difference_type start = distance(beg, cur);
//DocumentIterator::difference_type const total = start + distance(cur, end);
if (cur != buffer()->pos_iterator_begin()) ptrdiff_t start = 0, total = 0;
for (; cur != end && isLetter(cur); ++cur, ++start); DocumentIterator it = DocumentIterator(buffer()->inset());
for (start = 0; it != cur; it.forwardPos())
++start;
for (total = start; it.size(); it.forwardPos())
++total;
for (; cur.size() && isLetter(cur); cur.forwardPos())
++start;
while (res == SpellBase::OK || res == SpellBase::IGNORE) { while (res == SpellBase::OK || res == SpellBase::IGNORE) {
word_ = nextWord(cur, end, start, buffer()->params()); word_ = nextWord(cur, start, buffer()->params());
// end of document // end of document
if (word_.word().empty()) if (word_.word().empty())
@ -242,9 +248,13 @@ void ControlSpellchecker::check()
} }
int const size = word_.word().size(); int const size = word_.word().size();
#if 0
advance(cur, -size); advance(cur, -size);
bufferview()->putSelectionAt(cur, size, false); bufferview()->putSelectionAt(cur, size, false);
advance(cur, size); advance(cur, size);
#else
bufferview()->putSelectionAt(cur, size, true);
#endif
// set suggestions // set suggestions
if (res != SpellBase::OK && res != SpellBase::IGNORE) { if (res != SpellBase::OK && res != SpellBase::IGNORE) {
@ -292,7 +302,7 @@ void ControlSpellchecker::showSummary()
void ControlSpellchecker::replace(string const & replacement) void ControlSpellchecker::replace(string const & replacement)
{ {
bufferview()->cursor().replaceWord(replacement); lyx::cap::replaceWord(bufferview()->cursor(), replacement);
bufferview()->buffer()->markDirty(); bufferview()->buffer()->markDirty();
bufferview()->update(); bufferview()->update();
// fix up the count // fix up the count

View File

@ -1,3 +1,26 @@
2004-03-25 André Pönitz <poenitz@gmx.net>
* inset.[Ch]: remover owner
* insetcollapsable.[Ch]: derive from InsetText instead having such a
member
* insettext.[Ch]:
* insetbibitem.C:
* insetbox.C:
* insetbranch.C:
* insetcaption.C:
* insetcharstyle.[Ch]:
* insetert.C:
* insetfloat.C:
* insetfoot.C:
* insetmarginal.C:
* insetnote.C:
* insetoptarg.C:
* insettabular.C:
* insetwrap.C: adjust
2004-03-16 Jürgen Spitzmüller <j.spitzmueller@gmx.de> 2004-03-16 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* insetquote.C: use opening quote after '[' char. * insetquote.C: use opening quote after '[' char.

View File

@ -28,7 +28,7 @@ using std::string;
InsetOld::InsetOld() InsetOld::InsetOld()
: InsetBase(), : InsetBase(),
xo_(0), yo_(0), scx(0), owner_(0), xo_(0), yo_(0), scx(0),
//background_color_(LColor::inherit) //background_color_(LColor::inherit)
background_color_(LColor::background) background_color_(LColor::background)
{} {}
@ -36,7 +36,7 @@ InsetOld::InsetOld()
InsetOld::InsetOld(InsetOld const & in) InsetOld::InsetOld(InsetOld const & in)
: InsetBase(), : InsetBase(),
xo_(0), yo_(0), scx(0), owner_(0), name_(in.name_), xo_(0), yo_(0), scx(0), name_(in.name_),
background_color_(in.background_color_) background_color_(in.background_color_)
{} {}
@ -53,10 +53,8 @@ LColor_color InsetOld::backgroundColor() const
} }
bool InsetOld::forceDefaultParagraphs(InsetBase const * inset) const bool InsetOld::forceDefaultParagraphs(InsetBase const *) const
{ {
if (owner())
return owner()->forceDefaultParagraphs(inset);
return false; return false;
} }
@ -79,11 +77,9 @@ int InsetOld::width() const
} }
int InsetOld::scroll(bool recursive) const int InsetOld::scroll(bool) const
{ {
if (!recursive || !owner_) return scx;
return scx;
return 0;
} }

View File

@ -47,10 +47,6 @@ public:
/// ///
std::string const & getInsetName() const { return name_; } std::string const & getInsetName() const { return name_; }
/// ///
void setOwner(UpdatableInset * inset) { owner_ = inset; }
///
UpdatableInset * owner() const { return owner_; }
///
virtual void setBackgroundColor(LColor_color); virtual void setBackgroundColor(LColor_color);
/// ///
LColor_color backgroundColor() const; LColor_color backgroundColor() const;
@ -76,8 +72,6 @@ protected:
mutable Dimension dim_; mutable Dimension dim_;
private: private:
///
UpdatableInset * owner_;
/// ///
std::string name_; std::string name_;
/** We store the LColor::color value as an int to get LColor.h out /** We store the LColor::color value as an int to get LColor.h out

View File

@ -147,8 +147,6 @@ public:
virtual int cellXOffset(idx_type) const { return 0; } virtual int cellXOffset(idx_type) const { return 0; }
/// any additional y-offset when drawing a cell? /// any additional y-offset when drawing a cell?
virtual int cellYOffset(idx_type) const { return 0; } virtual int cellYOffset(idx_type) const { return 0; }
/// can we enter this cell?
virtual bool validCell(idx_type) const { return true; }
/// number of embedded cells /// number of embedded cells
virtual size_t nargs() const { return 0; } virtual size_t nargs() const { return 0; }
/// number of rows in gridlike structures /// number of rows in gridlike structures
@ -361,11 +359,6 @@ public:
/// return text or mathmode if that is possible to determine /// return text or mathmode if that is possible to determine
virtual mode_type currentMode() const { return UNDECIDED_MODE; } virtual mode_type currentMode() const { return UNDECIDED_MODE; }
/// FIXME: This ought to die.
virtual void setOwner(UpdatableInset *) {}
///
virtual UpdatableInset * owner() const { return 0; }
/// is this inset allowed within a font change? /// is this inset allowed within a font change?
virtual bool noFontChange() const { return false; } virtual bool noFontChange() const { return false; }

View File

@ -19,6 +19,7 @@
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxlex.h" #include "lyxlex.h"
#include "paragraph.h" #include "paragraph.h"
#include "ParagraphList_fwd.h"
#include "frontends/font_metrics.h" #include "frontends/font_metrics.h"

View File

@ -296,7 +296,7 @@ int InsetBox::latex(Buffer const & buf, ostream & os,
i += 1; i += 1;
} }
i += inset.latex(buf, os, runparams); i += InsetText::latex(buf, os, runparams);
if (params_.inner_box) { if (params_.inner_box) {
if (params_.use_parbox) if (params_.use_parbox)
@ -331,14 +331,14 @@ int InsetBox::latex(Buffer const & buf, ostream & os,
int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os, int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
return inset.linuxdoc(buf, os, runparams); return InsetText::linuxdoc(buf, os, runparams);
} }
int InsetBox::docbook(Buffer const & buf, std::ostream & os, int InsetBox::docbook(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
return inset.docbook(buf, os, runparams); return InsetText::docbook(buf, os, runparams);
} }
@ -356,7 +356,7 @@ int InsetBox::plaintext(Buffer const & buf, std::ostream & os,
case Doublebox: os << "[["; break; case Doublebox: os << "[["; break;
} }
int i = inset.plaintext(buf, os, runparams); int i = InsetText::plaintext(buf, os, runparams);
switch (btype) { switch (btype) {
case Frameless: break; case Frameless: break;
@ -386,14 +386,13 @@ void InsetBox::validate(LaTeXFeatures & features) const
features.require("fancybox"); features.require("fancybox");
break; break;
} }
inset.validate(features); InsetText::validate(features);
} }
InsetBoxMailer::InsetBoxMailer(InsetBox & inset) InsetBoxMailer::InsetBoxMailer(InsetBox & inset)
: inset_(inset) : inset_(inset)
{ {}
}
string const InsetBoxMailer::name_ = "box"; string const InsetBoxMailer::name_ = "box";

View File

@ -162,7 +162,7 @@ int InsetBranch::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
return isBranchSelected(buf.params().branchlist()) ? return isBranchSelected(buf.params().branchlist()) ?
inset.latex(buf, os, runparams) : 0; InsetText::latex(buf, os, runparams) : 0;
} }
@ -170,7 +170,7 @@ int InsetBranch::linuxdoc(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
return isBranchSelected(buf.params().branchlist()) ? return isBranchSelected(buf.params().branchlist()) ?
inset.linuxdoc(buf, os, runparams) : 0; InsetText::linuxdoc(buf, os, runparams) : 0;
} }
@ -178,7 +178,7 @@ int InsetBranch::docbook(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
return isBranchSelected(buf.params().branchlist()) ? return isBranchSelected(buf.params().branchlist()) ?
inset.docbook(buf, os, runparams) : 0; InsetText::docbook(buf, os, runparams) : 0;
} }
@ -186,18 +186,18 @@ int InsetBranch::plaintext(Buffer const & buf, std::ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
return isBranchSelected(buf.params().branchlist()) ? return isBranchSelected(buf.params().branchlist()) ?
inset.plaintext(buf, os, runparams): 0; InsetText::plaintext(buf, os, runparams): 0;
} }
void InsetBranch::validate(LaTeXFeatures & features) const void InsetBranch::validate(LaTeXFeatures & features) const
{ {
inset.validate(features); InsetText::validate(features);
} }
string const InsetBranchMailer:: name_("branch"); string const InsetBranchMailer::name_("branch");
InsetBranchMailer::InsetBranchMailer(InsetBranch & inset) InsetBranchMailer::InsetBranchMailer(InsetBranch & inset)
: inset_(inset) : inset_(inset)

View File

@ -87,19 +87,28 @@ void InsetCaption::draw(PainterInfo & pi, int x, int y) const
// See if we can find the name of the float this caption // See if we can find the name of the float this caption
// belongs to. // belongs to.
#if 0
InsetOld * i1 = owner(); InsetOld * i1 = owner();
InsetOld * i2 = i1 ? i1->owner() : 0; InsetOld * i2 = i1 ? i1->owner() : 0;
string type; string type;
if (i2->lyxCode() == FLOAT_CODE) if (i2->lyxCode() == FLOAT_CODE)
#warning Now, what happens for i2 == 0?
type = static_cast<InsetFloat *>(i2)->params().type; type = static_cast<InsetFloat *>(i2)->params().type;
else if (i2->lyxCode() == WRAP_CODE) else if (i2->lyxCode() == WRAP_CODE)
type = static_cast<InsetWrap *>(i2)->params().type; type = static_cast<InsetWrap *>(i2)->params().type;
else else
BOOST_ASSERT(false); BOOST_ASSERT(false);
#else
string type = "float";
#endif
FloatList const & floats = FloatList const & floats =
pi.base.bv->buffer()->params().getLyXTextClass().floats(); pi.base.bv->buffer()->params().getLyXTextClass().floats();
#if 0
string const fl = i2 ? floats.getType(type).name() : N_("Float"); string const fl = i2 ? floats.getType(type).name() : N_("Float");
#else
string const fl = N_("Float");
#endif
// Discover the number... // Discover the number...
string const num = "#"; string const num = "#";

View File

@ -109,33 +109,30 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
// FIXME: setStatus(Inlined); this is not a const operation // FIXME: setStatus(Inlined); this is not a const operation
LyXFont tmpfont = pi.base.font; LyXFont tmpfont = pi.base.font;
inset.setDrawFrame(InsetText::NEVER); //setDrawFrame(InsetText::NEVER);
getDrawFont(pi.base.font); getDrawFont(pi.base.font);
inset.draw(pi, x, y); InsetText::draw(pi, x, y);
pi.base.font = tmpfont; pi.base.font = tmpfont;
pi.pain.line(x + 2, y + inset.descent() - 4, x + 2, pi.pain.line(x + 2, y + InsetText::descent() - 4, x + 2,
y + inset.descent(), params_.labelfont.color()); y + InsetText::descent(), params_.labelfont.color());
pi.pain.line(x + 2, y + inset.descent(), x + dim_.wid - 2, pi.pain.line(x + 2, y + InsetText::descent(), x + dim_.wid - 2,
y + inset.descent(), params_.labelfont.color()); y + InsetText::descent(), params_.labelfont.color());
pi.pain.line(x + dim_.wid - 2, y + inset.descent(), x + dim_.wid - 2, pi.pain.line(x + dim_.wid - 2, y + InsetText::descent(), x + dim_.wid - 2,
y + inset.descent() - 4, params_.labelfont.color()); y + InsetText::descent() - 4, params_.labelfont.color());
if (has_label_) { if (has_label_) {
if (!owner()) LyXFont font(params_.labelfont);
x += scroll(); font.realize(LyXFont(LyXFont::ALL_SANE));
font.decSize();
LyXFont font(params_.labelfont); font.decSize();
font.realize(LyXFont(LyXFont::ALL_SANE)); int w = 0;
font.decSize(); int a = 0;
font.decSize(); int d = 0;
int w = 0; font_metrics::rectText(params_.type, font, w, a, d);
int a = 0; pi.pain.rectText(x + (dim_.wid - w) / 2,
int d = 0; y + InsetText::descent() + a,
font_metrics::rectText(params_.type, font, w, a, d); params_.type, font, LColor::none, LColor::none);
pi.pain.rectText(x + (dim_.wid - w) / 2,
y + inset.descent() + a,
params_.type, font, LColor::none, LColor::none);
} }
} }
@ -154,7 +151,7 @@ void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest & cmd)
if (cmd.button() == mouse_button::button3) if (cmd.button() == mouse_button::button3)
has_label_ = !has_label_; has_label_ = !has_label_;
else else
inset.dispatch(cur, cmd); InsetText::dispatch(cur, cmd);
break; break;
default: default:
@ -166,7 +163,7 @@ void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest & cmd)
namespace { namespace {
int outputVerbatim(std::ostream & os, InsetText inset) int outputVerbatim(std::ostream & os, InsetText const & inset)
{ {
int lines = 0; int lines = 0;
ParagraphList::iterator par = inset.paragraphs().begin(); ParagraphList::iterator par = inset.paragraphs().begin();
@ -200,7 +197,7 @@ int InsetCharStyle::latex(Buffer const &, ostream & os,
if (!params_.latexparam.empty()) if (!params_.latexparam.empty())
os << params_.latexparam; os << params_.latexparam;
os << "{"; os << "{";
int i = outputVerbatim(os, inset); int i = outputVerbatim(os, *this);
os << "}%\n"; os << "}%\n";
i += 2; i += 2;
return i; return i;
@ -214,7 +211,7 @@ int InsetCharStyle::linuxdoc(Buffer const &, std::ostream & os,
if (!params_.latexparam.empty()) if (!params_.latexparam.empty())
os << " " << params_.latexparam; os << " " << params_.latexparam;
os << ">"; os << ">";
int const i = outputVerbatim(os, inset); int const i = outputVerbatim(os, *this);
os << "</" << params_.latexname << ">"; os << "</" << params_.latexname << ">";
return i; return i;
} }
@ -227,7 +224,7 @@ int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
if (!params_.latexparam.empty()) if (!params_.latexparam.empty())
os << " " << params_.latexparam; os << " " << params_.latexparam;
os << ">"; os << ">";
int const i = outputVerbatim(os, inset); int const i = outputVerbatim(os, *this);
os << "</" << params_.latexname << ">"; os << "</" << params_.latexname << ">";
return i; return i;
} }
@ -236,7 +233,7 @@ int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
int InsetCharStyle::plaintext(Buffer const &, std::ostream & os, int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
OutputParams const & /*runparams*/) const OutputParams const & /*runparams*/) const
{ {
return outputVerbatim(os, inset); return outputVerbatim(os, *this);
} }

View File

@ -13,12 +13,11 @@
#ifndef INSETCHARSTYLE_H #ifndef INSETCHARSTYLE_H
#define INSETCHARSTYLE_H #define INSETCHARSTYLE_H
#include "insetcollapsable.h" #include "insetcollapsable.h"
#include "lyxtextclass.h" #include "lyxtextclass.h"
struct InsetCharStyleParams { struct InsetCharStyleParams {
/// ///
void write(std::ostream & os) const; void write(std::ostream & os) const;
/// ///
@ -44,8 +43,6 @@
class InsetCharStyle : public InsetCollapsable { class InsetCharStyle : public InsetCollapsable {
public: public:
/// ///
InsetCharStyle(BufferParams const &, CharStyles::iterator); InsetCharStyle(BufferParams const &, CharStyles::iterator);
/// Copy constructor /// Copy constructor
InsetCharStyle(InsetCharStyle const &); InsetCharStyle(InsetCharStyle const &);
@ -88,6 +85,7 @@ protected:
virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd); virtual void priv_dispatch(LCursor & cur, FuncRequest & cmd);
private: private:
///
friend class InsetCharStyleParams; friend class InsetCharStyleParams;
/// used by the constructors /// used by the constructors

View File

@ -41,26 +41,16 @@ using std::ostream;
InsetCollapsable::InsetCollapsable(BufferParams const & bp, InsetCollapsable::InsetCollapsable(BufferParams const & bp,
CollapseStatus status) CollapseStatus status)
: inset(bp), label("Label"), status_(status), openinlined_(false) : InsetText(bp), label("Label"), status_(status), openinlined_(false)
{ {
inset.setOwner(this); setAutoBreakRows(true);
inset.setAutoBreakRows(true); setDrawFrame(InsetText::ALWAYS);
inset.setDrawFrame(InsetText::ALWAYS); setFrameColor(LColor::collapsableframe);
inset.setFrameColor(LColor::collapsableframe);
setInsetName("Collapsable"); setInsetName("Collapsable");
setButtonLabel(); setButtonLabel();
} }
InsetCollapsable::InsetCollapsable(InsetCollapsable const & in)
: UpdatableInset(in), inset(in.inset),
labelfont_(in.labelfont_), label(in.label), status_(in.status_)
{
inset.setOwner(this);
setButtonLabel();
}
void InsetCollapsable::write(Buffer const & buf, ostream & os) const void InsetCollapsable::write(Buffer const & buf, ostream & os) const
{ {
os << "status "; os << "status ";
@ -76,7 +66,7 @@ void InsetCollapsable::write(Buffer const & buf, ostream & os) const
break; break;
} }
os << "\n"; os << "\n";
inset.text_.write(buf, os); text_.write(buf, os);
} }
@ -106,13 +96,13 @@ void InsetCollapsable::read(Buffer const & buf, LyXLex & lex)
lex.pushToken(token); lex.pushToken(token);
} }
} else { } else {
lyxerr << "InsetCollapsable::Read: Missing 'status'-tag!" lyxerr << "InsetCollapsable::read: Missing 'status'-tag!"
<< endl; << endl;
// take countermeasures // take countermeasures
lex.pushToken(token); lex.pushToken(token);
} }
} }
inset.read(buf, lex); InsetText::read(buf, lex);
if (!token_found) if (!token_found)
status_ = isOpen() ? Open : Collapsed; status_ = isOpen() ? Open : Collapsed;
@ -130,20 +120,19 @@ void InsetCollapsable::dimension_collapsed(Dimension & dim) const
void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const void InsetCollapsable::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
if (status_ == Inlined) { if (status_ == Inlined) {
inset.metrics(mi, dim); InsetText::metrics(mi, dim);
} else { } else {
dimension_collapsed(dim); dimension_collapsed(dim);
if (status_ == Open) { if (status_ == Open) {
Dimension insetdim; Dimension insetdim;
inset.metrics(mi, insetdim); InsetText::metrics(mi, insetdim);
openinlined_ = (insetdim.wid + dim.wid <= mi.base.textwidth); openinlined_ = (insetdim.wid + dim.wid <= mi.base.textwidth);
if (openinlined_) { if (openinlined_) {
dim.wid += insetdim.wid; dim.wid += insetdim.wid;
dim.des = max(dim.des, insetdim.des); dim.des = max(dim.des, insetdim.des);
dim.asc = max(dim.asc, insetdim.asc); dim.asc = max(dim.asc, insetdim.asc);
} else { } else {
dim.des += insetdim.height() dim.des += insetdim.height() + TEXT_TO_BOTTOM_OFFSET;
+ TEXT_TO_BOTTOM_OFFSET;
dim.wid = max(dim.wid, insetdim.wid); dim.wid = max(dim.wid, insetdim.wid);
} }
} }
@ -163,7 +152,7 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
setPosCache(pi, x, y); setPosCache(pi, x, y);
if (status_ == Inlined) { if (status_ == Inlined) {
inset.draw(pi, x, y); InsetText::draw(pi, x, y);
} else { } else {
Dimension dimc; Dimension dimc;
dimension_collapsed(dimc); dimension_collapsed(dimc);
@ -175,24 +164,16 @@ void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const
draw_collapsed(pi, x, y); draw_collapsed(pi, x, y);
if (status_ == Open) { if (status_ == Open) {
if (!owner()) x += scroll();
x += scroll();
if (openinlined_) if (openinlined_)
inset.draw(pi, x + dimc.width(), y - aa + inset.ascent()); InsetText::draw(pi, x + dimc.width(), y - aa + InsetText::ascent());
else else
inset.draw(pi, x, y - aa + dimc.height() + inset.ascent()); InsetText::draw(pi, x, y - aa + dimc.height() + InsetText::ascent());
} }
} }
} }
void InsetCollapsable::drawSelection(PainterInfo & pi, int x, int y) const
{
inset.drawSelection(pi, x, y);
}
InsetOld::EDITABLE InsetCollapsable::editable() const InsetOld::EDITABLE InsetCollapsable::editable() const
{ {
return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE; return status_ != Collapsed ? HIGHLY_EDITABLE : IS_EDITABLE;
@ -205,69 +186,6 @@ bool InsetCollapsable::descendable() const
} }
void InsetCollapsable::lfunMouseRelease(LCursor & cur, FuncRequest & cmd)
{
if (cmd.button() == mouse_button::button3) {
showInsetDialog(&cur.bv());
return;
}
switch (status_) {
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
edit(cur, true);
break;
case Open: {
FuncRequest cmd1 = cmd;
if (hitButton(cmd1)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed);
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
break;
}
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
inset.dispatch(cur, cmd);
break;
}
case Inlined:
inset.dispatch(cur, cmd);
break;
}
}
int InsetCollapsable::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
return inset.latex(buf, os, runparams);
}
int InsetCollapsable::plaintext(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
return inset.plaintext(buf, os, runparams);
}
int InsetCollapsable::linuxdoc(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
return inset.linuxdoc(buf, os, runparams);
}
int InsetCollapsable::docbook(Buffer const & buf, ostream & os,
OutputParams const & runparams) const
{
return inset.docbook(buf, os, runparams);
}
bool InsetCollapsable::hitButton(FuncRequest & cmd) const bool InsetCollapsable::hitButton(FuncRequest & cmd) const
{ {
return button_dim.contains(cmd.x, cmd.y); return button_dim.contains(cmd.x, cmd.y);
@ -278,17 +196,17 @@ string const InsetCollapsable::getNewLabel(string const & l) const
{ {
string label; string label;
pos_type const max_length = 15; pos_type const max_length = 15;
pos_type const p_siz = inset.paragraphs().begin()->size(); pos_type const p_siz = paragraphs().begin()->size();
pos_type const n = min(max_length, p_siz); pos_type const n = min(max_length, p_siz);
pos_type i = 0; pos_type i = 0;
pos_type j = 0; pos_type j = 0;
for( ; i < n && j < p_siz; ++j) { for( ; i < n && j < p_siz; ++j) {
if (inset.paragraphs().begin()->isInset(j)) if (paragraphs().begin()->isInset(j))
continue; continue;
label += inset.paragraphs().begin()->getChar(j); label += paragraphs().begin()->getChar(j);
++i; ++i;
} }
if (inset.paragraphs().size() > 1 || (i > 0 && j < p_siz)) { if (paragraphs().size() > 1 || (i > 0 && j < p_siz)) {
label += "..."; label += "...";
} }
return label.empty() ? l : label; return label.empty() ? l : label;
@ -299,7 +217,7 @@ void InsetCollapsable::edit(LCursor & cur, bool left)
{ {
//lyxerr << "InsetCollapsable: edit left/right" << endl; //lyxerr << "InsetCollapsable: edit left/right" << endl;
cur.push(*this); cur.push(*this);
inset.edit(cur, left); InsetText::edit(cur, left);
open(); open();
} }
@ -310,13 +228,13 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
//lyxerr << "InsetCollapsable: edit xy" << endl; //lyxerr << "InsetCollapsable: edit xy" << endl;
if (status_ == Collapsed) { if (status_ == Collapsed) {
setStatus(Open); setStatus(Open);
inset.edit(cur, true); // We are not calling editXY() because the row cache of the
#warning look here // inset might be invalid. 'Entering from the left' should be
//we are not calling edit(x,y) because there are no coordinates in the // ok, though.
//inset yet. I personally think it's ok. (ab) InsetText::edit(cur, true);
return this; return this;
} }
return inset.editXY(cur, x, y); return InsetText::editXY(cur, x, y);
} }
@ -327,90 +245,83 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
switch (cmd.action) { switch (cmd.action) {
case LFUN_MOUSE_PRESS: case LFUN_MOUSE_PRESS:
if (status_ == Inlined) if (status_ == Inlined)
inset.dispatch(cur, cmd); InsetText::priv_dispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd)) else if (status_ == Open && !hitButton(cmd))
inset.dispatch(cur, cmd); InsetText::priv_dispatch(cur, cmd);
break; break;
case LFUN_MOUSE_MOTION: case LFUN_MOUSE_MOTION:
if (status_ == Inlined) if (status_ == Inlined)
inset.dispatch(cur, cmd); InsetText::priv_dispatch(cur, cmd);
else if (status_ == Open && !hitButton(cmd)) else if (status_ == Open && !hitButton(cmd))
inset.dispatch(cur, cmd); InsetText::priv_dispatch(cur, cmd);
break; break;
case LFUN_MOUSE_RELEASE: case LFUN_MOUSE_RELEASE:
lfunMouseRelease(cur, cmd); if (cmd.button() == mouse_button::button3) {
showInsetDialog(&cur.bv());
break;
}
switch (status_) {
case Collapsed:
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
setStatus(Open);
edit(cur, true);
break;
case Open: {
FuncRequest cmd1 = cmd;
if (hitButton(cmd1)) {
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
setStatus(Collapsed);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT);
} else {
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
InsetText::priv_dispatch(cur, cmd);
}
break;
}
case Inlined:
lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
InsetText::priv_dispatch(cur, cmd);
break;
}
break; break;
case LFUN_INSET_TOGGLE: case LFUN_INSET_TOGGLE:
if (inset.text_.toggleInset(cur)) if (InsetText::text_.toggleInset(cur))
break; break;
if (status_ == Open) { if (status_ == Open) {
setStatus(Inlined); setStatus(Inlined);
break; break;
} }
setStatus(Collapsed); setStatus(Collapsed);
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
break; break;
default: default:
inset.dispatch(cur, cmd); InsetText::priv_dispatch(cur, cmd);
break; break;
} }
} }
bool InsetCollapsable::getStatus(LCursor & cur, FuncRequest const & cmd,
FuncStatus & flag) const
{
return inset.getStatus(cur, cmd, flag);
}
void InsetCollapsable::validate(LaTeXFeatures & features) const
{
inset.validate(features);
}
void InsetCollapsable::getCursorPos(CursorSlice const & cur,
int & x, int & y) const
{
inset.getCursorPos(cur, x, y);
}
void InsetCollapsable::getLabelList(Buffer const & buffer,
std::vector<string> & list) const
{
inset.getLabelList(buffer, list);
}
int InsetCollapsable::scroll(bool recursive) const int InsetCollapsable::scroll(bool recursive) const
{ {
int sx = UpdatableInset::scroll(false); int sx = UpdatableInset::scroll(false);
if (recursive) if (recursive)
sx += inset.scroll(false); sx += InsetText::scroll(false);
return sx; return sx;
} }
size_t InsetCollapsable::nargs() const
{
return inset.nargs();
}
LyXText * InsetCollapsable::getText(int i) const
{
return inset.getText(i);
}
void InsetCollapsable::open() void InsetCollapsable::open()
{ {
if (status_ == Collapsed) // ...but not inlined if (status_ == Collapsed) // ...but not inlined
@ -437,24 +348,6 @@ void InsetCollapsable::setStatus(CollapseStatus st)
} }
void InsetCollapsable::markErased()
{
inset.markErased();
}
void InsetCollapsable::addPreview(PreviewLoader & loader) const
{
inset.addPreview(loader);
}
bool InsetCollapsable::insetAllowed(InsetOld::Code code) const
{
return inset.insetAllowed(code);
}
void InsetCollapsable::setLabelFont(LyXFont & font) void InsetCollapsable::setLabelFont(LyXFont & font)
{ {
labelfont_ = font; labelfont_ = font;
@ -477,10 +370,3 @@ Box const & InsetCollapsable::buttonDim() const
{ {
return button_dim; return button_dim;
} }
void InsetCollapsable::setBackgroundColor(LColor_color color)
{
InsetOld::setBackgroundColor(color);
inset.setBackgroundColor(color);
}

View File

@ -28,7 +28,7 @@ class CursorSlice;
/** A collapsable text inset /** A collapsable text inset
*/ */
class InsetCollapsable : public UpdatableInset { class InsetCollapsable : public InsetText {
public: public:
/// ///
static int const TEXT_TO_TOP_OFFSET = 2; static int const TEXT_TO_TOP_OFFSET = 2;
@ -36,15 +36,13 @@ public:
static int const TEXT_TO_BOTTOM_OFFSET = 2; static int const TEXT_TO_BOTTOM_OFFSET = 2;
/// ///
enum CollapseStatus { enum CollapseStatus {
Open,
Collapsed, Collapsed,
Inlined Inlined,
Open
}; };
/// ///
InsetCollapsable(BufferParams const &, CollapseStatus status = Open); InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
/// ///
InsetCollapsable(InsetCollapsable const & in);
///
void read(Buffer const &, LyXLex &); void read(Buffer const &, LyXLex &);
/// ///
void write(Buffer const &, std::ostream &) const; void write(Buffer const &, std::ostream &) const;
@ -53,8 +51,6 @@ public:
/// ///
void draw(PainterInfo & pi, int x, int y) const; void draw(PainterInfo & pi, int x, int y) const;
/// ///
void drawSelection(PainterInfo & pi, int x, int y) const;
///
bool hitButton(FuncRequest &) const; bool hitButton(FuncRequest &) const;
/// ///
std::string const getNewLabel(std::string const & l) const; std::string const getNewLabel(std::string const & l) const;
@ -63,33 +59,13 @@ public:
/// can we go further down on mouse click? /// can we go further down on mouse click?
bool descendable() const; bool descendable() const;
/// ///
bool insetAllowed(InsetOld::Code code) const;
///
bool isTextInset() const { return true; } bool isTextInset() const { return true; }
/// ///
int latex(Buffer const &, std::ostream &,
OutputParams const &) const;
///
int plaintext(Buffer const &, std::ostream &,
OutputParams const &) const;
///
int linuxdoc(Buffer const &, std::ostream &,
OutputParams const &) const;
///
int docbook(Buffer const &, std::ostream &,
OutputParams const & runparams) const;
///
void validate(LaTeXFeatures & features) const;
/// get the screen x,y of the cursor
void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
///
void setLabel(std::string const & l); void setLabel(std::string const & l);
/// ///
virtual void setButtonLabel() {} virtual void setButtonLabel() {}
/// ///
void setLabelFont(LyXFont & f); void setLabelFont(LyXFont & f);
/// Appends \c list with all labels found within this inset.
void getLabelList(Buffer const &, std::vector<std::string> & list) const;
/// ///
int scroll(bool recursive = true) const; int scroll(bool recursive = true) const;
/// ///
@ -97,10 +73,6 @@ public:
/// ///
void scroll(BufferView & bv, int offset) const; void scroll(BufferView & bv, int offset) const;
/// ///
size_t nargs() const;
///
LyXText * getText(int) const;
///
bool isOpen() const { return status_ == Open || status_ == Inlined; } bool isOpen() const { return status_ == Open || status_ == Inlined; }
/// ///
bool inlined() const { return status_ == Inlined; } bool inlined() const { return status_ == Inlined; }
@ -111,21 +83,13 @@ public:
/// ///
void close(); void close();
/// ///
void markErased();
///
void addPreview(lyx::graphics::PreviewLoader &) const;
///
void setBackgroundColor(LColor_color);
///
void setStatus(CollapseStatus st);
///
bool allowSpellCheck() const { return true; } bool allowSpellCheck() const { return true; }
protected: protected:
/// ///
void priv_dispatch(LCursor & cur, FuncRequest & cmd); void setStatus(CollapseStatus st);
/// ///
bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; void priv_dispatch(LCursor & cur, FuncRequest & cmd);
/// ///
void dimension_collapsed(Dimension &) const; void dimension_collapsed(Dimension &) const;
/// ///
@ -139,13 +103,6 @@ protected:
/// ///
InsetBase * editXY(LCursor & cur, int x, int y); InsetBase * editXY(LCursor & cur, int x, int y);
private:
///
void lfunMouseRelease(LCursor & cur, FuncRequest & cmd);
public:
///
mutable InsetText inset;
protected: protected:
/// ///
LyXFont labelfont_; LyXFont labelfont_;

View File

@ -85,9 +85,9 @@ InsetERT::InsetERT(BufferParams const & bp,
string::const_iterator cit = contents.begin(); string::const_iterator cit = contents.begin();
string::const_iterator end = contents.end(); string::const_iterator end = contents.end();
pos_type pos = 0; pos_type pos = 0;
for (; cit != end; ++cit) { for (; cit != end; ++cit)
inset.paragraphs().begin()->insertChar(pos++, *cit, font); paragraphs().begin()->insertChar(pos++, *cit, font);
}
// the init has to be after the initialization of the paragraph // the init has to be after the initialization of the paragraph
// because of the label settings (draw_label for ert insets). // because of the label settings (draw_label for ert insets).
init(); init();
@ -116,8 +116,8 @@ string const InsetERT::editMessage() const
int InsetERT::latex(Buffer const &, ostream & os, int InsetERT::latex(Buffer const &, ostream & os,
OutputParams const &) const OutputParams const &) const
{ {
ParagraphList::iterator par = inset.paragraphs().begin(); ParagraphList::iterator par = paragraphs().begin();
ParagraphList::iterator end = inset.paragraphs().end(); ParagraphList::iterator end = paragraphs().end();
int lines = 0; int lines = 0;
while (par != end) { while (par != end) {
@ -153,10 +153,10 @@ int InsetERT::plaintext(Buffer const &, ostream &,
int InsetERT::linuxdoc(Buffer const &, ostream & os, int InsetERT::linuxdoc(Buffer const &, ostream & os,
OutputParams const &)const OutputParams const &) const
{ {
ParagraphList::iterator par = inset.paragraphs().begin(); ParagraphList::iterator par = paragraphs().begin();
ParagraphList::iterator end = inset.paragraphs().end(); ParagraphList::iterator end = paragraphs().end();
int lines = 0; int lines = 0;
while (par != end) { while (par != end) {
@ -183,8 +183,8 @@ int InsetERT::linuxdoc(Buffer const &, ostream & os,
int InsetERT::docbook(Buffer const &, ostream & os, int InsetERT::docbook(Buffer const &, ostream & os,
OutputParams const &) const OutputParams const &) const
{ {
ParagraphList::iterator par = inset.paragraphs().begin(); ParagraphList::iterator par = paragraphs().begin();
ParagraphList::iterator end = inset.paragraphs().end(); ParagraphList::iterator end = paragraphs().end();
int lines = 0; int lines = 0;
while (par != end) { while (par != end) {

View File

@ -133,9 +133,7 @@ string floatname(string const & type, BufferParams const & bp)
InsetFloat::InsetFloat(BufferParams const & bp, string const & type) InsetFloat::InsetFloat(BufferParams const & bp, string const & type)
: InsetCollapsable(bp) : InsetCollapsable(bp)
{ {
string lab(_("float: ")); setLabel(_("float: ") + floatname(type, bp));
lab += floatname(type, bp);
setLabel(lab);
LyXFont font(LyXFont::ALL_SANE); LyXFont font(LyXFont::ALL_SANE);
font.decSize(); font.decSize();
font.decSize(); font.decSize();
@ -145,7 +143,7 @@ InsetFloat::InsetFloat(BufferParams const & bp, string const & type)
setInsetName(type); setInsetName(type);
LyXTextClass const & tclass = bp.getLyXTextClass(); LyXTextClass const & tclass = bp.getLyXTextClass();
if (tclass.hasLayout(caplayout)) if (tclass.hasLayout(caplayout))
inset.paragraphs().begin()->layout(tclass[caplayout]); paragraphs().begin()->layout(tclass[caplayout]);
} }
@ -294,7 +292,7 @@ int InsetFloat::latex(Buffer const & buf, ostream & os,
} }
os << '\n'; os << '\n';
int const i = inset.latex(buf, os, runparams); int const i = InsetText::latex(buf, os, runparams);
// The \n is used to force \end{<floatname>} to appear in a new line. // The \n is used to force \end{<floatname>} to appear in a new line.
// In this case, we do not case if the current output line is empty. // In this case, we do not case if the current output line is empty.
@ -335,7 +333,7 @@ int InsetFloat::linuxdoc(Buffer const & buf, ostream & os,
} }
os << ">"; os << ">";
int const i = inset.linuxdoc(buf, os, runparams); int const i = InsetText::linuxdoc(buf, os, runparams);
os << "</" << tmptype << ">\n"; os << "</" << tmptype << ">\n";
return i; return i;
@ -346,7 +344,7 @@ int InsetFloat::docbook(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << '<' << params_.type << '>'; os << '<' << params_.type << '>';
int const i = inset.docbook(buf, os, runparams); int const i = InsetText::docbook(buf, os, runparams);
os << "</" << params_.type << '>'; os << "</" << params_.type << '>';
return i; return i;
@ -363,7 +361,7 @@ bool InsetFloat::insetAllowed(InsetOld::Code code) const
bool InsetFloat::showInsetDialog(BufferView * bv) const bool InsetFloat::showInsetDialog(BufferView * bv) const
{ {
if (!inset.showInsetDialog(bv)) if (!InsetText::showInsetDialog(bv))
InsetFloatMailer(const_cast<InsetFloat &>(*this)).showDialog(bv); InsetFloatMailer(const_cast<InsetFloat &>(*this)).showDialog(bv);
return true; return true;
} }
@ -381,8 +379,8 @@ void InsetFloat::wide(bool w, BufferParams const & bp)
void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
{ {
ParIterator pit(inset.paragraphs().begin(), inset.paragraphs()); ParIterator pit(0, paragraphs());
ParIterator end(inset.paragraphs().end(), inset.paragraphs()); ParIterator end(paragraphs().size(), paragraphs());
// Find a caption layout in one of the (child inset's) pars // Find a caption layout in one of the (child inset's) pars
for (; pit != end; ++pit) { for (; pit != end; ++pit) {

View File

@ -65,7 +65,7 @@ int InsetFoot::latex(Buffer const & buf, ostream & os,
os << "%\n\\footnote{"; os << "%\n\\footnote{";
int const i = inset.latex(buf, os, runparams); int const i = InsetText::latex(buf, os, runparams);
os << "%\n}"; os << "%\n}";
return i + 2; return i + 2;
@ -76,7 +76,7 @@ int InsetFoot::docbook(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << "<footnote>"; os << "<footnote>";
int const i = inset.docbook(buf, os, runparams); int const i = InsetText::docbook(buf, os, runparams);
os << "</footnote>"; os << "</footnote>";
return i; return i;

View File

@ -56,9 +56,7 @@ int InsetMarginal::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << "%\n\\marginpar{"; os << "%\n\\marginpar{";
int const i = InsetText::latex(buf, os, runparams);
int const i = inset.latex(buf, os, runparams);
os << "%\n}"; os << "%\n}";
return i + 2; return i + 2;
} }

View File

@ -226,7 +226,7 @@ int InsetNote::latex(Buffer const & buf, ostream & os,
ostringstream ss; ostringstream ss;
ss << "%\n\\begin{" << type << "}\n"; ss << "%\n\\begin{" << type << "}\n";
inset.latex(buf, ss, runparams); InsetText::latex(buf, ss, runparams);
ss << "%\n\\end{" << type << "}\n"; ss << "%\n\\end{" << type << "}\n";
string const str = ss.str(); string const str = ss.str();
@ -246,7 +246,7 @@ int InsetNote::linuxdoc(Buffer const & buf, std::ostream & os,
if (params_.type == InsetNoteParams::Comment) if (params_.type == InsetNoteParams::Comment)
ss << "<comment>\n"; ss << "<comment>\n";
inset.linuxdoc(buf, ss, runparams); InsetText::linuxdoc(buf, ss, runparams);
if (params_.type == InsetNoteParams::Comment) if (params_.type == InsetNoteParams::Comment)
ss << "\n</comment>\n"; ss << "\n</comment>\n";
@ -268,7 +268,7 @@ int InsetNote::docbook(Buffer const & buf, std::ostream & os,
if (params_.type == InsetNoteParams::Comment) if (params_.type == InsetNoteParams::Comment)
ss << "<remark>\n"; ss << "<remark>\n";
inset.docbook(buf, ss, runparams); InsetText::docbook(buf, ss, runparams);
if (params_.type == InsetNoteParams::Comment) if (params_.type == InsetNoteParams::Comment)
ss << "\n</remark>\n"; ss << "\n</remark>\n";
@ -288,7 +288,7 @@ int InsetNote::plaintext(Buffer const & buf, std::ostream & os,
ostringstream ss; ostringstream ss;
ss << "["; ss << "[";
inset.plaintext(buf, ss, runparams); InsetText::plaintext(buf, ss, runparams);
ss << "]"; ss << "]";
string const str = ss.str(); string const str = ss.str();
@ -306,12 +306,12 @@ void InsetNote::validate(LaTeXFeatures & features) const
features.require("color"); features.require("color");
features.require("lyxgreyedout"); features.require("lyxgreyedout");
} }
inset.validate(features); InsetText::validate(features);
} }
string const InsetNoteMailer:: name_("note"); string const InsetNoteMailer::name_("note");
InsetNoteMailer::InsetNoteMailer(InsetNote & inset) InsetNoteMailer::InsetNoteMailer(InsetNote & inset)
: inset_(inset) : inset_(inset)

View File

@ -73,7 +73,7 @@ int InsetOptArg::latexOptional(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << '['; os << '[';
int const i = inset.latex(buf, os, runparams); int const i = InsetText::latex(buf, os, runparams);
os << ']'; os << ']';
return i + 2; return i + 2;
} }

View File

@ -156,17 +156,13 @@ bool InsetTabular::hasPasteBuffer() const
InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns) InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
: tabular(buf.params(), max(rows, 1), max(columns, 1)), : tabular(buf.params(), max(rows, 1), max(columns, 1)),
buffer_(&buf), cursorx_(0) buffer_(&buf), cursorx_(0)
{ {}
tabular.setOwner(this);
}
InsetTabular::InsetTabular(InsetTabular const & tab) InsetTabular::InsetTabular(InsetTabular const & tab)
: UpdatableInset(tab), tabular(tab.tabular), : UpdatableInset(tab), tabular(tab.tabular),
buffer_(tab.buffer_), cursorx_(0) buffer_(tab.buffer_), cursorx_(0)
{ {}
tabular.setOwner(this);
}
InsetTabular::~InsetTabular() InsetTabular::~InsetTabular()
@ -265,9 +261,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
BufferView * bv = pi.base.bv; BufferView * bv = pi.base.bv;
setPosCache(pi, x, y); setPosCache(pi, x, y);
if (!owner()) x += scroll();
x += scroll();
x += ADD_TO_TABULAR_WIDTH; x += ADD_TO_TABULAR_WIDTH;
int idx = 0; int idx = 0;
@ -463,7 +457,6 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument))); scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
else else
scroll(cur.bv(), strToInt(cmd.argument)); scroll(cur.bv(), strToInt(cmd.argument));
cur.update();
break; break;
case LFUN_RIGHTSEL: case LFUN_RIGHTSEL:
@ -802,13 +795,16 @@ int InsetTabular::docbook(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
int ret = 0; int ret = 0;
InsetOld * master; InsetOld * master = 0;
#warning Why not pass a proper DocIterator here?
#if 0
// if the table is inside a float it doesn't need the informaltable // if the table is inside a float it doesn't need the informaltable
// wrapper. Search for it. // wrapper. Search for it.
for (master = owner(); master; master = master->owner()) for (master = owner(); master; master = master->owner())
if (master->lyxCode() == InsetOld::FLOAT_CODE) if (master->lyxCode() == InsetOld::FLOAT_CODE)
break; break;
#endif
if (!master) { if (!master) {
os << "<informaltable>"; os << "<informaltable>";
@ -1100,13 +1096,11 @@ void InsetTabular::tabularFeatures(LCursor & cur,
case LyXTabular::APPEND_ROW: case LyXTabular::APPEND_ROW:
// append the row into the tabular // append the row into the tabular
tabular.appendRow(bv.buffer()->params(), actcell); tabular.appendRow(bv.buffer()->params(), actcell);
tabular.setOwner(this);
break; break;
case LyXTabular::APPEND_COLUMN: case LyXTabular::APPEND_COLUMN:
// append the column into the tabular // append the column into the tabular
tabular.appendColumn(bv.buffer()->params(), actcell); tabular.appendColumn(bv.buffer()->params(), actcell);
tabular.setOwner(this);
actcell = tabular.getCellNumber(row, column); actcell = tabular.getCellNumber(row, column);
break; break;
@ -1553,7 +1547,6 @@ bool InsetTabular::copySelection(LCursor & cur)
getSelection(cur, rs, re, cs, ce); getSelection(cur, rs, re, cs, ce);
paste_tabular.reset(new LyXTabular(tabular)); paste_tabular.reset(new LyXTabular(tabular));
paste_tabular->setOwner(this);
for (int i = 0; i < rs; ++i) for (int i = 0; i < rs; ++i)
paste_tabular->deleteRow(0); paste_tabular->deleteRow(0);
@ -1611,7 +1604,6 @@ bool InsetTabular::pasteSelection(LCursor & cur)
} }
InsetText & inset = tabular.getCellInset(r2, c2); InsetText & inset = tabular.getCellInset(r2, c2);
inset = paste_tabular->getCellInset(r1, c1); inset = paste_tabular->getCellInset(r1, c1);
inset.setOwner(this);
inset.markNew(); inset.markNew();
} }
} }
@ -1642,8 +1634,8 @@ bool InsetTabular::isRightToLeft(LCursor & cur)
void InsetTabular::getSelection(LCursor & cur, void InsetTabular::getSelection(LCursor & cur,
int & rs, int & re, int & cs, int & ce) const int & rs, int & re, int & cs, int & ce) const
{ {
CursorSlice & beg = cur.selBegin(); CursorSlice const & beg = cur.selBegin();
CursorSlice & end = cur.selEnd(); CursorSlice const & end = cur.selEnd();
cs = tabular.column_of_cell(beg.idx()); cs = tabular.column_of_cell(beg.idx());
ce = tabular.column_of_cell(end.idx()); ce = tabular.column_of_cell(end.idx());
if (cs > ce) { if (cs > ce) {
@ -1738,7 +1730,6 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
if (usePaste) { if (usePaste) {
paste_tabular.reset( paste_tabular.reset(
new LyXTabular(bv.buffer()->params(), rows, maxCols)); new LyXTabular(bv.buffer()->params(), rows, maxCols));
paste_tabular->setOwner(this);
loctab = paste_tabular.get(); loctab = paste_tabular.get();
cols = 0; cols = 0;
} else { } else {
@ -1765,8 +1756,7 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
// we can only set this if we are not too far right // we can only set this if we are not too far right
if (cols < columns) { if (cols < columns) {
InsetText & inset = loctab->getCellInset(cell); InsetText & inset = loctab->getCellInset(cell);
LyXFont const font = inset.text_. LyXFont const font = inset.text_.getFont(0, 0);
getFont(inset.paragraphs().begin(), 0);
inset.setText(buf.substr(op, p - op), font); inset.setText(buf.substr(op, p - op), font);
++cols; ++cols;
++cell; ++cell;
@ -1776,8 +1766,7 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
// we can only set this if we are not too far right // we can only set this if we are not too far right
if (cols < columns) { if (cols < columns) {
InsetText & inset = tabular.getCellInset(cell); InsetText & inset = tabular.getCellInset(cell);
LyXFont const font = inset.text_. LyXFont const font = inset.text_.getFont(0, 0);
getFont(inset.paragraphs().begin(), 0);
inset.setText(buf.substr(op, p - op), font); inset.setText(buf.substr(op, p - op), font);
} }
cols = ocol; cols = ocol;
@ -1792,7 +1781,7 @@ bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
// check for the last cell if there is no trailing '\n' // check for the last cell if there is no trailing '\n'
if (cell < cells && op < len) { if (cell < cells && op < len) {
InsetText & inset = loctab->getCellInset(cell); InsetText & inset = loctab->getCellInset(cell);
LyXFont const font = inset.text_.getFont(inset.paragraphs().begin(), 0); LyXFont const font = inset.text_.getFont(0, 0);
inset.setText(buf.substr(op, len - op), font); inset.setText(buf.substr(op, len - op), font);
} }
return true; return true;

View File

@ -107,7 +107,6 @@ void InsetText::init()
for (; pit != end; ++pit) for (; pit != end; ++pit)
pit->setInsetOwner(this); pit->setInsetOwner(this);
old_par = -1; old_par = -1;
in_insetAllowed = false;
} }
@ -201,8 +200,7 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
BufferView * bv = pi.base.bv; BufferView * bv = pi.base.bv;
bv->hideCursor(); bv->hideCursor();
if (!owner()) x += scroll();
x += scroll();
y += bv->top_y() - text_.ascent(); y += bv->top_y() - text_.ascent();
text_.draw(pi, x, y); text_.draw(pi, x, y);
@ -220,11 +218,10 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
void InsetText::drawFrame(Painter & pain, int x, int y) const void InsetText::drawFrame(Painter & pain, int x, int y) const
{ {
int const ttoD2 = TEXT_TO_INSET_OFFSET / 2; int const frame_x = x + TEXT_TO_INSET_OFFSET / 2;
int const frame_x = x + ttoD2; int const frame_y = y - dim_.asc + TEXT_TO_INSET_OFFSET / 2;
int const frame_y = y - dim_.asc + ttoD2; int const frame_w = text_.width();
int const frame_w = dim_.wid - TEXT_TO_INSET_OFFSET; int const frame_h = text_.height();
int const frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
pain.rectangle(frame_x, frame_y, frame_w, frame_h, frameColor()); pain.rectangle(frame_x, frame_y, frame_w, frame_h, frameColor());
} }
@ -246,7 +243,7 @@ void InsetText::updateLocal(LCursor & cur)
} }
cur.clearSelection(); cur.clearSelection();
mergeParagraph(cur.bv().buffer()->params(), paragraphs(), first); mergeParagraph(cur.bv().buffer()->params(), paragraphs(), 0);
} }
} }
@ -258,7 +255,7 @@ void InsetText::updateLocal(LCursor & cur)
lv->updateMenubar(); lv->updateMenubar();
lv->updateToolbar(); lv->updateToolbar();
if (old_par != cur.par()) { if (old_par != cur.par()) {
lv->setLayout(text_.getPar(cur.par())->layout()->name()); lv->setLayout(text_.getPar(cur.par()).layout()->name());
old_par = cur.par(); old_par = cur.par();
} }
} }
@ -309,9 +306,7 @@ InsetBase * InsetText::editXY(LCursor & cur, int x, int y)
void InsetText::priv_dispatch(LCursor & cur, FuncRequest & cmd) void InsetText::priv_dispatch(LCursor & cur, FuncRequest & cmd)
{ {
//lyxerr << "InsetText::priv_dispatch (begin), act: " //lyxerr << "InsetText::priv_dispatch: " << cmd.action << " " << endl;
// << cmd.action << " " << endl;
setViewCache(&cur.bv()); setViewCache(&cur.bv());
bool was_empty = paragraphs().begin()->empty() && paragraphs().size() == 1; bool was_empty = paragraphs().begin()->empty() && paragraphs().size() == 1;
@ -327,8 +322,6 @@ void InsetText::priv_dispatch(LCursor & cur, FuncRequest & cmd)
font.setLanguage(cur.bv().getParentLanguage(this)); font.setLanguage(cur.bv().getParentLanguage(this));
text_.setFont(cur, font, false); text_.setFont(cur, font, false);
} }
//lyxerr << "InsetText::priv_dispatch (end)" << endl;
} }
@ -392,21 +385,6 @@ void InsetText::getCursorPos(CursorSlice const & cur, int & x, int & y) const
} }
bool InsetText::insetAllowed(InsetOld::Code code) const
{
// in_insetAllowed is a really gross hack,
// to allow us to call the owner's insetAllowed
// without stack overflow, which can happen
// when the owner uses InsetCollapsable::insetAllowed()
if (in_insetAllowed)
return true;
in_insetAllowed = true;
bool const ret = owner() && owner()->insetAllowed(code);
in_insetAllowed = false;
return ret;
}
bool InsetText::showInsetDialog(BufferView *) const bool InsetText::showInsetDialog(BufferView *) const
{ {
return false; return false;
@ -499,12 +477,6 @@ void InsetText::removeNewlines()
} }
int InsetText::scroll(bool /*recursive*/) const
{
return UpdatableInset::scroll(false);
}
void InsetText::clearInset(Painter & pain, int x, int y) const void InsetText::clearInset(Painter & pain, int x, int y) const
{ {
int w = dim_.wid; int w = dim_.wid;
@ -537,7 +509,8 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
ParagraphList::iterator pit = plist.begin(); ParagraphList::iterator pit = plist.begin();
ParagraphList::iterator ins = paragraphs().insert(paragraphs().end(), *pit); ParagraphList::iterator ins = paragraphs().insert(paragraphs().end(), *pit);
++pit; ++pit;
mergeParagraph(buffer->params(), paragraphs(), boost::prior(ins)); mergeParagraph(buffer->params(), paragraphs(),
ins - paragraphs().begin() - 1);
ParagraphList::iterator pend = plist.end(); ParagraphList::iterator pend = plist.end();
for (; pit != pend; ++pit) for (; pit != pend; ++pit)

View File

@ -13,7 +13,6 @@
#define INSETTEXT_H #define INSETTEXT_H
#include "updatableinset.h" #include "updatableinset.h"
#include "ParagraphList_fwd.h"
#include "RowList_fwd.h" #include "RowList_fwd.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "lyxtext.h" #include "lyxtext.h"
@ -29,7 +28,7 @@ class Dimension;
class LColor_color; class LColor_color;
class CursorSlice; class CursorSlice;
class Painter; class Painter;
class Paragraph; class ParagraphList;
class Row; class Row;
@ -91,8 +90,6 @@ public:
/// FIXME, document /// FIXME, document
void getCursorPos(CursorSlice const & cur, int & x, int & y) const; void getCursorPos(CursorSlice const & cur, int & x, int & y) const;
/// ///
bool insetAllowed(InsetOld::Code) const;
///
void setFont(BufferView *, LyXFont const &, void setFont(BufferView *, LyXFont const &,
bool toggleall = false, bool toggleall = false,
bool selectall = false); bool selectall = false);
@ -115,22 +112,12 @@ public:
/// Appends \c list with all labels found within this inset. /// Appends \c list with all labels found within this inset.
void getLabelList(Buffer const &, std::vector<std::string> & list) const; void getLabelList(Buffer const &, std::vector<std::string> & list) const;
/// ///
int scroll(bool recursive = true) const;
///
void scroll(BufferView & bv, float sx) const {
UpdatableInset::scroll(bv, sx);
}
///
void scroll(BufferView & bv, int offset) const {
UpdatableInset::scroll(bv, offset);
}
///
LyXText * getText(int) const; LyXText * getText(int) const;
/// ///
bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const; bool getStatus(LCursor & cur, FuncRequest const & cmd, FuncStatus &) const;
/// mark as erased for change tracking /// mark as erased for change tracking
void markErased() { clear(true); }; void markErased() { clear(true); }
/** /**
* Mark as new. Used when pasting in tabular, and adding rows * Mark as new. Used when pasting in tabular, and adding rows
* or columns. Note that pasting will ensure that tracking already * or columns. Note that pasting will ensure that tracking already
@ -156,9 +143,10 @@ public:
/// ///
ParagraphList & paragraphs() const; ParagraphList & paragraphs() const;
private: protected:
/// ///
void priv_dispatch(LCursor & cur, FuncRequest & cmd); void priv_dispatch(LCursor & cur, FuncRequest & cmd);
private:
/// ///
void updateLocal(LCursor &); void updateLocal(LCursor &);
/// ///
@ -184,12 +172,7 @@ private:
*/ */
int frame_color_; int frame_color_;
/// ///
mutable lyx::paroffset_type old_par; mutable lyx::par_type old_par;
/** to remember old painted frame dimensions to clear it on
* the right spot!
*/
mutable bool in_insetAllowed;
public: public:
/// ///
mutable LyXText text_; mutable LyXText text_;

View File

@ -70,7 +70,7 @@ InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
setInsetName(type); setInsetName(type);
LyXTextClass const & tclass = bp.getLyXTextClass(); LyXTextClass const & tclass = bp.getLyXTextClass();
if (tclass.hasLayout(caplayout)) if (tclass.hasLayout(caplayout))
inset.paragraphs().begin()->layout(tclass[caplayout]); paragraphs().begin()->layout(tclass[caplayout]);
} }
@ -180,13 +180,10 @@ int InsetWrap::latex(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << "\\begin{floating" << params_.type << '}'; os << "\\begin{floating" << params_.type << '}';
if (!params_.placement.empty()) { if (!params_.placement.empty())
os << '[' << params_.placement << ']'; os << '[' << params_.placement << ']';
} os << '{' << params_.width.asLatexString() << "}%\n";
os << '{' << params_.width.asLatexString() << "}%\n"; int const i = InsetText::latex(buf, os, runparams);
int const i = inset.latex(buf, os, runparams);
os << "\\end{floating" << params_.type << "}%\n"; os << "\\end{floating" << params_.type << "}%\n";
return i + 2; return i + 2;
} }
@ -196,9 +193,8 @@ int InsetWrap::docbook(Buffer const & buf, ostream & os,
OutputParams const & runparams) const OutputParams const & runparams) const
{ {
os << '<' << params_.type << '>'; os << '<' << params_.type << '>';
int const i = inset.docbook(buf, os, runparams); int const i = InsetText::docbook(buf, os, runparams);
os << "</" << params_.type << '>'; os << "</" << params_.type << '>';
return i; return i;
} }
@ -218,7 +214,7 @@ bool InsetWrap::insetAllowed(InsetOld::Code code) const
bool InsetWrap::showInsetDialog(BufferView * bv) const bool InsetWrap::showInsetDialog(BufferView * bv) const
{ {
if (!inset.showInsetDialog(bv)) if (!InsetText::showInsetDialog(bv))
InsetWrapMailer(const_cast<InsetWrap &>(*this)).showDialog(bv); InsetWrapMailer(const_cast<InsetWrap &>(*this)).showDialog(bv);
return true; return true;
} }
@ -227,8 +223,8 @@ bool InsetWrap::showInsetDialog(BufferView * bv) const
void InsetWrap::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const void InsetWrap::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
{ {
// Now find the caption in the float... // Now find the caption in the float...
ParagraphList::iterator tmp = inset.paragraphs().begin(); ParagraphList::iterator tmp = paragraphs().begin();
ParagraphList::iterator end = inset.paragraphs().end(); ParagraphList::iterator end = paragraphs().end();
for (; tmp != end; ++tmp) { for (; tmp != end; ++tmp) {
if (tmp->layout()->name() == caplayout) { if (tmp->layout()->name() == caplayout) {

View File

@ -13,7 +13,6 @@
#include "iterators.h" #include "iterators.h"
#include "paragraph.h" #include "paragraph.h"
#include "PosIterator.h"
#include "cursor.h" #include "cursor.h"
#include "buffer.h" #include "buffer.h"
#include "BufferView.h" #include "BufferView.h"
@ -25,6 +24,8 @@
#include <boost/next_prior.hpp> #include <boost/next_prior.hpp>
using lyx::par_type;
using boost::next; using boost::next;
/// ///
@ -32,12 +33,11 @@ using boost::next;
/// ///
ParPosition::ParPosition(ParagraphList::iterator p, ParagraphList const & pl) ParPosition::ParPosition(par_type p, ParagraphList const & pl)
: pit(p), plist(&pl) : pit(p), plist(&pl)
{ {
if (p != const_cast<ParagraphList&>(pl).end()) { if (p != pl.size())
it.reset(p->insetlist.begin()); it.reset(const_cast<InsetList&>(pl[p].insetlist).begin());
}
} }
@ -57,7 +57,7 @@ bool operator!=(ParPosition const & pos1, ParPosition const & pos2)
/// ParIterator /// ParIterator
/// ///
ParIterator::ParIterator(ParagraphList::iterator pit, ParagraphList const & pl) ParIterator::ParIterator(par_type pit, ParagraphList const & pl)
{ {
positions_.push_back(ParPosition(pit, pl)); positions_.push_back(ParPosition(pit, pl));
} }
@ -75,7 +75,7 @@ ParIterator::ParIterator(ParIterator const & pi)
void ParIterator::operator=(ParIterator const & pi) void ParIterator::operator=(ParIterator const & pi)
{ {
ParIterator tmp(pi); ParIterator tmp(pi);
swap(positions_ , tmp.positions_); swap(positions_, tmp.positions_);
} }
@ -90,7 +90,7 @@ ParIterator & ParIterator::operator++()
if (LyXText * text = (*p.it)->inset->getText(*p.index)) { if (LyXText * text = (*p.it)->inset->getText(*p.index)) {
ParagraphList & plist = text->paragraphs(); ParagraphList & plist = text->paragraphs();
if (!plist.empty()) { if (!plist.empty()) {
positions_.push_back(ParPosition(plist.begin(), plist)); positions_.push_back(ParPosition(0, plist));
return *this; return *this;
} }
} }
@ -99,29 +99,28 @@ ParIterator & ParIterator::operator++()
// The following line is needed because the value of // The following line is needed because the value of
// p.it may be invalid if inset was added/removed to // p.it may be invalid if inset was added/removed to
// the paragraph pointed by the iterator // the paragraph pointed by the iterator
p.it.reset(p.pit->insetlist.begin()); p.it.reset(const_cast<InsetList&>((*p.plist)[p.pit].insetlist).begin());
} }
// Try to find the next inset that contains paragraphs // Try to find the next inset that contains paragraphs
InsetList::iterator end = p.pit->insetlist.end(); InsetList::iterator end =
const_cast<InsetList&>((*p.plist)[p.pit].insetlist).end();
for (; *p.it != end; ++(*p.it)) { for (; *p.it != end; ++(*p.it)) {
if (LyXText * text = (*p.it)->inset->getText(0)) { if (LyXText * text = (*p.it)->inset->getText(0)) {
ParagraphList & plist = text->paragraphs(); ParagraphList & plist = text->paragraphs();
if (!plist.empty()) { if (!plist.empty()) {
p.index.reset(0); p.index.reset(0);
positions_.push_back(ParPosition(plist.begin(), plist)); positions_.push_back(ParPosition(0, plist));
return *this; return *this;
} }
} }
} }
// Try to go to the next paragarph // Try to go to the next paragarph
if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end() if (p.pit + 1 != p.plist->size() || positions_.size() == 1) {
|| positions_.size() == 1) {
++p.pit; ++p.pit;
p.index.reset(); p.index.reset();
p.it.reset(); p.it.reset();
return *this; return *this;
} }
@ -165,23 +164,23 @@ int ParIterator::index() const
Paragraph & ParIterator::operator*() const Paragraph & ParIterator::operator*() const
{ {
return *positions_.back().pit; return plist()[positions_.back().pit];
} }
ParagraphList::iterator ParIterator::pit() const par_type ParIterator::pit() const
{ {
return positions_.back().pit; return positions_.back().pit;
} }
ParagraphList::iterator ParIterator::operator->() const Paragraph * ParIterator::operator->() const
{ {
return positions_.back().pit; return &plist()[positions_.back().pit];
} }
ParagraphList::iterator ParIterator::outerPar() const par_type ParIterator::outerPar() const
{ {
return positions_[0].pit; return positions_[0].pit;
} }
@ -199,22 +198,23 @@ ParagraphList & ParIterator::plist() const
} }
ParIterator::ParIterator(PosIterator const & pos) ParIterator::ParIterator(DocumentIterator const & cur)
{ {
int const size = pos.stack_.size(); int const size = cur.size();
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
PosIteratorItem const & it = pos.stack_[i]; CursorSlice sl = cur[i];
ParPosition pp(it.pit, *it.pl); ParPosition pp(sl.par(), sl.text()->paragraphs());
if (i < size - 1) { if (i < size - 1) {
InsetBase * inset = it.pit->getInset(it.pos); Paragraph & par = sl.text()->paragraphs()[sl.par()];
InsetBase * inset = par.getInset(sl.pos());
BOOST_ASSERT(inset); BOOST_ASSERT(inset);
InsetList::iterator beg = it.pit->insetlist.begin(); InsetList::iterator beg = par.insetlist.begin();
InsetList::iterator end = it.pit->insetlist.end(); InsetList::iterator end = par.insetlist.end();
for ( ; beg != end && beg->inset != inset; ++beg) for ( ; beg != end && beg->inset != inset; ++beg)
; ;
pp.it.reset(beg); pp.it.reset(beg);
pp.index.reset(it.index - 1); pp.index.reset(sl.idx() - 1);
} }
positions_.push_back(pp); positions_.push_back(pp);
} }
@ -238,8 +238,7 @@ bool operator!=(ParIterator const & iter1, ParIterator const & iter2)
/// ///
ParConstIterator::ParConstIterator(ParagraphList::iterator pit, ParConstIterator::ParConstIterator(par_type pit, ParagraphList const & pl)
ParagraphList const & pl)
{ {
positions_.push_back(ParPosition(pit, pl)); positions_.push_back(ParPosition(pit, pl));
} }
@ -265,7 +264,7 @@ ParConstIterator & ParConstIterator::operator++()
if (LyXText * text = (*p.it)->inset->getText(*p.index)) { if (LyXText * text = (*p.it)->inset->getText(*p.index)) {
ParagraphList & plist = text->paragraphs(); ParagraphList & plist = text->paragraphs();
if (!plist.empty()) { if (!plist.empty()) {
positions_.push_back(ParPosition(plist.begin(), plist)); positions_.push_back(ParPosition(0, plist));
return *this; return *this;
} }
} }
@ -274,29 +273,28 @@ ParConstIterator & ParConstIterator::operator++()
// The following line is needed because the value of // The following line is needed because the value of
// p.it may be invalid if inset was added/removed to // p.it may be invalid if inset was added/removed to
// the paragraph pointed by the iterator // the paragraph pointed by the iterator
p.it.reset(p.pit->insetlist.begin()); p.it.reset(const_cast<InsetList&>((*p.plist)[p.pit].insetlist).begin());
} }
// Try to find the next inset that contains paragraphs // Try to find the next inset that contains paragraphs
InsetList::iterator end = p.pit->insetlist.end(); InsetList::iterator end =
const_cast<InsetList&>((*p.plist)[p.pit].insetlist).end();
for (; *p.it != end; ++(*p.it)) { for (; *p.it != end; ++(*p.it)) {
if (LyXText * text = (*p.it)->inset->getText(0)) { if (LyXText * text = (*p.it)->inset->getText(0)) {
ParagraphList & plist = text->paragraphs(); ParagraphList & plist = text->paragraphs();
if (!plist.empty()) { if (!plist.empty()) {
p.index.reset(0); p.index.reset(0);
positions_.push_back(ParPosition(plist.begin(), plist)); positions_.push_back(ParPosition(0, plist));
return *this; return *this;
} }
} }
} }
// Try to go to the next paragarph // Try to go to the next paragarph
if (next(p.pit) != const_cast<ParagraphList*>(p.plist)->end() if (p.pit + 1 != p.plist->size() || positions_.size() == 1) {
|| positions_.size() == 1) {
++p.pit; ++p.pit;
p.index.reset(); p.index.reset();
p.it.reset(); p.it.reset();
return *this; return *this;
} }
@ -310,19 +308,19 @@ ParConstIterator & ParConstIterator::operator++()
Paragraph const & ParConstIterator::operator*() const Paragraph const & ParConstIterator::operator*() const
{ {
return *positions_.back().pit; return plist()[positions_.back().pit];
} }
ParagraphList::const_iterator ParConstIterator::pit() const par_type ParConstIterator::pit() const
{ {
return positions_.back().pit; return positions_.back().pit;
} }
ParagraphList::const_iterator ParConstIterator::operator->() const Paragraph const * ParConstIterator::operator->() const
{ {
return positions_.back().pit; return &plist()[positions_.back().pit];
} }

View File

@ -12,8 +12,8 @@
#ifndef ITERATORS_H #ifndef ITERATORS_H
#define ITERATORS_H #define ITERATORS_H
#include "ParagraphList_fwd.h"
#include "InsetList.h" #include "InsetList.h"
#include "ParagraphList_fwd.h" // only for ParagraphList::value_type
#include "support/types.h" #include "support/types.h"
@ -21,19 +21,19 @@
#include <vector> #include <vector>
class LyXText;
class InsetBase;
class Cursor;
class Buffer; class Buffer;
class PosIterator; class Cursor;
class InsetBase;
class LyXText;
class DocumentIterator;
class ParPosition { class ParPosition {
public: public:
/// ///
ParPosition(ParagraphList::iterator p, ParagraphList const & pl); ParPosition(lyx::par_type p, ParagraphList const & pl);
/// ///
ParagraphList::iterator pit; lyx::par_type pit;
/// ///
ParagraphList const * plist; ParagraphList const * plist;
/// ///
@ -48,13 +48,13 @@ class ParIterator : public std::iterator<
ParagraphList::value_type> { ParagraphList::value_type> {
public: public:
/// ///
ParIterator(ParagraphList::iterator pit, ParagraphList const & pl); ParIterator(lyx::par_type pit, ParagraphList const & pl);
/// ///
~ParIterator(); ~ParIterator();
/// ///
ParIterator(ParIterator const &); ParIterator(ParIterator const &);
/// ///
ParIterator(PosIterator const &); ParIterator(DocumentIterator const &);
/// ///
void operator=(ParIterator const &); void operator=(ParIterator const &);
/// ///
@ -62,11 +62,11 @@ public:
/// ///
Paragraph & operator*() const; Paragraph & operator*() const;
/// ///
ParagraphList::iterator operator->() const; Paragraph * operator->() const;
/// This gives us the top-most parent paragraph /// This gives us the top-most parent paragraph
ParagraphList::iterator outerPar() const; lyx::par_type outerPar() const;
/// ///
ParagraphList::iterator pit() const; lyx::par_type pit() const;
/// ///
ParagraphList & plist() const; ParagraphList & plist() const;
/// returns 'innermost' LyXText /// returns 'innermost' LyXText
@ -99,7 +99,7 @@ class ParConstIterator : public std::iterator<
ParagraphList::value_type> { ParagraphList::value_type> {
public: public:
/// ///
ParConstIterator(ParagraphList::iterator pit, ParagraphList const & pl); ParConstIterator(lyx::par_type pit, ParagraphList const & pl);
/// ///
~ParConstIterator(); ~ParConstIterator();
/// ///
@ -107,22 +107,23 @@ public:
/// ///
ParConstIterator & operator++(); ParConstIterator & operator++();
/// ///
ParagraphList::const_iterator pit() const; lyx::par_type pit() const;
/// ///
Paragraph const & operator*() const; Paragraph const & operator*() const;
/// ///
ParagraphList::const_iterator operator->() const; Paragraph const * operator->() const;
/// ///
ParagraphList const & plist() const; ParagraphList const & plist() const;
/// depth of nesting /// depth of nesting
size_t size() const; size_t size() const;
///
typedef std::vector<ParPosition> PosHolder; typedef std::vector<ParPosition> PosHolder;
PosHolder const & positions() const ///
{ PosHolder const & positions() const { return positions_; }
return positions_;
}
private: private:
///
PosHolder positions_; PosHolder positions_;
}; };

View File

@ -9,8 +9,8 @@
* To add a new function: * To add a new function:
* - add a new enum constant immediately before LFUN_LASTACTION * - add a new enum constant immediately before LFUN_LASTACTION
* - add an appropriate line in LyXAction.C * - add an appropriate line in LyXAction.C
* - add a branch to the suitable ::dispatch() methods * - add a branch to a suitable ::priv_dispatch() method
* - add correct test in LyXFunc::getStatus() * - add correct test to the corresponding ::getStatus() method
*/ */
#ifndef LFUNS_H #ifndef LFUNS_H
@ -22,7 +22,9 @@
* through which the frontends communicate with the core. * through which the frontends communicate with the core.
* *
* They are managed in LyXAction.C and handled in various * They are managed in LyXAction.C and handled in various
* ::dispatch() functions, starting with LyXFunc.C:dispatch() * ::dispatch() functions, starting with LyXFunc.C:dispatch(),
* BufferView_pimpl::dispatch(), LCursor::dispatch() and
* Inset*::priv_dispatch();
*/ */
enum kb_action { enum kb_action {
LFUN_UNKNOWN_ACTION = -1, LFUN_UNKNOWN_ACTION = -1,

View File

@ -17,6 +17,7 @@
#include "buffer.h" #include "buffer.h"
#include "cursor.h" #include "cursor.h"
#include "CutAndPaste.h"
#include "BufferView.h" #include "BufferView.h"
#include "debug.h" #include "debug.h"
#include "iterators.h" #include "iterators.h"
@ -24,7 +25,6 @@
#include "gettext.h" #include "gettext.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "paragraph.h" #include "paragraph.h"
#include "PosIterator.h"
#include "undo.h" #include "undo.h"
#include "frontends/Alert.h" #include "frontends/Alert.h"
@ -39,6 +39,9 @@ using lyx::support::lowercase;
using lyx::support::uppercase; using lyx::support::uppercase;
using lyx::support::split; using lyx::support::split;
using lyx::par_type;
using lyx::pos_type;
using std::advance; using std::advance;
using std::ostringstream; using std::ostringstream;
using std::string; using std::string;
@ -56,21 +59,181 @@ bool parse_bool(string & howto)
} }
bool find(BufferView * bv, class MatchString : public std::binary_function<Paragraph, lyx::pos_type, bool>
string const & searchstr, bool cs, bool mw, bool fw); {
public:
MatchString(string const & str, bool cs, bool mw)
: str(str), cs(cs), mw(mw)
{}
// returns true if the specified string is at the specified position
bool operator()(Paragraph const & par, lyx::pos_type pos) const
{
string::size_type const size = str.length();
lyx::pos_type i = 0;
lyx::pos_type const parsize = par.size();
for (i = 0; pos + i < parsize; ++i) {
if (string::size_type(i) >= size)
break;
if (cs && str[i] != par.getChar(pos + i))
break;
if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
break;
}
if (size != string::size_type(i))
return false;
// if necessary, check whether string matches word
if (mw) {
if (pos > 0 && IsLetterCharOrDigit(par.getChar(pos - 1)))
return false;
if (pos + lyx::pos_type(size) < parsize
&& IsLetterCharOrDigit(par.getChar(pos + size)));
return false;
}
return true;
}
private:
// search string
string str;
// case sensitive
bool cs;
// match whole words only
bool mw;
};
int replace(BufferView * bv, bool findForward(DocumentIterator & cur, MatchString const & match)
string const & searchstr, string const & replacestr, {
bool cs, bool mw, bool fw); for (; cur.size(); cur.forwardChar())
if (match(cur.paragraph(), cur.pos()))
return true;
return false;
}
bool findBackwards(DocumentIterator & cur, MatchString const & match)
{
for (; cur.size(); cur.backwardChar())
if (match(cur.paragraph(), cur.pos()))
return true;
return false;
}
bool findChange(DocumentIterator & cur)
{
for (; cur.size(); cur.forwardChar())
if ((cur.paragraph().empty() || !cur.empty())
&& cur.paragraph().lookupChange(cur.pos()) != Change::UNCHANGED)
return true;
return false;
}
bool searchAllowed(BufferView * bv, string const & str)
{
if (str.empty()) {
Alert::error(_("Search error"), _("Search string is empty"));
return false;
}
return bv->available();
}
bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw)
{
if (!searchAllowed(bv, searchstr))
return false;
DocumentIterator cur = bv->cursor();
MatchString const match(searchstr, cs, mw);
bool found = fw ? findForward(cur, match) : findBackwards(cur, match);
if (found)
bv->putSelectionAt(cur, searchstr.length(), !fw);
return found;
}
int replaceAll(BufferView * bv, int replaceAll(BufferView * bv,
string const & searchstr, string const & replacestr, string const & searchstr, string const & replacestr,
bool cs, bool mw); bool cs, bool mw)
{
Buffer & buf = *bv->buffer();
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0;
recordUndoFullDocument(bv->cursor());
MatchString const match(searchstr, cs, mw);
int num = 0;
int const rsize = replacestr.size();
int const ssize = searchstr.size();
DocumentIterator cur = DocumentIterator(buf.inset());
while (findForward(cur, match)) {
lyx::pos_type pos = cur.pos();
LyXFont const font
= cur.paragraph().getFontSettings(buf.params(), pos);
int striked = ssize - cur.paragraph().erase(pos, pos + ssize);
cur.paragraph().insert(pos, replacestr, font);
for (int i = 0; i < rsize + striked; ++i)
cur.forwardChar();
++num;
}
bv->text()->init(bv);
bv->putSelectionAt(DocumentIterator(buf.inset()), 0, false);
if (num)
buf.markDirty();
return num;
}
bool findChange(PosIterator & cur, PosIterator const & end); bool stringSelected(BufferView * bv, string const & searchstr,
bool cs, bool mw, bool fw)
{
// if nothing selected or selection does not equal search
// string search and select next occurance and return
string const & str1 = searchstr;
string const str2 = bv->cursor().selectionAsString(false);
if ((cs && str1 != str2) || lowercase(str1) != lowercase(str2)) {
find(bv, searchstr, cs, mw, fw);
return false;
}
return true;
}
int replace(BufferView * bv, string const & searchstr,
string const & replacestr, bool cs, bool mw, bool fw)
{
if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
return 0;
if (!stringSelected(bv, searchstr, cs, mw, fw))
return 0;
LCursor & cur = bv->cursor();
lyx::cap::replaceSelectionWithString(cur, replacestr);
lyx::cap::setSelectionRange(cur, replacestr.length());
cur.top() = fw ? cur.selEnd() : cur.selBegin();
bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw);
bv->update();
return 1;
}
} // namespace anon } // namespace anon
@ -86,7 +249,6 @@ string const find2string(string const & search,
<< int(casesensitive) << ' ' << int(casesensitive) << ' '
<< int(matchword) << ' ' << int(matchword) << ' '
<< int(forward); << int(forward);
return ss.str(); return ss.str();
} }
@ -102,7 +264,6 @@ string const replace2string(string const & search, string const & replace,
<< int(matchword) << ' ' << int(matchword) << ' '
<< int(all) << ' ' << int(all) << ' '
<< int(forward); << int(forward);
return ss.str(); return ss.str();
} }
@ -153,11 +314,9 @@ void replace(BufferView * bv, FuncRequest const & ev)
LyXView * lv = bv->owner(); LyXView * lv = bv->owner();
int const replace_count = all ? int const replace_count = all
::replaceAll(bv, search, replace, ? ::replaceAll(bv, search, replace, casesensitive, matchword)
casesensitive, matchword) : : ::replace(bv, search, replace, casesensitive, matchword, forward);
::replace(bv, search, replace,
casesensitive, matchword, forward);
if (replace_count == 0) { if (replace_count == 0) {
lv->message(_("String not found!")); lv->message(_("String not found!"));
@ -178,21 +337,20 @@ bool findNextChange(BufferView * bv)
if (!bv->available()) if (!bv->available())
return false; return false;
PosIterator cur = PosIterator(*bv); DocumentIterator cur = DocumentIterator(bv->buffer()->inset());
PosIterator const endit = bv->buffer()->pos_iterator_end();
if (!findChange(cur, endit)) if (!findChange(cur))
return false; return false;
ParagraphList::iterator pit = cur.pit(); Paragraph const & par = cur.paragraph();
pos_type pos = cur.pos(); pos_type pos = cur.pos();
Change orig_change = pit->lookupChangeFull(pos); Change orig_change = par.lookupChangeFull(pos);
pos_type parsize = pit->size(); pos_type parsize = par.size();
pos_type end = pos; pos_type end = pos;
for (; end != parsize; ++end) { for (; end != parsize; ++end) {
Change change = pit->lookupChangeFull(end); Change change = par.lookupChangeFull(end);
if (change != orig_change) { if (change != orig_change) {
// slight UI optimisation: for replacements, we get // slight UI optimisation: for replacements, we get
// text like : _old_new. Consider that as one change. // text like : _old_new. Consider that as one change.
@ -210,194 +368,3 @@ bool findNextChange(BufferView * bv)
} // lyx namespace } // lyx namespace
namespace {
class MatchString : public std::binary_function<Paragraph, lyx::pos_type, bool>
{
public:
MatchString(string const & str, bool cs, bool mw)
: str(str), cs(cs), mw(mw)
{}
// returns true if the specified string is at the specified position
bool operator()(Paragraph const & par, lyx::pos_type pos) const
{
string::size_type const size = str.length();
lyx::pos_type i = 0;
lyx::pos_type const parsize = par.size();
for (i = 0; pos + i < parsize; ++i) {
if (string::size_type(i) >= size)
break;
if (cs && str[i] != par.getChar(pos + i))
break;
if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
break;
}
if (size != string::size_type(i))
return false;
// if necessary, check whether string matches word
if (mw) {
if (pos > 0 && IsLetterCharOrDigit(par.getChar(pos - 1)))
return false;
if (pos + lyx::pos_type(size) < parsize
&& IsLetterCharOrDigit(par.getChar(pos + size)));
return false;
}
return true;
}
private:
// search string
string str;
// case sensitive
bool cs;
// match whole words only
bool mw;
};
bool findForward(PosIterator & cur, PosIterator const & end,
MatchString const & match)
{
for (; cur != end; ++cur) {
if (match(*cur.pit(), cur.pos()))
return true;
}
return false;
}
bool findBackwards(PosIterator & cur, PosIterator const & beg,
MatchString const & match)
{
while (beg != cur) {
--cur;
if (match(*cur.pit(), cur.pos()))
return true;
}
return false;
}
bool findChange(PosIterator & cur, PosIterator const & end)
{
for (; cur != end; ++cur) {
if ((cur.pit()->empty() || !cur.at_end())
&& cur.pit()->lookupChange(cur.pos()) != Change::UNCHANGED)
return true;
}
return false;
}
bool searchAllowed(BufferView * bv, string const & str)
{
if (str.empty()) {
Alert::error(_("Search error"), _("Search string is empty"));
return false;
}
return bv->available();
}
bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw)
{
if (!searchAllowed(bv, searchstr))
return false;
PosIterator cur = PosIterator(*bv);
MatchString const match(searchstr, cs, mw);
PosIterator const end = bv->buffer()->pos_iterator_end();
PosIterator const beg = bv->buffer()->pos_iterator_begin();
bool found = fw ? findForward(cur, end, match)
: findBackwards(cur, beg, match);
if (found)
bv->putSelectionAt(cur, searchstr.length(), !fw);
return found;
}
int replaceAll(BufferView * bv,
string const & searchstr, string const & replacestr,
bool cs, bool mw)
{
Buffer & buf = *bv->buffer();
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0;
recordUndoFullDocument(bv->cursor());
PosIterator cur = buf.pos_iterator_begin();
PosIterator const end = buf.pos_iterator_end();
MatchString const match(searchstr, cs, mw);
int num = 0;
int const rsize = replacestr.size();
int const ssize = searchstr.size();
while (findForward(cur, end, match)) {
lyx::pos_type pos = cur.pos();
LyXFont const font
= cur.pit()->getFontSettings(buf.params(), pos);
int striked = ssize - cur.pit()->erase(pos, pos + ssize);
cur.pit()->insert(pos, replacestr, font);
advance(cur, rsize + striked);
++num;
}
PosIterator beg = buf.pos_iterator_begin();
bv->text()->init(bv);
bv->putSelectionAt(beg, 0, false);
if (num)
buf.markDirty();
return num;
}
bool stringSelected(BufferView * bv, string const & searchstr,
bool cs, bool mw, bool fw)
{
// if nothing selected or selection does not equal search
// string search and select next occurance and return
string const & str1 = searchstr;
string const str2 = bv->cursor().selectionAsString(false);
if ((cs && str1 != str2) || lowercase(str1) != lowercase(str2)) {
find(bv, searchstr, cs, mw, fw);
return false;
}
return true;
}
int replace(BufferView * bv, string const & searchstr,
string const & replacestr, bool cs, bool mw, bool fw)
{
if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
return 0;
if (!stringSelected(bv, searchstr, cs, mw, fw))
return 0;
LyXText * text = bv->getLyXText();
text->replaceSelectionWithString(bv->cursor(), replacestr);
text->setSelectionRange(bv->cursor(), replacestr.length());
bv->cursor().top() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin();
bv->buffer()->markDirty();
find(bv, searchstr, cs, mw, fw);
bv->update();
return 1;
}
} //namespace anon

View File

@ -389,14 +389,6 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
if (!inset) if (!inset)
break; break;
// jump back to owner if an InsetText, so
// we get back to the InsetTabular or whatever
if (inset->lyxCode() == InsetOld::TEXT_CODE)
inset = inset->owner();
lyxerr << "inset 2: " << inset << endl;
if (!inset)
break;
InsetOld::Code code = inset->lyxCode(); InsetOld::Code code = inset->lyxCode();
switch (code) { switch (code) {
case InsetOld::TABULAR_CODE: case InsetOld::TABULAR_CODE:
@ -431,6 +423,7 @@ FuncStatus LyXFunc::getStatus(FuncRequest const & cmd) const
if (!buf) if (!buf)
enable = name == "aboutlyx" enable = name == "aboutlyx"
|| name == "file" || name == "file"
|| name == "forks"
|| name == "preferences" || name == "preferences"
|| name == "texinfo"; || name == "texinfo";
else if (name == "print") else if (name == "print")
@ -586,7 +579,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
bool const fw = action == LFUN_WORDFINDFORWARD; bool const fw = action == LFUN_WORDFINDFORWARD;
string const data = string const data =
lyx::find::find2string(searched_string, true, false, fw); lyx::find::find2string(searched_string, true, false, fw);
view()->dispatch(FuncRequest(LFUN_WORD_FIND, data)); lyx::find::find(view(), FuncRequest(LFUN_WORD_FIND, data));
break; break;
} }
@ -694,13 +687,21 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
break; break;
case LFUN_QUIT: case LFUN_QUIT:
#if 0 #if 1
// test speed of DocumentIterator // test speed of DocumentIterator
lyxerr << "start" << endl; lyxerr << "start" << endl;
for (DocumentIterator it(owner->buffer()->inset()), end; for (DocumentIterator it(owner->buffer()->inset()), end;
it != end; it.forwardPos()) it != end; it.forwardPos())
; ;
lyxerr << "end" << endl; lyxerr << "end" << endl;
#endif
#if 1
// show some sizes
lyxerr << "sizeof Paragraph: " << sizeof(Paragraph) << endl;
lyxerr << "sizeof Spacing: " << sizeof(Spacing) << endl;
lyxerr << "sizeof LyXLength: " << sizeof(LyXLength) << endl;
lyxerr << "sizeof LyXFont: " << sizeof(LyXFont) << endl;
lyxerr << "sizeof LyXAlignment: " << sizeof(LyXAlignment) << endl;
#endif #endif
QuitLyX(); QuitLyX();
break; break;
@ -1108,6 +1109,10 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
break; break;
} }
case LFUN_BREAKLINE: {
#warning swallow 'Return' if the minibuffer is focused. But how?
}
default: { default: {
DispatchResult res = view()->cursor().dispatch(cmd); DispatchResult res = view()->cursor().dispatch(cmd);
if (!res.dispatched()); if (!res.dispatched());
@ -1115,22 +1120,22 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
break; break;
} }
} }
}
if (view()->available()) { if (view()->available()) {
view()->fitCursor(); view()->fitCursor();
view()->update(); view()->update();
view()->cursor().updatePos(); view()->cursor().updatePos();
// if we executed a mutating lfun, mark the buffer as dirty // if we executed a mutating lfun, mark the buffer as dirty
if (getStatus(cmd).enabled() if (getStatus(cmd).enabled()
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer) && !lyxaction.funcHasFlag(cmd.action, LyXAction::NoBuffer)
&& !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly)) && !lyxaction.funcHasFlag(cmd.action, LyXAction::ReadOnly))
view()->buffer()->markDirty(); view()->buffer()->markDirty();
} }
if (view()->cursor().inTexted()) { if (view()->cursor().inTexted()) {
view()->owner()->updateLayoutChoice(); view()->owner()->updateLayoutChoice();
sendDispatchMessage(getMessage(), cmd, verbose); sendDispatchMessage(getMessage(), cmd, verbose);
}
} }
} }

View File

@ -20,8 +20,8 @@
#include "lyxfont.h" #include "lyxfont.h"
#include "layout.h" #include "layout.h"
#include "lyxlayout_ptr_fwd.h" #include "lyxlayout_ptr_fwd.h"
#include "ParagraphList_fwd.h"
#include "RowList_fwd.h" #include "RowList_fwd.h"
#include "ParagraphList_fwd.h"
#include <iosfwd> #include <iosfwd>
@ -39,12 +39,10 @@ class LCursor;
class LyXTextClass; class LyXTextClass;
class MetricsInfo; class MetricsInfo;
class PainterInfo; class PainterInfo;
class Paragraph;
class Row; class Row;
class RowMetrics; class RowMetrics;
class Spacing; class Spacing;
class UpdatableInset;
class VSpace;
/// This class encapsulates the main text data and operations in LyX /// This class encapsulates the main text data and operations in LyX
class LyXText { class LyXText {
@ -52,7 +50,7 @@ public:
/// ///
typedef lyx::pos_type pos_type; typedef lyx::pos_type pos_type;
/// ///
typedef lyx::paroffset_type par_type; typedef lyx::par_type par_type;
/// constructor /// constructor
explicit LyXText(BufferView *); explicit LyXText(BufferView *);
@ -62,36 +60,32 @@ public:
/// update y coordinate cache of all paragraphs /// update y coordinate cache of all paragraphs
void updateParPositions(); void updateParPositions();
/// ///
LyXFont getFont(ParagraphList::iterator pit, pos_type pos) const; LyXFont getFont(par_type pit, pos_type pos) const;
/// ///
LyXFont getLayoutFont(ParagraphList::iterator pit) const; LyXFont getLayoutFont(par_type pit) const;
/// ///
LyXFont getLabelFont(ParagraphList::iterator pit) const; LyXFont getLabelFont(par_type pit) const;
/// ///
void setCharFont(ParagraphList::iterator pit, void setCharFont(par_type pit, pos_type pos, LyXFont const & font);
pos_type pos, LyXFont const & font); ///
void setCharFont(ParagraphList::iterator pit, void setCharFont(par_type pit, pos_type pos, LyXFont const & font,
pos_type pos, LyXFont const & font, bool toggleall); bool toggleall);
/// what you expect when pressing <enter> at cursor position /// what you expect when pressing <enter> at cursor position
void breakParagraph(LCursor & cur, char keep_layout = 0); void breakParagraph(LCursor & cur, char keep_layout = 0);
/** set layout over selection and make a total rebreak of /// set layout over selection
those paragraphs par_type setLayout(par_type start, par_type end,
*/ std::string const & layout);
ParagraphList::iterator
setLayout(ParagraphList::iterator start,
ParagraphList::iterator end,
std::string const & layout);
/// ///
void setLayout(LCursor & cur, std::string const & layout); void setLayout(LCursor & cur, std::string const & layout);
/// Increase or decrease the nesting depth of the selected paragraph(s)
/// what type of depth change to make /// what type of depth change to make
enum DEPTH_CHANGE { enum DEPTH_CHANGE {
INC_DEPTH, INC_DEPTH,
DEC_DEPTH DEC_DEPTH
}; };
/// Increase or decrease the nesting depth of the selected paragraph(s)
void changeDepth(LCursor & cur, DEPTH_CHANGE type); void changeDepth(LCursor & cur, DEPTH_CHANGE type);
/// Returns whether something would be changed by changeDepth /// Returns whether something would be changed by changeDepth
@ -101,10 +95,9 @@ public:
void setFont(LCursor & cur, LyXFont const &, bool toggleall = false); void setFont(LCursor & cur, LyXFont const &, bool toggleall = false);
/// rebreaks all paragaphs between the given pars. /// rebreaks all paragaphs between the given pars.
void redoParagraphs(ParagraphList::iterator begin, void redoParagraphs(par_type begin, par_type end);
ParagraphList::iterator end);
/// rebreaks the given par /// rebreaks the given par
void redoParagraph(ParagraphList::iterator pit); void redoParagraph(par_type pit);
/// rebreaks the cursor par /// rebreaks the cursor par
void redoParagraph(LCursor & cur); void redoParagraph(LCursor & cur);
@ -142,12 +135,8 @@ public:
/// access to out BufferView. This should go... /// access to out BufferView. This should go...
BufferView * bv() const; BufferView * bv() const;
/// returns an iterator pointing to a cursor paragraph /// access to individual paragraphs
ParagraphList::iterator getPar(CursorSlice const & cursor) const; Paragraph & getPar(par_type par) const;
///
ParagraphList::iterator getPar(par_type par) const;
///
int parOffset(ParagraphList::iterator pit) const;
// Returns the current font and depth as a message. // Returns the current font and depth as a message.
std::string LyXText::currentState(LCursor & cur); std::string LyXText::currentState(LCursor & cur);
@ -155,13 +144,12 @@ public:
* y-coordinate (relative to the whole text). y is set to the * y-coordinate (relative to the whole text). y is set to the
* real beginning of this row * real beginning of this row
*/ */
RowList::iterator getRowNearY(int y, RowList::iterator getRowNearY(int y, par_type & pit) const;
ParagraphList::iterator & pit) const;
/** returns the column near the specified x-coordinate of the row /** returns the column near the specified x-coordinate of the row
x is set to the real beginning of this column x is set to the real beginning of this column
*/ */
pos_type getColumnNearX(ParagraphList::iterator pit, pos_type getColumnNearX(par_type pit,
Row const & row, int & x, bool & boundary) const; Row const & row, int & x, bool & boundary) const;
/** Find the word under \c from in the relative location /** Find the word under \c from in the relative location
@ -243,15 +231,8 @@ public:
}; };
/// Change the case of the word at cursor position. /// Change the case of the word at cursor position.
void changeCase(LCursor & cur, TextCase action); void changeCase(LCursor & cur, TextCase action);
/// returns success /// returns success
bool toggleInset(LCursor & cur); bool toggleInset(LCursor & cur);
///
void cutSelection(LCursor & cur, bool doclear = true, bool realcut = true);
///
void copySelection(LCursor & cur);
///
void pasteSelection(LCursor & cur, size_t sel_index = 0);
/** the DTP switches for paragraphs. LyX will store the top settings /** the DTP switches for paragraphs. LyX will store the top settings
always in the first physical paragraph, the bottom settings in the always in the first physical paragraph, the bottom settings in the
@ -266,16 +247,6 @@ public:
/* these things are for search and replace */ /* these things are for search and replace */
/**
* Sets the selection from the current cursor position to length
* characters to the right. No safety checks.
*/
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
void replaceSelection(LCursor & cur);
/// needed to insert the selection /// needed to insert the selection
void insertStringAsLines(LCursor & cur, std::string const & str); void insertStringAsLines(LCursor & cur, std::string const & str);
/// needed to insert the selection /// needed to insert the selection
@ -303,9 +274,9 @@ public:
InsetBase * checkInsetHit(int x, int y); InsetBase * checkInsetHit(int x, int y);
/// ///
int singleWidth(ParagraphList::iterator pit, pos_type pos) const; int singleWidth(par_type pit, pos_type pos) const;
/// ///
int singleWidth(ParagraphList::iterator pit, int singleWidth(par_type pit,
pos_type pos, char c, LyXFont const & Font) const; pos_type pos, char c, LyXFont const & Font) const;
/// return the color of the canvas /// return the color of the canvas
@ -317,15 +288,14 @@ public:
* in LaTeX the beginning of the text fits in some cases * in LaTeX the beginning of the text fits in some cases
* (for example sections) exactly the label-width. * (for example sections) exactly the label-width.
*/ */
int leftMargin(ParagraphList::iterator pit, pos_type pos) const; int leftMargin(par_type pit, pos_type pos) const;
int leftMargin(ParagraphList::iterator pit) const; int leftMargin(par_type pit) const;
/// ///
int rightMargin(Paragraph const & par) const; int rightMargin(Paragraph const & par) const;
/** this calculates the specified parameters. needed when setting /** this calculates the specified parameters. needed when setting
* the cursor and when creating a visible row */ * the cursor and when creating a visible row */
RowMetrics RowMetrics computeRowMetrics(par_type pit, Row const & row) const;
computeRowMetrics(ParagraphList::iterator pit, Row const & row) const;
/// access to our paragraphs /// access to our paragraphs
ParagraphList & paragraphs() const; ParagraphList & paragraphs() const;
@ -339,16 +309,14 @@ public:
/// return row "behind" last row of text /// return row "behind" last row of text
RowList::iterator endRow() const; RowList::iterator endRow() const;
/// return next row crossing paragraph boundaries /// return next row crossing paragraph boundaries
void nextRow(ParagraphList::iterator & pit, void nextRow(par_type & pit, RowList::iterator & rit) const;
RowList::iterator & rit) const;
/// return previous row crossing paragraph boundaries /// return previous row crossing paragraph boundaries
void previousRow(ParagraphList::iterator & pit, void previousRow(par_type & pit, RowList::iterator & rit) const;
RowList::iterator & rit) const;
/// is this row the last in the text? /// is this row the last in the text?
bool isLastRow(ParagraphList::iterator pit, Row const & row) const; bool isLastRow(par_type pit, Row const & row) const;
/// is this row the first in the text? /// is this row the first in the text?
bool isFirstRow(ParagraphList::iterator pit, Row const & row) const; bool isFirstRow(par_type pit, Row const & row) const;
/// ///
double spacing(Paragraph const & par) const; double spacing(Paragraph const & par) const;
@ -376,13 +344,13 @@ public:
/// ///
friend class LyXScreen; friend class LyXScreen;
public:
/// ///
unsigned int width_; unsigned int width_;
/// ///
int maxwidth_; int maxwidth_;
/// ///
int height_; int height_;
public:
/// the current font settings /// the current font settings
LyXFont current_font; LyXFont current_font;
/// the current font /// the current font
@ -398,7 +366,7 @@ public:
/// ///
mutable Bidi bidi; mutable Bidi bidi;
/// ///
ParagraphList paragraphs_; ParagraphList pars_;
/// absolute document pixel coordinates of this LyXText /// absolute document pixel coordinates of this LyXText
mutable int xo_; mutable int xo_;
@ -407,38 +375,28 @@ public:
/// our 'outermost' Font /// our 'outermost' Font
LyXFont font_; LyXFont font_;
///
double fill_separator(Row const & row) const;
///
double fill_hfill(Row const & row) const;
///
double
fill_label_hfill(ParagraphList::iterator pit, Row const & row) const;
private: private:
/// return past-the-last paragraph influenced by a layout /// return past-the-last paragraph influenced by a layout
/// change on pit /// change on pit
ParagraphList::iterator undoSpan(ParagraphList::iterator pit); par_type undoSpan(par_type pit);
/// rebreaks the given par /// rebreaks the given par
void redoParagraphInternal(ParagraphList::iterator pit); void redoParagraphInternal(par_type pit);
/// used in setlayout /// used in setlayout
void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par); void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
/// Calculate and set the height of the row /// Calculate and set the height of the row
void setHeightOfRow(ParagraphList::iterator, Row & row); void setHeightOfRow(par_type, Row & row);
// fix the cursor `cur' after a characters has been deleted at `where' // fix the cursor `cur' after a characters has been deleted at `where'
// position. Called by deleteEmptyParagraphMechanism // position. Called by deleteEmptyParagraphMechanism
void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where); void fixCursorAfterDelete(CursorSlice & cur, CursorSlice const & where);
/// delete double space (false) or empty paragraphs (true) around old_cursor /// delete double space or empty paragraphs around old cursor
bool deleteEmptyParagraphMechanism( bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor const & old);
CursorSlice & cur,
CursorSlice const & old_cursor);
/// ///
void setCounter(Buffer const &, ParagraphList::iterator pit); void setCounter(Buffer const &, par_type pit);
/// ///
void deleteWordForward(LCursor & cur); void deleteWordForward(LCursor & cur);
/// ///
@ -448,13 +406,13 @@ private:
/// sets row.end to the pos value *after* which a row should break. /// sets row.end to the pos value *after* which a row should break.
/// for example, the pos after which isNewLine(pos) == true /// for example, the pos after which isNewLine(pos) == true
void rowBreakPoint(ParagraphList::iterator pit, Row & row) const; void rowBreakPoint(par_type pit, Row & row) const;
/// sets row.width to the minimum space a row needs on the screen in pixel /// sets row.width to the minimum space a row needs on the screen in pixel
void setRowWidth(ParagraphList::iterator pit, Row & row) const; void setRowWidth(par_type pit, Row & row) const;
/// the minimum space a manual label needs on the screen in pixels /// the minimum space a manual label needs on the screen in pixels
int labelFill(ParagraphList::iterator pit, Row const & row) const; int labelFill(par_type pit, Row const & row) const;
/// FIXME /// FIXME
int labelEnd(ParagraphList::iterator pit) const; int labelEnd(par_type pit) const;
/// ///
void charInserted(); void charInserted();

View File

@ -28,10 +28,11 @@ using std::endl;
MathMBoxInset::MathMBoxInset(BufferView & bv) MathMBoxInset::MathMBoxInset(BufferView & bv)
: text_(&bv), bv_(&bv) : text_(&bv), bv_(&bv)
{ {
text_.paragraphs().clear();
text_.paragraphs().push_back(Paragraph()); text_.paragraphs().push_back(Paragraph());
text_.paragraphs().back(). text_.paragraphs().back().
layout(bv.buffer()->params().getLyXTextClass().defaultLayout()); layout(bv.buffer()->params().getLyXTextClass().defaultLayout());
text_.redoParagraph(text_.paragraphs().begin()); text_.redoParagraph(0);
} }

View File

@ -200,8 +200,8 @@ void MathNestInset::drawSelection(PainterInfo & pi, int, int) const
return; return;
if (!ptr_cmp(&cur.inset(), this)) if (!ptr_cmp(&cur.inset(), this))
return; return;
CursorSlice & s1 = cur.selBegin(); CursorSlice s1 = cur.selBegin();
CursorSlice & s2 = cur.selEnd(); CursorSlice s2 = cur.selEnd();
if (s1.idx() == s2.idx()) { if (s1.idx() == s2.idx()) {
MathArray const & c = cell(s1.idx()); MathArray const & c = cell(s1.idx());
int x1 = c.xo() + c.pos2x(s1.pos()); int x1 = c.xo() + c.pos2x(s1.pos());
@ -1146,29 +1146,31 @@ bool MathNestInset::script(LCursor & cur, bool up)
cur.macroModeClose(); cur.macroModeClose();
string safe = cur.grabAndEraseSelection(); string safe = cur.grabAndEraseSelection();
if (asScriptInset() && cur.idx() == 2) { if (asScriptInset() && cur.idx() == 0) {
// we are in a nucleus of a script inset, move to _our_ script // we are in a nucleus of a script inset, move to _our_ script
asScriptInset()->ensure(up); MathScriptInset * inset = asScriptInset();
cur.idx() = up; lyxerr << " going to cell " << inset->idxOfScript(up) << endl;
inset->ensure(up);
cur.idx() = inset->idxOfScript(up);
cur.pos() = 0; cur.pos() = 0;
} else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) { } else if (cur.pos() != 0 && cur.prevAtom()->asScriptInset()) {
--cur.pos(); --cur.pos();
cur.nextAtom().nucleus()->asScriptInset()->ensure(up); MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
cur.push(*cur.nextInset()); cur.push(*inset);
cur.idx() = up; cur.idx() = inset->idxOfScript(up);
cur.pos() = cur.lastpos(); cur.pos() = cur.lastpos();
} else if (cur.pos() != 0) {
--cur.pos();
cur.cell()[cur.pos()] = MathAtom(new MathScriptInset(cur.nextAtom(), up));
cur.push(*cur.nextInset());
cur.idx() = up;
cur.pos() = 0;
} else { } else {
cur.plainInsert(MathAtom(new MathScriptInset(up))); // convert the thing to our left to a scriptinset or create a new
--cur.pos(); // one if in the very first position of the array
cur.nextAtom().nucleus()->asScriptInset()->ensure(up); if (cur.pos() == 0) {
cur.push(*cur.nextInset()); cur.insert(new MathScriptInset(up));
cur.idx() = up; } else {
--cur.pos();
cur.cell()[cur.pos()] = MathAtom(new MathScriptInset(cur.nextAtom(), up));
}
MathScriptInset * inset = cur.nextAtom().nucleus()->asScriptInset();
cur.push(*inset);
cur.idx() = 1;
cur.pos() = 0; cur.pos() = 0;
} }
cur.paste(safe); cur.paste(safe);

View File

@ -30,27 +30,19 @@ using std::endl;
MathScriptInset::MathScriptInset() MathScriptInset::MathScriptInset()
: MathNestInset(3), limits_(0) : MathNestInset(1), cell_1_is_up_(false), limits_(0)
{ {}
script_[0] = false;
script_[1] = false;
}
MathScriptInset::MathScriptInset(bool up) MathScriptInset::MathScriptInset(bool up)
: MathNestInset(3), limits_(0) : MathNestInset(2), cell_1_is_up_(up), limits_(0)
{ {}
script_[0] = !up;
script_[1] = up;
}
MathScriptInset::MathScriptInset(MathAtom const & at, bool up) MathScriptInset::MathScriptInset(MathAtom const & at, bool up)
: MathNestInset(3), limits_(0) : MathNestInset(2), cell_1_is_up_(up), limits_(0)
{ {
script_[0] = !up; cell(0).push_back(at);
script_[1] = up;
cell(2).push_back(at);
} }
@ -75,7 +67,7 @@ MathScriptInset * MathScriptInset::asScriptInset()
bool MathScriptInset::idxFirst(LCursor & cur) const bool MathScriptInset::idxFirst(LCursor & cur) const
{ {
cur.idx() = 2; cur.idx() = 0;
cur.pos() = 0; cur.pos() = 0;
return true; return true;
} }
@ -83,7 +75,7 @@ bool MathScriptInset::idxFirst(LCursor & cur) const
bool MathScriptInset::idxLast(LCursor & cur) const bool MathScriptInset::idxLast(LCursor & cur) const
{ {
cur.idx() = 2; cur.idx() = 0;
cur.pos() = nuc().size(); cur.pos() = nuc().size();
return true; return true;
} }
@ -91,13 +83,13 @@ bool MathScriptInset::idxLast(LCursor & cur) const
MathArray const & MathScriptInset::down() const MathArray const & MathScriptInset::down() const
{ {
return cell(0); return nargs() == 2 ? cell(2) : cell(1);
} }
MathArray & MathScriptInset::down() MathArray & MathScriptInset::down()
{ {
return cell(0); return nargs() == 2 ? cell(2) : cell(1);
} }
@ -115,19 +107,30 @@ MathArray & MathScriptInset::up()
void MathScriptInset::ensure(bool up) void MathScriptInset::ensure(bool up)
{ {
script_[up] = true; if (nargs() == 1) {
// just nucleus so far
cells_.push_back(MathArray());
cell_1_is_up_ = up;
} else if (nargs() == 2 && !has(up)) {
if (up) {
cells_.push_back(cell(1));
cell(1).clear();
} else {
cells_.push_back(MathArray());
}
}
} }
MathArray const & MathScriptInset::nuc() const MathArray const & MathScriptInset::nuc() const
{ {
return cell(2); return cell(0);
} }
MathArray & MathScriptInset::nuc() MathArray & MathScriptInset::nuc()
{ {
return cell(2); return cell(0);
} }
@ -200,10 +203,12 @@ int MathScriptInset::ndes() const
void MathScriptInset::metrics(MetricsInfo & mi, Dimension & dim) const void MathScriptInset::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
cell(2).metrics(mi);
ScriptChanger dummy(mi.base);
cell(0).metrics(mi); cell(0).metrics(mi);
cell(1).metrics(mi); ScriptChanger dummy(mi.base);
if (nargs() > 1)
cell(1).metrics(mi);
if (nargs() > 2)
cell(2).metrics(mi);
dim.wid = 0; dim.wid = 0;
if (hasLimits()) { if (hasLimits()) {
dim.wid = nwid(); dim.wid = nwid();
@ -291,26 +296,51 @@ bool MathScriptInset::hasLimits() const
void MathScriptInset::removeScript(bool up) void MathScriptInset::removeScript(bool up)
{ {
cell(up).clear(); if (nargs() == 2) {
script_[up] = false; if (up == cell_1_is_up_)
cells_.pop_back();
} else if (nargs() == 3) {
if (up == true) {
swap(cells_[1], cells_[2]);
cell_1_is_up_ = false;
} else {
cell_1_is_up_ = true;
}
}
} }
bool MathScriptInset::has(bool up) const bool MathScriptInset::has(bool up) const
{ {
return script_[up]; return idxOfScript(up);
} }
bool MathScriptInset::hasUp() const bool MathScriptInset::hasUp() const
{ {
return script_[1]; //lyxerr << "hasUp: " << bool(idxOfScript(true)) << endl;
//lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
return idxOfScript(true);
} }
bool MathScriptInset::hasDown() const bool MathScriptInset::hasDown() const
{ {
return script_[0]; //lyxerr << "hasDown: " << bool(idxOfScript(false)) << endl;
//lyxerr << "1up: " << bool(cell_1_is_up_) << endl;
return idxOfScript(false);
}
InsetBase::idx_type MathScriptInset::idxOfScript(bool up) const
{
if (nargs() == 1)
return 0;
if (nargs() == 2)
return cell_1_is_up_ == up ? 1 : 0;
if (nargs() == 3)
return up ? 1 : 2;
BOOST_ASSERT(false);
} }
@ -328,38 +358,44 @@ bool MathScriptInset::idxLeft(LCursor &) const
bool MathScriptInset::idxUpDown(LCursor & cur, bool up) const bool MathScriptInset::idxUpDown(LCursor & cur, bool up) const
{ {
if (cur.idx() == 1) { // in nucleus?
// if we are 'up' we can't go further up if (cur.idx() == 0) {
if (up) // don't go up/down if there is no cell in this direction
return false;
// otherwise go to last base position
cur.idx() = 2;
cur.pos() = cur.lastpos();
}
else if (cur.idx() == 0) {
// if we are 'down' we can't go further down
if (!up)
return false;
cur.idx() = 2;
cur.pos() = cur.lastpos();
}
else {
// in nucleus
// don't go up/down if there is no cell.
if (!has(up)) if (!has(up))
return false; return false;
// go up/down only if in the last position // go up/down only if in the last position
// or in the first position of something with displayed limits // or in the first position of something with displayed limits
if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && hasLimits())) { if (cur.pos() == cur.lastpos() || (cur.pos() == 0 && hasLimits())) {
cur.idx() = up; cur.idx() = idxOfScript(up);
cur.pos() = 0; cur.pos() = 0;
return true; return true;
} }
return false; return false;
} }
return true;
// Are we 'up'?
if (cur.idx() == idxOfScript(true)) {
// can't go further up
if (up)
return false;
// otherwise go to last position in the nucleus
cur.idx() = 0;
cur.pos() = cur.lastpos();
return true;
}
// Are we 'down'?
if (cur.idx() == idxOfScript(false)) {
// can't go further down
if (!up)
return false;
// otherwise go to last position in the nucleus
cur.idx() = 0;
cur.pos() = cur.lastpos();
return true;
}
return false;
} }
@ -506,9 +542,16 @@ void MathScriptInset::notifyCursorLeaves(idx_type idx)
MathNestInset::notifyCursorLeaves(idx); MathNestInset::notifyCursorLeaves(idx);
// remove empty scripts if possible // remove empty scripts if possible
if (idx != 2 && script_[idx] && cell(idx).empty()) { if (idx == 2 && cell(2).empty()) {
cell(idx).clear(); removeScript(false); // must be a subscript...
script_[idx] = false; } else if (idx == 1 && cell(1).empty()) {
if (nargs() == 2) {
cell_1_is_up_ = false;
cell(1) = cell(2);
cells_.pop_back();
} else if (nargs() == 1) {
cells_.pop_back();
}
} }
} }

View File

@ -15,7 +15,10 @@
#include "math_nestinset.h" #include "math_nestinset.h"
/// An inset for super- and subscripts. // An inset for super- and subscripts or both. The 'nucleus' is always
// cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
// is set accordingly. If both are used, cell 1 is up and cell 2 is down.
class MathScriptInset : public MathNestInset { class MathScriptInset : public MathNestInset {
public: public:
/// create inset without scripts /// create inset without scripts
@ -45,8 +48,6 @@ public:
bool idxFirst(LCursor & cur) const; bool idxFirst(LCursor & cur) const;
/// Target pos when we enter the inset from the right by pressing "Left" /// Target pos when we enter the inset from the right by pressing "Left"
bool idxLast(LCursor & cur) const; bool idxLast(LCursor & cur) const;
/// can we enter this cell?
bool validCell(idx_type i) const { return i == 2 || script_[i]; }
/// write LaTeX and Lyx code /// write LaTeX and Lyx code
void write(WriteStream & os) const; void write(WriteStream & os) const;
@ -88,6 +89,8 @@ public:
bool hasDown() const; bool hasDown() const;
/// do we have a script? /// do we have a script?
bool has(bool up) const; bool has(bool up) const;
/// what idx has super/subscript?
idx_type idxOfScript(bool up) const;
/// remove script /// remove script
void removeScript(bool up); void removeScript(bool up);
/// make sure a script is accessible /// make sure a script is accessible
@ -122,7 +125,7 @@ private:
void notifyCursorLeaves(idx_type idx); void notifyCursorLeaves(idx_type idx);
/// possible subscript (index 0) and superscript (index 1) /// possible subscript (index 0) and superscript (index 1)
bool script_[2]; bool cell_1_is_up_;
/// 1 - "limits", -1 - "nolimits", 0 - "default" /// 1 - "limits", -1 - "nolimits", 0 - "default"
int limits_; int limits_;
}; };

View File

@ -227,8 +227,9 @@ void docbookParagraphs(Buffer const & buf,
break; break;
} }
par->simpleDocBookOnePar(buf, os, outerFont(par, paragraphs), par->simpleDocBookOnePar(buf, os,
runparams, depth + 1 + command_depth, labelid); outerFont(par - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs),
runparams, depth + 1 + command_depth, labelid);
// write closing SGML tags // write closing SGML tags
switch (style->latextype) { switch (style->latextype) {

View File

@ -13,15 +13,13 @@
#ifndef OUTPUT_DOCBOOK_H #ifndef OUTPUT_DOCBOOK_H
#define OUTPUT_DOCBOOK_H #define OUTPUT_DOCBOOK_H
#include "ParagraphList_fwd.h"
#include <iosfwd> #include <iosfwd>
class Buffer; class Buffer;
class OutputParams; class OutputParams;
class ParagraphList;
/// ///
void docbookParagraphs(Buffer const & buf, void docbookParagraphs(Buffer const & buf,
ParagraphList const & paragraphs, ParagraphList const & paragraphs,
std::ostream & os, std::ostream & os,

View File

@ -320,7 +320,7 @@ TeXOnePar(Buffer const & buf,
os << everypar; os << everypar;
bool need_par = pit->simpleTeXOnePar(buf, bparams, bool need_par = pit->simpleTeXOnePar(buf, bparams,
outerFont(pit, paragraphs), outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs),
os, texrow, runparams); os, texrow, runparams);
// Make sure that \\par is done with the font of the last // Make sure that \\par is done with the font of the last
@ -332,7 +332,9 @@ TeXOnePar(Buffer const & buf,
// Is this really needed ? (Dekel) // Is this really needed ? (Dekel)
// We do not need to use to change the font for the last paragraph // We do not need to use to change the font for the last paragraph
// or for a command. // or for a command.
LyXFont const outerfont = outerFont(pit, paragraphs); LyXFont const outerfont =
outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(),
paragraphs);
LyXFont const font = LyXFont const font =
(pit->empty() (pit->empty()

View File

@ -12,12 +12,11 @@
#ifndef OUTPUT_LATEX_H #ifndef OUTPUT_LATEX_H
#define OUTPUT_LATEX_H #define OUTPUT_LATEX_H
#include "ParagraphList_fwd.h"
#include <string> #include <string>
class Buffer; class Buffer;
class OutputParams; class OutputParams;
class ParagraphList;
class TexRow; class TexRow;
/// Just a wrapper for the method below, first creating the ofstream. /// Just a wrapper for the method below, first creating the ofstream.

View File

@ -17,6 +17,7 @@
#include "bufferparams.h" #include "bufferparams.h"
#include "paragraph.h" #include "paragraph.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphList_fwd.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "sgml.h" #include "sgml.h"
@ -134,7 +135,8 @@ void linuxdocParagraphs(Buffer const & buf,
break; break;
} }
pit->simpleLinuxDocOnePar(buf, os, outerFont(pit, paragraphs), pit->simpleLinuxDocOnePar(buf, os,
outerFont(pit - const_cast<ParagraphList&>(paragraphs).begin(), paragraphs),
runparams, depth); runparams, depth);
os << "\n"; os << "\n";

View File

@ -13,11 +13,10 @@
#ifndef OUTPUT_LINUXDOC_H #ifndef OUTPUT_LINUXDOC_H
#define OUTPUT_LINUXDOC_H #define OUTPUT_LINUXDOC_H
#include "ParagraphList_fwd.h"
#include <iosfwd> #include <iosfwd>
class Buffer; class Buffer;
class ParagraphList;
class OutputParams; class OutputParams;
/// ///

View File

@ -19,6 +19,7 @@
#include "output.h" #include "output.h"
#include "outputparams.h" #include "outputparams.h"
#include "paragraph.h" #include "paragraph.h"
#include "ParagraphList_fwd.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "support/gzstream.h" #include "support/gzstream.h"
@ -51,9 +52,8 @@ void writeFileAscii(Buffer const & buf,
} }
void writeFileAscii(Buffer const & buf, void writeFileAscii(Buffer const & buf, ostream & os,
ostream & os, OutputParams const & runparams)
OutputParams const & runparams)
{ {
Buffer & tmp = const_cast<Buffer &>(buf); Buffer & tmp = const_cast<Buffer &>(buf);
ParagraphList par = const_cast<ParagraphList&>(tmp.paragraphs()); ParagraphList par = const_cast<ParagraphList&>(tmp.paragraphs());

View File

@ -12,16 +12,18 @@
#ifndef OUTPUT_PLAINTEXT_H #ifndef OUTPUT_PLAINTEXT_H
#define OUTPUT_PLAINTEXT_H #define OUTPUT_PLAINTEXT_H
#include "ParagraphList_fwd.h"
#include <iosfwd> #include <iosfwd>
#include <string> #include <string>
class Buffer; class Buffer;
class OutputParams; class OutputParams;
class Paragraph;
/// ///
void writeFileAscii(Buffer const & buf, std::string const &, OutputParams const &); void writeFileAscii(Buffer const & buf, std::string const &,
OutputParams const &);
/// ///
void writeFileAscii(Buffer const & buf, std::ostream &, OutputParams const &); void writeFileAscii(Buffer const & buf, std::ostream &, OutputParams const &);

View File

@ -32,6 +32,7 @@
#include "lyxrow.h" #include "lyxrow.h"
#include "outputparams.h" #include "outputparams.h"
#include "paragraph_funcs.h" #include "paragraph_funcs.h"
#include "ParagraphList_fwd.h"
#include "sgml.h" #include "sgml.h"
#include "texrow.h" #include "texrow.h"
#include "vspace.h" #include "vspace.h"
@ -64,10 +65,15 @@ using std::ostream;
using std::ostringstream; using std::ostringstream;
ParagraphList::ParagraphList()
{}
Paragraph::Paragraph() Paragraph::Paragraph()
: y(0), height(0), begin_of_body_(0), : y(0), height(0), begin_of_body_(0),
pimpl_(new Paragraph::Pimpl(this)) pimpl_(new Paragraph::Pimpl(this))
{ {
//lyxerr << "sizeof Paragraph::Pimpl: " << sizeof(Paragraph::Pimpl) << endl;
itemdepth = 0; itemdepth = 0;
params().clear(); params().clear();
} }
@ -717,8 +723,8 @@ namespace {
bool noTrivlistCentering(UpdatableInset const * inset) bool noTrivlistCentering(UpdatableInset const * inset)
{ {
if (inset && inset->owner()) { if (inset) {
InsetBase::Code const code = inset->owner()->lyxCode(); InsetBase::Code const code = inset->lyxCode();
return code == InsetBase::FLOAT_CODE || return code == InsetBase::FLOAT_CODE ||
code == InsetBase::WRAP_CODE; code == InsetBase::WRAP_CODE;
} }
@ -1459,21 +1465,15 @@ bool IsInsetChar(char c)
bool Paragraph::isHfill(pos_type pos) const bool Paragraph::isHfill(pos_type pos) const
{ {
return IsInsetChar(getChar(pos)) return
&& getInset(pos)->lyxCode() == InsetBase::HFILL_CODE; isInset(pos) && getInset(pos)->lyxCode() == InsetBase::HFILL_CODE;
}
bool Paragraph::isInset(pos_type pos) const
{
return IsInsetChar(getChar(pos));
} }
bool Paragraph::isNewline(pos_type pos) const bool Paragraph::isNewline(pos_type pos) const
{ {
return IsInsetChar(getChar(pos)) return
&& getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE; isInset(pos) && getInset(pos)->lyxCode() == InsetBase::NEWLINE_CODE;
} }
@ -1535,8 +1535,7 @@ bool Paragraph::isRightToLeftPar(BufferParams const & bparams) const
{ {
return lyxrc.rtl_support return lyxrc.rtl_support
&& getParLanguage(bparams)->RightToLeft() && getParLanguage(bparams)->RightToLeft()
&& !(inInset() && inInset()->owner() && && !(inInset() && inInset()->lyxCode() == InsetBase::ERT_CODE);
inInset()->owner()->lyxCode() == InsetBase::ERT_CODE);
} }
@ -1641,11 +1640,6 @@ string const Paragraph::asString(Buffer const & buffer,
void Paragraph::setInsetOwner(UpdatableInset * inset) void Paragraph::setInsetOwner(UpdatableInset * inset)
{ {
pimpl_->inset_owner = inset; pimpl_->inset_owner = inset;
InsetList::iterator it = insetlist.begin();
InsetList::iterator end = insetlist.end();
for (; it != end; ++it)
if (it->inset)
it->inset->setOwner(inset);
} }
@ -1802,8 +1796,8 @@ bool Paragraph::isFreeSpacing() const
// for now we just need this, later should we need this in some // for now we just need this, later should we need this in some
// other way we can always add a function to InsetBase too. // other way we can always add a function to InsetBase too.
if (pimpl_->inset_owner && pimpl_->inset_owner->owner()) if (pimpl_->inset_owner)
return pimpl_->inset_owner->owner()->lyxCode() == InsetBase::ERT_CODE; return pimpl_->inset_owner->lyxCode() == InsetBase::ERT_CODE;
return false; return false;
} }
@ -1812,8 +1806,8 @@ bool Paragraph::allowEmpty() const
{ {
if (layout()->keepempty) if (layout()->keepempty)
return true; return true;
if (pimpl_->inset_owner && pimpl_->inset_owner->owner()) if (pimpl_->inset_owner)
return pimpl_->inset_owner->owner()->lyxCode() == InsetBase::ERT_CODE; return pimpl_->inset_owner->lyxCode() == InsetBase::ERT_CODE;
return false; return false;
} }
@ -1887,3 +1881,5 @@ unsigned char Paragraph::transformChar(unsigned char c, pos_type pos) const
return Encodings::TransformChar(c, Encodings::FORM_ISOLATED); return Encodings::TransformChar(c, Encodings::FORM_ISOLATED);
} }
} }

View File

@ -294,8 +294,8 @@ public:
/// ///
bool isHfill(lyx::pos_type pos) const; bool isHfill(lyx::pos_type pos) const;
/// /// hinted by profiler
bool isInset(lyx::pos_type pos) const; bool isInset(lyx::pos_type pos) const { return getChar(pos) == META_INSET; }
/// ///
bool isNewline(lyx::pos_type pos) const; bool isNewline(lyx::pos_type pos) const;
/// ///

View File

@ -17,30 +17,16 @@
#include "debug.h" #include "debug.h"
#include "encoding.h" #include "encoding.h"
#include "errorlist.h"
#include "factory.h"
#include "gettext.h" #include "gettext.h"
#include "iterators.h" #include "iterators.h"
#include "language.h" #include "language.h"
#include "lyxlex.h" #include "lyxtext.h"
#include "lyxrc.h"
#include "outputparams.h" #include "outputparams.h"
#include "paragraph_pimpl.h" #include "paragraph_pimpl.h"
#include "sgml.h" #include "sgml.h"
#include "texrow.h" #include "texrow.h"
#include "vspace.h" #include "vspace.h"
#include "insets/insetbibitem.h"
#include "insets/insethfill.h"
#include "insets/insetlatexaccent.h"
#include "insets/insetline.h"
#include "insets/insetnewline.h"
#include "insets/insetpagebreak.h"
#include "insets/insetoptarg.h"
#include "insets/insetspace.h"
#include "insets/insetspecialchar.h"
#include "insets/insettabular.h"
#include "support/filetools.h" #include "support/filetools.h"
#include "support/lstrings.h" #include "support/lstrings.h"
#include "support/lyxlib.h" #include "support/lyxlib.h"
@ -49,6 +35,7 @@
#include <vector> #include <vector>
using lyx::pos_type; using lyx::pos_type;
using lyx::par_type;
using lyx::support::ascii_lowercase; using lyx::support::ascii_lowercase;
using lyx::support::atoi; using lyx::support::atoi;
@ -98,20 +85,17 @@ bool moveItem(Paragraph & from, Paragraph & to,
void breakParagraph(BufferParams const & bparams, void breakParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & pars, par_type par, pos_type pos, int flag)
ParagraphList::iterator par,
pos_type pos,
int flag)
{ {
// create a new paragraph, and insert into the list // create a new paragraph, and insert into the list
ParagraphList::iterator tmp = paragraphs.insert(boost::next(par), ParagraphList::iterator tmp =
Paragraph()); pars.insert(pars.begin() + par + 1, Paragraph());
// without doing that we get a crash when typing <Return> at the // without doing that we get a crash when typing <Return> at the
// end of a paragraph // end of a paragraph
tmp->layout(bparams.getLyXTextClass().defaultLayout()); tmp->layout(bparams.getLyXTextClass().defaultLayout());
// remember to set the inset_owner // remember to set the inset_owner
tmp->setInsetOwner(par->inInset()); tmp->setInsetOwner(pars[par].inInset());
if (bparams.tracking_changes) if (bparams.tracking_changes)
tmp->trackChanges(); tmp->trackChanges();
@ -121,19 +105,19 @@ void breakParagraph(BufferParams const & bparams,
// layout stays the same with latex-environments // layout stays the same with latex-environments
if (flag) { if (flag) {
tmp->layout(par->layout()); tmp->layout(pars[par].layout());
tmp->setLabelWidthString(par->params().labelWidthString()); tmp->setLabelWidthString(pars[par].params().labelWidthString());
} }
bool const isempty = (par->allowEmpty() && par->empty()); bool const isempty = (pars[par].allowEmpty() && pars[par].empty());
if (!isempty && (par->size() > pos || par->empty() || flag == 2)) { if (!isempty && (pars[par].size() > pos || pars[par].empty() || flag == 2)) {
tmp->layout(par->layout()); tmp->layout(pars[par].layout());
tmp->params().align(par->params().align()); tmp->params().align(pars[par].params().align());
tmp->setLabelWidthString(par->params().labelWidthString()); tmp->setLabelWidthString(pars[par].params().labelWidthString());
tmp->params().depth(par->params().depth()); tmp->params().depth(pars[par].params().depth());
tmp->params().noindent(par->params().noindent()); tmp->params().noindent(pars[par].params().noindent());
// copy everything behind the break-position // copy everything behind the break-position
// to the new paragraph // to the new paragraph
@ -145,40 +129,40 @@ void breakParagraph(BufferParams const & bparams,
* here with size() == 0. So pos_end becomes - 1. Why * here with size() == 0. So pos_end becomes - 1. Why
* doesn't this cause problems ??? * doesn't this cause problems ???
*/ */
pos_type pos_end = par->size() - 1; pos_type pos_end = pars[par].size() - 1;
pos_type i = pos; pos_type i = pos;
pos_type j = pos; pos_type j = pos;
for (; i <= pos_end; ++i) { for (; i <= pos_end; ++i) {
Change::Type change = par->lookupChange(i); Change::Type change = pars[par].lookupChange(i);
if (moveItem(*par, *tmp, bparams, i, j - pos)) { if (moveItem(pars[par], *tmp, bparams, i, j - pos)) {
tmp->setChange(j - pos, change); tmp->setChange(j - pos, change);
++j; ++j;
} }
} }
for (i = pos_end; i >= pos; --i) for (i = pos_end; i >= pos; --i)
par->eraseIntern(i); pars[par].eraseIntern(i);
} }
if (pos) if (pos)
return; return;
par->params().clear(); pars[par].params().clear();
par->layout(bparams.getLyXTextClass().defaultLayout()); pars[par].layout(bparams.getLyXTextClass().defaultLayout());
// layout stays the same with latex-environments // layout stays the same with latex-environments
if (flag) { if (flag) {
par->layout(tmp->layout()); pars[par].layout(tmp->layout());
par->setLabelWidthString(tmp->params().labelWidthString()); pars[par].setLabelWidthString(tmp->params().labelWidthString());
par->params().depth(tmp->params().depth()); pars[par].params().depth(tmp->params().depth());
} }
// subtle, but needed to get empty pars working right // subtle, but needed to get empty pars working right
if (bparams.tracking_changes) { if (bparams.tracking_changes) {
if (!par->size()) { if (!pars[par].size()) {
par->cleanChanges(); pars[par].cleanChanges();
} else if (!tmp->size()) { } else if (!tmp->size()) {
tmp->cleanChanges(); tmp->cleanChanges();
} }
@ -187,371 +171,121 @@ void breakParagraph(BufferParams const & bparams,
void breakParagraphConservative(BufferParams const & bparams, void breakParagraphConservative(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & pars, par_type par, pos_type pos)
ParagraphList::iterator par,
pos_type pos)
{ {
// create a new paragraph // create a new paragraph
ParagraphList::iterator tmp = paragraphs.insert(boost::next(par), Paragraph & tmp = *pars.insert(pars.begin() + par + 1, Paragraph());
Paragraph()); tmp.makeSameLayout(pars[par]);
tmp->makeSameLayout(*par);
// When can pos > size()? // When can pos > size()?
// I guess pos == size() is possible. // I guess pos == size() is possible.
if (par->size() > pos) { if (pars[par].size() > pos) {
// copy everything behind the break-position to the new // copy everything behind the break-position to the new
// paragraph // paragraph
pos_type pos_end = par->size() - 1; pos_type pos_end = pars[par].size() - 1;
for (pos_type i = pos, j = pos; i <= pos_end; ++i) for (pos_type i = pos, j = pos; i <= pos_end; ++i)
if (moveItem(*par, *tmp, bparams, i, j - pos)) if (moveItem(pars[par], tmp, bparams, i, j - pos))
++j; ++j;
for (pos_type k = pos_end; k >= pos; --k) for (pos_type k = pos_end; k >= pos; --k)
par->erase(k); pars[par].erase(k);
} }
} }
void mergeParagraph(BufferParams const & bparams, void mergeParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & pars, par_type par)
ParagraphList::iterator par)
{ {
ParagraphList::iterator the_next = boost::next(par); Paragraph & next = pars[par + 1];
pos_type pos_end = the_next->size() - 1; pos_type pos_end = next.size() - 1;
pos_type pos_insert = par->size(); pos_type pos_insert = pars[par].size();
// ok, now copy the paragraph // ok, now copy the paragraph
for (pos_type i = 0, j = 0; i <= pos_end; ++i) for (pos_type i = 0, j = 0; i <= pos_end; ++i)
if (moveItem(*the_next, *par, bparams, i, pos_insert + j)) if (moveItem(next, pars[par], bparams, i, pos_insert + j))
++j; ++j;
paragraphs.erase(the_next); pars.erase(pars.begin() + par + 1);
} }
ParagraphList::iterator depthHook(ParagraphList::iterator pit, par_type depthHook(par_type pit,
ParagraphList const & plist, ParagraphList const & pars, Paragraph::depth_type depth)
Paragraph::depth_type depth)
{ {
ParagraphList::iterator newpit = pit; par_type newpit = pit;
ParagraphList::iterator beg = const_cast<ParagraphList&>(plist).begin();
if (newpit != beg) if (newpit != 0)
--newpit; --newpit;
while (newpit != beg && newpit->getDepth() > depth) { while (newpit != 0 && pars[newpit].getDepth() > depth)
--newpit; --newpit;
}
if (newpit->getDepth() > depth) if (pars[newpit].getDepth() > depth)
return pit; return pit;
return newpit; return newpit;
} }
ParagraphList::iterator outerHook(ParagraphList::iterator pit, par_type outerHook(par_type par, ParagraphList const & pars)
ParagraphList const & plist)
{ {
if (!pit->getDepth()) if (pars[par].getDepth() == 0)
return const_cast<ParagraphList&>(plist).end(); return pars.size();
return depthHook(pit, plist, return depthHook(par, pars, Paragraph::depth_type(pars[par].getDepth() - 1));
Paragraph::depth_type(pit->getDepth() - 1));
} }
bool isFirstInSequence(ParagraphList::iterator pit, bool isFirstInSequence(par_type pit, ParagraphList const & pars)
ParagraphList const & plist)
{ {
ParagraphList::iterator dhook = depthHook(pit, plist, pit->getDepth()); par_type dhook = depthHook(pit, pars, pars[pit].getDepth());
return (dhook == pit return dhook == pit
|| dhook->layout() != pit->layout() || pars[dhook].layout() != pars[pit].layout()
|| dhook->getDepth() != pit->getDepth()); || pars[dhook].getDepth() != pars[pit].getDepth();
} }
int getEndLabel(ParagraphList::iterator p, ParagraphList const & plist) int getEndLabel(par_type p, ParagraphList const & pars)
{ {
ParagraphList::iterator pit = p; par_type pit = p;
Paragraph::depth_type par_depth = p->getDepth(); Paragraph::depth_type par_depth = pars[p].getDepth();
while (pit != const_cast<ParagraphList&>(plist).end()) { while (pit != pars.size()) {
LyXLayout_ptr const & layout = pit->layout(); LyXLayout_ptr const & layout = pars[pit].layout();
int const endlabeltype = layout->endlabeltype; int const endlabeltype = layout->endlabeltype;
if (endlabeltype != END_LABEL_NO_LABEL) { if (endlabeltype != END_LABEL_NO_LABEL) {
if (boost::next(p) == const_cast<ParagraphList&>(plist).end()) if (p + 1 == pars.size())
return endlabeltype; return endlabeltype;
Paragraph::depth_type const next_depth = boost::next(p)->getDepth(); Paragraph::depth_type const next_depth =
pars[p + 1].getDepth();
if (par_depth > next_depth || if (par_depth > next_depth ||
(par_depth == next_depth && (par_depth == next_depth && layout != pars[p + 1].layout()))
layout != boost::next(p)->layout()))
return endlabeltype; return endlabeltype;
break; break;
} }
if (par_depth == 0) if (par_depth == 0)
break; break;
pit = outerHook(pit, plist); pit = outerHook(pit, pars);
if (pit != const_cast<ParagraphList&>(plist).end()) if (pit != pars.size())
par_depth = pit->getDepth(); par_depth = pars[pit].getDepth();
} }
return END_LABEL_NO_LABEL; return END_LABEL_NO_LABEL;
} }
namespace { LyXFont const outerFont(par_type pit, ParagraphList const & pars)
int readParToken(Buffer const & buf, Paragraph & par, LyXLex & lex,
string const & token)
{ {
static LyXFont font; Paragraph::depth_type par_depth = pars[pit].getDepth();
static Change change;
BufferParams const & bp = buf.params();
if (token[0] != '\\') {
string::const_iterator cit = token.begin();
for (; cit != token.end(); ++cit) {
par.insertChar(par.size(), (*cit), font, change);
}
} else if (token == "\\begin_layout") {
lex.eatLine();
string layoutname = lex.getString();
font = LyXFont(LyXFont::ALL_INHERIT, bp.language);
change = Change();
LyXTextClass const & tclass = bp.getLyXTextClass();
if (layoutname.empty()) {
layoutname = tclass.defaultLayoutName();
}
bool hasLayout = tclass.hasLayout(layoutname);
if (!hasLayout) {
lyxerr << "Layout '" << layoutname << "' does not"
<< " exist in textclass '" << tclass.name()
<< "'." << endl;
lyxerr << "Trying to use default layout instead."
<< endl;
layoutname = tclass.defaultLayoutName();
}
par.layout(bp.getLyXTextClass()[layoutname]);
// Test whether the layout is obsolete.
LyXLayout_ptr const & layout = par.layout();
if (!layout->obsoleted_by().empty())
par.layout(bp.getLyXTextClass()[layout->obsoleted_by()]);
par.params().read(lex);
} else if (token == "\\end_layout") {
lyxerr << "Solitary \\end_layout in line " << lex.getLineNo() << "\n"
<< "Missing \\begin_layout?.\n";
} else if (token == "\\end_inset") {
lyxerr << "Solitary \\end_inset in line " << lex.getLineNo() << "\n"
<< "Missing \\begin_inset?.\n";
} else if (token == "\\begin_inset") {
InsetBase * inset = readInset(lex, buf);
if (inset)
par.insertInset(par.size(), inset, font, change);
else {
lex.eatLine();
string line = lex.getString();
buf.error(ErrorItem(_("Unknown Inset"), line,
par.id(), 0, par.size()));
return 1;
}
} else if (token == "\\family") {
lex.next();
font.setLyXFamily(lex.getString());
} else if (token == "\\series") {
lex.next();
font.setLyXSeries(lex.getString());
} else if (token == "\\shape") {
lex.next();
font.setLyXShape(lex.getString());
} else if (token == "\\size") {
lex.next();
font.setLyXSize(lex.getString());
} else if (token == "\\lang") {
lex.next();
string const tok = lex.getString();
Language const * lang = languages.getLanguage(tok);
if (lang) {
font.setLanguage(lang);
} else {
font.setLanguage(bp.language);
lex.printError("Unknown language `$$Token'");
}
} else if (token == "\\numeric") {
lex.next();
font.setNumber(font.setLyXMisc(lex.getString()));
} else if (token == "\\emph") {
lex.next();
font.setEmph(font.setLyXMisc(lex.getString()));
} else if (token == "\\bar") {
lex.next();
string const tok = lex.getString();
if (tok == "under")
font.setUnderbar(LyXFont::ON);
else if (tok == "no")
font.setUnderbar(LyXFont::OFF);
else if (tok == "default")
font.setUnderbar(LyXFont::INHERIT);
else
lex.printError("Unknown bar font flag "
"`$$Token'");
} else if (token == "\\noun") {
lex.next();
font.setNoun(font.setLyXMisc(lex.getString()));
} else if (token == "\\color") {
lex.next();
font.setLyXColor(lex.getString());
} else if (token == "\\InsetSpace" || token == "\\SpecialChar") {
// Insets don't make sense in a free-spacing context! ---Kayvan
if (par.isFreeSpacing()) {
if (token == "\\InsetSpace")
par.insertChar(par.size(), ' ', font, change);
else if (lex.isOK()) {
lex.next();
string const next_token = lex.getString();
if (next_token == "\\-")
par.insertChar(par.size(), '-', font, change);
else {
lex.printError("Token `$$Token' "
"is in free space "
"paragraph layout!");
}
}
} else {
auto_ptr<InsetBase> inset;
if (token == "\\SpecialChar" )
inset.reset(new InsetSpecialChar);
else
inset.reset(new InsetSpace);
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(),
font, change);
}
} else if (token == "\\i") {
auto_ptr<InsetBase> inset(new InsetLatexAccent);
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\backslash") {
par.insertChar(par.size(), '\\', font, change);
} else if (token == "\\newline") {
auto_ptr<InsetBase> inset(new InsetNewline);
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\LyXTable") {
auto_ptr<InsetBase> inset(new InsetTabular(buf));
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\bibitem") {
InsetCommandParams p("bibitem", "dummy");
auto_ptr<InsetBibitem> inset(new InsetBibitem(p));
inset->read(buf, lex);
par.insertInset(par.size(), inset.release(), font, change);
} else if (token == "\\hfill") {
par.insertInset(par.size(), new InsetHFill, font, change);
} else if (token == "\\lyxline") {
par.insertInset(par.size(), new InsetLine, font, change);
} else if (token == "\\newpage") {
par.insertInset(par.size(), new InsetPagebreak, font, change);
} else if (token == "\\change_unchanged") {
// Hack ! Needed for empty paragraphs :/
// FIXME: is it still ??
if (!par.size())
par.cleanChanges();
change = Change(Change::UNCHANGED);
} else if (token == "\\change_inserted") {
lex.nextToken();
istringstream is(lex.getString());
int aid;
lyx::time_type ct;
is >> aid >> ct;
change = Change(Change::INSERTED, bp.author_map[aid], ct);
} else if (token == "\\change_deleted") {
lex.nextToken();
istringstream is(lex.getString());
int aid;
lyx::time_type ct;
is >> aid >> ct;
change = Change(Change::DELETED, bp.author_map[aid], ct);
} else {
lex.eatLine();
string const s = bformat(_("Unknown token: %1$s %2$s\n"),
token, lex.getString());
buf.error(ErrorItem(_("Unknown token"), s,
par.id(), 0, par.size()));
return 1;
}
return 0;
}
}
int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex)
{
int unknown = 0;
lex.nextToken();
string token = lex.getString();
while (lex.isOK()) {
unknown += readParToken(buf, par, lex, token);
lex.nextToken();
token = lex.getString();
if (token.empty())
continue;
if (token == "\\end_layout") {
//Ok, paragraph finished
break;
}
lyxerr[Debug::PARSER] << "Handling paragraph token: `"
<< token << '\'' << endl;
if (token == "\\begin_layout" || token == "\\end_document"
|| token == "\\end_inset" || token == "\\begin_deeper"
|| token == "\\end_deeper") {
lex.pushToken(token);
lyxerr << "Paragraph ended in line "
<< lex.getLineNo() << "\n"
<< "Missing \\end_layout.\n";
break;
}
}
return unknown;
}
LyXFont const outerFont(ParagraphList::iterator pit,
ParagraphList const & plist)
{
Paragraph::depth_type par_depth = pit->getDepth();
LyXFont tmpfont(LyXFont::ALL_INHERIT); LyXFont tmpfont(LyXFont::ALL_INHERIT);
// Resolve against environment font information // Resolve against environment font information
while (pit != const_cast<ParagraphList&>(plist).end() && while (pit != pars.size() && par_depth && !tmpfont.resolved()) {
par_depth && !tmpfont.resolved()) { pit = outerHook(pit, pars);
pit = outerHook(pit, plist); if (pit != pars.size()) {
if (pit != const_cast<ParagraphList&>(plist).end()) { tmpfont.realize(pars[pit].layout()->font);
tmpfont.realize(pit->layout()->font); par_depth = pars[pit].getDepth();
par_depth = pit->getDepth();
} }
} }
@ -559,7 +293,7 @@ LyXFont const outerFont(ParagraphList::iterator pit,
} }
ParagraphList::iterator outerPar(Buffer const & buf, InsetBase const * inset) par_type outerPar(Buffer const & buf, InsetBase const * inset)
{ {
ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin(); ParIterator pit = const_cast<Buffer &>(buf).par_iterator_begin();
ParIterator end = const_cast<Buffer &>(buf).par_iterator_end(); ParIterator end = const_cast<Buffer &>(buf).par_iterator_end();
@ -578,7 +312,7 @@ ParagraphList::iterator outerPar(Buffer const & buf, InsetBase const * inset)
} }
lyxerr << "outerPar: should not happen" << endl; lyxerr << "outerPar: should not happen" << endl;
BOOST_ASSERT(false); BOOST_ASSERT(false);
return const_cast<Buffer &>(buf).paragraphs().end(); // shut up compiler return buf.paragraphs().size(); // shut up compiler
} }
@ -591,13 +325,13 @@ Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset)
// the second '=' below is intentional // the second '=' below is intentional
for (int i = 0; (text = inset->getText(i)); ++i) for (int i = 0; (text = inset->getText(i)); ++i)
if (&text->paragraphs() == &pit.plist()) if (&text->paragraphs() == &pit.plist())
return *pit.pit(); return *pit;
InsetList::const_iterator ii = pit->insetlist.begin(); InsetList::const_iterator ii = pit->insetlist.begin();
InsetList::const_iterator iend = pit->insetlist.end(); InsetList::const_iterator iend = pit->insetlist.end();
for ( ; ii != iend; ++ii) for ( ; ii != iend; ++ii)
if (ii->inset == inset) if (ii->inset == inset)
return *pit.pit(); return *pit;
} }
lyxerr << "ownerPar: should not happen" << endl; lyxerr << "ownerPar: should not happen" << endl;
BOOST_ASSERT(false); BOOST_ASSERT(false);
@ -606,20 +340,16 @@ Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset)
/// return the range of pars [beg, end[ owning the range of y [ystart, yend] /// return the range of pars [beg, end[ owning the range of y [ystart, yend]
void getParsInRange(ParagraphList & pl, void getParsInRange(ParagraphList & pars, int ystart, int yend,
int ystart, int yend, par_type & beg, par_type & end)
ParagraphList::iterator & beg,
ParagraphList::iterator & end)
{ {
ParagraphList::iterator const endpar = pl.end(); BOOST_ASSERT(!pars.empty());
ParagraphList::iterator const begpar = pl.begin(); par_type const endpar = pars.size();
par_type const begpar = 0;
BOOST_ASSERT(begpar != endpar); for (beg = endpar - 1; beg != begpar && pars[beg].y > ystart; --beg)
beg = endpar;
for (--beg; beg != begpar && beg->y > ystart; --beg)
; ;
for (end = beg ; end != endpar && end->y <= yend; ++end) for (end = beg ; end != endpar && pars[end].y <= yend; ++end)
; ;
} }

View File

@ -12,29 +12,27 @@
#ifndef PARAGRAPH_FUNCS_H #ifndef PARAGRAPH_FUNCS_H
#define PARAGRAPH_FUNCS_H #define PARAGRAPH_FUNCS_H
#include "ParagraphList_fwd.h"
#include "support/types.h" #include "support/types.h"
#include <string>
class Buffer; class Buffer;
class BufferParams; class BufferParams;
class LyXFont;
class LyXLex;
class InsetBase; class InsetBase;
class LyXFont;
class Paragraph;
class ParagraphList;
/// ///
void breakParagraph(BufferParams const & bparams, void breakParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & paragraphs,
ParagraphList::iterator par, lyx::par_type par,
lyx::pos_type pos, lyx::pos_type pos,
int flag); int flag);
/// ///
void breakParagraphConservative(BufferParams const & bparams, void breakParagraphConservative(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & paragraphs,
ParagraphList::iterator par, lyx::par_type par,
lyx::pos_type pos); lyx::pos_type pos);
/** /**
@ -42,43 +40,34 @@ void breakParagraphConservative(BufferParams const & bparams,
* Be careful, this doesent make any check at all. * Be careful, this doesent make any check at all.
*/ */
void mergeParagraph(BufferParams const & bparams, void mergeParagraph(BufferParams const & bparams,
ParagraphList & paragraphs, ParagraphList & paragraphs, lyx::par_type par);
ParagraphList::iterator par);
/// for the environments /// for the environments
ParagraphList::iterator depthHook(ParagraphList::iterator pit, lyx::par_type depthHook(lyx::par_type par,
ParagraphList const & plist, ParagraphList const & plist, lyx::depth_type depth);
lyx::depth_type depth);
ParagraphList::iterator outerHook(ParagraphList::iterator pit, lyx::par_type outerHook(lyx::par_type par, ParagraphList const & plist);
ParagraphList const & plist);
/// Is it the first par with same depth and layout? /// Is it the first par with same depth and layout?
bool isFirstInSequence(ParagraphList::iterator par, bool isFirstInSequence(lyx::par_type par, ParagraphList const & plist);
ParagraphList const & plist);
/** Check if the current paragraph is the last paragraph in a /** Check if the current paragraph is the last paragraph in a
proof environment */ proof environment */
int getEndLabel(ParagraphList::iterator pit, int getEndLabel(lyx::par_type par, ParagraphList const & plist);
ParagraphList const & plist);
/// read a paragraph from a .lyx file. Returns number of unrecognised tokens LyXFont const outerFont(lyx::par_type par, ParagraphList const & plist);
int readParagraph(Buffer const & buf, Paragraph & par, LyXLex & lex);
LyXFont const outerFont(ParagraphList::iterator pit,
ParagraphList const & plist);
/// find outermost paragraph containing an inset /// find outermost paragraph containing an inset
ParagraphList::iterator outerPar(Buffer const & buf, InsetBase const * inset); lyx::par_type outerPar(Buffer const & buf, InsetBase const * inset);
/// find owning paragraph containing an inset /// find owning paragraph containing an inset
Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset); Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset);
/// return the range of pars [beg, end[ owning the range of y [ystart, yend] /// return the range of pars [beg, end[ owning the range of y [ystart, yend]
void getParsInRange(ParagraphList & pl, void getParsInRange(ParagraphList & plist,
int ystart, int yend, int ystart, int yend,
ParagraphList::iterator & beg, lyx::par_type & beg,
ParagraphList::iterator & end); lyx::par_type & end);
#endif // PARAGRAPH_FUNCS_H #endif // PARAGRAPH_FUNCS_H

View File

@ -301,9 +301,6 @@ void Paragraph::Pimpl::insertInset(pos_type pos,
// Add a new entry in the insetlist. // Add a new entry in the insetlist.
owner_->insetlist.insert(inset, pos); owner_->insetlist.insert(inset, pos);
if (inset_owner)
inset->setOwner(inset_owner);
} }

View File

@ -20,11 +20,13 @@
#include "changes.h" #include "changes.h"
#include "lyxfont.h" #include "lyxfont.h"
#include "ParagraphParameters.h" #include "ParagraphParameters.h"
#include "ShareContainer.h"
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
class LyXLayout; class LyXLayout;
struct Paragraph::Pimpl { struct Paragraph::Pimpl {
/// ///
Pimpl(Paragraph * owner); Pimpl(Paragraph * owner);

View File

@ -39,6 +39,7 @@
#include "support/textutils.h" #include "support/textutils.h"
using lyx::pos_type; using lyx::pos_type;
using lyx::par_type;
using std::endl; using std::endl;
using std::max; using std::max;
@ -57,7 +58,7 @@ class RowPainter {
public: public:
/// initialise and run painter /// initialise and run painter
RowPainter(BufferView const & bv, LyXText const & text, RowPainter(BufferView const & bv, LyXText const & text,
ParagraphList::iterator pit, RowList::iterator rit, int xo, int yo); par_type pit, RowList::iterator rit, int xo, int yo);
private: private:
// paint various parts // paint various parts
void paintBackground(); void paintBackground();
@ -97,13 +98,14 @@ private:
/// LyXText for the row /// LyXText for the row
LyXText const & text_; LyXText const & text_;
ParagraphList & pars_;
/// The row to paint /// The row to paint
RowList::iterator const rit_; RowList::iterator const rit_;
Row & row_; Row & row_;
/// Row's paragraph /// Row's paragraph
mutable ParagraphList::iterator pit_; mutable par_type pit_;
// Looks ugly - is // Looks ugly - is
double xo_; double xo_;
@ -117,14 +119,13 @@ private:
RowPainter::RowPainter(BufferView const & bv, LyXText const & text, RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
ParagraphList::iterator pit, RowList::iterator rit, par_type pit, RowList::iterator rit, int xo, int yo)
int xo, int yo) : bv_(bv), pain_(bv_.painter()), text_(text), pars_(text.paragraphs()),
: bv_(bv), pain_(bv_.painter()), text_(text), rit_(rit), row_(*rit), rit_(rit), row_(*rit), pit_(pit), xo_(xo), yo_(yo), width_(text_.width())
pit_(pit), xo_(xo), yo_(yo), width_(text_.width())
{ {
//lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo //lyxerr << "RowPainter: x: " << x_ << " xo: " << xo << " yo: " << yo
// << " pit->y: " << pit_->y // << " pit->y: " << pit_->y
// << " row: " << (pit_->size() ? pit_->getChar(row_.pos()) : 'X') << endl; // << " row: " << (pars_[pit_].size() ? pars_[pit_].getChar(row_.pos()) : 'X') << endl;
RowMetrics m = text_.computeRowMetrics(pit, row_); RowMetrics m = text_.computeRowMetrics(pit, row_);
x_ = m.x + xo_; x_ = m.x + xo_;
separator_ = m.separator; separator_ = m.separator;
@ -151,7 +152,7 @@ RowPainter::RowPainter(BufferView const & bv, LyXText const & text,
if (row_.pos() == 0) if (row_.pos() == 0)
paintFirst(); paintFirst();
if (row_.endpos() >= pit_->size()) if (row_.endpos() >= pars_[pit_].size())
paintLast(); paintLast();
// paint text // paint text
@ -193,7 +194,7 @@ int RowPainter::leftMargin() const
void RowPainter::paintInset(pos_type const pos) void RowPainter::paintInset(pos_type const pos)
{ {
InsetBase const * inset = pit_->getInset(pos); InsetBase const * inset = pars_[pit_].getInset(pos);
BOOST_ASSERT(inset); BOOST_ASSERT(inset);
PainterInfo pi(const_cast<BufferView *>(&bv_)); PainterInfo pi(const_cast<BufferView *>(&bv_));
pi.base.font = getFont(pos); pi.base.font = getFont(pos);
@ -210,7 +211,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos)
string str; string str;
// first char // first char
char c = pit_->getChar(pos); char c = pars_[pit_].getChar(pos);
str += c; str += c;
++vpos; ++vpos;
@ -219,7 +220,7 @@ void RowPainter::paintHebrewComposeChar(pos_type & vpos)
int dx = 0; int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) { for (pos_type i = pos - 1; i >= 0; --i) {
c = pit_->getChar(i); c = pars_[pit_].getChar(i);
if (!Encodings::IsComposeChar_hebrew(c)) { if (!Encodings::IsComposeChar_hebrew(c)) {
if (IsPrintableNonspace(c)) { if (IsPrintableNonspace(c)) {
int const width2 = singleWidth(i, c); int const width2 = singleWidth(i, c);
@ -243,8 +244,8 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos)
string str; string str;
// first char // first char
char c = pit_->getChar(pos); char c = pars_[pit_].getChar(pos);
c = pit_->transformChar(c, pos); c = pars_[pit_].transformChar(c, pos);
str += c; str += c;
++vpos; ++vpos;
@ -253,7 +254,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos)
int dx = 0; int dx = 0;
for (pos_type i = pos - 1; i >= 0; --i) { for (pos_type i = pos - 1; i >= 0; --i) {
c = pit_->getChar(i); c = pars_[pit_].getChar(i);
if (!Encodings::IsComposeChar_arabic(c)) { if (!Encodings::IsComposeChar_arabic(c)) {
if (IsPrintableNonspace(c)) { if (IsPrintableNonspace(c)) {
int const width2 = singleWidth(i, c); int const width2 = singleWidth(i, c);
@ -275,26 +276,26 @@ void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
// first character // first character
string str; string str;
str += pit_->getChar(pos); str += pars_[pit_].getChar(pos);
if (arabic) { if (arabic) {
unsigned char c = str[0]; unsigned char c = str[0];
str[0] = pit_->transformChar(c, pos); str[0] = pars_[pit_].transformChar(c, pos);
} }
bool prev_struckout = isDeletedText(*pit_, pos); bool prev_struckout = isDeletedText(pars_[pit_], pos);
bool prev_newtext = isInsertedText(*pit_, pos); bool prev_newtext = isInsertedText(pars_[pit_], pos);
// collect as much similar chars as we can // collect as much similar chars as we can
for (++vpos; vpos < end && (pos = text_.bidi.vis2log(vpos)) >= 0; ++vpos) { for (++vpos; vpos < end && (pos = text_.bidi.vis2log(vpos)) >= 0; ++vpos) {
char c = pit_->getChar(pos); char c = pars_[pit_].getChar(pos);
if (!IsPrintableNonspace(c)) if (!IsPrintableNonspace(c))
break; break;
if (prev_struckout != isDeletedText(*pit_, pos)) if (prev_struckout != isDeletedText(pars_[pit_], pos))
break; break;
if (prev_newtext != isInsertedText(*pit_, pos)) if (prev_newtext != isInsertedText(pars_[pit_], pos))
break; break;
if (arabic && Encodings::IsComposeChar_arabic(c)) if (arabic && Encodings::IsComposeChar_arabic(c))
@ -307,7 +308,7 @@ void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
break; break;
if (arabic) if (arabic)
c = pit_->transformChar(c, pos); c = pars_[pit_].transformChar(c, pos);
str += c; str += c;
} }
@ -347,7 +348,7 @@ void RowPainter::paintFromPos(pos_type & vpos)
double const orig_x = x_; double const orig_x = x_;
char const c = pit_->getChar(pos); char const c = pars_[pit_].getChar(pos);
if (c == Paragraph::META_INSET) { if (c == Paragraph::META_INSET) {
paintInset(pos); paintInset(pos);
@ -391,7 +392,7 @@ void RowPainter::paintBackground()
void RowPainter::paintSelection() void RowPainter::paintSelection()
{ {
bool const is_rtl = text_.isRTL(*pit_); bool const is_rtl = text_.isRTL(pars_[pit_]);
// the current selection // the current selection
LCursor const & cur = bv_.cursor(); LCursor const & cur = bv_.cursor();
@ -399,13 +400,13 @@ void RowPainter::paintSelection()
int const endx = text_.cursorX(cur.selEnd()); int const endx = text_.cursorX(cur.selEnd());
int const starty = text_.cursorY(cur.selBegin()); int const starty = text_.cursorY(cur.selBegin());
int const endy = text_.cursorY(cur.selEnd()); int const endy = text_.cursorY(cur.selEnd());
ParagraphList::iterator startpit = text_.getPar(cur.selBegin()); par_type startpit = cur.selBegin().par();
ParagraphList::iterator endpit = text_.getPar(cur.selEnd()); par_type endpit = cur.selEnd().par();
RowList::iterator startrow = startpit->getRow(cur.selBegin().pos()); RowList::iterator startrow = pars_[startpit].getRow(cur.selBegin().pos());
RowList::iterator endrow = endpit->getRow(cur.selEnd().pos()); RowList::iterator endrow = pars_[endpit].getRow(cur.selEnd().pos());
int const h = row_.height(); int const h = row_.height();
int const row_y = text_.yo_ + pit_->y + row_.y_offset(); int const row_y = text_.yo_ + pars_[pit_].y + row_.y_offset();
bool const sel_starts_here = startpit == pit_ && startrow == rit_; bool const sel_starts_here = startpit == pit_ && startrow == rit_;
bool const sel_ends_here = endpit == pit_ && endrow == rit_; bool const sel_ends_here = endpit == pit_ && endrow == rit_;
@ -435,7 +436,7 @@ void RowPainter::paintSelection()
pain_.fillRectangle(int(xo_), yo_, pain_.fillRectangle(int(xo_), yo_,
int(x_), h, LColor::selection); int(x_), h, LColor::selection);
pos_type const body_pos = pit_->beginOfBody(); pos_type const body_pos = pars_[pit_].beginOfBody();
pos_type const end = row_.endpos(); pos_type const end = row_.endpos();
double tmpx = x_; double tmpx = x_;
@ -443,24 +444,24 @@ void RowPainter::paintSelection()
pos_type pos = text_.bidi.vis2log(vpos); pos_type pos = text_.bidi.vis2log(vpos);
double const old_tmpx = tmpx; double const old_tmpx = tmpx;
if (body_pos > 0 && pos == body_pos - 1) { if (body_pos > 0 && pos == body_pos - 1) {
LyXLayout_ptr const & layout = pit_->layout(); LyXLayout_ptr const & layout = pars_[pit_].layout();
LyXFont const lfont = getLabelFont(); LyXFont const lfont = getLabelFont();
tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont); tmpx += label_hfill_ + font_metrics::width(layout->labelsep, lfont);
if (pit_->isLineSeparator(body_pos - 1)) if (pars_[pit_].isLineSeparator(body_pos - 1))
tmpx -= singleWidth(body_pos - 1); tmpx -= singleWidth(body_pos - 1);
} }
tmpx += singleWidth(pos); tmpx += singleWidth(pos);
if (hfillExpansion(*pit_, row_, pos)) { if (hfillExpansion(pars_[pit_], row_, pos)) {
if (pos >= body_pos) if (pos >= body_pos)
tmpx += hfill_; tmpx += hfill_;
else else
tmpx += label_hfill_; tmpx += label_hfill_;
} else { } else {
if (pit_->isSeparator(pos) && pos >= body_pos) if (pars_[pit_].isSeparator(pos) && pos >= body_pos)
tmpx += separator_; tmpx += separator_;
} }
@ -487,7 +488,7 @@ void RowPainter::paintChangeBar()
pos_type const start = row_.pos(); pos_type const start = row_.pos();
pos_type const end = row_.endpos(); pos_type const end = row_.endpos();
if (start == end || !pit_->isChanged(start, end - 1)) if (start == end || !pars_[pit_].isChanged(start, end - 1))
return; return;
int const height = text_.isLastRow(pit_, row_) int const height = text_.isLastRow(pit_, row_)
@ -500,12 +501,12 @@ void RowPainter::paintChangeBar()
void RowPainter::paintAppendix() void RowPainter::paintAppendix()
{ {
if (!pit_->params().appendix()) if (!pars_[pit_].params().appendix())
return; return;
int y = yo_; int y = yo_;
if (pit_->params().startOfAppendix()) if (pars_[pit_].params().startOfAppendix())
y += 2 * defaultRowHeight(); y += 2 * defaultRowHeight();
pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix); pain_.line(1, y, 1, yo_ + row_.height(), LColor::appendix);
@ -515,25 +516,25 @@ void RowPainter::paintAppendix()
void RowPainter::paintDepthBar() void RowPainter::paintDepthBar()
{ {
Paragraph::depth_type const depth = pit_->getDepth(); Paragraph::depth_type const depth = pars_[pit_].getDepth();
if (depth <= 0) if (depth <= 0)
return; return;
Paragraph::depth_type prev_depth = 0; Paragraph::depth_type prev_depth = 0;
if (!text_.isFirstRow(pit_, row_)) { if (!text_.isFirstRow(pit_, row_)) {
ParagraphList::iterator pit2 = pit_; par_type pit2 = pit_;
if (row_.pos() == 0) if (row_.pos() == 0)
--pit2; --pit2;
prev_depth = pit2->getDepth(); prev_depth = pars_[pit2].getDepth();
} }
Paragraph::depth_type next_depth = 0; Paragraph::depth_type next_depth = 0;
if (!text_.isLastRow(pit_, row_)) { if (!text_.isLastRow(pit_, row_)) {
ParagraphList::iterator pit2 = pit_; par_type pit2 = pit_;
if (row_.endpos() >= pit2->size()) if (row_.endpos() >= pars_[pit2].size())
++pit2; ++pit2;
next_depth = pit2->getDepth(); next_depth = pars_[pit2].getDepth();
} }
for (Paragraph::depth_type i = 1; i <= depth; ++i) { for (Paragraph::depth_type i = 1; i <= depth; ++i) {
@ -580,7 +581,7 @@ int RowPainter::paintAppendixStart(int y)
void RowPainter::paintFirst() void RowPainter::paintFirst()
{ {
ParagraphParameters const & parparams = pit_->params(); ParagraphParameters const & parparams = pars_[pit_].params();
int y_top = 0; int y_top = 0;
@ -590,18 +591,17 @@ void RowPainter::paintFirst()
Buffer const & buffer = *bv_.buffer(); Buffer const & buffer = *bv_.buffer();
LyXLayout_ptr const & layout = pit_->layout(); LyXLayout_ptr const & layout = pars_[pit_].layout();
if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) { if (buffer.params().paragraph_separation == BufferParams::PARSEP_SKIP) {
if (pit_ != text_.paragraphs().begin()) { if (pit_ != 0) {
if (layout->latextype == LATEX_PARAGRAPH if (layout->latextype == LATEX_PARAGRAPH
&& !pit_->getDepth()) { && !pars_[pit_].getDepth()) {
y_top += buffer.params().getDefSkip().inPixels(bv_); y_top += buffer.params().getDefSkip().inPixels(bv_);
} else { } else {
LyXLayout_ptr const & playout = LyXLayout_ptr const & playout = pars_[pit_ - 1].layout();
boost::prior(pit_)->layout();
if (playout->latextype == LATEX_PARAGRAPH if (playout->latextype == LATEX_PARAGRAPH
&& !boost::prior(pit_)->getDepth()) { && !pars_[pit_ - 1].getDepth()) {
// is it right to use defskip here, too? (AS) // is it right to use defskip here, too? (AS)
y_top += buffer.params().getDefSkip().inPixels(bv_); y_top += buffer.params().getDefSkip().inPixels(bv_);
} }
@ -609,9 +609,9 @@ void RowPainter::paintFirst()
} }
} }
bool const is_rtl = text_.isRTL(*pit_); bool const is_rtl = text_.isRTL(pars_[pit_]);
bool const is_seq = isFirstInSequence(pit_, text_.paragraphs()); bool const is_seq = isFirstInSequence(pit_, text_.paragraphs());
//lyxerr << "paintFirst: " << pit_->id() << " is_seq: " << is_seq << std::endl; //lyxerr << "paintFirst: " << pars_[pit_].id() << " is_seq: " << is_seq << std::endl;
// should we print a label? // should we print a label?
if (layout->labeltype >= LABEL_STATIC if (layout->labeltype >= LABEL_STATIC
@ -620,9 +620,9 @@ void RowPainter::paintFirst()
|| is_seq)) { || is_seq)) {
LyXFont font = getLabelFont(); LyXFont font = getLabelFont();
if (!pit_->getLabelstring().empty()) { if (!pars_[pit_].getLabelstring().empty()) {
double x = x_; double x = x_;
string const str = pit_->getLabelstring(); string const str = pars_[pit_].getLabelstring();
// this is special code for the chapter layout. This is // this is special code for the chapter layout. This is
// printed in an extra row and has a pagebreak at // printed in an extra row and has a pagebreak at
@ -670,8 +670,8 @@ void RowPainter::paintFirst()
layout->labeltype == LABEL_BIBLIO || layout->labeltype == LABEL_BIBLIO ||
layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) { layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT)) {
LyXFont font = getLabelFont(); LyXFont font = getLabelFont();
if (!pit_->getLabelstring().empty()) { if (!pars_[pit_].getLabelstring().empty()) {
string const str = pit_->getLabelstring(); string const str = pars_[pit_].getLabelstring();
float spacing_val = 1.0; float spacing_val = 1.0;
if (!parparams.spacing().isDefault()) { if (!parparams.spacing().isDefault()) {
spacing_val = parparams.spacing().getValue(); spacing_val = parparams.spacing().getValue();
@ -686,7 +686,7 @@ void RowPainter::paintFirst()
double x = x_; double x = x_;
if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) { if (layout->labeltype == LABEL_CENTERED_TOP_ENVIRONMENT) {
x = ((is_rtl ? leftMargin() : x_) x = ((is_rtl ? leftMargin() : x_)
+ width_ - text_.rightMargin(*pit_)) / 2; + width_ - text_.rightMargin(pars_[pit_])) / 2;
x -= font_metrics::width(str, font) / 2; x -= font_metrics::width(str, font) / 2;
} else if (is_rtl) { } else if (is_rtl) {
x = width_ - leftMargin() - x = width_ - leftMargin() -
@ -702,7 +702,7 @@ void RowPainter::paintFirst()
void RowPainter::paintLast() void RowPainter::paintLast()
{ {
bool const is_rtl = text_.isRTL(*pit_); bool const is_rtl = text_.isRTL(pars_[pit_]);
int const endlabel = getEndLabel(pit_, text_.paragraphs()); int const endlabel = getEndLabel(pit_, text_.paragraphs());
// draw an endlabel // draw an endlabel
@ -726,10 +726,10 @@ void RowPainter::paintLast()
case END_LABEL_STATIC: { case END_LABEL_STATIC: {
LyXFont font = getLabelFont(); LyXFont font = getLabelFont();
string const & str = pit_->layout()->endlabelstring(); string const & str = pars_[pit_].layout()->endlabelstring();
double const x = is_rtl ? double const x = is_rtl ?
x_ - font_metrics::width(str, font) x_ - font_metrics::width(str, font)
: - text_.rightMargin(*pit_) - row_.width(); : - text_.rightMargin(pars_[pit_]) - row_.width();
pain_.text(int(x), yo_ + row_.baseline(), str, font); pain_.text(int(x), yo_ + row_.baseline(), str, font);
break; break;
} }
@ -743,13 +743,13 @@ void RowPainter::paintLast()
void RowPainter::paintText() void RowPainter::paintText()
{ {
pos_type const end = row_.endpos(); pos_type const end = row_.endpos();
pos_type body_pos = pit_->beginOfBody(); pos_type body_pos = pars_[pit_].beginOfBody();
if (body_pos > 0 && if (body_pos > 0 &&
(body_pos > end || !pit_->isLineSeparator(body_pos - 1))) { (body_pos > end || !pars_[pit_].isLineSeparator(body_pos - 1))) {
body_pos = 0; body_pos = 0;
} }
LyXLayout_ptr const & layout = pit_->layout(); LyXLayout_ptr const & layout = pars_[pit_].layout();
bool running_strikeout = false; bool running_strikeout = false;
bool is_struckout = false; bool is_struckout = false;
@ -761,7 +761,7 @@ void RowPainter::paintText()
pos_type pos = text_.bidi.vis2log(vpos); pos_type pos = text_.bidi.vis2log(vpos);
if (pos >= pit_->size()) { if (pos >= pars_[pit_].size()) {
++vpos; ++vpos;
continue; continue;
} }
@ -772,15 +772,15 @@ void RowPainter::paintText()
continue; continue;
} }
is_struckout = isDeletedText(*pit_, pos); is_struckout = isDeletedText(pars_[pit_], pos);
if (is_struckout && !running_strikeout) { if (is_struckout && !running_strikeout) {
running_strikeout = true; running_strikeout = true;
last_strikeout_x = int(x_); last_strikeout_x = int(x_);
} }
bool const highly_editable_inset = pit_->isInset(pos) bool const highly_editable_inset = pars_[pit_].isInset(pos)
&& isHighlyEditableInset(pit_->getInset(pos)); && isHighlyEditableInset(pars_[pit_].getInset(pos));
// if we reach the end of a struck out range, paint it // if we reach the end of a struck out range, paint it
// we also don't paint across things like tables // we also don't paint across things like tables
@ -798,7 +798,7 @@ void RowPainter::paintText()
x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1); x_ += label_hfill_ + lwidth - singleWidth(body_pos - 1);
} }
if (pit_->isHfill(pos)) { if (pars_[pit_].isHfill(pos)) {
x_ += 1; x_ += 1;
int const y0 = yo_ + row_.baseline(); int const y0 = yo_ + row_.baseline();
@ -806,7 +806,7 @@ void RowPainter::paintText()
pain_.line(int(x_), y1, int(x_), y0, LColor::added_space); pain_.line(int(x_), y1, int(x_), y0, LColor::added_space);
if (hfillExpansion(*pit_, row_, pos)) { if (hfillExpansion(pars_[pit_], row_, pos)) {
int const y2 = (y0 + y1) / 2; int const y2 = (y0 + y1) / 2;
if (pos >= body_pos) { if (pos >= body_pos) {
@ -824,7 +824,7 @@ void RowPainter::paintText()
} }
x_ += 2; x_ += 2;
++vpos; ++vpos;
} else if (pit_->isSeparator(pos)) { } else if (pars_[pit_].isSeparator(pos)) {
x_ += singleWidth(pos); x_ += singleWidth(pos);
if (pos >= body_pos) if (pos >= body_pos)
x_ += separator_; x_ += separator_;
@ -845,17 +845,16 @@ void RowPainter::paintText()
int paintPars(BufferView const & bv, LyXText const & text, int paintPars(BufferView const & bv, LyXText const & text,
ParagraphList::iterator pit, int xo, int yo, int y) par_type pit, int xo, int yo, int y)
{ {
//lyxerr << " paintRows: pit: " << &*pit << endl; //lyxerr << " paintRows: pit: " << &*pit << endl;
int const y2 = bv.painter().paperHeight(); int const y2 = bv.painter().paperHeight();
y -= bv.top_y(); y -= bv.top_y();
ParagraphList::iterator end = text.paragraphs().end(); ParagraphList & pars = text.paragraphs();
for ( ; pit != pars.size(); ++pit) {
for ( ; pit != end; ++pit) { RowList::iterator row = pars[pit].rows.begin();
RowList::iterator row = pit->rows.begin(); RowList::iterator rend = pars[pit].rows.end();
RowList::iterator rend = pit->rows.end();
for ( ; row != rend; ++row) { for ( ; row != rend; ++row) {
RowPainter(bv, text, pit, row, xo, y + yo); RowPainter(bv, text, pit, row, xo, y + yo);
@ -873,15 +872,15 @@ int paintPars(BufferView const & bv, LyXText const & text,
int paintText(BufferView const & bv) int paintText(BufferView const & bv)
{ {
ParagraphList::iterator pit; par_type pit;
bv.text()->updateParPositions(); bv.text()->updateParPositions();
bv.text()->getRowNearY(bv.top_y(), pit); bv.text()->getRowNearY(bv.top_y(), pit);
//lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl; //lyxerr << "top_y: " << bv.top_y() << " y: " << pit->y << endl;
return paintPars(bv, *bv.text(), pit, 0, 0, pit->y); return paintPars(bv, *bv.text(), pit, 0, 0, bv.text()->paragraphs()[pit].y);
} }
void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo) void paintTextInset(LyXText const & text, PainterInfo & pi, int xo, int yo)
{ {
paintPars(*pi.base.bv, text, text.paragraphs().begin(), xo, yo, 0); paintPars(*pi.base.bv, text, 0, xo, yo, 0);
} }

View File

@ -28,7 +28,7 @@ namespace lyx {
/// a type for paragraph offsets /// a type for paragraph offsets
// FIXME: should be unsigned as well. // FIXME: should be unsigned as well.
// however, simply changing it breaks a downward loop somewhere... // however, simply changing it breaks a downward loop somewhere...
typedef ptrdiff_t paroffset_type; typedef ptrdiff_t par_type;
/// a type for the nesting depth of a paragraph /// a type for the nesting depth of a paragraph
typedef size_t depth_type; typedef size_t depth_type;

View File

@ -387,17 +387,6 @@ void LyXTabular::fixCellNums()
} }
void LyXTabular::setOwner(InsetTabular * inset)
{
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j < columns_; ++j) {
cell_info[i][j].inset.setOwner(inset);
cell_info[i][j].inset.setDrawFrame(InsetText::LOCKED);
}
}
}
void LyXTabular::appendRow(BufferParams const & bp, int cell) void LyXTabular::appendRow(BufferParams const & bp, int cell)
{ {
++rows_; ++rows_;
@ -2007,9 +1996,9 @@ int LyXTabular::TeXRow(ostream & os, int i, Buffer const & buf,
ret += TeXCellPreamble(os, cell); ret += TeXCellPreamble(os, cell);
InsetText & inset = getCellInset(cell); InsetText & inset = getCellInset(cell);
Paragraph const & par = inset.paragraphs().front(); Paragraph & par = inset.paragraphs().front();
bool rtl = par.isRightToLeftPar(buf.params()) bool rtl = par.isRightToLeftPar(buf.params())
&& !inset.paragraphs().begin()->empty() && !par.empty()
&& getPWidth(cell).zero(); && getPWidth(cell).zero();
if (rtl) if (rtl)

View File

@ -172,8 +172,6 @@ public:
/// constructor /// constructor
LyXTabular(BufferParams const &, int columns_arg, int rows_arg); LyXTabular(BufferParams const &, int columns_arg, int rows_arg);
///
void setOwner(InsetTabular * inset);
/// Returns true if there is a topline, returns false if not /// Returns true if there is a topline, returns false if not
bool topLine(int cell, bool onlycolumn = false) const; bool topLine(int cell, bool onlycolumn = false) const;

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@
#include "bufferparams.h" #include "bufferparams.h"
#include "BufferView.h" #include "BufferView.h"
#include "cursor.h" #include "cursor.h"
#include "CutAndPaste.h"
#include "debug.h" #include "debug.h"
#include "dispatchresult.h" #include "dispatchresult.h"
#include "factory.h" #include "factory.h"
@ -62,6 +63,11 @@
using lyx::pos_type; using lyx::pos_type;
using lyx::cap::copySelection;
using lyx::cap::cutSelection;
using lyx::cap::pasteSelection;
using lyx::cap::replaceSelection;
using lyx::support::isStrUnsignedInt; using lyx::support::isStrUnsignedInt;
using lyx::support::strToUnsignedInt; using lyx::support::strToUnsignedInt;
using lyx::support::atoi; using lyx::support::atoi;
@ -124,8 +130,7 @@ namespace {
} }
void mathDispatch(LCursor & cur, LyXText * text, void mathDispatch(LCursor & cur, FuncRequest const & cmd, bool display)
FuncRequest const & cmd, bool display)
{ {
recordUndo(cur); recordUndo(cur);
string sel = cur.selectionAsString(false); string sel = cur.selectionAsString(false);
@ -144,7 +149,7 @@ namespace {
} else { } else {
// create a macro if we see "\\newcommand" somewhere, and an ordinary // create a macro if we see "\\newcommand" somewhere, and an ordinary
// formula otherwise // formula otherwise
text->cutSelection(cur, true, true); cutSelection(cur, true, true);
if (sel.find("\\newcommand") == string::npos if (sel.find("\\newcommand") == string::npos
&& sel.find("\\def") == string::npos) && sel.find("\\def") == string::npos)
{ {
@ -180,23 +185,22 @@ string const freefont2string()
//takes absolute x,y coordinates //takes absolute x,y coordinates
InsetBase * LyXText::checkInsetHit(int x, int y) InsetBase * LyXText::checkInsetHit(int x, int y)
{ {
ParagraphList::iterator pit; par_type pit;
ParagraphList::iterator end; par_type end;
getParsInRange(paragraphs(), getParsInRange(paragraphs(),
bv()->top_y() - yo_, bv()->top_y() - yo_,
bv()->top_y() - yo_ + bv()->workHeight(), bv()->top_y() - yo_ + bv()->workHeight(),
pit, end); pit, end);
lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl; //lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl;
for ( ; pit != end; ++pit) { for ( ; pit != end; ++pit) {
InsetList::iterator iit = pit->insetlist.begin(); InsetList::iterator iit = pars_[pit].insetlist.begin();
InsetList::iterator iend = pit->insetlist.end(); InsetList::iterator iend = pars_[pit].insetlist.end();
for ( ; iit != iend; ++iit) { for ( ; iit != iend; ++iit) {
InsetBase * inset = iit->inset; InsetBase * inset = iit->inset;
#if 1 #if 0
lyxerr << "examining inset " << inset lyxerr << "examining inset " << inset
//<< " xo/yo: " << inset->xo() << "/" << inset->yo()
<< " xo: " << inset->xo() << "..." << inset->xo() + inset->width() << " xo: " << inset->xo() << "..." << inset->xo() + inset->width()
<< " yo: " << inset->yo() - inset->ascent() << "..." << " yo: " << inset->yo() - inset->ascent() << "..."
<< inset->yo() + inset->descent() << endl; << inset->yo() + inset->descent() << endl;
@ -207,7 +211,7 @@ InsetBase * LyXText::checkInsetHit(int x, int y)
} }
} }
} }
lyxerr << "No inset hit. " << endl; //lyxerr << "No inset hit. " << endl;
return 0; return 0;
} }
@ -216,13 +220,13 @@ bool LyXText::gotoNextInset(LCursor & cur,
vector<InsetOld_code> const & codes, string const & contents) vector<InsetOld_code> const & codes, string const & contents)
{ {
BOOST_ASSERT(this == cur.text()); BOOST_ASSERT(this == cur.text());
ParagraphList::iterator end = paragraphs().end(); par_type end = paragraphs().size();
ParagraphList::iterator pit = getPar(cur.par()); par_type pit = cur.par();
pos_type pos = cur.pos(); pos_type pos = cur.pos();
InsetBase * inset; InsetBase * inset;
do { do {
if (pos + 1 < pit->size()) { if (pos + 1 < pars_[pit].size()) {
++pos; ++pos;
} else { } else {
++pit; ++pit;
@ -230,17 +234,17 @@ bool LyXText::gotoNextInset(LCursor & cur,
} }
} while (pit != end && } while (pit != end &&
!(pit->isInset(pos) && !(pars_[pit].isInset(pos) &&
(inset = pit->getInset(pos)) != 0 && (inset = pars_[pit].getInset(pos)) != 0 &&
find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() && find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
(contents.empty() || (contents.empty() ||
static_cast<InsetCommand *>(pit->getInset(pos))->getContents() static_cast<InsetCommand *>(pars_[pit].getInset(pos))->getContents()
== contents))); == contents)));
if (pit == end) if (pit == end)
return false; return false;
setCursor(cur, parOffset(pit), pos, false); setCursor(cur, pit, pos, false);
return true; return true;
} }
@ -273,7 +277,6 @@ void LyXText::gotoInset(LCursor & cur,
cur.message(_("No more insets")); cur.message(_("No more insets"));
} }
} }
cur.update();
cur.resetAnchor(); cur.resetAnchor();
} }
@ -287,7 +290,7 @@ void LyXText::gotoInset(LCursor & cur, InsetOld_code code, bool same_content)
void LyXText::cursorPrevious(LCursor & cur) void LyXText::cursorPrevious(LCursor & cur)
{ {
pos_type cpos = cur.pos(); pos_type cpos = cur.pos();
lyx::paroffset_type cpar = cur.par(); lyx::par_type cpar = cur.par();
int x = cur.x_target(); int x = cur.x_target();
int y = bv()->top_y(); int y = bv()->top_y();
@ -307,7 +310,7 @@ void LyXText::cursorPrevious(LCursor & cur)
void LyXText::cursorNext(LCursor & cur) void LyXText::cursorNext(LCursor & cur)
{ {
pos_type cpos = cur.pos(); pos_type cpos = cur.pos();
lyx::paroffset_type cpar = cur.par(); lyx::par_type cpar = cur.par();
int x = cur.x_target(); int x = cur.x_target();
int y = bv()->top_y() + bv()->workHeight(); int y = bv()->top_y() + bv()->workHeight();
@ -326,11 +329,10 @@ void LyXText::cursorNext(LCursor & cur)
namespace { namespace {
void specialChar(LCursor & cur, LyXText * text, InsetSpecialChar::Kind kind) void specialChar(LCursor & cur, InsetSpecialChar::Kind kind)
{ {
text->replaceSelection(cur); lyx::cap::replaceSelection(cur);
cur.insert(new InsetSpecialChar(kind)); cur.insert(new InsetSpecialChar(kind));
cur.update();
} }
@ -387,13 +389,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
bool start = !par.params().startOfAppendix(); bool start = !par.params().startOfAppendix();
// ensure that we have only one start_of_appendix in this document // ensure that we have only one start_of_appendix in this document
ParagraphList::iterator tmp = paragraphs().begin(); for (par_type tmp = 0, end = pars_.size(); tmp != end; ++tmp) {
ParagraphList::iterator end = paragraphs().end(); if (pars_[tmp].params().startOfAppendix()) {
recUndo(tmp);
for (; tmp != end; ++tmp) { pars_[tmp].params().startOfAppendix(false);
if (tmp->params().startOfAppendix()) {
recUndo(parOffset(tmp));
tmp->params().startOfAppendix(false);
redoParagraph(tmp); redoParagraph(tmp);
break; break;
} }
@ -405,7 +404,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
// we can set the refreshing parameters now // we can set the refreshing parameters now
updateCounters(); updateCounters();
redoParagraph(cur); redoParagraph(cur);
cur.update();
break; break;
} }
@ -463,40 +461,52 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_RIGHT: case LFUN_RIGHT:
case LFUN_RIGHTSEL: case LFUN_RIGHTSEL:
//lyxerr << "handle LFUN_RIGHT[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_RIGHTSEL); cur.selHandle(cmd.action == LFUN_RIGHTSEL);
if (isRTL(cur.paragraph())) if (isRTL(cur.paragraph()))
cursorLeft(cur); cursorLeft(cur);
else else
cursorRight(cur); cursorRight(cur);
if (sl == cur.top()) if (sl == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_RIGHT); cmd = FuncRequest(LFUN_FINISHED_RIGHT);
}
break; break;
case LFUN_LEFT: case LFUN_LEFT:
case LFUN_LEFTSEL: case LFUN_LEFTSEL:
//lyxerr << "handle LFUN_LEFT[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_LEFTSEL); cur.selHandle(cmd.action == LFUN_LEFTSEL);
if (isRTL(cur.paragraph())) if (isRTL(cur.paragraph()))
cursorRight(cur); cursorRight(cur);
else else
cursorLeft(cur); cursorLeft(cur);
if (sl == cur.top()) if (sl == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT); cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
break; break;
case LFUN_UP: case LFUN_UP:
case LFUN_UPSEL: case LFUN_UPSEL:
//lyxerr << "handle LFUN_UP[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_UPSEL); cur.selHandle(cmd.action == LFUN_UPSEL);
cursorUp(cur); cursorUp(cur);
if (sl == cur.top()) if (sl == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_UP); cmd = FuncRequest(LFUN_FINISHED_UP);
}
break; break;
case LFUN_DOWN: case LFUN_DOWN:
case LFUN_DOWNSEL: case LFUN_DOWNSEL:
//lyxerr << "handle LFUN_DOWN[SEL]:\n" << cur << endl;
cur.selHandle(cmd.action == LFUN_DOWNSEL); cur.selHandle(cmd.action == LFUN_DOWNSEL);
cursorDown(cur); cursorDown(cur);
if (sl == cur.top()) if (sl == cur.top()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_DOWN); cmd = FuncRequest(LFUN_FINISHED_DOWN);
}
break; break;
case LFUN_UP_PARAGRAPHSEL: case LFUN_UP_PARAGRAPHSEL:
@ -585,10 +595,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
if (!cur.mark()) if (!cur.mark())
cur.clearSelection(); cur.clearSelection();
finishChange(cur, false); finishChange(cur, false);
if (cur.par() == 0 && cur.textRow().pos() == 0) if (cur.par() == 0 && cur.textRow().pos() == 0) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_UP); cmd = FuncRequest(LFUN_FINISHED_UP);
else } else {
cursorPrevious(cur); cursorPrevious(cur);
}
break; break;
case LFUN_NEXT: case LFUN_NEXT:
@ -596,10 +608,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
cur.clearSelection(); cur.clearSelection();
finishChange(cur, false); finishChange(cur, false);
if (cur.par() == cur.lastpar() if (cur.par() == cur.lastpar()
&& cur.textRow().endpos() == cur.lastpos()) && cur.textRow().endpos() == cur.lastpos()) {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_DOWN); cmd = FuncRequest(LFUN_FINISHED_DOWN);
else } else {
cursorNext(cur); cursorNext(cur);
}
break; break;
case LFUN_HOME: case LFUN_HOME:
@ -619,7 +633,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_BREAKLINE: { case LFUN_BREAKLINE: {
// Not allowed by LaTeX (labels or empty par) // Not allowed by LaTeX (labels or empty par)
if (cur.pos() > cur.paragraph().beginOfBody()) { if (cur.pos() > cur.paragraph().beginOfBody()) {
replaceSelection(cur); lyx::cap::replaceSelection(cur);
cur.insert(new InsetNewline); cur.insert(new InsetNewline);
moveCursor(cur, false); moveCursor(cur, false);
} }
@ -650,7 +664,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} else { } else {
cutSelection(cur, true, false); cutSelection(cur, true, false);
} }
cur.update();
break; break;
@ -666,7 +679,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
cutSelection(cur, true, false); cutSelection(cur, true, false);
} }
bv->switchKeyMap(); bv->switchKeyMap();
cur.update();
break; break;
case LFUN_BACKSPACE_SKIP: case LFUN_BACKSPACE_SKIP:
@ -679,41 +691,31 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} else { } else {
cutSelection(cur, true, false); cutSelection(cur, true, false);
} }
cur.update();
break; break;
case LFUN_BREAKPARAGRAPH: case LFUN_BREAKPARAGRAPH:
replaceSelection(cur); lyx::cap::replaceSelection(cur);
breakParagraph(cur, 0); breakParagraph(cur, 0);
cur.update();
cur.resetAnchor(); cur.resetAnchor();
bv->switchKeyMap(); bv->switchKeyMap();
break; break;
case LFUN_BREAKPARAGRAPHKEEPLAYOUT: case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
replaceSelection(cur); lyx::cap::replaceSelection(cur);
breakParagraph(cur, 1); breakParagraph(cur, 1);
cur.update();
cur.resetAnchor(); cur.resetAnchor();
bv->switchKeyMap(); bv->switchKeyMap();
break; break;
case LFUN_BREAKPARAGRAPH_SKIP: { case LFUN_BREAKPARAGRAPH_SKIP: {
// When at the beginning of a paragraph, remove // When at the beginning of a paragraph, remove
// indentation and add a "defskip" at the top. // indentation. Otherwise, do the same as LFUN_BREAKPARAGRAPH.
// Otherwise, do the same as LFUN_BREAKPARAGRAPH. lyx::cap::replaceSelection(cur);
replaceSelection(cur); if (cur.pos() == 0)
if (cur.pos() == 0) { cur.paragraph().params().labelWidthString(string());
ParagraphParameters & params = cur.paragraph().params(); else
setParagraph(cur,
params.spacing(),
params.align(),
params.labelWidthString(), 1);
} else {
breakParagraph(cur, 0); breakParagraph(cur, 0);
} cur.resetAnchor();
cur.update();
// anchor() = cur;
bv->switchKeyMap(); bv->switchKeyMap();
break; break;
} }
@ -755,7 +757,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
if (cur_spacing != new_spacing || cur_value != new_value) { if (cur_spacing != new_spacing || cur_value != new_value) {
par.params().spacing(Spacing(new_spacing, new_value)); par.params().spacing(Spacing(new_spacing, new_value));
redoParagraph(cur); redoParagraph(cur);
cur.update();
} }
break; break;
} }
@ -803,56 +804,51 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
break; break;
case LFUN_HYPHENATION: case LFUN_HYPHENATION:
specialChar(cur, this, InsetSpecialChar::HYPHENATION); specialChar(cur, InsetSpecialChar::HYPHENATION);
break; break;
case LFUN_LIGATURE_BREAK: case LFUN_LIGATURE_BREAK:
specialChar(cur, this, InsetSpecialChar::LIGATURE_BREAK); specialChar(cur, InsetSpecialChar::LIGATURE_BREAK);
break; break;
case LFUN_LDOTS: case LFUN_LDOTS:
specialChar(cur, this, InsetSpecialChar::LDOTS); specialChar(cur, InsetSpecialChar::LDOTS);
break; break;
case LFUN_END_OF_SENTENCE: case LFUN_END_OF_SENTENCE:
specialChar(cur, this, InsetSpecialChar::END_OF_SENTENCE); specialChar(cur, InsetSpecialChar::END_OF_SENTENCE);
break; break;
case LFUN_MENU_SEPARATOR: case LFUN_MENU_SEPARATOR:
specialChar(cur, this, InsetSpecialChar::MENU_SEPARATOR); specialChar(cur, InsetSpecialChar::MENU_SEPARATOR);
break; break;
case LFUN_UPCASE_WORD: case LFUN_UPCASE_WORD:
changeCase(cur, LyXText::text_uppercase); changeCase(cur, LyXText::text_uppercase);
cur.update();
break; break;
case LFUN_LOWCASE_WORD: case LFUN_LOWCASE_WORD:
changeCase(cur, LyXText::text_lowercase); changeCase(cur, LyXText::text_lowercase);
cur.update();
break; break;
case LFUN_CAPITALIZE_WORD: case LFUN_CAPITALIZE_WORD:
changeCase(cur, LyXText::text_capitalization); changeCase(cur, LyXText::text_capitalization);
cur.update();
break; break;
case LFUN_TRANSPOSE_CHARS: case LFUN_TRANSPOSE_CHARS:
recordUndo(cur); recordUndo(cur);
redoParagraph(cur); redoParagraph(cur);
cur.update();
break; break;
case LFUN_PASTE: case LFUN_PASTE:
cur.message(_("Paste")); cur.message(_("Paste"));
replaceSelection(cur); lyx::cap::replaceSelection(cur);
#warning FIXME Check if the arg is in the domain of available selections. #warning FIXME Check if the arg is in the domain of available selections.
if (isStrUnsignedInt(cmd.argument)) if (isStrUnsignedInt(cmd.argument))
pasteSelection(cur, strToUnsignedInt(cmd.argument)); pasteSelection(cur, strToUnsignedInt(cmd.argument));
else else
pasteSelection(cur, 0); pasteSelection(cur, 0);
cur.clearSelection(); // bug 393 cur.clearSelection(); // bug 393
cur.update();
bv->switchKeyMap(); bv->switchKeyMap();
finishUndo(); finishUndo();
break; break;
@ -860,7 +856,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_CUT: case LFUN_CUT:
cutSelection(cur, true, true); cutSelection(cur, true, true);
cur.message(_("Cut")); cur.message(_("Cut"));
cur.update();
break; break;
case LFUN_COPY: case LFUN_COPY:
@ -937,10 +932,10 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
if (!change_layout && cur.selection() && if (!change_layout && cur.selection() &&
cur.selBegin().par() != cur.selEnd().par()) cur.selBegin().par() != cur.selEnd().par())
{ {
ParagraphList::iterator spit = getPar(cur.selBegin()); par_type spit = cur.selBegin().par();
ParagraphList::iterator epit = boost::next(getPar(cur.selEnd())); par_type epit = cur.selEnd().par() + 1;
while (spit != epit) { while (spit != epit) {
if (spit->layout()->name() != current_layout) { if (pars_[spit].layout()->name() != current_layout) {
change_layout = true; change_layout = true;
break; break;
} }
@ -952,7 +947,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
current_layout = layout; current_layout = layout;
setLayout(cur, layout); setLayout(cur, layout);
bv->owner()->setLayout(layout); bv->owner()->setLayout(layout);
cur.update();
bv->switchKeyMap(); bv->switchKeyMap();
} }
break; break;
@ -966,7 +960,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
insertStringAsParagraphs(cur, clip); insertStringAsParagraphs(cur, clip);
else else
insertStringAsLines(cur, clip); insertStringAsLines(cur, clip);
cur.update();
} }
break; break;
} }
@ -988,7 +981,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} }
case LFUN_QUOTE: { case LFUN_QUOTE: {
replaceSelection(cur); lyx::cap::replaceSelection(cur);
Paragraph & par = cur.paragraph(); Paragraph & par = cur.paragraph();
lyx::pos_type pos = cur.pos(); lyx::pos_type pos = cur.pos();
char c; char c;
@ -1022,7 +1015,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} }
case LFUN_DATE_INSERT: { case LFUN_DATE_INSERT: {
replaceSelection(cur); lyx::cap::replaceSelection(cur);
time_t now_time_t = time(NULL); time_t now_time_t = time(NULL);
struct tm * now_tm = localtime(&now_time_t); struct tm * now_tm = localtime(&now_time_t);
setlocale(LC_TIME, ""); setlocale(LC_TIME, "");
@ -1066,12 +1059,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
// Only use motion with button 1 // Only use motion with button 1
//if (cmd.button() != mouse_button::button1) //if (cmd.button() != mouse_button::button1)
// return false; // return false;
// The test for not selection possible is needed, that // We want to use only motion events for which
// only motion events are used, where the bottom press // the button press event was on the drawing area too.
// event was on the drawing area too
if (!selection_possible) { if (!selection_possible) {
lyxerr[Debug::ACTION] << "BufferView::Pimpl::" lyxerr[Debug::ACTION] << "BufferView::Pimpl::"
"Dispatch: no selection possible\n"; "dispatch: no selection possible\n";
lyxerr << "BufferView::Pimpl::dispatch: no selection possible\n";
break; break;
} }
CursorSlice old = cur.top(); CursorSlice old = cur.top();
@ -1087,14 +1080,15 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} }
// don't set anchor_ // don't set anchor_
bv->cursor().setCursor(cur, false); bv->cursor().setCursor(cur, true);
lyxerr << "MOTION: " << bv->cursor() << endl;
break; break;
} }
// Single-click on work area // Single-click on work area
case LFUN_MOUSE_PRESS: { case LFUN_MOUSE_PRESS: {
// ok ok, this is a hack (for xforms) // ok ok, this is a hack (for xforms)
// We shouldn't go further down as we really should only do the // We shouldn't go further down as we really need to. Only do the
// scrolling and be done with this. Otherwise we may open some // scrolling and be done with this. Otherwise we may open some
// dialogs (Jug 20020424). // dialogs (Jug 20020424).
if (cmd.button() == mouse_button::button4) { if (cmd.button() == mouse_button::button4) {
@ -1134,9 +1128,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
finishUndo(); finishUndo();
cur.x_target() = cursorX(cur.top()); cur.x_target() = cursorX(cur.top());
// set cursor and anchor to this position
bv->cursor() = cur;
if (bv->fitCursor()) if (bv->fitCursor())
selection_possible = false; selection_possible = false;
@ -1273,21 +1264,19 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_DEPTH_MIN: case LFUN_DEPTH_MIN:
changeDepth(cur, DEC_DEPTH); changeDepth(cur, DEC_DEPTH);
cur.update();
break; break;
case LFUN_DEPTH_PLUS: case LFUN_DEPTH_PLUS:
changeDepth(cur, INC_DEPTH); changeDepth(cur, INC_DEPTH);
cur.update();
break; break;
case LFUN_MATH_DISPLAY: case LFUN_MATH_DISPLAY:
mathDispatch(cur, this, cmd, true); mathDispatch(cur, cmd, true);
break; break;
case LFUN_MATH_IMPORT_SELECTION: case LFUN_MATH_IMPORT_SELECTION:
case LFUN_MATH_MODE: case LFUN_MATH_MODE:
mathDispatch(cur, this, cmd, false); mathDispatch(cur, cmd, false);
break; break;
case LFUN_MATH_MACRO: case LFUN_MATH_MACRO:
@ -1407,29 +1396,22 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} }
case LFUN_FINISHED_LEFT: case LFUN_FINISHED_LEFT:
lyxerr << "handle LFUN_FINISHED_LEFT" << endl; lyxerr << "handle LFUN_FINISHED_LEFT:\n" << cur << endl;
if (isRTL(cur.paragraph()))
cursorLeft(cur);
cur.bv().cursor() = cur;
break; break;
case LFUN_FINISHED_RIGHT: case LFUN_FINISHED_RIGHT:
lyxerr << "handle LFUN_FINISHED_RIGHT" << endl; lyxerr << "handle LFUN_FINISHED_RIGHT:\n" << cur << endl;
if (!isRTL(cur.paragraph())) ++cur.pos();
cursorRight(cur);
cur.bv().cursor() = cur;
break; break;
case LFUN_FINISHED_UP: case LFUN_FINISHED_UP:
lyxerr << "handle LFUN_FINISHED_UP" << endl; lyxerr << "handle LFUN_FINISHED_UP:\n" << cur << endl;
cursorUp(cur); cursorUp(cur);
cur.bv().cursor() = cur;
break; break;
case LFUN_FINISHED_DOWN: case LFUN_FINISHED_DOWN:
lyxerr << "handle LFUN_FINISHED_DOWN" << endl; lyxerr << "handle LFUN_FINISHED_DOWN:\n" << cur << endl;
cursorDown(cur); cursorDown(cur);
cur.bv().cursor() = cur;
break; break;
case LFUN_LAYOUT_PARAGRAPH: { case LFUN_LAYOUT_PARAGRAPH: {
@ -1503,13 +1485,11 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_ACCEPT_CHANGE: { case LFUN_ACCEPT_CHANGE: {
acceptChange(cur); acceptChange(cur);
cur.update();
break; break;
} }
case LFUN_REJECT_CHANGE: { case LFUN_REJECT_CHANGE: {
rejectChange(cur); rejectChange(cur);
cur.update();
break; break;
} }
@ -1542,7 +1522,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
params.align(), params.align(),
params.labelWidthString(), params.labelWidthString(),
params.noindent()); params.noindent());
cur.update();
cur.message(_("Paragraph layout set")); cur.message(_("Paragraph layout set"));
break; break;
} }
@ -1557,10 +1536,12 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
} }
case LFUN_ESCAPE: case LFUN_ESCAPE:
if (cur.selection()) if (cur.selection()) {
cur.selection() = false; cur.selection() = false;
else } else {
cur.undispatched();
cmd = FuncRequest(LFUN_FINISHED_LEFT); cmd = FuncRequest(LFUN_FINISHED_LEFT);
}
break; break;
default: default:

View File

@ -75,7 +75,7 @@ TocList const getTocList(Buffer const & buf)
for (; pit != end; ++pit) { for (; pit != end; ++pit) {
int const toclevel = pit->layout()->toclevel; int const toclevel = pit->layout()->toclevel;
if (toclevel > 0 && toclevel <= bufparams.tocdepth) { if (toclevel > 0 && toclevel <= bufparams.tocdepth) {
// insert this into the table of contents // insert this into the table of contents
TocItem const item(pit->id(), toclevel - 1, pit->asString(buf, true)); TocItem const item(pit->id(), toclevel - 1, pit->asString(buf, true));
toclist["TOC"].push_back(item); toclist["TOC"].push_back(item);
@ -87,14 +87,11 @@ TocList const getTocList(Buffer const & buf)
InsetList::const_iterator end = pit->insetlist.end(); InsetList::const_iterator end = pit->insetlist.end();
for (; it != end; ++it) { for (; it != end; ++it) {
if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) { if (it->inset->lyxCode() == InsetOld::FLOAT_CODE) {
InsetFloat * il = static_cast<InsetFloat*>(it->inset)
static_cast<InsetFloat*>(it->inset); ->addToToc(toclist, buf);
il->addToToc(toclist, buf);
} else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) { } else if (it->inset->lyxCode() == InsetOld::WRAP_CODE) {
InsetWrap * il = static_cast<InsetWrap*>(it->inset)
static_cast<InsetWrap*>(it->inset); ->addToToc(toclist, buf);
il->addToToc(toclist, buf);
} }
} }
} }

View File

@ -27,7 +27,7 @@
#include <algorithm> #include <algorithm>
using lyx::paroffset_type; using lyx::par_type;
namespace { namespace {
@ -45,7 +45,7 @@ std::ostream & operator<<(std::ostream & os, Undo const & undo)
void recordUndo(Undo::undo_kind kind, void recordUndo(Undo::undo_kind kind,
LCursor & cur, paroffset_type first_par, paroffset_type last_par, LCursor & cur, par_type first_par, par_type last_par,
limited_stack<Undo> & stack) limited_stack<Undo> & stack)
{ {
BOOST_ASSERT(first_par <= cur.lastpar()); BOOST_ASSERT(first_par <= cur.lastpar());
@ -200,14 +200,14 @@ bool textRedo(BufferView & bv)
void recordUndo(Undo::undo_kind kind, void recordUndo(Undo::undo_kind kind,
LCursor & cur, paroffset_type first, paroffset_type last) LCursor & cur, par_type first, par_type last)
{ {
Buffer * buf = cur.bv().buffer(); Buffer * buf = cur.bv().buffer();
recordUndo(kind, cur, first, last, buf->undostack()); recordUndo(kind, cur, first, last, buf->undostack());
buf->redostack().clear(); buf->redostack().clear();
lyxerr << "undostack:\n"; //lyxerr << "undostack:\n";
for (size_t i = 0, n = buf->undostack().size(); i != n && i < 6; ++i) //for (size_t i = 0, n = buf->undostack().size(); i != n && i < 6; ++i)
lyxerr << " " << i << ": " << buf->undostack()[i] << std::endl; // lyxerr << " " << i << ": " << buf->undostack()[i] << std::endl;
} }
@ -223,14 +223,14 @@ void recordUndoSelection(LCursor & cur, Undo::undo_kind kind)
} }
void recordUndo(LCursor & cur, Undo::undo_kind kind, paroffset_type from) void recordUndo(LCursor & cur, Undo::undo_kind kind, par_type from)
{ {
recordUndo(kind, cur, cur.par(), from); recordUndo(kind, cur, cur.par(), from);
} }
void recordUndo(LCursor & cur, Undo::undo_kind kind, void recordUndo(LCursor & cur, Undo::undo_kind kind,
paroffset_type from, paroffset_type to) par_type from, par_type to)
{ {
recordUndo(kind, cur, from, to); recordUndo(kind, cur, from, to);
} }

View File

@ -17,7 +17,7 @@
#define UNDO_H #define UNDO_H
#include "dociterator.h" #include "dociterator.h"
#include "ParagraphList_fwd.h" #include "ParagraphList_fwd.h"
#include "support/types.h" #include "support/types.h"
@ -54,9 +54,9 @@ struct Undo {
/// the position of the cursor /// the position of the cursor
StableDocumentIterator cursor; StableDocumentIterator cursor;
/// counted from begin of buffer /// counted from begin of buffer
lyx::paroffset_type from; lyx::par_type from;
/// complement to end of this cell /// complement to end of this cell
lyx::paroffset_type end; lyx::par_type end;
/// the contents of the saved paragraphs (for texted) /// the contents of the saved paragraphs (for texted)
ParagraphList pars; ParagraphList pars;
/// the contents of the saved matharray (for mathed) /// the contents of the saved matharray (for mathed)
@ -83,10 +83,10 @@ void finishUndo();
/// the common case: prepare undo for an arbitrary range /// the common case: prepare undo for an arbitrary range
void recordUndo(LCursor & cur, Undo::undo_kind kind, void recordUndo(LCursor & cur, Undo::undo_kind kind,
lyx::paroffset_type from, lyx::paroffset_type to); lyx::par_type from, lyx::par_type to);
/// convienience: prepare undo for the range between 'from' and cursor. /// convienience: prepare undo for the range between 'from' and cursor.
void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::paroffset_type from); void recordUndo(LCursor & cur, Undo::undo_kind kind, lyx::par_type from);
/// convienience: prepare undo for the single paragraph containing the cursor /// convienience: prepare undo for the single paragraph containing the cursor
void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC); void recordUndo(LCursor & cur, Undo::undo_kind kind = Undo::ATOMIC);