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