2 * \file GraphicsSupport.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS
14 #pragma implementation
17 #include "GraphicsSupport.h"
19 #include "BufferView.h"
22 #include "paragraph.h"
23 #include "frontends/Painter.h"
26 typedef std::list<VisibleParagraph> VPList;
29 VPList const getVisibleParagraphs(BufferView const & bv)
31 // top_y is not const because it's reset by getRowNearY.
32 int top_y = bv.text->first_y;
33 Row const * row = bv.text->getRowNearY(top_y);
35 int const bv_height = bv.painter().paperHeight();
38 Row const * last_row = 0;
40 for (int height = 0; row && height < bv_height; row = row->next()) {
41 height += row->height();
43 if (vps.empty() || vps.back().par != row->par()) {
44 vps.push_back(VisibleParagraph(row->par(),
52 // If the end of the final paragraph is not visble,
53 // update vps.back().end
54 if (last_row && last_row->next() &&
55 last_row->par() == last_row->next()->par()) {
56 vps.back().end = last_row->next()->pos();
65 struct InsetVisibleInParagraph {
66 InsetVisibleInParagraph(Inset const & inset) : inset_(inset) {}
67 bool operator()(VisibleParagraph const & vp)
69 Paragraph * par = vp.par;
70 InsetList::iterator it = par->insetlist.begin();
71 InsetList::iterator end = par->insetlist.end();
73 // Can't refactor this as a functor because we rely on the
74 // inset_iterator member function getPos().
75 for (; it != end; ++it) {
76 lyx::pos_type const pos = it.getPos();
77 if (pos >= vp.start && pos <= vp.end) {
78 if (it.getInset() == &inset_ ||
79 it.getInset()->getInsetFromID(inset_.id()) != 0)
93 bool isInsetVisible(Inset const & inset, VPList const & vps)
98 VPList::const_iterator it = vps.begin();
99 VPList::const_iterator end = vps.end();
101 it = std::find_if(it, end, InsetVisibleInParagraph(inset));