remove part of old texted<->mathed interface

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8502 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-03-18 16:05:32 +00:00
parent bed4cb9684
commit 13a89fc8af
4 changed files with 63 additions and 142 deletions

View File

@ -35,8 +35,8 @@
#include "insets/insettext.h"
#include "mathed/math_data.h"
#include "mathed/math_hullinset.h"
#include "mathed/math_support.h"
#include "mathed/math_inset.h"
#include "support/limited_stack.h"
#include "support/std_sstream.h"
@ -60,6 +60,26 @@ using std::swap;
limited_stack<string> theCutBuffer;
namespace {
void region(CursorSlice const & i1, CursorSlice const & i2,
LCursor::row_type & r1, LCursor::row_type & r2,
LCursor::col_type & c1, LCursor::col_type & c2)
{
InsetBase & p = i1.inset();
c1 = p.col(i1.idx_);
c2 = p.col(i2.idx_);
if (c1 > c2)
swap(c1, c2);
r1 = p.row(i1.idx_);
r2 = p.row(i2.idx_);
if (r1 > r2)
swap(r1, r2);
}
}
LCursor::LCursor(BufferView & bv)
: DocumentIterator(), bv_(&bv), anchor_(),
cached_y_(0), x_target_(-1), selection_(false), mark_(false)
@ -174,12 +194,9 @@ bool LCursor::popLeft()
{
BOOST_ASSERT(!empty());
//lyxerr << "Leaving inset to the left" << endl;
if (depth() <= 1) {
if (depth() == 1)
inset().notifyCursorLeaves(idx());
return false;
}
inset().notifyCursorLeaves(idx());
if (depth() == 1)
return false;
pop();
return true;
}
@ -189,12 +206,9 @@ bool LCursor::popRight()
{
BOOST_ASSERT(!empty());
//lyxerr << "Leaving inset to the right" << endl;
if (depth() <= 1) {
if (depth() == 1)
inset().notifyCursorLeaves(idx());
return false;
}
inset().notifyCursorLeaves(idx());
if (depth() == 1)
return false;
pop();
++pos();
return true;
@ -204,12 +218,12 @@ bool LCursor::popRight()
int LCursor::currentMode()
{
BOOST_ASSERT(!empty());
for (int i = size() - 1; i >= 1; --i) {
for (int i = size() - 1; i >= 0; --i) {
int res = operator[](i).inset().currentMode();
if (res != MathInset::UNDECIDED_MODE)
if (res != InsetBase::UNDECIDED_MODE)
return res;
}
return MathInset::TEXT_MODE;
return InsetBase::TEXT_MODE;
}
@ -396,26 +410,6 @@ void LCursor::info(std::ostream & os) const
}
namespace {
void region(CursorSlice const & i1, CursorSlice const & i2,
LCursor::row_type & r1, LCursor::row_type & r2,
LCursor::col_type & c1, LCursor::col_type & c2)
{
InsetBase & p = i1.inset();
c1 = p.col(i1.idx_);
c2 = p.col(i2.idx_);
if (c1 > c2)
swap(c1, c2);
r1 = p.row(i1.idx_);
r2 = p.row(i2.idx_);
if (r1 > r2)
swap(r1, r2);
}
}
string LCursor::grabSelection()
{
if (!selection())
@ -637,14 +631,8 @@ bool positionable(DocumentIterator const & cursor,
void LCursor::setScreenPos(int x, int y)
{
bool res = bruteFind(x, y, formula()->xlow(), formula()->xhigh(),
formula()->ylow(), formula()->yhigh());
if (!res) {
// this can happen on creation of "math-display"
idx() = 0;
pos() = 0;
}
clearTargetX();
x_target() = x;
bruteFind(x, y, 0, bv().workWidth(), 0, bv().workHeight());
}
@ -903,17 +891,6 @@ int LCursor::targetX() const
}
MathHullInset * LCursor::formula() const
{
for (int i = size() - 1; i >= 1; --i) {
MathInset * inset = operator[](i).inset().asMathInset();
if (inset && inset->asHullInset())
return static_cast<MathHullInset *>(inset);
}
return 0;
}
void LCursor::adjust(pos_type from, int diff)
{
if (pos() > from)
@ -1032,6 +1009,7 @@ bool LCursor::goUpDown(bool up)
// fragile. A distance of one pixel or a '<' vs '<=' _really
// matters. So fiddle around with it only if you think you know
// what you are doing!
int xo = 0;
int yo = 0;
getPos(xo, yo);
@ -1098,13 +1076,9 @@ bool LCursor::goUpDown(bool up)
// no such inset found, just take something "above"
//lyxerr << "updown: handled by strange case" << endl;
if (!popLeft()) {
return
bruteFind(xo, yo,
formula()->xlow(),
formula()->xhigh(),
up ? formula()->ylow() : yo + 4,
up ? yo - 4 : formula()->yhigh()
);
int ylow = up ? 0 : yo + 1;
int yhigh = up ? yo - 1 : bv().workHeight();
return bruteFind(xo, yo, 0, bv().workWidth(), ylow, yhigh);
}
// any improvement so far?
@ -1118,34 +1092,47 @@ bool LCursor::goUpDown(bool up)
bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{
DocumentIterator best_cursor;
double best_dist = 1e10;
BOOST_ASSERT(!empty());
ParagraphList::iterator beg;
ParagraphList::iterator end;
CursorSlice bottom = operator[](0);
LyXText * text = bottom.text();
BOOST_ASSERT(text);
getParsInRange(text->paragraphs(), ylow, yhigh, beg, end);
DocumentIterator it = insetBegin(bv().buffer()->inset());
DocumentIterator et = insetEnd();
while (1) {
DocumentIterator et;
lyxerr << "x: " << x << " y: " << y << endl;
lyxerr << "xlow: " << xlow << " ylow: " << ylow << endl;
lyxerr << "xhigh: " << xhigh << " yhigh: " << yhigh << endl;
it.par() = text->parOffset(beg);
//et.par() = text->parOffset(end);
double best_dist = 10e10;
DocumentIterator best_cursor = it;
for ( ; it != et; it.forwardPos()) {
// avoid invalid nesting when selecting
if (!selection() || positionable(it, anchor_)) {
int xo, yo;
int xo = 0, yo = 0;
CursorSlice & cur = it.back();
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);
//lyxerr << "x: " << x << " y: " << y << " d: " << endl;
lyxerr << "xo: " << xo << " yo: " << yo << " d: " << d << endl;
// '<=' in order to take the last possible position
// this is important for clicking behind \sum in e.g. '\sum_i a'
if (d <= best_dist) {
lyxerr << "*" << endl;
best_dist = d;
best_cursor = it;
}
}
}
if (it == et)
break;
it.forwardPos();
}
lyxerr << "best_dist: " << best_dist << " cur:\n" << best_cursor << endl;
if (best_dist < 1e10)
setCursor(best_cursor, false);
return best_dist < 1e10;

View File

@ -23,7 +23,6 @@ class FuncStatus;
class FuncRequest;
// these should go
class MathHullInset;
class MathUnknownInset;
class MathGridInset;
class Encoding;
@ -257,8 +256,6 @@ public:
MathGridInset * enclosingGrid(idx_type & idx) const;
/// adjust anchor position after deletions/insertions
void adjust(pos_type from, int diff);
///
MathHullInset * formula() const;
/// current offset in the top cell
/// interpret name a name of a macro
void macroModeClose();
@ -306,10 +303,6 @@ public:
/// moves position somehow up or down
bool goUpDown(bool up);
/// moves position closest to (x, y) in given box
bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
/// moves position closest to (x, y) in current cell
void bruteFind2(int x, int y);
/// the name of the macro we are currently inputting
std::string macroName();
@ -319,6 +312,12 @@ public:
bool openable(MathAtom const &) const;
///
Encoding const * getEncoding() const;
private:
/// moves position closest to (x, y) in current cell
void bruteFind2(int x, int y);
/// moves position closest to (x, y) in given box
bool bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh);
};
#endif // LYXCURSOR_H

View File

@ -909,30 +909,6 @@ string MathHullInset::fileInsetLabel() const
#include "support/lyxlib.h"
int MathHullInset::ylow() const
{
return yo_ - dim_.asc;
}
int MathHullInset::yhigh() const
{
return yo_ + dim_.des;
}
int MathHullInset::xlow() const
{
return xo_;
}
int MathHullInset::xhigh() const
{
return xo_ + dim_.wid;
}
// simply scrap this function if you want
void MathHullInset::mutateToText()
{
@ -990,18 +966,6 @@ string const MathHullInset::editMessage() const
}
void MathHullInset::insetUnlock(BufferView & bv)
{
if (bv.cursor().inMathed()) {
if (bv.cursor().inMacroMode())
bv.cursor().macroModeClose();
}
if (bv.buffer())
generatePreview(*bv.buffer());
bv.update();
}
void MathHullInset::getCursorDim(int & asc, int & desc) const
{
asc = 10;

View File

@ -154,22 +154,10 @@ private:
// Incorporate me
//
public:
/// lowest x coordinate
int xlow() const;
/// highest x coordinate
int xhigh() const;
/// lowest y coordinate
int ylow() const;
/// highest y coordinate
int yhigh() const;
/// what appears in the minibuffer when opening
virtual std::string const editMessage() const;
///
virtual void getCursorDim(int &, int &) const;
///
virtual void insetUnlock(BufferView & bv);
/// To allow transparent use of math editing functions
//virtual void status(FuncRequest &);
@ -193,28 +181,11 @@ public:
///
Code lyxCode() const;
private:
/// common base for handling accents
void handleAccent(BufferView & bv, std::string const & arg,
std::string const & name);
protected:
/** Find the PreviewLoader, add a LaTeX snippet to it and
* start the loading process.
*
* Most insets have no interest in this capability, so the method
* defaults to empty.
*/
virtual void generatePreview(Buffer const &) const {}
///
void handleFont(LCursor &, std::string const & arg, std::string const & font);
///
void handleFont2(LCursor &, std::string const & arg);
};
// We don't really want to mess around with mathed stuff outside mathed.
// So do it here.
void mathDispatch(LCursor & cur, FuncRequest & cmd);
#endif