2 * \file GraphicsSupport.C
3 * Copyright 2002 the LyX Team
4 * Read the file COPYING
6 * \author Angus Leeming <leeming@lyx.org>
12 #pragma implementation
15 #include "GraphicsSupport.h"
17 #include "BufferView.h"
20 #include "paragraph.h"
21 #include "frontends/Painter.h"
24 typedef std::list<VisibleParagraph> VPList;
27 VPList const getVisibleParagraphs(BufferView const & bv)
29 // top_y is not const because it's reset by getRowNearY.
30 int top_y = bv.text->first_y;
31 Row const * row = bv.text->getRowNearY(top_y);
33 int const bv_height = bv.painter().paperHeight();
36 Row const * last_row = 0;
38 for (int height = 0; row && height < bv_height; row = row->next()) {
39 height += row->height();
41 if (vps.empty() || vps.back().par != row->par()) {
42 vps.push_back(VisibleParagraph(row->par(),
50 // If the end of the final paragraph is not visble,
51 // update vps.back().end
52 if (last_row && last_row->next() &&
53 last_row->par() == last_row->next()->par()) {
54 vps.back().end = last_row->next()->pos();
63 struct InsetVisibleInParagraph {
64 InsetVisibleInParagraph(Inset const & inset) : inset_(inset) {}
65 bool operator()(VisibleParagraph const & vp)
67 Paragraph * par = vp.par;
68 InsetList::iterator it = par->insetlist.begin();
69 InsetList::iterator end = par->insetlist.end();
71 // Can't refactor this as a functor because we rely on the
72 // inset_iterator member function getPos().
73 for (; it != end; ++it) {
74 lyx::pos_type const pos = it.getPos();
75 if (pos >= vp.start && pos <= vp.end) {
76 if (it.getInset() == &inset_ ||
77 it.getInset()->getInsetFromID(inset_.id()) != 0)
91 bool isInsetVisible(Inset const & inset, VPList const & vps)
96 VPList::const_iterator it = vps.begin();
97 VPList::const_iterator end = vps.end();
99 it = std::find_if(it, end, InsetVisibleInParagraph(inset));