move around stuff, remove unneeded declarations etc

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8929 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-08-14 19:55:00 +00:00
parent ec4ebf3dcd
commit edbef46cd7
17 changed files with 132 additions and 132 deletions

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -1,3 +1,10 @@
2004-08-14 André Pönitz <poenitz@gmx.net>
* paragraph.h: inline getChar()
* BufferView.h: remove unused declarations
2004-08-14 José Matos <jamatos@lyx.org>
* Buffer.[Ch] (readDocument): new name for old readBody.

View File

@ -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;
}

View File

@ -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

View File

@ -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; }

View File

@ -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)

View File

@ -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;

View File

@ -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;
}

View File

@ -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 &);

View File

@ -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;
}

View File

@ -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

View File

@ -25,6 +25,8 @@
#include "support/types.h"
#include <boost/assert.hpp>
#include <string>
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.

View File

@ -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;

View File

@ -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<InsetOld_code> 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;
}

View File

@ -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