mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-26 10:01:50 +00:00
conmsolidate scrolling code
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10204 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
6719871884
commit
f5ecca49d6
@ -1,3 +1,10 @@
|
||||
|
||||
2005-07-14 André Pönitz <poenitz@gmx.net>
|
||||
|
||||
* insetcollapsable.[Ch]:
|
||||
* updatableinset.[Ch]: (scroll, setScroll)
|
||||
sanitize things
|
||||
|
||||
2005-07-14 Angus Leeming <leeming@lyx.org>
|
||||
|
||||
* insetbibtex.C (latex): when processing the LaTeX file in
|
||||
|
@ -28,14 +28,13 @@ using std::string;
|
||||
|
||||
|
||||
InsetOld::InsetOld()
|
||||
: scx(0),
|
||||
//background_color_(LColor::inherit)
|
||||
: //background_color_(LColor::inherit)
|
||||
background_color_(LColor::background)
|
||||
{}
|
||||
|
||||
|
||||
InsetOld::InsetOld(InsetOld const & in)
|
||||
: InsetBase(in), scx(0), name_(in.name_),
|
||||
: InsetBase(in), name_(in.name_),
|
||||
background_color_(in.background_color_)
|
||||
{}
|
||||
|
||||
@ -70,12 +69,6 @@ int InsetOld::width() const
|
||||
}
|
||||
|
||||
|
||||
int InsetOld::scroll(bool) const
|
||||
{
|
||||
return scx;
|
||||
}
|
||||
|
||||
|
||||
void InsetOld::setPosCache(PainterInfo const &, int x, int y) const
|
||||
{
|
||||
//lyxerr << "InsetOld:: position cache to " << x << " " << y << std::endl;
|
||||
|
@ -50,15 +50,11 @@ public:
|
||||
LColor_color backgroundColor() const;
|
||||
/// set x/y drawing position cache
|
||||
void setPosCache(PainterInfo const &, int, int) const;
|
||||
/// returns the actual scroll-value
|
||||
virtual int scroll(bool recursive = true) const;
|
||||
|
||||
protected:
|
||||
///
|
||||
InsetOld(InsetOld const & in);
|
||||
///
|
||||
mutable int scx;
|
||||
///
|
||||
mutable Dimension dim_;
|
||||
|
||||
private:
|
||||
|
@ -272,8 +272,8 @@ InsetBase * InsetCollapsable::editXY(LCursor & cur, int x, int y)
|
||||
|
||||
void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
|
||||
<< " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
|
||||
//lyxerr << "InsetCollapsable::doDispatch (begin): cmd: " << cmd
|
||||
// << " cur: " << cur << " bvcur: " << cur.bv().cursor() << endl;
|
||||
|
||||
switch (cmd.action) {
|
||||
case LFUN_MOUSE_PRESS:
|
||||
@ -305,7 +305,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
switch (status_) {
|
||||
|
||||
case Collapsed:
|
||||
lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
|
||||
//lyxerr << "InsetCollapsable::lfunMouseRelease 1" << endl;
|
||||
setStatus(cur, Open);
|
||||
edit(cur, true);
|
||||
cur.bv().cursor() = cur;
|
||||
@ -313,18 +313,18 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
|
||||
case Open: {
|
||||
if (hitButton(cmd)) {
|
||||
lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
|
||||
//lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
|
||||
setStatus(cur, Collapsed);
|
||||
cur.bv().cursor() = cur;
|
||||
} else {
|
||||
lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
|
||||
//lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Inlined:
|
||||
lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
|
||||
//lyxerr << "InsetCollapsable::lfunMouseRelease 4" << endl;
|
||||
InsetText::doDispatch(cur, cmd);
|
||||
break;
|
||||
}
|
||||
@ -399,14 +399,3 @@ void InsetCollapsable::setLabelFont(LyXFont & font)
|
||||
labelfont_ = font;
|
||||
}
|
||||
|
||||
|
||||
void InsetCollapsable::scroll(BufferView & bv, double sx) const
|
||||
{
|
||||
UpdatableInset::scroll(bv, sx);
|
||||
}
|
||||
|
||||
|
||||
void InsetCollapsable::scroll(BufferView & bv, int offset) const
|
||||
{
|
||||
UpdatableInset::scroll(bv, offset);
|
||||
}
|
||||
|
@ -67,10 +67,6 @@ public:
|
||||
///
|
||||
int scroll(bool recursive = true) const;
|
||||
///
|
||||
void scroll(BufferView & bv, double sx) const;
|
||||
///
|
||||
void scroll(BufferView & bv, int offset) const;
|
||||
///
|
||||
bool isOpen() const { return status_ == Open || status_ == Inlined; }
|
||||
///
|
||||
bool inlined() const { return status_ == Inlined; }
|
||||
|
@ -433,7 +433,7 @@ void InsetTabular::edit(LCursor & cur, bool left)
|
||||
|
||||
void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
|
||||
//lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
|
||||
//lyxerr << " cur:\n" << cur << endl;
|
||||
CursorSlice sl = cur.top();
|
||||
LCursor & bvcur = cur.bv().cursor();
|
||||
@ -441,7 +441,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
switch (cmd.action) {
|
||||
|
||||
case LFUN_MOUSE_PRESS:
|
||||
lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
|
||||
//lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
|
||||
|
||||
if (cmd.button() == mouse_button::button1) {
|
||||
cur.selection() = false;
|
||||
@ -465,7 +465,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_MOUSE_MOTION:
|
||||
lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
|
||||
//lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
|
||||
if (cmd.button() == mouse_button::button1) {
|
||||
// only accept motions to places not deeper nested than the real anchor
|
||||
if (bvcur.anchor_.hasPart(cur)) {
|
||||
@ -478,7 +478,7 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
break;
|
||||
|
||||
case LFUN_MOUSE_RELEASE:
|
||||
lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
|
||||
//lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
|
||||
if (cmd.button() == mouse_button::button3)
|
||||
InsetTabularMailer(*this).showDialog(&cur.bv());
|
||||
break;
|
||||
@ -493,13 +493,14 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
cur.selection() = false;
|
||||
break;
|
||||
|
||||
case LFUN_SCROLL_INSET:
|
||||
if (cmd.argument.empty())
|
||||
break;
|
||||
if (cmd.argument.find('.') != cmd.argument.npos)
|
||||
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
|
||||
else
|
||||
scroll(cur.bv(), convert<int>(cmd.argument));
|
||||
case LFUN_SCROLL_INSET:
|
||||
if (!cmd.argument.empty()) {
|
||||
int const ww = cur.bv().workWidth();
|
||||
if (cmd.argument.find('.') != cmd.argument.npos)
|
||||
setScroll(ww, static_cast<float>(convert<double>(cmd.argument)));
|
||||
else
|
||||
setScroll(ww, convert<int>(cmd.argument));
|
||||
}
|
||||
break;
|
||||
|
||||
case LFUN_RIGHTSEL:
|
||||
@ -1138,22 +1139,20 @@ int InsetTabular::dist(idx_type const cell, int x, int y) const
|
||||
+ tabular.getAdditionalHeight(row);
|
||||
int const yend = ybeg + rowheight;
|
||||
|
||||
if (x < xbeg) {
|
||||
if (x < xbeg)
|
||||
xx = xbeg - x;
|
||||
} else if (x > xend) {
|
||||
else if (x > xend)
|
||||
xx = x - xend;
|
||||
}
|
||||
|
||||
if (y < ybeg) {
|
||||
if (y < ybeg)
|
||||
yy = ybeg - y;
|
||||
} else if (y > yend) {
|
||||
else if (y > yend)
|
||||
yy = y - yend;
|
||||
}
|
||||
|
||||
lyxerr << " xbeg=" << xbeg << " xend=" << xend
|
||||
<< " ybeg=" << ybeg << " yend=" << yend
|
||||
<< " xx=" << xx << " yy=" << yy
|
||||
<< " dist=" << xx + yy << endl;
|
||||
//lyxerr << " xbeg=" << xbeg << " xend=" << xend
|
||||
// << " ybeg=" << ybeg << " yend=" << yend
|
||||
// << " xx=" << xx << " yy=" << yy
|
||||
// << " dist=" << xx + yy << endl;
|
||||
return xx + yy;
|
||||
}
|
||||
|
||||
@ -1181,7 +1180,7 @@ void InsetTabular::setCursorFromCoordinates(LCursor & cur, int x, int y) const
|
||||
|
||||
InsetTabular::idx_type InsetTabular::getNearestCell(int x, int y) const
|
||||
{
|
||||
lyxerr << "# InsetTabular::getNearestCell() x=" << x << " y=" << y << endl;
|
||||
//lyxerr << "# InsetTabular::getNearestCell() x=" << x << " y=" << y << endl;
|
||||
idx_type idx_min = 0;
|
||||
int dist_min = std::numeric_limits<int>::max();
|
||||
for (idx_type i = 0; i < nargs(); ++i) {
|
||||
@ -1214,6 +1213,7 @@ int InsetTabular::getCellXPos(idx_type const cell) const
|
||||
void InsetTabular::resetPos(LCursor & cur) const
|
||||
{
|
||||
BufferView & bv = cur.bv();
|
||||
int const maxwidth = bv.workWidth();
|
||||
// col_type const actcol = tabular.column_of_cell(cur.idx());
|
||||
// int const offset = ADD_TO_TABULAR_WIDTH + 2;
|
||||
// int const new_x = getCellXPos(cur.idx()) + offset;
|
||||
@ -1222,32 +1222,32 @@ void InsetTabular::resetPos(LCursor & cur) const
|
||||
// cursorx_ = new_x;
|
||||
// cursor.x(getCellXPos(cur.idx()) + offset);
|
||||
// if (actcol < tabular.columns() - 1 && scroll(false) &&
|
||||
// tabular.getWidthOfTabular() < bv.workWidth()-20)
|
||||
// tabular.getWidthOfTabular() < maxwidth - 20)
|
||||
// {
|
||||
// scroll(bv, 0.0F);
|
||||
// setScroll(maxwidth, 0.0F);
|
||||
// } else if (cursorx_ - offset > 20 &&
|
||||
// cursorx_ - offset + col_width > bv.workWidth() - 20) {
|
||||
// scroll(bv, - col_width - 20);
|
||||
// cursorx_ - offset + col_width > maxwidth - 20) {
|
||||
// setScroll(maxwidth, - col_width - 20);
|
||||
// } else if (cursorx_ - offset < 20) {
|
||||
// scroll(bv, 20 - cursorx_ + offset);
|
||||
// setScroll(maxwidth, 20 - cursorx_ + offset);
|
||||
// } else if (scroll() && xo() > 20 &&
|
||||
// xo() + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
|
||||
// scroll(bv, old_x - cursorx_);
|
||||
// xo() + tabular.getWidthOfTabular() > maxwidth - 20) {
|
||||
// setScroll(maxwidth, old_x - cursorx_);
|
||||
// }
|
||||
|
||||
if (&cur.inset() != this) {
|
||||
scroll(bv, 0.0F);
|
||||
setScroll(maxwidth, 0.0f);
|
||||
} else {
|
||||
int const X1 = 0;
|
||||
int const X2 = bv.workWidth();
|
||||
int const X2 = maxwidth;
|
||||
int const offset = ADD_TO_TABULAR_WIDTH + 2;
|
||||
int const x1 = xo() + scroll() + getCellXPos(cur.idx()) + offset;
|
||||
int const x2 = x1 + tabular.getWidthOfColumn(cur.idx());
|
||||
|
||||
if (x1 < X1)
|
||||
scroll(bv, X1 + 20 - x1);
|
||||
setScroll(maxwidth, X1 + 20 - x1);
|
||||
else if (x2 > X2)
|
||||
scroll(bv, X2 - 20 - x2);
|
||||
setScroll(maxwidth, X2 - 20 - x2);
|
||||
}
|
||||
|
||||
cur.needsUpdate();
|
||||
@ -1258,9 +1258,7 @@ void InsetTabular::resetPos(LCursor & cur) const
|
||||
|
||||
void InsetTabular::moveNextCell(LCursor & cur)
|
||||
{
|
||||
lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur.top() << endl;
|
||||
if (isRightToLeft(cur)) {
|
||||
lyxerr << "InsetTabular::moveNextCell A cur: " << endl;
|
||||
if (tabular.isFirstCellInRow(cur.idx())) {
|
||||
row_type const row = tabular.row_of_cell(cur.idx());
|
||||
if (row == tabular.rows() - 1)
|
||||
@ -1272,14 +1270,12 @@ void InsetTabular::moveNextCell(LCursor & cur)
|
||||
--cur.idx();
|
||||
}
|
||||
} else {
|
||||
lyxerr << "InsetTabular::moveNextCell B cur: " << endl;
|
||||
if (tabular.isLastCell(cur.idx()))
|
||||
return;
|
||||
++cur.idx();
|
||||
}
|
||||
cur.pit() = 0;
|
||||
cur.pos() = 0;
|
||||
lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur.top() << endl;
|
||||
resetPos(cur);
|
||||
}
|
||||
|
||||
|
@ -35,34 +35,41 @@ InsetBase::EDITABLE UpdatableInset::editable() const
|
||||
}
|
||||
|
||||
|
||||
void UpdatableInset::scroll(BufferView & bv, double s) const
|
||||
int UpdatableInset::scroll(bool) const
|
||||
{
|
||||
return scx;
|
||||
}
|
||||
|
||||
|
||||
void UpdatableInset::setScroll(int maxwidth, double s) const
|
||||
{
|
||||
lyxerr << "UpdatableInset::setScroll: (int) " << maxwidth << std::endl;
|
||||
if (!s) {
|
||||
scx = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int const workW = bv.workWidth();
|
||||
int xo_ = theCoords.getInsets().x(this);
|
||||
int const tmp_xo_ = xo_ - scx;
|
||||
|
||||
if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
|
||||
if (tmp_xo_ > 0 && tmp_xo_ + width() < maxwidth)
|
||||
return;
|
||||
if (s > 0.0 && xo_ > 0)
|
||||
return;
|
||||
|
||||
scx = int(s * workW / 2);
|
||||
scx = int(s * maxwidth / 2);
|
||||
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning metrics?
|
||||
#endif
|
||||
if (tmp_xo_ + scx + width() < workW / 2)
|
||||
scx = workW / 2 - tmp_xo_ - width();
|
||||
if (tmp_xo_ + scx + width() < maxwidth / 2)
|
||||
scx = maxwidth / 2 - tmp_xo_ - width();
|
||||
}
|
||||
|
||||
|
||||
void UpdatableInset::scroll(BufferView & bv, int offset) const
|
||||
void UpdatableInset::setScroll(int maxwidth, int offset) const
|
||||
{
|
||||
lyxerr << "UpdatableInset::setScroll: (double) " << maxwidth << std::endl;
|
||||
int const xo_ = theCoords.getInsets().x(this);
|
||||
if (offset > 0) {
|
||||
if (!scx && xo_ >= 20)
|
||||
@ -76,13 +83,13 @@ void UpdatableInset::scroll(BufferView & bv, int offset) const
|
||||
#ifdef WITH_WARNINGS
|
||||
#warning metrics?
|
||||
#endif
|
||||
if (!scx && xo_ + width() < bv.workWidth() - 20)
|
||||
if (!scx && xo_ + width() < maxwidth - 20)
|
||||
return;
|
||||
if (xo_ - scx + offset + width() < bv.workWidth() - 20) {
|
||||
scx += bv.workWidth() - width() - xo_ - 20;
|
||||
} else {
|
||||
|
||||
if (xo_ - scx + offset + width() < maxwidth - 20)
|
||||
scx += maxwidth - width() - xo_ - 20;
|
||||
else
|
||||
scx += offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,15 +97,13 @@ void UpdatableInset::scroll(BufferView & bv, int offset) const
|
||||
void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
|
||||
{
|
||||
switch (cmd.action) {
|
||||
//case LFUN_MOUSE_RELEASE:
|
||||
// return DispatchResult(editable() == IS_EDITABLE);
|
||||
|
||||
case LFUN_SCROLL_INSET:
|
||||
if (cmd.argument.empty()) {
|
||||
const int maxwidth = cur.bv().workWidth();
|
||||
if (cmd.argument.find('.') != cmd.argument.npos)
|
||||
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
|
||||
setScroll(maxwidth, static_cast<float>(convert<double>(cmd.argument)));
|
||||
else
|
||||
scroll(cur.bv(), convert<int>(cmd.argument));
|
||||
setScroll(maxwidth, convert<int>(cmd.argument));
|
||||
} else
|
||||
cur.noUpdate();
|
||||
break;
|
||||
@ -113,3 +118,4 @@ void UpdatableInset::getCursorDim(int &, int &) const
|
||||
{
|
||||
BOOST_ASSERT(false);
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,8 @@
|
||||
|
||||
class UpdatableInset : public InsetOld {
|
||||
public:
|
||||
///
|
||||
UpdatableInset() : scx(0) {}
|
||||
///
|
||||
virtual EDITABLE editable() const;
|
||||
/// identification as text inset in a cursor slice
|
||||
@ -30,19 +32,20 @@ public:
|
||||
|
||||
/// return the cursor dim
|
||||
virtual void getCursorDim(int &, int &) const;
|
||||
// We need this method to not clobber the real method in Inset
|
||||
int scroll(bool recursive = true) const
|
||||
{ return InsetOld::scroll(recursive); }
|
||||
///
|
||||
virtual bool showInsetDialog(BufferView *) const { return false; }
|
||||
|
||||
protected:
|
||||
/// An updatable inset could handle lyx editing commands
|
||||
virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
|
||||
/// scrolls to absolute position in bufferview-workwidth * sx units
|
||||
void scroll(BufferView &, double sx) const;
|
||||
/// scrolls to absolute position in maxwidth * sx units
|
||||
void setScroll(int maxwidth, double sx) const;
|
||||
/// scrolls offset pixels
|
||||
void scroll(BufferView &, int offset) const;
|
||||
void setScroll(int maxwidth, int offset) const;
|
||||
/// returns the actual scroll value
|
||||
virtual int scroll(bool recursive = true) const;
|
||||
///
|
||||
mutable int scx;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user