-// This is only the very first implemetation and use of the TextCache,
-// operations on it needs to be put into a class or a namespace, that part
-// is _NOT_ finished so don't bother to come with too many comments on it
-// (unless you have some nice ideas on where/how to do it)
-//
-// I think we need a TextCache that is common for all BufferViews,
-// please tell if you don't agree.
-//
-// Q. What are we caching?
-// A. We are caching the screen representations (LyXText) of the
-// documents (Buffer,LyXParagraph) for specific BufferView widths.
-// Q. Why the cache?
-// A. It is not really needed, but it speeds things up a lot
-// when you have more than one document loaded at once since a total
-// rebreak (reformatting) need not be done when switching between
-// documents. When the cache is in function a document only needs to be
-// formatted upon loading and when the with of the BufferView changes.
-// Later it will also be unneccessary to reformat when having two
-// BufferViews of equal width with the same document, a simple copy
-// of the LyXText structure will do.
-// Invariant for the TextCache:
-// - The buffer of the text in the TextCache _must_ exists
-// in the bufferlist.
-// - For a text in the TextCache there _must not_ be an equivalent
-// text in any BufferView. (same buffer and width).
-// Among others this mean:
-// - When a document is closed all trace of it must be removed from
-// the TextCache.
-// Scenarios:
-// I believe there are only three possible scenarios where the two first
-// are also covered by the third.
-// - The simplest scenario is what we have now, a single
-// BufferView only.
-// o Opening
-// Nothing to do with the TextCache is done when opening a file.
-// o Switching
-// We switch from buffer A to buffer B.
-// * A's text is cached in TextCache.
-// * We make a search for a text in TextCache that fits B
-// (same buffer and same width).
-// o Horizontal resize
-// If the BufferView's width (LyXView) is horizontally changed all
-// the entries in the TextCache are deleted. (This causes
-// reformat of all loaded documents when next viewed)
-// o Close
-// When a buffer is closed we don't have to do anything, because
-// to close a single buffer it is required to only exist in the
-// BufferView and not in the TextCache. Upon LFUN_QUIT we
-// don't really care since everything is deleted anyway.
-// - The next scenario is when we have several BufferViews (in one or
-// more LyXViews) of equal width.
-// o Opening
-// Nothing to do with the TextCache is done when opening a file.
-// o Switching
-// We switch from buffer A to buffer B.
-// * If A is in another Bufferview we do not put it into TextCache.
-// else we put A into TextCache.
-// * If B is viewed in another BufferView we make a copy of its
-// text and use that, else we search in TextCache for a match.
-// (same buffer same width)
-// o Horizontal resize
-// If the BufferView's width (LyXView) is horisontaly changed all
-// the entries in the TextCache is deleted. (This causes
-// reformat of all loaded documents when next viewed)
-// o Close
-// - The last scenario should cover both the previous ones, this time
-// we have several BufferViews (in one or more LyXViews) with no
-// limitations on width. (And if you wonder why the two other
-// senarios are needed... I used them to get to this one.)
-// o Opening
-// Nothing to do with the TextCache is done when opening a file.
-// o Switching
-// We switch from buffer A to buffer B.
-// o Horisontal rezize
-// o Close
-
-typedef vector<LyXText*> TextCache;
-TextCache textcache;
-
-class text_fits {
-public:
- text_fits(Buffer * b, unsigned short p)
- : buf(b), pw(p) {}
- bool operator()(TextCache::value_type & vt) {
- if (vt->params == buf && vt->paperWidth() == pw) return true;
- return false;
- }
-private:
- Buffer * buf;
- unsigned short pw;
-};
-
-
-class show_text {
-public:
- show_text(ostream & o) : os(o) {}
- void operator()(TextCache::value_type & vt) {
- os << "Buffer: " << vt->params
- << "\nWidth: " << vt->paperWidth() << endl;
- }
-private:
- ostream & os;
-};