From edbef46cd7865dab72ab6b503d62e2492479d297 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Sat, 14 Aug 2004 19:55:00 +0000 Subject: [PATCH] move around stuff, remove unneeded declarations etc git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8929 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 37 ++++--------------------- src/BufferView.h | 12 +------- src/BufferView_pimpl.C | 27 ++++++++++++------ src/ChangeLog | 7 +++++ src/cursor.C | 20 +++++++------- src/cursor.h | 2 +- src/insets/insetbase.h | 2 ++ src/insets/insetcollapsable.C | 10 +++++-- src/insets/insettabular.C | 3 +- src/mathed/math_decorationinset.C | 2 +- src/mathed/math_inset.h | 3 ++ src/mathed/math_nestinset.C | 3 +- src/paragraph.C | 34 +++++++++++------------ src/paragraph.h | 10 ++++++- src/text2.C | 43 +++++++++++++++++++++++++++++ src/text3.C | 46 ++----------------------------- src/undo.C | 3 +- 17 files changed, 132 insertions(+), 132 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index 2763929f1d..30d6327240 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -47,11 +47,7 @@ #include "insets/updatableinset.h" #include "insets/insettext.h" -#include "support/filetools.h" -#include "support/lyxalgo.h" // lyx_count - using lyx::support::bformat; -using lyx::support::MakeAbsPath; using lyx::cap::setSelectionRange; @@ -259,30 +255,6 @@ void BufferView::scroll(int lines) } -// Inserts a file into current document -bool BufferView::insertLyXFile(string const & filen) - // - // Copyright CHT Software Service GmbH - // Uwe C. Schroeder - // - // Insert a LyXformat - file into current buffer - // - // Moved from lyx_cb.C (Lgb) -{ - BOOST_ASSERT(!filen.empty()); - - string const fname = MakeAbsPath(filen); - - cursor().clearSelection(); - text()->breakParagraph(cursor()); - - BOOST_ASSERT(cursor().inTexted()); - bool res = buffer()->readFile(fname, cursor().par()); - resize(); - return res; -} - - void BufferView::showErrorList(string const & action) const { if (getErrorList().size()) { @@ -310,8 +282,7 @@ void BufferView::setCursorFromRow(int row) if (tmpid == -1) text()->setCursor(cursor(), 0, 0); else - text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), - tmppos); + text()->setCursor(cursor(), buffer()->getParFromID(tmpid).pit(), tmppos); } @@ -377,7 +348,8 @@ void BufferView::setCursor(ParIterator const & par, lyx::pos_type pos) for (int i = 0; i < last; ++i) par[i].inset().edit(cursor(), true); - cursor().setCursor(makeDocIterator(par, pos), false); + cursor().setCursor(makeDocIterator(par, pos)); + cursor().selection() = false; par.bottom().text()->redoParagraph(par.bottom().par()); } @@ -395,7 +367,8 @@ void BufferView::putSelectionAt(DocIterator const & cur, if (backwards) { cursor().setSelection(cursor(), -length); DocIterator const it = cursor(); - cursor().setCursor(cursor().anchor_, true); + cursor().setCursor(cursor().anchor_); + cursor().selection() = true; cursor().anchor_ = it; } else cursor().setSelection(cursor(), length); diff --git a/src/BufferView.h b/src/BufferView.h index 8bbb970012..e4ef2e5548 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -24,11 +24,9 @@ class Buffer; class Change; class DocIterator; -class Encoding; class ErrorList; class FuncRequest; class FuncStatus; -class InsetBase; class InsetOld; class Language; class LCursor; @@ -37,8 +35,6 @@ class LyXScreen; class LyXView; class Painter; class ParIterator; -class TeXErrors; -class UpdatableInset; /** * A buffer view encapsulates a view onto a particular @@ -128,12 +124,6 @@ public: /// set the cursor based on the given TeX source row void setCursorFromRow(int row); - /// Inserts a lyx file at cursor position. return false if it fails - bool insertLyXFile(std::string const & file); - - /// FIXME - bool fitLockedInsetCursor(int x, int y, int asc, int desc); - /// hide the cursor if it is visible void hideCursor(); @@ -142,7 +132,7 @@ public: /// scroll document by the given number of lines of default height void scroll(int lines); /// Scroll the view by a number of pixels - void scrollDocView(int); + void scrollDocView(int pixels); /// return the pixel width of the document view int workWidth() const; diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index d80723d200..9059d65711 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -81,6 +81,7 @@ using lyx::support::FileSearch; using lyx::support::ForkedcallsController; using lyx::support::IsDirWriteable; using lyx::support::MakeDisplayPath; +using lyx::support::MakeAbsPath; using lyx::support::strToUnsignedInt; using lyx::support::system_lyxdir; @@ -796,12 +797,19 @@ void BufferView::Pimpl::MenuInsertLyXFile(string const & filenm) string const disp_fn = MakeDisplayPath(filename); owner_->message(bformat(_("Inserting document %1$s..."), disp_fn)); - if (bv_->insertLyXFile(filename)) - owner_->message(bformat(_("Document %1$s inserted."), - disp_fn)); - else - owner_->message(bformat(_("Could not insert document %1$s"), - disp_fn)); + + bv_->cursor().clearSelection(); + bv_->text()->breakParagraph(bv_->cursor()); + + BOOST_ASSERT(bv_->cursor().inTexted()); + + string const fname = MakeAbsPath(filename); + bool const res = bv_->buffer()->readFile(fname, bv_->cursor().par()); + bv_->resize(); + + string s = res ? _("Document %1$s inserted.") + : _("Could not insert document %1$s"); + owner_->message(bformat(s, disp_fn)); } @@ -876,8 +884,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) // Build temporary cursor. InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y); - lyxerr << "hit inset at tip: " << inset << endl; - lyxerr << "created temp cursor:\n" << cur << endl; + lyxerr << " * created temp cursor: " << inset << endl; + lyxerr << " * hit inset at tip: " << inset << endl; + lyxerr << " * created temp cursor:" << cur << endl; // Put anchor at the same position. cur.resetAnchor(); @@ -885,7 +894,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) // Try to dispatch to an non-editable inset near this position // 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)' + // cur.bv().cursor() = cur; (or similar) if (inset) inset->dispatch(cur, cmd); diff --git a/src/ChangeLog b/src/ChangeLog index e0b6e3d491..555b745518 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ + +2004-08-14 André Pönitz + + * paragraph.h: inline getChar() + + * BufferView.h: remove unused declarations + 2004-08-14 José Matos * Buffer.[Ch] (readDocument): new name for old readBody. diff --git a/src/cursor.C b/src/cursor.C index 2a45dbd4da..63194839f7 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -92,7 +92,7 @@ namespace { for (int i = 0; ; ++i) { int xo, yo; LCursor cur = c; - cur.setCursor(it, false); + cur.setCursor(it); cur.inset().getCursorPos(cur, xo, yo); double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); // '<=' in order to take the last possible position @@ -138,7 +138,7 @@ namespace { if (!cursor.selection() || positionable(it, cursor.anchor_)) { int xo = 0, yo = 0; LCursor cur = cursor; - cur.setCursor(it, false); + cur.setCursor(it); cur.inset().getCursorPos(cur, xo, yo); if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); @@ -156,7 +156,7 @@ namespace { //lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl; if (best_dist < 1e10) - cursor.setCursor(best_cursor, false); + cursor.setCursor(best_cursor); return best_dist < 1e10; } @@ -181,11 +181,10 @@ void LCursor::reset(InsetBase & inset) } -void LCursor::setCursor(DocIterator const & cur, bool sel) +// this (intentionally) does neither touch anchor nor selection status +void LCursor::setCursor(DocIterator const & cur) { - // this (intentionally) does not touch the anchor DocIterator::operator=(cur); - selection() = sel; } @@ -447,7 +446,8 @@ void LCursor::setSelection() void LCursor::setSelection(DocIterator const & where, size_t n) { - setCursor(where, true); + setCursor(where); + selection() = true; anchor_ = where; pos() += n; } @@ -771,7 +771,7 @@ bool LCursor::up() DocIterator save = *this; if (goUpDown(true)) return true; - setCursor(save, false); + setCursor(save); autocorrect() = false; return selection(); } @@ -783,7 +783,7 @@ bool LCursor::down() DocIterator save = *this; if (goUpDown(false)) return true; - setCursor(save, false); + setCursor(save); autocorrect() = false; return selection(); } @@ -976,7 +976,7 @@ bool LCursor::goUpDown(bool up) if (inset().idxUpDown(*this, up)) { // try to find best position within this inset if (!selection()) - setCursor(bruteFind2(*this, xo, yo), false); + setCursor(bruteFind2(*this, xo, yo)); return true; } diff --git a/src/cursor.h b/src/cursor.h index ad99a3e6e1..2318cd9635 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -55,7 +55,7 @@ public: /// pop one slice off the cursor stack and go right bool popRight(); /// sets cursor part - void setCursor(DocIterator const & it, bool sel); + void setCursor(DocIterator const & it); // // selection diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 0109473402..d87ac7c15a 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -362,6 +362,8 @@ public: enum mode_type {UNDECIDED_MODE, TEXT_MODE, MATH_MODE}; /// return text or mathmode if that is possible to determine virtual mode_type currentMode() const { return UNDECIDED_MODE; } + /// returns whether this inset is allowed in other insets of given mode + virtual bool allowedIn(mode_type) const { return true; } /// is this inset allowed within a font change? virtual bool noFontChange() const { return false; } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index f8de8e7f6c..88e6782394 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -253,9 +253,13 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y) const void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd) { -// lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd -// << " button y: " << button_dim.y2 -// << " coll/inline/open: " << status_ << endl; +// lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd +// << " button y: " << button_dim.y2 +// << " coll/inline/open: " << status_ << endl; + + lyxerr << "InsetCollapsable::priv_dispatch (begin): cmd: " << cmd + << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl; + switch (cmd.action) { case LFUN_MOUSE_PRESS: if (status_ == Inlined) diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 140e1cf279..80fdeaeebd 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -440,7 +440,8 @@ void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd) if (bvcur.selection() && bvcur.anchor_.size() < cur.size()) break; setPos(cur, cmd.x, cmd.y); - bvcur.setCursor(cur, true); + bvcur.setCursor(cur); + bvcur.selection() = true; lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl; break; diff --git a/src/mathed/math_decorationinset.C b/src/mathed/math_decorationinset.C index 3f24a73e05..25dd231ca4 100644 --- a/src/mathed/math_decorationinset.C +++ b/src/mathed/math_decorationinset.C @@ -28,7 +28,7 @@ using std::auto_ptr; MathDecorationInset::MathDecorationInset(latexkeys const * key) : MathNestInset(1), key_(key) { - lyxerr << " creating deco " << key->name << std::endl; +// lyxerr << " creating deco " << key->name << std::endl; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 7e8365d05a..9979b65451 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -177,6 +177,9 @@ public: virtual void mutate(std::string const &) {} /// usually the latex name virtual std::string name() const; + + /// math stuff usually isn't allowed in text mode + virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; } }; std::ostream & operator<<(std::ostream &, MathAtom const &); diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 2d1596bbff..432bd33b52 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -933,7 +933,8 @@ void MathNestInset::lfunMouseMotion(LCursor & cur, FuncRequest & cmd) first_x = cmd.x; first_y = cmd.y; - cur.bv().cursor().setCursor(cur, true); + cur.bv().cursor().setCursor(cur); + cur.bv().cursor().selection() = true; } diff --git a/src/paragraph.C b/src/paragraph.C index 153648a936..33c4eb1b8e 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1736,23 +1736,23 @@ void Paragraph::rejectChange(pos_type start, pos_type end) } -Paragraph::value_type Paragraph::getChar(pos_type pos) const -{ - // This is in the critical path! - pos_type const siz = text_.size(); - - BOOST_ASSERT(0 <= pos); - BOOST_ASSERT(pos <= siz); - - if (pos == siz) { - lyxerr << "getChar() on pos " << pos << " in par id " - << id() << " of size " << siz - << " is a bit silly !" << endl; - BOOST_ASSERT(false); - } - - return text_[pos]; -} +//Paragraph::value_type Paragraph::getChar(pos_type pos) const +//{ +// // This is in the critical path! +// pos_type const siz = text_.size(); +// +// BOOST_ASSERT(0 <= pos); +// BOOST_ASSERT(pos <= siz); +// +// if (pos == siz) { +// lyxerr << "getChar() on pos " << pos << " in par id " +// << id() << " of size " << siz +// << " is a bit silly !" << endl; +// BOOST_ASSERT(false); +// } +// +// return text_[pos]; +//} int Paragraph::id() const diff --git a/src/paragraph.h b/src/paragraph.h index aa4e24156d..ded4888a95 100644 --- a/src/paragraph.h +++ b/src/paragraph.h @@ -25,6 +25,8 @@ #include "support/types.h" +#include + #include class Buffer; @@ -269,7 +271,13 @@ public: */ lyx::pos_type getEndPosOfFontSpan(lyx::pos_type pos) const; /// - value_type getChar(lyx::pos_type pos) const; + /// this is a bottleneck. + value_type getChar(lyx::pos_type pos) const + { + BOOST_ASSERT(pos >= 0); + BOOST_ASSERT(pos < int(text_.size())); + return text_[pos]; + } /// value_type getUChar(BufferParams const &, lyx::pos_type pos) const; /// The position must already exist. diff --git a/src/text2.C b/src/text2.C index f87fbe2fb6..f15294a1ee 100644 --- a/src/text2.C +++ b/src/text2.C @@ -27,6 +27,7 @@ #include "BufferView.h" #include "Bullet.h" #include "counters.h" +#include "coordcache.h" #include "cursor.h" #include "CutAndPaste.h" #include "debug.h" @@ -101,6 +102,46 @@ bool LyXText::isMainText() const } +// takes absolute x,y coordinates +InsetBase * LyXText::checkInsetHit(int x, int y) const +{ + par_type pit; + par_type end; + + getParsInRange(paragraphs(), + bv()->top_y() - yo_, + bv()->top_y() - yo_ + bv()->workHeight(), + pit, end); + + lyxerr << "checkInsetHit: x: " << x << " y: " << y << endl; + lyxerr << " pit: " << pit << " end: " << end << endl; + for (; pit != end; ++pit) { + InsetList::const_iterator iit = pars_[pit].insetlist.begin(); + InsetList::const_iterator iend = pars_[pit].insetlist.end(); + for (; iit != iend; ++iit) { + InsetBase * inset = iit->inset; +#if 1 + lyxerr << "examining inset " << inset << endl; + if (theCoords.insets_.has(inset)) + lyxerr + << " xo: " << inset->xo() << "..." << inset->xo() + inset->width() + << " yo: " << inset->yo() - inset->ascent() << "..." + << inset->yo() + inset->descent() << endl; + else + lyxerr << " inset has no cached position"; +#endif + if (inset->covers(x, y)) { + lyxerr << "Hit inset: " << inset << endl; + return inset; + } + } + } + lyxerr << "No inset hit. " << endl; + return 0; +} + + + // Gets the fully instantiated font at a given position in a paragraph // Basically the same routine as Paragraph::getFont() in paragraph.C. // The difference is that this one is used for displaying, and thus we @@ -1122,6 +1163,7 @@ pos_type LyXText::getColumnNearX(par_type pit, // x,y are absolute coordinates +// sets cursor only within this LyXText void LyXText::setCursorFromCoordinates(LCursor & cur, int x, int y) { x -= xo_; @@ -1138,6 +1180,7 @@ void LyXText::setCursorFromCoordinates(LCursor & cur, int x, int y) // x,y are absolute screen coordinates +// sets cursor recursively descending into nested editable insets InsetBase * LyXText::editXY(LCursor & cur, int x, int y) const { par_type pit; diff --git a/src/text3.C b/src/text3.C index d07a337b24..4b69a2b010 100644 --- a/src/text3.C +++ b/src/text3.C @@ -184,49 +184,6 @@ string const freefont2string() } - -// takes absolute x,y coordinates -InsetBase * LyXText::checkInsetHit(int x, int y) const -{ - par_type pit; - par_type end; - - getParsInRange(paragraphs(), - bv()->top_y() - yo_, - bv()->top_y() - yo_ + bv()->workHeight(), - pit, end); - - lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION - << ": x: " << x << " y: " << y - << " pit: " << pit << " end: " << end << endl; - for (; pit != end; ++pit) { - InsetList::const_iterator iit = pars_[pit].insetlist.begin(); - InsetList::const_iterator iend = pars_[pit].insetlist.end(); - for (; iit != iend; ++iit) { - InsetBase * inset = iit->inset; -#if 1 - lyxerr[Debug::DEBUG] - << "examining inset " << inset << endl; - if (theCoords.insets_.has(inset)) - lyxerr - << " xo: " << inset->xo() << "..." << inset->xo() + inset->width() - << " yo: " << inset->yo() - inset->ascent() << "..." - << inset->yo() + inset->descent() << endl; - else - lyxerr << " inset has no cached position"; -#endif - if (inset->covers(x, y)) { - lyxerr[Debug::DEBUG] - << "Hit inset: " << inset << endl; - return inset; - } - } - } - lyxerr[Debug::DEBUG] << "No inset hit. " << endl; - return 0; -} - - bool LyXText::gotoNextInset(LCursor & cur, vector const & codes, string const & contents) { @@ -1134,7 +1091,8 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) } // don't set anchor_ - bv->cursor().setCursor(cur, true); + bv->cursor().setCursor(cur); + bv->cursor().selection() = true; lyxerr << "MOTION: " << bv->cursor() << endl; break; } diff --git a/src/undo.C b/src/undo.C index b0f0fe1931..d7a36941d0 100644 --- a/src/undo.C +++ b/src/undo.C @@ -108,7 +108,8 @@ void performUndoOrRedo(BufferView & bv, Undo const & undo) { LCursor & cur = bv.cursor(); lyxerr << "undo, performing: " << undo << std::endl; - cur.setCursor(undo.cursor.asDocIterator(&bv.buffer()->inset()), false); + cur.setCursor(undo.cursor.asDocIterator(&bv.buffer()->inset())); + cur.selection() = false; if (cur.inMathed()) { // We stored the full cell here as there is not much to be -- 2.39.2