]> git.lyx.org Git - lyx.git/blob - src/graphics/GraphicsSupport.C
remove noload/don't typeset
[lyx.git] / src / graphics / GraphicsSupport.C
1 /**
2  *  \file GraphicsSupport.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming 
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "GraphicsSupport.h"
18
19 #include "BufferView.h"
20 #include "lyxtext.h"
21 #include "lyxrow.h"
22 #include "paragraph.h"
23 #include "frontends/Painter.h"
24
25
26 typedef std::list<VisibleParagraph> VPList;
27
28
29 VPList const getVisibleParagraphs(BufferView const & bv)
30 {
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);
34
35         int const bv_height = bv.painter().paperHeight();
36
37         VPList vps;
38         Row const * last_row = 0;
39
40         for (int height = 0; row && height < bv_height; row = row->next()) {
41                 height += row->height();
42
43                 if (vps.empty() || vps.back().par != row->par()) {
44                         vps.push_back(VisibleParagraph(row->par(),
45                                                        row->pos(),
46                                                        row->par()->size()));
47                 }
48
49                 last_row = row;
50         }
51
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();
57         }
58
59         return vps;
60 }
61
62
63 namespace {
64
65 struct InsetVisibleInParagraph {
66         InsetVisibleInParagraph(Inset const & inset) : inset_(inset) {}
67         bool operator()(VisibleParagraph const & vp)
68         {
69                 Paragraph * par = vp.par;
70                 InsetList::iterator it  = par->insetlist.begin();
71                 InsetList::iterator end = par->insetlist.end();
72
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)
80                                         return true;
81                         }
82                 }
83                 return false;
84         }
85
86 private:
87         Inset const & inset_;
88 };
89
90 } // namespace anon
91
92
93 bool isInsetVisible(Inset const & inset, VPList const & vps)
94 {
95         if (vps.empty())
96                 return false;
97
98         VPList::const_iterator it  = vps.begin();
99         VPList::const_iterator end = vps.end();
100
101         it = std::find_if(it, end, InsetVisibleInParagraph(inset));
102
103         return it != end;
104 }