Hello,
In order to support multiple LyXView each BufferView needs its own
CoordCache. This is what's implemented in this patch.
theCoords is now a global pointer instead of a global variable. It is
set at each BufferView::updateMetrics() call. I am not very happy with
that but BufferView is not visible everywhere. This needs to be fixed
IMHO. Ideally all CoordCache access should be done via
BufferView::cordCache().
Will commit tomorrow if there's no objection.
Abdel.
Index: BufferView.C
===================================================================
--- BufferView.C (revision 15305)
+++ BufferView.C (working copy)
@@ -103,6 +103,7 @@
namespace Alert = lyx::frontend::Alert;
+CoordCache * theCoords;
namespace {
@@ -1260,8 +1261,13 @@
void BufferView::updateMetrics(bool singlepar)
{
+ // FIXME: this global pointer is used where BufferView is not
+ // visible. When this is cleaned up. Replace all occurence of
+ // theCoords with BufferView::coordCache().
+ theCoords = &coord_cache_;
+
// Remove old position cache
- theCoords.clear();
+ coord_cache_.clear();
LyXText & buftext = buffer_->text();
lyx::pit_type size = int(buftext.paragraphs().size());
@@ -1325,7 +1331,7 @@
// The coordinates of all these paragraphs are correct, cache them
int y = y1;
- CoordCache::InnerParPosCache & parPos = theCoords.parPos()[&buftext];
+ CoordCache::InnerParPosCache & parPos = coord_cache_.parPos()[&buftext];
for (lyx::pit_type pit = pit1; pit <= pit2; ++pit) {
Paragraph const & par = buftext.getPar(pit);
y += par.ascent();
Index: BufferView.h
===================================================================
--- BufferView.h (revision 15305)
+++ BufferView.h (working copy)
@@ -15,6 +15,7 @@
#ifndef BUFFER_VIEW_H
#define BUFFER_VIEW_H
+#include "coordcache.h"
#include "cursor.h"
#include "metricsinfo.h"
@@ -199,6 +200,14 @@
///
void updateMetrics(bool singlepar = false);
+ ///
+ CoordCache & coordCache() {
+ return coord_cache_;
+ }
+ ///
+ CoordCache const & coordCache() const {
+ return coord_cache_;
+ }
/// get this view's keyboard map handler
Intl & getIntl() { return *intl_.get(); }
///
@@ -238,7 +247,7 @@
///
ViewMetricsInfo metrics_info_;
-
+ CoordCache coord_cache_;
///
Buffer * buffer_;
Index: bufferview_funcs.C
===================================================================
--- bufferview_funcs.C (revision 15305)
+++ bufferview_funcs.C (working copy)
@@ -202,8 +202,8 @@
{
CursorSlice const & bot = dit.bottom();
CoordCache::ParPosCache::const_iterator cache_it =
- theCoords.getParPos().find(bot.text());
- if (cache_it == theCoords.getParPos().end())
+ theCoords->getParPos().find(bot.text());
+ if (cache_it == theCoords->getParPos().end())
return Point(-1, -1);
CoordCache::InnerParPosCache const & cache = cache_it->second;
@@ -221,7 +221,8 @@
// this could be used elsewhere as well?
CurStatus status(BufferView const * bv, DocIterator const & dit)
{
- CoordCache::InnerParPosCache const & cache =
theCoords.getParPos().find(dit.bottom().text())->second;
+ CoordCache::InnerParPosCache const & cache =
+ bv->coordCache().getParPos().find(dit.bottom().text())->second;
if (cache.find(dit.bottom().pit()) != cache.end())
return CUR_INSIDE;
Index: coordcache.C
===================================================================
--- coordcache.C (revision 15305)
+++ coordcache.C (working copy)
@@ -19,8 +19,6 @@
#include <boost/assert.hpp>
-CoordCache theCoords;
-
// just a helper to be able to set a breakpoint
void lyxbreaker(void const * data, const char * hint, int size)
{
Index: coordcache.h
===================================================================
--- coordcache.h (revision 15305)
+++ coordcache.h (working copy)
@@ -150,6 +150,6 @@
SliceCache slices1_;
};
-extern CoordCache theCoords;
+extern CoordCache * theCoords;
#endif
Index: cursor.C
===================================================================
--- cursor.C (revision 15305)
+++ cursor.C (working copy)
@@ -98,7 +98,7 @@
int xo;
int yo;
InsetBase const * inset = &it.inset();
- Point o = theCoords.getInsets().xy(inset);
+ Point o = c.bv().coordCache().getInsets().xy(inset);
inset->cursorPos(it.top(), c.boundary(), xo, yo);
// Convert to absolute
xo += o.x_;
@@ -127,7 +127,8 @@
BOOST_ASSERT(!cursor.empty());
InsetBase & inset = cursor[0].inset();
- CoordCache::InnerParPosCache const & cache =
theCoords.getParPos().find(cursor.bottom().text())->second;
+ CoordCache::InnerParPosCache const & cache =
+
cursor.bv().coordCache().getParPos().find(cursor.bottom().text())->second;
// Get an iterator on the first paragraph in the cache
DocIterator it(inset);
it.push_back(CursorSlice(inset));
Index: insets/inset.C
===================================================================
--- insets/inset.C (revision 15305)
+++ insets/inset.C (working copy)
@@ -15,6 +15,7 @@
#include "inset.h"
+#include "BufferView.h"
#include "debug.h"
#include "gettext.h"
#include "lyxtext.h"
@@ -67,8 +68,8 @@
}
-void InsetOld::setPosCache(PainterInfo const &, int x, int y) const
+void InsetOld::setPosCache(PainterInfo const & pi, int x, int y) const
{
//lyxerr << "InsetOld:: position cache to " << x << " " << y <<
std::endl;
- theCoords.insets().add(this, x, y);
+ pi.base.bv->coordCache().insets().add(this, x, y);
}
Index: insets/insetbase.C
===================================================================
--- insets/insetbase.C (revision 15305)
+++ insets/insetbase.C (working copy)
@@ -329,13 +329,13 @@
int InsetBase::xo() const
{
- return theCoords.getInsets().x(this);
+ return theCoords->getInsets().x(this);
}
int InsetBase::yo() const
{
- return theCoords.getInsets().y(this);
+ return theCoords->getInsets().y(this);
}
@@ -346,7 +346,7 @@
// << " x1: " << xo() << " x2: " << xo() + width()
// << " y1: " << yo() - ascent() << " y2: " << yo() + descent()
// << std::endl;
- return theCoords.getInsets().has(this)
+ return theCoords->getInsets().has(this)
&& x >= xo()
&& x <= xo() + width()
&& y >= yo() - ascent()
Index: insets/insettabular.C
===================================================================
--- insets/insettabular.C (revision 15305)
+++ insets/insettabular.C (working copy)
@@ -1152,7 +1152,7 @@
int xx = 0;
int yy = 0;
InsetBase const & inset = *tabular.getCellInset(cell);
- Point o = theCoords.getInsets().xy(&inset);
+ Point o = theCoords->getInsets().xy(&inset);
int const xbeg = o.x_ - tabular.getBeginningOfTextInCell(cell);
int const xend = xbeg + tabular.getWidthOfColumn(cell);
row_type const row = tabular.row_of_cell(cell);
@@ -1201,7 +1201,7 @@
idx_type idx_min = 0;
int dist_min = std::numeric_limits<int>::max();
for (idx_type i = 0, n = nargs(); i != n; ++i) {
- if (theCoords.getInsets().has(tabular.getCellInset(i).get())) {
+ if (theCoords->getInsets().has(tabular.getCellInset(i).get())) {
int const d = dist(i, x, y);
if (d < dist_min) {
dist_min = d;
Index: lyx_main.C
===================================================================
--- lyx_main.C (revision 15306)
+++ lyx_main.C (working copy)
@@ -42,6 +42,7 @@
#include "frontends/Alert.h"
#include "frontends/Application.h"
+#include "frontends/Gui.h"
#include "frontends/LyXView.h"
#include "support/environment.h"
@@ -381,6 +382,13 @@
LyXView * view = &theApp->createView(width, height, posx, posy,
maximize);
ref().addLyXView(view);
+ int view2_id = theApp->gui().newView(width, height);
+ LyXView & view2 = theApp->gui().view(view2_id);
+ ref().addLyXView(&view2);
+ /*int workArea_id_ =*/ theApp->gui().newWorkArea(width, height,
view2_id);
+ view2.init();
+ view2.setGeometry(width-100, height-100, posx, posy, maximize);
+
// load files
for_each(files.begin(), files.end(),
bind(&LyXView::loadLyXFile, view, _1, true));
Index: mathed/InsetMathDim.C
===================================================================
--- mathed/InsetMathDim.C (revision 15305)
+++ mathed/InsetMathDim.C (working copy)
@@ -40,5 +40,5 @@
void InsetMathDim::setPosCache(PainterInfo const &, int x, int y) const
{
//lyxerr << "InsetMathDim: cache to " << x << " " << y << std::endl;
- theCoords.insets().add(this, x, y);
+ theCoords->insets().add(this, x, y);
}
Index: mathed/InsetMathNest.C
===================================================================
--- mathed/InsetMathNest.C (revision 15305)
+++ mathed/InsetMathNest.C (working copy)
@@ -106,7 +106,7 @@
// absolute again when actually drawing the cursor. What a mess.
BOOST_ASSERT(ptr_cmp(&sl.inset(), this));
MathArray const & ar = sl.cell();
- if (!theCoords.getArrays().has(&ar)) {
+ if (!theCoords->getArrays().has(&ar)) {
// this can (semi-)legally happen if we just created this cell
// and it never has been drawn before. So don't ASSERT.
//lyxerr << "no cached data for array " << &ar << endl;
@@ -114,15 +114,15 @@
y = 0;
return;
}
- Point const pt = theCoords.getArrays().xy(&ar);
- if (!theCoords.getInsets().has(this)) {
+ Point const pt = theCoords->getArrays().xy(&ar);
+ if (!theCoords->getInsets().has(this)) {
// same as above
//lyxerr << "no cached data for inset " << this << endl;
x = 0;
y = 0;
return;
}
- Point const pt2 = theCoords.getInsets().xy(this);
+ Point const pt2 = theCoords->getInsets().xy(this);
//lyxerr << "retrieving position cache for MathArray "
// << pt.x_ << ' ' << pt.y_ << std::endl;
x = pt.x_ - pt2.x_ + ar.pos2x(sl.pos());
Index: mathed/MathData.C
===================================================================
--- mathed/MathData.C (revision 15305)
+++ mathed/MathData.C (working copy)
@@ -19,11 +19,11 @@
#include "MathSupport.h"
#include "MathReplace.h"
-#include "coordcache.h"
-#include "LColor.h"
+#include "BufferView.h"
#include "buffer.h"
#include "cursor.h"
#include "debug.h"
+#include "LColor.h"
#include "frontends/Painter.h"
@@ -309,7 +309,8 @@
}
}
#endif
- theCoords.insets().add(at.nucleus(), x, y);
+ //BufferView & bv = *pi.base.bv;
+ pi.base.bv->coordCache().insets().add(at.nucleus(), x, y);
at->drawSelection(pi, x, y);
at->draw(pi, x, y);
x += at->width();
@@ -427,17 +428,17 @@
void MathArray::setXY(int x, int y) const
{
//lyxerr << "setting position cache for MathArray " << this <<
std::endl;
- theCoords.arrays().add(this, x, y);
+ theCoords->arrays().add(this, x, y);
}
int MathArray::xo() const
{
- return theCoords.getArrays().x(this);
+ return theCoords->getArrays().x(this);
}
int MathArray::yo() const
{
- return theCoords.getArrays().y(this);
+ return theCoords->getArrays().y(this);
}
Index: rowpainter.C
===================================================================
--- rowpainter.C (revision 15305)
+++ rowpainter.C (working copy)
@@ -97,7 +97,7 @@
LyXFont const getLabelFont() const;
/// bufferview to paint on
- BufferView const & bv_;
+ BufferView & bv_;
/// Painter to use
Painter & pain_;
@@ -173,7 +173,7 @@
font;
pi.ltr_pos = (text_.bidi.level(pos) % 2 == 0);
pi.erased_ = erased_ || isDeletedText(par_, pos);
- theCoords.insets().add(inset, int(x_), yo_);
+ bv_.coordCache().insets().add(inset, int(x_), yo_);
InsetText const * const in = inset->asTextInset();
// non-wide insets are painted completely. Recursive
bool tmp = refreshInside;
@@ -828,7 +828,7 @@
static PainterInfo nullpi(pi.base.bv, nop);
int const ww = pi.base.bv->workHeight();
- theCoords.parPos()[&text][pit] = Point(x, y);
+ pi.base.bv->coordCache().parPos()[&text][pit] = Point(x, y);
Paragraph const & par = text.paragraphs()[pit];
if (par.rows().empty())
@@ -913,7 +913,7 @@
} // namespace anon
-void paintText(BufferView const & bv, ViewMetricsInfo const & vi,
+void paintText(BufferView & bv, ViewMetricsInfo const & vi,
Painter & pain)
{
LyXText & text = bv.buffer()->text();
@@ -948,13 +948,13 @@
if (vi.p1 > 0) {
text.redoParagraph(vi.p1 - 1);
- theCoords.parPos()[&text][vi.p1 - 1] =
+ bv.coordCache().parPos()[&text][vi.p1 - 1] =
Point(0, vi.y1 - text.getPar(vi.p1 - 1).descent());
}
if (vi.p2 < lyx::pit_type(text.paragraphs().size()) - 1) {
text.redoParagraph(vi.p2 + 1);
- theCoords.parPos()[&text][vi.p2 + 1] =
+ bv.coordCache().parPos()[&text][vi.p2 + 1] =
Point(0, vi.y2 + text.getPar(vi.p2 + 1).ascent());
}
Index: rowpainter.h
===================================================================
--- rowpainter.h (revision 15305)
+++ rowpainter.h (working copy)
@@ -29,7 +29,7 @@
/// paint visible paragraph of main text
-void paintText(BufferView const & bv, ViewMetricsInfo const & vi,
+void paintText(BufferView & bv, ViewMetricsInfo const & vi,
lyx::frontend::Painter & painter);
/// paint the rows of a text inset
Index: text.C
===================================================================
--- text.C (revision 15305)
+++ text.C (working copy)
@@ -2549,7 +2549,7 @@
{
BOOST_ASSERT(this == cur.text());
pit_type pit = getPitNearY(y);
- int yy = theCoords.get(this, pit).y_ - pars_[pit].ascent();
+ int yy = cur.bv().coordCache().get(this, pit).y_ - pars_[pit].ascent();
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< ": x: " << x
Index: text2.C
===================================================================
--- text2.C (revision 15305)
+++ text2.C (working copy)
@@ -128,7 +128,7 @@
<< BOOST_CURRENT_FUNCTION
<< ": examining inset " << inset << endl;
- if (theCoords.getInsets().has(inset))
+ if (theCoords->getInsets().has(inset))
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< ": xo: " << inset->xo() << "..."
@@ -777,7 +777,7 @@
pos_type LyXText::getColumnNearX(pit_type const pit,
Row const & row, int & x, bool & boundary)
const
{
- int const xo = theCoords.get(this, pit).x_;
+ int const xo = theCoords->get(this, pit).x_;
x -= xo;
RowMetrics const r = computeRowMetrics(pit, row);
Paragraph const & par = pars_[pit];
@@ -913,8 +913,8 @@
pit_type LyXText::getPitNearY(int y) const
{
BOOST_ASSERT(!paragraphs().empty());
- BOOST_ASSERT(theCoords.getParPos().find(this) !=
theCoords.getParPos().end());
- CoordCache::InnerParPosCache const & cc =
theCoords.getParPos().find(this)->second;
+ BOOST_ASSERT(theCoords->getParPos().find(this) !=
theCoords.getParPos().end());
+ CoordCache::InnerParPosCache const & cc =
theCoords->getParPos().find(this)->second;
lyxerr[Debug::DEBUG]
<< BOOST_CURRENT_FUNCTION
<< ": y: " << y << " cache size: " << cc.size()
@@ -950,7 +950,7 @@
Row const & LyXText::getRowNearY(int y, pit_type pit) const
{
Paragraph const & par = pars_[pit];
- int yy = theCoords.get(this, pit).y_ - par.ascent();
+ int yy = theCoords->get(this, pit).y_ - par.ascent();
BOOST_ASSERT(!par.rows().empty());
RowList::const_iterator rit = par.rows().begin();
RowList::const_iterator const rlast = boost::prior(par.rows().end());