]> git.lyx.org Git - lyx.git/blobdiff - src/coordcache.h
Fix bug 886 and others not reported related with the document paper size.
[lyx.git] / src / coordcache.h
index 3a70e6d78dbe7a653c1e2cf262912bf5ec42bd2e..4fe2c006d1ad33e9d9f1f078cdfc86d3a9bb0e6c 100644 (file)
@@ -1,3 +1,13 @@
+// -*- C++ -*-
+/* \file coordcache.h
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
+ *
+ * \author André Pönitz
+ *
+ * Full author contact details are available in file CREDITS.
+ */
+
 #ifndef COORDCACHE_H
 #define COORDCACHE_H
 
@@ -12,13 +22,7 @@ class Paragraph;
 
 #include <map>
 
-
-// All positions cached in this cache are only valid between subsequent
-// updated. (x,y) == (0,0) is the upper left screen corner, x increases
-// to the right, y increases downwords.
-
 void lyxbreaker(void const * data, const char * hint, int size);
-void lyxaborter(int x, int y);
 
 class Point {
 public:
@@ -92,21 +96,55 @@ private:
        cache_type data_;
 };
 
-
+/**
+ * A global cache that allows us to come from a paragraph in a document
+ * to a position point on the screen.
+ * All points cached in this cache are only valid between subsequent
+ * updated. (x,y) == (0,0) is the upper left screen corner, x increases
+ * to the right, y increases downwords.
+ * The cache is built in BufferView::Pimpl::metrics which is called
+ * from BufferView::Pimpl::update. The individual points are added
+ * while we paint them. See for instance paintPar in RowPainter.C.
+ */
 class CoordCache {
 public:
+       CoordCache() : updating(false) { }
+       /// In order to find bugs, we record when we start updating the cache
+       void startUpdating();
+       /// When we are done, we record that to help find bugs
+       void doneUpdating();
+
        void clear();
        Point get(LyXText const *, lyx::pit_type);
 
+       /// A map from paragraph index number to screen point
+       typedef std::map<lyx::pit_type, Point> InnerParPosCache;
+       /// A map from a LyXText to the map of paragraphs to screen points
+       typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
+
+       /// A map from MathArray to position on the screen
+       CoordCacheBase<MathArray> & arrays() { BOOST_ASSERT(updating); return arrays_; }
+       CoordCacheBase<MathArray> const & getArrays() const { return arrays_; }
+       /// A map from insets to positions on the screen
+       CoordCacheBase<InsetBase> & insets() { BOOST_ASSERT(updating); return insets_; }
+       CoordCacheBase<InsetBase> const & getInsets() const { return insets_; }
+       /// A map from (LyXText, paragraph) pair to screen positions
+       ParPosCache & parPos() { BOOST_ASSERT(updating); return pars_; }
+       ParPosCache const & getParPos() const { return pars_; }
+private:
        CoordCacheBase<MathArray> arrays_;
-       
+
        // all insets
        CoordCacheBase<InsetBase> insets_;
 
        // paragraph grouped by owning text
-       typedef std::map<lyx::pit_type, Point> InnerParPosCache;
-       typedef std::map<LyXText const *, InnerParPosCache> ParPosCache;
        ParPosCache pars_;
+
+       /**
+        * Debugging flag only: Set to true while the cache is being built.
+        * No changes to the structure are allowed unless we are updating.
+        */
+       bool updating;
 };
 
 extern CoordCache theCoords;